static function displayAjaxValues($config, $request_data, $rand, $mode) { global $CFG_GLPI; $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployOrder = new PluginFusioninventoryDeployOrder(); if (isset($request_data['orders_id'])) { $pfDeployOrder->getFromDB($request_data['orders_id']); $pfDeployPackage->getFromDB($pfDeployOrder->fields['plugin_fusioninventory_deploypackages_id']); } else { $pfDeployPackage->getEmpty(); } $p2p = 0; $p2p_retention_duration = 0; $uncompress = 0; if ($mode === 'create') { $source = $request_data['value']; /** * No need to continue if there is no selected source */ if ($source === '0') { return; } } else { $p2p = $config['data']['p2p']; $p2p_retention_duration = $config['data']['p2p-retention-duration']; $uncompress = $config['data']['uncompress']; } echo "<table class='package_item'>"; /* * Display file upload input only in 'create' mode */ echo "<tr>"; echo "<th>" . __("File", 'fusioninventory') . "</th>"; echo "<td>"; if ($mode === 'create') { switch ($source) { case "Computer": echo "<input type='file' name='file' value='" . __("filename", 'fusioninventory') . "' />"; echo "<i>" . self::getMaxUploadSize() . "</i>"; break; case "Server": echo "<input type='text' name='filename' id='server_filename{$rand}'" . " style='width:120px;float:left' />"; echo "<input type='button' class='submit' value='" . __("Choose", 'fusioninventory') . "' onclick='fileModal{$rand}.dialog(\"open\");' />"; Ajax::createModalWindow("fileModal{$rand}", $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/ajax/deployfilemodal.php", array('title' => __('Select the file on server', 'fusioninventory'), 'extraparams' => array('rand' => $rand))); break; } } else { /* * Display only name in 'edit' mode */ echo $config['data']['name']; } echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<th>" . __("Uncompress", 'fusioninventory') . "<img style='float:right' " . "src='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory//pics/uncompress.png' /></th>"; echo "<td>"; Html::showCheckbox(array('name' => 'uncompress', 'checked' => $uncompress)); echo "</td>"; echo "</tr><tr>"; echo "<th>" . __("P2P", 'fusioninventory') . "<img style='float:right' src='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory//pics/p2p.png' /></th>"; echo "<td>"; Html::showCheckbox(array('name' => 'p2p', 'checked' => $p2p)); echo "</td>"; echo "</tr><tr>"; echo "<th>" . __("retention days", 'fusioninventory') . "</th>"; echo "<td>"; /* * TODO: use task periodicity input to propose days, months and years */ Dropdown::showNumber('p2p-retention-duration', array('value' => $p2p_retention_duration, 'min' => 0, 'max' => 400)); echo "</td>"; echo "</tr><tr>"; echo "<td>"; echo "</td><td>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { if ($mode === 'edit') { echo "<input type='submit' name='save_item' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } else { echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit' >"; } } echo "</td>"; echo "</tr></table>"; }
static function display_json_debug(PluginFusioninventoryDeployOrder $order) { global $CFG_GLPI; if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE) { $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployPackage->getFromDB($order->fields['plugin_fusioninventory_deploypackages_id']); // === debug === echo "<span class='red'><b>DEBUG</b></span>"; echo "<form action='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/deploypackage.form.php' method='POST'>"; echo "<textarea cols='132' rows='25' style='border:0' name='json'>"; echo PluginFusioninventoryToolbox::formatJson($order->fields['json']); echo "</textarea>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { echo "<input type='hidden' name='orders_id' value='{$order->fields['id']}' />"; echo "<input type='submit' name='update_json' value=\"" . _sx('button', 'Save') . "\" class='submit'>"; } Html::closeForm(); // === debug === } }
static function displayAjaxValues($config, $request_data, $rand, $mode) { global $CFG_GLPI; $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployOrder = new PluginFusioninventoryDeployOrder(); if (isset($request_data['orders_id'])) { $pfDeployOrder->getFromDB($request_data['orders_id']); $pfDeployPackage->getFromDB($pfDeployOrder->fields['plugin_fusioninventory_deploypackages_id']); } else { $pfDeployPackage->getEmpty(); } /* * Get type from request params */ $type = NULL; if ($mode === 'create') { $type = $request_data['values']; } else { $type = $config['type']; $config_data = $config['data']; } /* * Set default values */ $value_type_1 = "input"; $value_1 = ""; $value_2 = ""; $retChecks = NULL; /* * set values from element's config in 'edit' mode */ switch ($type) { case 'move': case 'copy': $value_label_1 = __("From", 'fusioninventory'); $name_label_1 = "from"; $value_label_2 = __("To", 'fusioninventory'); $name_label_2 = "to"; if ($mode === 'edit') { $value_1 = $config_data['from']; $value_2 = $config_data['to']; } break; case 'cmd': $value_label_1 = __("exec", 'fusioninventory'); $name_label_1 = "exec"; $value_label_2 = FALSE; $value_type_1 = "textarea"; if ($mode === 'edit') { $value_1 = $config_data['exec']; if (isset($config_data['retChecks'])) { $retChecks = $config_data['retChecks']; } } break; case 'delete': case 'mkdir': $value_label_1 = __("path", 'fusioninventory'); $name_label_1 = "list[]"; $value_label_2 = FALSE; if ($mode === 'edit') { /* * TODO : Add list input like `retChecks` on `mkdir` and `delete` * because those methods are defined as list in specification */ $value_1 = array_shift($config_data['list']); } break; default: return FALSE; } echo "<table class='package_item'>"; echo "<tr>"; echo "<th>{$value_label_1}</th>"; echo "<td>"; switch ($value_type_1) { case "input": echo "<input type='text' name='{$name_label_1}' value='{$value_1}' />"; break; case "textarea": echo "<textarea name='{$name_label_1}' rows='3'>{$value_1}</textarea>"; break; } echo "</td>"; echo "</tr>"; if ($value_label_2 !== FALSE) { echo "<tr>"; echo "<th>{$value_label_2}</th>"; echo "<td><input type='text' name='{$name_label_2}' value='{$value_2}'/></td>"; echo "</tr>"; } //specific case for cmd : add retcheck form if ($type == "cmd") { echo "<tr>"; echo "<th>" . __("Execution checks", 'fusioninventory'); PluginFusioninventoryDeployPackage::plusButton("retchecks", ".table_retchecks.template"); echo "</th>"; echo "<td>"; $display = "style='display:none'"; if ($retChecks) { $display = "style='display:block'"; } echo "<span id='retchecks' style='display:block'>"; if (is_array($retChecks) && count($retChecks)) { foreach ($retChecks as $retcheck) { echo "<table class='table_retchecks'>"; echo "<tr>"; echo "<td>"; Dropdown::showFromArray('retchecks_type[]', self::retchecks_entries(), array('value' => $retcheck['type'])); echo "</td>"; echo "<td>"; echo "<input type='text' name='retchecks_value[]' value='" . $retcheck['values'][0] . "' />"; echo "</td>"; echo "<td><a class='edit' onclick='removeLine(this)'><img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png' /></a></td>"; echo "</tr>"; echo "</table>"; } } echo "<table class='table_retchecks template' style='display:none'>"; echo "<tr>"; echo "<td>"; //Toolbox::logDebug(self::retchecks_entries()); Dropdown::showFromArray('retchecks_type[]', self::retchecks_entries(), array()); echo "</td>"; echo "<td><input type='text' name='retchecks_value[]' /></td>"; echo "<td><a class='edit' onclick='removeLine(this)'><img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png' /></a></td>"; echo "</tr>"; echo "</table>"; echo "</span>"; echo "</td>"; echo "</tr>"; } echo "<tr>"; echo "<td></td><td>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { if ($mode === 'edit') { echo "<input type='submit' name='save_item' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } else { echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit' >"; } } echo "</td>"; echo "</tr></table>"; echo "<script type='text/javascript'>\n function removeLine(item) {\n var tag_table = item.parentNode.parentNode.parentNode.parentNode;\n var parent = tag_table.parentNode;\n parent.removeChild(tag_table);\n }\n </script>"; }
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']); } }
static function displayAjaxValues($config, $request_data, $rand, $mode) { $pfDeployPackage = new PluginFusioninventoryDeployPackage(); $pfDeployOrder = new PluginFusioninventoryDeployOrder(); if (isset($request_data['orders_id'])) { $pfDeployOrder->getFromDB($request_data['orders_id']); $pfDeployPackage->getFromDB($pfDeployOrder->fields['plugin_fusioninventory_deploypackages_id']); } else { $pfDeployPackage->getEmpty(); } /* * Get type from request params */ $type = NULL; if ($mode === 'create') { $type = $request_data['value']; $config_data = NULL; } else { $type = $config['type']; $config_data = $config['data']; } $values = self::getValues($type, $config_data, $mode); if ($values === FALSE) { return FALSE; } echo "<table class='package_item'>"; echo "<tr>"; echo "<th>{$values['path_label']}</th>"; echo "<td><input type='text' name='path' id='check_path{$rand}' value='{$values['path_value']}' /></td>"; echo "</tr>"; if ($values['value_label'] !== FALSE) { echo "<tr>"; echo "<th>{$values['value_label']}</th>"; switch ($values['value_type']) { case "textarea": echo "<td><textarea name='value' id='check_value{$rand}' rows='5'>" . $values['value'] . "</textarea></td>"; break; case "input": echo "<td><input type='text' name='value' id='check_value{$rand}' value='" . $values['value'] . "' /></td>"; break; case "input+unit": $value = $values['value']; // freespaceGreater check is saved as MiB if ($type == 'freespaceGreater') { $value = $value * 1024 * 1024; } $options['value'] = 'KB'; if ($mode === 'edit') { if ($value >= self::getUnitSize('GB')) { $value = $value / self::getUnitSize('GB'); $options['value'] = 'GB'; } elseif ($value >= self::getUnitSize('MB')) { $value = $value / self::getUnitSize('MB'); $options['value'] = 'MB'; } elseif ($value >= self::getUnitSize('KB')) { $value = $value / self::getUnitSize('KB'); $options['value'] = 'KB'; } else { $options['value'] = 'B'; } } echo "<td>"; echo "<input " . "type='text' " . "name='value' " . "id='check_value{$rand}' " . "value='{$value}' " . "/>"; echo "</td>"; echo "</tr><tr>"; echo "<th>" . __("Unit", 'fusioninventory') . "</th>"; echo "<td>"; $unit_labels = self::getUnitLabel(); /* * The freespaceGreater check does not need to propose KiB or B * because its value is based on MiB according to REST API. * -- Kevin 'kiniou' Roy */ if ($type == 'freespaceGreater') { unset($unit_labels['KB']); unset($unit_labels['B']); } Dropdown::showFromArray('unit', $unit_labels, $options); echo "</td>"; break; } echo "</tr>"; } echo "<tr>"; echo "<th>" . __("In case of error", 'fusioninventory') . "</th>"; echo "<td>"; Dropdown::showFromArray('return', array("error" => __('Error', 'fusioninventory'), "ignore" => __("Ignore", 'fusioninventory')), array('value' => $values['return'])); echo "</td>"; echo "</tr>"; echo "<tr><td></td><td>"; if ($pfDeployPackage->can($pfDeployPackage->getID(), UPDATE)) { if ($mode === 'edit') { echo "<input type='submit' name='save_item' value=\"" . _sx('button', 'Save') . "\" class='submit' >"; } else { echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit' >"; } } echo "</td></tr>"; echo "</table>"; }