From 5093094d7d20bc4e1e1b6fc5f3b9e75ce98ed32b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:05:59 +0100 Subject: [PATCH] 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;