} ob_start(); include "../../../../inc/includes.php"; ob_end_clean(); $response = FALSE; //Agent communication using REST protocol if (isset($_GET['action']) && isset($_GET['machineid'])) { switch ($_GET['action']) { case 'getJobs': $pfAgent = new PluginFusioninventoryAgent(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $agent = $pfAgent->InfosByKey(Toolbox::addslashes_deep($_GET['machineid'])); if (isset($agent['id'])) { $taskjobstates = $pfTask->getTaskjobstatesForAgent($agent['id'], array('InventoryComputerESX')); ////start of json response $order = new stdClass(); $order->jobs = array(); $module = new PluginFusioninventoryInventoryComputerESX(); foreach ($taskjobstates as $taskjobstate) { $order->jobs[] = $module->run($taskjobstate); $taskjobstate->changeStatus($taskjobstate->fields['id'], $taskjobstate::SERVER_HAS_SENT_DATA); } // return an empty dictionnary if there are no jobs. if (count($order->jobs) == 0) { $response = "{}"; } else { $response = json_encode($order); } }
include "../../../../inc/includes.php"; ob_end_clean(); $response = FALSE; //Agent communication using REST protocol if (isset($_GET['action'])) { switch ($_GET['action']) { case 'getJobs': if (isset($_GET['machineid'])) { $pfAgent = new PluginFusioninventoryAgent(); $pfAgentModule = new PluginFusioninventoryAgentModule(); $pfTask = new PluginFusioninventoryTask(); $pfTaskjob = new PluginFusioninventoryTaskjob(); $pfTaskjobstate = new PluginFusioninventoryTaskjobstate(); $agent = $pfAgent->InfosByKey(Toolbox::addslashes_deep($_GET['machineid'])); if (isset($agent['id'])) { $taskjobstates = $pfTask->getTaskjobstatesForAgent($agent['id'], array('deployinstall', 'deployuninstall')); if (!$pfAgentModule->isAgentCanDo("DEPLOY", $agent['id'])) { foreach ($taskjobstates as $taskjobstate) { $taskjobstate->cancel(__("Deploy module has been disabled for this agent", 'fusioninventory')); } $response = "{}"; } else { //sort taskjobs by key id /** * TODO: sort taskjobs by 'index' field in the taskjob query since it can be * manipulated by drag and drop (cf. Task::getTaskjobsForAgent() ). */ ////start of json response $order = new stdClass(); $order->jobs = array(); $order->associatedFiles = new stdClass();
/** * Get all tasks prepared for this agent * * @param $agent_id interger id of agent * **/ function getTaskAgent($agent_id) { $pfTask = new PluginFusioninventoryTask(); /** * TODO: the following must be definitely done differently ! * (... but i'm kind in a hurry right now ;-) ) */ $methods = array(); $classnames = array(); foreach (PluginFusioninventoryStaticmisc::getmethods() as $method) { if (isset($method['classname'])) { $methods[] = $method['method']; $classnames[$method['method']] = $method['classname']; } } $jobstates = $pfTask->getTaskjobstatesForAgent($agent_id, $methods); foreach ($jobstates as $jobstate) { $className = $classnames[$jobstate->method]; if (class_exists($className)) { /* * TODO: check if use_rest is enabled in Staticmisc::get_methods. * Also, this get_methods function need to be reviewed */ if ($className != "PluginFusioninventoryInventoryComputerESX" && $className != "PluginFusioninventoryDeployCommon" && $className != "PluginFusioninventoryCollect") { $class = new $className(); $sxml_temp = $class->run($jobstate); PluginFusioninventoryToolbox::append_simplexml($this->message, $sxml_temp); } } } }