diff --git a/CHANGELOG.md b/CHANGELOG.md index 718fff52..89f98538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [UNRELEASED] + +### Fixed + +- Escape chart labels before injecting them into report graphs +- Cast state filter values before building SQL + +### Removed + +- Remove the logs activity report to prevent cross-entity data display + ## [1.10.1] - 2026-08-04 ### Fixed diff --git a/hook.php b/hook.php index 32e63953..5d3984b1 100644 --- a/hook.php +++ b/hook.php @@ -248,6 +248,21 @@ function plugin_mreporting_install() ); $migration->migrationOneTable('glpi_plugin_mreporting_dashboards'); + // == Remove the logs activity report (instance-wide counts, no entity restriction) + $logs_report = $DB->request([ + 'SELECT' => 'id', + 'FROM' => 'glpi_plugin_mreporting_configs', + 'WHERE' => [ + 'classname' => 'PluginMreportingOther', + 'name' => 'reportHbarLogs', + ], + ]); + foreach ($logs_report as $report) { + $DB->delete('glpi_plugin_mreporting_profiles', ['reports' => $report['id']]); + $DB->delete('glpi_plugin_mreporting_dashboards', ['reports_id' => $report['id']]); + $DB->delete('glpi_plugin_mreporting_configs', ['id' => $report['id']]); + } + // == Init available reports require_once __DIR__ . '/inc/baseclass.class.php'; require_once __DIR__ . '/inc/common.class.php'; diff --git a/inc/config.class.php b/inc/config.class.php index 5af5f6e1..52a77636 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -341,7 +341,7 @@ public function createFirstConfig() $input = []; if ($classConfig) { // If a preconfig exists in class we do it - /** @var null|PluginMreportingOther|PluginMreportingHelpdesk $classObject */ + /** @var null|PluginMreportingHelpdesk $classObject */ $input = $classObject->preconfig($funct_name, $classname, $this); } else {// Else we get the default preconfig $input = $this->preconfig($funct_name, $classname); diff --git a/inc/graph.class.php b/inc/graph.class.php index 528f3d6f..c03b80d5 100644 --- a/inc/graph.class.php +++ b/inc/graph.class.php @@ -1835,18 +1835,9 @@ public function initDatasSimple($datas, $unit = '', $links = []) $out = substr($out, 0, -2) . "\n"; $out .= "];\n"; - $out .= "var labels = [\n"; - foreach ($labels as $label) { - $out .= "\t'" . $label . "',\n"; - } - $out = substr($out, 0, -2) . "\n"; - $out .= "];\n"; + $out .= 'var labels = ' . json_encode($labels, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) . ";\n"; - $out .= "var links = [\n"; - foreach ($links as $link) { - $out .= "\t'" . $link . "',\n"; - } - $out .= "];\n"; + $out .= 'var links = ' . json_encode($links, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) . ";\n"; echo $out; $max = count($values) > 0 ? max($values) * 1.1 : 1; @@ -1915,19 +1906,9 @@ public function initDatasMultiple($datas, $labels2, $unit = '', $stacked = false $out = substr($out, 0, -2) . "\n"; $out .= "];\n"; - $out .= "var labels = [\n"; - foreach ($labels as $label) { - $out .= "\t'" . $label . "',\n"; - } - $out = substr($out, 0, -2) . "\n"; - $out .= "];\n"; + $out .= 'var labels = ' . json_encode($labels, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) . ";\n"; - $out .= "var labels2 = [\n"; - foreach ($labels2 as $label) { - $out .= "\t'" . $label . "',\n"; - } - $out = substr($out, 0, -2) . "\n"; - $out .= "];\n"; + $out .= 'var labels2 = ' . json_encode($labels2, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) . ";\n"; echo $out; if (!$stacked) { diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index 96bff60d..d8597c0b 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -171,6 +171,10 @@ public function generateImage($params) $params = array_merge($default_params, $params); + if ($params['f_name'] !== '' && !preg_match('/^[A-Za-z0-9_]+$/', $params['f_name'])) { + $params['f_name'] = ''; + } + ob_start(); if ($params['export'] == 'odt') { diff --git a/inc/inventory.class.php b/inc/inventory.class.php index de30da4d..15527366 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -94,13 +94,13 @@ public static function getStateCondition($field, $as_array = false) if ($as_array) { $sql_states[$field] = $_SESSION['mreporting_values']['states_id']; } else { - $sql_states = " AND $field IN (" . implode(',', $_SESSION['mreporting_values']['states_id']) . ')'; + $sql_states = " AND $field IN (" . implode(',', array_map('intval', $_SESSION['mreporting_values']['states_id'])) . ')'; } } elseif ($_SESSION['mreporting_values']['states_id'] > 0) { if ($as_array) { $sql_states[$field] = $_SESSION['mreporting_values']['states_id']; } else { - $sql_states = " AND $field = " . $_SESSION['mreporting_values']['states_id']; + $sql_states = " AND $field = " . (int) $_SESSION['mreporting_values']['states_id']; } } } diff --git a/inc/other.class.php b/inc/other.class.php deleted file mode 100644 index c45b3bbb..00000000 --- a/inc/other.class.php +++ /dev/null @@ -1,272 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -use Glpi\DBAL\QueryExpression; - -class PluginMreportingOther extends PluginMreportingBaseclass -{ - public function reportHbarLogs($configs = []) - { - /** @var DBmysql $DB */ - global $DB; - - //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - '`glpi_tickets`.`date`', - $configs['delay'], - $configs['randname'], - ); - - $prefix = 'SELECT COUNT(*) AS cpt FROM `glpi_logs` WHERE '; - $prefix2 = [ - 'COUNT' => 'cpt', - 'FROM' => Log::getTable(), - ]; - - //Add/remove a software on a computer - $query_computer_software = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.linked_action' => [4, 5], - ], - ], - ); - - $query_software_version = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.itemtype' => 'Software', - Log::getTable() . '.itemtype_link' => 'SoftwareVersion', - Log::getTable() . '.linked_action' => [17, 18, 19], - ], - ], - ); - - $query_add_infocom = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.itemtype' => 'Software', - Log::getTable() . '.itemtype_link' => 'Infocom', - Log::getTable() . '.linked_action' => [17], - ], - ], - ); - - $query_user_profiles = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.itemtype' => 'User', - Log::getTable() . '.itemtype_link' => 'Profile_User', - Log::getTable() . '.linked_action' => [17, 18, 19], - ], - ], - ); - - $query_user_groups = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.itemtype' => 'User', - Log::getTable() . '.itemtype_link' => 'Group_User', - Log::getTable() . '.linked_action' => [17, 18, 19], - ], - ], - ); - - $query_user_deleted = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.itemtype' => 'User', - Log::getTable() . '.linked_action' => [12], - ], - ], - ); - - $query_ocs = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.linked_action' => [8, 9, 10, 11], - ], - ], - ); - - $query_device = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.linked_action' => [1, 2, 3, 6, 7], - ], - ], - ); - - $query_relation = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.linked_action' => [15, 16], - ], - ], - ); - - $query_item = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.linked_action' => [13, 14, 17, 18, 19, 20], - ], - ], - ); - - $query_other = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . '.id_search_option' => [16, 19], - ], - ], - ); - - $datas = []; - - $result = $DB->request($query_computer_software); - $datas['datas'][__s('Add/remove software on a computer', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_software_version); - $datas['datas'][__s('Add/remove version on a software', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_add_infocom); - $datas['datas'][__s('Add infocom', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_user_profiles); - $datas['datas'][__s('Add/remove profile on a user', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_user_groups); - $datas['datas'][__s('Add/remove group on a user', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_user_deleted); - $datas['datas'][__s('User deleted from LDAP', 'mreporting')] = $result->current()['cpt']; - - $plugin = new Plugin(); - if ($plugin->isActivated('webservices')) { - $query_webservice = "$prefix `itemtype`='PluginWebservicesClient'"; - $query_webservice = array_merge( - $prefix2, - [ - 'WHERE' => [ - Log::getTable() . ".itemtype = 'PluginWebservicesClient'", - ], - ], - ); - - // Display this information is not usefull if webservices is not activated - $result = $DB->request($query_webservice); - $datas['datas'][__s('Webservice logs', 'mreporting')] = $result->current()['cpt']; - } - - $result = $DB->request($query_ocs); - $datas['datas'][__s('OCS Infos', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_device); - $datas['datas'][__s('Add/update/remove device', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_relation); - $datas['datas'][__s('Add/remove relation', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_item); - $datas['datas'][__s('Add/remove item', 'mreporting')] = $result->current()['cpt']; - - $result = $DB->request($query_other); - $datas['datas'][__s('Comments & date_mod changes', 'mreporting')] = $result->current()['cpt']; - - $plugin = new Plugin(); - if ($plugin->isActivated('genericobject')) { - $query_genericobject = array_merge( - $prefix2, - [ - 'WHERE' => [ - new QueryExpression( - Log::getTable() . ".itemtype LIKE '%PluginGenericobject%'", - ), - ], - ], - ); - - // Display this information is not usefull if genericobject is not activated - $result = $DB->request($query_genericobject); - $datas['datas'][__s('Genericobject plugin logs', 'mreporting')] = $result->current()['cpt']; - } - - return $datas; - } - - /** - * Preconfig datas with your values when init config is done - * - * @param string|int $funct_name - * @param string $classname - * @param PluginMreportingConfig $config - * @return array|boolean $config - */ - public function preconfig($funct_name, $classname, PluginMreportingConfig $config) - { - if ($funct_name != -1 && $classname) { - $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name); - if ($ex_func[0] != 'report') { - return false; - } - $gtype = strtolower($ex_func[1]); - - switch ($gtype) { - case 'pie': - $config->fields['name'] = $funct_name; - $config->fields['classname'] = $classname; - $config->fields['is_active'] = '1'; - $config->fields['show_label'] = 'hover'; - $config->fields['spline'] = '0'; - $config->fields['show_area'] = '0'; - $config->fields['show_graph'] = '1'; - $config->fields['default_delay'] = '30'; - $config->fields['show_label'] = 'hover'; - break; - default: - $config->preconfig($funct_name, $classname); - break; - } - } - - return $config->fields; - } -} diff --git a/locales/reports_locales/other_cs_CZ.php b/locales/reports_locales/other_cs_CZ.php deleted file mode 100644 index c0c29cdd..00000000 --- a/locales/reports_locales/other_cs_CZ.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Ostatní', - - 'reportHbarLogs' => [ - 'title' => 'Rozložení záznamů událostí', - 'desc' => 'Pruhový', - 'category' => 'Záznamy událostí (log)', - ], -]; diff --git a/locales/reports_locales/other_de_DE.php b/locales/reports_locales/other_de_DE.php deleted file mode 100644 index b21d92ac..00000000 --- a/locales/reports_locales/other_de_DE.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Weiteres', - - 'reportHbarLogs' => [ - 'title' => 'Log-Verteilung', - 'desc' => 'Bars', - 'category' => 'Logs', - ], -]; diff --git a/locales/reports_locales/other_en_GB.php b/locales/reports_locales/other_en_GB.php deleted file mode 100644 index 27040768..00000000 --- a/locales/reports_locales/other_en_GB.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Other', - - 'reportHbarLogs' => [ - 'title' => 'Logs distribution', - 'desc' => 'Bars', - 'category' => 'Logs', - ], -]; diff --git a/locales/reports_locales/other_es_VE.php b/locales/reports_locales/other_es_VE.php deleted file mode 100644 index 7a2cd6b1..00000000 --- a/locales/reports_locales/other_es_VE.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Otro', - - 'reportHbarLogs' => [ - 'title' => 'Distribución de eventos', - 'desc' => 'Barras', - 'category' => 'Eventos', - ], -]; diff --git a/locales/reports_locales/other_fr_FR.php b/locales/reports_locales/other_fr_FR.php deleted file mode 100644 index b25a0872..00000000 --- a/locales/reports_locales/other_fr_FR.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Autres', - - 'reportHbarLogs' => [ - 'title' => 'Répartition des logs', - 'desc' => 'Barres', - 'category' => 'Logs', - ], -]; diff --git a/locales/reports_locales/other_hr_HR.php b/locales/reports_locales/other_hr_HR.php deleted file mode 100644 index a89334e4..00000000 --- a/locales/reports_locales/other_hr_HR.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Ostalo', - - 'reportHbarLogs' => [ - 'title' => 'Log-zapisi', - 'desc' => 'Stupci', - 'category' => 'Log-zapisi', - ], -]; diff --git a/locales/reports_locales/other_pl_PL.php b/locales/reports_locales/other_pl_PL.php deleted file mode 100644 index 4779442e..00000000 --- a/locales/reports_locales/other_pl_PL.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Inne', - - 'reportHbarLogs' => [ - 'title' => 'Statystyka logów', - 'desc' => 'wykres słupkowy', - 'category' => 'Logi', - ], -]; diff --git a/locales/reports_locales/other_pt_BR.php b/locales/reports_locales/other_pt_BR.php deleted file mode 100644 index 9526baf2..00000000 --- a/locales/reports_locales/other_pt_BR.php +++ /dev/null @@ -1,36 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other']['title'] = 'Outros'; -$LANG['plugin_mreporting']['Other']['reportHbarLogs']['title'] = 'Distribuição de logs'; -$LANG['plugin_mreporting']['Other']['reportHbarLogs']['desc'] = 'Barras'; -$LANG['plugin_mreporting']['Other']['reportHbarLogs']['category'] = 'Logs'; diff --git a/locales/reports_locales/other_pt_PT.php b/locales/reports_locales/other_pt_PT.php deleted file mode 100644 index 2a278c70..00000000 --- a/locales/reports_locales/other_pt_PT.php +++ /dev/null @@ -1,39 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Outros', - 'reportHbarLogs' => [ - 'title' => 'Distribuição de Registros', - 'desc' => 'Barras', - 'category' => 'Registros', - ], -]; diff --git a/locales/reports_locales/other_ru_RU.php b/locales/reports_locales/other_ru_RU.php deleted file mode 100644 index ad4b5e53..00000000 --- a/locales/reports_locales/other_ru_RU.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Другое', - - 'reportHbarLogs' => [ - 'title' => 'Информация по логам', - 'desc' => 'Горизонтальная диаграмма', - 'category' => 'Логи', - ], -]; diff --git a/locales/reports_locales/other_sk_SK.php b/locales/reports_locales/other_sk_SK.php deleted file mode 100644 index c00c902a..00000000 --- a/locales/reports_locales/other_sk_SK.php +++ /dev/null @@ -1,41 +0,0 @@ -. - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2003-2023 by Mreporting plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/mreporting - * ------------------------------------------------------------------------- - */ - -global $LANG; - -$LANG['plugin_mreporting']['Other'] = [ - 'title' => 'Iné', - - 'reportHbarLogs' => [ - 'title' => 'Distribúcia logov', - 'desc' => 'Pruhový', - 'category' => 'Logy', - ], -];