From ec672d6bfbb7a0c133d372e772d4fd5ed4df34c1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 13:57:33 +0100 Subject: [PATCH 01/11] H&D network scan Former-commit-id: dcd22994d6addf69ab5d68a6724d12e26e994d15 --- pandora_console/godmode/servers/discovery.php | 14 +- .../godmode/wizards/HostDevices.class.php | 135 ++++++++++++------ 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 70da2939e7..2afbbb0f24 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -53,8 +53,18 @@ $classname_selected = get_wiz_class($wiz_in_use); if ($classname_selected !== null) { $wiz = new $classname_selected($page); $result = $wiz->run(); - // TODO: Here we'll controlle if return is a valid recon task id. - hd($result); + if (is_array($result) === true) { + if ($result['result'] === 0) { + // Success. + ui_print_success_message($result['msg']); + // TODO: Show task progress before redirect to main discovery menu. + } else { + // Failed. + ui_print_error_message($result['msg']); + } + + $classname_selected = null; + } } if ($classname_selected === null) { diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 7e2772d6e1..f31d16618b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -160,13 +160,17 @@ class HostDevices extends Wizard } if ($mode == 'netscan') { - $this->setBreadcrum( - [ - 'Host&devices', - 'Net scan', - ] - ); - $this->printHeader(); + if ($this->page != 3) { + // Do not paint breadcrum in last page. Redirected. + $this->setBreadcrum( + [ + 'Host&devices', + 'Net scan', + ] + ); + $this->printHeader(); + } + return $this->runNetScan(); } @@ -258,6 +262,9 @@ class HostDevices extends Wizard if ($task !== false) { $this->task = $task; } + + $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); + return false; } if (isset($this->task['id_rt']) === false) { @@ -334,6 +341,8 @@ class HostDevices extends Wizard $parent_detection = get_parameter_switch('parent_detection'); $parent_recursion = get_parameter_switch('parent_recursion'); $vlan_enabled = get_parameter_switch('vlan_enabled'); + $wmi_enabled = get_parameter_switch('wmi_enabled'); + $resolve_names = get_parameter_switch('resolve_names'); $snmp_version = get_parameter('snmp_version', null); $community = get_parameter('community', null); $snmp_context = get_parameter('snmp_context', null); @@ -357,6 +366,8 @@ class HostDevices extends Wizard $this->task['parent_detection'] = $parent_detection; $this->task['parent_recursion'] = $parent_recursion; $this->task['vlan_enabled'] = $vlan_enabled; + $this->task['wmi_enabled'] = $wmi_enabled; + $this->task['resolve_names'] = $resolve_names; $this->task['snmp_version'] = $snmp_version; $this->task['snmp_auth_user'] = $snmp_auth_user; $this->task['snmp_auth_pass'] = $snmp_auth_pass; @@ -640,9 +651,14 @@ class HostDevices extends Wizard ], ]; + $task_url = ''; + if (isset($this->task['id_rt'])) { + $task_url = '&task='.$this->task['id_rt']; + } + $form['form'] = [ 'method' => 'POST', - 'action' => $this->url.'&mode=netscan&page='.($this->page + 1), + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url, ]; // XXX: Could be improved validating inputs before continue (JS) @@ -682,12 +698,13 @@ class HostDevices extends Wizard $form['inputs'][] = [ 'label' => __('Module template'), 'arguments' => [ - 'name' => 'id_network_profile', - 'type' => 'select_from_sql', - 'sql' => 'SELECT id_np, name + 'name' => 'id_network_profile', + 'type' => 'select_from_sql', + 'sql' => 'SELECT id_np, name FROM tnetwork_profile ORDER BY name', - 'return' => true, + 'return' => true, + 'selected' => $this->task['id_network_profile'], ], ]; @@ -700,7 +717,7 @@ class HostDevices extends Wizard 'name' => 'snmp_enabled', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['snmp_enabled'])) ? $this->task['snmp_enabled'] : 1, 'onclick' => 'extraSNMP();', ], @@ -714,15 +731,16 @@ class HostDevices extends Wizard [ 'label' => __('SNMP version'), 'arguments' => [ - 'name' => 'snmp_version', - 'fields' => [ + 'name' => 'snmp_version', + 'fields' => [ '1' => 'v. 1', '2c' => 'v. 2c', '3' => 'v. 3', ], - 'type' => 'select', - 'script' => 'SNMPExtraShow(this.value)', - 'return' => true, + 'type' => 'select', + 'script' => 'SNMPExtraShow(this.value)', + 'selected' => $this->task['snmp_version'], + 'return' => true, ], ], ], @@ -743,6 +761,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'community', 'type' => 'text', + 'value' => $this->task['snmp_community'], 'size' => 25, 'return' => true, @@ -761,6 +780,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_context', 'type' => 'text', + 'value' => $this->task['snmp_community'], 'size' => 15, 'return' => true, @@ -771,6 +791,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_auth_user', 'type' => 'text', + 'value' => $this->task['snmp_auth_user'], 'size' => 15, 'return' => true, @@ -786,6 +807,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_auth_pass', 'type' => 'password', + 'value' => $this->task['snmp_auth_pass'], 'size' => 15, 'return' => true, @@ -794,14 +816,15 @@ class HostDevices extends Wizard [ 'label' => ''.__('Privacy method').'', 'arguments' => [ - 'name' => 'snmp_privacy_method', - 'type' => 'select', - 'fields' => [ + 'name' => 'snmp_privacy_method', + 'type' => 'select', + 'fields' => [ 'DES' => __('DES'), 'AES' => __('AES'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_privacy_method'], + 'size' => 15, + 'return' => true, ], ], @@ -815,6 +838,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_privacy_pass', 'type' => 'password', + 'value' => $this->task['snmp_privacy_pass'], 'size' => 15, 'return' => true, @@ -823,29 +847,31 @@ class HostDevices extends Wizard [ 'label' => ''.__('Auth method').'', 'arguments' => [ - 'name' => 'snmp_auth_method', - 'type' => 'select', - 'fields' => [ + 'name' => 'snmp_auth_method', + 'type' => 'select', + 'fields' => [ 'MD5' => __('MD5'), 'SHA' => __('SHA'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_auth_method'], + 'size' => 15, + 'return' => true, ], ], [ 'label' => ''.__('Security level').'', 'arguments' => [ - 'name' => 'snmp_security_level', - 'type' => 'select', - 'fields' => [ + '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'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_security_level'], + 'size' => 15, + 'return' => true, ], ], @@ -859,22 +885,27 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'wmi_enabled', 'type' => 'switch', + 'value' => (isset($this->task['wmi_enabled'])) ? $this->task['wmi_enabled'] : 0, 'return' => true, - 'onclick' => "\$('#wmi_extra').toggle();", + 'onclick' => 'toggleWMI();', ], ]; // WMI CONFIGURATION. $form['inputs'][] = [ - 'label' => __('WMI Auth. strings'), - 'hidden' => 1, - 'id' => 'wmi_extra', - 'arguments' => [ - 'name' => 'auth_strings', - 'type' => 'text', - 'return' => true, - + 'block_id' => 'wmi_extra', + 'hidden' => 1, + 'block_content' => [ + [ + 'label' => __('WMI Auth. strings'), + 'arguments' => [ + 'name' => 'auth_strings', + 'type' => 'text', + 'value' => $this->task['auth_strings'], + 'return' => true, + ], + ], ], ]; @@ -885,7 +916,7 @@ class HostDevices extends Wizard 'name' => 'os_detect', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['os_detect'])) ? $this->task['os_detect'] : 1, ], ]; @@ -897,6 +928,7 @@ class HostDevices extends Wizard 'name' => 'resolve_names', 'type' => 'switch', 'return' => true, + 'value' => (isset($this->task['resolve_names'])) ? $this->task['resolve_names'] : 0, ], ]; @@ -907,7 +939,7 @@ class HostDevices extends Wizard 'name' => 'parent_detection', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['parent_detection'])) ? $this->task['parent_detection'] : 1, ], ]; @@ -918,7 +950,7 @@ class HostDevices extends Wizard 'name' => 'parent_recursion', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['parent_recursion'])) ? $this->task['parent_recursion'] : 1, ], ]; @@ -929,7 +961,7 @@ class HostDevices extends Wizard 'name' => 'vlan_enabled', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['vlan_enabled'])) ? $this->task['vlan_enabled'] : 1, ], ]; @@ -979,8 +1011,16 @@ function extraSNMP() { } } +function toggleWMI() { + if (document.getElementsByName("wmi_enabled")[0].checked) + $("#wmi_extra").show(); + else + $("#wmi_extra").hide(); +} + $(function() { - SNMPExtraShow($("#snmp_version").val()) + SNMPExtraShow($("#snmp_version").val()); + toggleWMI(); }); '; @@ -1082,6 +1122,7 @@ $("select#interval_manual_defined").change(function() { }).change();'; $this->printForm($form); + return null; } if ($this->page == 3) { From 32d34cd09b9ff6fbfed2e6d9a77d3aaf7232a3b0 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 15 Feb 2019 14:02:32 +0100 Subject: [PATCH 02/11] Changed styles in host and devices Former-commit-id: 743f203466e8e3745a33837054e5bc4faa69337c --- pandora_console/godmode/servers/discovery.php | 9 +++--- .../godmode/wizards/HostDevices.class.php | 21 +++++++++++-- pandora_console/images/wizard/csv_image.svg | 4 +++ pandora_console/include/styles/discovery.css | 30 +++++++++++++++++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 pandora_console/images/wizard/csv_image.svg diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 70da2939e7..39cc86675c 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -15,7 +15,7 @@ if (! check_acl($config['id_user'], 0, 'AW')) { ui_require_css_file('discovery'); -ui_print_page_header(__('Discover'), 'wizards/hostDevices.png', false, '', true); +ui_print_page_header(__('Discover'), '', false, '', true); /** @@ -64,13 +64,12 @@ if ($classname_selected === null) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); $wiz_data = $obj->load(); - - hd($wiz_data); ?> +
  • - <?php echo $classname; ?> -
    + <?php echo $classname; ?> +
  • diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 7e2772d6e1..157657d237 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -138,9 +138,24 @@ class HostDevices extends Wizard if ($mode === null) { $this->setBreadcrum(['Host&devices']); $this->printHeader(); - - echo 'Importar csv'; - echo 'Escanear red'; + echo '
    '; + echo '
    '; + echo '
    '; + echo 'importcsv'; + echo '
    '; + echo '
    '; + echo ''.__('Import CSV').''; + echo '
    '; + echo '
    '; + echo '
    '; + echo '
    '; + echo 'importcsv'; + echo '
    '; + echo '
    '; + echo ''.__('Escanear red').''; + echo '
    '; + echo '
    '; + echo '
    '; return; } diff --git a/pandora_console/images/wizard/csv_image.svg b/pandora_console/images/wizard/csv_image.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/csv_image.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 62be6c7c98..5f2cc45b68 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -1,3 +1,33 @@ /* * Discovery css global */ + +#contenedor_principal { + height: auto; + position: relative; + margin: auto; +} +#contenedor_imagen_texto { + width: 11%; + height: auto; + position: relative; + display: inline-block; + vertical-align: top; + overflow: hidden; + margin-right: 5%; +} +#imagen { + width: 15%; + height: auto; + position: relative; + display: inline; +} +.texto { + height: auto; + text-align: center; +} +#text_wizard { + font-weight: bolder; + text-decoration: none; + font-size: 24px; +} From e397353f71b2cb60bab75a65ad788cb5d91f814f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 14:03:16 +0100 Subject: [PATCH 03/11] minor fix get_parameter_switch Former-commit-id: c8e430e1cbd789a99058217e7dffb4098aab821a --- pandora_console/include/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 58120c4616..e1861e70a3 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -862,9 +862,11 @@ function get_parameter_checkbox($name, $default='') */ function get_parameter_switch($name, $default='') { - $data = get_parameter($name, 0); + $data = get_parameter($name, null); - if ($data == 'on') { + if ($data === null) { + return 0; + } else if ($data == 'on') { return 1; } From c62c01c4a0cc26759b1dcc68dbc69720b96a8ea0 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 14:14:56 +0100 Subject: [PATCH 04/11] H&D minor fix - visual Former-commit-id: 57d1e3c62192d9568bfa4db11658e31a8d811a3a --- .../godmode/wizards/HostDevices.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index c7eddc84f4..adbc13180e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -740,7 +740,7 @@ class HostDevices extends Wizard // SNMP CONFIGURATION. $form['inputs'][] = [ - 'hidden' => 0, + 'hidden' => 1, 'block_id' => 'snmp_extra', 'block_content' => [ [ @@ -995,10 +995,12 @@ class HostDevices extends Wizard function SNMPExtraShow(target) { $("#snmp_options_basic").hide(); $("#snmp_options_v3").hide(); - if (target == 3) { - $("#snmp_options_v3").show(); - } else { - $("#snmp_options_basic").show(); + if (document.getElementsByName("snmp_enabled")[0].checked) { + if (target == 3) { + $("#snmp_options_v3").show(); + } else { + $("#snmp_options_basic").show(); + } } } From 45fd528e3880bea244a350425fbb4003013e0c7f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:02:55 +0100 Subject: [PATCH 05/11] minor fixes H&D Former-commit-id: c3236b91b4b6a0f37af2d4da4955c711dd4ace43 --- pandora_console/godmode/wizards/HostDevices.class.php | 5 ++--- pandora_server/lib/PandoraFMS/Recon/Base.pm | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index adbc13180e..12fcaaa39e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -276,10 +276,9 @@ class HostDevices extends Wizard if ($task !== false) { $this->task = $task; + $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); + return false; } - - $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); - return false; } if (isset($this->task['id_rt']) === false) { diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 8d24ebf311..116bcd75e6 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1500,6 +1500,9 @@ sub snmp_get_command { my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; if ($self->{'snmp_version'} eq "3") { + if ($self->{'community'}) { # Context + $command .= " -N $self->{'community} "; + } $command .= " -l$self->{'snmp_security_level'} "; if ($self->{'snmp_security_level'} ne "noAuthNoPriv") { $command .= " -u$self->{'snmp_auth_user'} -a$self->{'snmp_auth_method'} -A$self->{'snmp_auth_pass'} "; From 7a1b66755deea0a35d5f3ba83fb455726b54db93 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:06:28 +0100 Subject: [PATCH 06/11] minor fixes H&D Former-commit-id: a4ffc2e761dc0a4d06209fb1c448bc17d5d45022 --- 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 116bcd75e6..e819b06476 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1501,7 +1501,7 @@ sub snmp_get_command { my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; if ($self->{'snmp_version'} eq "3") { if ($self->{'community'}) { # Context - $command .= " -N $self->{'community} "; + $command .= " -N $self->{'community'} "; } $command .= " -l$self->{'snmp_security_level'} "; if ($self->{'snmp_security_level'} ne "noAuthNoPriv") { From 0f375d6a766e5118f999c9337b8368c4d1abedd5 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:37:48 +0100 Subject: [PATCH 07/11] H&D minor fix group cannot be All Former-commit-id: 2feb42ce06bd379bbb3804a30fab744a4b01b1e1 --- .../godmode/wizards/HostDevices.class.php | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 12fcaaa39e..f619d2d706 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -420,7 +420,12 @@ class HostDevices extends Wizard } $interval = get_parameter('interval', 0); + $id_os = get_parameter('id_os', 0); + $recon_ports = get_parameter('recon_ports', ''); + + $this->task['id_os'] = $id_os; $this->task['interval_sweep'] = $interval; + $this->task['recon_ports'] = $recon_ports; if ($this->task['disabled'] == 2) { // Wizard finished. @@ -640,11 +645,12 @@ class HostDevices extends Wizard $form['inputs'][] = [ 'label' => ''.__('Group').'', 'arguments' => [ - 'name' => 'id_group', - 'privilege' => 'PM', - 'type' => 'select_groups', - 'selected' => $this->task['id_group'], - 'return' => true, + 'name' => 'id_group', + 'returnAllGroup' => false, + 'privilege' => 'PM', + 'type' => 'select_groups', + 'selected' => $this->task['id_group'], + 'return' => true, ], ]; @@ -724,7 +730,7 @@ class HostDevices extends Wizard ]; // Feature configuration. - // Input: Module template. + // Input: SNMP enabled. $form['inputs'][] = [ 'label' => __('SNMP enabled'), 'arguments' => [ @@ -923,7 +929,7 @@ class HostDevices extends Wizard ], ]; - // Input: Module template. + // Input: Enforce os detection. $form['inputs'][] = [ 'label' => __('OS detection'), 'arguments' => [ @@ -1051,10 +1057,40 @@ $(function() { if ($this->page == 2) { // Interval and schedules. $interv_manual = 0; - if ((int) $interval == 0) { + if ((int) $this->task['interval_sweep'] == 0) { $interv_manual = 1; } + // Filter: OS. + $form['inputs'][] = [ + 'label' => ''.__('Filter by OS').'', + 'arguments' => [ + 'type' => 'select_from_sql', + 'sql' => 'SELECT id_os, name + FROM tconfig_os + ORDER BY name', + 'name' => 'id_os', + 'return' => 'true', + 'nothing' => __('Any'), + 'selected' => $this->task['id_os'], + ], + ]; + + // Filter: Ports. + $form['inputs'][] = [ + 'label' => ''.__('Filter by ports').''.ui_print_help_tip( + __('Ports defined like: 80 or 80,443,512 or even 0-1024 (Like Nmap command line format). If dont want to do a sweep using portscan, left it in blank'), + true + ), + 'arguments' => [ + 'type' => 'text', + 'name' => 'recon_ports', + 'return' => 'true', + 'recon_ports' => $this->task['recon_ports'], + ], + ]; + + // Schedule. $form['inputs'][] = [ 'label' => ''.__('Interval').''.ui_print_help_tip( __('Manual interval means that it will be executed only On-demand'), @@ -1072,7 +1108,7 @@ $(function() { ], 'extra' => ''.html_print_extended_select_for_time( 'interval', - $interval, + $this->task['interval_sweep'], '', '', '0', From 5093094d7d20bc4e1e1b6fc5f3b9e75ce98ed32b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:05:59 +0100 Subject: [PATCH 08/11] H&D tasklist and some visual changes Former-commit-id: d9130ec520b0c23a9cf42ce62aae6c3d2432649b --- pandora_console/godmode/servers/discovery.php | 15 +- .../wizards/DiscoveryTaskList.class.php | 297 ++++++++++++++++++ .../godmode/wizards/HostDevices.class.php | 59 +--- .../godmode/wizards/Wizard.main.php | 70 ++++- pandora_console/images/wizard/hostdevices.svg | 4 + pandora_console/images/wizard/tasklist.svg | 4 + pandora_console/include/styles/discovery.css | 37 +++ 7 files changed, 430 insertions(+), 56 deletions(-) create mode 100644 pandora_console/godmode/wizards/DiscoveryTaskList.class.php create mode 100644 pandora_console/images/wizard/hostdevices.svg create mode 100644 pandora_console/images/wizard/tasklist.svg diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 456bf05c01..024eb39e30 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -30,6 +30,9 @@ function get_wiz_class($str) case 'hd': return 'HostDevices'; + case 'tasklist': + return 'DiscoveryTaskList'; + default: // Ignore. return null; @@ -37,6 +40,10 @@ function get_wiz_class($str) } +/* + * CLASS LOADER. + */ + // Dynamic class loader. $classes = glob($config['homedir'].'/godmode/wizards/*.class.php'); foreach ($classes as $classpath) { @@ -76,10 +83,12 @@ if ($classname_selected === null) { $wiz_data = $obj->load(); ?> -
  • +
  • - <?php echo $classname; ?> -
    +
    + +
    +
  • diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php new file mode 100644 index 0000000000..0ad4af9683 --- /dev/null +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -0,0 +1,297 @@ +setBreadcrum([]); + + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->label = __($label); + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' + ); + + return $this; + } + + + /** + * Implements run method. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + // Load styles. + parent::run(); + return $this->showList(); + } + + + /** + * Implements load method. + * + * @return mixed Skeleton for button. + */ + public function load() + { + return [ + 'icon' => $this->icon, + 'label' => $this->label, + 'url' => $this->url, + + ]; + + } + + + /** + * Show complete list of running tasks. + * + * @return boolean Success or not. + */ + public function showList() + { + 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; + } + + // Get all recon servers + $servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3'); + if ($servers === false) { + $servers = []; + ui_print_error_message(__('Discovery Server is disabled')); + return; + } else { + $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); + if ($recon_task === false) { + ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); + include_once $config['homedir'].'/general/firts_task/recon_view.php'; + return; + } 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'; + + $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); + } + } + + 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); + + // 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] = __('Template'); + $table->align[5] = 'left'; + + $table->head[6] = __('Progress'); + $table->align[6] = 'left'; + + $table->head[7] = __('Updated at'); + $table->align[7] = 'left'; + + $table->head[8] = __('Edit'); + $table->align[8] = 'left'; + + foreach ($recon_tasks as $task) { + $data = []; + + if ($task['disabled'] == 0) { + $data[0] = ''; + $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); + $data[0] .= ''; + } else { + $data[0] = ''; + } + + $data[1] = ''.$task['name'].''; + + $data[2] = human_time_description_raw($task['interval_sweep']); + + 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) { + // Network recon task + $data[5] = html_print_image('images/network.png', true, ['title' => __('Network recon task')]).'  '; + $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); + } + + $data[7] = ui_print_timestamp($task['utimestamp'], true); + + if (check_acl($config['id_user'], $task['id_group'], 'PM')) { + $data[8] = ''.html_print_image( + 'images/wrench_orange.png', + true + ).''; + } else { + $data[8] = ''; + } + + array_push($table->data, $data); + } + + if (empty($table->data)) { + echo '
    '.__('Server').' '.$server_name.' '.__('has no recon tasks assigned').'
    '; + } 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; + } + + +} diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index f619d2d706..633fbfe19f 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -31,56 +31,12 @@ require_once $config['homedir'].'/include/functions_users.php'; enterprise_include('include/class/CSVImportAgents.class.php'); /** - * Undocumented class + * Wizard section Host&devices. + * Provides classic recon task creation. + * In enterprise environments, provides also CSV agent import features. */ class HostDevices extends Wizard { - // CSV constants. - const HDW_CSV_NOT_DATA = 0; - const HDW_CSV_DUPLICATED = 0; - const HDW_CSV_GROUP_EXISTS = 0; - - /** - * Undocumented variable - * - * @var array - */ - public $values = []; - - /** - * Undocumented variable - * - * @var [type] - */ - public $result; - - /** - * Undocumented variable - * - * @var [type] - */ - public $msg; - - /** - * Undocumented variable - * - * @var [type] - */ - public $icon; - - /** - * Undocumented variable - * - * @var [type] - */ - public $label; - - /** - * Undocumented variable - * - * @var [type] - */ - public $url; /** * Stores all needed parameters to create a recon task. @@ -91,7 +47,7 @@ class HostDevices extends Wizard /** - * Undocumented function. + * Constructor. * * @param integer $page Start page, by default 0. * @param string $msg Mensajito. @@ -103,7 +59,7 @@ class HostDevices extends Wizard public function __construct( int $page=0, string $msg='Default message. Not set.', - string $icon='hostDevices.png', + string $icon='images/wizard/hostdevices.svg', string $label='Host & Devices' ) { $this->setBreadcrum([]); @@ -122,9 +78,9 @@ class HostDevices extends Wizard /** - * Undocumented function + * Run wizard manager. * - * @return void + * @return mixed Returns null if wizard is ongoing. Result if done. */ public function run() { @@ -684,6 +640,7 @@ class HostDevices extends Wizard // XXX: Could be improved validating inputs before continue (JS) // Print NetScan page 0. $this->printForm($form); + $this->printGoBackButton(); } } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 1a70bae362..ecc253ad04 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -20,6 +20,41 @@ class Wizard */ public $page; + /** + * Target icon to be shown in discovery wizard list. + * + * @var string + */ + public $icon; + + /** + * Target label to be shown in discovery wizard list. + * + * @var string + */ + public $label; + + /** + * This wizard's url. + * + * @var string + */ + public $url; + + /** + * Result of wizard execution (0 - ok, 1 - not ok). + * + * @var integer + */ + public $result; + + /** + * Message to be delivered to user. + * + * @var string + */ + public $msg; + /** * Setter for breadcrum @@ -285,13 +320,13 @@ class Wizard ); case 'submit': - return html_print_submit_button( + return '
    '.html_print_submit_button( ((isset($data['label']) === true) ? $data['label'] : 'OK'), ((isset($data['name']) === true) ? $data['name'] : ''), ((isset($data['disabled']) === true) ? $data['disabled'] : false), ((isset($data['attributes']) === true) ? $data['attributes'] : ''), ((isset($data['return']) === true) ? $data['return'] : false) - ); + ).'
    '; case 'checkbox': return html_print_checkbox( @@ -316,6 +351,37 @@ class Wizard } + /** + * Prints a go back button redirecting to main page. + * + * @return void + */ + public function printGoBackButton() + { + $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); + } + + /** * Print a block of inputs. * diff --git a/pandora_console/images/wizard/hostdevices.svg b/pandora_console/images/wizard/hostdevices.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/hostdevices.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/images/wizard/tasklist.svg b/pandora_console/images/wizard/tasklist.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/tasklist.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 5f2cc45b68..df393fdf3e 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -2,6 +2,43 @@ * Discovery css global */ +li.discovery { + display: inline-block; + float: left; + width: 250px; + height: 120px; + margin: 15px; +} + +li.discovery > a { + text-decoration: none; +} + +li.discovery > a:hover { + color: #000; +} + +li.discovery img { + height: 90px; +} + +li.discovery > a label { + cursor: pointer; +} + +div.data_container { + width: 100%; + height: 100%; + text-align: center; + border: 1px solid #ddd; + padding-top: 30px; + padding-bottom: 30px; +} + +div.data_container:hover { + box-shadow: 2px 2px 10px #ddd; +} + #contenedor_principal { height: auto; position: relative; From a5ad61f340ac851ca5dc5226132a29e50c1c2ed7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:35:35 +0100 Subject: [PATCH 09/11] discovery delete task Former-commit-id: 8809067053aa6bebfa61498afb2108aea352f3d7 --- .../wizards/DiscoveryTaskList.class.php | 73 ++++++++++++++++--- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 0ad4af9683..5488b675b9 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -76,6 +76,13 @@ class DiscoveryTaskList extends Wizard { // Load styles. parent::run(); + + $delete = (bool) get_parameter('delete', false); + + if ($delete) { + return $this->deleteTask(); + } + return $this->showList(); } @@ -97,6 +104,41 @@ class DiscoveryTaskList extends Wizard } + /** + * Delete a recon task. + * + * @return void + */ + public function deleteTask() + { + global $config; + + if (! check_acl($config['id_user'], 0, 'PM')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + $task = get_parameter('task', null); + + if ($task !== null) { + db_process_sql_delete( + 'trecon_task', + ['id_rt' => $task] + ); + } + + return [ + 'result' => 0, + 'msg' => __('Task successfully deleted'), + 'id' => false, + ]; + } + + /** * Show complete list of running tasks. * @@ -114,21 +156,21 @@ class DiscoveryTaskList extends Wizard 'Trying to access recon task viewer' ); include 'general/noaccess.php'; - return; + return false; } - // Get all recon servers + // Get all recon servers. $servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3'); if ($servers === false) { $servers = []; ui_print_error_message(__('Discovery Server is disabled')); - return; + return false; } else { $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); if ($recon_task === false) { ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); include_once $config['homedir'].'/general/firts_task/recon_view.php'; - return; + return false; } else { include_once $config['homedir'].'/include/functions_graph.php'; include_once $config['homedir'].'/include/functions_servers.php'; @@ -145,6 +187,11 @@ class DiscoveryTaskList extends Wizard 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' + ) + ); } } @@ -153,7 +200,7 @@ class DiscoveryTaskList extends Wizard $server_name = servers_get_name($id_server); $recon_tasks = db_get_all_rows_field_filter('trecon_task', 'id_recon_server', $id_server); - // Show network tasks for Recon Server + // Show network tasks for Recon Server. if ($recon_tasks === false) { $recon_tasks = []; } @@ -195,14 +242,16 @@ class DiscoveryTaskList extends Wizard $table->head[7] = __('Updated at'); $table->align[7] = 'left'; - $table->head[8] = __('Edit'); + $table->head[8] = __('Operations'); $table->align[8] = 'left'; foreach ($recon_tasks as $task) { $data = []; if ($task['disabled'] == 0) { - $data[0] = ''; + $data[0] = ''; $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); $data[0] .= ''; } else { @@ -226,11 +275,11 @@ class DiscoveryTaskList extends Wizard } if ($task['id_recon_script'] == 0) { - // Network recon task + // Network recon task. $data[5] = html_print_image('images/network.png', true, ['title' => __('Network recon task')]).'  '; $data[5] .= network_profiles_get_name($task['id_network_profile']); } else { - // APP recon task + // 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'])); } @@ -250,6 +299,12 @@ class DiscoveryTaskList extends Wizard 'images/wrench_orange.png', true ).''; + $data[8] .= ''.html_print_image( + 'images/cross.png', + true + ).''; } else { $data[8] = ''; } From 912f0baace3b3917fdf76dd7703078901f86de48 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:42:44 +0100 Subject: [PATCH 10/11] Discovery Tasks first tasks and some minor fixes Former-commit-id: 4a37dc99f1b1a95217e9be207526d750133a14a6 --- pandora_console/general/firts_task/recon_view.php | 10 +++++----- .../godmode/wizards/DiscoveryTaskList.class.php | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pandora_console/general/firts_task/recon_view.php b/pandora_console/general/firts_task/recon_view.php index 1d81c13e98..2377ce7c20 100755 --- a/pandora_console/general/firts_task/recon_view.php +++ b/pandora_console/general/firts_task/recon_view.php @@ -15,17 +15,17 @@ global $config; check_login(); ui_require_css_file('firts_task'); ?> - true, 'message' => __('There are no recon task defined yet.') ]); ?> + true, 'message' => __('There are no discovery tasks defined yet.') ]); ?>
    __('Discovery server')]); ?>
    -

    +

    ICMP (pings), SNMP (detecting the topology of networks and their interfaces), and other customized @@ -33,8 +33,8 @@ ui_require_css_file('firts_task'); ); ?>

    -
    - + +

    diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 5488b675b9..d0c5da17fb 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -168,7 +168,6 @@ class DiscoveryTaskList extends Wizard } else { $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); if ($recon_task === false) { - ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); include_once $config['homedir'].'/general/firts_task/recon_view.php'; return false; } else { From c49c8bc0b5d84ab2b61c05ee629fe15764d27a76 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:44:59 +0100 Subject: [PATCH 11/11] discovery minor style changes Former-commit-id: ea572c9d797214cbfc6f1b9ff2025f0c4819b4ed --- pandora_console/include/styles/discovery.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index df393fdf3e..930dbd047d 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -30,7 +30,6 @@ div.data_container { width: 100%; height: 100%; text-align: center; - border: 1px solid #ddd; padding-top: 30px; padding-bottom: 30px; } @@ -39,6 +38,9 @@ div.data_container:hover { box-shadow: 2px 2px 10px #ddd; } +/* + * TODO: This may be at hostdevices.css + */ #contenedor_principal { height: auto; position: relative;