2013-07-08 Sergio Martin <sergio.martin@artica.es>
* include/javascript/pandora_modules.js include/functions_wmi.php extensions/snmp_explorer.php godmode/agentes/agent_wizard.wmi_explorer.php godmode/agentes/agent_wizard.snmp_interfaces_explorer.php godmode/agentes/agent_wizard.php godmode/agentes/configurar_agente.php: Replace the SNMP explorer by the Agent wizard with two initial sections. SNMP interfaces explorer and WMI explorer git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8495 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
eebc24e2a5
commit
6e994d796b
|
@ -1,3 +1,15 @@
|
|||
2013-07-08 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* include/javascript/pandora_modules.js
|
||||
include/functions_wmi.php
|
||||
extensions/snmp_explorer.php
|
||||
godmode/agentes/agent_wizard.wmi_explorer.php
|
||||
godmode/agentes/agent_wizard.snmp_interfaces_explorer.php
|
||||
godmode/agentes/agent_wizard.php
|
||||
godmode/agentes/configurar_agente.php: Replace the SNMP explorer by
|
||||
the Agent wizard with two initial sections. SNMP interfaces explorer
|
||||
and WMI explorer
|
||||
|
||||
2013-07-08 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* mobile/operation/modules.php, mobile/include/style/main.css:
|
||||
|
|
|
@ -1,485 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
global $config;
|
||||
include_once($config['homedir'] . "/include/functions_agents.php");
|
||||
require_once ('include/functions_modules.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
require_once ('include/functions_reporting.php');
|
||||
require_once ('include/graphs/functions_utils.php');
|
||||
|
||||
function snmp_explorer() {
|
||||
|
||||
$idAgent = (int) get_parameter('id_agente', 0);
|
||||
$ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
|
||||
|
||||
// Load global vars
|
||||
global $config;
|
||||
|
||||
|
||||
check_login ();
|
||||
|
||||
$ip_target = (string) get_parameter ('ip_target', $ipAgent);
|
||||
$snmp_community = (string) get_parameter ('snmp_community', 'public');
|
||||
$snmp_version = get_parameter('snmp_version', '1');
|
||||
$snmp3_auth_user = get_parameter('snmp3_auth_user');
|
||||
$snmp3_security_level = get_parameter('snmp3_security_level');
|
||||
$snmp3_auth_method = get_parameter('snmp3_auth_method');
|
||||
$snmp3_auth_pass = get_parameter('snmp3_auth_pass');
|
||||
$snmp3_privacy_method = get_parameter('snmp3_privacy_method');
|
||||
$snmp3_privacy_pass = get_parameter('snmp3_privacy_pass');
|
||||
$tcp_port = (string) get_parameter ('tcp_port');
|
||||
|
||||
//See if id_agente is set (either POST or GET, otherwise -1
|
||||
$id_agent = $idAgent;
|
||||
|
||||
// Get passed variables
|
||||
$snmpwalk = (int) get_parameter("snmpwalk", 0);
|
||||
$create_modules = (int) get_parameter("create_modules", 0);
|
||||
|
||||
$interfaces = array();
|
||||
|
||||
if ($snmpwalk) {
|
||||
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.2", $tcp_port);
|
||||
|
||||
if ($snmpis === false) {
|
||||
$snmpis = array();
|
||||
}
|
||||
|
||||
$interfaces = array();
|
||||
|
||||
// We get here only the interface part of the MIB, not full mib
|
||||
foreach($snmpis as $key => $snmp) {
|
||||
|
||||
$data = explode(': ',$snmp);
|
||||
$keydata = explode('::',$key);
|
||||
$keydata2 = explode('.',$keydata[1]);
|
||||
|
||||
// Avoid results without index and interfaces without name
|
||||
if (!isset($keydata2[1]) || !isset($data[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (array_key_exists(1,$data)) {
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['type'] = $data[0];
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[1];
|
||||
}
|
||||
else {
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['type'] = '';
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[0];
|
||||
}
|
||||
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['oid'] = $key;
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['checked'] = 0;
|
||||
}
|
||||
|
||||
unset($interfaces[0]);
|
||||
}
|
||||
|
||||
if ($create_modules) {
|
||||
$id_snmp_serialize = get_parameter_post('id_snmp_serialize');
|
||||
$interfaces = unserialize_in_temp($id_snmp_serialize);
|
||||
|
||||
if (!$interfaces) {
|
||||
$interfaces = array();
|
||||
}
|
||||
|
||||
$values = array();
|
||||
|
||||
if ($tcp_port != '') {
|
||||
$values['tcp_port'] = $tcp_port;
|
||||
}
|
||||
$values['snmp_community'] = $snmp_community;
|
||||
$values['ip_target'] = $ip_target;
|
||||
$values['tcp_send'] = $snmp_version;
|
||||
|
||||
if ($snmp_version == '3') {
|
||||
$values['plugin_user'] = $snmp3_auth_user;
|
||||
$values['plugin_pass'] = $snmp3_auth_pass;
|
||||
$values['plugin_parameter'] = $snmp3_auth_method;
|
||||
$values['custom_string_1'] = $snmp3_privacy_method;
|
||||
$values['custom_string_2'] = $snmp3_privacy_pass;
|
||||
$values['custom_string_3'] = $snmp3_security_level;
|
||||
}
|
||||
|
||||
$oids = array();
|
||||
foreach ($interfaces as $key => $interface) {
|
||||
foreach ($interface as $key2 => $module) {
|
||||
$oid = get_parameter($key."-".$key2, '');
|
||||
if ($oid != '') {
|
||||
$interfaces[$key][$key2]['checked'] = 1;
|
||||
$oids[$key][] = $interfaces[$key][$key2]['oid'];
|
||||
}
|
||||
else {
|
||||
$interfaces[$key][$key2]['checked'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$modules = get_parameter('module', array());
|
||||
$id_snmp = get_parameter('id_snmp');
|
||||
|
||||
if ($id_snmp == false) {
|
||||
ui_print_error_message (__('No modules selected'));
|
||||
$id_snmp = array();
|
||||
}
|
||||
|
||||
if (agents_get_name($id_agent) == false) {
|
||||
ui_print_error_message (__('No agent selected or the agent does not exist'));
|
||||
$id_snmp = array();
|
||||
}
|
||||
|
||||
$result = false;
|
||||
|
||||
$errors = array();
|
||||
$done = 0;
|
||||
|
||||
foreach ($id_snmp as $id) {
|
||||
if (isset($interfaces[$id]['ifName']) && $interfaces[$id]['ifName']['value'] != "") {
|
||||
$ifname = $interfaces[$id]['ifName']['value'];
|
||||
}
|
||||
else if (isset($interfaces[$id]['ifDescr']) && $interfaces[$id]['ifDescr']['value'] != "") {
|
||||
$ifname = $interfaces[$id]['ifDescr']['value'];
|
||||
}
|
||||
foreach ($modules as $module) {
|
||||
$oid_array = explode('.',$module);
|
||||
$oid_array[count($oid_array)-1] = $id;
|
||||
$oid = implode('.',$oid_array);
|
||||
|
||||
// Get the name
|
||||
$name_array = explode('::',$oid_array[0]);
|
||||
$name = $name_array[1] . "_" . $ifname;
|
||||
|
||||
// Clean the name
|
||||
$name = str_replace ( "\"" , "" , $name);
|
||||
|
||||
// Proc moduletypes
|
||||
if (preg_match ( "/Status/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
elseif (preg_match ( "/Present/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
elseif (preg_match ( "/PromiscuousMode/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
// String moduletypes
|
||||
elseif (preg_match ( "/Alias/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Address/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Name/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Specific/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Descr/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
// Specific counters (ends in s)
|
||||
elseif (preg_match ( "/s$/", $name_array[1]))
|
||||
$module_type = 16;
|
||||
|
||||
// Otherwise, numeric
|
||||
else
|
||||
$module_type = 15;
|
||||
|
||||
$values['id_tipo_modulo'] = $module_type;
|
||||
$values['descripcion'] = io_safe_input("(" . $ip_target." - ".$name . ") " . $interfaces[$id]['ifDescr']['value']);
|
||||
|
||||
$values['snmp_oid'] = $oid;
|
||||
$values['id_modulo'] = 2;
|
||||
|
||||
$result = modules_create_agent_module ($id_agent, io_safe_input($name), $values);
|
||||
|
||||
if (is_error($result)) {
|
||||
if (!isset($errors[$result])) {
|
||||
$errors[$result] = 0;
|
||||
}
|
||||
$errors[$result]++;
|
||||
}
|
||||
else {
|
||||
$done++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($done > 0) {
|
||||
ui_print_success_message(__('Successfully modules created')." ($done)");
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$msg = __('Could not be created').':';
|
||||
|
||||
|
||||
foreach ($errors as $code => $number) {
|
||||
switch ($code) {
|
||||
case ERR_EXIST:
|
||||
$msg .= '<br>'.__('Another module already exists with the same name')." ($number)";
|
||||
break;
|
||||
case ERR_INCOMPLETE:
|
||||
$msg .= '<br>'.__('Some required fields are missed').': ('.__('name').') '." ($number)";
|
||||
break;
|
||||
case ERR_DB:
|
||||
case ERR_GENERIC:
|
||||
default:
|
||||
$msg .= '<br>'.__('Processing error')." ($number)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ui_print_error_message($msg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Create the interface list for the interface
|
||||
$interfaces_list = array();
|
||||
foreach ($interfaces as $interface) {
|
||||
// Get the interface name, removing " " characters and avoid "blank" interfaces
|
||||
if (isset($interface['ifName']) && $interface['ifName']['value'] != "") {
|
||||
$ifname = $interface['ifName']['value'];
|
||||
}
|
||||
else if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != "") {
|
||||
$ifname = $interface['ifDescr']['value'];
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$interfaces_list[$interface['ifIndex']['value']] = str_replace ( "\"" , "" , $ifname);
|
||||
}
|
||||
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' id='walk_form' action='index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=extension&id_agente=$id_agent&id_extension=snmp_explorer'>";
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
$table->data[0][0] = '<b>' . __('Target IP') . '</b>';
|
||||
$table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true);
|
||||
|
||||
$table->data[0][2] = '<b>' . __('Port') . '</b>';
|
||||
$table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true);
|
||||
|
||||
$snmp_versions['1'] = 'v. 1';
|
||||
$snmp_versions['2'] = 'v. 2';
|
||||
$snmp_versions['2c'] = 'v. 2c';
|
||||
$snmp_versions['3'] = 'v. 3';
|
||||
|
||||
$table->data[1][0] = '<b>' . __('SNMP community') . '</b>';
|
||||
$table->data[1][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true);
|
||||
|
||||
$table->data[1][2] = '<b>' . _('SNMP version') . '</b>';
|
||||
$table->data[1][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, '');
|
||||
|
||||
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
|
||||
html_print_input_hidden('snmpwalk', 1);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
unset($table);
|
||||
|
||||
//SNMP3 OPTIONS
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
$table->data[2][1] = '<b>'.__('Auth user').'</b>';
|
||||
$table->data[2][2] = html_print_input_text ('snmp3_auth_user', $snmp3_auth_user, '', 15, 60, true);
|
||||
$table->data[2][3] = '<b>'.__('Auth password').'</b>';
|
||||
$table->data[2][4] = html_print_input_text ('snmp3_auth_pass', $snmp3_auth_pass, '', 15, 60, true);
|
||||
$table->data[2][4] .= html_print_input_hidden('active_snmp_v3', 0, true);
|
||||
|
||||
$table->data[5][0] = '<b>'.__('Privacy method').'</b>';
|
||||
$table->data[5][1] = html_print_select(array('DES' => __('DES'), 'AES' => __('AES')), 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true);
|
||||
$table->data[5][2] = '<b>'.__('privacy pass').'</b>';
|
||||
$table->data[5][3] = html_print_input_text ('snmp3_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true);
|
||||
|
||||
$table->data[6][0] = '<b>'.__('Auth method').'</b>';
|
||||
$table->data[6][1] = html_print_select(array('MD5' => __('MD5'), 'SHA' => __('SHA')), 'snmp3_auth_method', $snmp3_auth_method, '', '', '', true);
|
||||
$table->data[6][2] = '<b>'.__('Security level').'</b>';
|
||||
$table->data[6][3] = html_print_select(array('noAuthNoPriv' => __('Not auth and not privacy method'),
|
||||
'authNoPriv' => __('Auth and not privacy method'), 'authPriv' => __('Auth and privacy method')), 'snmp3_security_level', $snmp3_security_level, '', '', '', true);
|
||||
|
||||
if ($snmp_version == 3) {
|
||||
echo '<div id="snmp3_options">';
|
||||
}
|
||||
else {
|
||||
echo '<div id="snmp3_options" style="display: none;">';
|
||||
}
|
||||
html_print_table($table);
|
||||
echo '</div>';
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
echo '<span id="oid_loading" class="invisible">' . html_print_image("images/spinner.gif", true) . '</span>';
|
||||
html_print_submit_button(__('SNMP Walk'), 'snmp_walk', false, array('class' => 'sub next'));
|
||||
echo "</div>";
|
||||
|
||||
if ($snmpwalk && !$snmpis) {
|
||||
echo '<span id="no_snmp" style="margin-left:50px" class="error">'.__('Unable to do SNMP walk').'</span>';
|
||||
}
|
||||
|
||||
unset($table);
|
||||
|
||||
echo "</form>";
|
||||
|
||||
if (!empty($interfaces_list)) {
|
||||
echo '<span id="form_interfaces">';
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' action='index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=extension&id_agente=$id_agent&id_extension=snmp_explorer'>";
|
||||
|
||||
$id_snmp_serialize = serialize_in_temp($interfaces, $config['id_user']."_snmp");
|
||||
html_print_input_hidden('id_snmp_serialize', $id_snmp_serialize);
|
||||
|
||||
html_print_input_hidden('create_modules', 1);
|
||||
html_print_input_hidden('ip_target', $ip_target);
|
||||
html_print_input_hidden('tcp_port', $tcp_port);
|
||||
html_print_input_hidden('snmp_community', $snmp_community);
|
||||
html_print_input_hidden('snmp_version', $snmp_version);
|
||||
html_print_input_hidden('snmp3_auth_user', $snmp3_auth_user);
|
||||
html_print_input_hidden('snmp3_auth_pass', $snmp3_auth_pass);
|
||||
html_print_input_hidden('snmp3_auth_method', $snmp3_auth_method);
|
||||
html_print_input_hidden('snmp3_privacy_method', $snmp3_privacy_method);
|
||||
html_print_input_hidden('snmp3_privacy_pass', $snmp3_privacy_pass);
|
||||
html_print_input_hidden('snmp3_security_level', $snmp3_security_level);
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
//Agent selector
|
||||
$table->data[0][0] = '<b>'.__('Interfaces').'</b>';
|
||||
$table->data[0][1] = '';
|
||||
$table->data[0][2] = '<b>'.__('Modules').'</b>';
|
||||
|
||||
$table->data[1][0] = html_print_select ($interfaces_list, 'id_snmp[]', 0, false, '', '', true, true, true, '', false, 'width:200px;');
|
||||
$table->data[1][1] = html_print_image('images/darrowright.png', true);
|
||||
$table->data[1][2] = html_print_select (array (), 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:200px;');
|
||||
$table->data[1][2] .= html_print_input_hidden('agent', $id_agent, true);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
html_print_submit_button(__('Create modules'), '', false, array('class' => 'sub add'));
|
||||
echo "</div>";
|
||||
unset($table);
|
||||
|
||||
echo "</form>";
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
ui_require_jquery_file ('pandora.controls');
|
||||
ui_require_jquery_file ('ajaxqueue');
|
||||
ui_require_jquery_file ('bgiframe');
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
|
||||
$(document).ready (function () {
|
||||
var inputActive = true;
|
||||
|
||||
$(document).data('text_for_module', $("#none_text").html());
|
||||
|
||||
$("#id_snmp").change(snmp_changed_by_multiple_snmp);
|
||||
|
||||
$("#snmp_version").change(function () {
|
||||
if (this.value == "3") {
|
||||
$("#snmp3_options").css("display", "");
|
||||
}
|
||||
else {
|
||||
$("#snmp3_options").css("display", "none");
|
||||
}
|
||||
});
|
||||
|
||||
$("#walk_form").submit(function() {
|
||||
$("#submit-snmp_walk").disable ();
|
||||
$("#oid_loading").show ();
|
||||
$("#no_snmp").hide ();
|
||||
$("#form_interfaces").hide ();
|
||||
});
|
||||
});
|
||||
|
||||
function snmp_changed_by_multiple_snmp (event, id_snmp, selected) {
|
||||
var idSNMP = Array();
|
||||
|
||||
jQuery.each ($("#id_snmp option:selected"), function (i, val) {
|
||||
idSNMP.push($(val).val());
|
||||
});
|
||||
$('#module').attr ('disabled', 1);
|
||||
$('#module').empty ();
|
||||
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
|
||||
|
||||
jQuery.post ('ajax.php',
|
||||
{"page" : "godmode/agentes/agent_manager",
|
||||
"get_modules_json_for_multiple_snmp": 1,
|
||||
"id_snmp[]": idSNMP,
|
||||
"id_snmp_serialize": $("#hidden-id_snmp_serialize").val()
|
||||
},
|
||||
function (data) {
|
||||
$('#module').empty ();
|
||||
c = 0;
|
||||
jQuery.each (data, function (i, val) {
|
||||
s = js_html_entity_decode(val);
|
||||
$('#module').append ($('<option></option>').html (s).attr ("value", i));
|
||||
$('#module').fadeIn ('normal');
|
||||
c++;
|
||||
});
|
||||
|
||||
if (c == 0) {
|
||||
if (typeof($(document).data('text_for_module')) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html ($(document).data('text_for_module')).attr("value", 0).attr('selected', true));
|
||||
}
|
||||
else {
|
||||
if (typeof(data['any_text']) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html (data['any_text']).attr ("value", 0).attr('selected', true));
|
||||
}
|
||||
else {
|
||||
var anyText = $("#any_text").html(); //Trick for catch the translate text.
|
||||
|
||||
if (anyText == null) {
|
||||
anyText = 'Any';
|
||||
}
|
||||
|
||||
$('#module').append ($('<option></option>').html (anyText).attr ("value", 0).attr('selected', true));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected != undefined)
|
||||
$('#module').attr ('value', selected);
|
||||
$('#module').removeAttr('disabled');
|
||||
},
|
||||
"json");
|
||||
}
|
||||
|
||||
/* ]]> */
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
extensions_add_godmode_tab_agent('snmp_explorer', __('SNMP Explorer'), 'images/snmp_wizard.png', 'snmp_explorer', "v1r1");
|
||||
?>
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
$wizard_section = get_parameter('wizard_section', 'snmp_interfaces_explorer');
|
||||
$idAgent = (int) get_parameter('id_agente', 0);
|
||||
$ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
|
||||
|
||||
switch($wizard_section) {
|
||||
case 'snmp_interfaces_explorer':
|
||||
$snmp_interfaces_explorer_style = 'font-weight: bold;';
|
||||
$wmi_explorer_style = '';
|
||||
break;
|
||||
case 'wmi_explorer':
|
||||
$snmp_interfaces_explorer_style = '';
|
||||
$wmi_explorer_style = 'font-weight: bold;';
|
||||
break;
|
||||
}
|
||||
|
||||
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 " | ";
|
||||
echo "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=wmi_explorer&id_agente=$idAgent' style='" . $wmi_explorer_style . "'>" . __('WMI explorer') . "</a>";
|
||||
echo "</div>";
|
||||
|
||||
require("agent_wizard." . $wizard_section . ".php");
|
||||
|
||||
?>
|
|
@ -0,0 +1,475 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
global $config;
|
||||
include_once($config['homedir'] . "/include/functions_agents.php");
|
||||
require_once ('include/functions_modules.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
require_once ('include/functions_reporting.php');
|
||||
require_once ('include/graphs/functions_utils.php');
|
||||
|
||||
|
||||
$idAgent = (int) get_parameter('id_agente', 0);
|
||||
$ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
|
||||
|
||||
check_login ();
|
||||
|
||||
$ip_target = (string) get_parameter ('ip_target', $ipAgent);
|
||||
$snmp_community = (string) get_parameter ('snmp_community', 'public');
|
||||
$snmp_version = get_parameter('snmp_version', '1');
|
||||
$snmp3_auth_user = get_parameter('snmp3_auth_user');
|
||||
$snmp3_security_level = get_parameter('snmp3_security_level');
|
||||
$snmp3_auth_method = get_parameter('snmp3_auth_method');
|
||||
$snmp3_auth_pass = get_parameter('snmp3_auth_pass');
|
||||
$snmp3_privacy_method = get_parameter('snmp3_privacy_method');
|
||||
$snmp3_privacy_pass = get_parameter('snmp3_privacy_pass');
|
||||
$tcp_port = (string) get_parameter ('tcp_port');
|
||||
|
||||
//See if id_agente is set (either POST or GET, otherwise -1
|
||||
$id_agent = $idAgent;
|
||||
|
||||
// Get passed variables
|
||||
$snmpwalk = (int) get_parameter("snmpwalk", 0);
|
||||
$create_modules = (int) get_parameter("create_modules", 0);
|
||||
|
||||
$interfaces = array();
|
||||
|
||||
if ($snmpwalk) {
|
||||
|
||||
$snmpis = get_snmpwalk($ip_target, $snmp_version, $snmp_community, $snmp3_auth_user,
|
||||
$snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass,
|
||||
$snmp3_privacy_method, $snmp3_privacy_pass, 0, ".1.3.6.1.2.1.2", $tcp_port);
|
||||
|
||||
if ($snmpis === false) {
|
||||
$snmpis = array();
|
||||
}
|
||||
|
||||
$interfaces = array();
|
||||
|
||||
// We get here only the interface part of the MIB, not full mib
|
||||
foreach($snmpis as $key => $snmp) {
|
||||
|
||||
$data = explode(': ',$snmp);
|
||||
$keydata = explode('::',$key);
|
||||
$keydata2 = explode('.',$keydata[1]);
|
||||
|
||||
// Avoid results without index and interfaces without name
|
||||
if (!isset($keydata2[1]) || !isset($data[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (array_key_exists(1,$data)) {
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['type'] = $data[0];
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[1];
|
||||
}
|
||||
else {
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['type'] = '';
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['value'] = $data[0];
|
||||
}
|
||||
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['oid'] = $key;
|
||||
$interfaces[$keydata2[1]][$keydata2[0]]['checked'] = 0;
|
||||
}
|
||||
|
||||
unset($interfaces[0]);
|
||||
}
|
||||
|
||||
if ($create_modules) {
|
||||
$id_snmp_serialize = get_parameter_post('id_snmp_serialize');
|
||||
$interfaces = unserialize_in_temp($id_snmp_serialize);
|
||||
|
||||
if (!$interfaces) {
|
||||
$interfaces = array();
|
||||
}
|
||||
|
||||
$values = array();
|
||||
|
||||
if ($tcp_port != '') {
|
||||
$values['tcp_port'] = $tcp_port;
|
||||
}
|
||||
$values['snmp_community'] = $snmp_community;
|
||||
$values['ip_target'] = $ip_target;
|
||||
$values['tcp_send'] = $snmp_version;
|
||||
|
||||
if ($snmp_version == '3') {
|
||||
$values['plugin_user'] = $snmp3_auth_user;
|
||||
$values['plugin_pass'] = $snmp3_auth_pass;
|
||||
$values['plugin_parameter'] = $snmp3_auth_method;
|
||||
$values['custom_string_1'] = $snmp3_privacy_method;
|
||||
$values['custom_string_2'] = $snmp3_privacy_pass;
|
||||
$values['custom_string_3'] = $snmp3_security_level;
|
||||
}
|
||||
|
||||
$oids = array();
|
||||
foreach ($interfaces as $key => $interface) {
|
||||
foreach ($interface as $key2 => $module) {
|
||||
$oid = get_parameter($key."-".$key2, '');
|
||||
if ($oid != '') {
|
||||
$interfaces[$key][$key2]['checked'] = 1;
|
||||
$oids[$key][] = $interfaces[$key][$key2]['oid'];
|
||||
}
|
||||
else {
|
||||
$interfaces[$key][$key2]['checked'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$modules = get_parameter('module', array());
|
||||
$id_snmp = get_parameter('id_snmp');
|
||||
|
||||
if ($id_snmp == false) {
|
||||
ui_print_error_message (__('No modules selected'));
|
||||
$id_snmp = array();
|
||||
}
|
||||
|
||||
if (agents_get_name($id_agent) == false) {
|
||||
ui_print_error_message (__('No agent selected or the agent does not exist'));
|
||||
$id_snmp = array();
|
||||
}
|
||||
|
||||
$result = false;
|
||||
|
||||
$errors = array();
|
||||
$done = 0;
|
||||
|
||||
foreach ($id_snmp as $id) {
|
||||
if (isset($interfaces[$id]['ifName']) && $interfaces[$id]['ifName']['value'] != "") {
|
||||
$ifname = $interfaces[$id]['ifName']['value'];
|
||||
}
|
||||
else if (isset($interfaces[$id]['ifDescr']) && $interfaces[$id]['ifDescr']['value'] != "") {
|
||||
$ifname = $interfaces[$id]['ifDescr']['value'];
|
||||
}
|
||||
foreach ($modules as $module) {
|
||||
$oid_array = explode('.',$module);
|
||||
$oid_array[count($oid_array)-1] = $id;
|
||||
$oid = implode('.',$oid_array);
|
||||
|
||||
// Get the name
|
||||
$name_array = explode('::',$oid_array[0]);
|
||||
$name = $name_array[1] . "_" . $ifname;
|
||||
|
||||
// Clean the name
|
||||
$name = str_replace ( "\"" , "" , $name);
|
||||
|
||||
// Proc moduletypes
|
||||
if (preg_match ( "/Status/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
elseif (preg_match ( "/Present/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
elseif (preg_match ( "/PromiscuousMode/", $name_array[1]))
|
||||
$module_type = 18;
|
||||
|
||||
// String moduletypes
|
||||
elseif (preg_match ( "/Alias/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Address/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Name/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Specific/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
elseif (preg_match ( "/Descr/", $name_array[1]))
|
||||
$module_type = 17;
|
||||
|
||||
// Specific counters (ends in s)
|
||||
elseif (preg_match ( "/s$/", $name_array[1]))
|
||||
$module_type = 16;
|
||||
|
||||
// Otherwise, numeric
|
||||
else
|
||||
$module_type = 15;
|
||||
|
||||
$values['id_tipo_modulo'] = $module_type;
|
||||
$values['descripcion'] = io_safe_input("(" . $ip_target." - ".$name . ") " . $interfaces[$id]['ifDescr']['value']);
|
||||
|
||||
$values['snmp_oid'] = $oid;
|
||||
$values['id_modulo'] = 2;
|
||||
|
||||
$result = modules_create_agent_module ($id_agent, io_safe_input($name), $values);
|
||||
|
||||
if (is_error($result)) {
|
||||
if (!isset($errors[$result])) {
|
||||
$errors[$result] = 0;
|
||||
}
|
||||
$errors[$result]++;
|
||||
}
|
||||
else {
|
||||
$done++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($done > 0) {
|
||||
ui_print_success_message(__('Successfully modules created')." ($done)");
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$msg = __('Could not be created').':';
|
||||
|
||||
|
||||
foreach ($errors as $code => $number) {
|
||||
switch ($code) {
|
||||
case ERR_EXIST:
|
||||
$msg .= '<br>'.__('Another module already exists with the same name')." ($number)";
|
||||
break;
|
||||
case ERR_INCOMPLETE:
|
||||
$msg .= '<br>'.__('Some required fields are missed').': ('.__('name').') '." ($number)";
|
||||
break;
|
||||
case ERR_DB:
|
||||
case ERR_GENERIC:
|
||||
default:
|
||||
$msg .= '<br>'.__('Processing error')." ($number)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ui_print_error_message($msg);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Create the interface list for the interface
|
||||
$interfaces_list = array();
|
||||
foreach ($interfaces as $interface) {
|
||||
// Get the interface name, removing " " characters and avoid "blank" interfaces
|
||||
if (isset($interface['ifName']) && $interface['ifName']['value'] != "") {
|
||||
$ifname = $interface['ifName']['value'];
|
||||
}
|
||||
else if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != "") {
|
||||
$ifname = $interface['ifDescr']['value'];
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$interfaces_list[$interface['ifIndex']['value']] = str_replace ( "\"" , "" , $ifname);
|
||||
}
|
||||
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' id='walk_form' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$id_agent'>";
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
$table->data[0][0] = '<b>' . __('Target IP') . '</b>';
|
||||
$table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true);
|
||||
|
||||
$table->data[0][2] = '<b>' . __('Port') . '</b>';
|
||||
$table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true);
|
||||
|
||||
$snmp_versions['1'] = 'v. 1';
|
||||
$snmp_versions['2'] = 'v. 2';
|
||||
$snmp_versions['2c'] = 'v. 2c';
|
||||
$snmp_versions['3'] = 'v. 3';
|
||||
|
||||
$table->data[1][0] = '<b>' . __('SNMP community') . '</b>';
|
||||
$table->data[1][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true);
|
||||
|
||||
$table->data[1][2] = '<b>' . __('SNMP version') . '</b>';
|
||||
$table->data[1][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, '');
|
||||
|
||||
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
|
||||
html_print_input_hidden('snmpwalk', 1);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
unset($table);
|
||||
|
||||
//SNMP3 OPTIONS
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
$table->data[2][1] = '<b>'.__('Auth user').'</b>';
|
||||
$table->data[2][2] = html_print_input_text ('snmp3_auth_user', $snmp3_auth_user, '', 15, 60, true);
|
||||
$table->data[2][3] = '<b>'.__('Auth password').'</b>';
|
||||
$table->data[2][4] = html_print_input_text ('snmp3_auth_pass', $snmp3_auth_pass, '', 15, 60, true);
|
||||
$table->data[2][4] .= html_print_input_hidden('active_snmp_v3', 0, true);
|
||||
|
||||
$table->data[5][0] = '<b>'.__('Privacy method').'</b>';
|
||||
$table->data[5][1] = html_print_select(array('DES' => __('DES'), 'AES' => __('AES')), 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true);
|
||||
$table->data[5][2] = '<b>'.__('privacy pass').'</b>';
|
||||
$table->data[5][3] = html_print_input_text ('snmp3_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true);
|
||||
|
||||
$table->data[6][0] = '<b>'.__('Auth method').'</b>';
|
||||
$table->data[6][1] = html_print_select(array('MD5' => __('MD5'), 'SHA' => __('SHA')), 'snmp3_auth_method', $snmp3_auth_method, '', '', '', true);
|
||||
$table->data[6][2] = '<b>'.__('Security level').'</b>';
|
||||
$table->data[6][3] = html_print_select(array('noAuthNoPriv' => __('Not auth and not privacy method'),
|
||||
'authNoPriv' => __('Auth and not privacy method'), 'authPriv' => __('Auth and privacy method')), 'snmp3_security_level', $snmp3_security_level, '', '', '', true);
|
||||
|
||||
if ($snmp_version == 3) {
|
||||
echo '<div id="snmp3_options">';
|
||||
}
|
||||
else {
|
||||
echo '<div id="snmp3_options" style="display: none;">';
|
||||
}
|
||||
html_print_table($table);
|
||||
echo '</div>';
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
echo '<span id="oid_loading" class="invisible">' . html_print_image("images/spinner.gif", true) . '</span>';
|
||||
html_print_submit_button(__('SNMP Walk'), 'snmp_walk', false, array('class' => 'sub next'));
|
||||
echo "</div>";
|
||||
|
||||
if ($snmpwalk && !$snmpis) {
|
||||
ui_print_error_message(__('Unable to do SNMP walk'));
|
||||
}
|
||||
|
||||
unset($table);
|
||||
|
||||
echo "</form>";
|
||||
|
||||
if (!empty($interfaces_list)) {
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$id_agent'>";
|
||||
echo '<span id="form_interfaces">';
|
||||
|
||||
$id_snmp_serialize = serialize_in_temp($interfaces, $config['id_user']."_snmp");
|
||||
html_print_input_hidden('id_snmp_serialize', $id_snmp_serialize);
|
||||
|
||||
html_print_input_hidden('create_modules', 1);
|
||||
html_print_input_hidden('ip_target', $ip_target);
|
||||
html_print_input_hidden('tcp_port', $tcp_port);
|
||||
html_print_input_hidden('snmp_community', $snmp_community);
|
||||
html_print_input_hidden('snmp_version', $snmp_version);
|
||||
html_print_input_hidden('snmp3_auth_user', $snmp3_auth_user);
|
||||
html_print_input_hidden('snmp3_auth_pass', $snmp3_auth_pass);
|
||||
html_print_input_hidden('snmp3_auth_method', $snmp3_auth_method);
|
||||
html_print_input_hidden('snmp3_privacy_method', $snmp3_privacy_method);
|
||||
html_print_input_hidden('snmp3_privacy_pass', $snmp3_privacy_pass);
|
||||
html_print_input_hidden('snmp3_security_level', $snmp3_security_level);
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
//Agent selector
|
||||
$table->data[0][0] = '<b>'.__('Interfaces').'</b>';
|
||||
$table->data[0][1] = '';
|
||||
$table->data[0][2] = '<b>'.__('Modules').'</b>';
|
||||
|
||||
$table->data[1][0] = html_print_select ($interfaces_list, 'id_snmp[]', 0, false, '', '', true, true, true, '', false, 'width:200px;');
|
||||
$table->data[1][1] = html_print_image('images/darrowright.png', true);
|
||||
$table->data[1][2] = html_print_select (array (), 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:200px;');
|
||||
$table->data[1][2] .= html_print_input_hidden('agent', $id_agent, true);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
html_print_submit_button(__('Create modules'), '', false, array('class' => 'sub add'));
|
||||
echo "</div>";
|
||||
unset($table);
|
||||
|
||||
echo "</span>";
|
||||
echo "</form>";
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
ui_require_jquery_file ('pandora.controls');
|
||||
ui_require_jquery_file ('ajaxqueue');
|
||||
ui_require_jquery_file ('bgiframe');
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
|
||||
$(document).ready (function () {
|
||||
var inputActive = true;
|
||||
|
||||
$(document).data('text_for_module', $("#none_text").html());
|
||||
|
||||
$("#id_snmp").change(snmp_changed_by_multiple_snmp);
|
||||
|
||||
$("#snmp_version").change(function () {
|
||||
if (this.value == "3") {
|
||||
$("#snmp3_options").css("display", "");
|
||||
}
|
||||
else {
|
||||
$("#snmp3_options").css("display", "none");
|
||||
}
|
||||
});
|
||||
|
||||
$("#walk_form").submit(function() {
|
||||
$("#submit-snmp_walk").disable ();
|
||||
$("#oid_loading").show ();
|
||||
$("#no_snmp").hide ();
|
||||
$("#form_interfaces").hide ();
|
||||
});
|
||||
});
|
||||
|
||||
function snmp_changed_by_multiple_snmp (event, id_snmp, selected) {
|
||||
var idSNMP = Array();
|
||||
|
||||
jQuery.each ($("#id_snmp option:selected"), function (i, val) {
|
||||
idSNMP.push($(val).val());
|
||||
});
|
||||
$('#module').attr ('disabled', 1);
|
||||
$('#module').empty ();
|
||||
$('#module').append ($('<option></option>').html ("Loading...").attr ("value", 0));
|
||||
|
||||
jQuery.post ('ajax.php',
|
||||
{"page" : "godmode/agentes/agent_manager",
|
||||
"get_modules_json_for_multiple_snmp": 1,
|
||||
"id_snmp[]": idSNMP,
|
||||
"id_snmp_serialize": $("#hidden-id_snmp_serialize").val()
|
||||
},
|
||||
function (data) {
|
||||
$('#module').empty ();
|
||||
c = 0;
|
||||
jQuery.each (data, function (i, val) {
|
||||
s = js_html_entity_decode(val);
|
||||
$('#module').append ($('<option></option>').html (s).attr ("value", i));
|
||||
$('#module').fadeIn ('normal');
|
||||
c++;
|
||||
});
|
||||
|
||||
if (c == 0) {
|
||||
if (typeof($(document).data('text_for_module')) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html ($(document).data('text_for_module')).attr("value", 0).attr('selected', true));
|
||||
}
|
||||
else {
|
||||
if (typeof(data['any_text']) != 'undefined') {
|
||||
$('#module').append ($('<option></option>').html (data['any_text']).attr ("value", 0).attr('selected', true));
|
||||
}
|
||||
else {
|
||||
var anyText = $("#any_text").html(); //Trick for catch the translate text.
|
||||
|
||||
if (anyText == null) {
|
||||
anyText = 'Any';
|
||||
}
|
||||
|
||||
$('#module').append ($('<option></option>').html (anyText).attr ("value", 0).attr('selected', true));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selected != undefined)
|
||||
$('#module').attr ('value', selected);
|
||||
$('#module').removeAttr('disabled');
|
||||
},
|
||||
"json");
|
||||
}
|
||||
|
||||
/* ]]> */
|
||||
</script>
|
||||
|
|
@ -0,0 +1,518 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
global $config;
|
||||
include_once($config['homedir'] . "/include/functions_agents.php");
|
||||
require_once ('include/functions_modules.php');
|
||||
require_once ('include/functions_alerts.php');
|
||||
require_once ('include/functions_reporting.php');
|
||||
require_once ('include/functions_network_components.php');
|
||||
require_once ('include/functions_wmi.php');
|
||||
require_once ('include/graphs/functions_utils.php');
|
||||
|
||||
check_login ();
|
||||
|
||||
$ip_target = (string) get_parameter ('ip_target', $ipAgent); // Host
|
||||
$plugin_user = (string) get_parameter ('plugin_user', 'Administrator'); // Username
|
||||
$plugin_pass = get_parameter('plugin_pass', ''); // Password
|
||||
$tcp_send = (string) get_parameter ('tcp_send'); // Namespace
|
||||
|
||||
|
||||
//See if id_agente is set (either POST or GET, otherwise -1
|
||||
$id_agent = $idAgent;
|
||||
|
||||
// Get passed variables
|
||||
$wmiexplore = (int) get_parameter("wmiexplore", 0);
|
||||
$create_modules = (int) get_parameter("create_modules", 0);
|
||||
|
||||
$interfaces = array();
|
||||
|
||||
$wmi_client = 'wmic';
|
||||
|
||||
if ($wmiexplore) {
|
||||
$wmi_command = wmi_compose_query($wmi_client, $plugin_user, $plugin_pass, $ip_target, $tcp_send);
|
||||
|
||||
$processes = array();
|
||||
$services = array();
|
||||
$disks = array();
|
||||
$network_component_groups = array();
|
||||
|
||||
// Processes
|
||||
$wmi_processes = $wmi_command . ' "select Name from Win32_Process"';
|
||||
$processes_name_field = 1;
|
||||
|
||||
exec($wmi_processes, $output);
|
||||
|
||||
$fail = false;
|
||||
if (preg_match('/^Failed/', $output[0])) {
|
||||
$fail = true;
|
||||
}
|
||||
|
||||
if (!$fail) {
|
||||
foreach ($output as $index => $row) {
|
||||
// First and second rows are Class and column names, ignore it
|
||||
if ($index < 2) {
|
||||
continue;
|
||||
}
|
||||
$row_exploded = explode('|', $row);
|
||||
|
||||
if (!in_array($row_exploded[$processes_name_field], $processes)) {
|
||||
$processes[$row_exploded[$processes_name_field]] = $row_exploded[$processes_name_field];
|
||||
}
|
||||
}
|
||||
unset($output);
|
||||
|
||||
// Services
|
||||
$wmi_services = $wmi_command . ' "select Name from Win32_Service"';
|
||||
$services_name_field = 0;
|
||||
$services_check_field = 1;
|
||||
|
||||
exec($wmi_services, $output);
|
||||
|
||||
foreach ($output as $index => $row) {
|
||||
// First and second rows are Class and column names, ignore it
|
||||
if ($index < 2) {
|
||||
continue;
|
||||
}
|
||||
$row_exploded = explode('|', $row);
|
||||
|
||||
if (!in_array($row_exploded[$services_name_field], $services)) {
|
||||
$services[$row_exploded[$services_name_field]] = $row_exploded[$services_name_field];
|
||||
}
|
||||
}
|
||||
unset($output);
|
||||
|
||||
// Disks
|
||||
$wmi_disks = $wmi_command . ' "Select DeviceID from Win32_LogicalDisk"';
|
||||
$disks_name_field = 0;
|
||||
|
||||
exec($wmi_disks, $output);
|
||||
|
||||
foreach ($output as $index => $row) {
|
||||
// First and second rows are Class and column names, ignore it
|
||||
if ($index < 2) {
|
||||
continue;
|
||||
}
|
||||
$row_exploded = explode('|', $row);
|
||||
|
||||
if (!in_array($row_exploded[$disks_name_field], $services)) {
|
||||
$disk_string = sprintf(__('Free space on disk %s'), $row_exploded[$disks_name_field]);
|
||||
$disks[$row_exploded[$disks_name_field]] = $disk_string;
|
||||
}
|
||||
}
|
||||
unset($output);
|
||||
|
||||
// WMI Components
|
||||
$network_component_groups = network_components_get_groups(MODULE_WMI);
|
||||
}
|
||||
}
|
||||
|
||||
if ($create_modules) {
|
||||
$modules = get_parameter("module", array());
|
||||
|
||||
$services = array();
|
||||
$processes = array();
|
||||
$disks = array();
|
||||
$components = array();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
// Split module data to get type
|
||||
$module_exploded = explode('_', $module);
|
||||
$type = $module_exploded[0];
|
||||
|
||||
// Delete type from module data
|
||||
unset($module_exploded[0]);
|
||||
|
||||
// Rebuild module data
|
||||
$module = implode('_', $module_exploded);
|
||||
|
||||
switch($type) {
|
||||
case 'service':
|
||||
$services[] = $module;
|
||||
break;
|
||||
case 'process':
|
||||
$processes[] = $module;
|
||||
break;
|
||||
case 'disk':
|
||||
$disks[] = $module;
|
||||
break;
|
||||
case 'component':
|
||||
$components[] = $module;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Common values for WMI modules
|
||||
$values = array(
|
||||
'ip_target' => $ip_target,
|
||||
'tcp_send' => $tcp_send,
|
||||
'plugin_user' => $plugin_user,
|
||||
'plugin_pass' => $plugin_pass,
|
||||
'id_modulo' => MODULE_WMI);
|
||||
|
||||
// Create Service modules
|
||||
$services_values = $values;
|
||||
|
||||
$services_values['snmp_community'] = 'Running'; // Key string
|
||||
$services_values['tcp_port'] = 1; // Field number (Running/Stopped)
|
||||
$services_values['id_tipo_modulo'] = 2; // Generic boolean
|
||||
|
||||
$services_result = wmi_create_wizard_modules($id_agent, $services, 'services', $services_values);
|
||||
|
||||
// Create Process modules
|
||||
$processes_values = $values;
|
||||
|
||||
$processes_values['tcp_port'] = 0; // Field number (OID)
|
||||
$processes_values['id_tipo_modulo'] = 2; // Generic boolean
|
||||
|
||||
$processes_result = wmi_create_wizard_modules($id_agent, $processes, 'processes', $processes_values);
|
||||
|
||||
// Create Space on disk modules
|
||||
$disks_values = $values;
|
||||
|
||||
$disks_values['tcp_port'] = 1; // Free space in bytes
|
||||
$disks_values['id_tipo_modulo'] = 1; // Generic numeric
|
||||
$disks_values['unit'] = 'Bytes'; // Unit
|
||||
|
||||
$disks_result = wmi_create_wizard_modules($id_agent, $disks, 'disks', $disks_values);
|
||||
|
||||
// Create modules from component
|
||||
$components_values = $values;
|
||||
|
||||
$components_values['id_agente'] = $id_agent;
|
||||
|
||||
$components_result = wmi_create_module_from_components($components, $components_values);
|
||||
|
||||
|
||||
// Errors/Success messages
|
||||
$success_message = '';
|
||||
$error_message = '';
|
||||
if (!empty($services_result)) {
|
||||
if (count($services_result[NOERR]) > 0) {
|
||||
$success_message .= sprintf(__('%s service modules created succesfully'), count($services_result[NOERR])) . '<br>';
|
||||
}
|
||||
if (count($services_result[ERR_GENERIC]) > 0) {
|
||||
$error_message .= sprintf(__('Error creating %s service modules'), count($services_result[ERR_GENERIC])) . '<br>';
|
||||
}
|
||||
}
|
||||
if (!empty($processes_result)) {
|
||||
if (count($processes_result[NOERR]) > 0) {
|
||||
$success_message .= sprintf(__('%s process modules created succesfully'), count($processes_result[NOERR])) . '<br>';
|
||||
}
|
||||
if (count($processes_result[ERR_GENERIC]) > 0) {
|
||||
$error_message .= sprintf(__('Error creating %s process modules'), count($processes_result[ERR_GENERIC])) . '<br>';
|
||||
}
|
||||
}
|
||||
if (!empty($disks_result)) {
|
||||
if (count($disks_result[NOERR]) > 0) {
|
||||
$success_message .= sprintf(__('%s disk space modules created succesfully'), count($disks_result[NOERR])) . '<br>';
|
||||
}
|
||||
if (count($disks_result[ERR_GENERIC]) > 0) {
|
||||
$error_message .= sprintf(__('Error creating %s disk space modules'), count($disks_result[ERR_GENERIC])) . '<br>';
|
||||
}
|
||||
}
|
||||
if (!empty($components_result)) {
|
||||
if (count($components_result[NOERR]) > 0) {
|
||||
$success_message .= sprintf(__('%s modules created from components succesfully'), count($components_result[NOERR])) . '<br>';
|
||||
}
|
||||
if (count($components_result[ERR_GENERIC]) > 0) {
|
||||
$error_message .= sprintf(__('Error creating %s modules from components'), count($components_result[ERR_GENERIC])) . '<br>';
|
||||
}
|
||||
if (count($components_result[ERR_EXIST]) > 0) {
|
||||
$error_message .= sprintf(__('%s modules already exist'), count($components_result[ERR_EXIST])) . '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($success_message)) {
|
||||
ui_print_success_message($success_message);
|
||||
}
|
||||
if (!empty($error_message)) {
|
||||
ui_print_error_message($error_message);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the interface list for the interface
|
||||
$interfaces_list = array();
|
||||
foreach ($interfaces as $interface) {
|
||||
// Get the interface name, removing " " characters and avoid "blank" interfaces
|
||||
if (isset($interface['ifName']) && $interface['ifName']['value'] != "") {
|
||||
$ifname = $interface['ifName']['value'];
|
||||
}
|
||||
else if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != "") {
|
||||
$ifname = $interface['ifDescr']['value'];
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$interfaces_list[$interface['ifIndex']['value']] = str_replace ( "\"" , "" , $ifname);
|
||||
}
|
||||
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' id='wmi_form' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=wmi_explorer&id_agente=$id_agent'>";
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
$table->valign[0] = 'top';
|
||||
$table->valign[1] = 'top';
|
||||
|
||||
$table->data[0][0] = '<b>' . __('Target IP') . '</b>';
|
||||
$table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true);
|
||||
|
||||
$table->data[0][2] = '<b>' . __('Namespace') . '</b>';
|
||||
$table->data[0][2] .= ui_print_help_icon ('wminamespace', true);
|
||||
$table->data[0][3] = html_print_input_text ('tcp_send', $tcp_send, '', 15, 60, true);
|
||||
|
||||
$table->data[1][0] = '<b>' . __('Username') . '</b>';
|
||||
$table->data[1][1] = html_print_input_text ('plugin_user', $plugin_user, '', 15, 60, true);
|
||||
|
||||
$table->data[1][2] = '<b>' . __('Password') . '</b>';
|
||||
$table->data[1][3] = html_print_input_password ('plugin_pass', $plugin_pass, '', 15, 60, true);
|
||||
|
||||
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
|
||||
html_print_input_hidden('wmiexplore', 1);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
echo '<span id="oid_loading" class="invisible">' . html_print_image("images/spinner.gif", true) . '</span>';
|
||||
html_print_submit_button(__('WMI Explore'), 'wmi_explore', false, array('class' => 'sub next'));
|
||||
echo "</div>";
|
||||
|
||||
if ($wmiexplore && $fail) {
|
||||
ui_print_error_message(__('Unable to do WMI explorer'));
|
||||
}
|
||||
|
||||
unset($table);
|
||||
|
||||
echo "</form>";
|
||||
|
||||
if ($wmiexplore && !$fail) {
|
||||
echo '<span id ="none_text" style="display: none;">' . __('None') . '</span>';
|
||||
echo "<form method='post' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=wmi_explorer&id_agente=$id_agent'>";
|
||||
echo '<span id="form_interfaces">';
|
||||
|
||||
html_print_input_hidden('create_modules', 1);
|
||||
html_print_input_hidden('ip_target', $ip_target); // Host
|
||||
html_print_input_hidden('plugin_user', $plugin_user); // User
|
||||
html_print_input_hidden('plugin_pass', $plugin_pass); // Password
|
||||
html_print_input_hidden('tcp_send', $tcp_send); // Namespace
|
||||
|
||||
$table->width = '98%';
|
||||
|
||||
// Mode selector
|
||||
$modes = array();
|
||||
$modes['services'] = __('Services');
|
||||
$modes['processes'] = __('Processes');
|
||||
$modes['disks'] = __('Free space on disk');
|
||||
$modes['components'] = __('WMI components');
|
||||
|
||||
$table->data[1][0] = __('Wizard mode') . ': ';
|
||||
$table->data[1][0] .= html_print_select ($modes,
|
||||
'wmi_wizard_modes', '', '', '', '', true, false, false);
|
||||
$table->cellstyle[1][0] = 'vertical-align: middle;';
|
||||
|
||||
$table->colspan[1][0] = 2;
|
||||
$table->data[1][2] = '<b>'.__('Modules').'</b>';
|
||||
$table->cellstyle[1][2] = 'vertical-align: middle;';
|
||||
|
||||
// Components list
|
||||
$table->data[2][0] = '<div class="wizard_mode_form wizard_mode_components">';
|
||||
$table->data[2][0] .= __('Filter by group') . '<br>';
|
||||
$table->data[2][0] .= html_print_select ($network_component_groups,
|
||||
'network_component_group', '', '', '', '',
|
||||
true, false, false, '', false, 'width: 300px;') . '<br>';
|
||||
$table->data[2][0] .= html_print_select (array (), 'network_component', '', '',
|
||||
'', '', true, true, true, '', false, 'width: 300px;');
|
||||
$table->data[2][0] .= '</div>';
|
||||
|
||||
// Services list
|
||||
$table->data[2][0] .= '<div class="wizard_mode_form wizard_mode_services">';
|
||||
$table->data[2][0] .= html_print_select ($services, 'services', '', '',
|
||||
'', '', true, true, true, '', false, 'width: 300px;');
|
||||
$table->data[2][0] .= '</div>';
|
||||
|
||||
// Processes list
|
||||
$table->data[2][0] .= '<div class="wizard_mode_form wizard_mode_processes">';
|
||||
$table->data[2][0] .= html_print_select ($processes, 'processes', '', '',
|
||||
'', '', true, true, true, '', false, 'width: 300px;');
|
||||
$table->data[2][0] .= '</div>';
|
||||
$table->data[2][0] .= '<span id="no_component" class="invisible error wizard_mode_form wizard_mode_components">';
|
||||
$table->data[2][0] .= __('No component was found');
|
||||
$table->data[2][0] .= '</span>';
|
||||
|
||||
// Disks list
|
||||
$table->data[2][0] .= '<div class="wizard_mode_form wizard_mode_disks">';
|
||||
$table->data[2][0] .= html_print_select ($disks, 'disks', '', '',
|
||||
'', '', true, true, true, '', false, 'width: 300px;');
|
||||
$table->data[2][0] .= '</div>';
|
||||
$table->cellstyle[2][0] = 'vertical-align: top; text-align: center;';
|
||||
|
||||
|
||||
// Components arrow
|
||||
$table->data[2][1] = '<div class="wizard_mode_form wizard_mode_components wizard_mode_components_arrow clickable">' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '</div>';
|
||||
// Services arrow
|
||||
$table->data[2][1] .= '<div class="wizard_mode_form wizard_mode_services wizard_mode_services_arrow clickable">' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '</div>';
|
||||
// Processes arrow
|
||||
$table->data[2][1] .= '<div class="wizard_mode_form wizard_mode_processes wizard_mode_processes_arrow clickable">' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '</div>';
|
||||
// Disks arrow
|
||||
$table->data[2][1] .= '<div class="wizard_mode_form wizard_mode_disks wizard_mode_disks_arrow clickable">' . html_print_image('images/darrowright.png', true, array('title' => __('Add to modules list'))) . '</div>';
|
||||
|
||||
|
||||
$table->data[2][1] .= '<br><br><div class="wizard_mode_delete_arrow clickable">' . html_print_image('images/cross.png', true, array('title' => __('Remove from modules list'))) . '</div>';
|
||||
$table->cellstyle[2][1] = 'vertical-align: middle; text-align: center;';
|
||||
|
||||
$table->data[2][2] = html_print_select (array (), 'module[]', 0, false, '', 0, true, true, true, '', false, 'width:300px; height: 100%;');
|
||||
$table->data[2][2] .= html_print_input_hidden('agent', $id_agent, true);
|
||||
$table->cellstyle[2][2] = 'vertical-align: top; text-align: center;';
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='text-align:right; width:".$table->width."'>";
|
||||
html_print_submit_button(__('Create modules'), 'create_modules_btn', false, array('class' => 'sub add'));
|
||||
echo "</div>";
|
||||
unset($table);
|
||||
|
||||
echo "</span>";
|
||||
echo "</form>";
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
ui_require_jquery_file ('pandora.controls');
|
||||
ui_require_jquery_file ('ajaxqueue');
|
||||
ui_require_jquery_file ('bgiframe');
|
||||
ui_require_javascript_file ('pandora_modules');
|
||||
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
/* <![CDATA[ */
|
||||
|
||||
$(document).ready (function () {
|
||||
$("#wmi_form").submit(function() {
|
||||
$("#oid_loading").show ();
|
||||
});
|
||||
|
||||
network_component_group_change_event();
|
||||
$('#network_component_group').trigger('change');
|
||||
|
||||
$("#wmi_wizard_modes").change(function() {
|
||||
$(".wizard_mode_form").hide();
|
||||
var selected_mode = $("#wmi_wizard_modes").val();
|
||||
$(".wizard_mode_" + selected_mode).show();
|
||||
$('#form_interfaces').show();
|
||||
});
|
||||
|
||||
$("#wmi_wizard_modes").trigger('change');
|
||||
|
||||
<?php
|
||||
if (!$wmiexplore || $fail) {
|
||||
?>
|
||||
$('#form_interfaces').hide();
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
$('.wizard_mode_services_arrow').click(function() {
|
||||
jQuery.each($("select[name='services'] option:selected"), function (key, value) {
|
||||
var id = 'service_' + $(value).attr('value');
|
||||
var name = $(value).html() + ' (<?php echo __('Service'); ?>)';
|
||||
if (name != <?php echo "'".__('None')."'"; ?>) {
|
||||
if($("#module").find("option[value='" + id + "']").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(id).html(name));
|
||||
}
|
||||
else {
|
||||
alert('<?php echo __('Repeated'); ?>');
|
||||
}
|
||||
$("#module").find("option[value='0']").remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.wizard_mode_processes_arrow').click(function() {
|
||||
jQuery.each($("select[name='processes'] option:selected"), function (key, value) {
|
||||
var id = 'process_' + $(value).attr('value');
|
||||
var name = $(value).html() + ' (<?php echo __('Process'); ?>)';
|
||||
if (name != <?php echo "'".__('None')."'"; ?>) {
|
||||
if($("#module").find("option[value='" + id + "']").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(id).html(name));
|
||||
}
|
||||
else {
|
||||
alert('<?php echo __('Repeated'); ?>');
|
||||
}
|
||||
$("#module").find("option[value='0']").remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.wizard_mode_disks_arrow').click(function() {
|
||||
jQuery.each($("select[name='disks'] option:selected"), function (key, value) {
|
||||
var id = 'disk_' + $(value).attr('value');
|
||||
var name = $(value).html();
|
||||
if (name != <?php echo "'".__('None')."'"; ?>) {
|
||||
if($("#module").find("option[value='" + id + "']").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(id).html(name));
|
||||
}
|
||||
else {
|
||||
alert('<?php echo __('Repeated'); ?>');
|
||||
}
|
||||
$("#module").find("option[value='0']").remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.wizard_mode_components_arrow').click(function() {
|
||||
jQuery.each($("select[name='network_component'] option:selected"), function (key, value) {
|
||||
var id = 'component_' + $(value).attr('value');
|
||||
var name = $(value).html();
|
||||
if (name != <?php echo "'".__('None')."'"; ?>) {
|
||||
if($("#module").find("option[value='" + id + "']").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(id).html(name));
|
||||
}
|
||||
else {
|
||||
alert('<?php echo __('Repeated'); ?>');
|
||||
}
|
||||
$("#module").find("option[value='0']").remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.wizard_mode_delete_arrow').click(function() {
|
||||
jQuery.each($("select[name='module[]'] option:selected"), function (key, value) {
|
||||
var name = $(value).html();
|
||||
if (name != <?php echo "'".__('None')."'"; ?>) {
|
||||
$(value).remove();
|
||||
}
|
||||
});
|
||||
|
||||
if($("#module option").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(0).html(<?php echo "'".__('None')."'"; ?>));
|
||||
}
|
||||
});
|
||||
|
||||
$("#submit-create_modules_btn").click(function () {
|
||||
if($("#module option").length == 0 || ($("#module option").length == 1 && $("#module option").eq(0).val() == 0)) {
|
||||
alert('<?php echo __('Modules list is empty'); ?>');
|
||||
return false;
|
||||
}
|
||||
$('#module option').map(function(){
|
||||
$(this).attr('selected','selected');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/* ]]> */
|
||||
</script>
|
||||
|
|
@ -339,6 +339,16 @@ if ($id_agente) {
|
|||
$gistab['active'] = false;
|
||||
}
|
||||
|
||||
/* Agent wizard tab */
|
||||
$agent_wizard['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&id_agente='.$id_agente.'">'
|
||||
. html_print_image ("images/wand.png", true, array ( "title" => __('Agent wizard')))
|
||||
. '</a>';
|
||||
|
||||
if ($tab == "agent_wizard")
|
||||
$agent_wizard['active'] = true;
|
||||
else
|
||||
$agent_wizard['active'] = false;
|
||||
|
||||
$total_incidents = agents_get_count_incidents($id_agente);
|
||||
|
||||
/* Incident tab */
|
||||
|
@ -363,7 +373,8 @@ if ($id_agente) {
|
|||
'pluginstab' => $pluginstab,
|
||||
'collection'=> $collectiontab,
|
||||
'group' => $grouptab,
|
||||
'gis' => $gistab);
|
||||
'gis' => $gistab,
|
||||
'agent_wizard' => $agent_wizard);
|
||||
|
||||
// Only if the agent has incidents associated show incidents tab
|
||||
if ($total_incidents) {
|
||||
|
@ -1394,6 +1405,9 @@ switch ($tab) {
|
|||
ui_print_error_message (__('Invalid tab specified'));
|
||||
}
|
||||
break;
|
||||
case "agent_wizard":
|
||||
require("agent_wizard.php");
|
||||
break;
|
||||
default:
|
||||
if (enterprise_hook ('switch_agent_tab', array ($tab))) {
|
||||
//This will make sure that blank pages will have at least some
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 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.
|
||||
|
||||
global $config;
|
||||
|
||||
require_once($config['homedir'] . "/include/functions_modules.php");
|
||||
require_once($config['homedir'] . "/include/functions_tags.php");
|
||||
|
||||
/**
|
||||
* Compose and return a WMI query
|
||||
*
|
||||
* @param string WMI client i.e. wmic
|
||||
* @param string Administrator user of the system
|
||||
* @param string Administrator password
|
||||
* @param string host IP or host of the system
|
||||
* @param string parameter --namespace of the WMI query (if not provided, will be ignored)
|
||||
*
|
||||
* @return string WMI query
|
||||
*/
|
||||
function wmi_compose_query($wmi_client, $user, $password, $host, $namespace = '') {
|
||||
$wmi_command = '';
|
||||
|
||||
if (!empty($password)) {
|
||||
$wmi_command = $wmi_client . ' -U "' . $user . '"%"' . $password . '"';
|
||||
}
|
||||
else {
|
||||
$wmi_command = $wmi_client . ' -U "' . $user . '"';
|
||||
}
|
||||
|
||||
if (!empty($namespace)) {
|
||||
$namespace = str_replace(""", "'", $namespace);
|
||||
$wmi_command .= ' --namespace="' . $namespace . '"';
|
||||
}
|
||||
|
||||
$wmi_command .= ' //' . $host;
|
||||
|
||||
return $wmi_command;
|
||||
}
|
||||
|
||||
|
||||
function wmi_create_wizard_modules($id_agent, $names, $wizard_mode, $values) {
|
||||
$results = array(ERR_GENERIC => array(), NOERR => array());
|
||||
|
||||
if (empty($names)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach($names as $name) {
|
||||
// Add query to wmi_command
|
||||
switch ($wizard_mode) {
|
||||
case 'services':
|
||||
$wmi_query = 'SELECT state FROM Win32_Service WHERE Name="' . io_safe_output($name) . '"';
|
||||
break;
|
||||
case 'processes':
|
||||
$wmi_query = 'SELECT Name FROM Win32_Process WHERE Name="' . io_safe_output($name) . '"';
|
||||
break;
|
||||
case 'disks':
|
||||
$wmi_query = 'SELECT Freespace FROM Win32_LogicalDisk WHERE DeviceID ="' . io_safe_output($name) . '"';
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the query to values
|
||||
$values['snmp_oid'] = io_safe_input($wmi_query);
|
||||
|
||||
$return = modules_create_agent_module ($id_agent, $name, $values);
|
||||
|
||||
if($return < 0) {
|
||||
$results[ERR_GENERIC][] = $name;
|
||||
} else {
|
||||
$results[NOERR][] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
function wmi_create_module_from_components($components, $values) {
|
||||
$results = array(ERR_GENERIC => array(), NOERR => array(), ERR_EXIST => array());
|
||||
|
||||
if (empty($components)) {
|
||||
return array();
|
||||
}
|
||||
foreach ($components as $component_id) {
|
||||
$nc = db_get_row ("tnetwork_component", "id_nc", $component_id);
|
||||
|
||||
// Compatibilize the fields between components and modules table
|
||||
$nc['descripcion'] = $nc['description'];
|
||||
unset($nc['description']);
|
||||
|
||||
$nc['nombre'] = $nc['name'];
|
||||
unset($nc['name']);
|
||||
|
||||
$nc['id_tipo_modulo'] = $nc['type'];
|
||||
unset($nc['type']);
|
||||
|
||||
unset($nc['id_nc']);
|
||||
unset($nc['id_group']);
|
||||
|
||||
// Store the passed values with the component values
|
||||
foreach ($values as $k => $v) {
|
||||
$nc[$k] = $v;
|
||||
}
|
||||
|
||||
// Put tags in array if the component has to add them later
|
||||
if(!empty($nc['tags'])) {
|
||||
$tags = explode(',', $nc['tags']);
|
||||
}
|
||||
else {
|
||||
$tags = array();
|
||||
}
|
||||
|
||||
unset($nc['tags']);
|
||||
|
||||
// Check if this module exists in the agent
|
||||
$module_name_check = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('delete_pending' => 0, 'nombre' => $nc['nombre'], 'id_agente' => $nc['id_agente']));
|
||||
|
||||
if ($module_name_check !== false) {
|
||||
$results[ERR_EXIST][] = $nc["nombre"];
|
||||
}
|
||||
else {
|
||||
$id_agente_modulo = modules_create_agent_module($nc["id_agente"], $nc["nombre"], $nc);
|
||||
|
||||
if ($id_agente_modulo === false) {
|
||||
$results[ERR_GENERIC][] = $nc["nombre"];
|
||||
}
|
||||
else {
|
||||
if(!empty($tags)) {
|
||||
// Creating tags
|
||||
$tag_ids = array();
|
||||
foreach ($tags as $tag_name) {
|
||||
$tag_id = tags_get_id($tag_name);
|
||||
|
||||
//If tag exists in the system we store to create it
|
||||
$tag_ids[] = $tag_id;
|
||||
}
|
||||
|
||||
tags_insert_module_tag ($id_agente_modulo, $tag_ids);
|
||||
}
|
||||
|
||||
$results[NOERR][] = $nc["nombre"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
?>
|
|
@ -43,7 +43,7 @@ function configure_modules_form () {
|
|||
function (data, status) {
|
||||
if (data == false) {
|
||||
$("#component_loading").hide ();
|
||||
$("span#no_component").show ();
|
||||
$("#no_component").show ();
|
||||
return;
|
||||
}
|
||||
jQuery.each (data, function (i, val) {
|
||||
|
@ -58,7 +58,6 @@ function configure_modules_form () {
|
|||
},
|
||||
"json"
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -219,40 +218,8 @@ function configure_modules_form () {
|
|||
);
|
||||
});
|
||||
|
||||
$("#network_component_group").change (function () {
|
||||
var $select = $("#network_component").hide ();
|
||||
$("#component").hide ();
|
||||
if (this.value == 0)
|
||||
return;
|
||||
$("#component_loading").show ();
|
||||
$(".error, #no_component").hide ();
|
||||
$("option[value!=0]", $select).remove ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/agentes/module_manager_editor",
|
||||
"get_module_components" : 1,
|
||||
"id_module_component_group" : this.value,
|
||||
"id_module_component_type" : $("#hidden-id_module_component_type").attr ("value")
|
||||
},
|
||||
function (data, status) {
|
||||
if (data == false) {
|
||||
$("#component_loading").hide ();
|
||||
$("span#no_component").show ();
|
||||
return;
|
||||
}
|
||||
jQuery.each (data, function (i, val) {
|
||||
option = $("<option></option>")
|
||||
.attr ("value", val['id_nc'])
|
||||
.append (val['name']);
|
||||
$select.append (option);
|
||||
});
|
||||
$("#component_loading").hide ();
|
||||
$select.show ();
|
||||
$("#component").show ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
|
||||
network_component_group_change_event();
|
||||
|
||||
$("#network_component").change (function () {
|
||||
if (this.value == 0)
|
||||
return;
|
||||
|
@ -679,3 +646,39 @@ function show_module_detail_dialog(module_id, id_agente) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function network_component_group_change_event() {
|
||||
$("#network_component_group").change (function () {
|
||||
var $select = $("#network_component").hide ();
|
||||
$("#component").hide ();
|
||||
if (this.value == 0)
|
||||
return;
|
||||
$("#component_loading").show ();
|
||||
$(".error, #no_component").hide ();
|
||||
$("option[value!=0]", $select).remove ();
|
||||
jQuery.post ("ajax.php",
|
||||
{"page" : "godmode/agentes/module_manager_editor",
|
||||
"get_module_components" : 1,
|
||||
"id_module_component_group" : this.value,
|
||||
"id_module_component_type" : $("#hidden-id_module_component_type").attr ("value")
|
||||
},
|
||||
function (data, status) {
|
||||
if (data == false) {
|
||||
$("#component_loading").hide ();
|
||||
$("#no_component").show ();
|
||||
return;
|
||||
}
|
||||
jQuery.each (data, function (i, val) {
|
||||
option = $("<option></option>")
|
||||
.attr ("value", val['id_nc'])
|
||||
.append (val['name']);
|
||||
$select.append (option);
|
||||
});
|
||||
$("#component_loading").hide ();
|
||||
$select.show ();
|
||||
$("#component").show ();
|
||||
},
|
||||
"json"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue