/**
  * Import data
  *
  * @param $p_DEVICEID XML code to import
  * @param $p_CONTENT XML code to import
  * @param $p_xml value XML code to import
  *
  * @return "" (import ok) / error string (import ko)
  *
  **/
 function import($p_DEVICEID, $a_CONTENT, $arrayinventory)
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfAgent = new PluginFusioninventoryAgent();
     PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkDiscovery->import().');
     $errors = '';
     $a_agent = $pfAgent->InfosByKey($p_DEVICEID);
     if (isset($a_CONTENT['PROCESSNUMBER'])) {
         $_SESSION['glpi_plugin_fusioninventory_processnumber'] = $a_CONTENT['PROCESSNUMBER'];
         if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) {
             if ($pfTaskjobstate->fields['state'] != "3") {
                 $pfTaskjobstate->changeStatus($a_CONTENT['PROCESSNUMBER'], 2);
                 if (!isset($a_CONTENT['AGENT']['START']) and !isset($a_CONTENT['AGENT']['END'])) {
                     $nb_devices = 0;
                     if (isset($a_CONTENT['DEVICE'])) {
                         if (is_int(key($a_CONTENT['DEVICE']))) {
                             $nb_devices = count($a_CONTENT['DEVICE']);
                         } else {
                             $nb_devices = 1;
                         }
                     }
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $a_agent['id'];
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
                     $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = $nb_devices . ' ==devicesfound==';
                     $this->addtaskjoblog();
                 }
             }
         }
     }
     if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) {
         if ($pfTaskjobstate->fields['state'] != "3") {
             $pfImportExport = new PluginFusioninventorySnmpmodelImportExport();
             $errors .= $pfImportExport->import_netdiscovery($a_CONTENT, $p_DEVICEID);
             if (isset($a_CONTENT['AGENT']['END'])) {
                 if (isset($a_CONTENT['DICO']) and $a_CONTENT['DICO'] == "REQUEST") {
                     $pfAgent->getFromDB($pfTaskjobstate->fields["plugin_fusioninventory_agents_id"]);
                     $input = array();
                     $input['id'] = $pfAgent->fields['id'];
                     $input["senddico"] = "1";
                     $pfAgent->update($input);
                     $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '1', '==diconotuptodate==');
                 } else {
                     $messages = array('Total Found' => 0, 'Created' => 0, 'Updated' => 0);
                     $messages['Updated'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==updatetheitem==%'");
                     $messages['Created'] = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%==addtheitem==%'");
                     $messages['Total Found'] = $messages['Updated'] + $messages['Created'];
                     $message = 'Total Found:' . $messages['Total Found'] . ' Created:' . $messages['Created'] . ' Updated:' . $messages['Updated'];
                     $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $a_agent['id'], 'PluginFusioninventoryAgent', '0', $message);
                 }
             }
         }
     }
     return $errors;
 }
 /**
  * Import data
  *
  *@param $p_DEVICEID XML code to import
  *@param $p_CONTENT XML code to import
  *@return "" (import ok) / error string (import ko)
  **/
 function import($p_DEVICEID, $a_CONTENT, $arrayinventory)
 {
     //$_SESSION['SOURCEXML'] = $p_xml;
     PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->import().');
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $this->agent = $pfAgent->InfosByKey($p_DEVICEID);
     $this->arrayinventory = $arrayinventory;
     $_SESSION['glpi_plugin_fusioninventory_processnumber'] = $a_CONTENT['PROCESSNUMBER'];
     if (!isset($a_CONTENT['AGENT']['START']) and !isset($a_CONTENT['AGENT']['END'])) {
         $nb_devices = 0;
         if (isset($a_CONTENT['DEVICE'])) {
             if (is_int(key($a_CONTENT['DEVICE']))) {
                 $nb_devices = count($a_CONTENT['DEVICE']);
             } else {
                 $nb_devices = 1;
             }
         }
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $this->agent['id'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = $nb_devices . ' ==devicesqueried==';
         $this->addtaskjoblog();
     }
     $this->importContent($a_CONTENT);
     if (isset($a_CONTENT['AGENT']['END'])) {
         $cnt = countElementsInTable('glpi_plugin_fusioninventory_taskjoblogs', "`plugin_fusioninventory_taskjobstates_id`='" . $a_CONTENT['PROCESSNUMBER'] . "' " . " AND `comment` LIKE '%[==detail==] Update %'");
         $pfTaskjobstate->changeStatusFinish($a_CONTENT['PROCESSNUMBER'], $this->agent['id'], 'PluginFusioninventoryAgent', '0', 'Total updated:' . $cnt);
     }
     if (isset($a_CONTENT['AGENT']['START'])) {
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['taskjobs_id'] = $a_CONTENT['PROCESSNUMBER'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['items_id'] = $this->agent['id'];
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['itemtype'] = 'PluginFusioninventoryAgent';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['state'] = '6';
         $_SESSION['plugin_fusinvsnmp_taskjoblog']['comment'] = '==inventorystarted==';
         $this->addtaskjoblog();
     }
 }
コード例 #3
0
 /**
  * @test
  */
 public function getDevicesToInventory()
 {
     global $DB;
     // Verify prepare a network discovery task
     $DB->connect();
     $pfNetworkinventory = new PluginFusioninventoryNetworkinventory();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $jobstate->getFromDB(1);
     $data = $pfNetworkinventory->run($jobstate);
     $this->mark_incomplete("This test doesn't assert anything! Also, there are too much notices thrown ... needs" . "investigations.");
 }
コード例 #4
0
 /**
  * @see CommonDBTM::post_updateItem()
  **/
 function post_updateItem($history = 1)
 {
     global $DB, $CFG_GLPI;
     if (isset($this->oldvalues['is_active']) && $this->oldvalues['is_active'] == 1) {
         // If disable task, must end all taskjobstates prepared
         $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
         $query = implode(" \n", array("SELECT", "     task.`id`, task.`name`, task.`is_active`,", "     task.`datetime_start`, task.`datetime_end`,", "     task.`plugin_fusioninventory_timeslots_id` as timeslot_id,", "     job.`id`, job.`name`, job.`method`, job.`actors`,", "     run.`itemtype`, run.`items_id`, run.`state`,", "     run.`id`, run.`plugin_fusioninventory_agents_id`", "FROM `glpi_plugin_fusioninventory_taskjobstates` run", "LEFT JOIN `glpi_plugin_fusioninventory_taskjobs` job", "  ON job.`id` = run.`plugin_fusioninventory_taskjobs_id`", "LEFT JOIN `glpi_plugin_fusioninventory_tasks` task", "  ON task.`id` = job.`plugin_fusioninventory_tasks_id`", "WHERE", "  run.`state` IN ('" . implode("','", array(PluginFusioninventoryTaskjobstate::PREPARED)) . "')", "  AND task.`id` = " . $this->fields['id'], "ORDER BY job.`id`"));
         $query_result = $DB->query($query);
         $results = array();
         if ($query_result) {
             $results = PluginFusioninventoryToolbox::fetchAssocByTable($query_result);
         }
         foreach ($results as $data) {
             $pfTaskjobstate->getFromDB($data['run']['id']);
             $pfTaskjobstate->cancel(__('Task has been disabled', 'fusioninventory'));
         }
     }
     parent::post_updateItem($history);
 }
コード例 #5
0
  You should have received a copy of the GNU Affero General Public License
  along with FusionInventory. If not, see <http://www.gnu.org/licenses/>.

  ------------------------------------------------------------------------

  @package   FusionInventory
  @author    Kevin Roy
  @co-author
  @copyright Copyright (c) 2010-2015 FusionInventory team
  @license   AGPL License 3.0 or (at your option) any later version
             http://www.gnu.org/licenses/agpl-3.0-standalone.html
  @link      http://www.fusioninventory.org/
  @link      http://forge.fusioninventory.org/projects/fusioninventory-for-glpi/
  @since     2010

  ------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "jobstates_logs.php")) {
    include "../../../inc/includes.php";
    Session::checkCentralAccess();
}
//unlock session since access checks have been done
session_write_close();
header("Content-Type: text/json; charset=UTF-8");
Html::header_nocache();
$pfJobstate = new PluginFusioninventoryTaskjobstate();
$pfJobstate->ajaxGetLogs($_GET);
?>


