From 902e8589f38357b1a3cdc6e04542d2169986da74 Mon Sep 17 00:00:00 2001 From: samucarc Date: Tue, 29 Jan 2019 15:30:04 +0100 Subject: [PATCH 01/25] Apply a policy into an agent with CLI Former-commit-id: 87037688b1dd3a551c0585319ec545c855484a97 --- pandora_server/util/pandora_manage.pl | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 05547a779f..2dd9ee14c4 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -196,7 +196,7 @@ sub help_screen{ print "\nINCIDENTS:\n\n" unless $param ne ''; help_screen_line('--create_incident', " <description> <origin> <status> <priority 0 for Informative, \n\t 1 for Low, 2 for Medium, 3 for Serious, 4 for Very serious or 5 for Maintenance>\n\t <group> [<owner>]", 'Create incidents'); print "\nPOLICIES:\n\n" unless $param ne ''; - help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy'); + help_screen_line('--apply_policy', '<id_policy> [<id_agent> <return> <name agent>]', 'Force apply a policy'); help_screen_line('--apply_all_policies', '', 'Force apply to all the policies'); help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy'); help_screen_line('--remove_agent_from_policy', '<policy_id> <agent_id>', 'Delete an agent to a policy'); @@ -3509,19 +3509,11 @@ sub cli_delete_data($) { ############################################################################## sub cli_apply_policy() { - my $policy_name = @ARGV[2]; - - my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); - exist_check($policy_id,'policy',$policy_name); - - my $ret = enterprise_hook('pandora_add_policy_queue', [$dbh, $conf, $policy_id, 'apply']); - - if($ret == -1) { - print_log "[ERROR] Operation 'apply' cannot be added to policy '$policy_name' because is duplicated in queue or incompatible with others operations\n\n"; - exit; - } - - print_log "[INFO] Added operation 'apply' to policy '$policy_name'\n\n"; + my ($id_policy, $id_agent, $name, $return) = @ARGV[2..5]; + + # Call the API. + my $result = api_call(\%conf, 'set', 'apply_policy', $id_policy, $id_agent, "$name|$return"); + print "\n$result\n"; } ############################################################################## @@ -5918,7 +5910,7 @@ sub pandora_manage_main ($$$) { cli_delete_data($ltotal); } elsif ($param eq '--apply_policy') { - param_check($ltotal, 1); + param_check($ltotal, 4, 3); cli_apply_policy(); } elsif ($param eq '--disable_policy_alerts') { From 63d589c9188d24618ae364f9e330c36c796bd610 Mon Sep 17 00:00:00 2001 From: Daniel Maya <daniel.maya@artica.es> Date: Fri, 8 Feb 2019 11:34:47 +0100 Subject: [PATCH 02/25] Parameter changes deprecated in LDAP Former-commit-id: 2accf38ffe089c19475b1956cf04da7769dca2e9 --- pandora_console/include/auth/mysql.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index 69e848d805..8003275fbf 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -1369,8 +1369,7 @@ function local_ldap_search($ldap_host, $ldap_port=389, $ldap_version=3, $dn, $ac $tls = ' -ZZ '; } - $ldap_host = ' -h '.$ldap_host; - $ldap_port = ' -p '.$ldap_port; + $ldap_host = ' -H '.$ldap_host.':'.$ldap_port; $ldap_version = ' -P '.$ldap_version; if (!empty($ldap_admin_user)) { $ldap_admin_user = " -D '".$ldap_admin_user."'"; @@ -1382,7 +1381,7 @@ function local_ldap_search($ldap_host, $ldap_port=389, $ldap_version=3, $dn, $ac $dn = " -b '".$dn."'"; - $shell_ldap_search = explode("\n", shell_exec('ldapsearch -LLL -o ldif-wrap=no -x'.$ldap_host.$ldap_port.$ldap_version.' -E pr=10000/noprompt '.$ldap_admin_user.$ldap_admin_pass.$dn.$filter.$tls.' | grep -v "^#\|^$" | sed "s/:\+ /=>/g"')); + $shell_ldap_search = explode("\n", shell_exec('ldapsearch -LLL -o ldif-wrap=no -x'.$ldap_host.$ldap_version.' -E pr=10000/noprompt '.$ldap_admin_user.$ldap_admin_pass.$dn.$filter.$tls.' | grep -v "^#\|^$" | sed "s/:\+ /=>/g"')); foreach ($shell_ldap_search as $line) { $values = explode('=>', $line); if (!empty($values[0]) && !empty($values[1])) { From ffe8bba3f784ef392fdb6cd78be685e99e828ab4 Mon Sep 17 00:00:00 2001 From: Daniel Maya <daniel.maya@artica.es> Date: Fri, 15 Feb 2019 09:10:21 +0100 Subject: [PATCH 03/25] added exception in ldapsearch Former-commit-id: 4ab1637c30cac2bb4c827b1e08017f6b08fae1b9 --- pandora_console/include/auth/mysql.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index 8003275fbf..aab0b4c9e4 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -1369,7 +1369,12 @@ function local_ldap_search($ldap_host, $ldap_port=389, $ldap_version=3, $dn, $ac $tls = ' -ZZ '; } - $ldap_host = ' -H '.$ldap_host.':'.$ldap_port; + if (stripos($ldap_host, 'ldap') !== false) { + $ldap_host = ' -H '.$ldap_host.':'.$ldap_port; + } else { + $ldap_host = ' -h '.$ldap_host.' -p '.$ldap_port; + } + $ldap_version = ' -P '.$ldap_version; if (!empty($ldap_admin_user)) { $ldap_admin_user = " -D '".$ldap_admin_user."'"; From eb56fd566c41afa2ec2b517fae4230102892ccfb Mon Sep 17 00:00:00 2001 From: alejandro-campos <alejandro.campos@artica.es> Date: Fri, 22 Feb 2019 13:07:47 +0100 Subject: [PATCH 04/25] implemented services treeview Former-commit-id: d5d71442d0c6122ba91b160647559cdf03f55625 --- pandora_console/images/tree_events.png | Bin 0 -> 329 bytes pandora_console/images/tree_service_map.png | Bin 0 -> 401 bytes pandora_console/include/ajax/tree.ajax.php | 300 ++- pandora_console/include/class/Tree.class.php | 1819 ++++++++-------- .../include/class/TreeGroup.class.php | 786 ++++--- .../include/class/TreeGroupEdition.class.php | 184 +- .../include/class/TreeService.class.php | 342 +++ .../include/javascript/tree/TreeController.js | 1880 +++++++++-------- pandora_console/include/styles/pandora.css | 4 +- pandora_console/operation/events/events.php | 1 + pandora_console/operation/tree.php | 444 ++-- 11 files changed, 2973 insertions(+), 2787 deletions(-) create mode 100644 pandora_console/images/tree_events.png create mode 100644 pandora_console/images/tree_service_map.png create mode 100644 pandora_console/include/class/TreeService.class.php diff --git a/pandora_console/images/tree_events.png b/pandora_console/images/tree_events.png new file mode 100644 index 0000000000000000000000000000000000000000..7628d6a80d852ba73d65176446ae08840da77f7f GIT binary patch literal 329 zcmV-P0k-~$P)<h;3K|Lk000e1NJLTq000#L000#T1^@s6sTZY|0000PbVXQnQ*UN; zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBUy>q$gGRCwB~mC+4@AP|PpIDjK`1e@?q zSLh}>LF)wC4IBmEd0>M&f_?D4KM85bg(?D<Ttqy+{C99zaL#XxG2^*RRu=fk2xXNs z?%+Cs)xZY|)k-NzBZUwqu%+|!JQwae%J>_X0SbKep7s{(LZPy@X;JH=p?`oQQeRS_ zH1+jJWe8NzT0-TT3Z?0{sPo&Ni1Sb^yx>uLKAHJX6x43U6@K^Bbqwt&AJ}x5hH7{E zbyU~#WGgNJK2ta9)S-`oYN(uYL%YzxP^g4T8FQaD?)Bx`wr#!rLj*O73mtOa{F3E0 b`4wOQT9iM?aWo@)00000NkvXXu0mjfMuUuS literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree_service_map.png b/pandora_console/images/tree_service_map.png new file mode 100644 index 0000000000000000000000000000000000000000..16005f1c984dead9ac88069241b40d76c7501466 GIT binary patch literal 401 zcmV;C0dD?@P)<h;3K|Lk000e1NJLTq000#L000#T1^@s6sTZY|0000PbVXQnQ*UN; zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBUzGf6~2RCwCdRJ##^KoC70G7?L$1OjrT z13Pf6K&?QjKs#{kKr7%bCx8yH0}^808y?KMB7=&7JF|1_yW`z{Z{+*_Oetk`DA5iG zw*!(Yhkb8I(=WI@(!C^2lO)mdWDo=s{LqLo=II=zvH2eN@L)|EbES(qYcN(nkpCfd z`t%*v1!->Ug!OY$R9aJUg32_zw>?E=;}_>=v@ZuGlr7ffX(;SHhU3Jr_^t5e?c`xW z%a!9*MxJFvld!|=hpy|cXq}7Et-Y+}OnM<bGAu94atY5P*-~~S4+uSnJwezZ2(3NE zzQrQgoqd`iMBX+9u&f13`{eXUxvE1mtm-$>w;scaF47IcYhEtcyl6Q{I9BlgIH^a; vPFvncDbp70;dyjK9}YJAdf@j&-vt-|K80iT031UL00000NkvXXu0mjf?0~A# literal 0 HcmV?d00001 diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 6c8365a924..21df029b0a 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -3,173 +3,163 @@ // ================================================== // Copyright (c) 2005-2012 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list + // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 + // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + // Only accesible by ajax -if (is_ajax()) { - global $config; +if (is_ajax ()) { + global $config; + + enterprise_include_once("include/functions_dashboard.php"); - enterprise_include_once('include/functions_dashboard.php'); + $public_hash = get_parameter('hash', 0); - $public_hash = get_parameter('hash', 0); + // Try to authenticate by hash on public dashboards + if ($public_hash == 0) { + // Login check + check_login(); + } else { + $validate_hash = enterprise_hook( + 'dasboard_validate_public_hash', + array($public_hash, 'tree_view') + ); + if ($validate_hash === false || $validate_hash === ENTERPRISE_NOT_HOOK) { + db_pandora_audit("Invalid public hash", "Trying to access report builder"); + require ("general/noaccess.php"); + exit; + } + } + + require_once($config['homedir'] . "/include/class/Tree.class.php"); + require_once($config['homedir'] . "/include/class/TreeOS.class.php"); + require_once($config['homedir'] . "/include/class/TreeModuleGroup.class.php"); + require_once($config['homedir'] . "/include/class/TreeModule.class.php"); + require_once($config['homedir'] . "/include/class/TreeTag.class.php"); + require_once($config['homedir'] . "/include/class/TreeGroup.class.php"); + require_once($config['homedir'] . "/include/class/TreeService.class.php"); + require_once($config['homedir'] . "/include/class/TreeGroupEdition.class.php"); + enterprise_include_once("include/class/TreePolicies.class.php"); + enterprise_include_once("include/class/TreeGroupMeta.class.php"); + require_once($config['homedir'] . "/include/functions_reporting.php"); + require_once($config['homedir'] . "/include/functions_os.php"); + + $getChildren = (bool) get_parameter('getChildren', 0); + $getGroupStatus = (bool) get_parameter('getGroupStatus', 0); + $getDetail = (bool) get_parameter('getDetail'); + + if ($getChildren) { + $type = get_parameter('type', 'group'); + $rootType = get_parameter('rootType', ''); + $id = get_parameter('id', -1); + $rootID = get_parameter('rootID', -1); + $serverID = get_parameter('serverID', false); + $childrenMethod = get_parameter('childrenMethod', 'on_demand'); + $hash = get_parameter('hash', false); + if ($hash !== false) { + enterprise_hook('dasboard_validate_public_hash', array($hash, 'tree_view')); + } - // Try to authenticate by hash on public dashboards - if ($public_hash == 0) { - // Login check - check_login(); - } else { - $validate_hash = enterprise_hook( - 'dasboard_validate_public_hash', - [ - $public_hash, - 'tree_view', - ] - ); - if ($validate_hash === false || $validate_hash === ENTERPRISE_NOT_HOOK) { - db_pandora_audit('Invalid public hash', 'Trying to access report builder'); - include 'general/noaccess.php'; - exit; - } - } + $default_filters = array( + 'searchAgent' => '', + 'statusAgent' => AGENT_STATUS_ALL, + 'searchModule' => '', + 'statusModule' => -1, + 'groupID' => 0, + 'tagID' => 0, + ); + $filter = get_parameter('filter', $default_filters); - include_once $config['homedir'].'/include/class/Tree.class.php'; - include_once $config['homedir'].'/include/class/TreeOS.class.php'; - include_once $config['homedir'].'/include/class/TreeModuleGroup.class.php'; - include_once $config['homedir'].'/include/class/TreeModule.class.php'; - include_once $config['homedir'].'/include/class/TreeTag.class.php'; - include_once $config['homedir'].'/include/class/TreeGroup.class.php'; - include_once $config['homedir'].'/include/class/TreeGroupEdition.class.php'; - enterprise_include_once('include/class/TreePolicies.class.php'); - enterprise_include_once('include/class/TreeGroupMeta.class.php'); - include_once $config['homedir'].'/include/functions_reporting.php'; - include_once $config['homedir'].'/include/functions_os.php'; + $agent_a = check_acl ($config['id_user'], 0, "AR"); + $agent_w = check_acl ($config['id_user'], 0, "AW"); + $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); + $switch_type = !empty($rootType) ? $rootType : $type; + switch ($switch_type) { + case 'os': + $tree = new TreeOS($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'module_group': + $tree = new TreeModuleGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'module': + $tree = new TreeModule($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'tag': + $tree = new TreeTag($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'group': + if(is_metaconsole()){ + if (!class_exists('TreeGroupMeta')) break; + $tree = new TreeGroupMeta($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + else{ + $tree = new TreeGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + break; + case 'policies': + if (!class_exists('TreePolicies')) break; + $tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'group_edition': + $tree = new TreeGroupEdition($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + case 'services': + $tree = new TreeService($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + break; + default: + // FIXME. No error handler + return; + } - $getChildren = (bool) get_parameter('getChildren', 0); - $getGroupStatus = (bool) get_parameter('getGroupStatus', 0); - $getDetail = (bool) get_parameter('getDetail'); + $tree->setFilter($filter); + ob_clean(); - if ($getChildren) { - $type = get_parameter('type', 'group'); - $rootType = get_parameter('rootType', ''); - $id = get_parameter('id', -1); - $rootID = get_parameter('rootID', -1); - $serverID = get_parameter('serverID', false); - $childrenMethod = get_parameter('childrenMethod', 'on_demand'); - $hash = get_parameter('hash', false); - if ($hash !== false) { - enterprise_hook('dasboard_validate_public_hash', [$hash, 'tree_view']); - } - - $default_filters = [ - 'searchAgent' => '', - 'statusAgent' => AGENT_STATUS_ALL, - 'searchModule' => '', - 'statusModule' => -1, - 'groupID' => 0, - 'tagID' => 0, - ]; - $filter = get_parameter('filter', $default_filters); - - $agent_a = check_acl($config['id_user'], 0, 'AR'); - $agent_w = check_acl($config['id_user'], 0, 'AW'); - $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); - $switch_type = !empty($rootType) ? $rootType : $type; - switch ($switch_type) { - case 'os': - $tree = new TreeOS($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - case 'module_group': - $tree = new TreeModuleGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - case 'module': - $tree = new TreeModule($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - case 'tag': - $tree = new TreeTag($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - case 'group': - if (is_metaconsole()) { - if (!class_exists('TreeGroupMeta')) { - break; - } - - $tree = new TreeGroupMeta($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - } else { - $tree = new TreeGroup($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - } - break; - - case 'policies': - if (!class_exists('TreePolicies')) { - break; - } - - $tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - case 'group_edition': - $tree = new TreeGroupEdition($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - break; - - default: - // FIXME. No error handler - return; - } - - $tree->setFilter($filter); - ob_clean(); - echo json_encode(['success' => 1, 'tree' => $tree->getArray()]); - return; - } - - if ($getDetail) { - include_once $config['homedir'].'/include/functions_treeview.php'; - - $id = (int) get_parameter('id'); - $type = (string) get_parameter('type'); - - $server = []; - if (is_metaconsole()) { - $server_id = (int) get_parameter('serverID'); - $server = metaconsole_get_servers($server_id); - } - - ob_clean(); - - echo '<div class="left_align">'; - if (!empty($id) && !empty($type)) { - switch ($type) { - case 'agent': - treeview_printTable($id, $server, true); - break; - - case 'module': - treeview_printModuleTable($id, $server, true); - break; - - case 'alert': - treeview_printAlertsTable($id, $server, true); - break; - - default: - // Nothing - break; - } - } - - echo '<br></div>'; - - return; - } - - return; + echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); + return; + } + + if ($getDetail) { + require_once($config['homedir']."/include/functions_treeview.php"); + + $id = (int) get_parameter('id'); + $type = (string) get_parameter('type'); + + $server = array(); + if (is_metaconsole()) { + $server_id = (int) get_parameter('serverID'); + $server = metaconsole_get_servers($server_id); + } + + ob_clean(); + + echo '<div class="left_align">'; + if (!empty($id) && !empty($type)) { + switch ($type) { + case 'agent': + treeview_printTable($id, $server, true); + break; + case 'module': + treeview_printModuleTable($id, $server, true); + break; + case 'alert': + treeview_printAlertsTable($id, $server, true); + break; + default: + // Nothing + break; + } + } + echo '<br></div>'; + + return; + } + + return; } +?> \ No newline at end of file diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index eda92b48b5..da0380f4ea 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -1,904 +1,762 @@ <?php -// Pandora FMS- http://pandorafms.com +//Pandora FMS- http://pandorafms.com // ================================================== // Copyright (c) 2005-2011 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list + // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 + // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -class Tree -{ - protected $type = null; +class Tree { + protected $type = null; + protected $rootType = null; + protected $id = -1; + protected $rootID = -1; + protected $serverID = false; + protected $serverName = ''; + protected $tree = array(); + protected $filter = array(); + protected $childrenMethod = "on_demand"; - protected $rootType = null; + protected $userGroupsACL; + protected $userGroups; + protected $userGroupsArray; - protected $id = -1; + protected $access = false; - protected $rootID = -1; + protected $L1fieldName = ''; + protected $L1fieldNameSql = ''; + protected $L1extraFields = array(); + protected $L1inner = ''; + protected $L1innerInside = ''; + protected $L1orderByFinal = ''; - protected $serverID = false; + protected $L2condition = ''; + protected $L2conditionInside = ''; + protected $L2inner = ''; + protected $avoid_condition = false; - protected $serverName = ''; + protected $L3forceTagCondition = false; - protected $tree = []; + const TV_DEFAULT_AGENT_STATUS = -1; - protected $filter = []; + public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { - protected $childrenMethod = 'on_demand'; + $this->type = $type; + $this->rootType = !empty($rootType) ? $rootType : $type; + $this->id = $id; + $this->rootID = !empty($rootID) ? $rootID : $id; + $this->serverID = $serverID; + if (is_metaconsole()) { + $this->serverName = metaconsole_get_server_by_id($serverID); + } + $this->childrenMethod = $childrenMethod; + $this->access = $access; - protected $userGroupsACL; + $userGroupsACL = users_get_groups(false, $this->access); - protected $userGroups; + $this->userGroupsACL = empty($userGroupsACL) ? false : $userGroupsACL; + $this->userGroups = $this->userGroupsACL; + $this->userGroupsArray = array_keys($this->userGroups); - protected $userGroupsArray; + global $config; + include_once($config['homedir']."/include/functions_servers.php"); + include_once($config['homedir']."/include/functions_modules.php"); + require_once($config['homedir']."/include/functions_tags.php"); + enterprise_include_once("include/functions_agents.php"); - protected $access = false; + if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php"); + } - protected $L1fieldName = ''; + public function setFilter($filter) { + // There is not module filter in metaconsole. + if (is_metaconsole()) { + $filter['searchModule'] = ""; + $filter['statusModule'] = self::TV_DEFAULT_AGENT_STATUS; + } + $this->filter = $filter; + } - protected $L1fieldNameSql = ''; + protected function getEmptyModuleFilterStatus() { + return ( + !isset($this->filter['statusModule']) || + $this->filter['statusModule'] == -1 + ); + } - protected $L1extraFields = []; + protected function getModuleSearchFilter() { + if (empty($this->filter['searchModule'])) { + return ""; + } + return " AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' "; + } - protected $L1inner = ''; - - protected $L1innerInside = ''; - - protected $L1orderByFinal = ''; - - protected $L2condition = ''; - - protected $L2conditionInside = ''; - - protected $L2inner = ''; - - protected $L3forceTagCondition = false; - - const TV_DEFAULT_AGENT_STATUS = -1; + protected function getAgentSearchFilter() { + if (empty($this->filter['searchAgent'])) return ""; + return " AND LOWER(ta.alias) LIKE LOWER('%%".$this->filter['searchAgent']."%%')"; + } - public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR') - { - $this->type = $type; - $this->rootType = !empty($rootType) ? $rootType : $type; - $this->id = $id; - $this->rootID = !empty($rootID) ? $rootID : $id; - $this->serverID = $serverID; - if (is_metaconsole()) { - $this->serverName = metaconsole_get_server_by_id($serverID); - } + protected function getAgentStatusFilter ($status = self::TV_DEFAULT_AGENT_STATUS) { + if ($status == self::TV_DEFAULT_AGENT_STATUS) + $status = $this->filter['statusAgent']; - $this->childrenMethod = $childrenMethod; - $this->access = $access; - - $userGroupsACL = users_get_groups(false, $this->access); - $this->userGroupsACL = empty($userGroupsACL) ? false : $userGroupsACL; - $this->userGroups = $this->userGroupsACL; - $this->userGroupsArray = array_keys($this->userGroups); - - global $config; - include_once $config['homedir'].'/include/functions_servers.php'; - include_once $config['homedir'].'/include/functions_modules.php'; - include_once $config['homedir'].'/include/functions_tags.php'; - enterprise_include_once('include/functions_agents.php'); - - if (is_metaconsole()) { - enterprise_include_once('meta/include/functions_ui_meta.php'); - } - } - - - public function setFilter($filter) - { - // There is not module filter in metaconsole. - if (is_metaconsole()) { - $filter['searchModule'] = ''; - $filter['statusModule'] = self::TV_DEFAULT_AGENT_STATUS; - } - - $this->filter = $filter; - } - - - protected function getEmptyModuleFilterStatus() - { - return ( - !isset($this->filter['statusModule']) || - $this->filter['statusModule'] == -1 - ); - } - - - protected function getModuleSearchFilter() - { - if (empty($this->filter['searchModule'])) { - return ''; - } - - return " AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' "; - } - - - protected function getAgentSearchFilter() - { - if (empty($this->filter['searchAgent'])) { - return ''; - } - - return " AND LOWER(ta.alias) LIKE LOWER('%%".$this->filter['searchAgent']."%%')"; - } - - - protected function getAgentStatusFilter($status=self::TV_DEFAULT_AGENT_STATUS) - { - if ($status == self::TV_DEFAULT_AGENT_STATUS) { - $status = $this->filter['statusAgent']; - } - - $agent_status_filter = ''; - switch ($status) { - case AGENT_STATUS_ALL: - break; - - case AGENT_STATUS_NOT_INIT: - $agent_status_filter = ' AND (ta.total_count = 0 - OR ta.total_count = ta.notinit_count) '; - break; - - case AGENT_STATUS_CRITICAL: - $agent_status_filter = ' AND ta.critical_count > 0 '; - break; - - case AGENT_STATUS_WARNING: - $agent_status_filter = ' AND (ta.critical_count = 0 - AND ta.warning_count > 0) '; - break; - - case AGENT_STATUS_UNKNOWN: - $agent_status_filter = ' AND (ta.critical_count = 0 + $agent_status_filter = ""; + switch ($status) { + case AGENT_STATUS_ALL: + break; + case AGENT_STATUS_NOT_INIT: + $agent_status_filter = " AND (ta.total_count = 0 + OR ta.total_count = ta.notinit_count) "; + break; + case AGENT_STATUS_CRITICAL: + $agent_status_filter = " AND ta.critical_count > 0 "; + break; + case AGENT_STATUS_WARNING: + $agent_status_filter = " AND (ta.critical_count = 0 + AND ta.warning_count > 0) "; + break; + case AGENT_STATUS_UNKNOWN: + $agent_status_filter = " AND (ta.critical_count = 0 AND ta.warning_count = 0 - AND ta.unknown_count > 0) '; - break; - - case AGENT_STATUS_NORMAL: - $agent_status_filter = ' AND (ta.critical_count = 0 + AND ta.unknown_count > 0) "; + break; + case AGENT_STATUS_NORMAL: + $agent_status_filter = " AND (ta.critical_count = 0 AND ta.warning_count = 0 AND ta.unknown_count = 0 - AND ta.normal_count > 0) '; - break; - } + AND ta.normal_count > 0) "; + break; + } - return $agent_status_filter; - } + return $agent_status_filter; + } + protected function getFirstLevelFields() { + $fields = array ( + "g AS " . $this->L1fieldName, + "SUM(x_critical) AS total_critical_count", + "SUM(x_warning) AS total_warning_count", + "SUM(x_normal) AS total_normal_count", + "SUM(x_unknown) AS total_unknown_count", + "SUM(x_not_init) AS total_not_init_count", + "SUM(x_alerts) AS total_alerts_count", + "SUM(x_total) AS total_count" + ); + return implode(",", array_merge($fields, $this->L1extraFields)); + } - protected function getFirstLevelFields() - { - $fields = [ - 'g AS '.$this->L1fieldName, - 'SUM(x_critical) AS total_critical_count', - 'SUM(x_warning) AS total_warning_count', - 'SUM(x_normal) AS total_normal_count', - 'SUM(x_unknown) AS total_unknown_count', - 'SUM(x_not_init) AS total_not_init_count', - 'SUM(x_alerts) AS total_alerts_count', - 'SUM(x_total) AS total_count', - ]; - return implode(',', array_merge($fields, $this->L1extraFields)); - } + protected function getFirstLevelFieldsInside() { + return array( + 'warning' => array( + 'header' => "0 AS x_critical, SUM(total) AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_WARNING, $this->filter['show_not_init_agents']) + ), + 'critical' => array( + 'header' => "SUM(total) AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_CRITICAL, $this->filter['show_not_init_agents']) + ), + 'normal' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, SUM(total) AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NORMAL, $this->filter['show_not_init_agents']) + ), + 'unknown' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, SUM(total) AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_UNKNOWN, $this->filter['show_not_init_agents']) + ), + 'not_init' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, SUM(total) AS x_not_init, 0 AS x_alerts, 0 AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_NOT_INIT, $this->filter['show_not_init_agents']) + ), + 'alerts' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, SUM(total) AS x_alerts, 0 AS x_total, g", + 'condition' => "AND ta.fired_count > 0" + ), + 'total' => array( + 'header' => "0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, SUM(total) AS x_total, g", + 'condition' => "AND " . agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents']) + ) + ); + } + protected function getInnerOrLeftJoin () { + return $this->filter['show_not_init_agents'] + ? "LEFT" + : "INNER"; + } - protected function getFirstLevelFieldsInside() - { - return [ - 'warning' => [ - 'header' => '0 AS x_critical, SUM(total) AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_WARNING, $this->filter['show_not_init_agents']), - ], - 'critical' => [ - 'header' => 'SUM(total) AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_CRITICAL, $this->filter['show_not_init_agents']), - ], - 'normal' => [ - 'header' => '0 AS x_critical, 0 AS x_warning, SUM(total) AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_NORMAL, $this->filter['show_not_init_agents']), - ], - 'unknown' => [ - 'header' => '0 AS x_critical, 0 AS x_warning, 0 AS x_normal, SUM(total) AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_UNKNOWN, $this->filter['show_not_init_agents']), - ], - 'not_init' => [ - 'header' => '0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, SUM(total) AS x_not_init, 0 AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_NOT_INIT, $this->filter['show_not_init_agents']), - ], - 'alerts' => [ - 'header' => '0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, SUM(total) AS x_alerts, 0 AS x_total, g', - 'condition' => 'AND ta.fired_count > 0', - ], - 'total' => [ - 'header' => '0 AS x_critical, 0 AS x_warning, 0 AS x_normal, 0 AS x_unknown, 0 AS x_not_init, 0 AS x_alerts, SUM(total) AS x_total, g', - 'condition' => 'AND '.agents_get_status_clause(AGENT_STATUS_ALL, $this->filter['show_not_init_agents']), - ], - ]; - } + protected function getModuleStatusFilter () { + $show_init_condition = ($this->filter['show_not_init_agents']) + ? "" + : " AND ta.notinit_count <> ta.total_count"; + if ($this->getEmptyModuleFilterStatus()) { + return $show_init_condition; + } - protected function getInnerOrLeftJoin() - { - return $this->filter['show_not_init_agents'] ? 'LEFT' : 'INNER'; - } + $field_filter = modules_get_counter_by_states($this->filter['statusModule']); + if ($field_filter === false) return " AND 1=0"; + return "AND ta.$field_filter > 0" . $show_init_condition; + } - protected function getModuleStatusFilter() - { - $show_init_condition = ($this->filter['show_not_init_agents']) ? '' : ' AND ta.notinit_count <> ta.total_count'; - - if ($this->getEmptyModuleFilterStatus()) { - return $show_init_condition; - } - - $field_filter = modules_get_counter_by_states($this->filter['statusModule']); - if ($field_filter === false) { - return ' AND 1=0'; - } - - return "AND ta.$field_filter > 0".$show_init_condition; - } - - - protected function getTagJoin() - { - return 'INNER JOIN ttag_module ttm + protected function getTagJoin () { + return 'INNER JOIN ttag_module ttm ON tam.id_agente_modulo = ttm.id_agente_modulo'; - } + } + protected function getTagCondition () { + $tags = tags_get_user_applied_agent_tags($this->id, "AR"); + // All tags permision, returns no condition + if ($tags === true) return ""; + // No permision, do not show anything + if ($tags === false) return " AND 1=0"; + $tags_sql = implode(',', $tags); + return "AND ttm.id_tag IN ($tags_sql)";; + } - protected function getTagCondition() - { - $tags = tags_get_user_applied_agent_tags($this->id, 'AR'); - // All tags permision, returns no condition - if ($tags === true) { - return ''; - } + protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) { + $selected_status = ($state !== false && $state !== self::TV_DEFAULT_AGENT_STATUS) + ? $state + : $this->filter['statusModule']; - // No permision, do not show anything - if ($tags === false) { - return ' AND 1=0'; - } + $filter = array( + modules_get_state_condition($selected_status) + ); + if (!$this->filter['show_not_init_modules'] && $state === false) { + if (!empty($filter)) + $filter[] = "( + tae.estado <> ".AGENT_MODULE_STATUS_NO_DATA." + AND tae.estado <> ".AGENT_MODULE_STATUS_NOT_INIT." + )"; + } + $filter = implode(" AND ", $filter); + return ($without_ands) + ? $filter + : " AND $filter "; + } - $tags_sql = implode(',', $tags); - return "AND ttm.id_tag IN ($tags_sql)"; - ; - } + public function getGroupAclCondition() { + if (users_can_manage_group_all("AR")) return ""; - - protected function getModuleStatusFilterFromTestado($state=false, $without_ands=false) - { - $selected_status = ($state !== false && $state !== self::TV_DEFAULT_AGENT_STATUS) ? $state : $this->filter['statusModule']; - - $filter = [modules_get_state_condition($selected_status)]; - if (!$this->filter['show_not_init_modules'] && $state === false) { - if (!empty($filter)) { - $filter[] = '( - tae.estado <> '.AGENT_MODULE_STATUS_NO_DATA.' - AND tae.estado <> '.AGENT_MODULE_STATUS_NOT_INIT.' - )'; - } - } - - $filter = implode(' AND ', $filter); - return ($without_ands) ? $filter : " AND $filter "; - } - - - public function getGroupAclCondition() - { - if (users_can_manage_group_all('AR')) { - return ''; - } - - $groups_str = implode(',', $this->userGroupsArray); - return " AND ( + $groups_str= implode(",", $this->userGroupsArray); + return " AND ( ta.id_grupo IN ($groups_str) OR tasg.id_group IN ($groups_str) )"; - } + } - - protected function getGroupSearchInner() - { - if (empty($this->filter['searchGroup'])) { - return ''; - } - - return 'INNER JOIN tgrupo tg + protected function getGroupSearchInner() { + if (empty($this->filter['searchGroup'])) return ""; + return "INNER JOIN tgrupo tg ON ta.id_grupo = tg.id_grupo - OR tasg.id_group = tg.id_grupo'; - } - - - protected function getGroupSearchFilter() - { - if (empty($this->filter['searchGroup'])) { - return ''; - } - - return " AND tg.nombre LIKE '%%".$this->filter['searchGroup']."%%'"; - } - - - static function cmpSortNames($a, $b) - { - return strcmp($a['name'], $b['name']); - } - - - protected function getProcessedItem($item, $server=false) - { - if (isset($processed_item['is_processed']) && $processed_item['is_processed']) { - return $item; - } - - $processed_item = []; - $processed_item['id'] = $item['id']; - $processed_item['name'] = $item['name']; - $processed_item['rootID'] = $item['id']; - $processed_item['rootType'] = $this->rootType; - $processed_item['searchChildren'] = 1; - - if (isset($item['type'])) { - $processed_item['type'] = $item['type']; - } else { - $processed_item['type'] = $this->type; - } - - if (isset($item['rootType'])) { - $processed_item['rootType'] = $item['rootType']; - } else { - $processed_item['rootType'] = $this->rootType; - } - - if ($processed_item['type'] == 'group') { - $processed_item['parent'] = $item['parent']; - - $processed_item['icon'] = empty($item['icon']) ? 'without_group.png' : $item['icon'].'.png'; - } - - if (isset($item['iconHTML'])) { - $processed_item['icon'] = $item['iconHTML']; - } - - if (is_metaconsole() && !empty($server)) { - $processed_item['serverID'] = $server['id']; - } - - $counters = []; - if (isset($item['total_unknown_count'])) { - $counters['unknown'] = $item['total_unknown_count']; - } - - if (isset($item['total_critical_count'])) { - $counters['critical'] = $item['total_critical_count']; - } - - if (isset($item['total_warning_count'])) { - $counters['warning'] = $item['total_warning_count']; - } - - if (isset($item['total_not_init_count'])) { - $counters['not_init'] = $item['total_not_init_count']; - } - - if (isset($item['total_normal_count'])) { - $counters['ok'] = $item['total_normal_count']; - } - - if (isset($item['total_count'])) { - $counters['total'] = $item['total_count']; - } - - if (isset($item['total_fired_count'])) { - $counters['alerts'] = $item['total_fired_count']; - } - - if (!empty($counters)) { - $processed_item['counters'] = $counters; - } - - if (!empty($processed_item)) { - $processed_item['is_processed'] = true; - } - - return $processed_item; - } - - - // This function should be used only when retrieving the data of the metaconsole's nodes - protected function getMergedItems($items) - { - // This variable holds the result - $mergedItems = []; - - foreach ($items as $key => $item) { - // Avoid the deleted items - if (!isset($items[$key]) || empty($item)) { - continue; - } - - // Store the item in a temporary element - $resultItem = $item; - - // The 'id' parameter will be stored as 'server_id' => 'id' - $resultItem['id'] = []; - $resultItem['id'][$item['serverID']] = $item['id']; - $resultItem['rootID'] = []; - $resultItem['rootID'][$item['serverID']] = $item['rootID']; - $resultItem['serverID'] = []; - $resultItem['serverID'][$item['serverID']] = $item['rootID']; - - // Initialize counters if any of it don't exist - if (!isset($resultItem['counters'])) { - $resultItem['counters'] = []; - } - - if (!isset($resultItem['counters']['unknown'])) { - $resultItem['counters']['unknown'] = 0; - } - - if (!isset($resultItem['counters']['critical'])) { - $resultItem['counters']['critical'] = 0; - } - - if (!isset($resultItem['counters']['warning'])) { - $resultItem['counters']['warning'] = 0; - } - - if (!isset($resultItem['counters']['not_init'])) { - $resultItem['counters']['not_init'] = 0; - } - - if (!isset($resultItem['counters']['ok'])) { - $resultItem['counters']['ok'] = 0; - } - - if (!isset($resultItem['counters']['total'])) { - $resultItem['counters']['total'] = 0; - } - - if (!isset($resultItem['counters']['alerts'])) { - $resultItem['counters']['alerts'] = 0; - } - - if ($item['type'] == 'group') { - // Add the children - if (!isset($resultItem['children'])) { - $resultItem['children'] = []; - } - } - - // Iterate over the list to search items that match the actual item - foreach ($items as $key2 => $item2) { - // Skip the actual or empty items - if ($key == $key2 || !isset($items[$key2])) { - continue; - } - - // Match with the name and type - if ($item['name'] == $item2['name'] && $item['type'] == $item2['type']) { - // Add the matched ids - $resultItem['id'][$item2['serverID']] = $item2['id']; - $resultItem['rootID'][$item2['serverID']] = $item2['rootID']; - $resultItem['serverID'][$item2['serverID']] = $item2['rootID']; - - // Add the matched counters - if (isset($item2['counters']) && !empty($item2['counters'])) { - foreach ($item2['counters'] as $type => $value) { - if (isset($resultItem['counters'][$type])) { - $resultItem['counters'][$type] += $value; - } - } - } - - if ($item['type'] == 'group') { - // Add the matched children - if (isset($item2['children'])) { - $resultItem['children'] = array_merge($resultItem['children'], $item2['children']); - } - } - - // Remove the item - unset($items[$key2]); - } - } - - if ($item['type'] == 'group') { - // Get the merged children (recursion) - if (!empty($resultItem['children'])) { - $resultItem['children'] = $this->getMergedItems($resultItem['children']); - } - } - - // Add the resulting item - if (!empty($resultItem) && !empty($resultItem['counters']['total'])) { - $mergedItems[] = $resultItem; - } - - // Remove the item - unset($items[$key]); - } - - usort($mergedItems, ['Tree', 'cmpSortNames']); - - return $mergedItems; - } - - - protected function processModule(&$module, $server=false, $all_groups) - { - global $config; - - if (isset($module['children'])) { - foreach ($module['children'] as $i => $children) { - $this->processModule($module['children'][$i], $server, $all_groups); - } - } - - $module['type'] = 'module'; - $module['id'] = (int) $module['id']; - $module['name'] = io_safe_output($module['name']); - $module['id_module_type'] = (int) $module['id_tipo_modulo']; - $module['server_type'] = (int) $module['id_modulo']; - $module['status'] = $module['estado']; - $module['value'] = $module['datos']; - - if (is_metaconsole()) { - $module['serverID'] = $this->serverID; - $module['serverName'] = $this->serverName; - } else { - $module['serverName'] = false; - $module['serverID'] = false; - } - - if (!isset($module['value'])) { - $module['value'] = modules_get_last_value($module['id']); - } - - // Status - switch ($module['status']) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - $module['alert'] = 1; - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $statusType = STATUS_MODULE_CRITICAL_BALL; - $statusTitle = __('CRITICAL'); - $module['statusText'] = 'critical'; - break; - - case AGENT_MODULE_STATUS_WARNING_ALERT: - $module['alert'] = 1; - case AGENT_MODULE_STATUS_WARNING: - $statusType = STATUS_MODULE_WARNING_BALL; - $statusTitle = __('WARNING'); - $module['statusText'] = 'warning'; - break; - - case AGENT_MODULE_STATUS_UNKNOWN: - $statusType = STATUS_MODULE_UNKNOWN_BALL; - $statusTitle = __('UNKNOWN'); - $module['statusText'] = 'unknown'; - break; - - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $statusType = STATUS_MODULE_NO_DATA_BALL; - $statusTitle = __('NO DATA'); - $module['statusText'] = 'not_init'; - break; - - case AGENT_MODULE_STATUS_NORMAL_ALERT: - $module['alert'] = 1; - case AGENT_MODULE_STATUS_NORMAL: - default: - $statusType = STATUS_MODULE_OK_BALL; - $statusTitle = __('NORMAL'); - $module['statusText'] = 'ok'; - break; - } - - if ($statusType !== STATUS_MODULE_UNKNOWN_BALL - && $statusType !== STATUS_MODULE_NO_DATA_BALL - ) { - if (is_numeric($module['value'])) { - $statusTitle .= ' : '.format_for_graph($module['value']); - } else { - $statusTitle .= ' : '.substr(io_safe_output($module['value']), 0, 42); - } - } - - $module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true); - - // HTML of the server type image - $module['serverTypeHTML'] = servers_show_type($module['server_type']); - - // Link to the Module graph - // ACL - $acl_graphs = false; - $module['showGraphs'] = 0; - - // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions - if (!empty($group_id) && !is_metaconsole()) { - $acl_graphs = check_acl_one_of_groups($config['id_user'], $all_groups, 'RR'); - } else if (!empty($all_groups)) { - $acl_graphs = true; - } - - if ($acl_graphs) { - $module['showGraphs'] = 1; - } - - if ($module['showGraphs']) { - $graphType = return_graphtype($module['id_module_type']); - $url = ui_get_full_url('operation/agentes/stat_win.php', false, false, false); - $winHandle = dechex(crc32($module['id'].$module['name'])); - - $graph_params = [ - 'type' => $graphType, - 'period' => SECONDS_1DAY, - 'id' => $module['id'], - 'label' => base64_encode($module['name']), - 'refresh' => SECONDS_10MINUTES, - ]; - - if (is_metaconsole()) { - // Set the server id - $graph_params['server'] = $module['serverID']; - } - - $graph_params_str = http_build_query($graph_params); - $moduleGraphURL = "$url?$graph_params_str"; - - $module['moduleGraph'] = [ - 'url' => $moduleGraphURL, - 'handle' => $winHandle, - ]; - - // Info to be able to open the snapshot image new page - $module['snapshot'] = ui_get_snapshot_link( - [ - 'id_module' => $module['id'], - 'interval' => $module['current_interval'], - 'module_name' => $module['name'], - 'id_node' => $module['serverID'] ? $module['serverID'] : 0, - ], - true - ); - } - - // Alerts fired image - if ((bool) $module['alerts']) { - $module['alertsImageHTML'] = html_print_image('images/bell.png', true, ['title' => __('Module alerts')]); - } - } - - - protected function processModules(&$modules, $server=false) - { - if (!empty($modules)) { - $all_groups = modules_get_agent_groups($modules[0]['id']); - } - - foreach ($modules as $iterator => $module) { - $this->processModule($modules[$iterator], $server, $all_groups); - } - } - - - protected function processAgent(&$agent, $server=false) - { - global $config; - - $agent['type'] = 'agent'; - $agent['id'] = (int) $agent['id']; - $agent['name'] = $agent['name']; - - $agent['rootID'] = $this->rootID; - $agent['rootType'] = $this->rootType; - - if (is_metaconsole()) { - if (isset($agent['server_id'])) { - $agent['serverID'] = $agent['server_id']; - } else if (!empty($server)) { - $agent['serverID'] = $server['id']; - } - } - - // Counters - if (empty($agent['counters'])) { - $agent['counters'] = []; - - $agent['counters']['unknown'] = isset($agent['unknown_count']) ? $agent['unknown_count'] : 0; - $agent['counters']['critical'] = isset($agent['critical_count']) ? $agent['critical_count'] : 0; - $agent['counters']['warning'] = isset($agent['warning_count']) ? $agent['warning_count'] : 0; - $agent['counters']['not_init'] = isset($agent['notinit_count']) ? $agent['notinit_count'] : 0; - $agent['counters']['ok'] = isset($agent['normal_count']) ? $agent['normal_count'] : 0; - $agent['counters']['total'] = isset($agent['total_count']) ? $agent['total_count'] : 0; - $agent['counters']['alerts'] = isset($agent['fired_count']) ? $agent['fired_count'] : 0; - } - - // Status image - $agent['statusImageHTML'] = agents_tree_view_status_img_ball( - $agent['counters']['critical'], - $agent['counters']['warning'], - $agent['counters']['unknown'], - $agent['counters']['total'], - $agent['counters']['not_init'] - ); - - // Alerts fired image - $agent['alertImageHTML'] = agents_tree_view_alert_img_ball($agent['counters']['alerts']); - - // search module recalculate counters - if (array_key_exists('state_normal', $agent)) { - $agent['counters']['unknown'] = $agent['state_unknown']; - $agent['counters']['critical'] = $agent['state_critical']; - $agent['counters']['warning'] = $agent['state_warning']; - $agent['counters']['not_init'] = $agent['state_notinit']; - $agent['counters']['ok'] = $agent['state_normal']; - $agent['counters']['total'] = $agent['state_total']; - - $agent['critical_count'] = $agent['counters']['critical']; - $agent['warning_count'] = $agent['counters']['warning']; - $agent['unknown_count'] = $agent['counters']['unknown']; - $agent['notinit_count'] = $agent['counters']['not_init']; - $agent['normal_count'] = $agent['counters']['ok']; - $agent['total_count'] = $agent['counters']['total']; - } - - if (!$this->getEmptyModuleFilterStatus()) { - $agent['counters']['unknown'] = 0; - $agent['counters']['critical'] = 0; - $agent['counters']['warning'] = 0; - $agent['counters']['not_init'] = 0; - $agent['counters']['ok'] = 0; - $agent['counters']['total'] = 0; - switch ($this->filter['statusModule']) { - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_BAD: - $agent['counters']['critical'] = $agent['critical_count']; - $agent['counters']['total'] = $agent['critical_count']; - break; - - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_WARNING: - $agent['counters']['warning'] = $agent['warning_count']; - $agent['counters']['total'] = $agent['warning_count']; - break; - - case AGENT_MODULE_STATUS_UNKNOWN: - $agent['counters']['unknown'] = $agent['unknown_count']; - $agent['counters']['total'] = $agent['unknown_count']; - break; - - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $agent['counters']['not_init'] = $agent['notinit_count']; - $agent['counters']['total'] = $agent['notinit_count']; - break; - - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_NORMAL: - $agent['counters']['ok'] = $agent['normal_count']; - $agent['counters']['total'] = $agent['normal_count']; - break; - } - } - - if (!$this->filter['show_not_init_modules']) { - $agent['counters']['total'] -= $agent['counters']['not_init']; - $agent['counters']['not_init'] = 0; - } - - // Quiet image - if (isset($agent['quiet']) && $agent['quiet']) { - $agent['quietImageHTML'] = html_print_image('/images/dot_blue.png', true, ['title' => __('Quiet')]); - } - - // Children - if (empty($agent['children'])) { - $agent['children'] = []; - if ($agent['counters']['total'] > 0) { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 1; - break; - - case 'live': - $agent['searchChildren'] = 0; - break; - } - } else { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 0; - break; - - case 'live': - $agent['searchChildren'] = 0; - break; - } - } - } - } - - - protected function processAgents(&$agents, $server=false) - { - if (!empty($agents)) { - foreach ($agents as $iterator => $agent) { - $this->processAgent($agents[$iterator], $server); - } - } - } - - - protected function getData() - { - - } - - - protected function getFirstLevel() - { - $sql = $this->getFirstLevelSql(); - $items = db_get_all_rows_sql($sql); - if ($items === false) { - $items = []; - } - - $this->tree = $this->getProcessedItemsFirstLevel($items); - } - - - protected function getProcessedItemsFirstLevel($items) - { - $processed_items = []; - foreach ($items as $key => $item) { - $processed_item = $this->getProcessedItem($item); - $processed_items[] = $processed_item; - } - - return $processed_items; - } - - - protected function getFirstLevelSql() - { - $fields = $this->getFirstLevelFields(); - $field_name_sql = $this->L1fieldNameSql; - $inside_fields = $this->getFirstLevelFieldsInside(); - $inner = $this->L1inner; - $inner_inside = $this->L1innerInside; - $order_by_final = $this->L1orderByFinal; - - $group_inner = $this->getGroupSearchInner(); - $group_acl = $this->getGroupAclCondition(); - $group_search_filter = $this->getGroupSearchFilter(); - $agent_search_filter = $this->getAgentSearchFilter(); - $agent_status_filter = $this->getAgentStatusFilter(); - $module_search_filter = $this->getModuleSearchFilter(); - $module_status_inner = ''; - $module_status_filter = $this->getModuleStatusFilterFromTestado(); - if (!empty($module_status_filter)) { - $module_status_inner = ' + OR tasg.id_group = tg.id_grupo" + ; + } + + protected function getGroupSearchFilter() { + if (empty($this->filter['searchGroup'])) return ""; + return " AND tg.nombre LIKE '%%" . $this->filter['searchGroup'] . "%%'"; + } + + static function cmpSortNames($a, $b) { + return strcmp($a["name"], $b["name"]); + } + + protected function getProcessedItem ($item, $server = false) { + + if (isset($processed_item['is_processed']) && $processed_item['is_processed']) + return $item; + + $processed_item = array(); + $processed_item['id'] = $item['id']; + $processed_item['name'] = $item['name']; + $processed_item['rootID'] = $item['id']; + $processed_item['rootType'] = $this->rootType; + $processed_item['searchChildren'] = 1; + + if (isset($item['type'])) + $processed_item['type'] = $item['type']; + else + $processed_item['type'] = $this->type; + + if (isset($item['rootType'])) + $processed_item['rootType'] = $item['rootType']; + else + $processed_item['rootType'] = $this->rootType; + + if ($processed_item['type'] == 'group') { + $processed_item['parent'] = $item['parent']; + + $processed_item['icon'] = empty($item['icon']) + ? "without_group.png" + : $item['icon'].".png"; + } + if (isset($item['iconHTML'])) { + $processed_item['icon'] = $item['iconHTML']; + } + + if (is_metaconsole() && !empty($server)) { + $processed_item['serverID'] = $server['id']; + } + + $counters = array(); + if (isset($item['total_unknown_count'])) + $counters['unknown'] = $item['total_unknown_count']; + if (isset($item['total_critical_count'])) + $counters['critical'] = $item['total_critical_count']; + if (isset($item['total_warning_count'])) + $counters['warning'] = $item['total_warning_count']; + if (isset($item['total_not_init_count'])) + $counters['not_init'] = $item['total_not_init_count']; + if (isset($item['total_normal_count'])) + $counters['ok'] = $item['total_normal_count']; + if (isset($item['total_count'])) + $counters['total'] = $item['total_count']; + if (isset($item['total_fired_count'])) + $counters['alerts'] = $item['total_fired_count']; + + if (!empty($counters)) + $processed_item['counters'] = $counters; + + if (!empty($processed_item)) + $processed_item['is_processed'] = true; + + return $processed_item; + } + + // This function should be used only when retrieving the data of the metaconsole's nodes + protected function getMergedItems ($items) { + // This variable holds the result + $mergedItems = array(); + + foreach ($items as $key => $item) { + // Avoid the deleted items + if (!isset($items[$key]) || empty($item)) + continue; + + // Store the item in a temporary element + $resultItem = $item; + + // The 'id' parameter will be stored as 'server_id' => 'id' + $resultItem['id'] = array(); + $resultItem['id'][$item['serverID']] = $item['id']; + $resultItem['rootID'] = array(); + $resultItem['rootID'][$item['serverID']] = $item['rootID']; + $resultItem['serverID'] = array(); + $resultItem['serverID'][$item['serverID']] = $item['rootID']; + + // Initialize counters if any of it don't exist + if (!isset($resultItem['counters'])) + $resultItem['counters'] = array(); + if (!isset($resultItem['counters']['unknown'])) + $resultItem['counters']['unknown'] = 0; + if (!isset($resultItem['counters']['critical'])) + $resultItem['counters']['critical'] = 0; + if (!isset($resultItem['counters']['warning'])) + $resultItem['counters']['warning'] = 0; + if (!isset($resultItem['counters']['not_init'])) + $resultItem['counters']['not_init'] = 0; + if (!isset($resultItem['counters']['ok'])) + $resultItem['counters']['ok'] = 0; + if (!isset($resultItem['counters']['total'])) + $resultItem['counters']['total'] = 0; + if (!isset($resultItem['counters']['alerts'])) + $resultItem['counters']['alerts'] = 0; + + if ($item['type'] == 'group') { + // Add the children + if (!isset($resultItem['children'])) + $resultItem['children'] = array(); + } + + // Iterate over the list to search items that match the actual item + foreach ($items as $key2 => $item2) { + // Skip the actual or empty items + if ($key == $key2 || !isset($items[$key2])) + continue; + + // Match with the name and type + if ($item['name'] == $item2['name'] && $item['type'] == $item2['type']) { + // Add the matched ids + $resultItem['id'][$item2['serverID']] = $item2['id']; + $resultItem['rootID'][$item2['serverID']] = $item2['rootID']; + $resultItem['serverID'][$item2['serverID']] = $item2['rootID']; + + // Add the matched counters + if (isset($item2['counters']) && !empty($item2['counters'])) { + foreach ($item2['counters'] as $type => $value) { + if (isset($resultItem['counters'][$type])) + $resultItem['counters'][$type] += $value; + } + } + + if ($item['type'] == 'group') { + // Add the matched children + if (isset($item2['children'])) + $resultItem['children'] = array_merge($resultItem['children'], $item2['children']); + } + + // Remove the item + unset($items[$key2]); + } + } + + if ($item['type'] == 'group') { + // Get the merged children (recursion) + if (!empty($resultItem['children'])) + $resultItem['children'] = $this->getMergedItems($resultItem['children']); + + } + + // Add the resulting item + if (!empty($resultItem) && !empty($resultItem['counters']['total'])) + $mergedItems[] = $resultItem; + + // Remove the item + unset($items[$key]); + } + + usort($mergedItems, array("Tree", "cmpSortNames")); + + return $mergedItems; + } + + protected function processModule (&$module, $server = false, $all_groups) { + global $config; + + if (isset($module['children'])) { + foreach ($module['children'] as $i => $children) { + $this->processModule($module['children'][$i], $server, $all_groups); + } + } + + $module['type'] = 'module'; + $module['id'] = (int) $module['id']; + $module['name'] = io_safe_output($module['name']); + $module['id_module_type'] = (int) $module['id_tipo_modulo']; + $module['server_type'] = (int) $module['id_modulo']; + $module['status'] = $module['estado']; + $module['value'] = $module['datos']; + + if (is_metaconsole()) { + $module['serverID'] = $this->serverID; + $module['serverName'] = $this->serverName; + } + else { + $module['serverName'] = false; + $module['serverID'] = false; + } + + if (!isset($module['value'])) + $module['value'] = modules_get_last_value($module['id']); + + // Status + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + $module['alert'] = 1; + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $statusType = STATUS_MODULE_CRITICAL_BALL; + $statusTitle = __('CRITICAL'); + $module['statusText'] = "critical"; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + $module['alert'] = 1; + case AGENT_MODULE_STATUS_WARNING: + $statusType = STATUS_MODULE_WARNING_BALL; + $statusTitle = __('WARNING'); + $module['statusText'] = "warning"; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $statusType = STATUS_MODULE_UNKNOWN_BALL; + $statusTitle = __('UNKNOWN'); + $module['statusText'] = "unknown"; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $statusType = STATUS_MODULE_NO_DATA_BALL; + $statusTitle = __('NO DATA'); + $module['statusText'] = "not_init"; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + $module['alert'] = 1; + case AGENT_MODULE_STATUS_NORMAL: + default: + $statusType = STATUS_MODULE_OK_BALL; + $statusTitle = __('NORMAL'); + $module['statusText'] = "ok"; + break; + } + + if ($statusType !== STATUS_MODULE_UNKNOWN_BALL + && $statusType !== STATUS_MODULE_NO_DATA_BALL) { + if (is_numeric($module["value"])) { + $statusTitle .= " : " . format_for_graph($module["value"]); + } + else { + $statusTitle .= " : " . substr(io_safe_output($module["value"]),0,42); + } + } + + $module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true); + + // HTML of the server type image + $module['serverTypeHTML'] = servers_show_type($module['server_type']); + + // Link to the Module graph + + // ACL + $acl_graphs = false; + $module["showGraphs"] = 0; + + // Avoid the check on the metaconsole. Too slow to show/hide an icon depending on the permissions + if (!empty($group_id) && !is_metaconsole()) { + $acl_graphs = check_acl_one_of_groups($config['id_user'], $all_groups, "RR"); + } + else if (!empty($all_groups)) { + $acl_graphs = true; + } + + if ($acl_graphs) { + $module["showGraphs"] = 1; + } + + if ($module["showGraphs"]) { + $graphType = return_graphtype($module['id_module_type']); + $url = ui_get_full_url("operation/agentes/stat_win.php", false, false, false); + $winHandle = dechex(crc32($module['id'].$module['name'])); + + $graph_params = array( + "type" => $graphType, + "period" => SECONDS_1DAY, + "id" => $module['id'], + "label" => base64_encode($module['name']), + "refresh" => SECONDS_10MINUTES + ); + + if (is_metaconsole()) { + // Set the server id + $graph_params["server"] = $module['serverID']; + } + + $graph_params_str = http_build_query($graph_params); + $moduleGraphURL = "$url?$graph_params_str"; + + $module['moduleGraph'] = array( + 'url' => $moduleGraphURL, + 'handle' => $winHandle + ); + + // Info to be able to open the snapshot image new page + $module['snapshot'] = ui_get_snapshot_link(array( + 'id_module' => $module['id'], + 'interval' => $module['current_interval'], + 'module_name' => $module['name'], + 'id_node' => $module['serverID'] ? $module['serverID'] : 0, + ), true); + } + + // Alerts fired image + if ((bool)$module['alerts']) { + $module['alertsImageHTML'] = html_print_image("images/bell.png", true, array("title" => __('Module alerts'))); + } + } + + protected function processModules (&$modules, $server = false) { + if (!empty($modules)) { + $all_groups = modules_get_agent_groups($modules[0]['id']); + } + foreach ($modules as $iterator => $module) { + $this->processModule($modules[$iterator], $server, $all_groups); + } + } + + protected function processAgent (&$agent, $server = false) { + global $config; + + $agent['type'] = 'agent'; + $agent['id'] = (int) $agent['id']; + $agent['name'] = $agent['name']; + + $agent['rootID'] = $this->rootID; + $agent['rootType'] = $this->rootType; + + if (is_metaconsole()) { + if (isset($agent['server_id'])) + $agent['serverID'] = $agent['server_id']; + else if (!empty($server)) + $agent['serverID'] = $server['id']; + } + // Counters + if (empty($agent['counters'])) { + $agent['counters'] = array(); + + $agent['counters']['unknown'] = isset($agent['unknown_count']) ? $agent['unknown_count'] : 0; + $agent['counters']['critical'] = isset($agent['critical_count']) ? $agent['critical_count'] : 0; + $agent['counters']['warning'] = isset($agent['warning_count']) ? $agent['warning_count'] : 0; + $agent['counters']['not_init'] = isset($agent['notinit_count']) ? $agent['notinit_count'] : 0; + $agent['counters']['ok'] = isset($agent['normal_count']) ? $agent['normal_count'] : 0; + $agent['counters']['total'] = isset($agent['total_count']) ? $agent['total_count'] : 0; + $agent['counters']['alerts'] = isset($agent['fired_count']) ? $agent['fired_count'] : 0; + } + + // Status image + $agent['statusImageHTML'] = agents_tree_view_status_img_ball( + $agent['counters']['critical'], + $agent['counters']['warning'], + $agent['counters']['unknown'], + $agent['counters']['total'], + $agent['counters']['not_init']); + + // Alerts fired image + $agent["alertImageHTML"] = agents_tree_view_alert_img_ball($agent['counters']['alerts']); + + // search module recalculate counters + if(array_key_exists('state_normal', $agent)){ + $agent['counters']['unknown'] = $agent['state_unknown']; + $agent['counters']['critical'] = $agent['state_critical']; + $agent['counters']['warning'] = $agent['state_warning']; + $agent['counters']['not_init'] = $agent['state_notinit']; + $agent['counters']['ok'] = $agent['state_normal']; + $agent['counters']['total'] = $agent['state_total']; + + $agent['critical_count'] = $agent['counters']['critical']; + $agent['warning_count'] = $agent['counters']['warning']; + $agent['unknown_count'] = $agent['counters']['unknown']; + $agent['notinit_count'] = $agent['counters']['not_init']; + $agent['normal_count'] = $agent['counters']['ok']; + $agent['total_count'] = $agent['counters']['total']; + } + + if (!$this->getEmptyModuleFilterStatus()) { + $agent['counters']['unknown'] = 0; + $agent['counters']['critical'] = 0; + $agent['counters']['warning'] = 0; + $agent['counters']['not_init'] = 0; + $agent['counters']['ok'] = 0; + $agent['counters']['total'] = 0; + switch($this->filter['statusModule']) { + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $agent['counters']['critical'] = $agent['critical_count']; + $agent['counters']['total'] = $agent['critical_count']; + break; + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_WARNING: + $agent['counters']['warning'] = $agent['warning_count']; + $agent['counters']['total'] = $agent['warning_count']; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $agent['counters']['unknown'] = $agent['unknown_count']; + $agent['counters']['total'] = $agent['unknown_count']; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $agent['counters']['not_init'] = $agent['notinit_count']; + $agent['counters']['total'] = $agent['notinit_count']; + break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + $agent['counters']['ok'] = $agent['normal_count']; + $agent['counters']['total'] = $agent['normal_count']; + break; + } + } + + if (!$this->filter['show_not_init_modules']) { + $agent['counters']['total'] -= $agent['counters']['not_init']; + $agent['counters']['not_init'] = 0; + } + + // Quiet image + if (isset($agent['quiet']) && $agent['quiet']) + $agent['quietImageHTML'] = html_print_image("/images/dot_blue.png", true, array("title" => __('Quiet'))); + + // Children + if (empty($agent['children'])) { + $agent['children'] = array(); + if ($agent['counters']['total'] > 0) { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 1; + break; + case 'live': + $agent['searchChildren'] = 0; + break; + } + } + else { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 0; + break; + case 'live': + $agent['searchChildren'] = 0; + break; + } + } + } + } + + protected function processAgents (&$agents, $server = false) { + if (!empty($agents)) { + foreach ($agents as $iterator => $agent) { + $this->processAgent($agents[$iterator], $server); + } + } + } + + protected function getData() { + + } + + protected function getFirstLevel() { + $sql = $this->getFirstLevelSql(); + $items = db_get_all_rows_sql($sql); + if ($items === false) $items = array(); + + $this->tree = $this->getProcessedItemsFirstLevel($items); + } + + protected function getProcessedItemsFirstLevel($items){ + $processed_items = array(); + foreach ($items as $key => $item) { + $processed_item = $this->getProcessedItem($item); + $processed_items[] = $processed_item; + } + return $processed_items; + } + + protected function getFirstLevelSql() { + + $fields = $this->getFirstLevelFields(); + $field_name_sql = $this->L1fieldNameSql; + $inside_fields = $this->getFirstLevelFieldsInside(); + $inner = $this->L1inner; + $inner_inside = $this->L1innerInside; + $order_by_final = $this->L1orderByFinal; + + $group_inner = $this->getGroupSearchInner(); + $group_acl = $this->getGroupAclCondition(); + $group_search_filter = $this->getGroupSearchFilter(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_inner = ""; + $module_status_filter = $this->getModuleStatusFilterFromTestado(); + if (!empty($module_status_filter)) { + $module_status_inner = " INNER JOIN tagente_estado tae - ON tae.id_agente_modulo = tam.id_agente_modulo'; - } + ON tae.id_agente_modulo = tam.id_agente_modulo"; + } - $sql_model = "SELECT %s FROM + $sql_model = "SELECT %s FROM ( SELECT COUNT(DISTINCT(ta.id_agente)) AS total, $field_name_sql AS g FROM tagente ta @@ -920,42 +778,34 @@ class Tree $group_acl GROUP BY $field_name_sql ) x GROUP BY g"; - $sql_array = []; - foreach ($inside_fields as $inside_field) { - $sql_array[] = sprintf( - $sql_model, - $inside_field['header'], - $inside_field['condition'] - ); - } - - $sql = "SELECT $fields FROM (".implode(' UNION ALL ', $sql_array).") x2 + $sql_array = array(); + foreach ($inside_fields as $inside_field) { + $sql_array[] = sprintf( + $sql_model, + $inside_field['header'], + $inside_field['condition'] + ); + } + $sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2 $inner GROUP BY g ORDER BY $order_by_final"; - return $sql; - } + return $sql; + } + protected function getSecondLevel() { + $sql = $this->getSecondLevelSql(); + $data = db_process_sql($sql); + if (empty($data)) { + $this->tree = array(); + return; + } + $this->processAgents($data); + $this->tree = $data; + } - protected function getSecondLevel() - { - $sql = $this->getSecondLevelSql(); - $data = db_process_sql($sql); - if (empty($data)) { - $this->tree = []; - return; - } - - $this->processAgents($data); - - $this->tree = $data; - } - - - protected function getSecondLevelSql() - { - $columns = sprintf( - 'ta.id_agente AS id, ta.nombre AS name, ta.alias, + protected function getSecondLevelSql() { + $columns = sprintf("ta.id_agente AS id, ta.nombre AS name, ta.alias, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, ta.quiet, @@ -965,29 +815,29 @@ class Tree SUM(if(%s, 1, 0)) as state_notinit, SUM(if(%s, 1, 0)) as state_normal, SUM(if(%s AND tae.estado IS NOT NULL, 1, 0)) as state_total - ', - $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_CRITICAL_ALERT, true), - $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_WARNING_ALERT, true), - $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_UNKNOWN, true), - $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NO_DATA, true), - $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NORMAL, true), - $this->getModuleStatusFilterFromTestado(self::TV_DEFAULT_AGENT_STATUS, true) - ); + ", + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_CRITICAL_ALERT, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_WARNING_ALERT, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_UNKNOWN, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NO_DATA, true), + $this->getModuleStatusFilterFromTestado(AGENT_MODULE_STATUS_NORMAL, true), + $this->getModuleStatusFilterFromTestado(self::TV_DEFAULT_AGENT_STATUS, true) + ); - $inner_or_left = $this->getInnerOrLeftJoin(); - $group_inner = $this->getGroupSearchInner(); - $group_acl = $this->getGroupAclCondition(); - $group_search_filter = $this->getGroupSearchFilter(); - $agent_search_filter = $this->getAgentSearchFilter(); - $agent_status_filter = $this->getAgentStatusFilter(); - $module_search_filter = $this->getModuleSearchFilter(); - $module_status_filter = $this->getModuleStatusFilter(); + $inner_or_left = $this->getInnerOrLeftJoin(); + $group_inner = $this->getGroupSearchInner(); + $group_acl = $this->getGroupAclCondition(); + $group_search_filter = $this->getGroupSearchFilter(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_filter = $this->getModuleStatusFilter(); - $condition = $this->L2condition; - $condition_inside = $this->L2conditionInside; - $inner = $this->L2inner; + $condition = $this->L2condition; + $condition_inside = $this->L2conditionInside; + $inner = $this->L2inner; - $sql = "SELECT $columns + $sql = "SELECT $columns FROM tagente ta $inner_or_left JOIN tagente_modulo tam ON ta.id_agente = tam.id_agente @@ -1017,48 +867,51 @@ class Tree ORDER BY ta.alias ASC, ta.id_agente ASC "; - return $sql; - } + return $sql; + } + protected function getThirdLevel() { + $sql = $this->getThirdLevelSql(); + $data = db_process_sql($sql); + if (empty($data)) { + $this->tree = array(); + return; + } + $data = $this->getProcessedModules($data); + $this->processModules($data); +hd("MODULES: ", true); +hd($data, true); + $this->tree = $data; + } - protected function getThirdLevel() - { - $sql = $this->getThirdLevelSql(); - $data = db_process_sql($sql); - if (empty($data)) { - $this->tree = []; - return; - } + protected function getThirdLevelSql() { + // Get the server id + $serverID = $this->serverID; - $data = $this->getProcessedModules($data); - $this->processModules($data); + $group_acl = $this->getGroupAclCondition(); + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_search_filter = $this->getModuleSearchFilter(); + $module_status_filter = $this->getModuleStatusFilterFromTestado(); + $agent_filter = "AND ta.id_agente = " . $this->id; + $tag_condition = $this->getTagCondition(); + $tag_join = empty($tag_condition) && (!$this->L3forceTagCondition) + ? '' + : $this->getTagJoin(); - $this->tree = $data; - } + if ($this->avoid_condition === true) { + $condition = ''; + $inner = ''; + } else { + $condition = $this->L2condition; + $inner = $this->L2inner; + } - - protected function getThirdLevelSql() - { - // Get the server id - $serverID = $this->serverID; - - $group_acl = $this->getGroupAclCondition(); - $agent_search_filter = $this->getAgentSearchFilter(); - $agent_status_filter = $this->getAgentStatusFilter(); - $module_search_filter = $this->getModuleSearchFilter(); - $module_status_filter = $this->getModuleStatusFilterFromTestado(); - $agent_filter = 'AND ta.id_agente = '.$this->id; - $tag_condition = $this->getTagCondition(); - $tag_join = empty($tag_condition) && (!$this->L3forceTagCondition) ? '' : $this->getTagJoin(); - - $condition = $this->L2condition; - $inner = $this->L2inner; - - $columns = 'DISTINCT(tam.id_agente_modulo) AS id, tam.nombre AS name, + $columns = 'DISTINCT(tam.id_agente_modulo) AS id, tam.nombre AS name, tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos, tam.parent_module_id AS parent, tatm.id AS alerts'; - $sql = "SELECT $columns + $sql = "SELECT $columns FROM tagente_modulo tam $tag_join INNER JOIN tagente_estado tae @@ -1076,81 +929,57 @@ class Tree $group_acl $agent_search_filter $agent_status_filter - $module_status_filter $module_search_filter $tag_condition ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC"; - return $sql; - } + return $sql; + } - public function getJSON() - { - $this->getData(); + public function getJSON() { + $this->getData(); - return json_encode($this->tree); - } + return json_encode($this->tree); + } + public function getArray() { + $this->getData(); - public function getArray() - { - $this->getData(); + return $this->tree; + } - return $this->tree; - } + static function name2symbol($name) { + return str_replace( + array(' ','#','/','.','(',')','¿','?','¡','!'), + array( + '_articapandora_'.ord(' ').'_pandoraartica_', + '_articapandora_'.ord('#').'_pandoraartica_', + '_articapandora_'.ord('/').'_pandoraartica_', + '_articapandora_'.ord('.').'_pandoraartica_', + '_articapandora_'.ord('(').'_pandoraartica_', + '_articapandora_'.ord(')').'_pandoraartica_', + '_articapandora_'.ord('¿').'_pandoraartica_', + '_articapandora_'.ord('?').'_pandoraartica_', + '_articapandora_'.ord('¡').'_pandoraartica_', + '_articapandora_'.ord('!').'_pandoraartica_' + ), + io_safe_output($name) + ); + } + static function symbol2name($name) { + $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; + for ($i = 0; $i < strlen($symbols); $i++) { + $name = str_replace('_articapandora_' . + ord(substr($symbols, $i, 1)) .'_pandoraartica_', + substr($symbols, $i, 1), $name); + } + return io_safe_input($name); + } - static function name2symbol($name) - { - return str_replace( - [ - ' ', - '#', - '/', - '.', - '(', - ')', - '¿', - '?', - '¡', - '!', - ], - [ - '_articapandora_'.ord(' ').'_pandoraartica_', - '_articapandora_'.ord('#').'_pandoraartica_', - '_articapandora_'.ord('/').'_pandoraartica_', - '_articapandora_'.ord('.').'_pandoraartica_', - '_articapandora_'.ord('(').'_pandoraartica_', - '_articapandora_'.ord(')').'_pandoraartica_', - '_articapandora_'.ord('¿').'_pandoraartica_', - '_articapandora_'.ord('?').'_pandoraartica_', - '_articapandora_'.ord('¡').'_pandoraartica_', - '_articapandora_'.ord('!').'_pandoraartica_', - ], - io_safe_output($name) - ); - } - - - static function symbol2name($name) - { - $symbols = ' !"#$%&\'()*+,./:;<=>?@[\\]^{|}~'; - for ($i = 0; $i < strlen($symbols); $i++) { - $name = str_replace( - '_articapandora_'.ord(substr($symbols, $i, 1)).'_pandoraartica_', - substr($symbols, $i, 1), - $name - ); - } - - return io_safe_input($name); - } - - - protected function getProcessedModules($modules_tree) - { - return $modules_tree; - } - + protected function getProcessedModules($modules_tree) { + return $modules_tree; + } } +?> diff --git a/pandora_console/include/class/TreeGroup.class.php b/pandora_console/include/class/TreeGroup.class.php index bef4287c7d..fd38794d1c 100644 --- a/pandora_console/include/class/TreeGroup.class.php +++ b/pandora_console/include/class/TreeGroup.class.php @@ -1,215 +1,193 @@ <?php -// Pandora FMS- http://pandorafms.com +//Pandora FMS- http://pandorafms.com // ================================================== // Copyright (c) 2005-2018 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list + // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 + // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + global $config; -require_once $config['homedir'].'/include/class/Tree.class.php'; +require_once($config['homedir']."/include/class/Tree.class.php"); -class TreeGroup extends Tree -{ +class TreeGroup extends Tree { - protected $propagateCounters = true; + protected $propagateCounters = true; + protected $displayAllGroups = false; - protected $displayAllGroups = false; + public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { + global $config; - public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR') - { - global $config; + parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + $this->L1fieldName = "id_group"; + $this->L1extraFields = array( + "tg.nombre AS `name`", + "tg.icon", + "tg.id_grupo AS gid" + ); - $this->L1fieldName = 'id_group'; - $this->L1extraFields = [ - 'tg.nombre AS `name`', - 'tg.icon', - 'tg.id_grupo AS gid', - ]; + $this->L2conditionInside = "AND ( + ta.id_grupo = " . $this->id . " + OR tasg.id_group = " . $this->id . " + )"; + } - $this->L2conditionInside = 'AND ( - ta.id_grupo = '.$this->id.' - OR tasg.id_group = '.$this->id.' - )'; - } + public function setPropagateCounters($value) { + $this->propagateCounters = (bool)$value; + } + public function setDisplayAllGroups($value) { + $this->displayAllGroups = (bool)$value; + } - public function setPropagateCounters($value) - { - $this->propagateCounters = (bool) $value; - } + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); - public function setDisplayAllGroups($value) - { - $this->displayAllGroups = (bool) $value; - } + } elseif ($this->type == 'group') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } + protected function getGroupSearchFilter() { + return ""; + } - protected function getData() - { - if ($this->id == -1) { - $this->getFirstLevel(); - } else if ($this->type == 'group') { - $this->getSecondLevel(); - } else if ($this->type == 'agent') { - $this->getThirdLevel(); - } - } + protected function getFirstLevel() { + $processed_items = $this->getProcessedGroups(); + if (!empty($processed_items)) { + // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants + if (!empty($this->filter['searchGroup'])) { + // Save the groups which intersect with the user groups + $groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%')); + if ($groups == false) $groups = array(); + $userGroupsACL = $this->userGroupsACL; + $ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) { + $group_id = $group['id_grupo']; + if (isset($userGroupsACL[$group_id])) { + $userGroups[$group_id] = $userGroupsACL[$group_id]; + } - protected function getGroupSearchFilter() - { - return ''; - } + return $userGroups; + }, array()); + $result = self::extractGroupsWithIDs($processed_items, $ids_hash); - protected function getFirstLevel() - { - $processed_items = $this->getProcessedGroups(); + $processed_items = ($result === false) ? array() : $result; + } - if (!empty($processed_items)) { - // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants - if (!empty($this->filter['searchGroup'])) { - // Save the groups which intersect with the user groups - $groups = db_get_all_rows_filter('tgrupo', ['nombre' => '%'.$this->filter['searchGroup'].'%']); - if ($groups == false) { - $groups = []; - } + // groupID filter. To access the view from tactical views f.e. + if (!empty($this->filter['groupID'])) { + $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL); - $userGroupsACL = $this->userGroupsACL; - $ids_hash = array_reduce( - $groups, - function ($userGroups, $group) use ($userGroupsACL) { - $group_id = $group['id_grupo']; - if (isset($userGroupsACL[$group_id])) { - $userGroups[$group_id] = $userGroupsACL[$group_id]; - } + $processed_items = ($result === false) ? array() : array($result); + } + } + hd("G-GETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVEL", true); +hd($processed_items, true); + $this->tree = $processed_items; + } - return $userGroups; - }, - [] - ); + protected function getProcessedGroups () { + $processed_groups = array(); + // Index and process the groups + $groups = $this->getGroupCounters(); - $result = self::extractGroupsWithIDs($processed_items, $ids_hash); + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all("AR")) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); + // Propagate child counters to her parents - $processed_items = ($result === false) ? [] : $result; - } + if ($this->propagateCounters) { + TreeGroup::processCounters($groups); + // Filter groups and eliminates the reference to empty groups + $groups = $this->deleteEmptyGroups($groups); + } else { + $groups = $this->deleteEmptyGroupsNotPropagate($groups); + } - // groupID filter. To access the view from tactical views f.e. - if (!empty($this->filter['groupID'])) { - $result = self::extractItemWithID($processed_items, $this->filter['groupID'], 'group', $this->strictACL); + usort($groups, array("Tree", "cmpSortNames")); - $processed_items = ($result === false) ? [] : [$result]; - } - } + return $groups; + } - $this->tree = $processed_items; - } + protected function getGroupCounters() { + $fields = $this->getFirstLevelFields(); + $inside_fields = $this->getFirstLevelFieldsInside(); + $group_acl = ""; + $secondary_group_acl = ""; + if (!users_can_manage_group_all("AR")) { + $user_groups_str = implode(",", $this->userGroupsArray); + $group_acl = " AND ta.id_grupo IN ($user_groups_str)"; + $secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)"; + } + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_search_filter = preg_replace("/%/", "%%", $agent_search_filter); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_status_filter = $this->getModuleStatusFilter(); - protected function getProcessedGroups() - { - $processed_groups = []; - // Index and process the groups - $groups = $this->getGroupCounters(); - - // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all('AR')) { - foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { - $groups[$id]['parent'] = 0; - } - } - } - - // Build the group hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = []; - } - - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); - } - } - - // Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter( - $groups, - function ($group) { - return !$group['have_parent']; - } - ); - // Propagate child counters to her parents - if ($this->propagateCounters) { - self::processCounters($groups); - // Filter groups and eliminates the reference to empty groups - $groups = $this->deleteEmptyGroups($groups); - } else { - $groups = $this->deleteEmptyGroupsNotPropagate($groups); - } - - usort($groups, ['Tree', 'cmpSortNames']); - return $groups; - } - - - protected function getGroupCounters() - { - $fields = $this->getFirstLevelFields(); - $inside_fields = $this->getFirstLevelFieldsInside(); - - $group_acl = ''; - $secondary_group_acl = ''; - if (!users_can_manage_group_all('AR')) { - $user_groups_str = implode(',', $this->userGroupsArray); - $group_acl = " AND ta.id_grupo IN ($user_groups_str)"; - $secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)"; - } - - $agent_search_filter = $this->getAgentSearchFilter(); - $agent_search_filter = preg_replace('/%/', '%%', $agent_search_filter); - $agent_status_filter = $this->getAgentStatusFilter(); - $module_status_filter = $this->getModuleStatusFilter(); - - $module_search_inner = ''; - $module_search_filter = ''; - if (!empty($this->filter['searchModule'])) { - $module_search_inner = ' + $module_search_inner = ""; + $module_search_filter = ""; + if (!empty($this->filter['searchModule'])) { + $module_search_inner = " INNER JOIN tagente_modulo tam ON ta.id_agente = tam.id_agente INNER JOIN tagente_estado tae - ON tae.id_agente_modulo = tam.id_agente_modulo'; - $module_search_filter = "AND tam.disabled = 0 - AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' ".$this->getModuleStatusFilterFromTestado(); - } + ON tae.id_agente_modulo = tam.id_agente_modulo"; + $module_search_filter = "AND tam.disabled = 0 + AND tam.nombre LIKE '%%" . $this->filter['searchModule'] . "%%' " . + $this->getModuleStatusFilterFromTestado() + ; + } - $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente'; - $table_sec = is_metaconsole() ? 'tmetaconsole_agent_secondary_group' : 'tagent_secondary_group'; + $table = is_metaconsole() ? "tmetaconsole_agent" : "tagente"; + $table_sec = is_metaconsole() ? "tmetaconsole_agent_secondary_group" : "tagent_secondary_group"; - $sql_model = "SELECT %s FROM + $sql_model = "SELECT %s FROM ( SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_grupo AS g FROM $table ta @@ -236,294 +214,254 @@ class TreeGroup extends Tree $secondary_group_acl GROUP BY id_group ) x GROUP BY g"; - $sql_array = []; - foreach ($inside_fields as $inside_field) { - $sql_array[] = sprintf( - $sql_model, - $inside_field['header'], - $inside_field['condition'], - $inside_field['condition'] - ); - } - - $sql = "SELECT $fields FROM (".implode(' UNION ALL ', $sql_array).') x2 + $sql_array = array(); + foreach ($inside_fields as $inside_field) { + $sql_array[] = sprintf( + $sql_model, + $inside_field['header'], + $inside_field['condition'], + $inside_field['condition'] + ); + } + $sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2 RIGHT JOIN tgrupo tg ON x2.g = tg.id_grupo - GROUP BY tg.id_grupo'; - $stats = db_get_all_rows_sql($sql); + GROUP BY tg.id_grupo"; + $stats = db_get_all_rows_sql($sql); - $group_stats = []; - foreach ($stats as $group) { - $group_stats[$group['gid']]['total_count'] = (int) $group['total_count']; - $group_stats[$group['gid']]['total_critical_count'] = (int) $group['total_critical_count']; - $group_stats[$group['gid']]['total_unknown_count'] = (int) $group['total_unknown_count']; - $group_stats[$group['gid']]['total_warning_count'] = (int) $group['total_warning_count']; - $group_stats[$group['gid']]['total_not_init_count'] = (int) $group['total_not_init_count']; - $group_stats[$group['gid']]['total_normal_count'] = (int) $group['total_normal_count']; - $group_stats[$group['gid']]['total_fired_count'] = (int) $group['total_alerts_count']; - $group_stats[$group['gid']]['name'] = $group['name']; - $group_stats[$group['gid']]['parent'] = $group['parent']; - $group_stats[$group['gid']]['icon'] = $group['icon']; - $group_stats[$group['gid']]['id'] = $group['gid']; - $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); - } + $group_stats = array(); - return $group_stats; - } + hd("STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS ", true); + hd($stats, true); + foreach ($stats as $group) { + $group_stats[$group['gid']]['total_count'] = (int)$group['total_count']; + $group_stats[$group['gid']]['total_critical_count'] = (int)$group['total_critical_count']; + $group_stats[$group['gid']]['total_unknown_count'] = (int)$group['total_unknown_count']; + $group_stats[$group['gid']]['total_warning_count'] = (int)$group['total_warning_count']; + $group_stats[$group['gid']]['total_not_init_count'] = (int)$group['total_not_init_count']; + $group_stats[$group['gid']]['total_normal_count'] = (int)$group['total_normal_count']; + $group_stats[$group['gid']]['total_fired_count'] = (int)$group['total_alerts_count']; + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + + } - protected function getFirstLevelFields() - { - $fields = parent::getFirstLevelFields(); - $parent = $this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent'; - return "$fields, $parent"; - } + return $group_stats; + } - protected function getProcessedModules($modules_tree) - { - $groups = []; - foreach ($modules_tree as $group) { - $groups[$group['id']] = $group; - } + protected function getFirstLevelFields() { + $fields = parent::getFirstLevelFields(); + $parent = $this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent'; + return "$fields, $parent"; + } - // Build the module hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = []; - } + protected function getProcessedModules($modules_tree) { - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } + $groups = array(); + foreach ($modules_tree as $group) { + $groups[$group["id"]] = $group; + } - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); - } - } + // Build the module hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } - // Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter( - $groups, - function ($group) { - return !$group['have_parent']; - } - ); + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); - return array_values($groups); - } + return array_values($groups); + } + // FIXME: Hierarchy lops is broken + protected function getProcessedModules_old($modules_tree) { - // FIXME: Hierarchy lops is broken - protected function getProcessedModules_old($modules_tree) - { - $tree_modules = []; - $new_modules_root = array_filter( - $modules_tree, - function ($module) { - return (isset($module['parent']) && ($module['parent'] == 0)); - } - ); + $tree_modules = array(); + $new_modules_root = array_filter($modules_tree, function ($module) { + return (isset($module['parent']) && ($module['parent'] == 0)); + }); - $new_modules_child = array_filter( - $modules_tree, - function ($module) { - return (isset($module['parent']) && ($module['parent'] != 0)); - } - ); + $new_modules_child = array_filter($modules_tree, function ($module) { + return (isset($module['parent']) && ($module['parent'] != 0)); + }); - $i = 0; - while (!empty($new_modules_child)) { - foreach ($new_modules_child as $i => $child) { - self::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); - } - } + $i = 0; + while (!empty($new_modules_child)) { + foreach ($new_modules_child as $i => $child) { + TreeGroup::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); + } + } - foreach ($new_modules_root as $m) { - $tree_modules[] = $m; - } + foreach ($new_modules_root as $m) { + $tree_modules[] = $m; + } + return $tree_modules; + } - return $tree_modules; - } + // FIXME with getProcessedModules_old + static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) { + foreach ($new_modules as $index => $module) { + if ($module['id'] == $child['parent']) { + $new_modules[$index]['children'][] = $child; + unset($new_modules_child[$i]); + break; + } + else if (isset($new_modules[$index]['children'])) { + TreeGroup::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child); + } + } + } + static function processCounters(&$groups) { + $all_counters = array(); + foreach ($groups as $id => $group) { + $child_counters = array(); + if (!empty($groups[$id]['children'])) { + $child_counters = TreeGroup::processCounters($groups[$id]['children']); + } + if (!empty($child_counters)) { + foreach($child_counters as $type => $value) { + $groups[$id]['counters'][$type] += $value; + } + } + foreach($groups[$id]['counters'] as $type => $value) { + $all_counters[$type] += $value; + } + } + return $all_counters; + } - // FIXME with getProcessedModules_old - static function recursive_modules_tree_view(&$new_modules, &$new_modules_child, $i, $child) - { - foreach ($new_modules as $index => $module) { - if ($module['id'] == $child['parent']) { - $new_modules[$index]['children'][] = $child; - unset($new_modules_child[$i]); - break; - } else if (isset($new_modules[$index]['children'])) { - self::recursive_modules_tree_view($new_modules[$index]['children'], $new_modules_child, $i, $child); - } - } - } + /** + * @brief Recursive function to remove the empty groups + * + * @param groups All groups structure + * + * @return new_groups A new groups structure without empty groups + */ + protected function deleteEmptyGroups ($groups) { + if($this->displayAllGroups) return $groups; + $new_groups = array(); + foreach ($groups as $group) { + // If a group is empty, do not add to new_groups. + if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { + continue; + } + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = $this->deleteEmptyGroups ($group['children']); + if (empty($children)) unset($group['children']); + else $group['children'] = $children; + } + $new_groups[] = $group; + } + return $new_groups; + } + protected function deleteEmptyGroupsNotPropagate ($groups) { + if($this->displayAllGroups) return $groups; + $new_groups = array(); + foreach ($groups as $group) { + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = $this->deleteEmptyGroupsNotPropagate ($group['children']); + if (empty($children)) { + unset($group['children']); + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } else { + $group['children'] = $children; + $new_groups[] = $group; + } + } else { + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } + } + return $new_groups; + } - static function processCounters(&$groups) - { - $all_counters = []; - foreach ($groups as $id => $group) { - $child_counters = []; - if (!empty($groups[$id]['children'])) { - $child_counters = self::processCounters($groups[$id]['children']); - } + private static function extractGroupsWithIDs ($groups, $ids_hash) { + $result_groups = array(); + foreach ($groups as $group) { + if (isset($ids_hash[$group['id']])) { + $result_groups[] = $group; + } + else if (!empty($group['children'])) { + $result = self::extractGroupsWithIDs($group['children'], $ids_hash); - if (!empty($child_counters)) { - foreach ($child_counters as $type => $value) { - $groups[$id]['counters'][$type] += $value; - } - } + // Item found on children + if (!empty($result)) { + $result_groups = array_merge($result_groups, $result); + } + } + } - foreach ($groups[$id]['counters'] as $type => $value) { - $all_counters[$type] += $value; - } - } + return $result_groups; + } - return $all_counters; - } + private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) { + foreach ($items as $item) { + if ($item["type"] != $item_type) + continue; + // Item found + if ($strictACL && is_metaconsole()) { + foreach ($item["id"] as $server_id => $id) { + if ($id == $item_id) + return $item; + } + } + else { + if ($item["id"] == $item_id) + return $item; + } - /** - * @brief Recursive function to remove the empty groups - * - * @param groups All groups structure - * - * @return new_groups A new groups structure without empty groups - */ - protected function deleteEmptyGroups($groups) - { - if ($this->displayAllGroups) { - return $groups; - } + if ($item["type"] == "group" && !empty($item["children"])) { + $result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL); - $new_groups = []; - foreach ($groups as $group) { - // If a group is empty, do not add to new_groups. - if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { - continue; - } + // Item found on children + if ($result !== false) + return $result; + } + } - // Tray to remove the children groups - if (!empty($group['children'])) { - $children = $this->deleteEmptyGroups($group['children']); - if (empty($children)) { - unset($group['children']); - } else { - $group['children'] = $children; - } - } - - $new_groups[] = $group; - } - - return $new_groups; - } - - - protected function deleteEmptyGroupsNotPropagate($groups) - { - if ($this->displayAllGroups) { - return $groups; - } - - $new_groups = []; - foreach ($groups as $group) { - // Tray to remove the children groups - if (!empty($group['children'])) { - $children = $this->deleteEmptyGroupsNotPropagate($group['children']); - if (empty($children)) { - unset($group['children']); - // If a group is empty, do not add to new_groups. - if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { - $new_groups[] = $group; - } - } else { - $group['children'] = $children; - $new_groups[] = $group; - } - } else { - // If a group is empty, do not add to new_groups. - if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { - $new_groups[] = $group; - } - } - } - - return $new_groups; - } - - - private static function extractGroupsWithIDs($groups, $ids_hash) - { - $result_groups = []; - foreach ($groups as $group) { - if (isset($ids_hash[$group['id']])) { - $result_groups[] = $group; - } else if (!empty($group['children'])) { - $result = self::extractGroupsWithIDs($group['children'], $ids_hash); - - // Item found on children - if (!empty($result)) { - $result_groups = array_merge($result_groups, $result); - } - } - } - - return $result_groups; - } - - - private static function extractItemWithID($items, $item_id, $item_type='group', $strictACL=false) - { - foreach ($items as $item) { - if ($item['type'] != $item_type) { - continue; - } - - // Item found - if ($strictACL && is_metaconsole()) { - foreach ($item['id'] as $server_id => $id) { - if ($id == $item_id) { - return $item; - } - } - } else { - if ($item['id'] == $item_id) { - return $item; - } - } - - if ($item['type'] == 'group' && !empty($item['children'])) { - $result = self::extractItemWithID($item['children'], $item_id, $item_type, $strictACL); - - // Item found on children - if ($result !== false) { - return $result; - } - } - } - - // Item not found - return false; - } - - - protected function getDisplayHierarchy() - { - return $this->filter['searchHirearchy'] || - (empty($this->filter['searchAgent']) && empty($this->filter['searchModule'])); - } + // Item not found + return false; + } + protected function getDisplayHierarchy() { + return $this->filter['searchHirearchy'] || + (empty($this->filter['searchAgent']) && empty($this->filter['searchModule'])); + } } + +?> + diff --git a/pandora_console/include/class/TreeGroupEdition.class.php b/pandora_console/include/class/TreeGroupEdition.class.php index 55efebe976..dea62da238 100644 --- a/pandora_console/include/class/TreeGroupEdition.class.php +++ b/pandora_console/include/class/TreeGroupEdition.class.php @@ -1,120 +1,108 @@ <?php -// Pandora FMS- http://pandorafms.com +//Pandora FMS- http://pandorafms.com // ================================================== // Copyright (c) 2005-2018 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list + // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 + // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + global $config; -require_once $config['homedir'].'/include/class/Tree.class.php'; +require_once($config['homedir']."/include/class/Tree.class.php"); -class TreeGroupEdition extends TreeGroup -{ +class TreeGroupEdition extends TreeGroup { + public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { + global $config; + + parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } + } + + protected function getProcessedGroups () { + $processed_groups = array(); + // Index and process the groups + $groups = $this->getGroupCounters(); + + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all("AR")) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = array(); + } + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], array("Tree", "cmpSortNames")); + } + } + //Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter($groups, function ($group) { + return !$group['have_parent']; + }); + + usort($groups, array("Tree", "cmpSortNames")); + return $groups; + } - public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR') - { - global $config; - - parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - } - - - protected function getData() - { - if ($this->id == -1) { - $this->getFirstLevel(); - } - } - - - protected function getProcessedGroups() - { - $processed_groups = []; - // Index and process the groups - $groups = $this->getGroupCounters(); - - // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all('AR')) { - foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { - $groups[$id]['parent'] = 0; - } - } - } - - // Build the group hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = []; - } - - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); - } - } - - // Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter( - $groups, - function ($group) { - return !$group['have_parent']; - } - ); - - usort($groups, ['Tree', 'cmpSortNames']); - return $groups; - } - - - protected function getGroupCounters() - { - $messages = [ - 'confirm' => __('Confirm'), - 'cancel' => __('Cancel'), - 'messg' => __('Are you sure?'), - ]; - $sql = 'SELECT id_grupo AS gid, + protected function getGroupCounters() { + $messages = array( + 'confirm' => __('Confirm'), + 'cancel' => __('Cancel'), + 'messg' => __('Are you sure?') + ); + $sql = "SELECT id_grupo AS gid, nombre as name, parent, icon FROM tgrupo - '; + "; - $stats = db_get_all_rows_sql($sql); - $group_stats = []; - foreach ($stats as $group) { - $group_stats[$group['gid']]['name'] = $group['name']; - $group_stats[$group['gid']]['parent'] = $group['parent']; - $group_stats[$group['gid']]['icon'] = $group['icon']; - $group_stats[$group['gid']]['id'] = $group['gid']; - $group_stats[$group['gid']]['type'] = 'group'; - - $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); - $group_stats[$group['gid']]['delete']['messages'] = $messages; - $group_stats[$group['gid']]['edit'] = 1; - $group_stats[$group['gid']]['alerts'] = ''; - } - - return $group_stats; - } + $stats = db_get_all_rows_sql($sql); + $group_stats = array(); + foreach ($stats as $group) { + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']]['type'] = 'group'; + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + $group_stats[$group['gid']]['delete']['messages'] = $messages; + $group_stats[$group['gid']]['edit'] = 1; + $group_stats[$group['gid']]['alerts'] = ''; + } + return $group_stats; + } } + +?> + diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php new file mode 100644 index 0000000000..46f9139427 --- /dev/null +++ b/pandora_console/include/class/TreeService.class.php @@ -0,0 +1,342 @@ +<?php +//Pandora FMS- http://pandorafms.com +// ================================================== +// Copyright (c) 2005-2018 Artica Soluciones Tecnologicas +// Please see http://pandorafms.org for full contribution list + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation; version 2 + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +global $config; + +require_once($config['homedir']."/include/class/Tree.class.php"); + +class TreeService extends Tree { + + protected $propagateCounters = true; + protected $displayAllGroups = false; + + public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { + global $config; + + parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + + $this->L1fieldName = "id_group"; + $this->L1extraFields = array( + "ts.name AS `name`", + "ts.id AS `sid`" + ); + + $this->filter['statusAgent'] = AGENT_STATUS_ALL; + + $this->avoid_condition = true; + + $this->L2inner = 'LEFT JOIN tservice_element tse + ON tse.id_agent = ta.id_agente'; + + $this->L2condition = 'AND tse.id_service='.$this->id; + + } + + public function setPropagateCounters($value) { + $this->propagateCounters = (bool)$value; + } + + public function setDisplayAllGroups($value) { + $this->displayAllGroups = (bool)$value; + } + + protected function getData() { + if ($this->id == -1) { + $this->getFirstLevel(); + } elseif ($this->type == 'services') { + $this->getSecondLevel(); + } elseif ($this->type == 'agent') { + $this->getThirdLevel(); + } + } + + protected function getFirstLevel() { + $processed_items = $this->getProcessedServices(); + $ids = array_keys($processed_items); + + + + $filter=array('id'=>$ids); + + $own_info = get_user_info($config['id_user']); + + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) { + $display_all_services = true; + } else { + $display_all_services = false; + } + + $this->tree = []; + + $services = services_get_services($filter, false, $display_all_services); + + foreach ($services as $row) { + + + + $status = services_get_status($row, true); + + switch ($status) { + + case SERVICE_STATUS_NORMAL: + $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + break; + + case SERVICE_STATUS_CRITICAL: + $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + break; + + case SERVICE_STATUS_WARNING: + $processed_items[$row['id']][$key]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + break; + + case SERVICE_STATUS_UNKNOWN: + default: + $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + break; + } + } + + $this->tree = $processed_items; + } + + protected function getProcessedServices () { + $fields = $this->getFirstLevelFields(); + + //hd($this->userGroupsArray, true); + + if (users_can_manage_group_all("AR")){ + $groups_acl = ""; + } + else{ + $groups_acl = "AND ts.id_group IN (".implode(',', $this->userGroupsArray).")"; + } + + $sql = sprintf("SELECT t1.* + FROM tservice_element tss + RIGHT JOIN + (SELECT ts.id, ts.id_agent_module, ts.name, ts.name AS `alias`, ts.id AS `rootID`, + 'services' AS rootType, 'services' AS type, + 0 AS quiet, + SUM(if((tse.id_agent<>0), 1, 0)) AS `total_agents`, + SUM(if((tse.id_agente_modulo<>0), 1, 0)) AS `total_modules`, + SUM(if((tse.id_service_child<>0), 1, 0)) AS `total_services` + FROM tservice ts + LEFT JOIN tservice_element tse + ON ts.id=tse.id_service + GROUP BY id + ) as t1 + ON tss.id_service_child = t1.id + WHERE tss.id_service_child IS NULL + %s + ", + $groups_acl + ); + + + $stats = db_get_all_rows_sql($sql); + + + + + $services = array(); + + foreach ($stats as $service) { + $services[$service['id']] = $this->getProcessedItem($services[$service['id']]); + if ($service['total_services']+$service['total_agents']+$service['total_modules'] > 0) + $services[$service['id']]['searchChildren'] = 1; + else + $services[$service['id']]['searchChildren'] = 0; + + $services[$service['id']]['counters'] = array('total_services'=>$service['total_services'], 'total_agents'=>$service['total_agents'], 'total_modules'=>$service['total_modules']); + $services[$service['id']]['name'] = $service['name']; + $services[$service['id']]['id'] = $service['id']; + $services[$service['id']]['serviceDetail']='http://localhost/pandora_console/index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; + } + + hd("STATS:::::::::::::::::::::::::::::: ", true); +hd($services, true); + + return $services; + } + + protected function getFirstLevelFields() { + $fields = array(); + + return implode(",", array_merge($fields, $this->L1extraFields)); + } + + protected function getSecondLevel() { + $data = array(); + $data_agents = array(); + $data_modules = array(); + $data_services = array(); + + $sql = $this->getSecondLevelSql(); + $data_agents = db_process_sql($sql); + + if (empty($data_agents)) + $data_agents = array(); + + $this->processAgents($data_agents); + + foreach ($data_agents as $key => $agent) { + $data_agents[$key]['showEventsBtn'] = 1; + $data_agents[$key]['eventAgent'] = $agent['id']; + } + + $sql = $this->getSecondLevelModulesSql(); + $data_modules = db_process_sql($sql); + + if (empty($data_modules)) + $data_modules = array(); + else { + foreach ($data_modules as $key => $module) { + switch ($module['estado']) { + case '0': + $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + break; + case '1': + $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + break; + case '2': + $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + break; + case '4': + $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + break; + default: + # code... + break; + } + + $data_modules[$key]['showEventsBtn'] = 1; + $data_modules[$key]['eventModule'] = $module['id_agente_modulo']; + } + } + + hd("MODULESSSS::", true); +hd($data_modules, true); + + $sql = $this->getSecondLevelServicesSql(); + $data_services = db_process_sql($sql); + + + $service_stats = array(); + + foreach ($data_services as $service) { + $service_stats[$service['id']]['id'] = (int)$service['id']; + $service_stats[$service['id']]['name'] = $service['name']; + $service_stats[$service['id']]['alias'] = $service['name']; + if ($service['total_services']+$service['total_agents']+$service['total_modules'] > 0) + $service_stats[$service['id']]['searchChildren'] = 1; + else + $services[$service['id']]['searchChildren'] = 0; + + $service_stats[$service['id']]['rootID'] = $service['rootID']; + $service_stats[$service['id']]['rootType'] = $service['rootType']; + $service_stats[$service['id']]['type'] = 'services'; + $service_stats[$service['id']]['children']=array(); + $service_stats[$service['id']]['serviceDetail']='http://localhost/pandora_console/index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; + $service_stats[$service['id']]['counters']=array('total_services'=>$service['total_services'], 'total_agents'=>$service['total_agents'], 'total_modules'=>$service['total_modules']); + + } + + $own_info = get_user_info($config['id_user']); + + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) { + $display_all_services = true; + } else { + $display_all_services = false; + } + + $services = services_get_services($filter, false, $display_all_services); + + foreach ($services as $row) { + + if (!array_key_exists($row['id'], $service_stats)) + continue; + + $status = services_get_status($row, true); + + + switch ($status) { + + case SERVICE_STATUS_NORMAL: + $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + break; + + case SERVICE_STATUS_CRITICAL: + $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + break; + + case SERVICE_STATUS_WARNING: + $service_stats[$row['id']][$key]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + break; + + case SERVICE_STATUS_UNKNOWN: + default: + $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + break; + } + } + + $data_services = array_values($service_stats); + + $data = array_merge($data_services, $data_agents, $data_modules); + + if (empty($data)) { + $this->tree = array(); + return; + } + + $this->tree = $data; + } + + protected function getSecondLevelServicesSql() { + $group_acl = $this->getGroupAclCondition(); + + $sql = "SELECT ts.id, ts.name, tse1.id_service AS `rootID`, 'services' AS rootType, 'services' AS type, 0 AS quiet, SUM(if((tse2.id_agent<>0), 1, 0)) AS `total_agents`, SUM(if((tse2.id_agente_modulo<>0), 1, 0)) AS `total_modules`, SUM(if((tse2.id_service_child<>0), 1, 0)) AS `total_services`, 0 AS fired_count, 0 AS normal_count, 0 AS warning_count, 0 AS critical_count, 0 AS unknown_count, 0 AS notinit_count, 0 AS state_critical, 0 AS state_warning, 0 AS state_unknown, 0 AS state_notinit, 0 AS state_normal, 0 AS state_total, '' AS statusImageHTML, '' AS alertImageHTML + FROM tservice_element tse1 + LEFT JOIN tservice_element tse2 ON tse1.id_service_child=tse2.id_service + LEFT JOIN tservice ts ON tse1.id_service_child=ts.id + WHERE tse1.id_service=$this->id AND tse1.id_service_child<>0 + GROUP BY tse1.id_service_child + "; + + return $sql; + } + + + protected function getSecondLevelModulesSql() { + + $sql = "SELECT tse.id_agente_modulo, nombre AS `name`, nombre AS `alias`, tse.id_service AS `rootID`, 'services' AS `rootType`, 'modules' AS `type`, estado + FROM tservice_element tse + INNER JOIN tagente_modulo tam ON tse.id_agente_modulo=tam.id_agente_modulo + INNER JOIN tagente_estado tae ON tam.id_agente_modulo=tae.id_agente_estado + WHERE tse.id_service=$this->id AND tse.id_agente_modulo<>0 + "; + + return $sql; + } + + protected function getAgentStatusFilter ($status = self::TV_DEFAULT_AGENT_STATUS) { + return ''; + } + +} + +?> + diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index e3f7260de4..e22a17ced9 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -13,895 +13,991 @@ // GNU General Public License for more details. var TreeController = { - controllers: [], - getController: function() { - var controller = { - index: -1, - recipient: "", - tree: [], - emptyMessage: "No data found.", - foundMessage: "Found groups", - errorMessage: "Error", - baseURL: "", - ajaxURL: "ajax.php", - ajaxPage: "include/ajax/tree.ajax", - detailRecipient: "", - filter: {}, - counterTitles: {}, - shouldHaveCounters: true, - reload: function() { - // Bad recipient - if ( - typeof this.recipient == "undefined" || - this.recipient.length == 0 - ) { - return; - } - - // Load branch - function _processGroup(container, elements, rootGroup) { - var $group = $("<ul></ul>"); - - // First group - if (typeof rootGroup != "undefinded" && rootGroup == true) { - $group - .addClass("tree-root") - .hide() - .prepend( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - 'images/pandora.png" />' - ); - } - // Normal group - else { - $group.addClass("tree-group").hide(); - } - - container.append($group); - - _.each(elements, function(element) { - element.jqObject = _processNode($group, element); - }); - - return $group; - } - - // Load leaf counters - function _processNodeCounters(container, counters, type) { - var hasCounters = false; - - if (typeof counters != "undefined") { - function _processNodeCounterTitle( - container, - elementType, - counterType - ) { - var defaultCounterTitles = { - total: { - agents: "Total agents", - modules: "Total modules", - none: "Total" - }, - alerts: { - agents: "Alerts fired", - modules: "Alerts fired", - none: "Alerts fired" - }, - critical: { - agents: "Critical agents", - modules: "Critical modules", - none: "Critical" - }, - warning: { - agents: "Warning agents", - modules: "Warning modules", - none: "Warning" - }, - unknown: { - agents: "Unknown agents", - modules: "Unknown modules", - none: "Unknown" - }, - not_init: { - agents: "Not init agents", - modules: "Not init modules", - none: "Not init" - }, - ok: { - agents: "Normal agents", - modules: "Normal modules", - none: "Normal" - } - }; - - try { - var title = ""; - switch (elementType) { - case "group": - if ( - typeof controller.counterTitles != "undefined" && - typeof controller.counterTitles[counterType] != - "undefined" && - typeof controller.counterTitles[counterType].agents != - "undefined" - ) { - title = controller.counterTitles[counterType].agents; - } else { - title = defaultCounterTitles[counterType].agents; - } - break; - case "agent": - if ( - typeof controller.counterTitles != "undefined" && - typeof controller.counterTitles[counterType] != - "undefined" && - typeof controller.counterTitles[counterType].modules != - "undefined" - ) { - title = controller.counterTitles[counterType].modules; - } else { - title = defaultCounterTitles[counterType].modules; - } - break; - default: - if ( - typeof controller.counterTitles != "undefined" && - typeof controller.counterTitles[counterType] != - "undefined" && - typeof controller.counterTitles[counterType].none != - "undefined" - ) { - title = controller.counterTitles[counterType].none; - } else { - title = defaultCounterTitles[counterType].none; - } - break; - } - if (title.length > 0) { - container - .data("title", title) - .addClass("forced_title") - .data("use_title_for_force_title", 1); // Trick to make easier the 'force title' output - } - } catch (error) { - // console.log(error); - } - } - - var $counters = $("<div></div>"); - $counters.addClass("tree-node-counters"); - - if (typeof counters.total != "undefined" && counters.total >= 0) { - var $totalCounter = $("<div></div>"); - $totalCounter - .addClass("tree-node-counter") - .addClass("total") - .html(counters.total); - - _processNodeCounterTitle($totalCounter, type, "total"); - - // Open the parentheses - $counters.append(" ("); - - $counters.append($totalCounter); - - if ( - typeof counters.alerts != "undefined" && - counters.alerts > 0 - ) { - var $firedCounter = $("<div></div>"); - $firedCounter - .addClass("tree-node-counter") - .addClass("alerts") - .addClass("orange") - .html(counters.alerts); - - _processNodeCounterTitle($firedCounter, type, "alerts"); - - $counters.append(" : ").append($firedCounter); - } - if ( - typeof counters.critical != "undefined" && - counters.critical > 0 - ) { - var $criticalCounter = $("<div></div>"); - $criticalCounter - .addClass("tree-node-counter") - .addClass("critical") - .addClass("red") - .html(counters.critical); - - _processNodeCounterTitle($criticalCounter, type, "critical"); - - $counters.append(" : ").append($criticalCounter); - } - if ( - typeof counters.warning != "undefined" && - counters.warning > 0 - ) { - var $warningCounter = $("<div></div>"); - $warningCounter - .addClass("tree-node-counter") - .addClass("warning") - .addClass("yellow") - .html(counters.warning); - - _processNodeCounterTitle($warningCounter, type, "warning"); - - $counters.append(" : ").append($warningCounter); - } - if ( - typeof counters.unknown != "undefined" && - counters.unknown > 0 - ) { - var $unknownCounter = $("<div></div>"); - $unknownCounter - .addClass("tree-node-counter") - .addClass("unknown") - .addClass("grey") - .html(counters.unknown); - - _processNodeCounterTitle($unknownCounter, type, "unknown"); - - $counters.append(" : ").append($unknownCounter); - } - if ( - typeof counters.not_init != "undefined" && - counters.not_init > 0 - ) { - var $notInitCounter = $("<div></div>"); - $notInitCounter - .addClass("tree-node-counter") - .addClass("not_init") - .addClass("blue") - .html(counters.not_init); - - _processNodeCounterTitle($notInitCounter, type, "not_init"); - - $counters.append(" : ").append($notInitCounter); - } - if (typeof counters.ok != "undefined" && counters.ok > 0) { - var $okCounter = $("<div></div>"); - $okCounter - .addClass("tree-node-counter") - .addClass("ok") - .addClass("green") - .html(counters.ok); - - _processNodeCounterTitle($okCounter, type, "ok"); - - $counters.append(" : ").append($okCounter); - } - - // Close the parentheses - $counters.append(")"); - - hasCounters = true; - } - - // Add the counters html to the container - container.append($counters); - } - - return hasCounters; - } - - // Load leaf - function _processNode(container, element) { - // type, [id], [serverID], callback - function _getTreeDetailData(type, id, serverID, callback) { - var lastParam = arguments[arguments.length - 1]; - var callback; - if (typeof lastParam === "function") callback = lastParam; - - var serverID; - if (arguments.length >= 4) serverID = arguments[2]; - var id; - if (arguments.length >= 3) id = arguments[1]; - var type; - if (arguments.length >= 2) type = arguments[0]; - - if (typeof type === "undefined") - throw new TypeError("Type required"); - if (typeof callback === "undefined") - throw new TypeError("Callback required"); - - var postData = { - page: controller.ajaxPage, - getDetail: 1, - type: type - }; - - if (typeof id !== "undefined") postData.id = id; - if (typeof serverID !== "undefined") postData.serverID = serverID; - - $.ajax({ - url: controller.ajaxURL, - type: "POST", - dataType: "html", - data: postData, - success: function(data, textStatus, xhr) { - callback(null, data); - }, - error: function(xhr, textStatus, errorThrown) { - callback(errorThrown); - } - }); - } - - var $node = $("<li></li>"); - var $leafIcon = $("<div></div>"); - var $content = $("<div></div>"); - - // Leaf icon - $leafIcon.addClass("leaf-icon"); - - // Content - $content.addClass("node-content"); - switch (element.type) { - case "group": - if ( - typeof element.icon != "undefined" && - element.icon.length > 0 - ) { - $content.append( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - "images/groups_small/" + - element.icon + - '" /> ' - ); - } else if ( - typeof element.iconHTML != "undefined" && - element.iconHTML.length > 0 - ) { - $content.append(element.iconHTML + " "); - } - $content.append(element.name); - - if (typeof element.edit != "undefined") { - var url_edit = - controller.baseURL + - "index.php?sec=gagente&sec2=godmode/groups/configure_group&tab=tree&id_group=" + - element.id; - var $updateicon = $( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - 'images/config.png" style="width:18px; vertical-align: middle;"/>' - ); - var $updatebtn = $('<a href = "' + url_edit + '"></a>').append( - $updateicon - ); - $content.append($updatebtn); - } - - if (typeof element.delete != "undefined") { - var url_delete = - controller.baseURL + - "index.php?sec=gagente&sec2=godmode/groups/group_list&tab=tree&delete_group=1&id_group=" + - element.id; - var $deleteBtn = $( - '<a><img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - 'images/cross.png" style="width:18px; vertical-align: middle; cursor: pointer;"/></a>' - ); - $deleteBtn.click(function(event) { - var ok_function = function() { - window.location.replace(url_delete); - }; - display_confirm_dialog( - element.delete.messages.messg, - element.delete.messages.confirm, - element.delete.messages.cancel, - ok_function - ); - }); - $content.append($deleteBtn); - } - - if (typeof element.alerts != "undefined") { - $content.append(element.alerts); - } - - break; - case "agent": - // Is quiet - if ( - typeof element.quietImageHTML != "undefined" && - element.quietImageHTML.length > 0 - ) { - var $quietImage = $(element.quietImageHTML); - $quietImage.addClass("agent-quiet"); - - $content.append($quietImage); - } - // Status image - if ( - typeof element.statusImageHTML != "undefined" && - element.statusImageHTML.length > 0 - ) { - var $statusImage = $(element.statusImageHTML); - $statusImage.addClass("agent-status"); - - $content.append($statusImage); - } - // Alerts fired image - if ( - typeof element.alertImageHTML != "undefined" && - element.alertImageHTML.length > 0 - ) { - var $alertImage = $(element.alertImageHTML); - $alertImage.addClass("agent-alerts-fired"); - - $content.append($alertImage); - } - $content.append(element.alias); - break; - case "module": - // Status image - if ( - typeof element.statusImageHTML != "undefined" && - element.statusImageHTML.length > 0 - ) { - var $statusImage = $(element.statusImageHTML); - $statusImage.addClass("module-status"); - - $content.append($statusImage); - } - // Server type - if ( - typeof element.serverTypeHTML != "undefined" && - element.serverTypeHTML.length > 0 && - element.serverTypeHTML != "--" - ) { - var $serverTypeImage = $(element.serverTypeHTML); - $serverTypeImage.addClass("module-server-type"); - - $content.append($serverTypeImage); - } - - if ( - typeof element.showGraphs != "undefined" && - element.showGraphs != 0 - ) { - // Graph pop-up - if (typeof element.moduleGraph != "undefined") { - if (element.statusImageHTML.indexOf("data:image") != -1) { - var $graphImage = $( - '<img src="' + - (controller.baseURL.length > 0 - ? controller.baseURL - : "") + - 'images/photo.png" /> ' - ); - } else { - var $graphImage = $( - '<img src="' + - (controller.baseURL.length > 0 - ? controller.baseURL - : "") + - 'images/chart_curve.png" /> ' - ); - } - - $graphImage.addClass("module-graph").click(function(e) { - e.preventDefault(); - if (element.statusImageHTML.indexOf("data:image") != -1) { - try { - winopeng_var( - decodeURI(element.snapshot[0]), - element.snapshot[1], - element.snapshot[2], - element.snapshot[3] - ); - } catch (error) { - // console.log(error); - } - } else { - try { - winopeng( - element.moduleGraph.url, - element.moduleGraph.handle - ); - } catch (error) { - // console.log(error); - } - } - }); - - $content.append($graphImage); - } - - // Data pop-up - if (typeof element.id != "undefined" && !isNaN(element.id)) { - var $dataImage = $( - '<img src="' + - (controller.baseURL.length > 0 - ? controller.baseURL - : "") + - 'images/binary.png" /> ' - ); - $dataImage.addClass("module-data").click(function(e) { - e.preventDefault(); - - try { - var serverName = - element.serverName.length > 0 ? element.serverName : ""; - if ($("#module_details_window").length > 0) - show_module_detail_dialog( - element.id, - "", - serverName, - 0, - 86400, - element.name.replace(/ /g, " ") - ); - } catch (error) { - // console.log(error); - } - }); - - $content.append($dataImage); - } - } - - // Alerts - if ( - typeof element.alertsImageHTML != "undefined" && - element.alertsImageHTML.length > 0 - ) { - var $alertsImage = $(element.alertsImageHTML); - - $alertsImage - .addClass("module-alerts") - .click(function(e) { - _getTreeDetailData( - "alert", - element.id, - element.serverID, - function(error, data) { - if (error) { - // console.error(error); - } else { - controller.detailRecipient - .render(element.name, data) - .open(); - } - } - ); - - // Avoid the execution of the module detail event - e.stopPropagation(); - }) - .css("cursor", "pointer"); - - $content.append($alertsImage); - } - - $content.append(element.name); - break; - case "os": - if ( - typeof element.icon != "undefined" && - element.icon.length > 0 - ) { - $content.append( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - "images/os_icons/" + - element.icon + - '" /> ' - ); - } - $content.append(element.name); - break; - case "tag": - if ( - typeof element.icon != "undefined" && - element.icon.length > 0 - ) { - $content.append( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - "images/os_icons/" + - element.icon + - '" /> ' - ); - } else { - $content.append( - '<img src="' + - (controller.baseURL.length > 0 ? controller.baseURL : "") + - 'images/tag_red.png" /> ' - ); - } - $content.append(element.name); - break; - default: - $content.append(element.name); - break; - } - - // Load the status counters - var hasCounters = _processNodeCounters( - $content, - element.counters, - element.type - ); - //Don't show empty groups - if (element.type == "agent") { - if (!hasCounters) { - return; - } - } - // If exist the detail container, show the data - if (typeof controller.detailRecipient !== "undefined") { - if (element.type == "agent" || element.type == "module") { - $content - .click(function(e) { - _getTreeDetailData( - element.type, - element.id, - element.serverID, - function(error, data) { - if (error) { - // console.error(error); - } else { - controller.detailRecipient - .render(element.name, data) - .open(); - } - } - ); - }) - .css("cursor", "pointer"); - } - } - - $node - .addClass("tree-node") - .append($leafIcon) - .append($content); - - container.append($node); - - $node.addClass("leaf-empty"); - - if ( - typeof element.children != "undefined" && - element.children.length > 0 - ) { - $node.removeClass("leaf-empty").addClass("leaf-closed"); - - // Add children - var $children = _processGroup($node, element.children); - $node.data("children", $children); - - if ( - typeof element.searchChildren == "undefined" || - !element.searchChildren - ) { - $leafIcon.click(function(e) { - e.preventDefault(); - - if ($node.hasClass("leaf-open")) { - $node - .removeClass("leaf-open") - .addClass("leaf-closed") - .data("children") - .slideUp(); - } else { - $node - .removeClass("leaf-closed") - .addClass("leaf-open") - .data("children") - .slideDown(); - } - }); - } - } - // Get hash and user. - var public_hash = $("#hidden-publi_dash_tree_view_hash").val(); - if (typeof public_hash === "undefined") public_hash = 0; - var public_user = $("#hidden-publi_dash_tree_view_id_user").val(); - if (typeof public_user === "undefined") public_user = 0; - - if ( - typeof element.searchChildren != "undefined" && - element.searchChildren - ) { - if ( - element.rootType == "group_edition" && - typeof element.children == "undefined" - ) { - $node.addClass("leaf-empty"); - } else { - $node.removeClass("leaf-empty").addClass("leaf-closed"); - $leafIcon.click(function(e) { - e.preventDefault(); - - if ( - !$node.hasClass("leaf-loading") && - !$node.hasClass("children-loaded") && - !$node.hasClass("leaf-empty") - ) { - $node - .removeClass("leaf-closed") - .removeClass("leaf-error") - .addClass("leaf-loading"); - - $.ajax({ - url: controller.ajaxURL, - type: "POST", - dataType: "json", - data: { - page: controller.ajaxPage, - getChildren: 1, - id: element.id, - type: element.type, - rootID: element.rootID, - serverID: element.serverID, - rootType: element.rootType, - filter: controller.filter, - hash: public_hash, - id_user: public_user - }, - complete: function(xhr, textStatus) { - $node.removeClass("leaf-loading"); - $node.addClass("children-loaded"); - }, - success: function(data, textStatus, xhr) { - if (data.success) { - var $group = $node.children("ul.tree-group"); - if ( - (typeof data.tree != "undefined" && - data.tree.length > 0) || - $group.length > 0 - ) { - $node.addClass("leaf-open"); - - if ($group.length <= 0) { - $group = $("<ul></ul>"); - $group.addClass("tree-group").hide(); - $node.append($group); - } - - _.each(data.tree, function(element) { - element.jqObject = _processNode($group, element); - }); - - $group.slideDown(); - - $node.data("children", $group); - - // Add again the hover event to the 'force_callback' elements - forced_title_callback(); - } else { - $node.addClass("leaf-empty"); - } - } else { - $node.addClass("leaf-error"); - } - }, - error: function(xhr, textStatus, errorThrown) { - $node.addClass("leaf-error"); - } - }); - } else if (!$node.hasClass("leaf-empty")) { - if ($node.hasClass("leaf-open")) { - $node - .removeClass("leaf-open") - .addClass("leaf-closed") - .data("children") - .slideUp(); - } else { - $node - .removeClass("leaf-closed") - .addClass("leaf-open") - .data("children") - .slideDown(); - } - } - }); - } - } - - return $node; - } - - if (controller.recipient.length == 0) { - return; - } else if (controller.tree.length == 0) { - controller.recipient.empty(); - controller.recipient.html( - "<div>" + controller.emptyMessage + "</div>" - ); - return; - } - - controller.recipient.empty(); - controller.recipient.html( - "<div> " + - controller.foundMessage + - ": " + - controller.tree.length + - "</div>" + - "<br/>" - ); - - var $children = _processGroup(this.recipient, this.tree, true); - $children.show(); - - controller.recipient.data("children", $children); - - // Add again the hover event to the 'force_callback' elements - forced_title_callback(); - }, - load: function() { - this.reload(); - }, - changeTree: function(tree) { - this.tree = tree; - this.reload(); - }, - init: function(data) { - if ( - typeof data.recipient !== "undefined" && - data.recipient.length > 0 - ) { - this.recipient = data.recipient; - } - if (typeof data.detailRecipient !== "undefined") { - this.detailRecipient = data.detailRecipient; - } - if (typeof data.tree !== "undefined") { - this.tree = data.tree; - } - if ( - typeof data.emptyMessage !== "undefined" && - data.emptyMessage.length > 0 - ) { - this.emptyMessage = data.emptyMessage; - } - if ( - typeof data.foundMessage !== "undefined" && - data.foundMessage.length > 0 - ) { - this.foundMessage = data.foundMessage; - } - if ( - typeof data.errorMessage !== "undefined" && - data.errorMessage.length > 0 - ) { - this.errorMessage = data.errorMessage; - } - if (typeof data.baseURL !== "undefined" && data.baseURL.length > 0) { - this.baseURL = data.baseURL; - } - if (typeof data.ajaxURL !== "undefined" && data.ajaxURL.length > 0) { - this.ajaxURL = data.ajaxURL; - } - if (typeof data.ajaxPage !== "undefined" && data.ajaxPage.length > 0) { - this.ajaxPage = data.ajaxPage; - } - if (typeof data.filter !== "undefined") { - this.filter = data.filter; - } - - this.load(); - }, - remove: function() { - if (typeof this.recipient != "undefined" && this.recipient.length > 0) { - this.recipient.empty(); - } - - if (this.index > -1) { - TreeController.controllers.splice(this.index, 1); - } - } - }; - controller.index = TreeController.controllers.push(controller) - 1; - - return controller; - } -}; + controllers: [], + getController: function () { + var controller = { + index: -1, + recipient: '', + tree: [], + emptyMessage: "No data found.", + foundMessage: "Found groups", + errorMessage: "Error", + baseURL: "", + ajaxURL: "ajax.php", + ajaxPage: "include/ajax/tree.ajax", + detailRecipient: '', + filter: {}, + counterTitles: {}, + shouldHaveCounters: true, + reload: function () { + // Bad recipient + if (typeof this.recipient == 'undefined' || this.recipient.length == 0) { + return; + } + + // Load branch + function _processGroup (container, elements, rootGroup) { + + var $group = $("<ul></ul>"); + + // First group + if (typeof rootGroup != 'undefinded' && rootGroup == true) { + $group + .addClass("tree-root") + .hide() + .prepend('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '')+'images/pandora.png" />'); + } + // Normal group + else { + $group + .addClass("tree-group") + .hide(); + } + + container.append($group); + + _.each(elements, function(element) { + element.jqObject = _processNode($group, element); + }); + + return $group; + } + + // Load leaf counters + function _processNodeCounters (container, counters, type) { + var hasCounters = false; + + if (typeof counters != 'undefined') { + + function _processNodeCounterTitle (container, elementType, counterType) { + + var defaultCounterTitles = { + total: { + agents: "Total agents", + modules: "Total modules", + none: "Total" + }, + alerts: { + agents: "Alerts fired", + modules: "Alerts fired", + none: "Alerts fired" + }, + critical: { + agents: "Critical agents", + modules: "Critical modules", + none: "Critical" + }, + warning: { + agents: "Warning agents", + modules: "Warning modules", + none: "Warning" + }, + unknown: { + agents: "Unknown agents", + modules: "Unknown modules", + none: "Unknown" + }, + not_init: { + agents: "Not init agents", + modules: "Not init modules", + none: "Not init" + }, + ok: { + agents: "Normal agents", + modules: "Normal modules", + none: "Normal" + } + } + + var serviceCounterTitles = { + total_services: { + totals: "Services" + }, + total_agents: { + totals: "Agents" + }, + total_modules: { + totals: "Modules" + } + } + + try { + + var title = ''; + + switch (elementType) { + case "group": + if (typeof controller.counterTitles != 'undefined' + && typeof controller.counterTitles[counterType] != 'undefined' + && typeof controller.counterTitles[counterType].agents != 'undefined') { + title = controller.counterTitles[counterType].agents; + } + else { + title = defaultCounterTitles[counterType].agents; + } + break; + case "agent": + if (typeof controller.counterTitles != 'undefined' + && typeof controller.counterTitles[counterType] != 'undefined' + && typeof controller.counterTitles[counterType].modules != 'undefined') { + title = controller.counterTitles[counterType].modules; + } + else { + title = defaultCounterTitles[counterType].modules; + } + break; + case "services": + title = serviceCounterTitles[counterType].totals; + break; + default: + if (typeof controller.counterTitles != 'undefined' + && typeof controller.counterTitles[counterType] != 'undefined' + && typeof controller.counterTitles[counterType].none != 'undefined') { + title = controller.counterTitles[counterType].none; + } + else { + title = defaultCounterTitles[counterType].none; + } + break; + } + if (title.length > 0) { + container + .data("title", title) + .addClass("forced_title") + .data("use_title_for_force_title", 1); // Trick to make easier the 'force title' output + } + } + catch (error) { + // console.log(error); + } + } + + + if (type=="services") { + + var $counters = $("<div></div>"); + $counters.addClass('tree-node-counters'); + + if (counters.total_services+counters.total_agents+counters.total_modules > 0) { + + // Open the parentheses + $counters.append(" ("); + + if (typeof counters.total_services != 'undefined' + && counters.total_services >= 0) { + + var $servicesCounter = $("<div></div>"); + $servicesCounter + .addClass('tree-node-counter') + .addClass('total') + .html(counters.total_services); + + _processNodeCounterTitle($servicesCounter, type, "total_services"); + + $counters + .append($servicesCounter); + } else { + var $servicesCounter = $("<div></div>"); + $servicesCounter + .addClass('tree-node-counter') + .addClass('total') + .html('0'); + + _processNodeCounterTitle($servicesCounter, type, "total_services"); + + $counters + .append($servicesCounter); + } + + if (typeof counters.total_agents != 'undefined' + && counters.total_agents > 0) { + var $agentsCounter = $("<div></div>"); + $agentsCounter + .addClass('tree-node-counter') + .html(counters.total_agents); + + _processNodeCounterTitle($agentsCounter, type, "total_agents"); + + $counters + .append(" : ") + .append($agentsCounter); + } else { + var $agentsCounter = $("<div></div>"); + $agentsCounter + .addClass('tree-node-counter') + .addClass('total') + .html('0'); + + _processNodeCounterTitle($agentsCounter, type, "total_agents"); + + $counters + .append(" : ") + .append($agentsCounter); + } + + if (typeof counters.total_modules != 'undefined' + && counters.total_modules > 0) { + var $modulesCounter = $("<div></div>"); + $modulesCounter + .addClass('tree-node-counter') + .addClass('total') + .html(counters.total_modules); + + _processNodeCounterTitle($modulesCounter, type, "total_modules"); + + $counters + .append(" : ") + .append($modulesCounter); + } else { + var $modulesCounter = $("<div></div>"); + $modulesCounter + .addClass('tree-node-counter') + .addClass('total') + .html('0'); + + _processNodeCounterTitle($modulesCounter, type, "total_modules"); + + $counters + .append(" : ") + .append($modulesCounter); + } + + // Close the parentheses + $counters.append(")"); + + hasCounters = true; + } + } else { + + var $counters = $("<div></div>"); + $counters.addClass('tree-node-counters'); + + if (typeof counters.total != 'undefined' + && counters.total >= 0) { + + var $totalCounter = $("<div></div>"); + $totalCounter + .addClass('tree-node-counter') + .addClass('total') + .html(counters.total); + + _processNodeCounterTitle($totalCounter, type, "total"); + + // Open the parentheses + $counters.append(" ("); + + $counters.append($totalCounter); + + if (typeof counters.alerts != 'undefined' + && counters.alerts > 0) { + var $firedCounter = $("<div></div>"); + $firedCounter + .addClass('tree-node-counter') + .addClass('alerts') + .addClass('orange') + .html(counters.alerts); + + _processNodeCounterTitle($firedCounter, type, "alerts"); + + $counters + .append(" : ") + .append($firedCounter); + } + if (typeof counters.critical != 'undefined' + && counters.critical > 0) { + var $criticalCounter = $("<div></div>"); + $criticalCounter + .addClass('tree-node-counter') + .addClass('critical') + .addClass('red') + .html(counters.critical); + + _processNodeCounterTitle($criticalCounter, type, "critical"); + + $counters + .append(" : ") + .append($criticalCounter); + } + if (typeof counters.warning != 'undefined' + && counters.warning > 0) { + var $warningCounter = $("<div></div>"); + $warningCounter + .addClass('tree-node-counter') + .addClass('warning') + .addClass('yellow') + .html(counters.warning); + + _processNodeCounterTitle($warningCounter, type, "warning"); + + $counters + .append(" : ") + .append($warningCounter); + } + if (typeof counters.unknown != 'undefined' + && counters.unknown > 0) { + var $unknownCounter = $("<div></div>"); + $unknownCounter + .addClass('tree-node-counter') + .addClass('unknown') + .addClass('grey') + .html(counters.unknown); + + _processNodeCounterTitle($unknownCounter, type, "unknown"); + + $counters + .append(" : ") + .append($unknownCounter); + } + if (typeof counters.not_init != 'undefined' + && counters.not_init > 0) { + var $notInitCounter = $("<div></div>"); + $notInitCounter + .addClass('tree-node-counter') + .addClass('not_init') + .addClass('blue') + .html(counters.not_init); + + _processNodeCounterTitle($notInitCounter, type, "not_init"); + + $counters + .append(" : ") + .append($notInitCounter); + } + if (typeof counters.ok != 'undefined' + && counters.ok > 0) { + var $okCounter = $("<div></div>"); + $okCounter + .addClass('tree-node-counter') + .addClass('ok') + .addClass('green') + .html(counters.ok); + + _processNodeCounterTitle($okCounter, type, "ok"); + + $counters + .append(" : ") + .append($okCounter); + } + } + + // Close the parentheses + $counters.append(")"); + + hasCounters = true; + } + + // Add the counters html to the container + container.append($counters); + } + + return hasCounters; + } + + // Load leaf + function _processNode (container, element) { + // type, [id], [serverID], callback + function _getTreeDetailData (type, id, serverID, callback) { + var lastParam = arguments[arguments.length - 1]; + var callback; + if (typeof lastParam === 'function') + callback = lastParam; + + var serverID; + if (arguments.length >= 4) + serverID = arguments[2]; + var id; + if (arguments.length >= 3) + id = arguments[1]; + var type; + if (arguments.length >= 2) + type = arguments[0]; + + if (typeof type === 'undefined') + throw new TypeError('Type required'); + if (typeof callback === 'undefined') + throw new TypeError('Callback required'); + + var postData = { + page: controller.ajaxPage, + getDetail: 1, + type: type + } + + if (typeof id !== 'undefined') + postData.id = id; + if (typeof serverID !== 'undefined') + postData.serverID = serverID; + + $.ajax({ + url: controller.ajaxURL, + type: 'POST', + dataType: 'html', + data: postData, + success: function(data, textStatus, xhr) { + callback(null, data); + }, + error: function(xhr, textStatus, errorThrown) { + callback(errorThrown); + } + }); + } + + var $node = $("<li></li>"); + var $leafIcon = $("<div></div>"); + var $content = $("<div></div>"); + + // Leaf icon + $leafIcon.addClass("leaf-icon"); + + // Content + $content.addClass("node-content"); + switch (element.type) { + case 'group': + if (typeof element.icon != 'undefined' && element.icon.length > 0) { + $content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/groups_small/'+element.icon+'" /> '); + } + else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) { + $content.append(element.iconHTML + " "); + } + $content.append(element.name); + + if(typeof element.edit != 'undefined'){ + var url_edit = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/configure_group&tab=tree&id_group=" + element.id; + var $updateicon = $('<img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '')+ 'images/config.png" style="width:18px; vertical-align: middle;"/>') + var $updatebtn = $('<a href = "' + url_edit + '"></a>') + .append($updateicon); + $content.append($updatebtn); + } + + if(typeof element.delete != 'undefined'){ + var url_delete = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/group_list&tab=tree&delete_group=1&id_group=" + element.id; + var $deleteBtn = $('<a><img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '') +'images/cross.png" style="width:18px; vertical-align: middle; cursor: pointer;"/></a>'); + $deleteBtn.click(function (event){ + var ok_function = function(){ + window.location.replace(url_delete); + }; + display_confirm_dialog( + element.delete.messages.messg, + element.delete.messages.confirm, + element.delete.messages.cancel, + ok_function + ) + }); + $content.append($deleteBtn); + } + + if(typeof element.alerts != 'undefined'){ + $content.append(element.alerts); + } + + break; + case 'agent': + // Is quiet + if (typeof element.quietImageHTML != 'undefined' + && element.quietImageHTML.length > 0) { + var $quietImage = $(element.quietImageHTML); + $quietImage.addClass("agent-quiet"); + + $content.append($quietImage); + } + // Status image + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("agent-status"); + + $content.append($statusImage); + } + // Alerts fired image + if (typeof element.alertImageHTML != 'undefined' + && element.alertImageHTML.length > 0) { + var $alertImage = $(element.alertImageHTML); + $alertImage.addClass("agent-alerts-fired"); + + $content.append($alertImage); + } + + // Events by agent + if (element.showEventsBtn == 1) { + if (typeof element.eventAgent != 'undefined') { + + $content.append('<form method="post" id="hiddenAgentsEventsForm-'+element.eventAgent+'" style="display: none;" action="index.php?sec=eventos&sec2=operation/events/events&refr=0&pure=§ion=list&history=0"><input type="hidden" name="id_agent" value="'+element.eventAgent+'"></form>'); + var $eventImage = $('<img src="images/tree_events.png" />'); + $eventImage.addClass("agent-alerts-fired"); + $eventImage + .click(function (e) { + e.preventDefault(); + + document.getElementById('hiddenAgentsEventsForm-'+element.eventAgent).submit(); + }) + .css('cursor', 'pointer'); + + $content.append($eventImage); + } + } + + $content.append(' '+element.alias); + break; + case 'services': + + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("agent-status"); + + $content.append($statusImage); + } + + + var $serviceDetailImage = $('<img src="images/tree_service_map.png" />'); + + if (typeof element.serviceDetail != 'undefined') { + + $serviceDetailImage + .click(function (e) { + e.preventDefault(); + + window.location.href = element.serviceDetail; + }) + .css('cursor', 'pointer'); + + $content.append($serviceDetailImage); + } + + $content.append(' '+element.name); + + + + + break; + case 'modules': + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("agent-status"); + + $content.append($statusImage); + } + + // Events by module + if (element.showEventsBtn == 1) { + if (typeof element.eventModule != 'undefined') { + + $content.append('<form method="post" id="hiddenModulesEventsForm-'+element.eventModule+'" style="display: none;" action="index.php?sec=eventos&sec2=operation/events/events&refr=0&pure=§ion=list&history=0"><input type="hidden" name="module_search_hidden" value="'+element.eventModule+'"></form>'); + var $moduleImage = $('<img src="images/tree_events.png" />'); + $moduleImage + .click(function (e) { + e.preventDefault(); + + document.getElementById('hiddenModulesEventsForm-'+element.eventModule).submit(); + }) + .css('cursor', 'pointer'); + + $content.append($moduleImage); + } + } + + $content.append(' '+element.name); + break; + case 'module': + // Status image + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("module-status"); + + $content.append($statusImage); + } + // Server type + if (typeof element.serverTypeHTML != 'undefined' + && element.serverTypeHTML.length > 0 + && element.serverTypeHTML != '--') { + var $serverTypeImage = $(element.serverTypeHTML); + $serverTypeImage.addClass("module-server-type"); + + $content.append($serverTypeImage); + } + + if (typeof element.showGraphs != 'undefined' && element.showGraphs != 0) { + // Graph pop-up + if (typeof element.moduleGraph != 'undefined') { + + if(element.statusImageHTML.indexOf('data:image')!=-1){ + var $graphImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/photo.png" /> '); + } + else{ + + var $graphImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/chart_curve.png" /> '); + } + + $graphImage + .addClass('module-graph') + .click(function (e) { + e.preventDefault(); + if(element.statusImageHTML.indexOf('data:image')!=-1){ + try { + winopeng_var( + decodeURI(element.snapshot[0]), + element.snapshot[1], + element.snapshot[2], + element.snapshot[3] + ); + } + catch (error) { + // console.log(error); + } + } + else{ + try { + winopeng(element.moduleGraph.url, element.moduleGraph.handle); + } + catch (error) { + // console.log(error); + } + } + }); + + $content.append($graphImage); + } + + // Data pop-up + if (typeof element.id != 'undefined' && !isNaN(element.id)) { + + var $dataImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/binary.png" /> '); + $dataImage + .addClass('module-data') + .click(function (e) { + e.preventDefault(); + + try { + var serverName = element.serverName.length > 0 ? element.serverName : ''; + if ($("#module_details_window").length > 0) + show_module_detail_dialog(element.id, '', serverName, 0, 86400, element.name.replace(/ /g , " ") ); + } + catch (error) { + // console.log(error); + } + }); + + $content.append($dataImage); + } + } + + // Alerts + if (typeof element.alertsImageHTML != 'undefined' + && element.alertsImageHTML.length > 0) { + + var $alertsImage = $(element.alertsImageHTML); + + $alertsImage + .addClass("module-alerts") + .click(function (e) { + _getTreeDetailData('alert', element.id, element.serverID, function (error, data) { + if (error) { + // console.error(error); + } + else { + controller.detailRecipient.render(element.name, data).open(); + } + }); + + // Avoid the execution of the module detail event + e.stopPropagation(); + }) + .css('cursor', 'pointer'); + + $content.append($alertsImage); + } + + $content.append(element.name); + break; + case 'os': + if (typeof element.icon != 'undefined' && element.icon.length > 0) { + $content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/os_icons/'+element.icon+'" /> '); + } + $content.append(element.name); + break; + case 'tag': + if (typeof element.icon != 'undefined' && element.icon.length > 0) { + $content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/os_icons/'+element.icon+'" /> '); + } + else { + $content.append('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/tag_red.png" /> '); + } + $content.append(element.name); + break; + case 'services': + // Status image + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("agent-status"); + + $content.append($statusImage); + } + $content.append(element.name); + break; + default: + $content.append(element.name); + break; + } + + // Load the status counters + console.log(element.counters); + var hasCounters = _processNodeCounters($content, element.counters, element.type); + //Don't show empty groups + if (element.type == 'agent') { + if (!hasCounters) { + return; + } + } + // If exist the detail container, show the data + if (typeof controller.detailRecipient !== 'undefined') { + if (element.type == 'agent' || element.type == 'module') { + $content.click(function (e) { + _getTreeDetailData(element.type, element.id, element.serverID, function (error, data) { + if (error) { + // console.error(error); + } + else { + controller.detailRecipient.render(element.name, data).open(); + } + }); + }) + .css('cursor', 'pointer'); + } + } + + $node + .addClass("tree-node") + .append($leafIcon) + .append($content); + + container.append($node); + + $node.addClass("leaf-empty"); + + if (typeof element.children != 'undefined' && element.children.length > 0) { + $node + .removeClass("leaf-empty") + .addClass("leaf-closed"); + + // Add children + var $children = _processGroup($node, element.children); + $node.data('children', $children); + + if (typeof element.searchChildren == 'undefined' || !element.searchChildren) { + $leafIcon.click(function (e) { + e.preventDefault(); + + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + }); + } + } + // Get hash and user. + var public_hash = $("#hidden-publi_dash_tree_view_hash" ).val(); + if (typeof(public_hash) === 'undefined') public_hash = 0; + var public_user = $("#hidden-publi_dash_tree_view_id_user" ).val(); + if (typeof(public_user) === 'undefined') public_user = 0; + + if (typeof element.searchChildren != 'undefined' && element.searchChildren) { + if(element.rootType == "group_edition" + && typeof element.children == 'undefined'){ + $node.addClass("leaf-empty"); + } + else{ + $node + .removeClass("leaf-empty") + .addClass("leaf-closed"); + $leafIcon.click(function (e) { + e.preventDefault(); + + if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) { + $node + .removeClass("leaf-closed") + .removeClass("leaf-error") + .addClass("leaf-loading"); + + $.ajax({ + url: controller.ajaxURL, + type: 'POST', + dataType: 'json', + data: { + page: controller.ajaxPage, + getChildren: 1, + id: element.id, + type: element.type, + rootID: element.rootID, + serverID: element.serverID, + rootType: element.rootType, + filter: controller.filter, + hash: public_hash, + id_user: public_user + }, + complete: function(xhr, textStatus) { + $node.removeClass("leaf-loading"); + $node.addClass("children-loaded"); + }, + success: function(data, textStatus, xhr) { + if (data.success) { + var $group = $node.children("ul.tree-group"); + if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) { + $node.addClass("leaf-open"); + + if ($group.length <= 0) { + $group = $("<ul></ul>"); + $group + .addClass("tree-group") + .hide(); + $node.append($group); + } + //console.log(data.tree); + + _.each(data.tree, function(element) { + element.jqObject = _processNode($group, element); + }); + + $group.slideDown(); + + $node.data('children', $group); + + // Add again the hover event to the 'force_callback' elements + forced_title_callback(); + } + else { + $node.addClass("leaf-empty"); + } + } + else { + $node.addClass("leaf-error"); + } + }, + error: function(xhr, textStatus, errorThrown) { + $node.addClass("leaf-error"); + } + }); + } + else if (! $node.hasClass("leaf-empty")) { + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + } + }); + } + } + + return $node; + } + + if (controller.recipient.length == 0) { + return; + } + else if (controller.tree.length == 0) { + controller.recipient.empty(); + controller.recipient.html("<div>" + controller.emptyMessage + "</div>"); + return; + } + + controller.recipient.empty(); + controller.recipient.html( + "<div> " + + controller.foundMessage + ": " + controller.tree.length + + "</div>" + + "<br/>" + ); + + var $children = _processGroup(this.recipient, this.tree, true); + $children.show(); + + controller.recipient.data('children', $children); + + // Add again the hover event to the 'force_callback' elements + forced_title_callback(); + }, + load: function () { + this.reload(); + }, + changeTree: function (tree) { + this.tree = tree; + this.reload(); + }, + init: function (data) { + if (typeof data.recipient !== 'undefined' && data.recipient.length > 0) { + this.recipient = data.recipient; + } + if (typeof data.detailRecipient !== 'undefined') { + this.detailRecipient = data.detailRecipient; + } + if (typeof data.tree !== 'undefined') { + this.tree = data.tree; + } + if (typeof data.emptyMessage !== 'undefined' && data.emptyMessage.length > 0) { + this.emptyMessage = data.emptyMessage; + } + if (typeof data.foundMessage !== 'undefined' && data.foundMessage.length > 0) { + this.foundMessage = data.foundMessage; + } + if (typeof data.errorMessage !== 'undefined' && data.errorMessage.length > 0) { + this.errorMessage = data.errorMessage; + } + if (typeof data.baseURL !== 'undefined' && data.baseURL.length > 0) { + this.baseURL = data.baseURL; + } + if (typeof data.ajaxURL !== 'undefined' && data.ajaxURL.length > 0) { + this.ajaxURL = data.ajaxURL; + } + if (typeof data.ajaxPage !== 'undefined' && data.ajaxPage.length > 0) { + this.ajaxPage = data.ajaxPage; + } + if (typeof data.filter !== 'undefined') { + this.filter = data.filter; + } + + this.load(); + }, + remove: function () { + if (typeof this.recipient != 'undefined' && this.recipient.length > 0) { + this.recipient.empty(); + } + + if (this.index > -1) { + TreeController.controllers.splice(this.index, 1); + } + } + } + controller.index = TreeController.controllers.push(controller) - 1; + + return controller; + } +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 70a9c4920e..180c187db0 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -21,8 +21,8 @@ Description: The default Pandora FMS theme layout */ /* Tree view styles */ -/*@import url(tree.css); -@import url(fixed-bottom-box.css);*/ +@import url(tree.css); +@import url(fixed-bottom-box.css); /* * --------------------------------------------------------------------- diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 18e1e77ffc..5dc7caea1b 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -314,6 +314,7 @@ if ($id_agent != 0) { $text_module = (string) get_parameter('module_search', ''); $id_agent_module = get_parameter('module_search_hidden', get_parameter('id_agent_module', 0)); +hd("------------------------------------>>>>>>> ".$id_agent_module." y id_agent: ".$id_agent, true); if ($id_agent_module != 0) { $text_module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); if ($text_module == false) { diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index fde9586325..3491f71458 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -278,226 +278,228 @@ enterprise_hook('close_meta_frame'); <?php } ?> <script type="text/javascript"> - var treeController = TreeController.getController(); - - processTreeSearch(); - - $("form#tree_search").submit(function(e) { - e.preventDefault(); - processTreeSearch(); - }); - - function processTreeSearch () { - // Clear the tree - if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0) - treeController.recipient.empty(); - - $(".loading_tree").show(); - - var parameters = {}; - parameters['page'] = "include/ajax/tree.ajax"; - parameters['getChildren'] = 1; - parameters['type'] = "<?php echo $tab; ?>"; - parameters['filter'] = {}; - parameters['filter']['searchGroup'] = $("input#text-search_group").val(); - parameters['filter']['searchAgent'] = $("input#text-search_agent").val(); - parameters['filter']['statusAgent'] = $("select#status_agent").val(); - parameters['filter']['searchModule'] = $("input#text-search_module").val(); - parameters['filter']['statusModule'] = $("select#status_module").val(); - parameters['filter']['groupID'] = $("input#hidden-group-id").val(); - parameters['filter']['tagID'] = $("input#hidden-tag-id").val(); - - if($("#checkbox-serach_hirearchy").is(':checked')){ - parameters['filter']['searchHirearchy'] = 1; - } - else{ - parameters['filter']['searchHirearchy'] = 0; - } - - if($("#checkbox-show_not_init_agents").is(':checked')){ - parameters['filter']['show_not_init_agents'] = 1; - } - else{ - parameters['filter']['show_not_init_agents'] = 0; - } - - if($("#checkbox-show_not_init_modules").is(':checked')){ - parameters['filter']['show_not_init_modules'] = 1; - $('#hidden-show_not_init_modules_hidden').val(1); - } - else{ - parameters['filter']['show_not_init_modules'] = 0; - $('#hidden-show_not_init_modules_hidden').val(0); - } + var treeController = TreeController.getController(); + + processTreeSearch(); + + $("form#tree_search").submit(function(e) { + e.preventDefault(); + processTreeSearch(); + }); + + function processTreeSearch () { + // Clear the tree + if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0) + treeController.recipient.empty(); + + $(".loading_tree").show(); + - $.ajax({ - type: "POST", - url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", - data: parameters, - success: function(data) { - if (data.success) { - $(".loading_tree").hide(); - - treeController.init({ - recipient: $("div#tree-controller-recipient"), - detailRecipient: $.fixedBottomBox({ width: 400, height: window.innerHeight * 0.9 }), - page: parameters['page'], - emptyMessage: "<?php echo __('No data found'); ?>", - foundMessage: "<?php echo __('Found groups'); ?>", - tree: data.tree, - baseURL: "<?php echo ui_get_full_url(false, false, false, is_metaconsole()); ?>", - ajaxURL: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", - filter: parameters['filter'], - counterTitles: { - total: { - agents: "<?php echo __('Total agents'); ?>", - modules: "<?php echo __('Total modules'); ?>", - none: "<?php echo __('Total'); ?>" - }, - alerts: { - agents: "<?php echo __('Fired alerts'); ?>", - modules: "<?php echo __('Fired alerts'); ?>", - none: "<?php echo __('Fired alerts'); ?>" - }, - critical: { - agents: "<?php echo __('Critical agents'); ?>", - modules: "<?php echo __('Critical modules'); ?>", - none: "<?php echo __('Critical'); ?>" - }, - warning: { - agents: "<?php echo __('Warning agents'); ?>", - modules: "<?php echo __('Warning modules'); ?>", - none: "<?php echo __('Warning'); ?>" - }, - unknown: { - agents: "<?php echo __('Unknown agents'); ?>", - modules: "<?php echo __('Unknown modules'); ?>", - none: "<?php echo __('Unknown'); ?>" - }, - not_init: { - agents: "<?php echo __('Not init agents'); ?>", - modules: "<?php echo __('Not init modules'); ?>", - none: "<?php echo __('Not init'); ?>" - }, - ok: { - agents: "<?php echo __('Normal agents'); ?>", - modules: "<?php echo __('Normal modules'); ?>", - none: "<?php echo __('Normal'); ?>" - } - } - }); - } - }, - dataType: "json" - }); - } - - // Show the modal window of an module - var moduleDetailsWindow = $("<div></div>"); - moduleDetailsWindow - .hide() - .prop("id", "module_details_window") - .appendTo('body'); - - function show_module_detail_dialog(module_id, id_agent, server_name, offset, period, module_name) { - var params = {}; - var f = new Date(); - period = $('#period').val(); - - params.selection_mode = $('input[name=selection_mode]:checked').val(); - if (!params.selection_mode) { - params.selection_mode='fromnow'; - } - - params.date_from = $('#text-date_from').val(); - if (!params.date_from) { - params.date_from = f.getFullYear() + "/" + (f.getMonth() +1) + "/" + f.getDate(); - } - - params.time_from = $('#text-time_from').val(); - if (!params.time_from) { - params.time_from = f.getHours() + ":" + f.getMinutes(); - } - - params.date_to = $('#text-date_to').val(); - if (!params.date_to) { - params.date_to =f.getFullYear() + "/" + (f.getMonth() +1) + "/" + f.getDate(); - } - - params.time_to = $('#text-time_to').val(); - if (!params.time_to) { - params.time_to = f.getHours() + ":" + f.getMinutes(); - } - - params.page = "include/ajax/module"; - params.get_module_detail = 1; - params.server_name = server_name; - params.id_agent = id_agent; - params.id_module = module_id; - params.offset = offset; - params.period = period; - title = <?php echo "'".__('Module: ')."'"; ?> ; - $.ajax({ - type: "POST", - url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", - data: params, - dataType: "html", - success: function(data) { - $("#module_details_window").hide () - .empty () - .append (data) - .dialog ({ - resizable: true, - draggable: true, - modal: true, - title: title + module_name, - overlay: { - opacity: 0.5, - background: "black" - }, - width: 650, - height: 500 - }) - .show (); - refresh_pagination_callback(module_id, id_agent, server_name, module_name); - datetime_picker_callback(); - forced_title_callback(); - } - }); - } - - function datetime_picker_callback() { - $("#text-time_from, #text-time_to").timepicker({ - showSecond: true, - timeFormat: '<?php echo TIME_FORMAT_JS; ?>', - timeOnlyTitle: '<?php echo __('Choose time'); ?>', - timeText: '<?php echo __('Time'); ?>', - hourText: '<?php echo __('Hour'); ?>', - minuteText: '<?php echo __('Minute'); ?>', - secondText: '<?php echo __('Second'); ?>', - currentText: '<?php echo __('Now'); ?>', - closeText: '<?php echo __('Close'); ?>'}); - - $.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]); - $("#text-date_from, #text-date_to").datepicker({dateFormat: "<?php echo DATE_FORMAT_JS; ?>"}); - - } - - function refresh_pagination_callback (module_id, id_agent, server_name,module_name) { - - $(".binary_dialog").click( function() { - - var classes = $(this).attr('class'); - classes = classes.split(' '); - var offset_class = classes[2]; - offset_class = offset_class.split('_'); - var offset = offset_class[1]; - - var period = $('#period').val(); - - show_module_detail_dialog(module_id, id_agent, server_name, offset, period,module_name); - return false; - }); - } - + + var parameters = {}; + parameters['page'] = "include/ajax/tree.ajax"; + parameters['getChildren'] = 1; + parameters['type'] = "<?php echo $tab; ?>"; + parameters['filter'] = {}; + parameters['filter']['searchGroup'] = $("input#text-search_group").val(); + parameters['filter']['searchAgent'] = $("input#text-search_agent").val(); + parameters['filter']['statusAgent'] = $("select#status_agent").val(); + parameters['filter']['searchModule'] = $("input#text-search_module").val(); + parameters['filter']['statusModule'] = $("select#status_module").val(); + parameters['filter']['groupID'] = $("input#hidden-group-id").val(); + parameters['filter']['tagID'] = $("input#hidden-tag-id").val(); + + if($("#checkbox-serach_hirearchy").is(':checked')){ + parameters['filter']['searchHirearchy'] = 1; + } + else{ + parameters['filter']['searchHirearchy'] = 0; + } + + if($("#checkbox-show_not_init_agents").is(':checked')){ + parameters['filter']['show_not_init_agents'] = 1; + } + else{ + parameters['filter']['show_not_init_agents'] = 0; + } + + if($("#checkbox-show_not_init_modules").is(':checked')){ + parameters['filter']['show_not_init_modules'] = 1; + $('#hidden-show_not_init_modules_hidden').val(1); + } + else{ + parameters['filter']['show_not_init_modules'] = 0; + $('#hidden-show_not_init_modules_hidden').val(0); + } + + $.ajax({ + type: "POST", + url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", + data: parameters, + success: function(data) { + if (data.success) { + $(".loading_tree").hide(); + + treeController.init({ + recipient: $("div#tree-controller-recipient"), + detailRecipient: $.fixedBottomBox({ width: 400, height: window.innerHeight * 0.9 }), + page: parameters['page'], + emptyMessage: "<?php echo __('No data found'); ?>", + foundMessage: "<?php echo __('Found groups'); ?>", + tree: data.tree, + baseURL: "<?php echo ui_get_full_url(false, false, false, is_metaconsole()); ?>", + ajaxURL: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", + filter: parameters['filter'], + counterTitles: { + total: { + agents: "<?php echo __('Total agents'); ?>", + modules: "<?php echo __('Total modules'); ?>", + none: "<?php echo __('Total'); ?>" + }, + alerts: { + agents: "<?php echo __('Fired alerts'); ?>", + modules: "<?php echo __('Fired alerts'); ?>", + none: "<?php echo __('Fired alerts'); ?>" + }, + critical: { + agents: "<?php echo __('Critical agents'); ?>", + modules: "<?php echo __('Critical modules'); ?>", + none: "<?php echo __('Critical'); ?>" + }, + warning: { + agents: "<?php echo __('Warning agents'); ?>", + modules: "<?php echo __('Warning modules'); ?>", + none: "<?php echo __('Warning'); ?>" + }, + unknown: { + agents: "<?php echo __('Unknown agents'); ?>", + modules: "<?php echo __('Unknown modules'); ?>", + none: "<?php echo __('Unknown'); ?>" + }, + not_init: { + agents: "<?php echo __('Not init agents'); ?>", + modules: "<?php echo __('Not init modules'); ?>", + none: "<?php echo __('Not init'); ?>" + }, + ok: { + agents: "<?php echo __('Normal agents'); ?>", + modules: "<?php echo __('Normal modules'); ?>", + none: "<?php echo __('Normal'); ?>" + } + } + }); + } + }, + dataType: "json" + }); + } + + // Show the modal window of an module + var moduleDetailsWindow = $("<div></div>"); + moduleDetailsWindow + .hide() + .prop("id", "module_details_window") + .appendTo('body'); + + function show_module_detail_dialog(module_id, id_agent, server_name, offset, period, module_name) { + var params = {}; + var f = new Date(); + period = $('#period').val(); + + params.selection_mode = $('input[name=selection_mode]:checked').val(); + if (!params.selection_mode) { + params.selection_mode='fromnow'; + } + + params.date_from = $('#text-date_from').val(); + if (!params.date_from) { + params.date_from = f.getFullYear() + "/" + (f.getMonth() +1) + "/" + f.getDate(); + } + + params.time_from = $('#text-time_from').val(); + if (!params.time_from) { + params.time_from = f.getHours() + ":" + f.getMinutes(); + } + + params.date_to = $('#text-date_to').val(); + if (!params.date_to) { + params.date_to =f.getFullYear() + "/" + (f.getMonth() +1) + "/" + f.getDate(); + } + + params.time_to = $('#text-time_to').val(); + if (!params.time_to) { + params.time_to = f.getHours() + ":" + f.getMinutes(); + } + + params.page = "include/ajax/module"; + params.get_module_detail = 1; + params.server_name = server_name; + params.id_agent = id_agent; + params.id_module = module_id; + params.offset = offset; + params.period = period; + title = <?php echo "'" . __("Module: ") . "'" ?> ; + $.ajax({ + type: "POST", + url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", + data: params, + dataType: "html", + success: function(data) { + $("#module_details_window").hide () + .empty () + .append (data) + .dialog ({ + resizable: true, + draggable: true, + modal: true, + title: title + module_name, + overlay: { + opacity: 0.5, + background: "black" + }, + width: 650, + height: 500 + }) + .show (); + refresh_pagination_callback(module_id, id_agent, server_name, module_name); + datetime_picker_callback(); + forced_title_callback(); + } + }); + } + + function datetime_picker_callback() { + $("#text-time_from, #text-time_to").timepicker({ + showSecond: true, + timeFormat: '<?php echo TIME_FORMAT_JS; ?>', + timeOnlyTitle: '<?php echo __('Choose time');?>', + timeText: '<?php echo __('Time');?>', + hourText: '<?php echo __('Hour');?>', + minuteText: '<?php echo __('Minute');?>', + secondText: '<?php echo __('Second');?>', + currentText: '<?php echo __('Now');?>', + closeText: '<?php echo __('Close');?>'}); + + $.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]); + $("#text-date_from, #text-date_to").datepicker({dateFormat: "<?php echo DATE_FORMAT_JS; ?>"}); + + } + + function refresh_pagination_callback (module_id, id_agent, server_name,module_name) { + + $(".binary_dialog").click( function() { + + var classes = $(this).attr('class'); + classes = classes.split(' '); + var offset_class = classes[2]; + offset_class = offset_class.split('_'); + var offset = offset_class[1]; + + var period = $('#period').val(); + + show_module_detail_dialog(module_id, id_agent, server_name, offset, period,module_name); + return false; + }); + } + </script> From faae9c58b34fbababffd4f5c746156c6a3f9a5ba Mon Sep 17 00:00:00 2001 From: alejandro-campos <alejandro.campos@artica.es> Date: Fri, 22 Feb 2019 14:09:27 +0100 Subject: [PATCH 05/25] implement services tree view Former-commit-id: a081515f62ab210f96687577bfde60d5f6d23f23 --- pandora_console/include/class/Tree.class.php | 2 - .../include/class/TreeGroup.class.php | 906 ++++++++++-------- .../include/class/TreeGroupEdition.class.php | 184 ++-- .../include/class/TreeService.class.php | 8 - .../include/javascript/tree/TreeController.js | 2 - pandora_console/operation/events/events.php | 1 - 6 files changed, 582 insertions(+), 521 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index da0380f4ea..4ad71f9ce1 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -879,8 +879,6 @@ class Tree { } $data = $this->getProcessedModules($data); $this->processModules($data); -hd("MODULES: ", true); -hd($data, true); $this->tree = $data; } diff --git a/pandora_console/include/class/TreeGroup.class.php b/pandora_console/include/class/TreeGroup.class.php index fd38794d1c..05ba271e24 100644 --- a/pandora_console/include/class/TreeGroup.class.php +++ b/pandora_console/include/class/TreeGroup.class.php @@ -1,467 +1,529 @@ <?php -//Pandora FMS- http://pandorafms.com +// Pandora FMS- http://pandorafms.com // ================================================== // Copyright (c) 2005-2018 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list - // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 - // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - global $config; -require_once($config['homedir']."/include/class/Tree.class.php"); +require_once $config['homedir'].'/include/class/Tree.class.php'; -class TreeGroup extends Tree { +class TreeGroup extends Tree +{ - protected $propagateCounters = true; - protected $displayAllGroups = false; + protected $propagateCounters = true; - public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { - - global $config; - - parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - - $this->L1fieldName = "id_group"; - $this->L1extraFields = array( - "tg.nombre AS `name`", - "tg.icon", - "tg.id_grupo AS gid" - ); - - $this->L2conditionInside = "AND ( - ta.id_grupo = " . $this->id . " - OR tasg.id_group = " . $this->id . " - )"; - } - - public function setPropagateCounters($value) { - $this->propagateCounters = (bool)$value; - } - - public function setDisplayAllGroups($value) { - $this->displayAllGroups = (bool)$value; - } - - protected function getData() { - if ($this->id == -1) { - - $this->getFirstLevel(); - - } elseif ($this->type == 'group') { - $this->getSecondLevel(); - } elseif ($this->type == 'agent') { - $this->getThirdLevel(); - } - } - - protected function getGroupSearchFilter() { - return ""; - } - - protected function getFirstLevel() { - $processed_items = $this->getProcessedGroups(); - - if (!empty($processed_items)) { - // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants - if (!empty($this->filter['searchGroup'])) { - // Save the groups which intersect with the user groups - $groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%')); - if ($groups == false) $groups = array(); - $userGroupsACL = $this->userGroupsACL; - $ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) { - $group_id = $group['id_grupo']; - if (isset($userGroupsACL[$group_id])) { - $userGroups[$group_id] = $userGroupsACL[$group_id]; - } - - return $userGroups; - }, array()); - - $result = self::extractGroupsWithIDs($processed_items, $ids_hash); - - $processed_items = ($result === false) ? array() : $result; - } - - // groupID filter. To access the view from tactical views f.e. - if (!empty($this->filter['groupID'])) { - $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL); - - $processed_items = ($result === false) ? array() : array($result); - } - } - hd("G-GETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVELGETFIRSTLEVEL", true); -hd($processed_items, true); - $this->tree = $processed_items; - } - - protected function getProcessedGroups () { - $processed_groups = array(); - // Index and process the groups - $groups = $this->getGroupCounters(); - - // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all("AR")) { - foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { - $groups[$id]['parent'] = 0; - } - } - } - // Build the group hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = array(); - } - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], array("Tree", "cmpSortNames")); - } - } - //Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter($groups, function ($group) { - return !$group['have_parent']; - }); - // Propagate child counters to her parents - - if ($this->propagateCounters) { - TreeGroup::processCounters($groups); - // Filter groups and eliminates the reference to empty groups - $groups = $this->deleteEmptyGroups($groups); - } else { - $groups = $this->deleteEmptyGroupsNotPropagate($groups); - } - - usort($groups, array("Tree", "cmpSortNames")); - - return $groups; - } - - protected function getGroupCounters() { - $fields = $this->getFirstLevelFields(); - $inside_fields = $this->getFirstLevelFieldsInside(); - - $group_acl = ""; - $secondary_group_acl = ""; - if (!users_can_manage_group_all("AR")) { - $user_groups_str = implode(",", $this->userGroupsArray); - $group_acl = " AND ta.id_grupo IN ($user_groups_str)"; - $secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)"; - } - $agent_search_filter = $this->getAgentSearchFilter(); - $agent_search_filter = preg_replace("/%/", "%%", $agent_search_filter); - $agent_status_filter = $this->getAgentStatusFilter(); - $module_status_filter = $this->getModuleStatusFilter(); - - $module_search_inner = ""; - $module_search_filter = ""; - if (!empty($this->filter['searchModule'])) { - $module_search_inner = " - INNER JOIN tagente_modulo tam - ON ta.id_agente = tam.id_agente - INNER JOIN tagente_estado tae - ON tae.id_agente_modulo = tam.id_agente_modulo"; - $module_search_filter = "AND tam.disabled = 0 - AND tam.nombre LIKE '%%" . $this->filter['searchModule'] . "%%' " . - $this->getModuleStatusFilterFromTestado() - ; - } - - $table = is_metaconsole() ? "tmetaconsole_agent" : "tagente"; - $table_sec = is_metaconsole() ? "tmetaconsole_agent_secondary_group" : "tagent_secondary_group"; - - $sql_model = "SELECT %s FROM - ( - SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_grupo AS g - FROM $table ta - $module_search_inner - WHERE ta.disabled = 0 - %s - $agent_search_filter - $agent_status_filter - $module_status_filter - $module_search_filter - $group_acl - GROUP BY id_grupo - UNION ALL - SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_group AS g - FROM $table ta INNER JOIN $table_sec tasg - ON ta.id_agente = tasg.id_agent - $module_search_inner - WHERE ta.disabled = 0 - %s - $agent_search_filter - $agent_status_filter - $module_status_filter - $module_search_filter - $secondary_group_acl - GROUP BY id_group - ) x GROUP BY g"; - $sql_array = array(); - foreach ($inside_fields as $inside_field) { - $sql_array[] = sprintf( - $sql_model, - $inside_field['header'], - $inside_field['condition'], - $inside_field['condition'] - ); - } - $sql = "SELECT $fields FROM (" . implode(" UNION ALL ", $sql_array) . ") x2 - RIGHT JOIN tgrupo tg - ON x2.g = tg.id_grupo - GROUP BY tg.id_grupo"; - $stats = db_get_all_rows_sql($sql); - - $group_stats = array(); - - hd("STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS STATS ", true); - hd($stats, true); - foreach ($stats as $group) { - $group_stats[$group['gid']]['total_count'] = (int)$group['total_count']; - $group_stats[$group['gid']]['total_critical_count'] = (int)$group['total_critical_count']; - $group_stats[$group['gid']]['total_unknown_count'] = (int)$group['total_unknown_count']; - $group_stats[$group['gid']]['total_warning_count'] = (int)$group['total_warning_count']; - $group_stats[$group['gid']]['total_not_init_count'] = (int)$group['total_not_init_count']; - $group_stats[$group['gid']]['total_normal_count'] = (int)$group['total_normal_count']; - $group_stats[$group['gid']]['total_fired_count'] = (int)$group['total_alerts_count']; - $group_stats[$group['gid']]['name'] = $group['name']; - $group_stats[$group['gid']]['parent'] = $group['parent']; - $group_stats[$group['gid']]['icon'] = $group['icon']; - $group_stats[$group['gid']]['id'] = $group['gid']; - $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); - - } + protected $displayAllGroups = false; + public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR') + { + global $config; - return $group_stats; - } + parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - protected function getFirstLevelFields() { - $fields = parent::getFirstLevelFields(); - $parent = $this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent'; - return "$fields, $parent"; - } + $this->L1fieldName = 'id_group'; + $this->L1extraFields = [ + 'tg.nombre AS `name`', + 'tg.icon', + 'tg.id_grupo AS gid', + ]; - protected function getProcessedModules($modules_tree) { + $this->L2conditionInside = 'AND ( + ta.id_grupo = '.$this->id.' + OR tasg.id_group = '.$this->id.' + )'; + } - $groups = array(); - foreach ($modules_tree as $group) { - $groups[$group["id"]] = $group; - } - // Build the module hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = array(); - } - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } + public function setPropagateCounters($value) + { + $this->propagateCounters = (bool) $value; + } - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], array("Tree", "cmpSortNames")); - } - } - //Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter($groups, function ($group) { - return !$group['have_parent']; - }); - return array_values($groups); - } + public function setDisplayAllGroups($value) + { + $this->displayAllGroups = (bool) $value; + } - // FIXME: Hierarchy lops is broken - protected function getProcessedModules_old($modules_tree) { - $tree_modules = array(); - $new_modules_root = array_filter($modules_tree, function ($module) { - return (isset($module['parent']) && ($module['parent'] == 0)); - }); + protected function getData() + { + if ($this->id == -1) { + $this->getFirstLevel(); + } else if ($this->type == 'group') { + $this->getSecondLevel(); + } else if ($this->type == 'agent') { + $this->getThirdLevel(); + } + } - $new_modules_child = array_filter($modules_tree, function ($module) { - return (isset($module['parent']) && ($module['parent'] != 0)); - }); - $i = 0; - while (!empty($new_modules_child)) { - foreach ($new_modules_child as $i => $child) { - TreeGroup::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); - } - } + protected function getGroupSearchFilter() + { + return ''; + } - foreach ($new_modules_root as $m) { - $tree_modules[] = $m; - } - return $tree_modules; - } - // FIXME with getProcessedModules_old - static function recursive_modules_tree_view (&$new_modules, &$new_modules_child, $i, $child) { - foreach ($new_modules as $index => $module) { - if ($module['id'] == $child['parent']) { - $new_modules[$index]['children'][] = $child; - unset($new_modules_child[$i]); - break; - } - else if (isset($new_modules[$index]['children'])) { - TreeGroup::recursive_modules_tree_view ($new_modules[$index]['children'], $new_modules_child, $i, $child); - } - } - } + protected function getFirstLevel() + { + $processed_items = $this->getProcessedGroups(); - static function processCounters(&$groups) { - $all_counters = array(); - foreach ($groups as $id => $group) { - $child_counters = array(); - if (!empty($groups[$id]['children'])) { - $child_counters = TreeGroup::processCounters($groups[$id]['children']); - } - if (!empty($child_counters)) { - foreach($child_counters as $type => $value) { - $groups[$id]['counters'][$type] += $value; - } - } - foreach($groups[$id]['counters'] as $type => $value) { - $all_counters[$type] += $value; - } - } - return $all_counters; - } + if (!empty($processed_items)) { + // Filter by group name. This should be done after rerieving the items cause we need the possible items descendants + if (!empty($this->filter['searchGroup'])) { + // Save the groups which intersect with the user groups + $groups = db_get_all_rows_filter('tgrupo', ['nombre' => '%'.$this->filter['searchGroup'].'%']); + if ($groups == false) { + $groups = []; + } - /** - * @brief Recursive function to remove the empty groups - * - * @param groups All groups structure - * - * @return new_groups A new groups structure without empty groups - */ - protected function deleteEmptyGroups ($groups) { - if($this->displayAllGroups) return $groups; - $new_groups = array(); - foreach ($groups as $group) { - // If a group is empty, do not add to new_groups. - if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { - continue; - } - // Tray to remove the children groups - if (!empty($group['children'])) { - $children = $this->deleteEmptyGroups ($group['children']); - if (empty($children)) unset($group['children']); - else $group['children'] = $children; - } - $new_groups[] = $group; - } - return $new_groups; - } + $userGroupsACL = $this->userGroupsACL; + $ids_hash = array_reduce( + $groups, + function ($userGroups, $group) use ($userGroupsACL) { + $group_id = $group['id_grupo']; + if (isset($userGroupsACL[$group_id])) { + $userGroups[$group_id] = $userGroupsACL[$group_id]; + } - protected function deleteEmptyGroupsNotPropagate ($groups) { - if($this->displayAllGroups) return $groups; - $new_groups = array(); - foreach ($groups as $group) { - // Tray to remove the children groups - if (!empty($group['children'])) { - $children = $this->deleteEmptyGroupsNotPropagate ($group['children']); - if (empty($children)) { - unset($group['children']); - // If a group is empty, do not add to new_groups. - if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { - $new_groups[] = $group; - } - } else { - $group['children'] = $children; - $new_groups[] = $group; - } - } else { - // If a group is empty, do not add to new_groups. - if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { - $new_groups[] = $group; - } - } - } - return $new_groups; - } + return $userGroups; + }, + [] + ); - private static function extractGroupsWithIDs ($groups, $ids_hash) { - $result_groups = array(); - foreach ($groups as $group) { - if (isset($ids_hash[$group['id']])) { - $result_groups[] = $group; - } - else if (!empty($group['children'])) { - $result = self::extractGroupsWithIDs($group['children'], $ids_hash); + $result = self::extractGroupsWithIDs($processed_items, $ids_hash); - // Item found on children - if (!empty($result)) { - $result_groups = array_merge($result_groups, $result); - } - } - } + $processed_items = ($result === false) ? [] : $result; + } - return $result_groups; - } + // groupID filter. To access the view from tactical views f.e. + if (!empty($this->filter['groupID'])) { + $result = self::extractItemWithID($processed_items, $this->filter['groupID'], 'group', $this->strictACL); - private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) { - foreach ($items as $item) { - if ($item["type"] != $item_type) - continue; + $processed_items = ($result === false) ? [] : [$result]; + } + } - // Item found - if ($strictACL && is_metaconsole()) { - foreach ($item["id"] as $server_id => $id) { - if ($id == $item_id) - return $item; - } - } - else { - if ($item["id"] == $item_id) - return $item; - } + $this->tree = $processed_items; + } - if ($item["type"] == "group" && !empty($item["children"])) { - $result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL); - // Item found on children - if ($result !== false) - return $result; - } - } + protected function getProcessedGroups() + { + $processed_groups = []; + // Index and process the groups + $groups = $this->getGroupCounters(); - // Item not found - return false; - } + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all('AR')) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = []; + } + + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); + } + } + + // Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter( + $groups, + function ($group) { + return !$group['have_parent']; + } + ); + // Propagate child counters to her parents + if ($this->propagateCounters) { + self::processCounters($groups); + // Filter groups and eliminates the reference to empty groups + $groups = $this->deleteEmptyGroups($groups); + } else { + $groups = $this->deleteEmptyGroupsNotPropagate($groups); + } + + usort($groups, ['Tree', 'cmpSortNames']); + return $groups; + } + + + protected function getGroupCounters() + { + $fields = $this->getFirstLevelFields(); + $inside_fields = $this->getFirstLevelFieldsInside(); + + $group_acl = ''; + $secondary_group_acl = ''; + if (!users_can_manage_group_all('AR')) { + $user_groups_str = implode(',', $this->userGroupsArray); + $group_acl = " AND ta.id_grupo IN ($user_groups_str)"; + $secondary_group_acl = " AND tasg.id_group IN ($user_groups_str)"; + } + + $agent_search_filter = $this->getAgentSearchFilter(); + $agent_search_filter = preg_replace('/%/', '%%', $agent_search_filter); + $agent_status_filter = $this->getAgentStatusFilter(); + $module_status_filter = $this->getModuleStatusFilter(); + + $module_search_inner = ''; + $module_search_filter = ''; + if (!empty($this->filter['searchModule'])) { + $module_search_inner = ' + INNER JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + INNER JOIN tagente_estado tae + ON tae.id_agente_modulo = tam.id_agente_modulo'; + $module_search_filter = "AND tam.disabled = 0 + AND tam.nombre LIKE '%%".$this->filter['searchModule']."%%' ".$this->getModuleStatusFilterFromTestado(); + } + + $table = is_metaconsole() ? 'tmetaconsole_agent' : 'tagente'; + $table_sec = is_metaconsole() ? 'tmetaconsole_agent_secondary_group' : 'tagent_secondary_group'; + + $sql_model = "SELECT %s FROM + ( + SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_grupo AS g + FROM $table ta + $module_search_inner + WHERE ta.disabled = 0 + %s + $agent_search_filter + $agent_status_filter + $module_status_filter + $module_search_filter + $group_acl + GROUP BY id_grupo + UNION ALL + SELECT COUNT(DISTINCT(ta.id_agente)) AS total, id_group AS g + FROM $table ta INNER JOIN $table_sec tasg + ON ta.id_agente = tasg.id_agent + $module_search_inner + WHERE ta.disabled = 0 + %s + $agent_search_filter + $agent_status_filter + $module_status_filter + $module_search_filter + $secondary_group_acl + GROUP BY id_group + ) x GROUP BY g"; + $sql_array = []; + foreach ($inside_fields as $inside_field) { + $sql_array[] = sprintf( + $sql_model, + $inside_field['header'], + $inside_field['condition'], + $inside_field['condition'] + ); + } + + $sql = "SELECT $fields FROM (".implode(' UNION ALL ', $sql_array).') x2 + RIGHT JOIN tgrupo tg + ON x2.g = tg.id_grupo + GROUP BY tg.id_grupo'; + $stats = db_get_all_rows_sql($sql); + + $group_stats = []; + foreach ($stats as $group) { + $group_stats[$group['gid']]['total_count'] = (int) $group['total_count']; + $group_stats[$group['gid']]['total_critical_count'] = (int) $group['total_critical_count']; + $group_stats[$group['gid']]['total_unknown_count'] = (int) $group['total_unknown_count']; + $group_stats[$group['gid']]['total_warning_count'] = (int) $group['total_warning_count']; + $group_stats[$group['gid']]['total_not_init_count'] = (int) $group['total_not_init_count']; + $group_stats[$group['gid']]['total_normal_count'] = (int) $group['total_normal_count']; + $group_stats[$group['gid']]['total_fired_count'] = (int) $group['total_alerts_count']; + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + } + + return $group_stats; + } + + + protected function getFirstLevelFields() + { + $fields = parent::getFirstLevelFields(); + $parent = $this->getDisplayHierarchy() ? 'tg.parent' : '0 as parent'; + return "$fields, $parent"; + } + + + protected function getProcessedModules($modules_tree) + { + $groups = []; + foreach ($modules_tree as $group) { + $groups[$group['id']] = $group; + } + + // Build the module hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = []; + } + + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); + } + } + + // Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter( + $groups, + function ($group) { + return !$group['have_parent']; + } + ); + + return array_values($groups); + } + + + // FIXME: Hierarchy lops is broken + protected function getProcessedModules_old($modules_tree) + { + $tree_modules = []; + $new_modules_root = array_filter( + $modules_tree, + function ($module) { + return (isset($module['parent']) && ($module['parent'] == 0)); + } + ); + + $new_modules_child = array_filter( + $modules_tree, + function ($module) { + return (isset($module['parent']) && ($module['parent'] != 0)); + } + ); + + $i = 0; + while (!empty($new_modules_child)) { + foreach ($new_modules_child as $i => $child) { + self::recursive_modules_tree_view($new_modules_root, $new_modules_child, $i, $child); + } + } + + foreach ($new_modules_root as $m) { + $tree_modules[] = $m; + } + + return $tree_modules; + } + + + // FIXME with getProcessedModules_old + static function recursive_modules_tree_view(&$new_modules, &$new_modules_child, $i, $child) + { + foreach ($new_modules as $index => $module) { + if ($module['id'] == $child['parent']) { + $new_modules[$index]['children'][] = $child; + unset($new_modules_child[$i]); + break; + } else if (isset($new_modules[$index]['children'])) { + self::recursive_modules_tree_view($new_modules[$index]['children'], $new_modules_child, $i, $child); + } + } + } + + + static function processCounters(&$groups) + { + $all_counters = []; + foreach ($groups as $id => $group) { + $child_counters = []; + if (!empty($groups[$id]['children'])) { + $child_counters = self::processCounters($groups[$id]['children']); + } + + if (!empty($child_counters)) { + foreach ($child_counters as $type => $value) { + $groups[$id]['counters'][$type] += $value; + } + } + + foreach ($groups[$id]['counters'] as $type => $value) { + $all_counters[$type] += $value; + } + } + + return $all_counters; + } + + + /** + * @brief Recursive function to remove the empty groups + * + * @param groups All groups structure + * + * @return new_groups A new groups structure without empty groups + */ + protected function deleteEmptyGroups($groups) + { + if ($this->displayAllGroups) { + return $groups; + } + + $new_groups = []; + foreach ($groups as $group) { + // If a group is empty, do not add to new_groups. + if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) { + continue; + } + + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = $this->deleteEmptyGroups($group['children']); + if (empty($children)) { + unset($group['children']); + } else { + $group['children'] = $children; + } + } + + $new_groups[] = $group; + } + + return $new_groups; + } + + + protected function deleteEmptyGroupsNotPropagate($groups) + { + if ($this->displayAllGroups) { + return $groups; + } + + $new_groups = []; + foreach ($groups as $group) { + // Tray to remove the children groups + if (!empty($group['children'])) { + $children = $this->deleteEmptyGroupsNotPropagate($group['children']); + if (empty($children)) { + unset($group['children']); + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } else { + $group['children'] = $children; + $new_groups[] = $group; + } + } else { + // If a group is empty, do not add to new_groups. + if (isset($group['counters']['total']) && $group['counters']['total'] != 0) { + $new_groups[] = $group; + } + } + } + + return $new_groups; + } + + + private static function extractGroupsWithIDs($groups, $ids_hash) + { + $result_groups = []; + foreach ($groups as $group) { + if (isset($ids_hash[$group['id']])) { + $result_groups[] = $group; + } else if (!empty($group['children'])) { + $result = self::extractGroupsWithIDs($group['children'], $ids_hash); + + // Item found on children + if (!empty($result)) { + $result_groups = array_merge($result_groups, $result); + } + } + } + + return $result_groups; + } + + + private static function extractItemWithID($items, $item_id, $item_type='group', $strictACL=false) + { + foreach ($items as $item) { + if ($item['type'] != $item_type) { + continue; + } + + // Item found + if ($strictACL && is_metaconsole()) { + foreach ($item['id'] as $server_id => $id) { + if ($id == $item_id) { + return $item; + } + } + } else { + if ($item['id'] == $item_id) { + return $item; + } + } + + if ($item['type'] == 'group' && !empty($item['children'])) { + $result = self::extractItemWithID($item['children'], $item_id, $item_type, $strictACL); + + // Item found on children + if ($result !== false) { + return $result; + } + } + } + + // Item not found + return false; + } + + + protected function getDisplayHierarchy() + { + return $this->filter['searchHirearchy'] || + (empty($this->filter['searchAgent']) && empty($this->filter['searchModule'])); + } - protected function getDisplayHierarchy() { - return $this->filter['searchHirearchy'] || - (empty($this->filter['searchAgent']) && empty($this->filter['searchModule'])); - } } - -?> - diff --git a/pandora_console/include/class/TreeGroupEdition.class.php b/pandora_console/include/class/TreeGroupEdition.class.php index dea62da238..55efebe976 100644 --- a/pandora_console/include/class/TreeGroupEdition.class.php +++ b/pandora_console/include/class/TreeGroupEdition.class.php @@ -1,108 +1,120 @@ <?php -//Pandora FMS- http://pandorafms.com +// Pandora FMS- http://pandorafms.com // ================================================== // Copyright (c) 2005-2018 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list - // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation; version 2 - // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - global $config; -require_once($config['homedir']."/include/class/Tree.class.php"); +require_once $config['homedir'].'/include/class/Tree.class.php'; -class TreeGroupEdition extends TreeGroup { - public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') { - global $config; - - parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); - } - protected function getData() { - if ($this->id == -1) { - $this->getFirstLevel(); - } - } - - protected function getProcessedGroups () { - $processed_groups = array(); - // Index and process the groups - $groups = $this->getGroupCounters(); - - // If user have not permissions in parent, set parent node to 0 (all) - // Avoid to do foreach for admins - if (!users_can_manage_group_all("AR")) { - foreach ($groups as $id => $group) { - if (!isset($this->userGroups[$groups[$id]['parent']])) { - $groups[$id]['parent'] = 0; - } - } - } - // Build the group hierarchy - foreach ($groups as $id => $group) { - if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { - $parent = $groups[$id]['parent']; - // Parent exists - if (!isset($groups[$parent]['children'])) { - $groups[$parent]['children'] = array(); - } - // Store a reference to the group into the parent - $groups[$parent]['children'][] = &$groups[$id]; - // This group was introduced into a parent - $groups[$id]['have_parent'] = true; - } - } - - // Sort the children groups - foreach ($groups as $id => $group) { - if (isset($groups[$id]['children'])) { - usort($groups[$id]['children'], array("Tree", "cmpSortNames")); - } - } - //Filter groups and eliminates the reference to children groups out of her parent - $groups = array_filter($groups, function ($group) { - return !$group['have_parent']; - }); - - usort($groups, array("Tree", "cmpSortNames")); - return $groups; - } +class TreeGroupEdition extends TreeGroup +{ - protected function getGroupCounters() { - $messages = array( - 'confirm' => __('Confirm'), - 'cancel' => __('Cancel'), - 'messg' => __('Are you sure?') - ); - $sql = "SELECT id_grupo AS gid, + public function __construct($type, $rootType='', $id=-1, $rootID=-1, $serverID=false, $childrenMethod='on_demand', $access='AR') + { + global $config; + + parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access); + } + + + protected function getData() + { + if ($this->id == -1) { + $this->getFirstLevel(); + } + } + + + protected function getProcessedGroups() + { + $processed_groups = []; + // Index and process the groups + $groups = $this->getGroupCounters(); + + // If user have not permissions in parent, set parent node to 0 (all) + // Avoid to do foreach for admins + if (!users_can_manage_group_all('AR')) { + foreach ($groups as $id => $group) { + if (!isset($this->userGroups[$groups[$id]['parent']])) { + $groups[$id]['parent'] = 0; + } + } + } + + // Build the group hierarchy + foreach ($groups as $id => $group) { + if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { + $parent = $groups[$id]['parent']; + // Parent exists + if (!isset($groups[$parent]['children'])) { + $groups[$parent]['children'] = []; + } + + // Store a reference to the group into the parent + $groups[$parent]['children'][] = &$groups[$id]; + // This group was introduced into a parent + $groups[$id]['have_parent'] = true; + } + } + + // Sort the children groups + foreach ($groups as $id => $group) { + if (isset($groups[$id]['children'])) { + usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); + } + } + + // Filter groups and eliminates the reference to children groups out of her parent + $groups = array_filter( + $groups, + function ($group) { + return !$group['have_parent']; + } + ); + + usort($groups, ['Tree', 'cmpSortNames']); + return $groups; + } + + + protected function getGroupCounters() + { + $messages = [ + 'confirm' => __('Confirm'), + 'cancel' => __('Cancel'), + 'messg' => __('Are you sure?'), + ]; + $sql = 'SELECT id_grupo AS gid, nombre as name, parent, icon FROM tgrupo - "; + '; - $stats = db_get_all_rows_sql($sql); - $group_stats = array(); - foreach ($stats as $group) { - $group_stats[$group['gid']]['name'] = $group['name']; - $group_stats[$group['gid']]['parent'] = $group['parent']; - $group_stats[$group['gid']]['icon'] = $group['icon']; - $group_stats[$group['gid']]['id'] = $group['gid']; - $group_stats[$group['gid']]['type'] = 'group'; + $stats = db_get_all_rows_sql($sql); + $group_stats = []; + foreach ($stats as $group) { + $group_stats[$group['gid']]['name'] = $group['name']; + $group_stats[$group['gid']]['parent'] = $group['parent']; + $group_stats[$group['gid']]['icon'] = $group['icon']; + $group_stats[$group['gid']]['id'] = $group['gid']; + $group_stats[$group['gid']]['type'] = 'group'; + + $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); + $group_stats[$group['gid']]['delete']['messages'] = $messages; + $group_stats[$group['gid']]['edit'] = 1; + $group_stats[$group['gid']]['alerts'] = ''; + } + + return $group_stats; + } - $group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]); - $group_stats[$group['gid']]['delete']['messages'] = $messages; - $group_stats[$group['gid']]['edit'] = 1; - $group_stats[$group['gid']]['alerts'] = ''; - } - return $group_stats; - } } - -?> - diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index 46f9139427..bbddc8dc2a 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -114,8 +114,6 @@ class TreeService extends Tree { protected function getProcessedServices () { $fields = $this->getFirstLevelFields(); - - //hd($this->userGroupsArray, true); if (users_can_manage_group_all("AR")){ $groups_acl = ""; @@ -166,9 +164,6 @@ class TreeService extends Tree { $services[$service['id']]['serviceDetail']='http://localhost/pandora_console/index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; } - hd("STATS:::::::::::::::::::::::::::::: ", true); -hd($services, true); - return $services; } @@ -227,9 +222,6 @@ hd($services, true); } } - hd("MODULESSSS::", true); -hd($data_modules, true); - $sql = $this->getSecondLevelServicesSql(); $data_services = db_process_sql($sql); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index e22a17ced9..3fab4f6dab 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -750,7 +750,6 @@ var TreeController = { } // Load the status counters - console.log(element.counters); var hasCounters = _processNodeCounters($content, element.counters, element.type); //Don't show empty groups if (element.type == 'agent') { @@ -871,7 +870,6 @@ var TreeController = { .hide(); $node.append($group); } - //console.log(data.tree); _.each(data.tree, function(element) { element.jqObject = _processNode($group, element); diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 5dc7caea1b..18e1e77ffc 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -314,7 +314,6 @@ if ($id_agent != 0) { $text_module = (string) get_parameter('module_search', ''); $id_agent_module = get_parameter('module_search_hidden', get_parameter('id_agent_module', 0)); -hd("------------------------------------>>>>>>> ".$id_agent_module." y id_agent: ".$id_agent, true); if ($id_agent_module != 0) { $text_module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); if ($text_module == false) { From 12b8042c5317d61f826e2f4695beff1b4106a95c Mon Sep 17 00:00:00 2001 From: Daniel Maya <daniel.maya@artica.es> Date: Fri, 22 Feb 2019 14:26:58 +0100 Subject: [PATCH 06/25] Added server plugins in meta Former-commit-id: 7f69f55c3fad06c7b15408d755d088d5ac89b111 --- pandora_console/godmode/servers/plugin.php | 294 ++++++++++++++++++--- 1 file changed, 257 insertions(+), 37 deletions(-) diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index ff370a5c48..fcb34363f0 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -112,6 +112,7 @@ $edit_file = get_parameter('edit_file', false); $update_file = get_parameter('update_file', false); $plugin_command = get_parameter('plugin_command', ''); $tab = get_parameter('tab', ''); +$deploy_plugin = get_parameter('deploy_plugin', 0); if ($view != '') { $form_id = $view; @@ -192,9 +193,8 @@ if ($filemanager) { // If is win compatible and the compatibility must be unix if ($is_win_compatible !== false && $compatibility == 'unix') { $contentFile = str_replace("\r\n", "\n", $contentFile); - } - // If is unix compatible and the compatibility must be win - else if ($is_win_compatible === false && $compatibility == 'windows') { + } else if ($is_win_compatible === false && $compatibility == 'windows') { + // If is unix compatible and the compatibility must be win $contentFile = str_replace("\n", "\r\n", $contentFile); } @@ -268,12 +268,16 @@ if ($filemanager) { // ===================================================================== $sec = 'gservers'; -if (($create != '') or ($view != '')) { +if (($create != '') || ($view != '')) { enterprise_hook('open_meta_frame'); if (defined('METACONSOLE')) { components_meta_print_header(); $sec = 'advanced'; + $management_allowed = is_management_allowed(); + if (!$management_allowed) { + ui_print_warning_message(__('To manage plugin you must activate centralized management')); + } } else { if ($create != '') { ui_print_page_header( @@ -292,6 +296,16 @@ if (($create != '') or ($view != '')) { true ); } + + $management_allowed = !is_central_policies_on_node(); + if (!$management_allowed) { + ui_print_warning_message( + __( + 'This console is not manager of this environment, + please manage this feature from centralized manager console (Metaconsole).' + ) + ); + } } @@ -564,9 +578,53 @@ if (($create != '') or ($view != '')) { if (defined('METACONSOLE')) { components_meta_print_header(); $sec = 'advanced'; + $management_allowed = is_management_allowed(); + if (!$management_allowed) { + ui_print_warning_message(__('To manage plugin you must activate centralized management')); + } + + if (!$config['metaconsole_deploy_plugin_server'] && $management_allowed) { + $deploy_plugin_server = true; + + echo '<div id="deploy_messages" style="display: none">'; + echo '<span>'.__('The previous configuration of plugins has been imported from the nodes. Please check that the definitions are correct.').'</br></br>'.'<b>'.__('Note:').'</b>'.__( + 'These definitions will not be operational until you manually + copy the files from the nodes to the atachment/plugin/ directory of the meta console.' + ).'</br></br>'.__('You can find more information at:')."<a href='https://wiki.pandorafms.com'>https://wiki.pandorafms.com</a>".'</span>'; + echo '</div>'; + ?> + <script type="text/javascript"> + $(document).ready(function () { + $("#deploy_messages").dialog({ + resizable: true, + draggable: true, + modal: true, + height: 220, + title: '<?php echo __('Warning'); ?>', + width: 528, + overlay: { + opacity: 0.5, + background: "black" + } + }); + }); + </script> + <?php + config_update_value('metaconsole_deploy_plugin_server', 1); + } } else { ui_print_page_header(__('Plug-ins registered on %s', get_product_name()), 'images/gm_servers.png', false, '', true); + $management_allowed = !is_central_policies_on_node(); + if (!$management_allowed) { + ui_print_warning_message( + __( + 'This console is not manager of this environment, + please manage this feature from centralized manager console (Metaconsole).' + ) + ); + } + $is_windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'; if ($is_windows) { echo '<div class="notify">'; @@ -709,12 +767,15 @@ if (($create != '') or ($view != '')) { $result = db_process_sql_delete('tplugin', ['id' => $plugin_id]); - if (! $result) { - ui_print_error_message(__('Problem deleting plugin')); - } else { - ui_print_success_message(__('Plugin deleted successfully')); + if (!is_metaconsole()) { + if (!$result) { + ui_print_error_message(__('Problem deleting plugin')); + } else { + ui_print_success_message(__('Plugin deleted successfully')); + } } + if ($plugin_id != 0) { // Delete all the modules with this plugin $plugin_modules = db_get_all_rows_filter( @@ -737,6 +798,153 @@ if (($create != '') or ($view != '')) { policies_change_delete_pending_module($policies_id['id']); } } + + if (is_metaconsole()) { + enterprise_include_once('include/functions_plugins.php'); + $result = plugins_delete_plugin($plugin_id); + if (!$result) { + ui_print_error_message(__('Problem deleting plugin')); + } else { + ui_print_success_message(__('Plugin deleted successfully')); + } + } + } + } + + if ($deploy_plugin) { + if (is_metaconsole()) { + enterprise_include_once('include/functions_plugins.php'); + $result = plugins_deploy_plugin($deploy_plugin); + if (!$result) { + ui_print_error_message(__('Problem deploying plugin')); + } else { + ui_print_success_message(__('Plugin deployed successfully')); + } + } + } + + if ($deploy_plugin_server) { + $setup = db_get_all_rows_in_table('tmetaconsole_setup'); + // recorremos todos los nodos. + foreach ($setup as $key => $value) { + // Obtenemos los plugins de la meta. + $all_plugin_meta = db_get_all_rows_in_table('tplugin'); + // Conectamos con el nodo. + if (metaconsole_connect($value) == NOERR) { + $values = []; + // Obtenemos los plugin del nodo. + $node_plugin_server = db_get_all_rows_in_table('tplugin'); + foreach ($node_plugin_server as $key2 => $plugin) { + // Comprobamos si el id esta meta y nodo al mismo tiempo. + $key_exists = array_search($plugin['id'], array_column($all_plugin_meta, 'id')); + if ($key_exists !== false) { + // Si el plugin tiene el mismo id pero diferentes datos. + if ($all_plugin_meta[$key_exists] != $plugin) { + $old_id = $plugin['id']; + $new_id = ($plugin['id'] + (1000 * $value['id'])); + + // El plugin del nodo pasa a tener otro id y otro nombre. + $plugin['id'] = $new_id; + $plugin['name'] = $plugin['name'].'_'.$value['server_name']; + $result_update = db_process_sql_update( + 'tplugin', + [ + 'id' => $new_id, + 'name' => $plugin['name'], + ], + ['id' => $old_id] + ); + + if ($result_update) { + db_process_sql_update( + 'tagente_modulo', + ['id_plugin' => $new_id], + ['id_plugin' => $old_id] + ); + + db_process_sql_update( + 'tnetwork_component', + ['id_plugin' => $new_id], + ['id_plugin' => $old_id] + ); + + db_process_sql_update( + 'tpolicy_modules', + ['id_plugin' => $new_id], + ['id_plugin' => $old_id] + ); + } + + // New plugins to insert in the metaconsole. + $values[$plugin['id']] = $plugin; + } + } else { + // Exists in the node, but does not exist in the metaconsole. + $values[$plugin['id']] = $plugin; + } + } + + // Restore to metaconsole. + metaconsole_restore_db(); + + // Insert in metaconsole. + if (!empty($values)) { + foreach ($values as $key2 => $val) { + // Insert into metaconsole. + $result_insert = db_process_sql_insert('tplugin', $val); + } + } + } + } + + $all_plugin_meta = db_get_all_rows_in_table('tplugin'); + + foreach ($setup as $key => $value) { + if (metaconsole_connect($value) == NOERR) { + $all_plugin_node = db_get_all_rows_in_table('tplugin'); + + $array_diff = array_diff(array_column($all_plugin_meta, 'id'), array_column($all_plugin_node, 'id')); + foreach ($array_diff as $key2 => $pluginid) { + $other = []; + $plugin_meta = $all_plugin_meta[$key2]; + + unset($plugin_meta['id']); + $other['name'] = urlencode($plugin_meta['name']); + $other['description'] = urlencode($plugin_meta['description']); + $other['max_timeout'] = $plugin_meta['max_timeout']; + $other['max_retries'] = $plugin_meta['max_retries']; + $other['execute'] = urlencode($plugin_meta['execute']); + $other['net_dst_opt'] = $plugin_meta['net_dst_opt']; + $other['net_port_opt'] = $plugin_meta['net_port_opt']; + $other['user_opt'] = $plugin_meta['user_opt']; + $other['pass_opt'] = $plugin_meta['pass_opt']; + $other['plugin_type'] = $plugin_meta['plugin_type']; + $other['macros'] = urlencode($plugin_meta['macros']); + $other['parameters'] = urlencode($plugin_meta['parameters']); + $other = implode('%7C', $other); + + $auth_token = json_decode($value['auth_token']); + $url = $value['server_url'].'include/api.php?op=set&op2=push_plugin'.'&id='.$pluginid.'&other_mode=url_encode_separator_%7C&other='.$other."&apipass=$auth_token->api_password"."&user=$auth_token->console_user&pass=$auth_token->console_password"; + $file_path = realpath($plugin_meta['execute']); + $post = ''; + if (file_exists($file_path)) { + $post = ['file' => curl_file_create($file_path)]; + } + + $curlObj = curl_init(); + curl_setopt($curlObj, CURLOPT_URL, $url); + curl_setopt($curlObj, CURLOPT_POST, 1); + curl_setopt($curlObj, CURLOPT_POSTFIELDS, $post); + curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); + + $api_result = curl_exec($curlObj); + curl_close($curlObj); + } + } + + // restore to metaconsole + metaconsole_restore_db(); } } @@ -753,7 +961,10 @@ if (($create != '') or ($view != '')) { echo '<th>'.__('Name').'</th>'; echo '<th>'.__('Type').'</th>'; echo '<th>'.__('Command').'</th>'; - echo "<th style='width: 90px;'>".'<span title="Operations">'.__('Op.').'</span>'.'</th>'; + if ($management_allowed) { + echo "<th style='width: 120px;'>".'<span title="Operations">'.__('Op.').'</span>'.'</th>'; + } + $color = 0; foreach ($rows as $row) { @@ -780,31 +991,38 @@ if (($create != '') or ($view != '')) { echo "</td><td class=$tdcolor>"; echo $row['execute']; echo '</td>'; - echo "<td class='$tdcolor' align='center'>"; + if ($management_allowed) { + echo "<td class='$tdcolor' align='center'>"; - // Show it is locket - $modules_using_plugin = db_get_value_filter( - 'count(*)', - 'tagente_modulo', - [ - 'delete_pending' => 0, - 'id_plugin' => $row['id'], - ] - ); - $components_using_plugin = db_get_value_filter( - 'count(*)', - 'tnetwork_component', - ['id_plugin' => $row['id']] - ); - if (($components_using_plugin + $modules_using_plugin) > 0) { - echo '<a href="javascript: show_locked_dialog('.$row['id'].', \''.$row['name'].'\');">'; - html_print_image('images/lock.png'); - echo '</a>'; + // Show it is locket + $modules_using_plugin = db_get_value_filter( + 'count(*)', + 'tagente_modulo', + [ + 'delete_pending' => 0, + 'id_plugin' => $row['id'], + ] + ); + $components_using_plugin = db_get_value_filter( + 'count(*)', + 'tnetwork_component', + ['id_plugin' => $row['id']] + ); + if (($components_using_plugin + $modules_using_plugin) > 0) { + echo '<a href="javascript: show_locked_dialog('.$row['id'].', \''.$row['name'].'\');">'; + html_print_image('images/lock.png'); + echo '</a>'; + } + + echo "<a href='index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&view=".$row['id'].'&tab=plugins&pure='.$config['pure']."'>".html_print_image('images/config.png', true, ['title' => __('Edit')]).'</a>  '; + echo "<a href='index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&kill_plugin=".$row['id'].'&tab=plugins&pure='.$config['pure']."' onclick='javascript: if (!confirm(\"".__('All the modules that are using this plugin will be deleted').'. '.__('Are you sure?')."\")) return false;'>".html_print_image('images/cross.png', true, ['border' => '0']).'</a>'; + if (is_metaconsole()) { + echo "   <a href='index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&deploy_plugin=".$row['id'].'&tab=plugins&pure='.$config['pure']."'>".html_print_image('images/deploy.png', true, ['title' => __('Deploy'), 'width' => '21 px']).'</a>  '; + } + + echo '</td>'; } - echo "<a href='index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&view=".$row['id'].'&tab=plugins&pure='.$config['pure']."'>".html_print_image('images/config.png', true, ['title' => __('Edit')]).'</a>  '; - echo "<a href='index.php?sec=$sec&sec2=godmode/servers/plugin&tab=$tab&kill_plugin=".$row['id'].'&tab=plugins&pure='.$config['pure']."' onclick='javascript: if (!confirm(\"".__('All the modules that are using this plugin will be deleted').'. '.__('Are you sure?')."\")) return false;'>".html_print_image('images/cross.png', true, ['border' => '0']).'</a>'; - echo '</td>'; echo '</tr>'; } @@ -813,12 +1031,15 @@ if (($create != '') or ($view != '')) { ui_print_info_message(['no_close' => true, 'message' => __('There are no plugins in the system') ]); } - echo "<table width='100%'>"; + if ($management_allowed) { + echo "<table width='100%'>"; - echo '<tr><td align=right>'; - echo "<form name=plugin method='post' action='index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&create=1&pure=".$config['pure']."'>"; - echo "<input name='crtbutton' type='submit' class='sub next' value='".__('Add')."'>"; - echo '</td></tr></table>'; + echo '<tr><td align=right>'; + echo "<form name=plugin method='post' action='index.php?sec=gservers&sec2=godmode/servers/plugin&tab=$tab&create=1&pure=".$config['pure']."'>"; + echo "<input name='crtbutton' type='submit' class='sub next' value='".__('Add')."'>"; + echo '</td></tr></table>'; + echo '<div id="deploy_messages" style="display: none">'; + } // The '%s' will be replaced in the javascript code of the function 'show_locked_dialog' echo "<div id='dialog_locked' title='".__('List of modules and components created by "%s" ')."' style='display: none; text-align: left;'>"; @@ -828,7 +1049,6 @@ if (($create != '') or ($view != '')) { } ui_require_javascript_file('pandora_modules'); - ?> <script type="text/javascript"> From 67e53bf7a7894006b5e06dccd135e634b16b34e0 Mon Sep 17 00:00:00 2001 From: alejandro-campos <alejandro.campos@artica.es> Date: Mon, 25 Feb 2019 16:15:17 +0100 Subject: [PATCH 07/25] add new way of importing css for treeview Former-commit-id: d88bb38ac7d20ab5f554cfb1399b17ddf6f62fb2 --- pandora_console/include/styles/pandora.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 180c187db0..70a9c4920e 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -21,8 +21,8 @@ Description: The default Pandora FMS theme layout */ /* Tree view styles */ -@import url(tree.css); -@import url(fixed-bottom-box.css); +/*@import url(tree.css); +@import url(fixed-bottom-box.css);*/ /* * --------------------------------------------------------------------- From db5d2ceee142a2154e6a2a3b747cbd9e5e08edbe Mon Sep 17 00:00:00 2001 From: alejandro-campos <alejandro.campos@artica.es> Date: Mon, 25 Feb 2019 17:04:07 +0100 Subject: [PATCH 08/25] fix bad routes in services treeview Former-commit-id: 27bfcca5a7e0f7c3929e2a1f449c0f1d318891c9 --- pandora_console/include/class/TreeService.class.php | 4 ++-- .../include/javascript/tree/TreeController.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index bbddc8dc2a..d211cd1055 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -161,7 +161,7 @@ class TreeService extends Tree { $services[$service['id']]['counters'] = array('total_services'=>$service['total_services'], 'total_agents'=>$service['total_agents'], 'total_modules'=>$service['total_modules']); $services[$service['id']]['name'] = $service['name']; $services[$service['id']]['id'] = $service['id']; - $services[$service['id']]['serviceDetail']='http://localhost/pandora_console/index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; + $services[$service['id']]['serviceDetail']='index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; } return $services; @@ -241,7 +241,7 @@ class TreeService extends Tree { $service_stats[$service['id']]['rootType'] = $service['rootType']; $service_stats[$service['id']]['type'] = 'services'; $service_stats[$service['id']]['children']=array(); - $service_stats[$service['id']]['serviceDetail']='http://localhost/pandora_console/index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; + $service_stats[$service['id']]['serviceDetail']='index.php?sec=network&sec2=enterprise/operation/services/services&tab=service_map&id_service='.(int)$service['id']; $service_stats[$service['id']]['counters']=array('total_services'=>$service['total_services'], 'total_agents'=>$service['total_agents'], 'total_modules'=>$service['total_modules']); } diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 3fab4f6dab..3e177f3ae9 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -523,7 +523,8 @@ var TreeController = { if (typeof element.eventAgent != 'undefined') { $content.append('<form method="post" id="hiddenAgentsEventsForm-'+element.eventAgent+'" style="display: none;" action="index.php?sec=eventos&sec2=operation/events/events&refr=0&pure=§ion=list&history=0"><input type="hidden" name="id_agent" value="'+element.eventAgent+'"></form>'); - var $eventImage = $('<img src="images/tree_events.png" />'); + var $eventImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/tree_events.png" /> '); $eventImage.addClass("agent-alerts-fired"); $eventImage .click(function (e) { @@ -550,7 +551,8 @@ var TreeController = { } - var $serviceDetailImage = $('<img src="images/tree_service_map.png" />'); + var $serviceDetailImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/tree_service_map.png" /> '); if (typeof element.serviceDetail != 'undefined') { @@ -585,7 +587,8 @@ var TreeController = { if (typeof element.eventModule != 'undefined') { $content.append('<form method="post" id="hiddenModulesEventsForm-'+element.eventModule+'" style="display: none;" action="index.php?sec=eventos&sec2=operation/events/events&refr=0&pure=§ion=list&history=0"><input type="hidden" name="module_search_hidden" value="'+element.eventModule+'"></form>'); - var $moduleImage = $('<img src="images/tree_events.png" />'); + var $moduleImage = $('<img src="'+(controller.baseURL.length > 0 ? controller.baseURL : '') + +'images/tree_events.png" /> '); $moduleImage .click(function (e) { e.preventDefault(); From d4c46ec14f12359aaf1d31dbbb7a3626d6c1b8d5 Mon Sep 17 00:00:00 2001 From: daniel <daniel.barbero@artica.es> Date: Tue, 26 Feb 2019 08:44:50 +0100 Subject: [PATCH 09/25] fix minor error Former-commit-id: 81b5c41c49a5e121c5ac34c12bfd5b1b7f5f943a --- pandora_console/include/functions_config.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 475ef2db79..ce69858132 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -755,6 +755,10 @@ function config_update_config() if (!config_update_value('max_graph_container', get_parameter('max_graph_container'))) { $error_update[] = __('Graph container - Max. Items'); } + + if (!config_update_value('max_execution_event_response', get_parameter('max_execution_event_response'))) { + $error_update[] = __('Max execution event response'); + } break; case 'vis': @@ -1547,6 +1551,10 @@ function config_process_config() config_update_value('max_graph_container', 10); } + if (!isset($config['max_execution_event_response'])) { + config_update_value('max_execution_event_response', 10); + } + if (!isset($config['max_macro_fields'])) { config_update_value('max_macro_fields', 10); } From c38ac4b837aaa8ecb2a1a3de489889243ef8864e Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 10:34:37 +0100 Subject: [PATCH 10/25] Updated breadcrum Former-commit-id: 51c14ea50e6c7d419d610ef1b52c4769214495ef --- pandora_console/godmode/wizards/HostDevices.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 6e31299b9a..aa5c94666c 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -476,6 +476,10 @@ class HostDevices extends Wizard $task_url = '&task='.$this->task['id_rt']; } + $breadcrum[] = [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd', + 'label' => __($this->label), + ]; for ($i = 0; $i < $this->maxPagesNetScan; $i++) { $breadcrum[] = [ 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd&mode=netscan&page='.$i.$task_url, @@ -710,9 +714,6 @@ $("select#interval_manual_defined").change(function() { // XXX: Could be improved validating inputs before continue (JS) // Print NetScan page 0. $this->printForm($form); - $this->printGoBackButton( - $this->url.'&page='.($this->page - 1).$task_url - ); } } From 45419fbfb0f9e6ab2bab62c32b7e889b58b6d95b Mon Sep 17 00:00:00 2001 From: Daniel Maya <daniel.maya@artica.es> Date: Tue, 26 Feb 2019 12:23:46 +0100 Subject: [PATCH 11/25] Fixed href in plugins with centralized node Former-commit-id: 03fa2c15b7a9fb14cdc12499c3bc2a204bae3cd5 --- pandora_console/godmode/servers/plugin.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index fcb34363f0..4380f3ba31 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -634,9 +634,8 @@ if (($create != '') || ($view != '')) { } - // Update plugin + // Update plugin. if (isset($_GET['update_plugin'])) { - // if modified any parameter $plugin_id = get_parameter('update_plugin', 0); $plugin_name = get_parameter('form_name', ''); $plugin_description = get_parameter('form_description', ''); @@ -978,7 +977,10 @@ if (($create != '') || ($view != '')) { echo '<tr>'; echo "<td class=$tdcolor>"; - echo "<b><a href='index.php?sec=$sec&sec2=godmode/servers/plugin&view=".$row['id'].'&tab=plugins&pure='.$config['pure']."'>"; + if ($management_allowed) { + echo "<b><a href='index.php?sec=$sec&sec2=godmode/servers/plugin&view=".$row['id'].'&tab=plugins&pure='.$config['pure']."'>"; + } + echo $row['name']; echo '</a></b></td>'; echo "<td class=$tdcolor>"; From 7791639b3545145dd9cd2a137dc93d76dd73cb67 Mon Sep 17 00:00:00 2001 From: alejandro-campos <alejandro.campos@artica.es> Date: Tue, 26 Feb 2019 13:31:35 +0100 Subject: [PATCH 12/25] fix bad image routes Former-commit-id: 236701131f5c2f5b11c01b878d8a04b71f76ddd3 --- .../include/class/TreeService.class.php | 24 +++++++++---------- .../include/javascript/tree/TreeController.js | 14 ++++++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index d211cd1055..b55643219d 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -91,20 +91,20 @@ class TreeService extends Tree { switch ($status) { case SERVICE_STATUS_NORMAL: - $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + $processed_items[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; break; case SERVICE_STATUS_CRITICAL: - $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + $processed_items[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; break; case SERVICE_STATUS_WARNING: - $processed_items[$row['id']][$key]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + $processed_items[$row['id']][$key]['statusImageHTML']='<img src="images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; break; case SERVICE_STATUS_UNKNOWN: default: - $processed_items[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + $processed_items[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; break; } } @@ -201,16 +201,16 @@ class TreeService extends Tree { foreach ($data_modules as $key => $module) { switch ($module['estado']) { case '0': - $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + $data_modules[$key]['statusImageHTML'] = '<img src="images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; break; case '1': - $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + $data_modules[$key]['statusImageHTML'] = '<img src="images/status_sets/default/agent_critical_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; break; case '2': - $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + $data_modules[$key]['statusImageHTML'] = '<img src="images/status_sets/default/agent_warning_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; break; case '4': - $data_modules[$key]['statusImageHTML'] = '<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + $data_modules[$key]['statusImageHTML'] = '<img src="images/status_sets/default/agent_no_data_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; break; default: # code... @@ -267,20 +267,20 @@ class TreeService extends Tree { switch ($status) { case SERVICE_STATUS_NORMAL: - $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; + $service_stats[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_ok_ball.png" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />'; break; case SERVICE_STATUS_CRITICAL: - $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; + $service_stats[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_critical_ball.png" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />'; break; case SERVICE_STATUS_WARNING: - $service_stats[$row['id']][$key]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; + $service_stats[$row['id']][$key]['statusImageHTML']='<img src="images/status_sets/default/agent_warning_ball.png" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />'; break; case SERVICE_STATUS_UNKNOWN: default: - $service_stats[$row['id']]['statusImageHTML']='<img src="http://localhost/pandora_console/images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; + $service_stats[$row['id']]['statusImageHTML']='<img src="images/status_sets/default/agent_no_data_ball.png" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />'; break; } } diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 3e177f3ae9..04e67e670b 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -931,12 +931,14 @@ var TreeController = { } controller.recipient.empty(); - controller.recipient.html( - "<div> " + - controller.foundMessage + ": " + controller.tree.length + - "</div>" + - "<br/>" - ); + if (controller.tree.length !== undefined) { + controller.recipient.html( + "<div> " + + controller.foundMessage + ": " + controller.tree.length + + "</div>" + + "<br/>" + ); + } var $children = _processGroup(this.recipient, this.tree, true); $children.show(); From 2c0c05050768424c081ac1451efe426c9a7d30af Mon Sep 17 00:00:00 2001 From: Daniel Maya <daniel.maya@artica.es> Date: Tue, 26 Feb 2019 17:20:23 +0100 Subject: [PATCH 13/25] Disabled cache in server plugin synchronization Former-commit-id: c8d60db8aece2db8611ee7d8ac44347f661d9b83 --- pandora_console/godmode/servers/plugin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 4380f3ba31..b04643e1c3 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -827,12 +827,12 @@ if (($create != '') || ($view != '')) { // recorremos todos los nodos. foreach ($setup as $key => $value) { // Obtenemos los plugins de la meta. - $all_plugin_meta = db_get_all_rows_in_table('tplugin'); + $all_plugin_meta = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); // Conectamos con el nodo. if (metaconsole_connect($value) == NOERR) { $values = []; // Obtenemos los plugin del nodo. - $node_plugin_server = db_get_all_rows_in_table('tplugin'); + $node_plugin_server = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); foreach ($node_plugin_server as $key2 => $plugin) { // Comprobamos si el id esta meta y nodo al mismo tiempo. $key_exists = array_search($plugin['id'], array_column($all_plugin_meta, 'id')); @@ -896,11 +896,11 @@ if (($create != '') || ($view != '')) { } } - $all_plugin_meta = db_get_all_rows_in_table('tplugin'); + $all_plugin_meta = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); foreach ($setup as $key => $value) { if (metaconsole_connect($value) == NOERR) { - $all_plugin_node = db_get_all_rows_in_table('tplugin'); + $all_plugin_node = db_get_all_rows_sql('SELECT SQL_NO_CACHE * FROM tplugin', false, false); $array_diff = array_diff(array_column($all_plugin_meta, 'id'), array_column($all_plugin_node, 'id')); foreach ($array_diff as $key2 => $pluginid) { From 5b3ce095150e4fc7f899ee6e5b885de994aa1d35 Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 17:41:42 +0100 Subject: [PATCH 14/25] Comment updates in wizard class Former-commit-id: 0b820729a631d906fe4816ba74f84f700b500c01 --- .../godmode/wizards/Wizard.main.php | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index c584e6a9b7..708caa4c52 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -1,11 +1,39 @@ <?php - /** - * Interfaz tope gama que obliga a implementar metodos. + * Extension to schedule tasks on Pandora FMS Console + * + * @category Wizard + * @package Pandora FMS + * @subpackage Wizard skel + * @version 1.0.0 + * @license See below + * + * ______ ___ _______ _______ ________ + * | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __| + * | __/| _ | | _ || _ | _| _ | | ___| |__ | + * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| + * + * ============================================================================ + * Copyright (c) 2005-2019 Artica Soluciones Tecnologicas + * Please see http://pandorafms.org for full contribution list + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation for version 2. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ============================================================================ */ define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2'); +/** + * Global Wizard generic class. Needs to be inherited. + * + * Used in Hostdevices class, Applications class and others, is the core of + * Discovery proyect. + */ class Wizard { @@ -17,9 +45,9 @@ class Wizard public $breadcrum; /** - * Undocumented variable + * Current page * - * @var [type] + * @var integer */ public $page; From 5382f07ae2090ad4e7fddc342e8976dcc912badd Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 17:42:12 +0100 Subject: [PATCH 15/25] Comment updates in wizard class Former-commit-id: 9fbb1d0c6499dd1ad71c472970b3993193b581da --- pandora_console/godmode/wizards/Wizard.main.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 708caa4c52..c763e0ff29 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -526,6 +526,8 @@ class Wizard /** * Prints a go back button redirecting to main page. * + * @param string $url Optional target url. + * * @return void */ public function printGoBackButton($url=null) From 0e7c498e1abd6a628f12ea7cf1782729ffb11960 Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 17:53:58 +0100 Subject: [PATCH 16/25] Comment updates Former-commit-id: a711916af981c065d26def1943fc526d936de5d3 --- pandora_console/include/ajax/events.php | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index af05a8c07f..9d327bb540 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -580,7 +580,6 @@ if ($get_extended_event) { dataType : "html", success: function (data) { $("#related_data").html(data); - console.log("vamos puta"); } }); });'; From a8874f9b1b0922f8bc82b713833aa924b143d42b Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 20:00:41 +0100 Subject: [PATCH 17/25] Minor fixes Former-commit-id: c3abb9964c61f0535ab59644f6eb1d0a8328212a --- .../wizards/DiscoveryTaskList.class.php | 888 +++++------------- .../godmode/wizards/HostDevices.class.php | 315 +------ 2 files changed, 246 insertions(+), 957 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 9f7c416854..0daa3d3cd7 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -30,6 +30,7 @@ require_once __DIR__.'/Wizard.main.php'; require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_reports.php'; require_once $config['homedir'].'/include/functions_cron.php'; +enterprise_include('include/functions_tasklist.php'); /** * Defined as wizard to guide user to explore running tasks. @@ -72,6 +73,9 @@ class DiscoveryTaskList extends Wizard /** * Implements run method. * + * @param string $message Redirected input. + * @param boolean $status Redirected input. + * * @return mixed Returns null if wizard is ongoing. Result if done. */ public function run($message='', $status=null) @@ -115,45 +119,41 @@ class DiscoveryTaskList extends Wizard if (enterprise_installed()) { // This check only applies to enterprise users. - // Check if DiscoveryCronTasks is running. Warn user if not. - if ($config['cron_last_run'] == 0 - || (get_system_time() - $config['cron_last_run']) > 3600 - ) { - $message_conf_cron = __('DiscoveryConsoleTasks is not running properly').'. '; - if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { - $message_conf_cron .= __('Discovery relies on a proper setup of cron, the time-based scheduling service'); - $message_conf_cron .= '. '.__('Please, add the following line to your crontab file:'); - $message_conf_cron .= '<b><pre style="color: #333;">* * * * * <user> wget -q -O - --no-check-certificate '; - $message_conf_cron .= str_replace( - ENTERPRISE_DIR.'/meta/', - '', - ui_get_full_url(false) - ); - $message_conf_cron .= ENTERPRISE_DIR.'/'.EXTENSIONS_DIR; - $message_conf_cron .= '/cron/cron.php >> '; - $message_conf_cron .= $config['homedir'].'/pandora_console.log</pre></b>'; - } + enterprise_hook('tasklist_checkrunning'); - if (isset($config['cron_last_run']) === true - && $config['cron_last_run'] > 0 - ) { - $message_conf_cron .= '<p style="color: #333;">'.__('Last execution').': '; - $message_conf_cron .= date('Y/m/d H:i:s', $config['cron_last_run']).'</p>'; - $message_conf_cron .= '<p style="color: #333;">'; - $message_conf_cron .= __('Please check process is no locked.').'</p>'; - } - - ui_print_warning_message($message_conf_cron, '', false); - } + $ret = $this->showListConsoleTask(); + } else { + $ret = false; } - $ret = $this->showListConsoleTask(); $ret2 = $this->showList(); if ($ret === false && $ret2 === false) { include_once $config['homedir'].'/general/firts_task/recon_view.php'; + } else { + $form = [ + 'form' => [ + 'method' => 'POST', + 'action' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + ], + 'inputs' => [ + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go back'), + 'type' => 'submit', + 'attributes' => 'class="sub cancel"', + 'return' => true, + ], + ], + ], + ]; } + $this->printForm($form); + return $ret; } @@ -237,7 +237,7 @@ class DiscoveryTaskList extends Wizard $id_console_task = (int) get_parameter('id_console_task'); if ($id_console_task !== null) { - cron_task_run($id_console_task, true); + enterprise_include('cron_task_run', $id_console_task, true); // Trick to avoid double execution. header('Location: '.$this->url); } @@ -313,255 +313,229 @@ class DiscoveryTaskList extends Wizard ui_print_error_message(__('Discovery Server is disabled')); return false; } else { - $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); - if ($recon_task === false) { - return false; - } else { - include_once $config['homedir'].'/include/functions_graph.php'; - include_once $config['homedir'].'/include/functions_servers.php'; - include_once $config['homedir'].'/include/functions_network_profiles.php'; + include_once $config['homedir'].'/include/functions_graph.php'; + include_once $config['homedir'].'/include/functions_servers.php'; + include_once $config['homedir'].'/include/functions_network_profiles.php'; - $modules_server = 0; - $total_modules = 0; - $total_modules_data = 0; + $modules_server = 0; + $total_modules = 0; + $total_modules_data = 0; - // -------------------------------- - // FORCE A RECON TASK - // -------------------------------- - if (check_acl($config['id_user'], 0, 'PM')) { - if (isset($_GET['force'])) { - $id = (int) get_parameter_get('force', 0); - servers_force_recon_task($id); - header( - 'Location: '.ui_get_full_url( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' + // -------------------------------- + // FORCE A RECON TASK + // -------------------------------- + if (check_acl($config['id_user'], 0, 'PM')) { + if (isset($_GET['force'])) { + $id = (int) get_parameter_get('force', 0); + servers_force_recon_task($id); + header( + 'Location: '.ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' + ) + ); + } + } + + foreach ($servers as $serverItem) { + $id_server = $serverItem['id_server']; + $server_name = servers_get_name($id_server); + $recon_tasks = db_get_all_rows_field_filter( + 'trecon_task', + 'id_recon_server', + $id_server + ); + + $user_groups = implode(',', array_keys(users_get_groups())); + $defined_tasks = db_get_all_rows_filter( + 'tuser_task_scheduled', + 'id_grupo IN ('.$user_groups.')' + ); + + if (isset($tasks_console) === true + && is_array($tasks_console) === true + ) { + foreach ($tasks_console as $key => $value) { + $value['parameters'] = unserialize( + $value['parameters'] + ); + + $value['type'] = 'Cron'; + array_push($recon_tasks, $value); + } + } + + // Show network tasks for Recon Server. + if ($recon_tasks === false) { + $recon_tasks = []; + } + + $table = new StdClass(); + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = '100%'; + $table->class = 'databox data'; + $table->head = []; + $table->data = []; + $table->align = []; + $table->headstyle = []; + for ($i = 0; $i < 9; $i++) { + $table->headstyle[$i] = 'text-align: left;'; + } + + $table->head[0] = __('Force'); + $table->align[0] = 'left'; + + $table->head[1] = __('Task name'); + $table->align[1] = 'left'; + + $table->head[2] = __('Interval'); + $table->align[2] = 'left'; + + $table->head[3] = __('Network'); + $table->align[3] = 'left'; + + $table->head[4] = __('Status'); + $table->align[4] = 'left'; + + $table->head[5] = __('Task type'); + $table->align[5] = 'left'; + + $table->head[6] = __('Progress'); + $table->align[6] = 'left'; + + $table->head[7] = __('Updated at'); + $table->align[7] = 'left'; + + $table->head[8] = __('Operations'); + $table->align[8] = 'left'; + + foreach ($recon_tasks as $task) { + $data = []; + + if ($task['disabled'] == 0) { + $data[0] = '<a href="'.ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$id_server.'&force='.$task['id_rt'] + ).'">'; + $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); + $data[0] .= '</a>'; + } else if ($task['disabled'] == 2) { + $data[0] = ui_print_help_tip( + __('This task has not been completely defined, please edit it'), + true + ); + } else { + $data[0] = ''; + } + + $data[1] = '<b>'.$task['name'].'</b>'; + + if ($task['interval_sweep'] > 0) { + $data[2] = human_time_description_raw( + $task['interval_sweep'] + ); + } else { + $data[2] = __('Manual'); + } + + if ($task['id_recon_script'] == 0) { + $data[3] = $task['subnet']; + } else { + $data[3] = '-'; + } + + if ($task['status'] <= 0) { + $data[4] = __('Done'); + } else { + $data[4] = __('Pending'); + } + + if ($task['id_recon_script'] == 0) { + // Discovery NetScan. + $data[5] = html_print_image( + 'images/network.png', + true, + ['title' => __('Discovery NetScan')] + ).'  '; + $data[5] .= network_profiles_get_name( + $task['id_network_profile'] + ); + } else { + // APP recon task. + $data[5] = html_print_image( + 'images/plugin.png', + true + ).'  '; + $data[5] .= db_get_sql( + sprintf( + 'SELECT name FROM trecon_script WHERE id_recon_script = %d', + $task['id_recon_script'] ) ); } - } - foreach ($servers as $serverItem) { - $id_server = $serverItem['id_server']; - $server_name = servers_get_name($id_server); - $recon_tasks = db_get_all_rows_field_filter( - 'trecon_task', - 'id_recon_server', - $id_server - ); - - $user_groups = implode(',', array_keys(users_get_groups())); - $defined_tasks = db_get_all_rows_filter( - 'tuser_task_scheduled', - 'id_grupo IN ('.$user_groups.')' - ); - - if (isset($tasks_console) === true - && is_array($tasks_console) === true - ) { - foreach ($tasks_console as $key => $value) { - $value['parameters'] = unserialize( - $value['parameters'] - ); - - $value['type'] = 'Cron'; - array_push($recon_tasks, $value); - } - } - - // Show network tasks for Recon Server. - if ($recon_tasks === false) { - $recon_tasks = []; - } - - $table = new StdClass(); - $table->cellpadding = 4; - $table->cellspacing = 4; - $table->width = '100%'; - $table->class = 'databox data'; - $table->head = []; - $table->data = []; - $table->align = []; - $table->headstyle = []; - for ($i = 0; $i < 9; $i++) { - $table->headstyle[$i] = 'text-align: left;'; - } - - $table->head[0] = __('Force'); - $table->align[0] = 'left'; - - $table->head[1] = __('Task name'); - $table->align[1] = 'left'; - - $table->head[2] = __('Interval'); - $table->align[2] = 'left'; - - $table->head[3] = __('Network'); - $table->align[3] = 'left'; - - $table->head[4] = __('Status'); - $table->align[4] = 'left'; - - $table->head[5] = __('Task type'); - $table->align[5] = 'left'; - - $table->head[6] = __('Progress'); - $table->align[6] = 'left'; - - $table->head[7] = __('Updated at'); - $table->align[7] = 'left'; - - $table->head[8] = __('Operations'); - $table->align[8] = 'left'; - - foreach ($recon_tasks as $task) { - $data = []; - - if ($task['disabled'] == 0) { - $data[0] = '<a href="'.ui_get_full_url( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$id_server.'&force='.$task['id_rt'] - ).'">'; - $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); - $data[0] .= '</a>'; - } else if ($task['disabled'] == 2) { - $data[0] = ui_print_help_tip( - __('This task has not been completely defined, please edit it'), - true - ); - } else { - $data[0] = ''; - } - - $data[1] = '<b>'.$task['name'].'</b>'; - - if ($task['interval_sweep'] > 0) { - $data[2] = human_time_description_raw( - $task['interval_sweep'] - ); - } else { - $data[2] = __('Manual'); - } - - if ($task['id_recon_script'] == 0) { - $data[3] = $task['subnet']; - } else { - $data[3] = '-'; - } - - if ($task['status'] <= 0) { - $data[4] = __('Done'); - } else { - $data[4] = __('Pending'); - } - - if ($task['id_recon_script'] == 0) { - // Discovery NetScan. - $data[5] = html_print_image( - 'images/network.png', - true, - ['title' => __('Discovery NetScan')] - ).'  '; - $data[5] .= network_profiles_get_name( - $task['id_network_profile'] - ); - } else { - // APP recon task. - $data[5] = html_print_image( - 'images/plugin.png', - true - ).'  '; - $data[5] .= db_get_sql( - sprintf( - 'SELECT name FROM trecon_script WHERE id_recon_script = %d', - $task['id_recon_script'] - ) - ); - } - - if ($task['status'] <= 0 || $task['status'] > 100) { - $data[6] = '-'; - } else { - $data[6] = progress_bar( - $task['status'], - 100, - 20, - __('Progress').':'.$task['status'].'%', - 1 - ); - } - - if ($task['utimestamp'] > 0) { - $data[7] = ui_print_timestamp( - $task['utimestamp'], - true - ); - } else { - $data[7] = __('Not executed yet'); - } - - if (check_acl( - $config['id_user'], - $task['id_group'], - 'PM' - ) - ) { - // Check if is a H&D, Cloud or Application. - $data[8] = '<a href="'.ui_get_full_url( - sprintf( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', - $this->getTargetWiz($task), - $task['id_rt'] - ) - ).'">'.html_print_image( - 'images/config.png', - true - ).'</a>'; - $data[8] .= '<a href="'.ui_get_full_url( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&delete=1&task='.$task['id_rt'] - ).'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'.html_print_image( - 'images/cross.png', - true - ).'</a>'; - } else { - $data[8] = ''; - } - - array_push($table->data, $data); - } - - if (empty($table->data)) { - echo '<div class="nf">'.__('Server').' '.$server_name.' '.__('has no recon tasks assigned').'</div>'; + if ($task['status'] <= 0 || $task['status'] > 100) { + $data[6] = '-'; } else { - echo '<h2>'.__('Server task').'</h2>'; - html_print_table($table); + $data[6] = progress_bar( + $task['status'], + 100, + 20, + __('Progress').':'.$task['status'].'%', + 1 + ); } - unset($table); + if ($task['utimestamp'] > 0) { + $data[7] = ui_print_timestamp( + $task['utimestamp'], + true + ); + } else { + $data[7] = __('Not executed yet'); + } + + if (check_acl( + $config['id_user'], + $task['id_group'], + 'PM' + ) + ) { + // Check if is a H&D, Cloud or Application. + $data[8] = '<a href="'.ui_get_full_url( + sprintf( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', + $this->getTargetWiz($task), + $task['id_rt'] + ) + ).'">'.html_print_image( + 'images/config.png', + true + ).'</a>'; + $data[8] .= '<a href="'.ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&delete=1&task='.$task['id_rt'] + ).'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'.html_print_image( + 'images/cross.png', + true + ).'</a>'; + } else { + $data[8] = ''; + } + + array_push($table->data, $data); } + + echo '<h2>'.__('Server tasks').'</h2>'; + if (empty($table->data)) { + echo '<div class="nf">'.__('Server').' '.$server_name.' '.__('has no discovery tasks assigned').'</div>'; + return false; + } else { + html_print_table($table); + } + + unset($table); } } - $form = [ - 'form' => [ - 'method' => 'POST', - 'action' => ui_get_full_url( - 'index.php?sec=gservers&sec2=godmode/servers/discovery' - ), - ], - 'inputs' => [ - [ - 'arguments' => [ - 'name' => 'submit', - 'label' => __('Go back'), - 'type' => 'submit', - 'attributes' => 'class="sub cancel"', - 'return' => true, - ], - ], - ], - ]; - - $this->printForm($form); - return true; } @@ -573,385 +547,7 @@ class DiscoveryTaskList extends Wizard */ public function showListConsoleTask() { - global $config; - - check_login(); - - if (! check_acl($config['id_user'], 0, 'PM')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access recon task viewer' - ); - include 'general/noaccess.php'; - return false; - } - - $read_perms = check_acl( - $config['id_user'], - 0, - 'RR' - ); - $write_perms = check_acl( - $config['id_user'], - 0, - 'RW' - ); - $manage_perms = check_acl( - $config['id_user'], - 0, - 'RM' - ); - $manage_pandora = check_acl( - $config['id_user'], - 0, - 'PM' - ); - - $url = 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&'; - - $user_groups = implode( - ',', - array_keys(users_get_groups()) - ); - - $defined_tasks = db_get_all_rows_filter( - 'tuser_task_scheduled', - 'id_grupo IN ('.$user_groups.')' - ); - - if (!check_acl($config['id_user'], 0, 'PM')) { - $read_tasks = []; - foreach ($defined_tasks as $task) { - $function_name = db_get_value( - 'function_name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - if (($function_name != 'cron_task_execute_custom_script') - && ($function_name != 'cron_task_do_backup') - ) { - $read_tasks[] = $task; - } - } - - $defined_tasks = $read_tasks; - - if (empty($defined_tasks)) { - $defined_tasks = false; - } - } - - if ($defined_tasks !== false) { - echo '<h2>'.__('Console task').'</h2>'; - - $table = new stdClass(); - $table->class = 'databox data'; - $table->width = '100%'; - $table->data = []; - $table->head = []; - $table->head[0] = ''; - $table->head[1] = __('User'); - $table->head[2] = __('Task'); - $table->head[3] = __('Scheduled'); - $table->head[4] = __('Next execution'); - $table->head[5] = __('Last run'); - $table->head[6] = __('Group'); - $table->head[7] = __('Operations'); - $table->align[7] = 'left'; - - foreach ($defined_tasks as $task) { - $data = []; - - $function_name = db_get_value( - 'function_name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - switch ($function_name) { - case 'cron_task_generate_report': - if ($write_perms || $manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - $args = unserialize($task['args']); - $report = reports_get_report($args[0]); - - // Check ACL in reports_get_report return false. - if ($report === false) { - continue; - } - - $email = $args[1]; - $data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=".$args[0]."'>"; - $data[2] .= $report['name'].'</a>'; - $data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>"; - $data[2] .= ui_print_truncate_text( - $email, - 60, - false - ).'</a>'; - break; - - case 'cron_task_generate_report_by_template': - if ($write_perms || $manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - $args = unserialize($task['args']); - - $filter = []; - $filter['id_report'] = $args[0]; - $template = db_get_row_filter( - 'treport_template', - $filter, - false - ); - - // Check ACL in reports_get_report return false. - if ($template === false) { - continue; - } - - $agents_id = $args[1]; - $id_group = $args[2]; - $report_per_agent = $args[0]; - $report_name = $args[3]; - $email = $args[4]; - $data[2] .= '<br>- '.__('Template').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer"; - $data[2] .= '&id='.$args[0]."'>".$template['name'].'</a>'; - $data[2] .= '<br>- '.__('Agents').': '.$agents_id.'</a>'; - $data[2] .= '<br>- '.__('Report per agent').': '.$report_per_agent.'</a>'; - $data[2] .= '<br>- '.__('Report name').': '.$report_name.'</a>'; - $data[2] .= '<br>- '.__('Email').": <a href='mailto:".$email."'>".$email.'</a>'; - break; - - case 'cron_task_execute_custom_script': - if ($manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - $args = unserialize($task['args']); - $data[2] .= '<br>- '.__('Custom script').': '.$args[0]; - break; - - case 'cron_task_save_report_to_disk': - if ($write_perms || $manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - - $args = unserialize($task['args']); - $report = reports_get_report($args[0]); - - // Check ACL in reports_get_report return false. - if ($report === false) { - continue; - } - - $path = $args[1]; - $data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer"; - $data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>'; - $data[2] .= '<br>- '.__('Path').': '.$path.'</a>'; - break; - - case 'cron_task_save_xml_report_to_disk': - if ($write_perms || $manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value('name', 'tuser_task', 'id', $task['id_user_task']); - $args = unserialize($task['args']); - $report = reports_get_report($args[0]); - - // Check ACL in reports_get_report return false. - if ($report === false) { - continue; - } - - $path = $args[1]; - $data[2] .= '<br>- '.__('Report').": <a href='index.php?sec=reporting&sec2=operation/reporting/reporting_viewer"; - $data[2] .= '&id='.$args[0]."'>".$report['name'].'</a>'; - $data[2] .= '<br>- '.__('Path').': '.$path.'</a>'; - break; - - case 'cron_task_do_backup': - if ($manage_pandora) { - $data[0] = '<a href="'.$url; - $data[0] .= 'force_run=1&id_console_task='.$task['id'].'">'; - $data[0] .= html_print_image( - 'images/target.png', - true, - ['title' => __('Force run')] - ); - $data[0] .= '</a>'; - } else { - $data[0] = ''; - } - - $data[1] = $task['id_usuario']; - $data[2] = db_get_value( - 'name', - 'tuser_task', - 'id', - $task['id_user_task'] - ); - $args = unserialize($task['args']); - break; - - default: - // Ignore. - break; - } - - $data[3] = cron_get_scheduled_string($task['scheduled']); - $data[4] = date('Y/m/d H:i:s', $args['first_execution']); - $data[5] = empty($task['last_run']) ? __('Never') : date('Y/m/d H:i:s', $task['last_run']); - - $data[6] = ui_print_group_icon($task['id_grupo'], true); - - if ($function_name == 'cron_task_do_backup' || $function_name == 'cron_task_execute_custom_script') { - if ($manage_pandora) { - $data[7] = '<a href="'.ui_get_full_url( - sprintf( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', - $this->getTargetWiz(['description' => 'console_task']), - $task['id'] - ) - ).'">'; - $data[7] .= html_print_image( - 'images/config.png', - true, - ['title' => __('Edit')] - ).'</a>'; - } - - if ($manage_pandora) { - $data[7] .= '<a href="'.$url; - $data[7] .= 'delete_console_task=1&id_console_task='.$task['id'].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'; - $data[7] .= html_print_image( - 'images/cross.png', - true, - ['title' => __('Delete')] - ); - $data[7] .= '</a>'; - } - } else { - if ($write_perms || $manage_pandora) { - $data[7] = '<a href="'.ui_get_full_url( - sprintf( - 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', - $this->getTargetWiz(['description' => 'console_task']), - $task['id'] - ) - ).'">'; - $data[7] .= html_print_image( - 'images/config.png', - true, - ['title' => __('Edit')] - ).'</a>'; - } - - if ($manage_perms || $manage_pandora) { - $data[7] .= '<a href="'.$url; - $data[7] .= 'delete_console_task=1&id_console_task='.$task['id'].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">'; - $data[7] .= html_print_image( - 'images/cross.png', - true, - ['title' => __('Delete')] - ); - $data[7] .= '</a>'; - } - } - - array_push($table->data, $data); - } - - html_print_table($table); - } else { - return false; - } - - return true; + return enterprise_hook('tasklist_showListConsoleTask', [$this]); } diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index aa5c94666c..1626b1db0b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -780,266 +780,10 @@ $("select#interval_manual_defined").change(function() { ]; } - // Feature configuration. - // Input: SNMP enabled. - $form['inputs'][] = [ - 'label' => __('SNMP enabled'), - 'arguments' => [ - 'name' => 'snmp_enabled', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['snmp_enabled'])) ? $this->task['snmp_enabled'] : 1, - 'onclick' => 'extraSNMP();', - - ], - ]; - - // SNMP CONFIGURATION. - $form['inputs'][] = [ - 'hidden' => 1, - 'block_id' => 'snmp_extra', - 'block_content' => [ - [ - 'label' => __('SNMP version'), - 'arguments' => [ - 'name' => 'snmp_version', - 'fields' => [ - '1' => 'v. 1', - '2c' => 'v. 2c', - '3' => 'v. 3', - ], - 'type' => 'select', - 'script' => 'SNMPExtraShow(this.value)', - 'selected' => $this->task['snmp_version'], - 'return' => true, - ], - ], - ], - ]; - - // SNMP Options pack v1. - $form['inputs'][] = [ - 'hidden' => 1, - 'block_id' => 'snmp_options_basic', - 'block_content' => [ - [ - 'label' => '<b>'.__('SNMP Default community').'</b>'.ui_print_help_tip( - __( - 'You can specify several values, separated by commas, for example: public,mysecret,1234' - ), - true - ), - 'arguments' => [ - 'name' => 'community', - 'type' => 'text', - 'value' => $this->task['snmp_community'], - 'size' => 25, - 'return' => true, - - ], - ], - ], - ]; - - // SNMP Options pack v3. - $form['inputs'][] = [ - 'hidden' => 1, - 'block_id' => 'snmp_options_v3', - 'block_content' => [ - [ - 'label' => '<b>'.__('Context').'</b>', - 'arguments' => [ - 'name' => 'snmp_context', - 'type' => 'text', - 'value' => $this->task['snmp_community'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Auth user').'</b>', - 'arguments' => [ - 'name' => 'snmp_auth_user', - 'type' => 'text', - 'value' => $this->task['snmp_auth_user'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Auth password').'</b>'.ui_print_help_tip( - __( - 'The pass length must be eight character minimum.' - ), - true - ), - 'arguments' => [ - 'name' => 'snmp_auth_pass', - 'type' => 'password', - 'value' => $this->task['snmp_auth_pass'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Privacy method').'</b>', - 'arguments' => [ - 'name' => 'snmp_privacy_method', - 'type' => 'select', - 'fields' => [ - 'DES' => __('DES'), - 'AES' => __('AES'), - ], - 'selected' => $this->task['snmp_privacy_method'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Privacy pass').'</b>'.ui_print_help_tip( - __( - 'The pass length must be eight character minimum.' - ), - true - ), - 'arguments' => [ - 'name' => 'snmp_privacy_pass', - 'type' => 'password', - 'value' => $this->task['snmp_privacy_pass'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Auth method').'</b>', - 'arguments' => [ - 'name' => 'snmp_auth_method', - 'type' => 'select', - 'fields' => [ - 'MD5' => __('MD5'), - 'SHA' => __('SHA'), - ], - 'selected' => $this->task['snmp_auth_method'], - 'size' => 15, - 'return' => true, - - ], - ], - [ - 'label' => '<b>'.__('Security level').'</b>', - 'arguments' => [ - 'name' => 'snmp_security_level', - 'type' => 'select', - 'fields' => [ - 'noAuthNoPriv' => __('Not auth and not privacy method'), - 'authNoPriv' => __('Auth and not privacy method'), - 'authPriv' => __('Auth and privacy method'), - ], - 'selected' => $this->task['snmp_security_level'], - 'size' => 15, - 'return' => true, - - ], - ], - - ], - ]; - - // Input: WMI enabled. - $form['inputs'][] = [ - 'label' => __('WMI enabled'), - 'arguments' => [ - 'name' => 'wmi_enabled', - 'type' => 'switch', - 'value' => (isset($this->task['wmi_enabled'])) ? $this->task['wmi_enabled'] : 0, - 'return' => true, - 'onclick' => 'toggleWMI();', - - ], - ]; - - // WMI CONFIGURATION. - $form['inputs'][] = [ - 'block_id' => 'wmi_extra', - 'hidden' => 1, - 'block_content' => [ - [ - 'label' => '<b>'.__('WMI Auth. strings').'</b>'.ui_print_help_tip( - __( - 'Auth strings must be defined as user%pass, comma separated as many you need.' - ), - true - ), - 'arguments' => [ - 'name' => 'auth_strings', - 'type' => 'text', - 'value' => $this->task['auth_strings'], - 'return' => true, - ], - ], - ], - ]; - - // Input: Enforce os detection. - $form['inputs'][] = [ - 'label' => __('OS detection'), - 'arguments' => [ - 'name' => 'os_detect', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['os_detect'])) ? $this->task['os_detect'] : 1, - - ], - ]; - - // Input: Name resolution. - $form['inputs'][] = [ - 'label' => __('Name resolution'), - 'arguments' => [ - 'name' => 'resolve_names', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['resolve_names'])) ? $this->task['resolve_names'] : 0, - ], - ]; - - // Input: Parent detection. - $form['inputs'][] = [ - 'label' => __('Parent detection'), - 'arguments' => [ - 'name' => 'parent_detection', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['parent_detection'])) ? $this->task['parent_detection'] : 1, - ], - ]; - - // Input: Parent recursion. - $form['inputs'][] = [ - 'label' => __('Parent recursion'), - 'arguments' => [ - 'name' => 'parent_recursion', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['parent_recursion'])) ? $this->task['parent_recursion'] : 1, - ], - ]; - - // Input: VLAN enabled. - $form['inputs'][] = [ - 'label' => __('VLAN enabled'), - 'arguments' => [ - 'name' => 'vlan_enabled', - 'type' => 'switch', - 'return' => true, - 'value' => (isset($this->task['vlan_enabled'])) ? $this->task['vlan_enabled'] : 1, - ], - ]; + if (enterprise_installed()) { + // Feature configuration. + enterprise_require('include/hostdevices_extra.php'); + } // Submit button. $form['inputs'][] = [ @@ -1052,57 +796,6 @@ $("select#interval_manual_defined").change(function() { ], ]; - $form['js'] = ' -function SNMPExtraShow(target) { - $("#snmp_options_basic").hide(); - $("#snmp_options_v3").hide(); - if (document.getElementsByName("snmp_enabled")[0].checked) { - $("#snmp_extra").show(); - if (target == 3) { - $("#snmp_options_v3").show(); - } else { - $("#snmp_options_basic").show(); - } - } - -} - -function extraSNMP() { - if (document.getElementsByName("snmp_enabled")[0].checked) { - SNMPExtraShow($("#snmp_version").val()); - $("#snmp_extra").show(); - } else { - // Hide unusable sections - $("#snmp_extra").hide(); - $("#snmp_options_basic").hide(); - $("#snmp_options_v3").hide(); - - // Disable snmp dependant checks - if (document.getElementsByName("parent_recursion")[0].checked) - $("input[name=parent_recursion]").click(); - - if (document.getElementsByName("parent_detection")[0].checked) - $("input[name=parent_detection]").click(); - - if (document.getElementsByName("vlan_enabled")[0].checked) - $("input[name=vlan_enabled]").click(); - - } -} - -function toggleWMI() { - if (document.getElementsByName("wmi_enabled")[0].checked) - $("#wmi_extra").show(); - else - $("#wmi_extra").hide(); -} - -$(function() { - SNMPExtraShow($("#snmp_version").val()); - toggleWMI(); -}); - '; - $form['form'] = [ 'method' => 'POST', 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'], From 24a1adfb9fa293e4d33ef9dc50a52ad17ccb0b20 Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 20:08:01 +0100 Subject: [PATCH 18/25] minor fix Former-commit-id: 6729d11217d0fecb7b64283b6e4d0485b9bdfdc8 --- pandora_console/godmode/wizards/HostDevices.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 1626b1db0b..a1143fad03 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -782,7 +782,7 @@ $("select#interval_manual_defined").change(function() { if (enterprise_installed()) { // Feature configuration. - enterprise_require('include/hostdevices_extra.php'); + enterprise_require_once('include/hostdevices_extra.php'); } // Submit button. From 7ed3252ca5a3afb929b8d0f2fd6308a896647bfa Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Tue, 26 Feb 2019 20:23:52 +0100 Subject: [PATCH 19/25] minor fixes Former-commit-id: 75b33343bed508ff3ff136fa0fedc5d9d8c952be --- .../godmode/wizards/DiscoveryTaskList.class.php | 14 +++++--------- .../godmode/wizards/HostDevices.class.php | 10 +++++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 0daa3d3cd7..144e6e29ee 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -150,9 +150,9 @@ class DiscoveryTaskList extends Wizard ], ], ]; - } - $this->printForm($form); + $this->printForm($form); + } return $ret; } @@ -311,7 +311,8 @@ class DiscoveryTaskList extends Wizard if ($servers === false) { $servers = []; ui_print_error_message(__('Discovery Server is disabled')); - return false; + $check = db_get_all_rows_sql('SELECT * FROM trecon_task'); + return (bool) $check; } else { include_once $config['homedir'].'/include/functions_graph.php'; include_once $config['homedir'].'/include/functions_servers.php'; @@ -339,12 +340,7 @@ class DiscoveryTaskList extends Wizard foreach ($servers as $serverItem) { $id_server = $serverItem['id_server']; $server_name = servers_get_name($id_server); - $recon_tasks = db_get_all_rows_field_filter( - 'trecon_task', - 'id_recon_server', - $id_server - ); - + $recon_tasks = db_get_all_rows_sql('SELECT * FROM trecon_task'); $user_groups = implode(',', array_keys(users_get_groups())); $defined_tasks = db_get_all_rows_filter( 'tuser_task_scheduled', diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index a1143fad03..f405641fde 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -29,6 +29,7 @@ require_once __DIR__.'/Wizard.main.php'; require_once $config['homedir'].'/include/functions_users.php'; enterprise_include('include/class/CSVImportAgents.class.php'); +enterprise_include_once('include/functions_hostdevices.php'); /** * Wizard section Host&devices. @@ -782,7 +783,14 @@ $("select#interval_manual_defined").change(function() { if (enterprise_installed()) { // Feature configuration. - enterprise_require_once('include/hostdevices_extra.php'); + $extra = enterprise_hook('hd_showextrainputs', [$this]); + if (is_array($extra) === true) { + $form['inputs'] = array_merge( + $form['inputs'], + $extra['inputs'] + ); + $form['js'] = $extra['js']; + } } // Submit button. From 65b89f66880123f0ffd51197640b0497a994f1f8 Mon Sep 17 00:00:00 2001 From: artica <artica.devel@gmail.com> Date: Wed, 27 Feb 2019 00:01:47 +0100 Subject: [PATCH 20/25] Auto-updated build strings. Former-commit-id: 59e3d47f8cc8c9fedb86f0ba6fd7fe183cb908b8 --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/unix/pandora_agent_installer | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/pandora_server_installer | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index e9d22f629b..015f306205 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.731-190226 +Version: 7.0NG.731-190227 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 64c13e926e..4e132515b9 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190226" +pandora_version="7.0NG.731-190227" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index bb7d98e310..97b13365d3 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -42,7 +42,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.731'; -use constant AGENT_BUILD => '190226'; +use constant AGENT_BUILD => '190227'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index d4e33903d4..ce3173b9f3 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.731 -%define release 190226 +%define release 190227 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 87436366bb..f5be518e22 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.731 -%define release 190226 +%define release 190227 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 3ff9b6a963..e27ad14333 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.731" -PI_BUILD="190226" +PI_BUILD="190227" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index abdf2e0ce4..3d62982f64 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190226} +{190227} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 01f027089d..8ce589ce8a 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.731(Build 190226)") +#define PANDORA_VERSION ("7.0NG.731(Build 190227)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index cb30f2163d..f54a5ebd36 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.731(Build 190226))" + VALUE "ProductVersion", "(7.0NG.731(Build 190227))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index fe87752dff..8ece3fcc84 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.731-190226 +Version: 7.0NG.731-190227 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 60d17de09e..ea4a0bd5a1 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190226" +pandora_version="7.0NG.731-190227" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 81ddb9f336..3a5efda30b 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC190226'; +$build_version = 'PC190227'; $pandora_version = 'v7.0NG.731'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index ec9414274a..e63f181b52 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -129,7 +129,7 @@ <div style='height: 10px'> <?php $version = '7.0NG.731'; -$build = '190226'; +$build = '190227'; $banner = "v$version Build $build"; error_reporting(0); diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index 5ffa0a60fd..fd3d576780 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.731 -%define release 190226 +%define release 190227 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index 1cc5f88b10..7a03758761 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.731 -%define release 190226 +%define release 190227 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index 52e071fda9..eeb2aa1c00 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.731-190226 +Version: 7.0NG.731-190227 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index 937c46f882..14df936933 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190226" +pandora_version="7.0NG.731-190227" package_cpan=0 package_pandora=1 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 1b1ed03412..6fa0020285 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -45,7 +45,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.731"; -my $pandora_build = "190226"; +my $pandora_build = "190227"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index 41cb56f39b..9413a58f32 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -32,7 +32,7 @@ our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.731"; -my $pandora_build = "190226"; +my $pandora_build = "190227"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 076f19497a..2ce12d8e32 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.731 -%define release 190226 +%define release 190227 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index e3adf2711e..c29be2cabf 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.731 -%define release 190226 +%define release 190227 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 55915d85a0..c59ea4898c 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.731" -PI_BUILD="190226" +PI_BUILD="190227" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index c8eb037f7a..e8f8a43cdd 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.731 PS190226"; +my $version = "7.0NG.731 PS190227"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 33a9c811b8..bcfc3939bd 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.731 PS190226"; +my $version = "7.0NG.731 PS190227"; # save program name for logging my $progname = basename($0); From 26560c734ca93b970ff8f94a77ae35c91cdab000 Mon Sep 17 00:00:00 2001 From: artica <git@artica.es> Date: Wed, 27 Feb 2019 11:25:50 +0100 Subject: [PATCH 21/25] Updated version and build strings. Former-commit-id: 39df6ee0aee9f29c9afb8729f9e95b316ca8cd67 --- pandora_agents/pc/AIX/pandora_agent.conf | 2 +- pandora_agents/pc/FreeBSD/pandora_agent.conf | 2 +- pandora_agents/pc/HP-UX/pandora_agent.conf | 2 +- pandora_agents/pc/Linux/pandora_agent.conf | 2 +- pandora_agents/pc/NT4/pandora_agent.conf | 2 +- pandora_agents/pc/SunOS/pandora_agent.conf | 2 +- pandora_agents/pc/Win32/pandora_agent.conf | 2 +- pandora_agents/shellscript/aix/pandora_agent.conf | 2 +- pandora_agents/shellscript/bsd-ipso/pandora_agent.conf | 2 +- pandora_agents/shellscript/hp-ux/pandora_agent.conf | 2 +- pandora_agents/shellscript/linux/pandora_agent.conf | 2 +- pandora_agents/shellscript/mac_osx/pandora_agent.conf | 2 +- pandora_agents/shellscript/openWRT/pandora_agent.conf | 2 +- pandora_agents/shellscript/solaris/pandora_agent.conf | 2 +- pandora_agents/unix/AIX/pandora_agent.conf | 2 +- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/Darwin/pandora_agent.conf | 2 +- pandora_agents/unix/FreeBSD/pandora_agent.conf | 2 +- pandora_agents/unix/HP-UX/pandora_agent.conf | 2 +- pandora_agents/unix/Linux/pandora_agent.conf | 2 +- pandora_agents/unix/NT4/pandora_agent.conf | 2 +- pandora_agents/unix/NetBSD/pandora_agent.conf | 2 +- pandora_agents/unix/SunOS/pandora_agent.conf | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 4 ++-- pandora_agents/unix/pandora_agent.spec | 4 ++-- pandora_agents/unix/pandora_agent_installer | 2 +- pandora_agents/win32/bin/pandora_agent.conf | 2 +- pandora_agents/win32/installer/pandora.mpi | 4 ++-- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 4 ++-- pandora_console/pandora_console.redhat.spec | 4 ++-- pandora_console/pandora_console.spec | 4 ++-- pandora_console/pandora_console_install | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/conf/pandora_server.conf.new | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/pandora_server.redhat.spec | 4 ++-- pandora_server/pandora_server.spec | 4 ++-- pandora_server/pandora_server_installer | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 50 files changed, 58 insertions(+), 58 deletions(-) diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index bff05d8732..07054ee2e1 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, AIX version +# Version 7.0NG.732, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index 938691a2af..9d8a49bb99 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, FreeBSD Version +# Version 7.0NG.732, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index d6f6d248c9..c02e4647e1 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, HP-UX Version +# Version 7.0NG.732, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 0de221f790..153113e070 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, GNU/Linux +# Version 7.0NG.732, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index cb90a522a3..6ddeba7edc 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, GNU/Linux +# Version 7.0NG.732, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 1758206b7b..502317f893 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, Solaris Version +# Version 7.0NG.732, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index bc4a50047f..96b20ea7e3 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2010 Artica Soluciones Tecnologicas -# Version 7.0NG.731 +# Version 7.0NG.732 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index 6ca5613d16..200ff9db97 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.731, AIX version +# Version 7.0NG.732, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index b55b3033f6..2002f4db65 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.731 +# Version 7.0NG.732 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index 4a5a240381..f9c19dbd06 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.731, HPUX Version +# Version 7.0NG.732, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 8e2600567a..dc272a7a71 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731 +# Version 7.0NG.732 # Licensed under GPL license v2, # (c) 2003-2010 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index 8dfed3e54d..5a466677d2 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731 +# Version 7.0NG.732 # Licensed under GPL license v2, # (c) 2003-2009 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index ca04eca187..170188cc6f 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731 +# Version 7.0NG.732 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index 563805acdb..aad04ca60d 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.731, Solaris version +# Version 7.0NG.732, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 9d787783ff..3ce7da3c7e 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, AIX version +# Version 7.0NG.732, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 015f306205..e22ad033cd 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.731-190227 +Version: 7.0NG.732 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 4e132515b9..3bf9ddbeab 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190227" +pandora_version="7.0NG.732" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/Darwin/pandora_agent.conf b/pandora_agents/unix/Darwin/pandora_agent.conf index 2164faaedc..35202fcbe5 100644 --- a/pandora_agents/unix/Darwin/pandora_agent.conf +++ b/pandora_agents/unix/Darwin/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, GNU/Linux +# Version 7.0NG.732, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2012 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/FreeBSD/pandora_agent.conf b/pandora_agents/unix/FreeBSD/pandora_agent.conf index 0c5a190f9b..c505d5f75e 100644 --- a/pandora_agents/unix/FreeBSD/pandora_agent.conf +++ b/pandora_agents/unix/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, FreeBSD Version +# Version 7.0NG.732, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2016 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/HP-UX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf index f039431f7a..237bffb291 100644 --- a/pandora_agents/unix/HP-UX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, HP-UX Version +# Version 7.0NG.732, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/Linux/pandora_agent.conf b/pandora_agents/unix/Linux/pandora_agent.conf index df03402446..5a65e0e095 100644 --- a/pandora_agents/unix/Linux/pandora_agent.conf +++ b/pandora_agents/unix/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, GNU/Linux +# Version 7.0NG.732, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2014 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NT4/pandora_agent.conf b/pandora_agents/unix/NT4/pandora_agent.conf index 12421565e8..1394067390 100644 --- a/pandora_agents/unix/NT4/pandora_agent.conf +++ b/pandora_agents/unix/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, GNU/Linux +# Version 7.0NG.732, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/NetBSD/pandora_agent.conf b/pandora_agents/unix/NetBSD/pandora_agent.conf index 6dd394db7a..677615a47c 100644 --- a/pandora_agents/unix/NetBSD/pandora_agent.conf +++ b/pandora_agents/unix/NetBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, NetBSD Version +# Version 7.0NG.732, NetBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2010 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/SunOS/pandora_agent.conf b/pandora_agents/unix/SunOS/pandora_agent.conf index 3d7294a56a..89d5b46100 100644 --- a/pandora_agents/unix/SunOS/pandora_agent.conf +++ b/pandora_agents/unix/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.731, Solaris Version +# Version 7.0NG.732, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2009 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 97b13365d3..d23b2dbc8b 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; # Semaphore used to control the number of threads my $ThreadSem = undef; -use constant AGENT_VERSION => '7.0NG.731'; +use constant AGENT_VERSION => '7.0NG.732'; use constant AGENT_BUILD => '190227'; # Agent log default file size maximum and instances diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index ce3173b9f3..68e68b96da 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index f5be518e22..d0ba8171de 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -2,8 +2,8 @@ #Pandora FMS Linux Agent # %define name pandorafms_agent_unix -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index e27ad14333..066c36036d 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -9,7 +9,7 @@ # Please see http://www.pandorafms.org. This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.731" +PI_VERSION="7.0NG.732" PI_BUILD="190227" OS_NAME=`uname -s` diff --git a/pandora_agents/win32/bin/pandora_agent.conf b/pandora_agents/win32/bin/pandora_agent.conf index aab9a2f315..3d1e208de8 100644 --- a/pandora_agents/win32/bin/pandora_agent.conf +++ b/pandora_agents/win32/bin/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2017 Artica Soluciones Tecnologicas -# Version 7.0NG.731 +# Version 7.0NG.732 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 3d62982f64..160347190c 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -3,7 +3,7 @@ AllowLanguageSelection {Yes} AppName -{Pandora FMS Windows Agent v7.0NG.731} +{Pandora FMS Windows Agent v7.0NG.732} ApplicationID {17E3D2CF-CA02-406B-8A80-9D31C17BD08F} @@ -2387,7 +2387,7 @@ Windows,BuildSeparateArchives {No} Windows,Executable -{<%AppName%>-<%Version%>-Setup<%Ext%>} +{<%AppName%>-Setup<%Ext%>} Windows,FileDescription {<%AppName%> <%Version%> Setup} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 8ce589ce8a..9698e9c322 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.731(Build 190227)") +#define PANDORA_VERSION ("7.0NG.732(Build 190227)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index f54a5ebd36..0feb88dcc9 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.731(Build 190227))" + VALUE "ProductVersion", "(7.0NG.732(Build 190227))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 8ece3fcc84..5e56471fa3 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.731-190227 +Version: 7.0NG.732 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index ea4a0bd5a1..6f582418aa 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190227" +pandora_version="7.0NG.732" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 3a5efda30b..d5ca8db9fe 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -21,7 +21,7 @@ * Pandora build version and version */ $build_version = 'PC190227'; -$pandora_version = 'v7.0NG.731'; +$pandora_version = 'v7.0NG.732'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); diff --git a/pandora_console/install.php b/pandora_console/install.php index 0799f277b9..ae179b9418 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -128,8 +128,8 @@ </div> <div style='height: 10px'> <?php - $version = '7.0NG.731'; - $build = '190227'; +$version = '7.0NG.732'; +$build = '190227'; $banner = "v$version Build $build"; error_reporting(0); diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index fd3d576780..d71e64adfd 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index 7a03758761..c6a51abb2f 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -2,8 +2,8 @@ # Pandora FMS Console # %define name pandorafms_console -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_console/pandora_console_install b/pandora_console/pandora_console_install index e90610ba10..1e11c575bf 100644 --- a/pandora_console/pandora_console_install +++ b/pandora_console/pandora_console_install @@ -9,7 +9,7 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.731" +PI_VERSION="7.0NG.732" FORCE=0 DESTDIR="" LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index f5da1f12fa..b471ca22f0 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -114,7 +114,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 24), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '731'), +('current_package_enterprise', '732'), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index eeb2aa1c00..d7a7c7cb43 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.731-190227 +Version: 7.0NG.732 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index 14df936933..5c8bbedd5e 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.731-190227" +pandora_version="7.0NG.732" package_cpan=0 package_pandora=1 diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 8a4c8b6901..933613ef82 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -1,7 +1,7 @@ ############################################################################# # Pandora FMS Server Parameters # Pandora FMS, the Flexible Monitoring System. -# Version 7.0NG.731 +# Version 7.0NG.732 # Licensed under GPL license v2, # (c) 2003-2017 Artica Soluciones Tecnologicas # http://www.pandorafms.com diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 6fa0020285..134a934310 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -44,7 +44,7 @@ our @EXPORT = qw( ); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.731"; +my $pandora_version = "7.0NG.732"; my $pandora_build = "190227"; our $VERSION = $pandora_version." ".$pandora_build; diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index 9413a58f32..ca7f3228ea 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -31,7 +31,7 @@ use base 'Exporter'; our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only -my $pandora_version = "7.0NG.731"; +my $pandora_version = "7.0NG.732"; my $pandora_build = "190227"; our $VERSION = $pandora_version." ".$pandora_build; diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 2ce12d8e32..33cb660483 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index c29be2cabf..54afdb0335 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -2,8 +2,8 @@ # Pandora FMS Server # %define name pandorafms_server -%define version 7.0NG.731 -%define release 190227 +%define version 7.0NG.732 +%define release 1 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index c59ea4898c..cce5d0097e 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -8,7 +8,7 @@ # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION="7.0NG.731" +PI_VERSION="7.0NG.732" PI_BUILD="190227" MODE=$1 diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index e8f8a43cdd..8fdf28afbd 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.731 PS190227"; +my $version = "7.0NG.732 PS190227"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 5f4f2a6c9b..6de65ff850 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.731 PS190227"; +my $version = "7.0NG.732 PS190227"; # save program name for logging my $progname = basename($0); From e55e47cbfa80e12a31728e2cb207db2dc87b5aad Mon Sep 17 00:00:00 2001 From: daniel <daniel.barbero@artica.es> Date: Wed, 27 Feb 2019 11:35:00 +0100 Subject: [PATCH 22/25] change mr Former-commit-id: 4ec37be9caef34e88b3e5ca65bca2c1aee7f03dd --- pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 4 ++-- pandora_console/pandoradb_data.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 2492a9913f..d8377484c3 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1199,13 +1199,13 @@ ALTER TABLE titem MODIFY `source_data` int(10) unsigned; INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30'); -INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 24); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 25); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); UPDATE tconfig SET value = 'https://licensing.artica.es/pandoraupdate7/server.php' WHERE token='url_update_manager'; DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; -INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '731'); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '732'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp'); -- --------------------------------------------------------------------- diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index b471ca22f0..25bff0eb4d 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -111,7 +111,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_report_front_logo', 'images/pandora_logo_white.jpg'), ('custom_report_front_header', ''), ('custom_report_front_footer', ''), -('MR', 24), +('MR', 25), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), ('current_package_enterprise', '732'), From ec5c9d7c2765d5ec565fb11ee18287ed7c723b0b Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Wed, 27 Feb 2019 13:41:26 +0100 Subject: [PATCH 23/25] clippy returns Former-commit-id: b9ed010f5af1002593471a0d0298848b3593e41e --- pandora_console/general/header.php | 3 + pandora_console/include/functions_clippy.php | 108 ++++++++++++++----- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index e35d401502..3d7ce7dd6e 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -294,6 +294,9 @@ config_check(); <!-- Notifications content wrapper--> <div id='notification-content' style='display:none;' /></div> +<!-- Old style div wrapper --> +<div id="alert_messages" style="display: none"></div>; + <script type="text/javascript"> /* <![CDATA[ */ diff --git a/pandora_console/include/functions_clippy.php b/pandora_console/include/functions_clippy.php index 725ce5078a..f3bc6a5967 100644 --- a/pandora_console/include/functions_clippy.php +++ b/pandora_console/include/functions_clippy.php @@ -1,23 +1,31 @@ <?php - -// Pandora FMS - http://pandorafms.com -// ================================================== -// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas -// Please see http://pandorafms.org for full contribution list -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation; version 2 -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - /** + * Pandora FMS - http://pandorafms.com + * ================================================== + * Copyright (c) 2005-2011 Artica Soluciones Tecnologicas + * Please see http://pandorafms.org for full contribution list + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; version 2 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * @package Include * @subpackage Clippy */ +// Begin. + +/** + * Starts clippy. + * + * @param string $sec2 Section. + + * @return void + */ function clippy_start($sec2) { global $config; @@ -28,7 +36,7 @@ function clippy_start($sec2) $sec2 = str_replace('/', '_', $sec2); - // Avoid some case the other parameters in the url + // Avoid some case the other parameters in the url. if (strstr($sec2, '&') !== false) { $chunks = explode('&', $sec2); $sec2 = $chunks[0]; @@ -42,7 +50,7 @@ function clippy_start($sec2) clippy_write_javascript_helps_steps($tours); } - // Add homepage for all pages for to show the "task sugestions" + // Add homepage for all pages for to show the "task sugestions". include 'include/help/clippy/homepage.php'; $tours = clippy_start_page_homepage(); @@ -56,12 +64,24 @@ function clippy_start($sec2) } +/** + * Undocumented function + * + * @return void + */ function clippy_clean_help() { set_cookie('clippy', null); } +/** + * Undocumented function + * + * @param something $tours Tour. + * + * @return void + */ function clippy_write_javascript_helps_steps($tours) { global $config; @@ -71,7 +91,7 @@ function clippy_write_javascript_helps_steps($tours) $first_step_by_default = $tours['first_step_by_default']; } - // For the help context instead the clippy + // For the help context instead the clippy. $help_context = false; if (isset($tours['help_context'])) { $help_context = $tours['help_context']; @@ -86,7 +106,7 @@ function clippy_write_javascript_helps_steps($tours) $clippy = get_cookie('clippy', false); set_cookie('clippy', null); - // Get the help steps from a task + // Get the help steps from a task. $steps = null; if (isset($tours['tours'][$clippy])) { $steps = $tours['tours'][$clippy]['steps']; @@ -94,7 +114,7 @@ function clippy_write_javascript_helps_steps($tours) if ($first_step_by_default) { if (empty($steps)) { - // Get the first by default + // Get the first by default. $temp = reset($tours['tours']); $steps = $temp['steps']; } @@ -121,7 +141,7 @@ function clippy_write_javascript_helps_steps($tours) if ($first_step_by_default) { if (empty($conf)) { - // Get the first by default + // Get the first by default. $temp = reset($tours['tours']); $conf = $temp['conf']; } @@ -137,7 +157,7 @@ function clippy_write_javascript_helps_steps($tours) } $autostart = true; - if (!is_null($conf['autostart'])) { + if (isset($conf['autostart'])) { $autostart = $conf['autostart']; } @@ -185,9 +205,25 @@ function clippy_write_javascript_helps_steps($tours) <?php echo $name_obj_js_tour; ?> = introJs(); <?php echo $name_obj_js_tour; ?>.setOptions({ - steps: <?php echo json_encode((bool) $steps); ?>, - showBullets: <?php echo json_encode((bool) $show_bullets); ?>, - showStepNumbers: <?php echo json_encode((bool) $show_step_numbers); ?>, + steps: <?php echo json_encode($steps); ?>, + showBullets: + <?php + if ($show_bullets) { + echo 'true'; + } else { + echo 'false'; + } + ?> + , + showStepNumbers: + <?php + if ($show_step_numbers) { + echo 'true'; + } else { + echo 'false'; + } + ?> + , nextLabel: "<?php echo __('Next →'); ?>", prevLabel: "<?php echo __('← Back'); ?>", skipLabel: "<?php echo $skipLabel; ?>", @@ -205,13 +241,22 @@ function clippy_write_javascript_helps_steps($tours) return exit; }); - if (<?php echo json_encode(!empty($conf['next_help'])); ?>) { + <?php + if (!empty($conf['next_help'])) { + ?> clippy_set_help('<?php echo $conf['next_help']; ?>'); + <?php } + ?> - if (<?php echo json_encode((bool) $autostart); ?>) { - <?php echo $name_obj_js_tour; ?>.start(); + <?php + if ($autostart) { + echo $name_obj_js_tour; + ?> + .start(); + <?php } + ?> }); <?php echo $other_js; ?> @@ -221,6 +266,13 @@ function clippy_write_javascript_helps_steps($tours) } +/** + * Undocumented function + * + * @param string $help Help. + * + * @return void + */ function clippy_context_help($help=null) { global $config; @@ -244,10 +296,10 @@ function clippy_context_help($help=null) $code = str_replace('{clippy}', '#'.$id, $code); $code = str_replace('{clippy_obj}', 'intro_'.$id, $code); - $return = $code.'<div id="'.$id.'" style="display: inline;">'.'<a onclick="show_'.$id.'();" href="javascript: void(0);" >'.html_print_image( + $return = $code.'<div id="'.$id.'" style="display: inline;"><a onclick="show_'.$id.'();" href="javascript: void(0);" >'.html_print_image( 'images/clippy_icon.png', true - ).'</a>'.'</div> + ).'</a></div> <script type="text/javascript"> function show_'.$id.'() { From f979af0735751bd28003f19a8949b61dfc85efa5 Mon Sep 17 00:00:00 2001 From: fbsanchez <fborja.sanchez@artica.es> Date: Wed, 27 Feb 2019 13:56:06 +0100 Subject: [PATCH 24/25] minor fixes Former-commit-id: 51a2308e80a85c5a099410c5883c9b389d3a74ab --- pandora_server/lib/PandoraFMS/Recon/Base.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index ec3eb0d853..45f5d87a27 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -216,7 +216,7 @@ sub new { $self->{'snmp_security_level'} = ''; # Disable SNMP scans if no community was given. - if (scalar(@{$self->{'communities'}}) == 0) { + if (ref($self->{'communities'}) ne "ARRAY" || scalar(@{$self->{'communities'}}) == 0) { $self->{'snmp_enabled'} = 0; $self->call('message', "There is not any SNMP community configured.", 5); From a8a9a9d6204a00850bb7a4d92216f7db38a6816d Mon Sep 17 00:00:00 2001 From: artica <artica.devel@gmail.com> Date: Thu, 28 Feb 2019 00:01:32 +0100 Subject: [PATCH 25/25] Auto-updated build strings. Former-commit-id: 2c0ee9351e5f306085921bde697a1b10de102b2e --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/unix/pandora_agent_installer | 2 +- pandora_agents/win32/installer/pandora.mpi | 4 ++-- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/pandora_server_installer | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 24 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index e22ad033cd..13323ebd9e 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.732 +Version: 7.0NG.732-190228 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 3bf9ddbeab..50d31d3941 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.732" +pandora_version="7.0NG.732-190228" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index d23b2dbc8b..2f3f0c05e9 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -42,7 +42,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.732'; -use constant AGENT_BUILD => '190227'; +use constant AGENT_BUILD => '190228'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 68e68b96da..b16be00748 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.732 -%define release 1 +%define release 190228 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index d0ba8171de..95f66a4e1d 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.732 -%define release 1 +%define release 190228 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 066c36036d..9332f50cd4 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.732" -PI_BUILD="190227" +PI_BUILD="190228" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 160347190c..dc8705f89e 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{190227} +{190228} ViewReadme {Yes} @@ -2387,7 +2387,7 @@ Windows,BuildSeparateArchives {No} Windows,Executable -{<%AppName%>-Setup<%Ext%>} +{<%AppName%>-<%Version%>-Setup<%Ext%>} Windows,FileDescription {<%AppName%> <%Version%> Setup} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 9698e9c322..6f83db7f80 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.732(Build 190227)") +#define PANDORA_VERSION ("7.0NG.732(Build 190228)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 0feb88dcc9..73e4a154c7 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.732(Build 190227))" + VALUE "ProductVersion", "(7.0NG.732(Build 190228))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 5e56471fa3..e6aeef61b0 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.732 +Version: 7.0NG.732-190228 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 6f582418aa..9902501164 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.732" +pandora_version="7.0NG.732-190228" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index d5ca8db9fe..2b612c0819 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC190227'; +$build_version = 'PC190228'; $pandora_version = 'v7.0NG.732'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index ae179b9418..44c2bdf9fc 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -129,7 +129,7 @@ <div style='height: 10px'> <?php $version = '7.0NG.732'; -$build = '190227'; +$build = '190228'; $banner = "v$version Build $build"; error_reporting(0); diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec index d71e64adfd..9ca0f54737 100644 --- a/pandora_console/pandora_console.redhat.spec +++ b/pandora_console/pandora_console.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.732 -%define release 1 +%define release 190228 # User and Group under which Apache is running %define httpd_name httpd diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec index c6a51abb2f..0f671c6a55 100644 --- a/pandora_console/pandora_console.spec +++ b/pandora_console/pandora_console.spec @@ -3,7 +3,7 @@ # %define name pandorafms_console %define version 7.0NG.732 -%define release 1 +%define release 190228 %define httpd_name httpd # User and Group under which Apache is running %define httpd_name apache2 diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control index d7a7c7cb43..4f78a1c055 100644 --- a/pandora_server/DEBIAN/control +++ b/pandora_server/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-server -Version: 7.0NG.732 +Version: 7.0NG.732-190228 Architecture: all Priority: optional Section: admin diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh index 5c8bbedd5e..e4214ee973 100644 --- a/pandora_server/DEBIAN/make_deb_package.sh +++ b/pandora_server/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.732" +pandora_version="7.0NG.732-190228" package_cpan=0 package_pandora=1 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 134a934310..fc5f7e91a7 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -45,7 +45,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.732"; -my $pandora_build = "190227"; +my $pandora_build = "190228"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index ca7f3228ea..34ebd8098f 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -32,7 +32,7 @@ our @ISA = qw(Exporter); # version: Defines actual version of Pandora Server for this module only my $pandora_version = "7.0NG.732"; -my $pandora_build = "190227"; +my $pandora_build = "190228"; our $VERSION = $pandora_version." ".$pandora_build; our %EXPORT_TAGS = ( 'all' => [ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index 33cb660483..1193281389 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.732 -%define release 1 +%define release 190228 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 54afdb0335..eeba06bb63 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.732 -%define release 1 +%define release 190228 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index cce5d0097e..fd38bb42f0 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.732" -PI_BUILD="190227" +PI_BUILD="190228" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 8fdf28afbd..8e83f423a8 100644 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -34,7 +34,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.732 PS190227"; +my $version = "7.0NG.732 PS190228"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 6de65ff850..7c735994f7 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.732 PS190227"; +my $version = "7.0NG.732 PS190228"; # save program name for logging my $progname = basename($0);