WIP: Backup upload

This commit is contained in:
Jose Gonzalez 2020-04-06 09:49:59 +02:00
parent 5c04c6c03b
commit a6ce19db66
2 changed files with 409 additions and 11 deletions

View File

@ -1,5 +1,73 @@
<?php <?php
/**
* Wizard for SNMP / WMI discover.
*
* @category Agent Wizard
* @package Pandora FMS
* @subpackage Opensource
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2020 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.
* ============================================================================
*/
// Begin.
global $config;
// Require needed class.
require_once $config['homedir'].'/include/class/AgentWizard.class.php';
// This page.
hd($_REQUEST);
$ajaxPage = 'godmode/agentes/agent_wizard';
// Control call flow.
try {
// User access and validation is being processed on class constructor.
$obj = new AgentWizard($ajaxPage);
} catch (Exception $e) {
if (is_ajax()) {
echo json_encode(['error' => '[AgentWizard]'.$e->getMessage() ]);
exit;
} else {
echo '[AgentWizard]'.$e->getMessage();
}
// Stop this execution, but continue 'globally'.
return;
}
// AJAX controller.
if (is_ajax()) {
$method = get_parameter('method');
if (method_exists($obj, $method) === true) {
$obj->{$method}();
} else {
$obj->error('Method not found. ['.$method.']');
}
// Stop any execution.
exit;
} else {
// Run.
$obj->run();
}
// OLD. FOR ERASE.
// Pandora FMS - http://pandorafms.com // Pandora FMS - http://pandorafms.com
// ================================================== // ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas // Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
@ -11,15 +79,16 @@
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
global $config; /*
global $config;
check_login(); check_login();
$wizard_section = get_parameter('wizard_section', 'snmp_interfaces_explorer'); $wizard_section = get_parameter('wizard_section', 'snmp_interfaces_explorer');
$idAgent = (int) get_parameter('id_agente', 0); $idAgent = (int) get_parameter('id_agente', 0);
$ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent); $ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
switch ($wizard_section) { switch ($wizard_section) {
case 'snmp_interfaces_explorer': case 'snmp_interfaces_explorer':
$snmp_interfaces_explorer_style = 'font-weight: bold;'; $snmp_interfaces_explorer_style = 'font-weight: bold;';
$wmi_explorer_style = ''; $wmi_explorer_style = '';
@ -34,9 +103,9 @@ switch ($wizard_section) {
$snmp_interfaces_explorer_style = ''; $snmp_interfaces_explorer_style = '';
$wmi_explorer_style = 'font-weight: bold;'; $wmi_explorer_style = 'font-weight: bold;';
break; break;
} }
/* /*
echo "<div style='text-align: right; width: 98%; padding-top: 10px; padding-bottom: 10px;'>"; echo "<div style='text-align: right; width: 98%; padding-top: 10px; padding-bottom: 10px;'>";
echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$idAgent' style='" . $snmp_interfaces_explorer_style . "'>" . __('SNMP Interfaces explorer') . "</a>"; echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$idAgent' style='" . $snmp_interfaces_explorer_style . "'>" . __('SNMP Interfaces explorer') . "</a>";
echo " | "; echo " | ";
@ -44,11 +113,11 @@ switch ($wizard_section) {
echo "</div>"; echo "</div>";
*/ */
require 'agent_wizard.'.$wizard_section.'.php'; // require 'agent_wizard.'.$wizard_section.'.php';
?> ?>
<script language="javascript" type="text/javascript">
<script language="javascript" type="text/javascript">
/*
function satellite_remote_warn(id_satellite, remote) function satellite_remote_warn(id_satellite, remote)
{ {
if(!remote) if(!remote)

View File

@ -0,0 +1,329 @@
<?php
/**
* Agent Wizard for SNMP and WMI
*
* @category Class
* @package Pandora FMS
* @subpackage Agent Configuration
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2020 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.
* ============================================================================
*/
// Get global data.
global $config;
// Necessary class for extends.
require_once $config['homedir'].'/include/class/HTML.class.php';
/**
* AgentWizard class
*/
class AgentWizard extends HTML
{
/**
* Var that contain very cool stuff
*
* @var string
*/
private $ajaxController;
/**
* Contains the URL of this
*
* @var string
*/
private $baseUrl;
/**
* Id of this current agent
*
* @var integer
*/
private $idAgent;
/**
* Wizard Section (SNMP or WMI)
*
* @var string
*/
private $wizardSection;
/**
* Constructor
*
* @param string $ajax_controller Pues hace cosas to wapas.
*/
public function __construct(string $ajax_controller)
{
global $config;
// Check access.
check_login();
if (! check_acl($config['id_user'], 0, 'AR')) {
db_pandora_audit(
'ACL Violation',
'Trying to access event viewer'
);
if (is_ajax()) {
echo json_encode(['error' => 'noaccess']);
}
include 'general/noaccess.php';
exit;
}
// Set baseUrl for use it in several locations in this class.
$this->baseUrl = ui_get_full_url('index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard');
// Capture all parameters before start.
$this->ajaxController = $ajax_controller;
$this->wizardSection = get_parameter('wizard_section', '');
$this->idAgent = get_parameter('id_agente', '');
return $this;
}
/**
* Run main page.
*
* @return void
*/
public function run()
{
// CSS.
ui_require_css_file('wizard');
ui_require_css_file('discovery');
// Javascript.
// ui_require_javascript_file('jquery.caret.min');
$this->loadMainForm();
// Load integrated JS
$this->loadJS();
}
/**
* Common Main Wizard form
*
* @return void
*/
private function loadMainForm()
{
// Define name of explorer button
if ($this->wizardSection === 'snmp_explorer') {
$btnActionLabel = __('SNMP Walk');
} else if ($this->wizardSection === 'wmi_explorer') {
$btnActionLabel = __('WMI Explorer');
} else {
$btnActionLabel = 'Nothing';
}
// Fill with servers to perform SNMP walk.
$fieldsServers = [
'Local',
'Network',
];
// Fill with SNMP versions allowed.
$fieldsVersions = [
'1',
'2c',
'3',
];
// Main form.
$form = [
'action' => $this->baseUrl,
'id' => 'main_wizard_form',
'method' => 'POST',
'class' => 'discovery databox filters',
'extra' => '',
];
// Inputs.
$inputs = [];
$inputs[] = [
'id' => 'inp-id_np',
'arguments' => [
'name' => 'id_np',
'type' => 'hidden',
'value' => $this->id_np,
'return' => true,
],
];
$inputs[] = [
'label' => __('Target IP'),
'id' => 'txt-target-ip',
'arguments' => [
'name' => 'target-ip',
'input_class' => 'flex-row',
'type' => 'text',
'class' => '',
'return' => true,
],
];
$inputs[] = [
'label' => __('Port'),
'id' => 'txt-target-port',
'arguments' => [
'name' => 'target-port',
'input_class' => 'flex-row',
'type' => 'text',
'size' => '20',
'class' => '',
'return' => true,
],
];
if ($this->wizardSection === 'snmp_explorer') {
$inputs[] = [
'label' => __('Use agent IP'),
'id' => 'txt-use-agent-ip',
'arguments' => [
'name' => 'use-agent-ip',
'input_class' => 'flex-row',
'type' => 'checkbox',
'class' => '',
'return' => true,
],
];
}
if ($this->wizardSection === 'wmi_explorer') {
$inputs[] = [
'label' => __('Namespace'),
'id' => 'txt-namespace',
'arguments' => [
'name' => 'namespace',
'input_class' => 'flex-row',
'type' => 'text',
'class' => '',
'return' => true,
],
];
$inputs[] = [
'label' => __('Username'),
'id' => 'txt-username',
'arguments' => [
'name' => 'username',
'input_class' => 'flex-row',
'type' => 'text',
'class' => '',
'return' => true,
],
];
$inputs[] = [
'label' => __('Password'),
'id' => 'txt-password',
'arguments' => [
'name' => 'password',
'input_class' => 'flex-row',
'type' => 'text',
'class' => '',
'return' => true,
],
];
}
$inputs[] = [
'label' => __('Server to execute command'),
'id' => 'txt-target-port',
'arguments' => [
'name' => 'target-port',
'input_class' => 'flex-row',
'type' => 'select',
'fields' => $fieldsServers,
'class' => '',
'return' => true,
],
];
if ($this->wizardSection === 'snmp_explorer') {
$inputs[] = [
'label' => __('SNMP community'),
'id' => 'txt-snmp-community',
'arguments' => [
'name' => 'snmp-community',
'input_class' => 'flex-row',
'type' => 'text',
'size' => '20',
'class' => '',
'return' => true,
],
];
$inputs[] = [
'label' => __('SNMP version'),
'id' => 'txt-snmnp-version',
'arguments' => [
'name' => 'snmnp-version',
'input_class' => 'flex-row',
'type' => 'select',
'fields' => $fieldsVersions,
'class' => '',
'return' => true,
],
];
}
$inputs[] = [
'arguments' => [
'label' => $btnActionLabel,
'name' => 'action',
'type' => 'button',
'attributes' => 'class="sub next"',
'return' => true,
],
];
$this->printForm(
[
'form' => $form,
'inputs' => $inputs,
]
);
}
/**
* Generate the JS needed for use inside
*
* @return void
*/
private function loadJS()
{
$str = '';
ob_start();
?>
<script type="text/javascript">
// The functions goes here!
</script>
<?php
$str = ob_get_clean();
echo $str;
return $str;
}
}