コード例 #6
0
 /**
  * Display short logs
  *
  * @param $taskjobs_id integer id of taskjob
  * @param $veryshort boolean activation to have very very short display
  *
  * @return nothing
  */
 function displayShortLogs($taskjobs_id, $veryshort = 0)
 {
     global $DB, $CFG_GLPI;
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     echo "<td colspan='2' valign='top'>";
     if ($veryshort == '0') {
         echo "<table width='100%'>";
         echo "<tr class='tab_bg_3'>";
     } else {
         echo "<table>";
         echo "<tr class='tab_bg_1'>";
     }
     $query = "SELECT * FROM `glpi_plugin_fusioninventory_taskjobstates`\n         WHERE `plugin_fusioninventory_taskjobs_id`='" . $taskjobs_id . "'\n         ORDER BY `uniqid` DESC\n         LIMIT 1";
     $result = $DB->query($query);
     $uniqid = 0;
     while ($data = $DB->fetch_array($result)) {
         $uniqid = $data['uniqid'];
     }
     $query = "SELECT `glpi_plugin_fusioninventory_taskjoblogs`.*\n            FROM `glpi_plugin_fusioninventory_taskjoblogs`\n         LEFT JOIN `glpi_plugin_fusioninventory_taskjobstates`\n            ON plugin_fusioninventory_taskjobstates_id = " . "`glpi_plugin_fusioninventory_taskjobstates`.`id`\n         WHERE `uniqid`='" . $uniqid . "'\n         ORDER BY `glpi_plugin_fusioninventory_taskjoblogs`.`id` DESC\n         LIMIT 1";
     $state = 0;
     $date = '';
     $comment = '';
     $taskstates_id = 0;
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $state = $data['state'];
         $date = $data['date'];
         $comment = $data['comment'];
         $taskstates_id = $data['plugin_fusioninventory_taskjobstates_id'];
     }
     if (strstr($comment, "Merged with")) {
         $state = '7';
     }
     $a_taskjobstates = count($pfTaskjobstate->find("`plugin_fusioninventory_taskjobs_id`='" . $taskjobs_id . "'\n               AND `state` != '3'\n               AND `uniqid`='" . $uniqid . "'"));
     if ($state == '1' or $state == '6' or $state == '7') {
         // not finish
         if ($veryshort == '0') {
             echo "<th>";
             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/task_running.png'/>";
             echo "</th>";
         }
         echo $this->getDivState($state, 'td');
         echo "<td align='center'>";
         echo " <a href='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjoblog.php?sort=1&order=DESC&field[0]=6&" . "searchtype[0]=contains&contains[0]=" . $uniqid . "&" . "itemtype=PluginFusioninventoryTaskjoblog&start=0'>" . __('View logs of this execution', 'fusioninventory') . "</a>";
         echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjob.form.php'>";
         echo "<input type='hidden' name='taskjobstates_id' value='" . $taskstates_id . "' />";
         echo "<input type='hidden' name='taskjobs_id' value='" . $taskjobs_id . "' />";
         echo '&nbsp;&nbsp;&nbsp;<input name="forceend" value="' . __('Force the end', 'fusioninventory') . '" class="submit" type="submit">';
         Html::closeForm();
         echo "</td>";
         if ($veryshort == '0') {
             echo "</tr>";
             echo "<tr class='tab_bg_3'>";
             echo "<th>";
             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/task_finished.png'/>";
             echo "</th>";
             echo "<td colspan='2' align='center'>";
             echo " <a href='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjoblog.php?sort=1&order=DESC&" . "field[0]=3&searchtype[0]=equals&contains[0]=" . $taskjobs_id . "&" . "itemtype=PluginFusioninventoryTaskjoblog&start=0'>" . __('See all executions', 'fusioninventory') . "</a>";
             echo "</td>";
             echo "</tr>";
         }
     } else {
         // Finish
         if ($veryshort == '0') {
             echo "<th rowspan='2' height='64'>";
             echo "<img src='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/pics/task_finished.png'/>";
             echo "</th>";
         }
         echo $this->getDivState($state, 'td');
         if ($veryshort == '0') {
             echo "<td align='center'>";
         } else {
             echo "<td>";
         }
         if ($taskstates_id == '0') {
             echo __('Last run') . "&nbsp;:&nbsp;" . __('Never');
         } else {
             if ($veryshort == '0') {
                 if ($a_taskjobstates == '0') {
                     echo __('Last run') . " (" . Html::convDateTime($date) . ") : ";
                 }
                 echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjoblog.php?field[0]=6&" . "searchtype[0]=contains&contains[0]=" . $uniqid . "&" . "itemtype=PluginFusioninventoryTaskjoblog&start=0'>" . __('View logs of this execution', 'fusioninventory') . "</a>";
             } else {
                 if ($a_taskjobstates == '0') {
                     echo __('Last run') . " :<br/> " . Html::convDateTime($date) . "";
                 }
             }
         }
         if ($a_taskjobstates != '0') {
             echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjob.form.php'>";
             echo "<input type='hidden' name='taskjobstates_id' value='" . $taskstates_id . "' />";
             echo "<input type='hidden' name='taskjobs_id' value='" . $taskjobs_id . "' />";
             echo '&nbsp;&nbsp;&nbsp;<input name="forceend" value="' . __('Force the end', 'fusioninventory') . '" class="submit" type="submit">';
             Html::closeForm();
         }
         echo "</td>";
         echo "</tr>";
         if ($veryshort == '0') {
             echo "<tr class='tab_bg_3'>";
             echo "<td colspan='2' align='center'>";
             echo " <a href='" . $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/taskjoblog.php?field[0]=3&" . "searchtype[0]=equals&contains[0]=" . $taskjobs_id . "&" . "itemtype=PluginFusioninventoryTaskjoblog&start=0'>" . __('See all executions', 'fusioninventory') . "</a>";
             echo "</td>";
             echo "</tr>";
         }
     }
     echo "</table>";
     echo "</td>";
 }
コード例 #7
0
 /**
  * Force end task
  */
 function forceEnd()
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $a_taskjobstates = $pfTaskjobstate->find("`plugin_fusioninventory_taskjobs_id`='" . $this->fields["id"] . "'");
     //TODO: in order to avoid too many atomic operations on DB, convert the
     //following into a massive prepared operation (ie. ids in one massive action)
     foreach ($a_taskjobstates as $a_taskjobstate) {
         $pfTaskjobstate->getFromDB($a_taskjobstate['id']);
         if ($a_taskjobstate['state'] != PluginFusioninventoryTaskjobstate::FINISHED) {
             $pfTaskjobstate->changeStatusFinish($a_taskjobstate['id'], 0, '', 1, "Action cancelled by user", 0, 0);
         }
     }
     $this->reinitializeTaskjobs($this->fields['plugin_fusioninventory_tasks_id']);
 }
