Minor fixes Wiz.Discovery

Former-commit-id: 750cd3ab1902ed3eda9806aa9b505d5e4a1175be
This commit is contained in:
manuel 2019-02-21 11:19:38 +01:00
parent 6a43536b33
commit ad3e2b88bf
5 changed files with 298 additions and 112 deletions

View File

@ -19,10 +19,11 @@ ui_print_page_header(__('Discover'), '', false, '', true);
/**
* Undocumented function
* Mask class names.
*
* @param [type] $str
* @return void
* @param string $str Wiz parameter.
*
* @return string Classname.
*/
function get_wiz_class($str)
{
@ -39,6 +40,9 @@ function get_wiz_class($str)
case 'app':
return 'Applications';
case 'ctask':
return 'ConsoleTasks';
default:
// Ignore.
return null;
@ -46,6 +50,31 @@ function get_wiz_class($str)
}
/**
* Aux. function to compare classpath names.
*
* @param string $a Classpath A.
* @param string $b Classpath B.
*
* @return string Matching one.
*/
function cl_load_cmp($a, $b)
{
$str_a = basename($a, '.class.php');
$str_b = basename($b, '.class.php');
if ($str_a == $str_b) {
return 0;
}
if ($str_a < $str_b) {
return -1;
}
return 1;
}
/*
* CLASS LOADER.
*/
@ -79,8 +108,13 @@ if (enterprise_installed() === true) {
}
}
// Combine class paths.
$classes = array_merge($classes, $enterprise_classes);
// Sort output.
uasort($classes, 'cl_load_cmp');
// Check user action.
$wiz_in_use = get_parameter('wiz', null);
$page = get_parameter('page', 0);
@ -110,7 +144,13 @@ if ($classname_selected === null) {
foreach ($classes as $classpath) {
$classname = basename($classpath, '.class.php');
$obj = new $classname();
$wiz_data[] = $obj->load();
// DiscoveryTaskList must be first button.
if ($classname == 'DiscoveryTaskList') {
array_unshift($wiz_data, $obj->load());
} else {
$wiz_data[] = $obj->load();
}
}
Wizard::printBigButtonsList($wiz_data);

View File

@ -0,0 +1,133 @@
<?php
/**
* 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.
* ============================================================================
*/
require_once __DIR__.'/Wizard.main.php';
require_once $config['homedir'].'/include/functions_users.php';
/**
* Defined as wizard to guide user to explore running tasks.
*/
class ConsoleTasks extends Wizard
{
/**
* Number of pages to control breadcrum.
*
* @var integer
*/
public $MAXPAGES = 1;
/**
* Labels for breadcrum.
*
* @var array
*/
public $pageLabels = ['Base'];
/**
* Constructor.
*
* @param integer $page Start page, by default 0.
* @param string $msg Custom default mesage.
* @param string $icon Custom icon.
* @param string $label Custom label.
*
* @return class HostDevices
*/
public function __construct(
int $page=0,
string $msg='Default message. Not set.',
string $icon='images/wizard/csv_image.svg',
string $label='Console Tasks'
) {
$this->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=ctask'
);
return $this;
}
/**
* Implements run method.
*
* @return mixed Returns null if wizard is ongoing. Result if done.
*/
public function run()
{
global $config;
// Load styles.
parent::run();
echo 'hola';
for ($i = 0; $i < $this->MAXPAGES; $i++) {
$breadcrum[] = [
'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app&mode=vmware&page='.$i.'&task='.$this->task['id_rt'],
'label' => $this->label.' '.$this->pageLabels[$i],
'selected' => (($i == $this->page) ? 1 : 0),
];
}
if ($this->page < $this->MAXPAGES) {
// Avoid to print header out of wizard.
$this->prepareBreadcrum($breadcrum);
$this->printHeader();
}
$this->printGoBackButton();
return null;
}
/**
* Implements load method.
*
* @return mixed Skeleton for button.
*/
public function load()
{
return [
'icon' => $this->icon,
'label' => $this->label,
'url' => $this->url,
];
}
}

View File

