diff --git a/ajax/deploypackage_form.php b/ajax/deploypackage_form.php index d24083645..6c9d74219 100644 --- a/ajax/deploypackage_form.php +++ b/ajax/deploypackage_form.php @@ -65,7 +65,7 @@ $item = new $itemtype(); $item->move_item($params); } else { - Toolbox::logDebug("package subtype not found : " . $params['itemtype']); + Toolbox::logDebug("package subtype not found : " . $itemtype); Html::displayErrorAndDie ("package subtype not found"); } diff --git a/ajax/deployuser.logged.in.php b/ajax/deployuser.logged.in.php deleted file mode 100644 index 874bf232f..000000000 --- a/ajax/deployuser.logged.in.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display deploy user logged. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author Kevin Roy - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -include ("../../../inc/includes.php"); - -$loggedin = []; -$loggedin['result'] = 1; -if (!isset($_SESSION["glpiname"])) { - if (!Session::getLoginUserID()) { - $loggedin['result'] = 0; - } -} - -echo json_encode($loggedin); - diff --git a/ajax/dropdownactiontype.php b/ajax/dropdownactiontype.php deleted file mode 100644 index 1d6c36979..000000000 --- a/ajax/dropdownactiontype.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display dropdown action types. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "dropdownactiontype.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} - -Session::checkCentralAccess(); - -$pfTaskjob = new PluginFusioninventoryTaskjob; -$pfTaskjob->dropdownActionType( - "ActionType", - filter_input(INPUT_POST, "method"), - ''); diff --git a/ajax/dropdowndefinitionselection.php b/ajax/dropdowndefinitionselection.php deleted file mode 100644 index 711074bf7..000000000 --- a/ajax/dropdowndefinitionselection.php +++ /dev/null @@ -1,80 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display dropdown task - * definition selection. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "dropdowndefinitionselection.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} -if (!defined('GLPI_ROOT') || !isset($CFG_GLPI)) { - die("Can not acces directly to this file"); -} -Session::checkCentralAccess(); - -echo ""; - diff --git a/ajax/dropdowndefinitiontypelist.php b/ajax/dropdowndefinitiontypelist.php deleted file mode 100644 index 1d897f0ea..000000000 --- a/ajax/dropdowndefinitiontypelist.php +++ /dev/null @@ -1,65 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display dropdown task - * definition type list. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "dropdowndefinitiontypelist.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} -if (!defined('GLPI_ROOT')) { - die("Can not acces directly to this file"); -} - -Session::checkCentralAccess(); -$pfTaskjob = new PluginFusioninventoryTaskjob(); -$pfTaskjob->dropdownDefinition( - "DefinitionList", - filter_input(INPUT_POST, "DefinitionType"), - filter_input(INPUT_POST, "method"), - filter_input(INPUT_POST, "deftypeid"), - filter_input(INPUT_POST, "taskjobs_id")); - diff --git a/ajax/dropdownjobdefinition.php b/ajax/dropdownjobdefinition.php deleted file mode 100644 index 777f2f426..000000000 --- a/ajax/dropdownjobdefinition.php +++ /dev/null @@ -1,119 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display dropdown task job - * definition. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -include ("../../../inc/includes.php"); - -header("Content-Type: text/html; charset=UTF-8"); -Html::header_nocache(); -Session::checkCentralAccess(); - -// Make a select box -$type = filter_input(INPUT_POST, "type"); -$actortype = filter_input(INPUT_POST, "actortype"); - -if (!empty($type) && !empty($actortype)) { - $rand = mt_rand(); - - $entity_restrict = filter_input(INPUT_POST, "entity_restrict"); - switch ($type) { - case "user" : - $right = 'all'; - /// TODO : review depending of itil object - // Only steal or own ticket whit empty assign - if ($actortype == 'assign') { - $right = "own_ticket"; - if (!$item->canAssign()) { - $right = 'id'; - } - } - - $options = ['name' => '_itil_'.$actortype.'[users_id]', - 'entity' => $entity_restrict, - 'right' => $right, - 'ldap_import' => true]; - $withemail = false; - if ($CFG_GLPI["use_mailing"]) { - $allow_email = filter_input(INPUT_POST, "allow_email"); - $withemail = (!empty($allow_email) ? $allow_email : false); - $paramscomment = ['value' => '__VALUE__', - 'allow_email' => $withemail, - 'field' => "_itil_".$actortype]; - // Fix rand value - $options['rand'] = $rand; - $options['toupdate'] = ['value_fieldname' => 'value', - 'to_update' => "notif_user_$rand", - 'url' => $CFG_GLPI["root_doc"]."/ajax/uemailUpdate.php", - 'moreparams' => $paramscomment]; - } - $rand = User::dropdown($options); - - if ($CFG_GLPI["use_mailing"]==1) { - echo "
"; - if ($withemail) { - echo __('Email followup').' : '; - $rand = Dropdown::showYesNo('_itil_'.$actortype.'[use_notification]', 1); - echo '
'.__('Email').' : '; - echo ""; - } - echo "
"; - } - break; - - case "group" : - $cond = ($actortype=='assign' ? $cond = '`is_assign`' : $cond = '`is_requester`'); - Dropdown::show('Group', ['name' => '_itil_'.$actortype.'[groups_id]', - 'entity' => $entity_restrict, - 'condition' => $cond]); - break; - - case "supplier" : - Dropdown::show('Supplier', ['name' => 'suppliers_id_assign', - 'entity' => $entity_restrict]); - break; - } -} - diff --git a/ajax/dropdowntype.php b/ajax/dropdowntype.php deleted file mode 100644 index 5f734ebe1..000000000 --- a/ajax/dropdowntype.php +++ /dev/null @@ -1,65 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and display dropdown method types. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "dropdowntype.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} - -Session::checkCentralAccess(); - -$typename = filter_input(INPUT_POST, "typename"); -$method = filter_input(INPUT_POST, "method"); -$taskjobs_id = filter_input(INPUT_POST, "taskjobs_id"); - -$pfTaskjob = new PluginFusioninventoryTaskjob(); -if (!empty($typename) - && !empty($method) - && !empty($taskjobs_id)) { - $pfTaskjob->dropdownType($typename, $method, - filter_input(INPUT_POST, "value"), $taskjobs_id, ""); -} diff --git a/ajax/taskjob_form.php b/ajax/taskjob_form.php index 293197fbb..7ba5763cd 100644 --- a/ajax/taskjob_form.php +++ b/ajax/taskjob_form.php @@ -62,7 +62,7 @@ "task_id" => filter_input(INPUT_GET, "task_id") ]; -if (is_null($params['id']) || is_null($params['task_id'])) { +if (is_null($params['id']) && is_null($params['task_id'])) { exit; } diff --git a/ajax/taskjobdeletetype.php b/ajax/taskjobdeletetype.php deleted file mode 100644 index 05e834510..000000000 --- a/ajax/taskjobdeletetype.php +++ /dev/null @@ -1,70 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and delete task job type. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "taskjobdeletetype.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} - -Session::checkCentralAccess(); - -$type = filter_input(INPUT_POST, "type"); -$taskjobs_id = filter_input(INPUT_POST, "taskjobs_id"); - -if (is_null($type) || is_null($taskjobs_id) || !is_numeric($taskjobs_id)) { - exit; -} -$taskjobs_id = intval($taskjobs_id); - -$item = filter_input(INPUT_POST, $type . 'item'); - -if (is_null($item)) { - exit; -} - -$pfTaskjob = new PluginFusioninventoryTaskjob(); -$pfTaskjob->deleteitemtodefatc($type, $item, $taskjobs_id); diff --git a/ajax/taskmethodupdate.php b/ajax/taskmethodupdate.php deleted file mode 100644 index 3b1e982d7..000000000 --- a/ajax/taskmethodupdate.php +++ /dev/null @@ -1,66 +0,0 @@ -. - * - * ------------------------------------------------------------------------ - * - * This file is called by ajax function and update task method. - * - * ------------------------------------------------------------------------ - * - * @package FusionInventory - * @author David Durieux - * @copyright Copyright (c) 2010-2023 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 https://github.com/fusioninventory/fusioninventory-for-gsit - * - */ - -if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "taskmethodupdate.php")) { - include ("../../../inc/includes.php"); - header("Content-Type: text/html; charset=UTF-8"); - Html::header_nocache(); -} - -Session::checkCentralAccess(); - -$method = filter_input(INPUT_POST, "method"); -$taskjobs_id = filter_input(INPUT_POST, "taskjobs_id"); - -if (is_null($method) || is_null($taskjobs_id) || !is_numeric($taskjobs_id)) { - exit; -} -$taskjobs_id = intval($taskjobs_id); - -if ($method != '') { - $pfTaskjob = new PluginFusioninventoryTaskjob(); - $pfTaskjob->updateMethod($method, $taskjobs_id); -} diff --git a/css/views.css b/css/views.css index 40d8e3ea6..0850ea202 100644 --- a/css/views.css +++ b/css/views.css @@ -1000,3 +1000,11 @@ hr.criteriarule { background-image: -ms-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0); background-image: -o-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0); } + +.clear_list { + cursor: pointer; +} + +.delete_items_selected { + cursor: pointer; +} diff --git a/front/deploypackage.form.php b/front/deploypackage.form.php index 76ed1003c..a9b03eb46 100644 --- a/front/deploypackage.form.php +++ b/front/deploypackage.form.php @@ -58,19 +58,128 @@ Html::back(); exit; } else if (isset($_POST['add_item'])) { - $data = array_map(['Toolbox', 'stripslashes_deep'], - $package->escapeText($_POST)); - PluginFusioninventoryDeployPackage::alterJSON('add_item', $data); + $itemtype = filter_input(INPUT_POST, "itemtype"); + if (is_null($itemtype) || $itemtype === false) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + $item = new stdClass(); + $data = false; + switch ($itemtype) { + case 'PluginFusioninventoryDeployCheck': + $item = new PluginFusioninventoryDeployCheck(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployFile': + $item = new PluginFusioninventoryDeployFile(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployAction': + $item = new PluginFusioninventoryDeployAction(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployUserinteraction': + $item = new PluginFusioninventoryDeployUserinteraction(); + $data = $item->check_data_from_form(); + break; + + default: + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + + if ($data === false) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + $item->add_item($data); Html::back(); } else if (isset($_POST['save_item'])) { - $data = array_map(['Toolbox', 'stripslashes_deep'], - $package->escapeText($_POST)); - PluginFusioninventoryDeployPackage::alterJSON('save_item', $data); + $itemtype = filter_input(INPUT_POST, "itemtype"); + if (is_null($itemtype) || $itemtype === false) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + $item = new stdClass(); + $data = false; + switch ($itemtype) { + case 'PluginFusioninventoryDeployCheck': + $item = new PluginFusioninventoryDeployCheck(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployFile': + $item = new PluginFusioninventoryDeployFile(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployAction': + $item = new PluginFusioninventoryDeployAction(); + $data = $item->check_data_from_form(); + break; + + case 'PluginFusioninventoryDeployUserinteraction': + $item = new PluginFusioninventoryDeployUserinteraction(); + $data = $item->check_data_from_form(); + break; + + default: + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + + if ($data === false) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + $item->save_item($data); Html::back(); } else if (isset($_POST['remove_item'])) { - $data = array_map(['Toolbox', 'stripslashes_deep'], - $package->escapeText($_POST)); - PluginFusioninventoryDeployPackage::alterJSON('remove_item', $data); + $itemtype = filter_input(INPUT_POST, "itemtype"); + if (is_null($itemtype) || $itemtype === false) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + + $packages_id = filter_input(INPUT_POST, "packages_id"); + if ( + is_null($packages_id) || $packages_id === false || + !is_numeric($packages_id) || intval($packages_id) === 0 + ) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + + $item = new stdClass(); + $data = [ + 'packages_id' => intval($packages_id) + ]; + $varEntries = ''; + switch ($itemtype) { + case 'PluginFusioninventoryDeployCheck': + $varEntries = 'checks_entries'; + $item = new PluginFusioninventoryDeployCheck(); + break; + + case 'PluginFusioninventoryDeployFile': + $varEntries = 'actions_entries'; + $item = new PluginFusioninventoryDeployFile(); + break; + + case 'PluginFusioninventoryDeployAction': + $varEntries = 'actions_entries'; + $item = new PluginFusioninventoryDeployAction(); + break; + + case 'PluginFusioninventoryDeployUserinteraction': + $varEntries = 'userinteractions_entries'; + $item = new PluginFusioninventoryDeployUserinteraction(); + break; + + default: + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + + if (!isset($_POST[$varEntries]) || !is_array($_POST[$varEntries])) { + Html::displayErrorAndDie("Error with wrong format of data sent"); + } + $data[$varEntries] = $_POST[$varEntries]; + $item->remove_item($data); Html::back(); } diff --git a/inc/collectcontentcommon.class.php b/inc/collectcontentcommon.class.php index 217ce831d..838367339 100644 --- a/inc/collectcontentcommon.class.php +++ b/inc/collectcontentcommon.class.php @@ -130,8 +130,8 @@ function getTabNameForItem(CommonGLPI $item, $withtemplate = false) { } $in = array_keys($a_colfiles); $fk = getForeignKeyFieldForItemType($collect); - if ($nb = countElementsInTable($this->getTable(), - [$fk => $in]) > 0) { + $nb = countElementsInTable($this->getTable(), [$fk => $in]); + if ($nb > 0) { return self::createTabEntry($collect::getTypeName(Session::getPluralNumber()), $nb); } } diff --git a/inc/commonview.class.php b/inc/commonview.class.php index 852c3454d..bf3cb3263 100644 --- a/inc/commonview.class.php +++ b/inc/commonview.class.php @@ -187,7 +187,7 @@ public function showCheckboxField($title, $varname, $options = []) { * @param string $title * @param string $itemtype a glpi/plugin itemtype * @param mixed[] $options - * @return string the rand number can be used with ajax to update something + * @return integer|boolean */ public function showDropdownForItemtype($title, $itemtype, $options = []) { echo ""; diff --git a/inc/communication.class.php b/inc/communication.class.php index 248fb8667..019559c2f 100644 --- a/inc/communication.class.php +++ b/inc/communication.class.php @@ -167,7 +167,7 @@ static function addLog($p_logs) { /** * Import and parse the XML sent by the agent * - * @param object $arrayinventory SimpleXMLElement + * @param mixed[] $arrayinventory * @return boolean */ function import($arrayinventory) { @@ -179,10 +179,9 @@ function import($arrayinventory) { 'Function import().' ); - $this->message = $arrayinventory; $errors = ''; - $xmltag = $this->message['QUERY']; + $xmltag = $arrayinventory['QUERY']; if ($xmltag == "NETDISCOVERY") { $xmltag = "NETWORKDISCOVERY"; } @@ -192,7 +191,7 @@ function import($arrayinventory) { } if (!isset($_SESSION['plugin_fusioninventory_agents_id'])) { - $agent = $pfAgent->infoByKey($this->message['DEVICEID']); + $agent = $pfAgent->infoByKey($arrayinventory['DEVICEID']); } else { $agent = ['id' => $_SESSION['plugin_fusioninventory_agents_id']]; } @@ -200,33 +199,33 @@ function import($arrayinventory) { return false; } - if (isset($this->message['CONTENT']['MODULEVERSION'])) { + if (isset($arrayinventory['CONTENT']['MODULEVERSION'])) { $pfAgent->setAgentVersions($agent['id'], $xmltag, - $this->message['CONTENT']['MODULEVERSION']); - } else if (isset($this->message['CONTENT']['VERSIONCLIENT'])) { + $arrayinventory['CONTENT']['MODULEVERSION']); + } else if (isset($arrayinventory['CONTENT']['VERSIONCLIENT'])) { $version = str_replace("FusionInventory-Agent_", "", - $this->message['CONTENT']['VERSIONCLIENT']); + $arrayinventory['CONTENT']['VERSIONCLIENT']); $pfAgent->setAgentVersions($agent['id'], $xmltag, $version); } - if (isset($this->message->CONTENT->MODULEVERSION)) { + if (isset($arrayinventory['CONTENT']['MODULEVERSION'])) { $pfAgent->setAgentVersions($agent['id'], $xmltag, - (string)$this->message->CONTENT->MODULEVERSION); - } else if (isset($this->message->CONTENT->VERSIONCLIENT)) { + (string)$arrayinventory['CONTENT']['MODULEVERSION']); + } else if (isset($arrayinventory['CONTENT']['VERSIONCLIENT'])) { $version = str_replace("FusionInventory-Agent_", "", - (string)$this->message->CONTENT->VERSIONCLIENT); + (string)$arrayinventory['CONTENT']['VERSIONCLIENT']); $pfAgent->setAgentVersions($agent['id'], $xmltag, $version); } if (isset($_SESSION['glpi_plugin_fusioninventory']['xmltags']["$xmltag"])) { $moduleClass = $_SESSION['glpi_plugin_fusioninventory']['xmltags']["$xmltag"]; $moduleCommunication = new $moduleClass(); - $errors .= $moduleCommunication->import($this->message['DEVICEID'], - $this->message['CONTENT'], + $moduleCommunication->import($arrayinventory['DEVICEID'], + $arrayinventory['CONTENT'], $arrayinventory); } else { $errors.=__('Unattended element in', 'fusioninventory').' QUERY : *'.$xmltag."*\n"; diff --git a/inc/communicationnetworkdiscovery.class.php b/inc/communicationnetworkdiscovery.class.php index ddb179923..95bbf4405 100644 --- a/inc/communicationnetworkdiscovery.class.php +++ b/inc/communicationnetworkdiscovery.class.php @@ -105,7 +105,7 @@ function import($p_DEVICEID, $a_CONTENT, $arrayinventory) { if ($pfTaskjobstate->getFromDB($a_CONTENT['PROCESSNUMBER'])) { if ($pfTaskjobstate->fields['state'] != PluginFusioninventoryTaskjobstate::FINISHED) { $pfImportExport = new PluginFusioninventorySnmpmodelImportExport(); - $errors .= $pfImportExport->import_netdiscovery($a_CONTENT, $p_DEVICEID); + $pfImportExport->import_netdiscovery($a_CONTENT, $p_DEVICEID); if (isset($a_CONTENT['AGENT']['END'])) { $messages = [ 'Total Found' => 0, diff --git a/inc/computer.class.php b/inc/computer.class.php index d131e2b7d..3484eb56b 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -76,7 +76,7 @@ function rawSearchOptions() { 'id' => 'fields_plugin', 'name' => __('Plugin fields') ]; - $fieldsoptions = plugin_fields_getAddSearchOptions('Computer'); + $fieldsoptions = plugin_fields_getAddSearchOptions('Computer'); foreach ($fieldsoptions as $id=>$data) { $data['id'] = $id; $options[$id] = $data; diff --git a/inc/config.class.php b/inc/config.class.php index ba778b9dd..edbebed60 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -245,7 +245,7 @@ function defineTabs($options = []) { * * @param CommonGLPI $item the item object * @param boolean $withtemplate true if is a template form - * @return string|array name of the tab + * @return string name of the tab */ function getTabNameForItem(CommonGLPI $item, $withtemplate = false) { if ($item->getType() == __CLASS__) { diff --git a/inc/crontask.class.php b/inc/crontask.class.php index 4dc2e91ed..fe7797b4e 100644 --- a/inc/crontask.class.php +++ b/inc/crontask.class.php @@ -123,8 +123,8 @@ static function getMenuContent() { * @return string name of the tab */ function getTabNameForItem(CommonGLPI $item, $withtemplate = false) { - if ($this->canView()) { - $cnt = PluginFusioninventoryCrontask::countForItem($item); + if ($this->canView() && $item instanceof CommonDBTM) { + $cnt = PluginFusioninventoryCronTask::countForItem($item); return self::createTabEntry(__('Cron tasks', 'fusioninventory'), $cnt); } return ''; diff --git a/inc/deployaction.class.php b/inc/deployaction.class.php index c7be47904..60e8de86a 100644 --- a/inc/deployaction.class.php +++ b/inc/deployaction.class.php @@ -477,36 +477,105 @@ function removeLine(item) { /** - * Add a new item in actions of the package - * - * @param mixed[] $params list of fields with value of the action - * @return boolean + * Clean data of package form + * @return array{'id': integer, 'actionstype': string, 'name': string, 'exec'?: string, 'retChecks'?: array{'type': string, 'values': (string|integer)[]}[], 'logLineLimit'?: int, 'from'?: string, 'to'?: string, 'list'?: string[]}|false */ - function add_item($params) { - //prepare new action entry to insert in json - $tmp = []; - $fields = ['list', 'from', 'to', 'exec', 'name', 'logLineLimit']; - foreach ($fields as $field) { - if (isset($params[$field])) { - $tmp[$field] = $params[$field]; - } + function check_data_from_form() { + $id = filter_input(INPUT_POST, "id"); + $actionstype = filter_input(INPUT_POST, "actionstype"); + $name = filter_input(INPUT_POST, "name"); + // Optional, not present in all cases + $exec = filter_input(INPUT_POST, "exec"); + $logLineLimit = filter_input(INPUT_POST, "logLineLimit"); + $from = filter_input(INPUT_POST, "from"); + $to = filter_input(INPUT_POST, "to"); + + if ( + is_null($id) || $id === false || !is_numeric($id) || + is_null($actionstype) || $actionstype === false || + is_null($name) || $name === false + ) { + return false; } - //process ret checks - if (isset($params['retchecks_type']) - && !empty($params['retchecks_type'])) { - foreach ($params['retchecks_type'] as $index => $type) { - if ($type !== '0') { - $tmp['retChecks'][] = [ - 'type' => $type, - 'values' => [$params['retchecks_value'][$index]] - ]; + $data = [ + 'id' => intval($id), + 'actionstype' => $actionstype, + 'name' => $name + ]; + + switch ($actionstype) { + case 'cmd': + if (is_null($exec) || $exec === false || !is_string($exec) || empty($exec)) { + return false; } - } + if (is_null($logLineLimit) || $exec === $logLineLimit) { + $logLineLimit = -1; + } + $data['exec'] = $exec; + $data['logLineLimit'] = intval($logLineLimit); + $data['retChecks'] = []; + if ( + isset($_POST['retchecks_type']) && is_array($_POST['retchecks_type']) && + isset($_POST['retchecks_value']) && is_array($_POST['retchecks_value']) && + count($_POST['retchecks_type']) == count($_POST['retchecks_value']) + ) { + foreach ($_POST['retchecks_type'] as $index => $type) { + if ($type !== '0') { + if (!is_string($type) && !is_numeric($_POST['retchecks_value'][$index]) || !is_string($_POST['retchecks_value'][$index])) { + return false; + } + $data['retChecks'][] = [ + 'type' => $type, + 'values' => [$_POST['retchecks_value'][$index]] + ]; + } + } + } + break; + + case 'move': + case 'copy': + if (is_null($from) || $from === false || !is_string($from) || empty($from)) { + return false; + } + if (is_null($to) || $to === false || !is_string($to) || empty($to)) { + return false; + } + $data['from'] = $from; + $data['to'] = $to; + break; + + case 'mkdir': + case 'delete': + if ( + !isset($_POST['list']) || + !isset($_POST['list'][0]) || + $_POST['list'][0] === false || + !is_string($_POST['list'][0]) || + empty($_POST['list'][0]) + ) { + return false; + } + $data['list'] = [ + $_POST['list'][0] + ]; + break; + } + return $data; + } + + /** + * Add a new item in actions of the package + * + * @param array{'id': integer, 'actionstype': string, 'name': string, 'exec'?: string, 'retChecks'?: array{'type': string, 'values': (string|integer)[]}[], 'logLineLimit'?: int, 'from'?: string, 'to'?: string, 'list'?: string[]} $params list of fields with value of the action + * @return boolean + */ + function add_item($params) { //append prepared data to new entry - $new_entry[$params['actionstype']] = $tmp; + $new_entry[$params['actionstype']] = $params; //get current order json $data = json_decode($this->getJson($params['id']), true); diff --git a/inc/deploycheck.class.php b/inc/deploycheck.class.php index bd9f0d4e0..a1ac1f03d 100644 --- a/inc/deploycheck.class.php +++ b/inc/deploycheck.class.php @@ -470,7 +470,7 @@ function displayAjaxValues($config, $request_data, $rand, $mode) { echo ""; echo ""; echo "{$values['path_label']}"; - echo ""; + echo ""; if ($values['path_comment']) { echo "
".$values['path_comment'].""; } @@ -603,17 +603,10 @@ function getValueForReturn($value) { /** * Return an array corresponding to a check, ready to be serialized - * @param mixed[] $params the check's parameters - * @return mixed[] the array to be encoded in json and serialized + * @param array{'id': integer,'checkstype': string, 'name': string, 'path': string, 'return': string, 'value': string, 'unit': string} $params the check's parameters + * @return array{'name': string, 'type': string, 'path': string, 'value': string, 'return': string} the array to be encoded in json and serialized */ static function formatCheckForJson($params) { - if (!isset($params['value'])) { - $params['value'] = ""; - } - if (!isset($params['name'])) { - $params['name'] = ""; - } - if (!empty($params['unit'])) { $params['value'] = str_replace(",", ".", $params['value']); if (!empty($params['value']) && is_numeric($params['value'])) { @@ -624,28 +617,65 @@ static function formatCheckForJson($params) { } else { $params['value'] = $params['value'] * self::getUnitSize($params['unit']); } - } - } //prepare updated check entry to insert in json - $entry = [ + return [ 'name' => $params['name'], 'type' => $params['checkstype'], 'path' => $params['path'], 'value' => strval($params['value']), 'return' => $params['return'] ]; + } + + /** + * Clean data of package form + * @return array{'id': integer,'checkstype': string, 'name': string, 'path': string, 'return': string, 'value': string, 'unit': string}|false + */ + function check_data_from_form() { + $id = filter_input(INPUT_POST, "id"); + $checkstype = filter_input(INPUT_POST, "checkstype"); + $name = filter_input(INPUT_POST, "name"); + $path = filter_input(INPUT_POST, "path"); + $return = filter_input(INPUT_POST, "return"); + // Optional, not present in all cases + $value = filter_input(INPUT_POST, "value"); + $unit = filter_input(INPUT_POST, "unit"); + + if ( + is_null($id) || $id === false || !is_numeric($id) || + is_null($checkstype) || $checkstype === false || + is_null($name) || $name === false || + is_null($path) || $path === false || !is_string($path) || empty($path) || + is_null($return) || $return === false + ) { + return false; + } + if (is_null($value) || $value === false) { + $value = ''; + } + if (is_null($unit) || $unit === false) { + $unit = ''; + } - return $entry; + return [ + 'id' => intval($id), + 'checkstype' => $checkstype, + 'name' => $name, + 'path' => $path, + 'return' => $return, + 'value' => $value, + 'unit' => $unit + ]; } /** * Add a new item in checks of the package * - * @param mixed[] $params list of fields with value of the check + * @param array{'id': integer,'checkstype': string, 'name': string, 'path': string, 'return': string, 'value': string, 'unit': string} $params list of fields with value of the check * @return boolean */ function add_item($params) { diff --git a/inc/deployfile.class.php b/inc/deployfile.class.php index 26bd30b0e..8929860c5 100644 --- a/inc/deployfile.class.php +++ b/inc/deployfile.class.php @@ -153,7 +153,7 @@ function displayList(PluginFusioninventoryDeployPackage $package, $data, $rand) // start new line $pics_path = Plugin::getWebDir('fusioninventory')."/pics/"; - echo Search::showNewLine(Search::HTML_OUTPUT, ($i%2)); + echo Search::showNewLine(Search::HTML_OUTPUT, boolval($i%2)); if ($canedit) { echo ""; Html::showCheckbox(['name' => 'file_entries['.$i.']', 'value' => 0]); @@ -273,6 +273,7 @@ function displayAjaxValues($config, $request_data, $rand, $mode) { $p2p = 0; $p2p_retention_duration = 0; $uncompress = 0; + $source = ''; if ($mode === self::CREATE) { $source = $request_data['value']; @@ -495,15 +496,65 @@ static function getServerFileTree($node) { print json_encode($nodes); } + /** + * Clean data of package form + * @return array{'id': integer,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer, 'filestype'?: string, 'filename'?: string}|false + */ + function check_data_from_form() { + $id = filter_input(INPUT_POST, "id"); + $p2p = filter_input(INPUT_POST, "p2p"); + $uncompress = filter_input(INPUT_POST, "uncompress"); + $retentionDuration = filter_input(INPUT_POST, "p2p-retention-duration"); + // And for files from server only + $filestype = filter_input(INPUT_POST, "filestype"); + $filename = filter_input(INPUT_POST, "filename"); + + if ( + is_null($id) || $id === false || !is_numeric($id) || + is_null($retentionDuration) || $retentionDuration === false || !is_numeric($retentionDuration) + ) { + return false; + } + if (is_null($p2p)) { + $p2p = 0; + } + if (is_null($uncompress)) { + $uncompress = 0; + } + + if (intval($p2p) > 1) { + $p2p = 0; + } + if (intval($uncompress) > 1) { + $uncompress = 0; + } + + $data = [ + 'id' => intval($id), + 'p2p' => intval($p2p), + 'uncompress' => intval($uncompress), + 'p2p-retention-duration' => intval($retentionDuration) + ]; + + if (!is_null($filestype) && $filestype === 'Server') { + if (is_null($filename) || $filename === false || empty($filename)) { + return false; + } + $data['filestype'] = 'Server'; + $data['filename'] = $filename; + } + return $data; + } + /** * Add a new item in files of the package * - * @param mixed[] $params list of fields with value of the file + * @param array{'id': integer,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer, 'filestype'?: string, 'filename'?: string} $params list of fields with value of the file * @return boolean */ function add_item($params) { - if ($params['filestype'] == 'Server') { + if (isset($params['filestype']) && $params['filestype'] == 'Server') { return $this->uploadFileFromServer($params); } // other cases @@ -514,7 +565,7 @@ function add_item($params) { /** * Remove an item * - * @param mixed[] $params + * @param array{'id': integer,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer, 'filestype': string, 'filename': string} $params * @return boolean */ function remove_item($params) { @@ -590,86 +641,87 @@ function save_item($params) { /** * Upload file from user computer * - * @param mixed[] $params + * @param array{'id': integer,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer, 'filestype': string, 'filename': string} $params * @return boolean */ function uploadFileFromComputer($params) { - if (isset($params["id"])) { + //file uploaded? + if (isset($_FILES['file']['tmp_name']) + && !empty($_FILES['file']['tmp_name'])) { + $file_tmp_name = $_FILES['file']['tmp_name']; + } else { + Session::addMessageAfterRedirect(__('File missing', 'fusioninventory')); + return false; + } + if (isset($_FILES['file']['name']) + && !empty($_FILES['file']['name'])) { + $filename = $_FILES['file']['name']; + } else { + Session::addMessageAfterRedirect(__('File missing', 'fusioninventory')); + return false; + } - //file uploaded? - if (isset($_FILES['file']['tmp_name']) - && !empty($_FILES['file']['tmp_name'])) { - $file_tmp_name = $_FILES['file']['tmp_name']; - } - if (isset($_FILES['file']['name']) - && !empty($_FILES['file']['name'])) { - $filename = $_FILES['file']['name']; - } + $msg = ''; - //file upload errors - if (isset($_FILES['file']['error'])) { - $error = true; - switch ($_FILES['file']['error']) { + //file upload errors + if (isset($_FILES['file']['error'])) { + $error = true; + switch ($_FILES['file']['error']) { - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - $msg = __("Transfer error: the file size is too big", 'fusioninventory'); - break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $msg = __("Transfer error: the file size is too big", 'fusioninventory'); + break; - case UPLOAD_ERR_PARTIAL: - $msg = __("The uploaded file was only partially uploaded", 'fusioninventory'); - break; + case UPLOAD_ERR_PARTIAL: + $msg = __("The uploaded file was only partially uploaded", 'fusioninventory'); + break; - case UPLOAD_ERR_NO_FILE: - $msg = __("No file was uploaded", 'fusioninventory'); - break; + case UPLOAD_ERR_NO_FILE: + $msg = __("No file was uploaded", 'fusioninventory'); + break; - case UPLOAD_ERR_NO_TMP_DIR: - $msg = __("Missing a temporary folder", 'fusioninventory'); - break; + case UPLOAD_ERR_NO_TMP_DIR: + $msg = __("Missing a temporary folder", 'fusioninventory'); + break; - case UPLOAD_ERR_CANT_WRITE: - $msg = __("Failed to write file to disk", 'fusioninventory'); - break; + case UPLOAD_ERR_CANT_WRITE: + $msg = __("Failed to write file to disk", 'fusioninventory'); + break; - case UPLOAD_ERR_EXTENSION: - $msg = __("PHP extension stopped the file upload", 'fusioninventory'); - break; + case UPLOAD_ERR_EXTENSION: + $msg = __("PHP extension stopped the file upload", 'fusioninventory'); + break; - case UPLOAD_ERR_OK: - //no error, continue - $error = false; + case UPLOAD_ERR_OK: + //no error, continue + $error = false; - } - if ($error) { - Session::addMessageAfterRedirect($msg); - return false; - } } - - //prepare file data for insertion in repo - $data = [ - 'id' => $params['id'], - 'file_tmp_name' => $file_tmp_name, - 'mime_type' => $_FILES['file']['type'], - 'filesize' => $_FILES['file']['size'], - 'filename' => $filename, - 'p2p' => isset($params['p2p']) ? $params['p2p'] : 0, - 'uncompress' => isset($params['uncompress']) ? $params['uncompress'] : 0, - 'p2p-retention-duration' => (is_numeric($params['p2p-retention-duration']) - ? $params['p2p-retention-duration']: 0) - ]; - - //Add file in repo - if ($filename && $this->addFileInRepo($data)) { - Session::addMessageAfterRedirect(__('File saved!', 'fusioninventory')); - return true; - } else { - Session::addMessageAfterRedirect(__('Failed to copy file', 'fusioninventory')); + if ($error) { + Session::addMessageAfterRedirect($msg); return false; } } - Session::addMessageAfterRedirect(__('File missing', 'fusioninventory')); + + //prepare file data for insertion in repo + $data = [ + 'id' => $params['id'], + 'file_tmp_name' => $file_tmp_name, + 'mime_type' => $_FILES['file']['type'], + 'filesize' => $_FILES['file']['size'], + 'filename' => $filename, + 'p2p' => $params['p2p'], + 'uncompress' => $params['uncompress'], + 'p2p-retention-duration' => $params['p2p-retention-duration'] + ]; + + //Add file in repo + if ($this->addFileInRepo($data)) { + Session::addMessageAfterRedirect(__('File saved!', 'fusioninventory')); + return true; + } + Session::addMessageAfterRedirect(__('Failed to copy file', 'fusioninventory')); return false; } @@ -677,55 +729,44 @@ function uploadFileFromComputer($params) { /** * Upload file from temp folder in server * - * @param mixed[] $params + * @param array{'id': integer,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer, 'filestype': string, 'filename': string} $params * @return boolean */ function uploadFileFromServer($params) { - if (preg_match('/\.\./', $params['filename'])) { die; } + $mime_type = false; + $file_path = $params['filename']; + $filename = basename($file_path); + if (function_exists('finfo_open') + && ($finfo = finfo_open(FILEINFO_MIME))) { + $mime_type = finfo_file($finfo, $file_path); + finfo_close($finfo); + + } else if (function_exists('mime_content_type')) { + $mime_type = mime_content_type($file_path); + } + $filesize = filesize($file_path); + + //prepare file data for insertion in repo + $data = [ + 'file_tmp_name' => $file_path, + 'mime_type' => $mime_type, + 'filesize' => $filesize, + 'filename' => $filename, + 'p2p' => $params['p2p'], + 'uncompress' => $params['uncompress'], + 'p2p-retention-duration' => $params['p2p-retention-duration'], + 'id' => $params['id'] + ]; - if (isset($params["id"])) { - $file_path = $params['filename']; - $filename = basename($file_path); - if (function_exists('finfo_open') - && ($finfo = finfo_open(FILEINFO_MIME))) { - $mime_type = finfo_file($finfo, $file_path); - finfo_close($finfo); - - } else if (function_exists('mime_content_type')) { - $mime_type = mime_content_type($file_path); - } - $filesize = filesize($file_path); - - //prepare file data for insertion in repo - $data = [ - 'file_tmp_name' => $file_path, - 'mime_type' => $mime_type, - 'filesize' => $filesize, - 'filename' => $filename, - 'p2p' => isset($params['p2p']) ? $params['p2p'] : 0, - 'uncompress' => isset($params['uncompress']) ? $params['uncompress'] : 0, - 'p2p-retention-duration' => ( - isset($params['p2p-retention-duration']) - && is_numeric($params['p2p-retention-duration']) - ? $params['p2p-retention-duration'] - : 0 - ), - 'id' => $params['id'] - ]; - - //Add file in repo - if ($filename && $this->addFileInRepo($data)) { - Session::addMessageAfterRedirect(__('File saved!', 'fusioninventory')); - return true; - } else { - Session::addMessageAfterRedirect(__('Failed to copy file', 'fusioninventory')); - return false; - } + //Add file in repo + if ($filename && $this->addFileInRepo($data)) { + Session::addMessageAfterRedirect(__('File saved!', 'fusioninventory')); + return true; } - Session::addMessageAfterRedirect(__('File missing', 'fusioninventory')); + Session::addMessageAfterRedirect(__('Failed to copy file', 'fusioninventory')); return false; } @@ -788,7 +829,7 @@ function registerFilepart ($filePath, $skip_creation = false) { /** * Add file in the fusioninventory repository * - * @param mixed[] $params + * @param array{'id': integer,'file_tmp_name': string,'mime_type': string,'filesize': integer,'filename': string,'p2p': integer,'uncompress': integer,'p2p-retention-duration': integer} $params * @return boolean */ function addFileInRepo($params) { diff --git a/inc/deploypackage.class.php b/inc/deploypackage.class.php index 07d0987ba..7b90260ba 100644 --- a/inc/deploypackage.class.php +++ b/inc/deploypackage.class.php @@ -713,46 +713,6 @@ function showDebug() { } - /** - * Update the json structure - * - * @param string $action_type type of action - * @param mixed[] $params data used to update the json - * @return void - */ - static function alterJSON($action_type, $params) { - //route to sub class - $item_type = $params['itemtype']; - - if (in_array($item_type, [ - 'PluginFusioninventoryDeployCheck', - 'PluginFusioninventoryDeployFile', - 'PluginFusioninventoryDeployAction', - 'PluginFusioninventoryDeployUserinteraction' - ])) { - $class = new $item_type(); - switch ($action_type) { - - case "add_item" : - return $class->add_item($params); - - case "save_item" : - return $class->save_item($params); - - case "remove_item" : - return $class->remove_item($params); - - case "move_item" : - return $class->move_item($params); - - } - } else { - Toolbox::logDebug("package subtype not found : " . $params['itemtype']); - Html::displayErrorAndDie ("package subtype not found"); - } - } - - /** * Export the package (information, actions, files...) * diff --git a/inc/deployuserinteraction.class.php b/inc/deployuserinteraction.class.php index db1cd660d..f3e6b6ba4 100644 --- a/inc/deployuserinteraction.class.php +++ b/inc/deployuserinteraction.class.php @@ -328,30 +328,53 @@ function getInteractionDescription($interaction) { /** - * Add a new item in checks of the package - * - * @param mixed[] $params list of fields with value of the check - * @return boolean + * Clean data of package form + * @return array{'id': integer, 'type': string, 'name': string, 'title': string, 'text': string, 'template': integer}|false */ - function add_item($params) { - if (!isset($params['text'])) { - $params['text'] = ""; + function check_data_from_form() { + $id = filter_input(INPUT_POST, "id"); + $type = filter_input(INPUT_POST, "userinteractionstype"); + $name = filter_input(INPUT_POST, "name"); + $title = filter_input(INPUT_POST, "title"); + $text = filter_input(INPUT_POST, "text"); + $template = filter_input(INPUT_POST, "template"); + + if ( + is_null($id) || $id === false || !is_numeric($id) || + is_null($type) || $type === false || + is_null($name) || $name === false || + is_null($title) || $title === false || empty($title) || + is_null($text) || $text === false || + is_null($template) || $template === false || !is_numeric($template) + ) { + return false; } - if (!isset($params['template'])) { - $params['template'] = 0; + + // Need a template for a user interaction + if (intval($template) == 0) { + return false; } - //prepare new check entry to insert in json - $entry = [ - 'name' => $params['name'], - 'title' => $params['title'], - 'text' => $params['text'], - 'type' => $params['userinteractionstype'], - 'template' => $params['template'] + return [ + 'id' => intval($id), + 'type' => $type, + 'name' => $name, + 'title' => $title, + 'text' => str_replace('\r\n', PluginFusioninventoryDeployUserinteraction::RN_TRANSFORMATION, $text), + 'template' => intval($template) ]; + } + + /** + * Add a new item in checks of the package + * + * @param array{'id': integer, 'type': string, 'name': string, 'title': string, 'text': string, 'template': integer} $params list of fields with value of the check + * @return boolean + */ + function add_item($params) { //Add to package defintion - return $this->addToPackage($params['id'], $entry, 'userinteractions'); + return $this->addToPackage($params['id'], $params, 'userinteractions'); } diff --git a/inc/inventorycomputerinventory.class.php b/inc/inventorycomputerinventory.class.php index 0225e0a66..728a8ead8 100644 --- a/inc/inventorycomputerinventory.class.php +++ b/inc/inventorycomputerinventory.class.php @@ -72,16 +72,14 @@ class PluginFusioninventoryInventoryComputerInventory { * import data * * @global object $DB - * @global mixed[] $CFG_GLPI * @param string $p_DEVICEID * @param mixed[] $a_CONTENT * @param mixed[] $arrayinventory - * @return string errors + * @return void */ function import($p_DEVICEID, $a_CONTENT, $arrayinventory) { - global $DB, $CFG_GLPI; + global $DB; - $errors = ''; $_SESSION["plugin_fusioninventory_entity"] = -1; // Prevent 2 computers with same name (Case of have the computer inventory 2 times in same time @@ -105,8 +103,6 @@ function import($p_DEVICEID, $a_CONTENT, $arrayinventory) { 'value' => $name ] ); - - return $errors; } diff --git a/inc/taskjob.class.php b/inc/taskjob.class.php index 06fd33286..dd8940dde 100644 --- a/inc/taskjob.class.php +++ b/inc/taskjob.class.php @@ -173,57 +173,6 @@ function getTask() { } - /** - * Display definitions type dropdown - * - * @global array $CFG_GLPI - * @param string $myname - * @param string $method - * @param integer $value - * @param integer $taskjobs_id - * @param string $entity_restrict - * @return string unique id of html element - */ - function dropdownType($myname, $method, $value = 0, $taskjobs_id = 0, $entity_restrict = '') { - global $CFG_GLPI; - - $a_methods = PluginFusioninventoryStaticmisc::getmethods(); - $a_type = []; - $a_type[''] = Dropdown::EMPTY_VALUE; - if ($myname == 'action') { - $a_type['PluginFusioninventoryAgent'] = PluginFusioninventoryAgent::getTypeName(); - } - foreach ($a_methods as $datas) { - if ($method == $datas['method']) { - $module = $datas['module']; - $class = PluginFusioninventoryStaticmisc::getStaticMiscClass($module); - if (is_callable([$class, "task_".$myname."type_".$method])) { - $a_type = call_user_func([$class, "task_".$myname."type_".$method], $a_type); - } - } - } - - $rand = Dropdown::showFromArray(ucfirst($myname)."Type", $a_type); - - $params=[ucfirst($myname).'Type'=>'__VALUE__', - 'entity_restrict' => $entity_restrict, - 'rand' => $rand, - 'myname' => ucfirst($myname)."Type", - 'name' => $myname, - 'method' => $method, - $myname.'typeid' => 'dropdown_'.ucfirst($myname).'Type'.$rand, - 'taskjobs_id' => $taskjobs_id]; - - Ajax::updateItemOnEvent( - 'dropdown_'.ucfirst($myname).'Type'.$rand, - "show_".ucfirst($myname)."List".$taskjobs_id, - Plugin::getWebDir('fusioninventory')."/ajax/dropdowntypelist.php", - $params); - - return $rand; - } - - /** * Get Itemtypes list for the selected method * @@ -336,53 +285,6 @@ function dropdownvalue($myname, $definitiontype, $method, $deftypeid, $taskjobs_ } - /** - * Display actions type (itemtypes) - * - * @global array $CFG_GLPI - * @param string $myname name of dropdown - * @param string $method name of the method selected - * @param string $entity_restrict restriction of entity if required - * @return string unique id of html element - */ - function dropdownActionType($myname, $method, $entity_restrict = '') { - global $CFG_GLPI; - - $a_methods = PluginFusioninventoryStaticmisc::getmethods(); - $a_actioninitiontype = []; - $a_actioninitiontype[''] = Dropdown::EMPTY_VALUE; - $a_actioninitiontype['PluginFusioninventoryAgent'] - = PluginFusioninventoryAgent::getTypeName(); - foreach ($a_methods as $datas) { - if ($method == $datas['method']) { - $module = ucfirst($datas['module']); - $class = PluginFusioninventoryStaticmisc::getStaticMiscClass($module); - - if (is_callable([$class, "task_actiontype_".$method])) { - $a_actioninitiontype = call_user_func([$class, "task_actiontype_".$method], - $a_actioninitiontype); - } - } - } - - $rand = Dropdown::showFromArray($myname, $a_actioninitiontype); - - $params=['ActionType'=>'__VALUE__', - 'entity_restrict'=>$entity_restrict, - 'rand'=>$rand, - 'myname'=>$myname, - 'method'=>$method, - 'actiontypeid'=>'dropdown_'.$myname.$rand - ]; - Ajax::updateItemOnSelectEvent('dropdown_ActionType'.$rand, - "show_ActionList", - Plugin::getWebDir('fusioninventory')."/ajax/dropdownactionlist.php", - $params); - - return $rand; - } - - /** * Display actions value with preselection of action type * @@ -1015,43 +917,6 @@ function additemtodefatc($type, $itemtype, $items_id, $taskjobs_id) { } - /** - * Function used to delete item in definition or action of a taskjob - * and hide add form - * and refresh type list - * - * @global mixed[] $CFG_GLPI - * @param string $type - * @param string $a_items_id - * @param integer $taskjobs_id - * @return void - */ - function deleteitemtodefatc($type, $a_items_id, $taskjobs_id) { - global $CFG_GLPI; - - $this->getFromDB($taskjobs_id); - $a_type = importArrayFromDB($this->fields[$type]); - $split = explode("-", $a_items_id); - foreach ($split as $key) { - unset($a_type[$key]); - } - $input = []; - $input['id'] = $this->fields['id']; - $input[$type] = exportArrayToDB($a_type); - $this->update($input); - - // reload item list - $params = []; - $params['taskjobs_id'] = $taskjobs_id; - $params['typename'] = $type; - echo ""; - } - - /** * Display + button to add definition or action * diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..fb2d9d84b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +parameters: + level: 6 + paths: + - inc + - hook.php + - setup.php + - ajax + - front + - install + scanDirectories: + - ../../inc + - ../../front + - ../../ajax diff --git a/tests/Integration/Deploy/RepositoryTest.php b/tests/Integration/Deploy/RepositoryTest.php index d34d6b547..57bfcaf32 100644 --- a/tests/Integration/Deploy/RepositoryTest.php +++ b/tests/Integration/Deploy/RepositoryTest.php @@ -99,7 +99,8 @@ public function cleanFiles() { 'filestype' => 'Server', 'filename' => $this->filename, ]; - $ret = PluginFusioninventoryDeployPackage::alterJSON('add_item', $data_file); + // check data is correct + $ret = $pfDeployFile->add_item($data_file); $this->assertTrue($ret, 'File not right added'); // check json of the package @@ -122,7 +123,7 @@ public function cleanFiles() { // add the same file to the second package $data_file['id'] = $this->packages_2_id; - PluginFusioninventoryDeployPackage::alterJSON('add_item', $data_file); + $pfDeployFile->add_item($data_file); // remove file from the first package $data_file = [ @@ -130,7 +131,7 @@ public function cleanFiles() { 'itemtype' => 'PluginFusioninventoryDeployFile', 'file_entries' => [0 => 1] ]; - PluginFusioninventoryDeployPackage::alterJSON('remove_item', $data_file); + $pfDeployFile->remove_item($data_file); // check json of the package $pfDeployPackage->getFromDB($this->packages_1_id); @@ -147,7 +148,7 @@ public function cleanFiles() { 'itemtype' => 'PluginFusioninventoryDeployFile', 'file_entries' => [0 => 1] ]; - PluginFusioninventoryDeployPackage::alterJSON('remove_item', $data_file); + $pfDeployFile->remove_item($data_file); // check json of the package $pfDeployPackage->getFromDB($this->packages_2_id); @@ -178,9 +179,9 @@ public function cleanPackage() { 'filestype' => 'Server', 'filename' => $this->filename, ]; - PluginFusioninventoryDeployPackage::alterJSON('add_item', $data_file); + $pfDeployFile->add_item($data_file); $data_file['id'] = $this->packages_2_id; - PluginFusioninventoryDeployPackage::alterJSON('add_item', $data_file); + $pfDeployFile->add_item($data_file); // remove a package and check presence of file $pfDeployPackage->delete([ diff --git a/tests/Unit/Deploy/PackageJsonTest.php b/tests/Unit/Deploy/PackageJsonTest.php index a91df5f2a..613f14288 100644 --- a/tests/Unit/Deploy/PackageJsonTest.php +++ b/tests/Unit/Deploy/PackageJsonTest.php @@ -67,6 +67,7 @@ public function JsonCreateNewPackage() { */ public function AddItem() { $pfDeployPackage = new PluginFusioninventoryDeployPackage(); + $pfDeployCheck = new PluginFusioninventoryDeployCheck(); $input = [ 'name' => 'test2', 'entities_id' => 0 @@ -83,7 +84,7 @@ public function AddItem() { 'return' => 'error', 'add_item' => 'Add' ]; - PluginFusioninventoryDeployPackage::alterJSON('add_item', $item); + $pfDeployCheck->add_item($item); $pfDeployPackage->getFromDB($packages_id); $json_structure = '{"jobs":{"checks":[{"name":"check winkey","type":"winkeyExists","path":"toto","value":"","return":"error"}],"associatedFiles":[],"actions":[],"userinteractions":[]},"associatedFiles":[]}';