コード例 #8
0
 function prepareRun($taskjob_id, $definitions_filter = NULL)
 {
     global $DB;
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $agent = new PluginFusioninventoryAgent();
     $agentmodule = new PluginFusioninventoryAgentmodule();
     $job->getFromDB($taskjob_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     $actions = importArrayFromDB($job->fields['action']);
     $definitions = importArrayFromDB($job->fields['definition']);
     $taskvalid = 0;
     $computers = array();
     foreach ($actions as $action) {
         $itemtype = key($action);
         $items_id = current($action);
         switch ($itemtype) {
             case 'Computer':
                 if ($this->definitionFiltered("Computer", $definitions_filter)) {
                     break;
                 }
                 $computers[] = $items_id;
                 break;
             case 'Group':
                 if ($this->definitionFiltered("Group", $definitions_filter)) {
                     break;
                 }
                 $computer_object = new Computer();
                 //find computers by user associated with this group
                 $group_users = new Group_User();
                 $group = new Group();
                 $group->getFromDB($items_id);
                 $members = array();
                 $computers_a_1 = array();
                 $computers_a_2 = array();
                 //array_keys($group_users->find("groups_id = '$items_id'"));
                 $members = $group_users->getGroupUsers($items_id);
                 foreach ($members as $member) {
                     $computers = $computer_object->find("users_id = '{$member['id']}' " . " AND `is_deleted`='0' AND `is_template`='0'");
                     foreach ($computers as $computer) {
                         $computers_a_1[] = $computer['id'];
                     }
                 }
                 //find computers directly associated with this group
                 $computers = $computer_object->find("groups_id = '{$items_id}' " . " AND `is_deleted`='0' AND `is_template`='0'");
                 foreach ($computers as $computer) {
                     $computers_a_2[] = $computer['id'];
                 }
                 //merge two previous array and deduplicate entries
                 $computers = array_unique(array_merge($computers_a_1, $computers_a_2));
                 break;
             case 'PluginFusioninventoryDeployGroup':
                 $group = new PluginFusioninventoryDeployGroup();
                 $group->getFromDB($items_id);
                 switch ($group->getField('type')) {
                     case 'STATIC':
                         if ($this->definitionFiltered("PluginFusioninventoryDeployGroupStatic", $definitions_filter)) {
                             break;
                         }
                         $query = "SELECT items_id\n                     FROM glpi_plugin_fusioninventory_deploygroups_staticdatas\n                     WHERE groups_id = '{$items_id}'\n                     AND itemtype = 'Computer'";
                         $res = $DB->query($query);
                         while ($row = $DB->fetch_assoc($res)) {
                             $computers[] = $row['items_id'];
                         }
                         break;
                     case 'DYNAMIC':
                         if ($this->definitionFiltered("PluginFusioninventoryDeployGroupDynamic", $definitions_filter)) {
                             break;
                         }
                         //$definitions_filter is NULL = update by crontask !
                         if ($definitions_filter != NULL) {
                             $where = " AND `can_update_group`='1'";
                         } else {
                             $where = "";
                         }
                         $query = "SELECT fields_array\n                     FROM glpi_plugin_fusioninventory_deploygroups_dynamicdatas\n                     WHERE groups_id = '{$items_id}' {$where}\n                     LIMIT 1";
                         $res = $DB->query($query);
                         $row = $DB->fetch_assoc($res);
                         //No dynamic groups have been found : break
                         if ($DB->numrows($res) == 0) {
                             break;
                         }
                         if (isset($_GET)) {
                             $get_tmp = $_GET;
                         }
                         if (isset($_SESSION["glpisearchcount"]['Computer'])) {
                             unset($_SESSION["glpisearchcount"]['Computer']);
                         }
                         if (isset($_SESSION["glpisearchcount2"]['Computer'])) {
                             unset($_SESSION["glpisearchcount2"]['Computer']);
                         }
                         $_GET = importArrayFromDB($row['fields_array']);
                         $_GET["glpisearchcount"] = count($_GET['field']);
                         if (isset($_GET['field2'])) {
                             $_GET["glpisearchcount2"] = count($_GET['field2']);
                         }
                         $pfSearch = new PluginFusioninventorySearch();
                         Search::manageParams('Computer');
                         $glpilist_limit = $_SESSION['glpilist_limit'];
                         $_SESSION['glpilist_limit'] = 999999999;
                         $result = $pfSearch->constructSQL('Computer', $_GET);
                         $_SESSION['glpilist_limit'] = $glpilist_limit;
                         while ($data = $DB->fetch_array($result)) {
                             $computers[] = $data['id'];
                         }
                         if (count($get_tmp) > 0) {
                             $_GET = $get_tmp;
                         }
                         break;
                 }
                 break;
         }
     }
     //Remove duplicatas from array
     //We are using isset for faster processing than array_unique because we might have many
     //entries in this list.
     $tmp_computers = array();
     foreach ($computers as $computer) {
         if (!isset($tmp_computers[$computer])) {
             $tmp_computers[$computer] = 1;
         }
     }
     $computers = array_keys($tmp_computers);
     $c_input = array();
     $c_input['plugin_fusioninventory_taskjobs_id'] = $job->fields['id'];
     $c_input['state'] = 0;
     $c_input['plugin_fusioninventory_agents_id'] = 0;
     $c_input['execution_id'] = $task->fields['execution_id'];
     $package = new PluginFusioninventoryDeployPackage();
     foreach ($computers as $computer_id) {
         //Unique Id match taskjobstatuses for an agent(computer)
         foreach ($definitions as $definition) {
             $uniqid = uniqid();
             $package->getFromDB($definition['PluginFusioninventoryDeployPackage']);
             $c_input['state'] = 0;
             $c_input['itemtype'] = 'PluginFusioninventoryDeployPackage';
             $c_input['items_id'] = $package->fields['id'];
             $c_input['date'] = date("Y-m-d H:i:s");
             $c_input['uniqid'] = $uniqid;
             //get agent for this computer
             $agents_id = $agent->getAgentWithComputerid($computer_id);
             if ($agents_id === FALSE) {
                 $jobstates_id = $jobstate->add($c_input);
                 $jobstate->changeStatusFinish($jobstates_id, 0, '', 1, "No agent found for [[Computer::" . $computer_id . "]]", 0, 0);
             } else {
                 if ($agentmodule->isAgentCanDo('DEPLOY', $agents_id)) {
                     $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                     $jobstates_running = $jobstate->find(implode(" ", array("    `itemtype` = 'PluginFusioninventoryDeployPackage'", "AND `items_id` = " . $package->fields['id'], "AND `state` <> " . PluginFusioninventoryTaskjobstate::FINISHED, "AND `plugin_fusioninventory_agents_id` = " . $agents_id)));
                     if (count($jobstates_running) == 0) {
                         # Push the agent, in the stack of agent to awake
                         if ($communication == "push") {
                             $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                         }
                         $jobstates_id = $jobstate->add($c_input);
                         //Add log of taskjob
                         $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                         $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                         $taskvalid++;
                         $joblog->add($c_input);
                         unset($c_input['state']);
                         unset($c_input['plugin_fusioninventory_agents_id']);
                     }
                 }
             }
         }
     }
     if ($taskvalid > 0) {
         $job->fields['status'] = 1;
         $job->update($job->fields);
     } else {
         $job->reinitializeTaskjobs($job->fields['plugin_fusioninventory_tasks_id']);
     }
 }
コード例 #9
0
 function pre_deleteItem()
 {
     global $CFG_GLPI;
     //if task active, delete denied
     if ($this->getField('is_active') == 1) {
         Session::addMessageAfterRedirect(__('This task is active. delete denied', 'fusioninventory'));
         Html::redirect($CFG_GLPI["root_doc"] . "/plugins/fusinvdeploy/front/task.form.php?id=" . $this->getField('id'));
         return FALSE;
     }
     $task_id = $this->getField('id');
     $job = new PluginFusioninventoryTaskjob();
     $status = new PluginFusioninventoryTaskjobstate();
     $log = new PluginFusioninventoryTaskjoblog();
     // clean all sub-tables
     $a_taskjobs = $job->find("`plugin_fusioninventory_tasks_id`='{$task_id}'");
     foreach ($a_taskjobs as $a_taskjob) {
         $a_taskjobstatuss = $status->find("`plugin_fusioninventory_taskjobs_id`='" . $a_taskjob['id'] . "'");
         foreach ($a_taskjobstatuss as $a_taskjobstatus) {
             $a_taskjoblogs = $log->find("`plugin_fusioninventory_taskjobstates_id`='" . $a_taskjobstatus['id'] . "'");
             foreach ($a_taskjoblogs as $a_taskjoblog) {
                 $log->delete($a_taskjoblog, 1);
             }
             $status->delete($a_taskjobstatus, 1);
         }
         $job->delete($a_taskjob, 1);
     }
     return TRUE;
 }
コード例 #10
0
 /**
  * @test
  */
 public function getESXURLRootEntity()
 {
     global $DB;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $entities_id = 1;
     $agents_id = 1;
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $input = array('itemtype' => 'PluginFusioninventoryCredentialIp', 'plugin_fusioninventory_agents_id' => 1);
     $pfTaskjobstate->add($input);
     // Get answer
     $input = array('action' => 'getConfig', 'task' => array('ESX' => '1.0.0'), 'machineid' => 'toto-device');
     $response = PluginFusioninventoryCommunicationRest::communicate($input);
     $this->assertEquals('http://10.0.2.2/glpi085/plugins/fusioninventory/b/esx/', $response['schedule'][0]['remote'], 'Wrong URL');
 }
コード例 #11
0
 /**
  * @test
  */
 public function deleteTask()
 {
     global $DB;
     $pfTask = new PluginFusioninventoryTask();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $pfTaskjobState = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     //delete task
     $return = $pfTask->delete(array('id' => self::$tasks_id));
     $this->assertEquals(true, $return);
     //check deletion of job
     $jobs_found = $pfTaskjob->find("id = " . self::$taskjobs_id);
     $this->assertEquals(array(), $jobs_found);
     //check deletion of state
     $states_found = $pfTaskjobState->find("id = " . self::$taskjobstates_id);
     $this->assertEquals(array(), $states_found);
     //check deletion of log
     $logs_found = $pfTaskjoblog->find("id = " . self::$taskjobstates_id);
     $this->assertEquals(array(), $logs_found);
 }
コード例 #12
0
function plugin_fusioninventory_giveItem($type, $id, $data, $num)
{
    global $CFG_GLPI;
    $searchopt =& Search::getOptions($type);
    $table = $searchopt[$id]["table"];
    $field = $searchopt[$id]["field"];
    switch ($table . '.' . $field) {
        case "glpi_plugin_fusioninventory_taskjobs.status":
            $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
            return $pfTaskjobstate->stateTaskjob($data['raw']['id'], '200', 'htmlvar', 'simple');
            break;
        case "glpi_plugin_fusioninventory_agents.version":
            $array = importArrayFromDB($data['raw']['ITEM_' . $num]);
            $input = "";
            foreach ($array as $name => $version) {
                $input .= "<strong>" . $name . "</strong> : " . $version . "<br/>";
            }
            $input .= "*";
            $input = str_replace("<br/>*", "", $input);
            return $input;
            break;
        case "glpi_plugin_fusioninventory_credentials.itemtype":
            if ($label = PluginFusioninventoryCredential::getLabelByItemtype($data['raw']['ITEM_' . $num])) {
                return $label;
            } else {
                return '';
            }
            break;
        case 'glpi_plugin_fusioninventory_taskjoblogs.state':
            $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
            return $pfTaskjoblog->getDivState($data['raw']['ITEM_' . $num]);
            break;
        case 'glpi_plugin_fusioninventory_taskjoblogs.comment':
            $comment = $data['raw']['ITEM_' . $num];
            return PluginFusioninventoryTaskjoblog::convertComment($comment);
            break;
        case 'glpi_plugin_fusioninventory_taskjobstates.plugin_fusioninventory_agents_id':
            $pfAgent = new PluginFusioninventoryAgent();
            $pfAgent->getFromDB($data['raw']['ITEM_' . $num]);
            if (!isset($pfAgent->fields['name'])) {
                return NOT_AVAILABLE;
            }
            $itemtype = PluginFusioninventoryTaskjoblog::getStateItemtype($data['raw']['ITEM_0']);
            if ($itemtype == 'PluginFusioninventoryDeployPackage') {
                $computer = new Computer();
                $computer->getFromDB($pfAgent->fields['computers_id']);
                return $computer->getLink(1);
            }
            return $pfAgent->getLink(1);
            break;
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.ip':
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.mac':
            $array = importArrayFromDB($data['raw']['ITEM_' . $num]);
            return implode("<br/>", $array);
            break;
        case 'glpi_plugin_fusioninventory_ignoredimportdevices.method':
            $a_methods = PluginFusioninventoryStaticmisc::getmethods();
            foreach ($a_methods as $mdata) {
                if ($mdata['method'] == $data['raw']['ITEM_' . $num]) {
                    return $mdata['name'];
                }
            }
            break;
    }
    if ($table == "glpi_plugin_fusioninventory_agentmodules") {
        if ($type == 'Computer') {
            $pfAgentmodule = new PluginFusioninventoryAgentmodule();
            $a_modules = $pfAgentmodule->find("`modulename`='" . $field . "'");
            $data2 = current($a_modules);
            if ($table . "." . $field == "glpi_plugin_fusioninventory_agentmodules." . $data2['modulename']) {
                if (strstr($data['raw']["ITEM_" . $num . "_0"], '"' . $data['raw']["ITEM_" . $num . "_1"] . '"')) {
                    if ($data['raw']['ITEM_' . $num] == '0') {
                        return Dropdown::getYesNo(TRUE);
                    } else {
                        return Dropdown::getYesNo(FALSE);
                    }
                }
                return Dropdown::getYesNo($data['raw']['ITEM_' . $num]);
            }
        } else {
            $pfAgentmodule = new PluginFusioninventoryAgentmodule();
            $a_modules = $pfAgentmodule->find("`modulename`='" . $field . "'");
            foreach ($a_modules as $data2) {
                if ($table . "." . $field == "glpi_plugin_fusioninventory_agentmodules." . $data2['modulename']) {
                    if (strstr($data['raw']["ITEM_" . $num . "_0"], '"' . $data['raw']['id'] . '"')) {
                        if ($data['raw']['ITEM_' . $num] == 0) {
                            return Dropdown::getYesNo('1');
                        } else {
                            return Dropdown::getYesNo('0');
                        }
                    }
                    return Dropdown::getYesNo($data['raw']['ITEM_' . $num]);
                }
            }
        }
    }
    switch ($type) {
        case 'Computer':
            if ($table . '.' . $field == 'glpi_plugin_fusioninventory_networkports.id') {
                if (strstr($data['raw']["ITEM_{$num}"], "\$")) {
                    $split = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    $ports = array();
                    foreach ($split as $portconcat) {
                        $split2 = explode("....", $portconcat);
                        if (isset($split2[1])) {
                            $ports[] = $split2[1];
                        }
                    }
                    $out = implode("<br/>", $ports);
                    return $out;
                }
            }
            break;
            // * Networking List (front/networking.php)
        // * Networking List (front/networking.php)
        case 'NetworkEquipment':
            switch ($table . '.' . $field) {
            }
            break;
        case 'Printer':
            if ($table . '.' . $field == 'glpi_plugin_fusioninventory_networkequipments.name') {
                if (strstr($data['raw']["ITEM_{$num}"], "\$")) {
                    $split = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    $out = implode("<br/>", $split);
                    return $out;
                }
            }
            break;
            // * Authentification List (plugins/fusinvsnmp/front/configsecurity.php)
        // * Authentification List (plugins/fusinvsnmp/front/configsecurity.php)
        case 'PluginFusioninventoryConfigSecurity':
            switch ($table . '.' . $field) {
                // ** Hidden auth passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_configsecurities.auth_passphrase":
                    $out = "";
                    if (empty($data['raw']["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
                    // ** Hidden priv passphrase (SNMP v3)
                // ** Hidden priv passphrase (SNMP v3)
                case "glpi_plugin_fusioninventory_configsecurities.priv_passphrase":
                    $out = "";
                    if (empty($data['raw']["ITEM_{$num}"])) {
                    } else {
                        $out = "********";
                    }
                    return $out;
                    break;
            }
            break;
            // * Unknown mac addresses connectd on switch - report
            //   (plugins/fusinvsnmp/report/unknown_mac.php)
        // * Unknown mac addresses connectd on switch - report
        //   (plugins/fusinvsnmp/report/unknown_mac.php)
        case 'PluginFusioninventoryUnmanaged':
            switch ($table . '.' . $field) {
                // ** FusionInventory - switch
                case "glpi_plugin_fusioninventory_networkequipments.id":
                    $out = '';
                    $NetworkPort = new NetworkPort();
                    $list = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                    foreach ($list as $numtmp => $vartmp) {
                        $NetworkPort->getDeviceData($vartmp, 'PluginFusioninventoryUnmanaged');
                        $out .= "<a href=\"" . $CFG_GLPI["root_doc"] . "/";
                        $out .= "plugins/fusioninventory/front/unmanaged.form.php?id=" . $vartmp . "\">";
                        $out .= $NetworkPort->device_name;
                        if ($CFG_GLPI["view_ID"]) {
                            $out .= " (" . $vartmp . ")";
                        }
                        $out .= "</a><br/>";
                    }
                    return "<center>" . $out . "</center>";
                    break;
                    // ** FusionInventory - switch port
                // ** FusionInventory - switch port
                case "glpi_plugin_fusioninventory_networkports.id":
                    $out = '';
                    if (!empty($data['raw']["ITEM_{$num}"])) {
                        $list = explode("\$\$\$\$", $data['raw']["ITEM_{$num}"]);
                        $np = new NetworkPort();
                        foreach ($list as $numtmp => $vartmp) {
                            $np->getFromDB($vartmp);
                            $out .= "<a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=" . $vartmp . "'>";
                            $out .= $np->fields["name"] . "</a><br/>";
                        }
                    }
                    return "<center>" . $out . "</center>";
                    break;
                case "glpi_plugin_fusinvsnmp_unmanageds.type":
                    $out = '<center> ';
                    switch ($data['raw']["ITEM_{$num}"]) {
                        case COMPUTER_TYPE:
                            $out .= __('Computers');
                            break;
                        case NETWORKING_TYPE:
                            $out .= __('Networks');
                            break;
                        case PRINTER_TYPE:
                            $out .= __('Printers');
                            break;
                        case PERIPHERAL_TYPE:
                            $out .= __('Devices');
                            break;
                        case PHONE_TYPE:
                            $out .= __('Phones');
                            break;
                    }
                    $out .= '</center>';
                    return $out;
                    break;
            }
            break;
            // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php)
        // * Ports date connection - report (plugins/fusinvsnmp/report/ports_date_connections.php)
        case 'PluginFusioninventoryNetworkPort':
            switch ($table . '.' . $field) {
                // ** Name and link of networking device (switch)
                case "glpi_plugin_fusioninventory_networkports.id":
                    $query = "SELECT `glpi_networkequipments`.`name` AS `name`, `glpi_networkequipments`.`id` AS `id`\n                         FROM `glpi_networkequipments`\n                              LEFT JOIN `glpi_networkports`\n                                        ON `items_id` = `glpi_networkequipments`.`id`\n                              LEFT JOIN `glpi_plugin_fusioninventory_networkports`\n                                        ON `glpi_networkports`.`id`=`networkports_id`\n                         WHERE `glpi_plugin_fusioninventory_networkports`.`id`='" . $data['raw']["ITEM_{$num}"] . "'\n                         LIMIT 0, 1;";
                    $result = $DB->query($query);
                    $data2 = $DB->fetch_assoc($result);
                    $out = "<a href='" . $CFG_GLPI['root_doc'] . "/front/networking.form.php?id=" . $data2["id"] . "'>";
                    $out .= $data2["name"] . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Name and link of port of networking device (port of switch)
                // ** Name and link of port of networking device (port of switch)
                case "glpi_plugin_fusioninventory_networkports.networkports_id":
                    $NetworkPort = new NetworkPort();
                    $NetworkPort->getFromDB($data['raw']["ITEM_{$num}"]);
                    $name = "";
                    if (isset($NetworkPort->fields["name"])) {
                        $name = $NetworkPort->fields["name"];
                    }
                    $out = "<a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=" . $data['raw']["ITEM_{$num}"];
                    $out .= "'>" . $name . "</a>";
                    return "<center>" . $out . "</center>";
                    break;
                    // ** Location of switch
                // ** Location of switch
                case "glpi_locations.id":
                    $out = Dropdown::getDropdownName("glpi_locations", $data['raw']["ITEM_{$num}"]);
                    return "<center>" . $out . "</center>";
                    break;
            }
            break;
            // * range IP list (plugins/fusinvsnmp/front/iprange.php)
        // * range IP list (plugins/fusinvsnmp/front/iprange.php)
        case 'PluginFusioninventoryIPRange':
            switch ($table . '.' . $field) {
                // ** Display entity name
                case "glpi_entities.name":
                    if ($data['raw']["ITEM_{$num}"] == '') {
                        $out = Dropdown::getDropdownName("glpi_entities", $data['raw']["ITEM_{$num}"]);
                        return "<center>" . $out . "</center>";
                    }
                    break;
            }
            break;
        case 'PluginFusioninventoryNetworkPortLog':
            switch ($table . '.' . $field) {
                // ** Display switch and Port
                case "glpi_networkports.id":
                    $Array_device = PluginFusioninventoryNetworkPort::getUniqueObjectfieldsByportID($data['raw']["ITEM_{$num}"]);
                    $item = new $Array_device["itemtype"]();
                    $item->getFromDB($Array_device["items_id"]);
                    $out = "<div align='center'>" . $item->getLink(1);
                    $query = "SELECT *\n                         FROM `glpi_networkports`\n                         WHERE `id`='" . $data['raw']["ITEM_{$num}"] . "';";
                    $result = $DB->query($query);
                    if ($DB->numrows($result) != "0") {
                        $out .= "<br/><a href='" . $CFG_GLPI['root_doc'] . "/front/networkport.form.php?id=";
                        $out .= $data['raw']["ITEM_{$num}"] . "'>" . $DB->result($result, 0, "name") . "</a>";
                    }
                    $out .= "</td>";
                    return $out;
                    break;
                    // ** Display GLPI field of device
                // ** Display GLPI field of device
                case "glpi_plugin_fusinvsnmp_networkportlogs.field":
                    //               $out = $FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$data['raw']["ITEM_$num"]]['name'];
                    $out = '';
                    $map = new PluginFusioninventoryMapping();
                    $mapfields = $map->get('NetworkEquipment', $data['raw']["ITEM_{$num}"]);
                    if ($mapfields != FALSE) {
                        $out = _get('_LANG[\'plugin_fusinvsnmp\'][\'mapping\'][$mapfields["locale"]]');
                    }
                    return $out;
                    break;
                    // ** Display Old Value (before changement of value)
                // ** Display Old Value (before changement of value)
                case "glpi_plugin_fusinvsnmp_networkportlogs.old_value":
                    // TODO ADD LINK TO DEVICE
                    if (substr_count($data['raw']["ITEM_{$num}"], ":") == 5 && empty($data['raw']["ITEM_3"])) {
                        return "<center><b>" . $data['raw']["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
                    // ** Display New Value (new value modified)
                // ** Display New Value (new value modified)
                case "glpi_plugin_fusinvsnmp_networkportlogs.new_value":
                    if (substr_count($data['raw']["ITEM_{$num}"], ":") == 5 && empty($data['raw']["ITEM_3"])) {
                        return "<center><b>" . $data['raw']["ITEM_{$num}"] . "</b></center>";
                    }
                    break;
            }
            break;
        case "PluginFusioninventoryPrinterLog":
            switch ($table . '.' . $field) {
                case 'glpi_printers.name':
                    // Search pages in printer history to limit SQL queries
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_start'])) {
                        unset($_SESSION['glpi_plugin_fusioninventory_history_start']);
                    }
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_end'])) {
                        unset($_SESSION['glpi_plugin_fusioninventory_history_end']);
                    }
                    if (isset($_SESSION['glpi_plugin_fusioninventory_date_start']) and isset($_SESSION['glpi_plugin_fusioninventory_date_end'])) {
                        $query = "SELECT * FROM `glpi_plugin_fusioninventory_printerlogs`\n                     WHERE `printers_id`='" . $data['raw']['ITEM_0_2'] . "'\n                        AND `date`>= '" . $_SESSION['glpi_plugin_fusioninventory_date_start'] . "'\n                        AND `date`<= '" . $_SESSION['glpi_plugin_fusioninventory_date_end'] . " 23:59:59'\n                     ORDER BY date asc\n                     LIMIT 1";
                        $result = $DB->query($query);
                        while ($data2 = $DB->fetch_array($result)) {
                            $_SESSION['glpi_plugin_fusioninventory_history_start'] = $data2;
                        }
                        $query = "SELECT * FROM `glpi_plugin_fusioninventory_printerlogs`\n                     WHERE `printers_id`='" . $data['raw']['ITEM_0_2'] . "'\n                        AND `date`>= '" . $_SESSION['glpi_plugin_fusioninventory_date_start'] . "'\n                        AND `date`<= '" . $_SESSION['glpi_plugin_fusioninventory_date_end'] . " 23:59:59'\n                     ORDER BY date desc\n                     LIMIT 1";
                        $result = $DB->query($query);
                        while ($data2 = $DB->fetch_array($result)) {
                            $_SESSION['glpi_plugin_fusioninventory_history_end'] = $data2;
                        }
                    }
                    return "";
                    break;
            }
            switch ($table) {
                case 'glpi_plugin_fusioninventory_printerlogs':
                    if (isset($_SESSION['glpi_plugin_fusioninventory_history_start'][$field]) and isset($_SESSION['glpi_plugin_fusioninventory_history_end'][$field])) {
                        $counter_start = $_SESSION['glpi_plugin_fusioninventory_history_start'][$field];
                        $counter_end = $_SESSION['glpi_plugin_fusioninventory_history_end'][$field];
                        if ($_SESSION['glpi_plugin_fusioninventory_date_start'] == "1970-01-01") {
                            $counter_start = 0;
                        }
                        $number = $counter_end - $counter_start;
                        if ($number == '0') {
                            return '-';
                        } else {
                            return $number;
                        }
                    } else {
                        return '-';
                    }
                    break;
            }
            break;
    }
    return "";
}
コード例 #13
0
 /**
  * Update agent status for a task
  *
  * @param params parameters from the GET HTTP request
  *
  * @return nothing
  */
 static function updateLog($params = array())
 {
     global $DB;
     $p = array();
     $p['machineid'] = '';
     //DeviceId
     $p['uuid'] = '';
     //Task uuid
     $p['msg'] = 'ok';
     //status of the task
     $p['code'] = '';
     //current step of processing
     foreach ($params as $key => $value) {
         $p[$key] = $value;
     }
     //Get the agent ID by its deviceid
     $agent = PluginFusioninventoryAgent::getByDeviceID($p['machineid']);
     //No need to continue since the requested agent doesn't exists in database
     if ($agent === FALSE) {
         self::sendError();
         return;
     }
     //Get task job status : identifier is the uuid given by the agent
     $taskjobstates = $DB->request(getTableForItemType('PluginFusioninventoryTaskjobstate'), "`uniqid`='" . $p['uuid'] . "'");
     $taskjobstate = new PluginFusioninventoryTaskjobstate();
     foreach ($taskjobstates as $jobstate) {
         $taskjobstate->getFromDB($jobstate['id']);
         //Get taskjoblog associated
         $taskjoblog = new PluginFusioninventoryTaskjobLog();
         $taskjoblog->getFromDBByQuery("WHERE `plugin_fusioninventory_taskjobstates_id`=" . $jobstate['id']);
         switch ($p['code']) {
             case 'running':
                 $taskjoblog->addTaskjoblog($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], PluginFusioninventoryTaskjoblog::TASK_RUNNING, $p['msg']);
                 break;
             case 'ok':
                 $taskjobstate->changeStatusFinish($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], 0, $p['msg']);
                 break;
             case 'ko':
                 $taskjobstate->changeStatusFinish($taskjobstate->fields['id'], $taskjobstate->fields['items_id'], $taskjobstate->fields['itemtype'], 1, $p['msg']);
                 break;
         }
     }
     self::sendOk();
 }
コード例 #14
0
 function prepareRun($taskjobs_id)
 {
     global $DB;
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $agent = new PluginFusioninventoryAgent();
     $uniqid = uniqid();
     $job->getFromDB($taskjobs_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     $actions = importArrayFromDB($job->fields['action']);
     $definitions = importArrayFromDB($job->fields['definition']);
     $taskvalid = 0;
     $computers = array();
     foreach ($actions as $action) {
         $itemtype = key($action);
         $items_id = current($action);
         switch ($itemtype) {
             case 'Computer':
                 $computers[] = $items_id;
                 break;
             case 'Group':
                 $computer_object = new Computer();
                 //find computers by user associated with this group
                 $group_users = new Group_User();
                 $group = new Group();
                 $group->getFromDB($items_id);
                 $members = array();
                 $computers_a_1 = array();
                 $computers_a_2 = array();
                 //array_keys($group_users->find("groups_id = '$items_id'"));
                 $members = $group_users->getGroupUsers($items_id);
                 foreach ($members as $member) {
                     $computers = $computer_object->find("users_id = '{$member['id']}'");
                     foreach ($computers as $computer) {
                         $computers_a_1[] = $computer['id'];
                     }
                 }
                 //find computers directly associated with this group
                 $computers = $computer_object->find("groups_id = '{$items_id}'");
                 foreach ($computers as $computer) {
                     $computers_a_2[] = $computer['id'];
                 }
                 //merge two previous array and deduplicate entries
                 $computers = array_unique(array_merge($computers_a_1, $computers_a_2));
                 break;
             case 'PluginFusioninventoryDeployGroup':
                 $group = new PluginFusioninventoryDeployGroup();
                 $group->getFromDB($items_id);
                 switch ($group->getField('type')) {
                     case 'STATIC':
                         $query = "SELECT items_id\n                     FROM glpi_plugin_fusioninventory_deploygroups_staticdatas\n                     WHERE groups_id = '{$items_id}'\n                     AND itemtype = 'Computer'";
                         $res = $DB->query($query);
                         while ($row = $DB->fetch_assoc($res)) {
                             $computers[] = $row['items_id'];
                         }
                         break;
                     case 'DYNAMIC':
                         $query = "SELECT fields_array\n                     FROM glpi_plugin_fusioninventory_deploygroups_dynamicdatas\n                     WHERE groups_id = '{$items_id}'\n                     LIMIT 1";
                         $res = $DB->query($query);
                         $row = $DB->fetch_assoc($res);
                         if (isset($_GET)) {
                             $get_tmp = $_GET;
                         }
                         if (isset($_SESSION["glpisearchcount"]['Computer'])) {
                             unset($_SESSION["glpisearchcount"]['Computer']);
                         }
                         if (isset($_SESSION["glpisearchcount2"]['Computer'])) {
                             unset($_SESSION["glpisearchcount2"]['Computer']);
                         }
                         $_GET = importArrayFromDB($row['fields_array']);
                         $_GET["glpisearchcount"] = count($_GET['field']);
                         if (isset($_GET['field2'])) {
                             $_GET["glpisearchcount2"] = count($_GET['field2']);
                         }
                         $pfSearch = new PluginFusioninventorySearch();
                         Search::manageGetValues('Computer');
                         $glpilist_limit = $_SESSION['glpilist_limit'];
                         $_SESSION['glpilist_limit'] = 999999999;
                         $result = $pfSearch->constructSQL('Computer', $_GET);
                         $_SESSION['glpilist_limit'] = $glpilist_limit;
                         while ($data = $DB->fetch_array($result)) {
                             $computers[] = $data['id'];
                         }
                         if (count($get_tmp) > 0) {
                             $_GET = $get_tmp;
                         }
                         break;
                 }
                 break;
         }
     }
     $c_input = array();
     $c_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
     $c_input['state'] = 0;
     $c_input['plugin_fusioninventory_agents_id'] = 0;
     $c_input['execution_id'] = $task->fields['execution_id'];
     $pfCollect = new PluginFusioninventoryCollect();
     foreach ($computers as $computer_id) {
         //get agent if for this computer
         $agents_id = $agent->getAgentWithComputerid($computer_id);
         if ($agents_id === FALSE) {
             $jobstates_id = $jobstate->add($c_input);
             $jobstate->changeStatusFinish($jobstates_id, 0, '', 1, "No agent found for [[Computer::" . $computer_id . "]]", 0, 0);
         } else {
             foreach ($definitions as $definition) {
                 $pfCollect->getFromDB($definition['PluginFusioninventoryCollect']);
                 switch ($pfCollect->fields['type']) {
                     case 'registry':
                         // get all registry
                         $pfCollect_Registry = new PluginFusioninventoryCollect_Registry();
                         $a_registries = $pfCollect_Registry->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_registries as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_Registry';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                     case 'wmi':
                         // get all wmi
                         $pfCollect_Wmi = new PluginFusioninventoryCollect_Wmi();
                         $a_wmies = $pfCollect_Wmi->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_wmies as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_Wmi';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                     case 'file':
                         // find files
                         $pfCollect_File = new PluginFusioninventoryCollect_File();
                         $a_files = $pfCollect_File->find("`plugin_fusioninventory_collects_id`='" . $pfCollect->fields['id'] . "'");
                         foreach ($a_files as $data_r) {
                             $uniqid = uniqid();
                             $c_input['state'] = 0;
                             $c_input['itemtype'] = 'PluginFusioninventoryCollect_File';
                             $c_input['items_id'] = $data_r['id'];
                             $c_input['date'] = date("Y-m-d H:i:s");
                             $c_input['uniqid'] = $uniqid;
                             $c_input['plugin_fusioninventory_agents_id'] = $agents_id;
                             # Push the agent, in the stack of agent to awake
                             if ($communication == "push") {
                                 $_SESSION['glpi_plugin_fusioninventory']['agents'][$agents_id] = 1;
                             }
                             $jobstates_id = $jobstate->add($c_input);
                             //Add log of taskjob
                             $c_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                             $c_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                             $taskvalid++;
                             $joblog->add($c_input);
                         }
                         break;
                 }
             }
         }
     }
     if ($taskvalid > 0) {
         $job->fields['status'] = 1;
         $job->update($job->fields);
     } else {
         $job->reinitializeTaskjobs($job->fields['plugin_fusioninventory_tasks_id']);
     }
 }
 function storeTempFilesFound($taskjobstates_id, $a_values)
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjobstate->getFromDB($taskjobstates_id);
     $a_specificity = array();
     if ($pfTaskjobstate->fields['specificity'] != '') {
         $a_specificity = importArrayFromDB($pfTaskjobstate->fields['specificity']);
     }
     unset($a_values['_cpt']);
     $a_specificity[] = $a_values;
     $input = array();
     $input['id'] = $pfTaskjobstate->fields['id'];
     $input['specificity'] = exportArrayToDB($a_specificity);
     $pfTaskjobstate->update($input);
 }
コード例 #16
0
 /**
  * Cron for clean taskjob
  *
  * @return nothing
  */
 static function cronCleantaskjob()
 {
     global $DB;
     $config = new PluginFusioninventoryConfig();
     $retentiontime = $config->getValue('delete_task');
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $sql = "SELECT * FROM `glpi_plugin_fusioninventory_taskjoblogs`\n         WHERE  `date` < date_add(now(), interval -" . $retentiontime . " day)\n         GROUP BY `plugin_fusioninventory_taskjobstates_id`";
     $result = $DB->query($sql);
     if ($result) {
         while ($data = $DB->fetch_array($result)) {
             $pfTaskjobstate->getFromDB($data['plugin_fusioninventory_taskjobstates_id']);
             $pfTaskjobstate->delete($pfTaskjobstate->fields, 1);
             $sql_delete = "DELETE FROM `glpi_plugin_fusioninventory_taskjoblogs`\n               WHERE `plugin_fusioninventory_taskjobstates_id` = '" . $data['plugin_fusioninventory_taskjobstates_id'] . "'";
             $DB->query($sql_delete);
         }
     }
 }
コード例 #17
0
 /**
  * Get all devices and put in taskjobstate each task for
  * each device for each agent
  *
  * @param type $taskjobs_id id of taskjob esx
  *
  * @return uniqid value
  */
 function prepareRun($taskjobs_id)
 {
     $task = new PluginFusioninventoryTask();
     $job = new PluginFusioninventoryTaskjob();
     $joblog = new PluginFusioninventoryTaskjoblog();
     $jobstate = new PluginFusioninventoryTaskjobstate();
     $uniqid = uniqid();
     $job->getFromDB($taskjobs_id);
     $task->getFromDB($job->fields['plugin_fusioninventory_tasks_id']);
     $communication = $task->fields['communication'];
     //list all agents
     $agent_actions = importArrayFromDB($job->fields['action']);
     $task_definitions = importArrayFromDB($job->fields['definition']);
     $agent_actionslist = array();
     foreach ($agent_actions as $targets) {
         foreach ($targets as $itemtype => $items_id) {
             $item = new $itemtype();
             // Detect if agent exists
             if ($item->getFromDB($items_id)) {
                 $agent_actionslist[$items_id] = 1;
             }
         }
     }
     // *** Add jobstate
     if (empty($agent_actionslist)) {
         $a_input = array();
         $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
         $a_input['state'] = 0;
         $a_input['plugin_fusioninventory_agents_id'] = 0;
         $a_input['uniqid'] = $uniqid;
         $a_input['execution_id'] = $task->fields['execution_id'];
         foreach ($task_definitions as $task_definition) {
             foreach ($task_definition as $task_itemtype => $task_items_id) {
                 $a_input['itemtype'] = $task_itemtype;
                 $a_input['items_id'] = $task_items_id;
                 $jobstates_id = $jobstate->add($a_input);
                 //Add log of taskjob
                 $a_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                 $a_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                 $a_input['date'] = date("Y-m-d H:i:s");
                 $joblog->add($a_input);
                 $jobstate->changeStatusFinish($jobstates_id, 0, 'PluginFusioninventoryInventoryComputerESX', 1, "Unable to find agent to run this job");
             }
         }
         $job->update($job->fields);
     } else {
         foreach ($agent_actions as $targets) {
             foreach ($targets as $items_id) {
                 if ($communication == "push") {
                     $_SESSION['glpi_plugin_fusioninventory']['agents'][$items_id] = 1;
                 }
                 foreach ($task_definitions as $task_definition) {
                     foreach ($task_definition as $task_itemtype => $task_items_id) {
                         $a_input = array();
                         $a_input['plugin_fusioninventory_taskjobs_id'] = $taskjobs_id;
                         $a_input['state'] = 0;
                         $a_input['plugin_fusioninventory_agents_id'] = $items_id;
                         $a_input['itemtype'] = $task_itemtype;
                         $a_input['items_id'] = $task_items_id;
                         $a_input['uniqid'] = $uniqid;
                         $a_input['date'] = date("Y-m-d H:i:s");
                         $a_input['execution_id'] = $task->fields['execution_id'];
                         $jobstates_id = $jobstate->add($a_input);
                         //Add log of taskjob
                         $a_input['plugin_fusioninventory_taskjobstates_id'] = $jobstates_id;
                         $a_input['state'] = PluginFusioninventoryTaskjoblog::TASK_PREPARED;
                         $joblog->add($a_input);
                         unset($a_input['state']);
                     }
                 }
             }
         }
         $job->fields['status'] = 1;
         $job->update($job->fields);
     }
     return $uniqid;
 }
コード例 #18
0
 /**
  *  When agent contact server, this function send datas to agent
  */
 function run($jobstate)
 {
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $NetworkPort = new NetworkPort();
     $sxml_option = $this->message->addChild('OPTION');
     $sxml_option->addChild('NAME', 'WAKEONLAN');
     $changestate = 0;
     //      foreach ($taskjobstates as $jobstate) {
     $data = $jobstate->fields;
     $a_networkPort = $NetworkPort->find("`itemtype`='Computer' AND `items_id`='" . $data['items_id'] . "' ");
     $computerip = 0;
     foreach ($a_networkPort as $datanetwork) {
         //if ($datanetwork['ip'] != "127.0.0.1") {
         if ($datanetwork['mac'] != '') {
             $computerip++;
             $sxml_param = $sxml_option->addChild('PARAM');
             $sxml_param->addAttribute('MAC', $datanetwork['mac']);
             //$sxml_param->addAttribute('IP', $datanetwork['ip']);
             if ($changestate == '0') {
                 $pfTaskjobstate->changeStatus($data['id'], 1);
                 $pfTaskjoblog->addTaskjoblog($data['id'], '0', 'Computer', '1', '');
                 $changestate = $pfTaskjobstate->fields['id'];
             } else {
                 $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, "Merged with " . $changestate);
             }
             // Update taskjobstate (state = 3 : finish); Because we haven't return of agent on this action
             $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 0, 'WakeOnLan have not return state', 1);
         }
         //}
     }
     if ($computerip == '0') {
         $pfTaskjobstate->changeStatusFinish($data['id'], $data['items_id'], $data['itemtype'], 1, "No IP found on the computer");
     }
     //}
     return $this->message;
 }