@ -38,6 +38,24 @@ enterprise_include('include/class/CSVImportAgents.class.php');
class HostDevices extends Wizard
{
/**
* Number of pages to control breadcrum.
*
* @var integer
*/
public $maxPagesNetScan = 2;
/**
* Labels for breadcrum.
*
* @var array
*/
public $pageLabelsNetScan = [
'NetScan definition',
'NetScan features',
];
/**
* Stores all needed parameters to create a recon task.
*
@ -92,16 +110,6 @@ class HostDevices extends Wizard
$mode = get_parameter('mode', null);
if ($mode === null) {
$this->prepareBreadcrum(
[
[
'link' => $this->url.'&wiz=hd',
'label' => __('&nbsp &nbsp Host & devices'),
],
]
);
$this->printHeader();
$this->printBigButtonsList(
[
[
@ -123,62 +131,12 @@ class HostDevices extends Wizard
if (enterprise_installed()) {
if ($mode == 'importcsv') {
$this->prepareBreadcrum(
[
[
'link' => $this->url.'&wiz=hd',
'label' => __('&nbsp &nbsp Host & devices'),
],
[
'link' => $this->url.'&wiz=hd&mode=importcsv',
'label' => __('&nbsp &nbsp &nbsp Import CSV'),
],
]
);
$this->printHeader();
$csv_importer = new CSVImportAgents($this->page, $this->breadcrum);
return $csv_importer->runCSV();
}
}
if ($mode == 'netscan') {
if ($this->page != 2) {
// Do not paint breadcrum in last page. Redirected.
$this->prepareBreadcrum(
[
[
'link' => $this->url.'&wiz=hd',
'label' => __('&nbsp &nbsp Host & devices'),
],
[
'link' => $this->url.'&wiz=hd&mode=netscan',
'label' => __('&nbsp &nbsp &nbsp Net scan definition'),
],
]
);
if ($this->page == 1) {
$this->prepareBreadcrum(
[
[
'link' => $this->url.'&wiz=hd',
'label' => __('&nbsp &nbsp Host & devices'),
],
[
'link' => $this->url.'&wiz=hd&mode=netscan',
'label' => __('&nbsp &nbsp &nbsp Net scan definition'),
],
[
'link' => $this->url.'&wiz=hd&mode=netscan&page=1',
'label' => __('&nbsp &nbsp &nbsp Net scan features'),
],
]
);
}
$this->printHeader();
}
return $this->runNetScan();
}
@ -257,53 +215,77 @@ class HostDevices extends Wizard
}
}
if (isset($this->task['id_rt']) === false) {
// Disabled 2 Implies wizard non finished.
$this->task['disabled'] = 2;
}
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;
$this->task['id_group'] = $id_group;
$this->task['interval_sweep'] = $interval;
if (isset($this->task['id_rt']) === false) {
// Create.
$this->task['id_rt'] = db_process_sql_insert(
'trecon_task',
$this->task
);
if ($task_id !== null
&& $taskname == null
&& $server_id == null
&& $id_group == null
&& $server == null
&& $datacenter == ''
&& $user == ''
&& $pass == ''
&& $encrypt == null
&& $interval == 0
) {
// Default values, no data received.
// User is accesing directly to this page.
if (users_is_admin() !== true && check_acl(
$config['id_usuario'],
$this->task['id_group'],
'PM'
) !== true
) {
$this->msg = __('You have no access to edit this task.');
return false;
}
} else {
// Update.
db_process_sql_update(
'trecon_task',
$this->task,
['id_rt' => $this->task['id_rt']]
);
if (isset($this->task['id_rt']) === false) {
// Disabled 2 Implies wizard non finished.
$this->task['disabled'] = 2;
}
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;
$this->task['id_group'] = $id_group;
$this->task['interval_sweep'] = $interval;
if (isset($this->task['id_rt']) === false) {
// 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;
@ -408,7 +390,6 @@ class HostDevices extends Wizard
}
return false;
}
@ -478,6 +459,25 @@ class HostDevices extends Wizard
return null;
}
$task_url = '';
if (isset($this->task['id_rt'])) {
$task_url = '&task='.$this->task['id_rt'];
}
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,
'label' => $this->pageLabelsNetScan[$i],
'selected' => (($i == $this->page) ? 1 : 0),
];
}
if ($this->page < $this->maxPagesNetScan) {
// Avoid to print header out of wizard.
$this->prepareBreadcrum($breadcrum);
$this->printHeader();
}
if (isset($this->page) === true
&& $this->page != 0
&& isset($this->task['id_rt']) === false
@ -698,7 +698,9 @@ $("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->printGoBackButton(
$this->url.'&page='.($this->page - 1).$task_url
);
}
}

View File

@ -94,3 +94,11 @@ div.data_container:hover {
.arrow_box.selected:before {
border-left-color: #82b92e;
}
.arrow_box {
display: inline-block;
position: relative;
padding: 14px;
margin-left: 20px;
margin-bottom: 10px;
padding-left: 3em;
}

View File

@ -0,0 +1,3 @@
/*
* TODO: This may be at hostdevices.css
*/