2019-02-12 14:39:01 +01:00
< ? php
2019-02-14 17:56:10 +01:00
/**
* Extension to schedule tasks on Pandora FMS Console
*
* @ category Wizard
* @ package Pandora FMS
* @ subpackage Host & Devices
* @ 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 .
* ============================================================================
*/
2019-02-12 14:39:01 +01:00
2019-02-14 10:56:25 +01:00
require_once __DIR__ . '/Wizard.main.php' ;
2019-02-14 13:27:49 +01:00
require_once $config [ 'homedir' ] . '/include/functions_users.php' ;
2019-02-14 17:56:10 +01:00
enterprise_include ( 'include/class/CSVImportAgents.class.php' );
2019-02-12 14:39:01 +01:00
/**
2019-02-15 18:05:59 +01:00
* Wizard section Host & devices .
* Provides classic recon task creation .
* In enterprise environments , provides also CSV agent import features .
2019-02-12 14:39:01 +01:00
*/
2019-02-14 10:56:25 +01:00
class HostDevices extends Wizard
2019-02-12 14:39:01 +01:00
{
2019-02-14 17:14:01 +01:00
/**
* Stores all needed parameters to create a recon task .
*
* @ var array
*/
public $task ;
2019-02-12 14:39:01 +01:00
/**
2019-02-15 18:05:59 +01:00
* Constructor .
2019-02-12 14:39:01 +01:00
*
2019-02-14 11:32:07 +01:00
* @ param integer $page Start page , by default 0.
2019-02-12 14:39:01 +01:00
* @ param string $msg Mensajito .
* @ param string $icon Mensajito .
* @ param string $label Mensajito .
*
* @ return class HostDevices
*/
public function __construct (
int $page = 0 ,
2019-02-15 13:08:44 +01:00
string $msg = 'Default message. Not set.' ,
2019-02-15 18:05:59 +01:00
string $icon = 'images/wizard/hostdevices.svg' ,
2019-02-12 14:39:01 +01:00
string $label = 'Host & Devices'
) {
2019-02-14 11:32:07 +01:00
$this -> setBreadcrum ([]);
2019-02-14 17:14:01 +01:00
$this -> task = [];
2019-02-12 14:39:01 +01:00
$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=hd'
);
return $this ;
}
/**
2019-02-15 18:05:59 +01:00
* Run wizard manager .
2019-02-12 14:39:01 +01:00
*
2019-02-15 18:05:59 +01:00
* @ return mixed Returns null if wizard is ongoing . Result if done .
2019-02-12 14:39:01 +01:00
*/
public function run ()
{
global $config ;
2019-02-14 13:27:49 +01:00
// Load styles.
parent :: run ();
2019-02-12 14:39:01 +01:00
$mode = get_parameter ( 'mode' , null );
if ( $mode === null ) {
2019-02-14 11:32:07 +01:00
$this -> setBreadcrum ([ '<a href="index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd">Host&devices</a>' ]);
$this -> printHeader ();
2019-02-18 11:42:55 +01:00
$this -> printBigButtonsList (
[
[
'url' => $this -> url . '&mode=importcsv' ,
'icon' => 'images/wizard/csv_image.svg' ,
'label' => __ ( 'Import CSV' ),
],
[
'url' => $this -> url . '&mode=netscan' ,
'icon' => 'images/wizard/csv_image.svg' ,
'label' => __ ( 'Net Scan' ),
],
]
);
2019-02-14 16:56:03 +01:00
2019-02-12 14:39:01 +01:00
return ;
}
2019-02-14 17:56:10 +01:00
if ( enterprise_installed ()) {
if ( $mode == 'importcsv' ) {
$this -> setBreadcrum (
[
'<a href="index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd">Host&devices</a>' ,
'<a href="index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd&mode=importcsv">Import CSV</a>' ,
]
);
$this -> printHeader ();
$csv_importer = new CSVImportAgents ( $this -> page , $this -> breadcrum );
return $csv_importer -> runCSV ();
}
2019-02-12 14:39:01 +01:00
}
if ( $mode == 'netscan' ) {
2019-02-15 13:57:33 +01:00
if ( $this -> page != 3 ) {
// Do not paint breadcrum in last page. Redirected.
$this -> setBreadcrum (
[
'<a href="index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd">Host&devices</a>' ,
'<a href="index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=hd&mode=netscan">Net scan</a>' ,
]
);
$this -> printHeader ();
}
2019-02-12 14:39:01 +01:00
return $this -> runNetScan ();
}
return null ;
}
/**
* Checks if environment is ready ,
* returns array
* icon : icon to be displayed
* label : label to be displayed
*
* @ return array With data .
**/
public function load ()
{
return [
'icon' => $this -> icon ,
'label' => $this -> label ,
'url' => $this -> url ,
];
}
2019-02-14 10:56:25 +01:00
// Extra methods.
2019-02-12 14:39:01 +01:00
2019-02-14 13:27:49 +01:00
/**
* Retrieves and validates information given by user in NetScan wizard .
*
* @ return boolean Data OK or not .
*/
public function parseNetScan ()
{
2019-02-14 17:19:20 +01:00
if ( $this -> page == 0 ) {
2019-02-15 13:08:44 +01:00
// Check if we're updating a task.
$task_id = get_parameter ( 'task' , null );
if ( isset ( $task_id ) === true ) {
// We're updating this task.
$task = db_get_row (
'trecon_task' ,
'id_rt' ,
$task_id
);
if ( $task !== false ) {
$this -> task = $task ;
}
}
2019-02-14 17:19:20 +01:00
return true ;
}
// Validate response from page 0. No, not a bug, we're always 1 page
// from 'validation' page.
if ( $this -> page == 1 ) {
2019-02-15 13:08:44 +01:00
$task_id = get_parameter ( 'task' , null );
2019-02-14 17:19:20 +01:00
$taskname = get_parameter ( 'taskname' , '' );
$comment = get_parameter ( 'comment' , '' );
$server_id = get_parameter ( 'id_recon_server' , '' );
2019-02-15 13:08:44 +01:00
$network = get_parameter ( 'network' , '' );
2019-02-14 17:19:20 +01:00
$id_group = get_parameter ( 'id_group' , '' );
2019-02-15 13:08:44 +01:00
if ( isset ( $task_id ) === true ) {
// We're updating this task.
$task = db_get_row (
'trecon_task' ,
'id_rt' ,
$task_id
);
if ( $task !== false ) {
$this -> task = $task ;
}
} else if ( isset ( $taskname ) === true
&& isset ( $network ) === true
) {
// Avoid double creation.
$task = db_get_row_filter (
'trecon_task' ,
[
'name' => $taskname ,
'subnet' => $network ,
]
);
if ( $task !== false ) {
$this -> task = $task ;
2019-02-15 16:02:55 +01:00
$this -> msg = __ ( 'This network scan task has been already defined. Please edit it or create a new one.' );
return false ;
2019-02-15 13:08:44 +01:00
}
}
if ( isset ( $this -> task [ 'id_rt' ]) === false ) {
// Disabled 2 Implies wizard non finished.
$this -> task [ 'disabled' ] = 2 ;
}
2019-02-14 17:19:20 +01:00
if ( $taskname == '' ) {
$this -> msg = __ ( 'You must provide a task name.' );
return false ;
}
if ( $server_id == '' ) {
$this -> msg = __ ( 'You must select a Discovery Server.' );
return false ;
}
if ( $network == '' ) {
// XXX: Could be improved validating provided network.
$this -> msg = __ ( 'You must provide a valid network.' );
return false ;
}
if ( $id_group == '' ) {
$this -> msg = __ ( 'You must select a valid group.' );
return false ;
}
// Assign fields.
$this -> task [ 'name' ] = $taskname ;
$this -> task [ 'description' ] = $comment ;
$this -> task [ 'subnet' ] = $network ;
$this -> task [ 'id_recon_server' ] = $server_id ;
2019-02-15 13:08:44 +01:00
$this -> task [ 'id_group' ] = $id_group ;
2019-02-14 17:19:20 +01:00
2019-02-15 13:08:44 +01:00
if ( isset ( $this -> task [ 'id_rt' ]) === false ) {
2019-02-14 17:19:20 +01:00
// Create.
$this -> task [ 'id_rt' ] = db_process_sql_insert (
'trecon_task' ,
$this -> task
);
} else {
// Update.
db_process_sql_update (
'trecon_task' ,
$this -> task ,
[ 'id_rt' => $this -> task [ 'id_rt' ]]
);
}
return true ;
}
// Validate response from page 1.
if ( $this -> page == 2 ) {
$id_rt = get_parameter ( 'task' , - 1 );
2019-02-15 13:08:44 +01:00
$task = db_get_row (
2019-02-14 17:19:20 +01:00
'trecon_task' ,
'id_rt' ,
$id_rt
);
2019-02-15 13:08:44 +01:00
if ( $task !== false ) {
$this -> task = $task ;
} else {
$this -> msg = __ ( 'Failed to find network scan task.' );
return false ;
}
$id_network_profile = get_parameter ( 'id_network_profile' , null );
$snmp_enabled = get_parameter_switch ( 'snmp_enabled' );
$os_detect = get_parameter_switch ( 'os_detect' );
$parent_detection = get_parameter_switch ( 'parent_detection' );
$parent_recursion = get_parameter_switch ( 'parent_recursion' );
$vlan_enabled = get_parameter_switch ( 'vlan_enabled' );
2019-02-15 13:57:33 +01:00
$wmi_enabled = get_parameter_switch ( 'wmi_enabled' );
$resolve_names = get_parameter_switch ( 'resolve_names' );
2019-02-15 13:08:44 +01:00
$snmp_version = get_parameter ( 'snmp_version' , null );
$community = get_parameter ( 'community' , null );
$snmp_context = get_parameter ( 'snmp_context' , null );
$snmp_auth_user = get_parameter ( 'snmp_auth_user' , null );
$snmp_auth_pass = get_parameter ( 'snmp_auth_pass' , null );
$snmp_privacy_method = get_parameter ( 'snmp_privacy_method' , null );
$snmp_privacy_pass = get_parameter ( 'snmp_privacy_pass' , null );
$snmp_auth_method = get_parameter ( 'snmp_auth_method' , null );
$snmp_security_level = get_parameter ( 'snmp_security_level' , null );
$auth_strings = get_parameter ( 'auth_strings' , null );
if ( $snmp_version == 3 ) {
$this -> task [ 'snmp_community' ] = $snmp_context ;
} else {
$this -> task [ 'snmp_community' ] = $community ;
}
$this -> task [ 'id_network_profile' ] = $id_network_profile ;
$this -> task [ 'snmp_enabled' ] = $snmp_enabled ;
$this -> task [ 'os_detect' ] = $os_detect ;
$this -> task [ 'parent_detection' ] = $parent_detection ;
$this -> task [ 'parent_recursion' ] = $parent_recursion ;
$this -> task [ 'vlan_enabled' ] = $vlan_enabled ;
2019-02-15 13:57:33 +01:00
$this -> task [ 'wmi_enabled' ] = $wmi_enabled ;
$this -> task [ 'resolve_names' ] = $resolve_names ;
2019-02-15 13:08:44 +01:00
$this -> task [ 'snmp_version' ] = $snmp_version ;
$this -> task [ 'snmp_auth_user' ] = $snmp_auth_user ;
$this -> task [ 'snmp_auth_pass' ] = $snmp_auth_pass ;
$this -> task [ 'snmp_privacy_method' ] = $snmp_privacy_method ;
$this -> task [ 'snmp_privacy_pass' ] = $snmp_privacy_pass ;
$this -> task [ 'snmp_auth_method' ] = $snmp_auth_method ;
$this -> task [ 'snmp_security_level' ] = $snmp_security_level ;
$this -> task [ 'auth_strings' ] = $auth_strings ;
// Update.
$res = db_process_sql_update (
'trecon_task' ,
$this -> task ,
[ 'id_rt' => $this -> task [ 'id_rt' ]]
);
2019-02-14 17:19:20 +01:00
2019-02-15 13:08:44 +01:00
return true ;
2019-02-14 17:19:20 +01:00
}
if ( $this -> page == 3 ) {
// Interval and schedules.
// By default manual if not defined.
2019-02-15 13:08:44 +01:00
$id_rt = get_parameter ( 'task' , - 1 );
$task = db_get_row (
'trecon_task' ,
'id_rt' ,
$id_rt
);
if ( $task !== false ) {
$this -> task = $task ;
} else {
$this -> msg = __ ( 'Failed to find network scan task.' );
return false ;
}
2019-02-14 17:19:20 +01:00
2019-02-15 13:08:44 +01:00
$interval = get_parameter ( 'interval' , 0 );
2019-02-15 16:37:48 +01:00
$id_os = get_parameter ( 'id_os' , 0 );
$recon_ports = get_parameter ( 'recon_ports' , '' );
$this -> task [ 'id_os' ] = $id_os ;
2019-02-14 17:19:20 +01:00
$this -> task [ 'interval_sweep' ] = $interval ;
2019-02-15 16:37:48 +01:00
$this -> task [ 'recon_ports' ] = $recon_ports ;
2019-02-15 13:08:44 +01:00
if ( $this -> task [ 'disabled' ] == 2 ) {
// Wizard finished.
$this -> task [ 'disabled' ] = 0 ;
}
// Update.
$res = db_process_sql_update (
'trecon_task' ,
$this -> task ,
[ 'id_rt' => $this -> task [ 'id_rt' ]]
);
return true ;
}
if ( $this -> page == 4 ) {
// Wizard ended. Load data and return control to Discovery.
$id_rt = get_parameter ( 'task' , - 1 );
$task = db_get_row (
'trecon_task' ,
'id_rt' ,
$id_rt
);
if ( $task !== false ) {
$this -> task = $task ;
} else {
$this -> msg = __ ( 'Failed to find network scan task.' );
return false ;
}
return true ;
2019-02-14 17:19:20 +01:00
}
2019-02-14 13:27:49 +01:00
return false ;
}
2019-02-12 14:39:01 +01:00
/**
* Undocumented function
*
* @ return void
*/
public function runNetScan ()
{
global $config ;
check_login ();
if ( ! check_acl ( $config [ 'id_user' ], 0 , 'PM' )) {
db_pandora_audit (
'ACL Violation' ,
'Trying to access Agent Management'
);
include 'general/noaccess.php' ;
return ;
}
2019-02-14 17:19:20 +01:00
if ( $this -> parseNetScan () === false ) {
// Error.
ui_print_error_message (
$this -> msg
);
$form = [
'form' => [
'method' => 'POST' ,
2019-02-15 13:08:44 +01:00
'action' => $this -> url . '&mode=netscan&page=' . ( $this -> page - 1 ) . '&task=' . $this -> task [ 'id_rt' ],
2019-02-14 17:19:20 +01:00
],
'inputs' => [
[
'arguments' => [
'type' => 'hidden' ,
2019-02-15 13:08:44 +01:00
'name' => 'task' ,
'value' => $this -> task [ 'id_rt' ],
2019-02-14 17:19:20 +01:00
],
],
[
'arguments' => [
'name' => 'submit' ,
'label' => __ ( 'Go back' ),
'type' => 'submit' ,
'attributes' => 'class="sub cancel"' ,
'return' => true ,
],
],
],
];
2019-02-18 12:14:03 +01:00
// Check ACL. If user is not able to manage target task,
// redirect him to main page.
if ( users_is_admin () || check_acl (
$config [ 'id_usuario' ],
$this -> task [ 'id_group' ],
'PM'
) !== true
) {
$form [ 'form' ][ 'action' ] = $this -> url . '&mode=netscan&page=' . ( $this -> page - 1 );
}
2019-02-14 17:19:20 +01:00
$this -> printForm ( $form );
return null ;
2019-02-14 13:27:49 +01:00
}
2019-02-14 17:19:20 +01:00
if ( isset ( $this -> page )
&& $this -> page != 0
&& isset ( $this -> task [ 'id_rt' ]) === false
) {
// Error.
ui_print_error_message (
__ ( 'Internal error, please re-run this wizard.' )
);
$form = [
'form' => [
'method' => 'POST' ,
2019-02-15 13:08:44 +01:00
'action' => $this -> url . '&mode=netscan&page=0' ,
2019-02-14 17:19:20 +01:00
],
'inputs' => [
[
'arguments' => [
'type' => 'hidden' ,
'name' => 'page' ,
'value' => 0 ,
],
],
[
'arguments' => [
'name' => 'submit' ,
'label' => __ ( 'Go back' ),
'type' => 'submit' ,
'attributes' => 'class="sub cancel"' ,
'return' => true ,
],
],
],
];
$this -> printForm ( $form );
return null ;
}
2019-02-14 13:27:49 +01:00
2019-02-14 17:19:20 +01:00
// -------------------------------.
// Page 0. wizard starts HERE.
// -------------------------------.
if ( ! isset ( $this -> page ) || $this -> page == 0 ) {
2019-02-14 13:27:49 +01:00
if ( isset ( $this -> page ) === false
|| $this -> page == 0
) {
$form = [];
// Input task name.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Task name' ) . '</b>' ,
'arguments' => [
'name' => 'taskname' ,
2019-02-15 13:08:44 +01:00
'value' => $this -> task [ 'name' ],
2019-02-14 13:27:49 +01:00
'type' => 'text' ,
'size' => 25 ,
],
];
2019-02-15 13:08:44 +01:00
if ( isset ( $this -> task [ 'id_rt' ]) === true ) {
// Propagate id.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'task' ,
'value' => $this -> task [ 'id_rt' ],
'type' => 'hidden' ,
],
];
}
2019-02-14 17:19:20 +01:00
// Input task name.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Comment' ) . '</b>' ,
'arguments' => [
'name' => 'comment' ,
2019-02-15 13:08:44 +01:00
'value' => $this -> task [ 'description' ],
2019-02-14 17:19:20 +01:00
'type' => 'text' ,
'size' => 25 ,
],
];
2019-02-14 13:27:49 +01:00
// Input Discovery Server.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Discovery server' ) . '</b>' . ui_print_help_tip (
__ ( 'You must select a Discovery Server to run the Task, otherwise the Recon Task will never run' ),
true
),
'arguments' => [
'type' => 'select_from_sql' ,
'sql' => sprintf (
' SELECT id_server , name
FROM tserver
WHERE server_type = % d
ORDER BY name ' ,
SERVER_TYPE_DISCOVERY
),
'name' => 'id_recon_server' ,
2019-02-15 13:08:44 +01:00
'selected' => $this -> task [ 'id_recon_server' ],
2019-02-14 13:27:49 +01:00
'return' => true ,
],
];
// Input Network.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Network' ) . '</b>' . ui_print_help_tip (
__ ( 'You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24' ),
true
),
2019-02-14 11:53:06 +01:00
'arguments' => [
2019-02-15 13:08:44 +01:00
'name' => 'network' ,
'value' => $this -> task [ 'subnet' ],
2019-02-14 11:53:06 +01:00
'type' => 'text' ,
'size' => 25 ,
],
2019-02-14 13:27:49 +01:00
];
// Input Group.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Group' ) . '</b>' ,
'arguments' => [
2019-02-15 16:37:48 +01:00
'name' => 'id_group' ,
'returnAllGroup' => false ,
'privilege' => 'PM' ,
'type' => 'select_groups' ,
'selected' => $this -> task [ 'id_group' ],
'return' => true ,
2019-02-14 13:27:49 +01:00
],
];
2019-02-15 13:08:44 +01:00
$str = __ ( 'Next' );
if ( isset ( $this -> task [ 'id_rt' ]) === true ) {
$str = __ ( 'Update and continue' );
}
2019-02-14 13:27:49 +01:00
// Submit button.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'submit' ,
2019-02-15 13:08:44 +01:00
'label' => $str ,
2019-02-14 13:27:49 +01:00
'type' => 'submit' ,
'attributes' => 'class="sub next"' ,
'return' => true ,
],
];
2019-02-15 13:57:33 +01:00
$task_url = '' ;
if ( isset ( $this -> task [ 'id_rt' ])) {
$task_url = '&task=' . $this -> task [ 'id_rt' ];
}
2019-02-14 13:27:49 +01:00
$form [ 'form' ] = [
'method' => 'POST' ,
2019-02-15 13:57:33 +01:00
'action' => $this -> url . '&mode=netscan&page=' . ( $this -> page + 1 ) . $task_url ,
2019-02-14 13:27:49 +01:00
];
2019-02-14 17:14:01 +01:00
// XXX: Could be improved validating inputs before continue (JS)
2019-02-14 13:27:49 +01:00
// Print NetScan page 0.
$this -> printForm ( $form );
2019-02-15 18:05:59 +01:00
$this -> printGoBackButton ();
2019-02-14 13:27:49 +01:00
}
}
2019-02-14 11:53:06 +01:00
2019-02-14 13:27:49 +01:00
if ( $this -> page == 1 ) {
// Page 1.
2019-02-14 17:14:01 +01:00
$form = [];
// Hidden, id_rt.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'task' ,
'value' => $this -> task [ 'id_rt' ],
'type' => 'hidden' ,
'return' => true ,
],
];
// Hidden, page.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'page' ,
'value' => ( $this -> page + 1 ),
'type' => 'hidden' ,
'return' => true ,
],
];
$form [ 'inputs' ][] = [
'extra' => '<p>Please, configure task <b>' . io_safe_output ( $this -> task [ 'name' ]) . '</b></p>' ,
];
// Input: Module template.
$form [ 'inputs' ][] = [
'label' => __ ( 'Module template' ),
'arguments' => [
2019-02-15 13:57:33 +01:00
'name' => 'id_network_profile' ,
'type' => 'select_from_sql' ,
'sql' => ' SELECT id_np , name
2019-02-14 17:14:01 +01:00
FROM tnetwork_profile
ORDER BY name ' ,
2019-02-15 13:57:33 +01:00
'return' => true ,
'selected' => $this -> task [ 'id_network_profile' ],
2019-02-14 17:14:01 +01:00
],
];
// Feature configuration.
2019-02-15 16:37:48 +01:00
// Input: SNMP enabled.
2019-02-14 17:14:01 +01:00
$form [ 'inputs' ][] = [
'label' => __ ( 'SNMP enabled' ),
'arguments' => [
'name' => 'snmp_enabled' ,
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'snmp_enabled' ])) ? $this -> task [ 'snmp_enabled' ] : 1 ,
2019-02-15 13:08:44 +01:00
'onclick' => 'extraSNMP();' ,
2019-02-14 17:14:01 +01:00
],
];
// SNMP CONFIGURATION.
$form [ 'inputs' ][] = [
2019-02-15 14:14:56 +01:00
'hidden' => 1 ,
2019-02-14 17:14:01 +01:00
'block_id' => 'snmp_extra' ,
'block_content' => [
2019-02-14 17:19:20 +01:00
[
'label' => __ ( 'SNMP version' ),
'arguments' => [
2019-02-15 13:57:33 +01:00
'name' => 'snmp_version' ,
'fields' => [
2019-02-14 17:19:20 +01:00
'1' => 'v. 1' ,
'2c' => 'v. 2c' ,
'3' => 'v. 3' ,
],
2019-02-15 13:57:33 +01:00
'type' => 'select' ,
'script' => 'SNMPExtraShow(this.value)' ,
'selected' => $this -> task [ 'snmp_version' ],
'return' => true ,
2019-02-14 17:14:01 +01:00
],
],
],
];
2019-02-14 17:56:10 +01:00
// SNMP Options pack v1.
2019-02-14 17:14:01 +01:00
$form [ 'inputs' ][] = [
'hidden' => 1 ,
2019-02-15 13:08:44 +01:00
'block_id' => 'snmp_options_basic' ,
2019-02-14 17:14:01 +01:00
'block_content' => [
2019-02-14 17:19:20 +01:00
[
2019-02-15 13:08:44 +01:00
'label' => '<b>' . __ ( 'SNMP Default community' ) . '</b>' . ui_print_help_tip (
__ (
'You can specify several values, separated by commas, for example: public,mysecret,1234'
),
true
),
2019-02-14 17:19:20 +01:00
'arguments' => [
'name' => 'community' ,
'type' => 'text' ,
2019-02-15 13:57:33 +01:00
'value' => $this -> task [ 'snmp_community' ],
2019-02-14 17:19:20 +01:00
'size' => 25 ,
'return' => true ,
2019-02-14 17:14:01 +01:00
2019-02-14 17:19:20 +01:00
],
2019-02-14 17:14:01 +01:00
],
],
];
2019-02-15 13:08:44 +01:00
// SNMP Options pack v3.
2019-02-14 17:56:10 +01:00
$form [ 'inputs' ][] = [
'hidden' => 1 ,
2019-02-15 13:08:44 +01:00
'block_id' => 'snmp_options_v3' ,
2019-02-14 17:56:10 +01:00
'block_content' => [
[
2019-02-15 13:08:44 +01:00
'label' => '<b>' . __ ( 'Context' ) . '</b>' ,
2019-02-14 17:56:10 +01:00
'arguments' => [
2019-02-15 13:08:44 +01:00
'name' => 'snmp_context' ,
2019-02-14 17:56:10 +01:00
'type' => 'text' ,
2019-02-15 13:57:33 +01:00
'value' => $this -> task [ 'snmp_community' ],
2019-02-15 13:08:44 +01:00
'size' => 15 ,
2019-02-14 17:56:10 +01:00
'return' => true ,
],
],
[
2019-02-15 13:08:44 +01:00
'label' => '<b>' . __ ( 'Auth user' ) . '</b>' ,
2019-02-14 17:56:10 +01:00
'arguments' => [
2019-02-15 13:08:44 +01:00
'name' => 'snmp_auth_user' ,
2019-02-14 17:56:10 +01:00
'type' => 'text' ,
2019-02-15 13:57:33 +01:00
'value' => $this -> task [ 'snmp_auth_user' ],
2019-02-15 13:08:44 +01:00
'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' ,
2019-02-15 13:57:33 +01:00
'value' => $this -> task [ 'snmp_auth_pass' ],
2019-02-15 13:08:44 +01:00
'size' => 15 ,
'return' => true ,
],
],
[
'label' => '<b>' . __ ( 'Privacy method' ) . '</b>' ,
'arguments' => [
2019-02-15 13:57:33 +01:00
'name' => 'snmp_privacy_method' ,
'type' => 'select' ,
'fields' => [
2019-02-15 13:08:44 +01:00
'DES' => __ ( 'DES' ),
'AES' => __ ( 'AES' ),
],
2019-02-15 13:57:33 +01:00
'selected' => $this -> task [ 'snmp_privacy_method' ],
'size' => 15 ,
'return' => true ,
2019-02-15 13:08:44 +01:00
],
],
[
'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' ,
2019-02-15 13:57:33 +01:00
'value' => $this -> task [ 'snmp_privacy_pass' ],
2019-02-15 13:08:44 +01:00
'size' => 15 ,
'return' => true ,
],
],
[
'label' => '<b>' . __ ( 'Auth method' ) . '</b>' ,
'arguments' => [
2019-02-15 13:57:33 +01:00
'name' => 'snmp_auth_method' ,
'type' => 'select' ,
'fields' => [
2019-02-15 13:08:44 +01:00
'MD5' => __ ( 'MD5' ),
'SHA' => __ ( 'SHA' ),
],
2019-02-15 13:57:33 +01:00
'selected' => $this -> task [ 'snmp_auth_method' ],
'size' => 15 ,
'return' => true ,
2019-02-14 17:56:10 +01:00
],
],
2019-02-15 13:08:44 +01:00
[
'label' => '<b>' . __ ( 'Security level' ) . '</b>' ,
'arguments' => [
2019-02-15 13:57:33 +01:00
'name' => 'snmp_security_level' ,
'type' => 'select' ,
'fields' => [
2019-02-15 13:08:44 +01:00
'noAuthNoPriv' => __ ( 'Not auth and not privacy method' ),
'authNoPriv' => __ ( 'Auth and not privacy method' ),
'authPriv' => __ ( 'Auth and privacy method' ),
],
2019-02-15 13:57:33 +01:00
'selected' => $this -> task [ 'snmp_security_level' ],
'size' => 15 ,
'return' => true ,
2019-02-15 13:08:44 +01:00
],
],
2019-02-14 17:56:10 +01:00
],
];
2019-02-14 17:14:01 +01:00
// Input: WMI enabled.
$form [ 'inputs' ][] = [
'label' => __ ( 'WMI enabled' ),
'arguments' => [
'name' => 'wmi_enabled' ,
'type' => 'switch' ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'wmi_enabled' ])) ? $this -> task [ 'wmi_enabled' ] : 0 ,
2019-02-14 17:14:01 +01:00
'return' => true ,
2019-02-15 13:57:33 +01:00
'onclick' => 'toggleWMI();' ,
2019-02-14 17:14:01 +01:00
],
];
// WMI CONFIGURATION.
$form [ 'inputs' ][] = [
2019-02-15 13:57:33 +01:00
'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 ,
],
],
2019-02-14 17:14:01 +01:00
],
];
2019-02-15 16:37:48 +01:00
// Input: Enforce os detection.
2019-02-14 17:14:01 +01:00
$form [ 'inputs' ][] = [
'label' => __ ( 'OS detection' ),
'arguments' => [
'name' => 'os_detect' ,
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'os_detect' ])) ? $this -> task [ 'os_detect' ] : 1 ,
2019-02-14 17:14:01 +01:00
],
];
// Input: Name resolution.
$form [ 'inputs' ][] = [
'label' => __ ( 'Name resolution' ),
'arguments' => [
'name' => 'resolve_names' ,
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'resolve_names' ])) ? $this -> task [ 'resolve_names' ] : 0 ,
2019-02-14 17:14:01 +01:00
],
];
// Input: Parent detection.
$form [ 'inputs' ][] = [
'label' => __ ( 'Parent detection' ),
'arguments' => [
'name' => 'parent_detection' ,
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'parent_detection' ])) ? $this -> task [ 'parent_detection' ] : 1 ,
2019-02-15 13:08:44 +01:00
],
];
// Input: Parent recursion.
$form [ 'inputs' ][] = [
'label' => __ ( 'Parent recursion' ),
'arguments' => [
'name' => 'parent_recursion' ,
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'parent_recursion' ])) ? $this -> task [ 'parent_recursion' ] : 1 ,
2019-02-14 17:14:01 +01:00
],
];
// Input: VLAN enabled.
$form [ 'inputs' ][] = [
'label' => __ ( 'VLAN enabled' ),
'arguments' => [
2019-02-15 13:08:44 +01:00
'name' => 'vlan_enabled' ,
2019-02-14 17:14:01 +01:00
'type' => 'switch' ,
'return' => true ,
2019-02-15 13:57:33 +01:00
'value' => ( isset ( $this -> task [ 'vlan_enabled' ])) ? $this -> task [ 'vlan_enabled' ] : 1 ,
2019-02-14 17:14:01 +01:00
],
];
// Submit button.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'submit' ,
'label' => __ ( 'Next' ),
'type' => 'submit' ,
'attributes' => 'class="sub next"' ,
'return' => true ,
],
];
2019-02-15 13:08:44 +01:00
$form [ 'js' ] = '
function SNMPExtraShow ( target ) {
$ ( " #snmp_options_basic " ) . hide ();
$ ( " #snmp_options_v3 " ) . hide ();
2019-02-15 14:14:56 +01:00
if ( document . getElementsByName ( " snmp_enabled " )[ 0 ] . checked ) {
2019-02-18 12:14:03 +01:00
$ ( " #snmp_extra " ) . show ();
2019-02-15 14:14:56 +01:00
if ( target == 3 ) {
$ ( " #snmp_options_v3 " ) . show ();
} else {
$ ( " #snmp_options_basic " ) . show ();
}
2019-02-15 13:08:44 +01:00
}
}
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 ();
}
}
2019-02-15 13:57:33 +01:00
function toggleWMI () {
if ( document . getElementsByName ( " wmi_enabled " )[ 0 ] . checked )
$ ( " #wmi_extra " ) . show ();
else
$ ( " #wmi_extra " ) . hide ();
}
2019-02-15 13:08:44 +01:00
$ ( function () {
2019-02-15 13:57:33 +01:00
SNMPExtraShow ( $ ( " #snmp_version " ) . val ());
toggleWMI ();
2019-02-15 13:08:44 +01:00
});
' ;
2019-02-14 17:14:01 +01:00
$form [ 'form' ] = [
'method' => 'POST' ,
2019-02-15 13:08:44 +01:00
'action' => $this -> url . '&mode=netscan&page=' . ( $this -> page + 1 ) . '&task=' . $this -> task [ 'id_rt' ],
2019-02-14 17:14:01 +01:00
];
$this -> printForm ( $form );
}
if ( $this -> page == 2 ) {
// Interval and schedules.
$interv_manual = 0 ;
2019-02-15 16:37:48 +01:00
if (( int ) $this -> task [ 'interval_sweep' ] == 0 ) {
2019-02-14 17:14:01 +01:00
$interv_manual = 1 ;
}
2019-02-15 16:37:48 +01:00
// Filter: OS.
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Filter by OS' ) . '</b>' ,
'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' => '<b>' . __ ( 'Filter by ports' ) . '</b>' . 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.
2019-02-14 17:14:01 +01:00
$form [ 'inputs' ][] = [
'label' => '<b>' . __ ( 'Interval' ) . '</b>' . ui_print_help_tip (
__ ( 'Manual interval means that it will be executed only On-demand' ),
true
),
'arguments' => [
'type' => 'select' ,
'selected' => $interv_manual ,
'fields' => [
0 => __ ( 'Defined' ),
1 => __ ( 'Manual' ),
],
'name' => 'interval_manual_defined' ,
'return' => true ,
],
'extra' => '<span id="interval_manual_container">' . html_print_extended_select_for_time (
'interval' ,
2019-02-15 16:37:48 +01:00
$this -> task [ 'interval_sweep' ],
2019-02-14 17:14:01 +01:00
'' ,
'' ,
'0' ,
false ,
true ,
false ,
false
) . ui_print_help_tip (
__ ( 'The minimum recomended interval for Recon Task is 5 minutes' ),
true
) . '</span>' ,
];
// Hidden, id_rt.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'task' ,
'value' => $this -> task [ 'id_rt' ],
'type' => 'hidden' ,
'return' => true ,
],
];
// Hidden, page.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'page' ,
'value' => ( $this -> page + 1 ),
'type' => 'hidden' ,
'return' => true ,
],
];
// Submit button.
$form [ 'inputs' ][] = [
'arguments' => [
'name' => 'submit' ,
'label' => __ ( 'Next' ),
'type' => 'submit' ,
'attributes' => 'class="sub next"' ,
'return' => true ,
],
];
$form [ 'form' ] = [
'method' => 'POST' ,
2019-02-15 13:08:44 +01:00
'action' => $this -> url . '&mode=netscan&page=' . ( $this -> page + 1 ) . '&task=' . $this -> task [ 'id_rt' ],
2019-02-14 17:14:01 +01:00
];
$form [ 'js' ] = '
$ ( " select#interval_manual_defined " ) . change ( function () {
if ( $ ( " #interval_manual_defined " ) . val () == 1 ) {
$ ( " #interval_manual_container " ) . hide ();
$ ( " #text-interval_text " ) . val ( 0 );
$ ( " #hidden-interval " ) . val ( 0 );
}
else {
$ ( " #interval_manual_container " ) . show ();
$ ( " #text-interval_text " ) . val ( 10 );
$ ( " #hidden-interval " ) . val ( 600 );
$ ( " #interval_units " ) . val ( 60 );
}
}) . change (); ' ;
$this -> printForm ( $form );
2019-02-15 13:57:33 +01:00
return null ;
2019-02-12 14:39:01 +01:00
}
2019-02-15 13:08:44 +01:00
if ( $this -> page == 3 ) {
if ( $this -> task [ 'id_rt' ]) {
// 0 - Is OK.
$this -> result = 0 ;
$this -> msg = __ ( 'Task configured.' );
} else {
// 1 - Is NOT OK.
$this -> result = 1 ;
$this -> msg = __ ( 'Wizard failed. Cannot configure task.' );
}
2019-02-14 11:53:06 +01:00
return [
'result' => $this -> result ,
2019-02-15 13:08:44 +01:00
'id' => $this -> task [ 'id_rt' ],
2019-02-14 11:53:06 +01:00
'msg' => $this -> msg ,
];
2019-02-12 14:39:01 +01:00
}
}
}