コード例 #19
0
 function run($jobstate)
 {
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $pfIPRange = new PluginFusioninventoryIPRange();
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     $pfToolbox = new PluginFusioninventoryToolbox();
     $pfAgent->getFromDB($jobstate->fields['plugin_fusioninventory_agents_id']);
     $sxml_option = $this->message->addChild('OPTION');
     $sxml_option->addChild('NAME', 'NETDISCOVERY');
     $a_versions = importArrayFromDB($pfAgent->fields["version"]);
     // * Disabled by David Durieux, I think it's not required now * //
     //      if (((isset($a_versions["NETWORKDISCOVERY"])) AND ($a_versions["NETWORKDISCOVERY"] >= 1.3))
     //              OR !isset($a_versions["NETWORKDISCOVERY"])) {
     //         if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml")) {
     //            PluginFusioninventorySnmpmodelImportExport::exportDictionnaryFile(FALSE);
     //         }
     //         $sxml_option->addChild('DICOHASH',
     //                                md5_file(GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml"));
     //      }
     //      if (($pfAgent->fields["senddico"] == "1")) {
     //
     //         if (((isset($a_versions["NETWORKDISCOVERY"]))
     //                 AND ($a_versions["NETWORKDISCOVERY"] >= 1.3))) {
     //
     //            $sxml_option->addChild('DICO',
     //                                   file_get_contents(
     //                                           GLPI_PLUGIN_DOC_DIR."/fusioninventory/discovery.xml"));
     //         }
     //         $input = array();
     //         $input['id'] = $pfAgent->fields['id'];
     //         $input["senddico"] = "0";
     //         $pfAgent->update($input);
     //      }
     $sxml_param = $sxml_option->addChild('PARAM');
     $sxml_param->addAttribute('THREADS_DISCOVERY', $pfAgent->fields["threads_networkdiscovery"]);
     $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkdiscovery"]);
     $sxml_param->addAttribute('PID', $jobstate->fields['id']);
     $changestate = 0;
     //foreach ($a_Taskjobstates as $taskjobstate) {
     $taskjobstatedatas = $jobstate->fields;
     $sxml_rangeip = $sxml_option->addChild('RANGEIP');
     $pfTaskjob->getFromDB($taskjobstatedatas['plugin_fusioninventory_taskjobs_id']);
     $pfTaskjobstate->getFromDB($taskjobstatedatas['id']);
     $pfIPRange->getFromDB($taskjobstatedatas['items_id']);
     $sxml_rangeip->addAttribute('ID', $pfIPRange->fields['id']);
     if (!is_null($pfTaskjobstate->fields['specificity'])) {
         $a_split = explode("-", $pfTaskjobstate->fields['specificity']);
         $first_ip = $pfIPRange->getIp2long($pfIPRange->fields["ip_start"]);
         $last_ip = long2ip($first_ip + $a_split[1]);
         $first_ip = long2ip($first_ip + $a_split[0]);
         if ($first_ip != '0.0.0.0' && $last_ip != '0.0.0.0') {
             $sxml_rangeip->addAttribute('IPSTART', $first_ip);
             $sxml_rangeip->addAttribute('IPEND', $last_ip);
         }
     } else {
         $sxml_rangeip->addAttribute('IPSTART', $pfIPRange->fields["ip_start"]);
         $sxml_rangeip->addAttribute('IPEND', $pfIPRange->fields["ip_end"]);
     }
     $sxml_rangeip->addAttribute('ENTITY', $pfIPRange->fields["entities_id"]);
     if ($changestate == '0') {
         $pfTaskjobstate->changeStatus($pfTaskjobstate->fields['id'], 1);
         $pfTaskjoblog->addTaskjoblog($pfTaskjobstate->fields['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkdiscovery"] . ' threads', $pfAgent->fields["timeout_networkdiscovery"] . ' timeout');
         $changestate = $pfTaskjobstate->fields['id'];
     } else {
         $pfTaskjobstate->changeStatusFinish($pfTaskjobstate->fields['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate);
     }
     //}
     $pfIPRange_ConfigSecurity = new PluginFusioninventoryIPRange_ConfigSecurity();
     $a_auths = $pfIPRange_ConfigSecurity->find("`plugin_fusioninventory_ipranges_id`='" . $pfIPRange->fields['id'] . "'", "rank");
     foreach ($a_auths as $dataAuth) {
         $pfToolbox->addAuth($sxml_option, $dataAuth['plugin_fusioninventory_configsecurities_id']);
     }
     return $this->message;
 }
コード例 #20
0
 function run($jobstate)
 {
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $pfConfigSecurity = new PluginFusioninventoryConfigSecurity();
     $pfToolbox = new PluginFusioninventoryToolbox();
     $current = $jobstate;
     $pfAgent->getFromDB($current->fields['plugin_fusioninventory_agents_id']);
     $ip = current(PluginFusioninventoryToolbox::getIPforDevice($jobstate->fields['itemtype'], $jobstate->fields['items_id']));
     if ($ip == '') {
         $pfTaskjobstate->changeStatusFinish($jobstate->fields['id'], $jobstate->fields['items_id'], $jobstate->fields['itemtype'], 1, "Device have no ip");
     } else {
         $sxml_option = $this->message->addChild('OPTION');
         $sxml_option->addChild('NAME', 'SNMPQUERY');
         $sxml_param = $sxml_option->addChild('PARAM');
         $sxml_param->addAttribute('THREADS_QUERY', $pfAgent->fields["threads_networkinventory"]);
         $sxml_param->addAttribute('TIMEOUT', $pfAgent->fields["timeout_networkinventory"]);
         $sxml_param->addAttribute('PID', $current->fields['id']);
         $changestate = 0;
         $taskjobstatedatas = $jobstate->fields;
         $sxml_device = $sxml_option->addChild('DEVICE');
         $a_extended = array('plugin_fusioninventory_configsecurities_id' => 0);
         if ($jobstate->fields['itemtype'] == 'Printer') {
             $sxml_device->addAttribute('TYPE', 'PRINTER');
             $pfPrinter = new PluginFusioninventoryPrinter();
             $a_extended = current($pfPrinter->find("`printers_id`='" . $jobstate->fields['items_id'] . "'", '', 1));
         } else {
             if ($jobstate->fields['itemtype'] == 'NetworkEquipment') {
                 $sxml_device->addAttribute('TYPE', 'NETWORKING');
                 $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment();
                 $a_extended = current($pfNetworkEquipment->find("`networkequipments_id`='" . $jobstate->fields['items_id'] . "'", '', 1));
             }
         }
         $sxml_device->addAttribute('ID', $jobstate->fields['items_id']);
         $sxml_device->addAttribute('IP', $ip);
         $sxml_device->addAttribute('AUTHSNMP_ID', $a_extended['plugin_fusioninventory_configsecurities_id']);
         if ($changestate == '0') {
             $pfTaskjobstate->changeStatus($taskjobstatedatas['id'], 1);
             $pfTaskjoblog->addTaskjoblog($taskjobstatedatas['id'], '0', 'PluginFusioninventoryAgent', '1', $pfAgent->fields["threads_networkinventory"] . ' threads', $pfAgent->fields["timeout_networkinventory"] . ' timeout');
             $changestate = $pfTaskjobstate->fields['id'];
         } else {
             $pfTaskjobstate->changeStatusFinish($taskjobstatedatas['id'], $taskjobstatedatas['items_id'], $taskjobstatedatas['itemtype'], 0, "Merged with " . $changestate);
         }
         $snmpauthlist = $pfConfigSecurity->find();
         if (count($snmpauthlist)) {
             foreach ($snmpauthlist as $snmpauth) {
                 $pfToolbox->addAuth($sxml_option, $snmpauth['id']);
             }
         }
     }
     return $this->message;
 }
コード例 #21
0
                             $a_input['itemtype'] = 'PluginFusioninventoryAgent';
                             $a_input['date'] = date("Y-m-d H:i:s");
                             $a_input['comment'] = '';
                             $a_input['state'] = PluginFusioninventoryTaskjoblog::TASK_STARTED;
                             $pfTaskjoblog->add($a_input);
                         }
                     }
                 }
             }
         }
     }
     break;
 case 'setAnswer':
     // example
     // ?action=setAnswer&InformationSource=0x00000000&BIOSVersion=VirtualBox&SystemManufacturer=innotek%20GmbH&uuid=fepjhoug56743h&SystemProductName=VirtualBox&BIOSReleaseDate=12%2F01%2F2006
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfAgent = new PluginFusioninventoryAgent();
     $jobstate = current($pfTaskjobstate->find("`uniqid`='" . $_GET['uuid'] . "'\n            AND `state`!='" . PluginFusioninventoryTaskjobstate::FINISHED . "'", '', 1));
     if (isset($jobstate['plugin_fusioninventory_agents_id'])) {
         $pfAgent->getFromDB($jobstate['plugin_fusioninventory_agents_id']);
         $computers_id = $pfAgent->fields['computers_id'];
         $a_values = $_GET;
         unset($a_values['action']);
         unset($a_values['uuid']);
         switch ($jobstate['itemtype']) {
             case 'PluginFusioninventoryCollect_Registry':
                 // update registry content
                 $pfCRC = new PluginFusioninventoryCollect_Registry_Content();
                 $pfCRC->updateComputer($computers_id, $a_values, $jobstate['items_id']);
                 $pfTaskjobstate->changeStatus($jobstate['id'], PluginFusioninventoryTaskjobstate::AGENT_HAS_SENT_DATA);
                 if (isset($a_values['_cpt']) && $a_values['_cpt'] == 0) {
コード例 #22
-1
 function display($options = array())
 {
     global $DB, $CFG_GLPI;
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $pfStateInventory = new PluginFusioninventoryStateInventory();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $start = 0;
     if (isset($_REQUEST["start"])) {
         $start = $_REQUEST["start"];
     }
     // Total Number of events
     $querycount = "SELECT count(*) AS cpt FROM `glpi_plugin_fusioninventory_taskjobstates`\n         LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n            ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n         WHERE `method` = 'networkdiscovery'\n         GROUP BY `uniqid`\n         ORDER BY `uniqid` DESC ";
     $resultcount = $DB->query($querycount);
     $number = $DB->numrows($resultcount);
     // Display the pager
     Html::printPager($start, $number, $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/stateinventory.php", '');
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Unique id', 'fusioninventory') . "</th>";
     echo "<th>" . __('Task job', 'fusioninventory') . "</th>";
     echo "<th>" . __('Agent', 'fusioninventory') . "</th>";
     echo "<th>" . __('Status') . "</th>";
     echo "<th>" . __('Starting date', 'fusioninventory') . "</th>";
     echo "<th>" . __('Ending date', 'fusioninventory') . "</th>";
     echo "<th>" . __('Total duration') . "</th>";
     echo "<th>" . __('Threads number', 'fusioninventory') . "</th>";
     echo "<th>" . __('Total discovery devices', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices not imported', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices linked', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices imported', 'fusioninventory') . "</th>";
     echo "</tr>";
     $sql = "SELECT `glpi_plugin_fusioninventory_taskjobstates`.*\n            FROM `glpi_plugin_fusioninventory_taskjobstates`\n         LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n            ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n         WHERE `method` = 'networkdiscovery'\n         GROUP BY `uniqid`\n         ORDER BY `uniqid` DESC\n         LIMIT " . intval($start) . ", " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($sql);
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . $data['uniqid'] . "</td>";
         $pfTaskjob->getFromDB($data['plugin_fusioninventory_taskjobs_id']);
         echo "<td>" . $pfTaskjob->getLink() . "</td>";
         $pfAgent->getFromDB($data['plugin_fusioninventory_agents_id']);
         echo "<td>" . $pfAgent->getLink(1) . "</td>";
         $nb_found = 0;
         $nb_threads = 0;
         $start_date = "";
         $end_date = "";
         $notimporteddevices = 0;
         $updateddevices = 0;
         $createddevices = 0;
         $a_taskjobstates = $pfTaskjobstate->find("`uniqid`='" . $data['uniqid'] . "'");
         foreach ($a_taskjobstates as $datastate) {
             $a_taskjoblog = $pfTaskjoblog->find("`plugin_fusioninventory_taskjobstates_id`='" . $datastate['id'] . "'");
             foreach ($a_taskjoblog as $taskjoblog) {
                 if (strstr($taskjoblog['comment'], " ==devicesfound==")) {
                     $nb_found += str_replace(" ==devicesfound==", "", $taskjoblog['comment']);
                 } else {
                     if (strstr($taskjoblog['comment'], "==importdenied==")) {
                         $notimporteddevices++;
                     } else {
                         if (strstr($taskjoblog['comment'], "==updatetheitem==")) {
                             $updateddevices++;
                         } else {
                             if (strstr($taskjoblog['comment'], "==addtheitem==")) {
                                 $createddevices++;
                             } else {
                                 if ($taskjoblog['state'] == "1") {
                                     $nb_threads = str_replace(" threads", "", $taskjoblog['comment']);
                                     $start_date = $taskjoblog['date'];
                                 }
                             }
                         }
                     }
                 }
                 if ($taskjoblog['state'] == "2" or $taskjoblog['state'] == "3" or $taskjoblog['state'] == "4" or $taskjoblog['state'] == "5") {
                     if (!strstr($taskjoblog['comment'], 'Merged with ')) {
                         $end_date = $taskjoblog['date'];
                     }
                 }
             }
         }
         // State
         echo "<td>";
         switch ($data['state']) {
             case 0:
                 echo __('Prepared', 'fusioninventory');
                 break;
             case 1:
             case 2:
                 echo __('Started', 'fusioninventory');
                 break;
             case 3:
                 echo __('Finished tasks', 'fusioninventory');
                 break;
         }
         echo "</td>";
         echo "<td>" . Html::convDateTime($start_date) . "</td>";
         echo "<td>" . Html::convDateTime($end_date) . "</td>";
         if ($end_date == '') {
             $end_date = date("Y-m-d H:i:s");
         }
         if ($start_date == '') {
             echo "<td>-</td>";
         } else {
             $interval = '';
             if (phpversion() >= 5.3) {
                 $date1 = new DateTime($start_date);
                 $date2 = new DateTime($end_date);
                 $interval = $date1->diff($date2);
                 $display_date = '';
                 if ($interval->h > 0) {
                     $display_date .= $interval->h . "h ";
                 } else {
                     if ($interval->i > 0) {
                         $display_date .= $interval->i . "min ";
                     }
                 }
                 echo "<td>" . $display_date . $interval->s . "s</td>";
             } else {
                 $interval = $pfStateInventory->date_diff($start_date, $end_date);
             }
         }
         echo "<td>" . $nb_threads . "</td>";
         echo "<td>" . $nb_found . "</td>";
         echo "<td>" . $notimporteddevices . "</td>";
         echo "<td>" . $updateddevices . "</td>";
         echo "<td>" . $createddevices . "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }