Commit version 24.12.13800
213
.phpcs.xml
Normal file
@ -0,0 +1,213 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Observium ruleset">
|
||||
<description>Observium rules for PHP CodeSniffer</description>
|
||||
|
||||
<arg value="sp"/>
|
||||
<arg name="extensions" value="php"/>
|
||||
|
||||
<file>.</file>
|
||||
|
||||
<!-- <arg name="report" value="xml"/>
|
||||
<arg name="report-file" value="phpcs-report.xml"/> -->
|
||||
|
||||
<!-- Exclude unused code. -->
|
||||
<exclude-pattern>*/attic/*</exclude-pattern>
|
||||
<!-- Exclude devel code. -->
|
||||
<exclude-pattern>*/devel/*</exclude-pattern>
|
||||
<!-- Exclude Composer vendor directory. -->
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<!-- Weathermap exclude -->
|
||||
<exclude-pattern>*/weathermap/*</exclude-pattern>
|
||||
<!-- Self PHPCompatibility exclude -->
|
||||
<exclude-pattern>tests/php-compatibility/*</exclude-pattern>
|
||||
|
||||
<!-- Strip the filepaths down to the relevant bit. -->
|
||||
<arg name="basepath" value="./"/>
|
||||
|
||||
<!-- Check up to 8 files simultanously. -->
|
||||
<arg name="parallel" value="8"/>
|
||||
|
||||
<!-- PHPCompatibility standard path -->
|
||||
<!-- <config name="installed_paths" value="tests/php-compatibility"/> -->
|
||||
|
||||
<!-- Check for cross-version support for PHP 5.6 and higher. -->
|
||||
<config name="testVersion" value="5.6-"/>
|
||||
|
||||
<!-- Run against the PHPCompatibility ruleset -->
|
||||
<rule ref="PHPCompatibility">
|
||||
<exclude-pattern>irc\.php$</exclude-pattern>
|
||||
<exclude-pattern>*/weathermap/*</exclude-pattern>
|
||||
<!-- random_bytes() already exist by compatibility lib -->
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.random_bytesFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.random_intFound"/>
|
||||
<!-- array_key_first() already exist by compatibility -->
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_key_firstFound"/>
|
||||
</rule>
|
||||
|
||||
<!-- Whitelist the mysql_to_rfc3339() and mysql_another_function() functions. -->
|
||||
<rule ref="PHPCompatibility.Extensions.RemovedExtensions">
|
||||
<properties>
|
||||
<property name="functionWhitelist" type="array" value="mysql_authenticate,mysql_auth_can_logout,mysql_auth_can_change_password,mysql_auth_change_password,mysql_auth_usermanagement,mysql_adduser,mysql_auth_user_exists,mysql_auth_username_by_id,mysql_auth_user_level,mysql_auth_user_id,mysql_deluser,mysql_auth_user_list,mysql_auth_user_info"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- random_compat lib -->
|
||||
<rule ref="PHPCompatibility.Classes.NewClasses.typeerrorFound">
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Classes.NewClasses.errorFound">
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated">
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_create_ivDeprecatedRemoved">
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_dev_urandomDeprecatedRemoved">
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- pear chap lib excludes -->
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_module_openDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_desDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_enc_get_iv_sizeDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_randDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_generic_initDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_genericDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_generic_deinitDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_module_closeDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- pear net socket excludes -->
|
||||
<rule ref="PHPCompatibility.IniDirectives.RemovedIniDirectives.track_errorsDeprecated">
|
||||
<exclude-pattern>libs/pear/Net/Socket\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Variables.RemovedPredefinedGlobalVariables.php_errormsgDeprecated">
|
||||
<exclude-pattern>libs/pear/Net/Socket\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.error_clear_lastFound">
|
||||
<exclude-pattern>libs/pear/Net/Socket\.php</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Exclude shiff on specific patterns -->
|
||||
<rule ref="PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection">
|
||||
<exclude-pattern>includes/common\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/Fabiang/Xmpp/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Miscellaneous.ValidIntegers.HexNumericStringFound">
|
||||
<exclude-pattern>tests/*</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.IniDirectives.RemovedIniDirectives.magic_quotes_runtimeDeprecatedRemoved">
|
||||
<exclude-pattern>libs/pear/Mail/mime*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.NewConstants.json_preserve_zero_fractionFound">
|
||||
<exclude-pattern>includes/definitions\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved">
|
||||
<exclude-pattern>includes/db/mysql\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.IniDirectives.RemovedIniDirectives.session_hash_functionRemoved">
|
||||
<exclude-pattern>html/includes/authenticate\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_keybytesFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.NewConstants.sodium_crypto_secretbox_noncebytesFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_padFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_secretboxFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Classes.NewClasses.sodiumexceptionFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.sodium_crypto_secretbox_openFound">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Extensions.RemovedExtensions.mcryptDeprecatedRemoved">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/random_compat/*</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_encryptDeprecatedRemoved">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.mcrypt_decryptDeprecatedRemoved">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_rijndael_256DeprecatedRemoved">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.RemovedConstants.mcrypt_mode_ecbDeprecatedRemoved">
|
||||
<exclude-pattern>tests/IncludesEncryptTest\.php</exclude-pattern>
|
||||
<exclude-pattern>includes/encrypt\.inc\.php</exclude-pattern>
|
||||
<exclude-pattern>libs/pear/Crypt/CHAP\.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_gpcDeprecated">
|
||||
<exclude-pattern>html/includes/collectd/functions.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctions.session_create_idFound">
|
||||
<exclude-pattern>html/includes/authenticate.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<!-- compatability fixed in code -->
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.ldap_control_paged_resultDeprecated">
|
||||
<exclude-pattern>html/includes/authentication/ldap.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.RemovedFunctions.ldap_control_paged_result_responseDeprecated">
|
||||
<exclude-pattern>html/includes/authentication/ldap.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctionParameters.ldap_search_serverctrlsFound">
|
||||
<exclude-pattern>html/includes/authentication/ldap.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.FunctionUse.NewFunctionParameters.ldap_parse_result_serverctrlsFound">
|
||||
<exclude-pattern>html/includes/authentication/ldap.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.NewConstants.ldap_control_pagedresultsFound">
|
||||
<exclude-pattern>html/includes/authentication/ldap.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Miscellaneous.ValidIntegers.HexNumericStringFound">
|
||||
<exclude-pattern>includes/entities/sensor.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PHPCompatibility.Constants.NewConstants.mysqli_client_ssl_dont_verify_server_certFound">
|
||||
<exclude-pattern>includes/db/mysqli.inc.php</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Run against a second ruleset -->
|
||||
<!-- <rule ref="PSR2"/> -->
|
||||
|
||||
</ruleset>
|
303
add_device.php
@ -7,239 +7,128 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/// FIXME. This is mostly DERP arguments parsing, new cmd will be soon
|
||||
/// FIXME. This is mostly DERP arguments parsing
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("dhpt");
|
||||
if (isset($options['d'])) { array_shift($argv); }
|
||||
$options = getopt("dhpt", [], $opt_index);
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
include("includes/discovery/functions.inc.php");
|
||||
|
||||
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WAdd Device(s)%n\n", 'color');
|
||||
|
||||
if (OBS_DEBUG) { print_versions(); }
|
||||
if (OBS_DEBUG) {
|
||||
print_versions();
|
||||
}
|
||||
|
||||
if (isset($options['h'])) { print_help(OBS_SCRIPT_NAME); exit; }
|
||||
if (isset($options['h'])) {
|
||||
print_help(OBS_SCRIPT_NAME);
|
||||
exit;
|
||||
}
|
||||
|
||||
$snmp_options = array();
|
||||
// Just test, do not add device
|
||||
$snmp_options = [];
|
||||
// Just test, do not add a device
|
||||
if (isset($options['t'])) {
|
||||
$snmp_options['test'] = TRUE;
|
||||
array_shift($argv);
|
||||
$snmp_options['test'] = TRUE;
|
||||
}
|
||||
// Add skip pingable checks if argument -p passed
|
||||
if (isset($options['p'])) {
|
||||
$snmp_options['ping_skip'] = 1;
|
||||
array_shift($argv);
|
||||
$snmp_options['ping_skip'] = 1;
|
||||
}
|
||||
// Remove options and script name from argv
|
||||
$argv = array_slice($argv, $opt_index);
|
||||
|
||||
$added = 0;
|
||||
$add_array = [];
|
||||
if (!empty($argv[0])) {
|
||||
if (is_file($argv[0])) {
|
||||
// Parse file into an array with devices to add
|
||||
foreach (new SplFileObject($argv[0]) as $line) {
|
||||
$d = preg_split('/\s/', $line, -1, PREG_SPLIT_NO_EMPTY);
|
||||
if (empty($d) || str_starts_with($d[0], '#')) {
|
||||
// Skip empty lines or commented
|
||||
continue;
|
||||
}
|
||||
$add_array[] = $d;
|
||||
}
|
||||
} else {
|
||||
$add_array[] = $argv;
|
||||
}
|
||||
|
||||
// Save base SNMP v3 credentials and v2c/v1 community
|
||||
$snmp_config_v3 = $config['snmp']['v3'];
|
||||
$snmp_config_community = $config['snmp']['community'];
|
||||
|
||||
foreach ($add_array as $add) {
|
||||
$snmp = get_device_snmp_argv($add, $snmp_options);
|
||||
if (!$snmp) {
|
||||
//print_error("Try to add $hostname:");
|
||||
continue;
|
||||
}
|
||||
$hostname = $snmp['hostname'];
|
||||
$snmp_version = $snmp['snmp_version'];
|
||||
$snmp_transport = $snmp['snmp_transport'];
|
||||
$snmp_port = $snmp['snmp_port'];
|
||||
|
||||
// FIXME. Still used hard set v2c/v3 auth by config
|
||||
if ($snmp_version === "v3") {
|
||||
// v3
|
||||
$config['snmp']['v3'] = $snmp['snmp_v3_auth'];
|
||||
} elseif (!empty($snmp_version)) {
|
||||
// v1 or v2c
|
||||
$config['snmp']['community'] = $snmp['snmp_community'];
|
||||
}
|
||||
|
||||
print_message("Try to add $hostname:");
|
||||
|
||||
// If a known snmp version passed in arguments, then use the exact version (v1, v2c, v3)
|
||||
// otherwise checks all possible snmp versions and auth options
|
||||
if ($device_id = add_device($hostname, $snmp_version, $snmp_port, $snmp_transport, $snmp_options)) {
|
||||
if (!isset($snmp_options['test'])) {
|
||||
$device = device_by_id_cache($device_id);
|
||||
print_success("Added device " . $device['hostname'] . " (" . $device_id . ").");
|
||||
} // Else this is device testing, success message already written by add_device()
|
||||
$added++;
|
||||
}
|
||||
|
||||
// Restore base SNMP v1/2c/3 credentials (need for add multiple devices)
|
||||
$config['snmp']['community'] = $snmp_config_community;
|
||||
$config['snmp']['v3'] = $snmp_config_v3;
|
||||
}
|
||||
}
|
||||
|
||||
$added = 0;
|
||||
|
||||
if (!empty($argv[1])) {
|
||||
$add_array = array();
|
||||
if (is_file($argv[1])) {
|
||||
// Parse file into array with devices to add
|
||||
foreach (new SplFileObject($argv[1]) as $line) {
|
||||
$d = preg_split('/\s/', $line, -1, PREG_SPLIT_NO_EMPTY);
|
||||
if (empty($d) || strpos(reset($d), '#') === 0) { continue; }
|
||||
$add_array[] = $d;
|
||||
}
|
||||
} else {
|
||||
$add_array[0] = $argv;
|
||||
array_shift($add_array[0]);
|
||||
}
|
||||
|
||||
// Save base SNMP v3 credentials and v2c/v1 community
|
||||
$snmp_config_v3 = $config['snmp']['v3'];
|
||||
$snmp_config_community = $config['snmp']['community'];
|
||||
|
||||
foreach ($add_array as $add) {
|
||||
$hostname = strtolower($add[0]);
|
||||
$snmp_community = $add[1];
|
||||
$snmp_version = strtolower($add[2]);
|
||||
|
||||
$snmp_port = 161;
|
||||
if (str_contains($hostname, ':') && get_ip_version($hostname) !== 6) {
|
||||
// Allow pass common hostname:port
|
||||
list($host_tmp, $port_tmp) = explode(':', $hostname, 2);
|
||||
if (is_valid_param($port_tmp, 'port')) {
|
||||
$hostname = $host_tmp;
|
||||
$snmp_port = $port_tmp;
|
||||
}
|
||||
unset($host_tmp, $port_tmp);
|
||||
}
|
||||
$snmp_transport = 'udp';
|
||||
|
||||
if ($snmp_version === "v3") {
|
||||
$config['snmp']['v3'] = $snmp_config_v3; // Restore base SNMP v3 credentials
|
||||
$snmp_v3_seclevel = $snmp_community;
|
||||
|
||||
// These values are the same as in defaults.inc.php
|
||||
$snmp_v3_auth = [
|
||||
'authlevel' => "noAuthNoPriv",
|
||||
'authname' => "observium",
|
||||
'authpass' => "",
|
||||
'authalgo' => "MD5",
|
||||
'cryptopass' => "",
|
||||
'cryptoalgo' => "AES"
|
||||
];
|
||||
|
||||
$add_context = FALSE; // Derp, last arg after transport is context
|
||||
if ($snmp_v3_seclevel === "nanp" || $snmp_v3_seclevel === "any" || $snmp_v3_seclevel === "noAuthNoPriv") {
|
||||
$snmp_v3_auth['authlevel'] = "noAuthNoPriv";
|
||||
$snmp_v3_args = array_slice($add, 3);
|
||||
|
||||
while ($arg = array_shift($snmp_v3_args)) {
|
||||
// parse all remaining args
|
||||
if (is_valid_param($arg, 'port')) {
|
||||
$snmp_port = $arg;
|
||||
} elseif (preg_match('/^(' . implode("|", $config['snmp']['transports']) . ')$/', $arg)) {
|
||||
$snmp_transport = $arg;
|
||||
$add_context = TRUE; // Derp, last arg after transport is context
|
||||
} elseif ($add_context && strlen($arg)) {
|
||||
$snmp_context = $arg;
|
||||
break;
|
||||
} else {
|
||||
// FIXME: should add a sanity check of chars allowed in user
|
||||
$user = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
if ($snmp_v3_seclevel !== "any") {
|
||||
$config['snmp']['v3'] = [ $snmp_v3_auth ];
|
||||
}
|
||||
} elseif ($snmp_v3_seclevel === "anp" || $snmp_v3_seclevel === "authNoPriv") {
|
||||
|
||||
$snmp_v3_auth['authlevel'] = "authNoPriv";
|
||||
$snmp_v3_args = array_slice($argv, 4);
|
||||
$snmp_v3_auth['authname'] = array_shift($snmp_v3_args);
|
||||
$snmp_v3_auth['authpass'] = array_shift($snmp_v3_args);
|
||||
|
||||
while ($arg = array_shift($snmp_v3_args)) {
|
||||
// parse all remaining args
|
||||
if (is_valid_param($arg, 'port')) {
|
||||
$snmp_port = $arg;
|
||||
} elseif (preg_match('/^(' . implode("|", $config['snmp']['transports']) . ')$/i', $arg)) {
|
||||
$snmp_transport = $arg;
|
||||
$add_context = TRUE; // Derp, last arg after transport is context
|
||||
} elseif (is_valid_param($arg, 'snmp_authalgo')) {
|
||||
$snmp_v3_auth['authalgo'] = $arg;
|
||||
} elseif ($add_context && strlen($arg)) {
|
||||
$snmp_context = $arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$config['snmp']['v3'] = [ $snmp_v3_auth ];
|
||||
} elseif ($snmp_v3_seclevel === "ap" || $snmp_v3_seclevel === "authPriv") {
|
||||
$snmp_v3_auth['authlevel'] = "authPriv";
|
||||
$snmp_v3_args = array_slice($argv, 4);
|
||||
$snmp_v3_auth['authname'] = array_shift($snmp_v3_args);
|
||||
$snmp_v3_auth['authpass'] = array_shift($snmp_v3_args);
|
||||
$snmp_v3_auth['cryptopass'] = array_shift($snmp_v3_args);
|
||||
|
||||
while ($arg = array_shift($snmp_v3_args)) {
|
||||
// parse all remaining args
|
||||
if (is_valid_param($arg, 'port')) {
|
||||
$snmp_port = $arg;
|
||||
} elseif (preg_match('/^(' . implode("|", $config['snmp']['transports']) . ')$/i', $arg)) {
|
||||
$snmp_transport = $arg;
|
||||
$add_context = TRUE; // Derp, last arg after transport is context
|
||||
} elseif (is_valid_param($arg, 'snmp_authalgo')) {
|
||||
$snmp_v3_auth['authalgo'] = $arg;
|
||||
} elseif (is_valid_param($arg, 'snmp_cryptoalgo')) {
|
||||
$snmp_v3_auth['cryptoalgo'] = $arg;
|
||||
} elseif ($add_context && strlen($arg)) {
|
||||
$snmp_context = $arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$config['snmp']['v3'] = [ $snmp_v3_auth ];
|
||||
}
|
||||
//print_debug_vars($snmp_v3_auth);
|
||||
//print_debug_vars($config['snmp']['v3']);
|
||||
} else {
|
||||
// v1 or v2c
|
||||
$snmp_v2_args = array_slice($argv, 2);
|
||||
|
||||
$add_context = FALSE; // Derp, last arg after transport is context
|
||||
while ($arg = array_shift($snmp_v2_args)) {
|
||||
// parse all remaining args
|
||||
if (is_valid_param($arg, 'port')) {
|
||||
$snmp_port = $arg;
|
||||
} elseif (preg_match('/(' . implode("|", $config['snmp']['transports']) . ')/i', $arg)) {
|
||||
$snmp_transport = $arg;
|
||||
$add_context = TRUE; // Derp, last arg after transport is context
|
||||
} elseif (preg_match('/^(v1|v2c)$/i', $arg)) {
|
||||
$snmp_version = $arg;
|
||||
} elseif ($add_context && strlen($arg)) {
|
||||
$snmp_context = $arg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$config['snmp']['community'] = ($snmp_community ? array($snmp_community) : $snmp_config_community);
|
||||
}
|
||||
|
||||
// Add snmp context to params
|
||||
if (isset($snmp_context)) {
|
||||
$snmp_options['snmp_context'] = $snmp_context;
|
||||
unset($snmp_context);
|
||||
}
|
||||
|
||||
print_message("Try to add $hostname:");
|
||||
if (in_array($snmp_version, array('v1', 'v2c', 'v3'))) {
|
||||
// If snmp version passed in arguments, then use the exact version
|
||||
$device_id = add_device($hostname, $snmp_version, $snmp_port, $snmp_transport, $snmp_options);
|
||||
} else {
|
||||
// If snmp version unknown check all possible snmp versions and auth options
|
||||
$device_id = add_device($hostname, NULL, $snmp_port, $snmp_transport, $snmp_options);
|
||||
}
|
||||
|
||||
if ($device_id) {
|
||||
if (!isset($options['t'])) {
|
||||
$device = device_by_id_cache($device_id);
|
||||
print_success("Added device " . $device['hostname'] . " (" . $device_id . ").");
|
||||
} // Else this is device testing, success message already written by add_device()
|
||||
$added++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$count = safe_count($add_array);
|
||||
$count = safe_count($add_array);
|
||||
$failed = $count - $added;
|
||||
if ($added) {
|
||||
print_message("\nDevices success: $added.");
|
||||
if ($failed) {
|
||||
print_message("Devices failed: $failed.");
|
||||
}
|
||||
print_message("\nDevices success: $added.");
|
||||
if ($failed) {
|
||||
print_message("Devices failed: $failed.");
|
||||
}
|
||||
} else {
|
||||
if ($count) {
|
||||
print_message("Devices failed: $failed.");
|
||||
}
|
||||
print_help(OBS_SCRIPT_NAME);
|
||||
if ($count) {
|
||||
print_message("Devices failed: $failed.");
|
||||
}
|
||||
print_help(OBS_SCRIPT_NAME);
|
||||
}
|
||||
|
||||
function print_help($scriptname) {
|
||||
global $config;
|
||||
global $config;
|
||||
|
||||
$snmp_version = get_versions('snmp');
|
||||
if (version_compare($snmp_version, '5.8', '<')) {
|
||||
$snmpv3_auth = '[md5|sha]';
|
||||
$snmpv3_crypto = '[des|aes]';
|
||||
} else {
|
||||
$snmpv3_auth = '[md5|sha|sha-224|sha-256|sha-384|sha-512]';
|
||||
$snmpv3_crypto = '[des|aes|aes-192|aes-192-c|aes-256|aes-256-c]';
|
||||
}
|
||||
$snmp_transports = '[' . implode("|", $config['snmp']['transports']) . ']';
|
||||
print_message("%n
|
||||
$snmp_version = get_versions('snmp');
|
||||
if (version_compare($snmp_version, '5.8', '<')) {
|
||||
$snmpv3_auth = '[md5|sha]';
|
||||
$snmpv3_crypto = '[des|aes]';
|
||||
} else {
|
||||
$snmpv3_auth = '[md5|sha|sha-224|sha-256|sha-384|sha-512]';
|
||||
$snmpv3_crypto = '[des|aes|aes-192|aes-192-c|aes-256|aes-256-c]';
|
||||
}
|
||||
$snmp_transports = '[' . implode("|", $config['snmp']['transports']) . ']';
|
||||
print_message("%n
|
||||
USAGE:
|
||||
$scriptname <hostname> [community] [v1|v2c] [port] $snmp_transports
|
||||
$scriptname <hostname> [any|nanp|anp|ap] [v3] [user] [password] [enckey] $snmpv3_auth $snmpv3_crypto [port] $snmp_transports
|
||||
|
81
adduser.php
@ -5,70 +5,71 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("d");
|
||||
if (isset($options['d'])) { array_shift($argv); } // for compatibility
|
||||
if (isset($options['d'])) {
|
||||
array_shift($argv);
|
||||
} // for compatibility
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
|
||||
print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WAdd User%n\n", 'color');
|
||||
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WAdd User%n\n", 'color');
|
||||
|
||||
if (OBS_DEBUG) { print_versions(); }
|
||||
|
||||
$auth_file = $config['html_dir'].'/includes/authentication/' . $config['auth_mechanism'] . '.inc.php';
|
||||
if (is_file($auth_file))
|
||||
{
|
||||
include($auth_file);
|
||||
|
||||
// Include base auth functions calls
|
||||
include($config['html_dir'].'/includes/authenticate-functions.inc.php');
|
||||
} else {
|
||||
print_error("ERROR: no valid auth_mechanism defined.");
|
||||
exit();
|
||||
if (OBS_DEBUG) {
|
||||
print_versions();
|
||||
}
|
||||
|
||||
if (auth_usermanagement())
|
||||
{
|
||||
if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]))
|
||||
{
|
||||
if (!auth_user_exists($argv[1]))
|
||||
{
|
||||
if (adduser($argv[1], $argv[2], $argv[3], @$argv[4]))
|
||||
{
|
||||
print_success("User ".$argv[1]." added successfully.");
|
||||
} else {
|
||||
print_error("User ".$argv[1]." creation failed!");
|
||||
}
|
||||
$auth_file = $config['html_dir'] . '/includes/authentication/' . $config['auth_mechanism'] . '.inc.php';
|
||||
if (is_file($auth_file)) {
|
||||
// Include base auth functions calls
|
||||
include_once($config['html_dir'] . '/includes/sessions.inc.php');
|
||||
include_once($config['html_dir'] . '/includes/authenticate-functions.inc.php');
|
||||
|
||||
include_once($auth_file);
|
||||
} else {
|
||||
print_error("ERROR: no valid auth_mechanism defined.");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!auth_usermanagement()) {
|
||||
print_error("Auth module does not allow adding users!");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($argv[1], $argv[2], $argv[3])) {
|
||||
if (!auth_user_exists($argv[1])) {
|
||||
if (adduser($argv[1], $argv[2], $argv[3], @$argv[4])) {
|
||||
print_success("User " . $argv[1] . " added successfully.");
|
||||
} else {
|
||||
print_error("User " . $argv[1] . " creation failed!");
|
||||
}
|
||||
} else {
|
||||
print_warning("User ".$argv[1]." already exists!");
|
||||
print_warning("User " . $argv[1] . " already exists!");
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
|
||||
$msg = "%n
|
||||
USAGE:
|
||||
$scriptname <username> <password> <level 1-10> [email]
|
||||
$scriptname <username> <password> <level 1-10>
|
||||
|
||||
EXAMPLE:
|
||||
%WADMIN%n: $scriptname <username> <password> 10 [email]
|
||||
%WADMIN%n: $scriptname <username> <password> 10
|
||||
|
||||
USER LEVELS:" . PHP_EOL;
|
||||
|
||||
foreach($GLOBALS['config']['user_level'] as $level => $entry)
|
||||
{
|
||||
$msg .= ' '.$level.' - %W'.$entry['name'].'%n ('.$entry['subtext'].')'. PHP_EOL;
|
||||
foreach ($GLOBALS['config']['user_level'] as $level => $entry) {
|
||||
$msg .= ' ' . $level . ' - %W' . $entry['name'] . '%n (' . $entry['subtext'] . ')' . PHP_EOL;
|
||||
}
|
||||
$msg .= PHP_EOL . "%rInvalid arguments!%n";
|
||||
|
||||
print_message($msg, 'color', FALSE);
|
||||
}
|
||||
} else {
|
||||
print_error("Auth module does not allow adding users!");
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
68
alerter.php
@ -5,9 +5,9 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -15,7 +15,7 @@ chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("h:p:dqrsV");
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
|
||||
include("includes/polling/functions.inc.php");
|
||||
include("html/includes/functions.inc.php");
|
||||
@ -23,43 +23,43 @@ include("html/includes/functions.inc.php");
|
||||
$start = utime();
|
||||
|
||||
if (isset($options['V'])) {
|
||||
print_message(OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION);
|
||||
exit;
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($options['s'])) {
|
||||
// User has asked for spam. LETS MAKE THE SPAM. (sends alerts even if they have already been sent)
|
||||
$spam = TRUE;
|
||||
// User has asked for spam. LETS MAKE THE SPAM. (sends alerts even if they have already been sent)
|
||||
$spam = TRUE;
|
||||
}
|
||||
|
||||
if (!isset($options['q'])) {
|
||||
print_cli_banner();
|
||||
print_cli_banner();
|
||||
}
|
||||
|
||||
if ($options['h'] === "all") {
|
||||
$where = " ";
|
||||
$doing = "all";
|
||||
$where = " ";
|
||||
$doing = "all";
|
||||
} elseif ($options['h']) {
|
||||
$params = [];
|
||||
if (is_numeric($options['h'])) {
|
||||
$where = "AND `device_id` = ?";
|
||||
$doing = $options['h'];
|
||||
$params[] = $options['h'];
|
||||
} else {
|
||||
$where = "AND `hostname` LIKE ?";
|
||||
$doing = $options['h'];
|
||||
$params[] = str_replace('*','%', $options['h']);
|
||||
}
|
||||
$params = [];
|
||||
if (is_numeric($options['h'])) {
|
||||
$where = "AND `device_id` = ?";
|
||||
$doing = $options['h'];
|
||||
$params[] = $options['h'];
|
||||
} else {
|
||||
$where = "AND `hostname` LIKE ?";
|
||||
$doing = $options['h'];
|
||||
$params[] = str_replace('*', '%', $options['h']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['p'])) {
|
||||
print_cli_heading("%WConstrained to poller partition id ".$options['p']);
|
||||
$where .= ' AND `poller_id` = ?';
|
||||
$params[] = $options['p'];
|
||||
print_cli_heading("%WConstrained to poller partition id " . $options['p']);
|
||||
$where .= ' AND `poller_id` = ?';
|
||||
$params[] = $options['p'];
|
||||
}
|
||||
|
||||
if (!$where) {
|
||||
print_message("%n
|
||||
print_message("%n
|
||||
USAGE:
|
||||
$scriptname [-drqV] [-p poller_id] [-h device]
|
||||
|
||||
@ -82,10 +82,10 @@ DEBUGGING OPTIONS:
|
||||
-dd More verbose debugging output.
|
||||
|
||||
%rInvalid arguments!%n", 'color');
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
print_cli_heading("%WStarting alerter run at ".date("Y-m-d H:i:s"), 0);
|
||||
print_cli_heading("%WStarting alerter run at " . date("Y-m-d H:i:s"), 0);
|
||||
|
||||
$polled_devices = 0;
|
||||
|
||||
@ -102,17 +102,17 @@ $_SESSION['userlevel'] = 10;
|
||||
$query = "SELECT * FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC";
|
||||
foreach (dbFetchRows($query, $params) as $device) {
|
||||
|
||||
humanize_device($device);
|
||||
humanize_device($device);
|
||||
|
||||
process_alerts($device);
|
||||
if ($config['poller-wrapper']['notifications'] || $spam) {
|
||||
process_notifications([ 'device_id' => $device['device_id'] ]); // Send all notifications (also for syslog from queue)
|
||||
}
|
||||
process_alerts($device);
|
||||
if ($config['poller-wrapper']['notifications'] || $spam) {
|
||||
process_notifications(['device_id' => $device['device_id']]); // Send all notifications (also for syslog from queue)
|
||||
}
|
||||
|
||||
dbUpdate([ 'last_alerter' => [ 'NOW()' ] ], 'devices', '`device_id` = ?', [ $device['device_id'] ]);
|
||||
dbUpdate(['last_alerter' => ['NOW()']], 'devices', '`device_id` = ?', [$device['device_id']]);
|
||||
|
||||
}
|
||||
|
||||
print_cli_heading("%WFinished alerter run at ".date("Y-m-d H:i:s"), 0);
|
||||
print_cli_heading("%WFinished alerter run at " . date("Y-m-d H:i:s"), 0);
|
||||
|
||||
// EOF
|
||||
|
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("d");
|
||||
if (isset($options['d'])) { array_shift($argv); } // for compatibility
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
|
||||
// Check all of our interface RRD files for errors
|
||||
|
||||
if ($argv[1]) { $where = "AND `port_id` = ?"; $params = array($argv[1]); }
|
||||
|
||||
$i = 0;
|
||||
$errored = 0;
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where", $params) as $interface)
|
||||
{
|
||||
$errors = $interface['ifInErrors_delta'] + $interface['ifOutErrors_delta'];
|
||||
if ($errors > '1')
|
||||
{
|
||||
$errored[] = generate_device_link($interface, $interface['hostname'] . " - " . $interface['ifDescr'] . " - " . $interface['ifAlias'] . " - " . $interface['ifInErrors_delta'] . " - " . $interface['ifOutErrors_delta']);
|
||||
$errored++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo("Checked $i interfaces\n");
|
||||
|
||||
if (is_array($errored))
|
||||
{ // If there are errored ports
|
||||
$i = 0;
|
||||
$msg = "Interfaces with errors : \n\n";
|
||||
|
||||
foreach ($errored as $int)
|
||||
{
|
||||
$msg .= "$int\n"; // Add a line to the report email warning about them
|
||||
$i++;
|
||||
}
|
||||
// Send the alert email
|
||||
//notify($device, "Observium detected errors on $i interface" . ($i != 1 ? 's' : ''), $msg);
|
||||
}
|
||||
|
||||
echo("$errored interfaces with errors over the past 5 minutes.\n");
|
||||
|
||||
// EOF
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage poller
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage poller
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -15,20 +15,30 @@
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
// Get options before definitions!
|
||||
$options = getopt("o:d");
|
||||
$options = getopt("o:dt");
|
||||
$cload_time = microtime(TRUE);
|
||||
|
||||
require_once("includes/sql-config.inc.php");
|
||||
if (isset($options['o'])) {
|
||||
// Skip load full definitions, while not required on initial config
|
||||
define('OBS_DEFINITIONS_SKIP', TRUE);
|
||||
}
|
||||
require_once("includes/observium.inc.php");
|
||||
|
||||
if (is_cli()) {
|
||||
if (isset($options['o'])) {
|
||||
if (!is_cli()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($options['t'])) {
|
||||
print_cli(OBS_PROCESS_NAME . ' Load time: ' . elapsed_time($cload_time, 4) . PHP_EOL);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($options['o'])) {
|
||||
// get filtered options
|
||||
get_config_json($options['o']);
|
||||
//print_vars($options);
|
||||
} else {
|
||||
} else {
|
||||
// All config options
|
||||
get_config_json();
|
||||
//print(safe_json_encode($config));
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -5,41 +5,40 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("d");
|
||||
if (isset($options['d'])) { array_shift($argv); } // for compatibility
|
||||
if (isset($options['d'])) {
|
||||
array_shift($argv);
|
||||
} // for compatibility
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
|
||||
print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WRemove Device%n\n", 'color');
|
||||
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WRemove Device%n\n", 'color');
|
||||
|
||||
// Remove a host and all related data from the system
|
||||
if ($argv[1])
|
||||
{
|
||||
$host = strtolower($argv[1]);
|
||||
if (is_numeric($host))
|
||||
{
|
||||
$id = $host;
|
||||
} else {
|
||||
$id = get_device_id_by_hostname($host);
|
||||
}
|
||||
$delete_rrd = isset($argv[2]) && strtolower($argv[2]) === 'rrd';
|
||||
if ($argv[1]) {
|
||||
$host = strtolower($argv[1]);
|
||||
if (is_numeric($host)) {
|
||||
$id = $host;
|
||||
} else {
|
||||
$id = get_device_id_by_hostname($host);
|
||||
}
|
||||
$delete_rrd = isset($argv[2]) && strtolower($argv[2]) === 'rrd';
|
||||
|
||||
// Test if a valid id was fetched from get_device_id_by_hostname()
|
||||
if (isset($id) && is_numeric($id))
|
||||
{
|
||||
print_warning(delete_device($id, $delete_rrd));
|
||||
print_success("Device $host removed.");
|
||||
} else {
|
||||
print_error("Device $host doesn't exist!");
|
||||
}
|
||||
// Test if a valid id was fetched from get_device_id_by_hostname()
|
||||
if (isset($id) && is_numeric($id)) {
|
||||
print_warning(delete_device($id, $delete_rrd));
|
||||
print_success("Device $host removed.");
|
||||
} else {
|
||||
print_error("Device $host doesn't exist!");
|
||||
}
|
||||
|
||||
} else {
|
||||
print_message("%n
|
||||
|
375
discovery.php
@ -7,129 +7,150 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage discovery
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
// Get options before definitions!
|
||||
$options = getopt("h:i:m:n:p:U:dquaMV");
|
||||
$options = getopt("h:i:m:n:p:U:dfquaMV");
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
include("includes/discovery/functions.inc.php");
|
||||
|
||||
$cli = TRUE;
|
||||
|
||||
//if (is_cron()) { $options['q'] = TRUE; } // Set quiet for cron
|
||||
|
||||
$start = utime();
|
||||
$runtime_stats = array();
|
||||
$start = utime();
|
||||
$runtime_stats = [];
|
||||
|
||||
if (isset($options['V'])) {
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
if (is_array($options['V'])) { print_versions(); }
|
||||
exit;
|
||||
}
|
||||
if (isset($options['M'])) {
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
|
||||
print_message('Enabled discovery modules:');
|
||||
$m_disabled = array();
|
||||
foreach ($config['discovery_modules'] as $module => $ok) {
|
||||
if ($ok) {
|
||||
print_message(' ' . $module);
|
||||
if (is_array($options['V'])) {
|
||||
// Show more detailed Observium version and installed software versions
|
||||
print_versions();
|
||||
} else {
|
||||
$m_disabled[] = $module;
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION_LONG);
|
||||
}
|
||||
}
|
||||
if (count($m_disabled)) {
|
||||
print_message('Disabled discovery modules:');
|
||||
print_message(' ' . implode("\n ", $m_disabled));
|
||||
}
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($options['M'])) {
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
|
||||
print_message('Enabled discovery modules:');
|
||||
$m_disabled = [];
|
||||
foreach ($config['discovery_modules'] as $module => $ok) {
|
||||
if ($ok) {
|
||||
print_message(' ' . $module);
|
||||
} else {
|
||||
$m_disabled[] = $module;
|
||||
}
|
||||
}
|
||||
if (count($m_disabled)) {
|
||||
print_message('Disabled discovery modules:');
|
||||
print_message(' ' . implode("\n ", $m_disabled));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($options['q'])) {
|
||||
print_cli_banner();
|
||||
print_cli_banner();
|
||||
|
||||
if (OBS_DEBUG) { print_versions(); }
|
||||
if (OBS_DEBUG) {
|
||||
print_versions();
|
||||
}
|
||||
|
||||
// Warning about obsolete configs.
|
||||
if (print_obsolete_config()) { echo PHP_EOL; }
|
||||
// Warning about obsolete configs.
|
||||
if (print_obsolete_config()) {
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['u']) || isset($options['U']) ||
|
||||
(isset($options['h']) && in_array($options['h'], [ 'all', 'odd', 'even', 'none' ]))) {
|
||||
$options['u'] = TRUE;
|
||||
$options['u'] = TRUE;
|
||||
if (isset($options['f'])) {
|
||||
//$options['U'] = TRUE;
|
||||
}
|
||||
|
||||
include($config['install_dir'] . '/includes/update/update.php');
|
||||
include($config['install_dir'] . '/includes/update/update.php');
|
||||
if ($updating) {
|
||||
// DB schema updated. force alert/groups update
|
||||
$options['a'] = TRUE;
|
||||
}
|
||||
|
||||
// check remote poller params
|
||||
if (OBS_DISTRIBUTED) {
|
||||
check_local_poller();
|
||||
}
|
||||
} elseif (!isset($options['q'])) {
|
||||
// Warn about need DB schema update
|
||||
$db_version = get_db_version();
|
||||
$db_version = sprintf("%03d", $db_version + 1);
|
||||
if (is_file($config['install_dir'] . "/update/$db_version.sql") || is_file($config['install_dir'] . "/update/$db_version.php")) {
|
||||
print_warning("Your database schema is old and needs updating. Run from console:\n " . $config['install_dir'] . "/discovery.php -u");
|
||||
}
|
||||
unset($db_version);
|
||||
// Warn about need DB schema update
|
||||
$db_version = get_db_version();
|
||||
$db_version = sprintf("%03d", $db_version + 1);
|
||||
if (is_file($config['install_dir'] . "/update/$db_version.sql") || is_file($config['install_dir'] . "/update/$db_version.php")) {
|
||||
print_warning("Your database schema is old and needs updating. Run from console:\n " . $config['install_dir'] . "/discovery.php -u");
|
||||
}
|
||||
unset($db_version);
|
||||
}
|
||||
|
||||
$where = '';
|
||||
|
||||
if (isset($options['h'])) {
|
||||
$params = array();
|
||||
switch ($options['h']) {
|
||||
case 'odd':
|
||||
$options['n'] = 1;
|
||||
$options['i'] = 2;
|
||||
break;
|
||||
case 'even':
|
||||
$options['n'] = 0;
|
||||
$options['i'] = 2;
|
||||
break;
|
||||
case 'all':
|
||||
$where = ' ';
|
||||
$doing = 'all';
|
||||
break;
|
||||
case 'new':
|
||||
$where = ' AND (`last_discovered` IS NULL OR `last_discovered` = ? OR `force_discovery` = ?)';
|
||||
$params[] = '0000-00-00 00:00:00';
|
||||
$params[] = 1;
|
||||
$doing = 'new';
|
||||
$params = [];
|
||||
switch ($options['h']) {
|
||||
case 'odd':
|
||||
$options['n'] = 1;
|
||||
$options['i'] = 2;
|
||||
break;
|
||||
case 'even':
|
||||
$options['n'] = 0;
|
||||
$options['i'] = 2;
|
||||
break;
|
||||
case 'all':
|
||||
$where = ' ';
|
||||
$doing = 'all';
|
||||
break;
|
||||
case 'new':
|
||||
$where = ' AND (`last_discovered` IS NULL OR `last_discovered` = ? OR `force_discovery` = ?)';
|
||||
$params[] = '0000-00-00 00:00:00';
|
||||
$params[] = 1;
|
||||
$doing = 'new';
|
||||
|
||||
// add new devices on remote poller from actions queue
|
||||
if (OBS_DISTRIBUTED && function_exists('run_action_queue')) {
|
||||
run_action_queue('device_add');
|
||||
//run_action_queue('device_rename');
|
||||
//run_action_queue('device_delete');
|
||||
// add new devices on remote poller from actions queue
|
||||
if (OBS_DISTRIBUTED && function_exists('run_action_queue')) {
|
||||
run_action_queue('device_add');
|
||||
//run_action_queue('device_rename');
|
||||
//run_action_queue('device_delete');
|
||||
|
||||
// Update alert and group tables
|
||||
run_action_queue('tables_update');
|
||||
}
|
||||
break;
|
||||
case 'none':
|
||||
//$options['u'] = TRUE;
|
||||
break;
|
||||
default:
|
||||
$doing = $options['h'];
|
||||
if (is_numeric($options['h'])) {
|
||||
$where = ' AND `device_id` = ?';
|
||||
$params[] = $options['h'];
|
||||
} else {
|
||||
$where = ' AND `hostname` LIKE ?';
|
||||
$params[] = str_replace('*', '%', $options['h']);
|
||||
}
|
||||
}
|
||||
// Update alert and group tables
|
||||
run_action_queue('tables_update');
|
||||
}
|
||||
break;
|
||||
case 'none':
|
||||
//$options['u'] = TRUE;
|
||||
break;
|
||||
default:
|
||||
$doing = $options['h'];
|
||||
if (is_numeric($options['h'])) {
|
||||
$where = ' AND `device_id` = ?';
|
||||
$params[] = $options['h'];
|
||||
} else {
|
||||
$where = ' AND `hostname` LIKE ?';
|
||||
$params[] = str_replace('*', '%', $options['h']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['i'], $options['n']) && $options['i']) {
|
||||
$where .= ' AND MOD(device_id,' . $options['i'] . ') = ?';
|
||||
$params[] = $options['n'];
|
||||
$doing = $options['n'] . '/' . $options['i'];
|
||||
$where .= ' AND MOD(device_id,' . $options['i'] . ') = ?';
|
||||
$params[] = $options['n'];
|
||||
$doing = $options['n'] . '/' . $options['i'];
|
||||
}
|
||||
|
||||
if (!$where && !$options['u'] && !isset($options['a'])) {
|
||||
print_message("%n
|
||||
print_message("%n
|
||||
USAGE:
|
||||
$scriptname [-dquV] [-i instances] [-n number] [-m module] [-h device]
|
||||
|
||||
@ -148,12 +169,13 @@ OPTIONS:
|
||||
-i Discovery instance.
|
||||
-n Discovery number.
|
||||
-q Quiet output.
|
||||
-a Force update Groups/Alerts table
|
||||
-a Update Groups/Alerts table
|
||||
-u Upgrade DB schema
|
||||
-M Show globally enabled/disabled modules and exit.
|
||||
-V Show version and exit.
|
||||
|
||||
DEBUGGING OPTIONS:
|
||||
-f Force requested option
|
||||
-d Enable debugging output.
|
||||
-dd More verbose debugging output.
|
||||
-m Specify modules (separated by commas) to be run.
|
||||
@ -162,100 +184,102 @@ DEBUGGING OPTIONS:
|
||||
}
|
||||
|
||||
if ($config['version_check'] && ($options['h'] !== 'new' || $options['u'])) {
|
||||
include($config['install_dir'] . '/includes/versioncheck.inc.php');
|
||||
include($config['install_dir'] . '/includes/versioncheck.inc.php');
|
||||
}
|
||||
|
||||
if (!$where) {
|
||||
// Only update Group/Alert tables
|
||||
if (isset($options['a'])) {
|
||||
|
||||
if (OBS_DISTRIBUTED && function_exists('run_action_queue')) {
|
||||
//run_action_queue('device_add');
|
||||
//run_action_queue('device_rename');
|
||||
//run_action_queue('device_delete');
|
||||
// Only update Group/Alert tables
|
||||
if (isset($options['a'])) {
|
||||
|
||||
// Update alert and group tables
|
||||
run_action_queue('tables_update');
|
||||
} else {
|
||||
$silent = isset($options['q']);
|
||||
if (function_exists('update_group_tables')) { update_group_tables($silent); } // Not exist in CE
|
||||
if (function_exists('update_alert_tables')) { update_alert_tables($silent); }
|
||||
// Distributed handling doesn't make sense here. It's just database action.
|
||||
// if (OBS_DISTRIBUTED && function_exists('run_action_queue')) {
|
||||
//run_action_queue('device_add');
|
||||
//run_action_queue('device_rename');
|
||||
//run_action_queue('device_delete');
|
||||
|
||||
// Update alert and group tables
|
||||
// run_action_queue('tables_update', $options);
|
||||
// } else {
|
||||
$silent = isset($options['q']);
|
||||
if (function_exists('update_group_tables')) {
|
||||
update_group_tables($silent);
|
||||
} // Not exist in CE
|
||||
if (function_exists('update_alert_tables')) {
|
||||
update_alert_tables($silent);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
// For not new devices discovery, skip down devices
|
||||
if ($options['h'] !== 'new') {
|
||||
$where .= ' AND `status` = ?';
|
||||
$params[] = 1;
|
||||
if ($options['h'] !== 'new' && !isset($options['f'])) {
|
||||
$where .= ' AND `status` = ?';
|
||||
$params[] = 1;
|
||||
}
|
||||
|
||||
// Discovered device counter
|
||||
$discovered_devices = 0;
|
||||
|
||||
print_cli_heading("%WStarting discovery run at " . date("Y-m-d H:i:s"), 0);
|
||||
|
||||
$where .= ' AND `poller_id` = ?';
|
||||
$where .= ' AND `poller_id` = ?';
|
||||
$params[] = $config['poller_id'];
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` WHERE `disabled` = 0 $where ORDER BY `last_discovered_timetaken` ASC", $params) as $device) {
|
||||
// Additional check if device SNMPable, because during
|
||||
// discovery many devices (long time), the some device can be switched off
|
||||
if ($options['h'] === 'new' || isSNMPable($device)) {
|
||||
discover_device($device, $options);
|
||||
} else {
|
||||
$string = "Device '" . $device['hostname'] . "' skipped, because switched off during runtime discovery process.";
|
||||
print_debug($string);
|
||||
logfile($argv[0] . ": $string");
|
||||
}
|
||||
// Additional check if device SNMPable, because during
|
||||
// discovery many devices (long time), some device can be switched off
|
||||
if ($options['h'] === 'new' || is_snmpable($device)) {
|
||||
$discover_status = discover_device($device, $options);
|
||||
} else {
|
||||
$string = "Device '" . $device['hostname'] . "' skipped, because switched off during runtime discovery process.";
|
||||
print_debug($string);
|
||||
logfile($argv[0] . ": $string");
|
||||
$discover_status = FALSE;
|
||||
}
|
||||
|
||||
if ($discover_status !== FALSE) {
|
||||
$discovered_devices++;
|
||||
}
|
||||
}
|
||||
|
||||
print_cli_heading("%WFinished discovery run at " . date("Y-m-d H:i:s"), 0);
|
||||
|
||||
$end = utime();
|
||||
$run = $end - $start;
|
||||
$discovery_time = substr($run, 0, 5);
|
||||
$discovery_time = elapsed_time($start, 4);
|
||||
|
||||
// Update Group/Alert tables
|
||||
if (($discovered_devices && !isset($options['m'])) || isset($options['a'])) {
|
||||
$silent = isset($options['q']);
|
||||
if (OBS_DISTRIBUTED && !isset($options['a']) && function_exists('add_action_queue') &&
|
||||
$action_id = add_action_queue('tables_update', 'discovery', [ 'silent' => $silent ])) {
|
||||
print_message("Update alert and group tables added to queue [$action_id].");
|
||||
//log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].", NULL, 'info', NULL, 7);
|
||||
} else {
|
||||
if (function_exists('update_group_tables')) { update_group_tables($silent); } // Not exist in CE
|
||||
if (function_exists('update_alert_tables')) { update_alert_tables($silent); }
|
||||
}
|
||||
$silent = isset($options['q']);
|
||||
if (OBS_DISTRIBUTED && !isset($options['a']) && function_exists('add_action_queue') &&
|
||||
$action_id = add_action_queue('tables_update', 'discovery', ['silent' => $silent])) {
|
||||
print_message("Update alert and group tables added to queue [$action_id].");
|
||||
//log_event("Device with hostname '$hostname' added to queue [$action_id] for addition on remote Poller [{$vars['poller_id']}].", NULL, 'info', NULL, 7);
|
||||
} else {
|
||||
// Not exist in CE
|
||||
if (function_exists('update_group_tables')) {
|
||||
// update_group_tables($silent);
|
||||
update_group_tables();
|
||||
}
|
||||
if (function_exists('update_alert_tables')) {
|
||||
update_alert_tables($silent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($discovered_devices) {
|
||||
// Single device ID convert to hostname for log
|
||||
if (is_numeric($doing)) {
|
||||
$doing = $device['hostname'];
|
||||
// Single device ID convert to hostname for log
|
||||
if (is_numeric($doing)) {
|
||||
$doing = $device['hostname'];
|
||||
|
||||
// This discovery passed from wrapper and with process id
|
||||
if ($config['poller_id'] > 0 &&
|
||||
$poller = dbFetchRow('SELECT * FROM `pollers` WHERE `poller_id` = ?', [ $config['poller_id'] ])) {
|
||||
print_debug_vars($poller, 1);
|
||||
$host_id = get_local_id();
|
||||
$update = [];
|
||||
if ($poller['host_id'] != $host_id) {
|
||||
$update['host_id'] = $host_id;
|
||||
log_event("Poller ".$config['poller_id']." host ID changed: '".$poller['host_id']."' -> '".$host_id."'");
|
||||
}
|
||||
if ($poller['host_uname'] != php_uname()) {
|
||||
$update['host_uname'] = php_uname();
|
||||
log_event("Poller ".$config['poller_id']." host uname changed: '".$poller['host_uname']."' -> '".$update['host_uname']."'");
|
||||
}
|
||||
if (count($update)) {
|
||||
dbUpdate($update, 'pollers', '`poller_id` = ?', [ $config['poller_id'] ]);
|
||||
}
|
||||
// This discovery passed from wrapper and with process id
|
||||
if (OBS_DISTRIBUTED && !$options['u']) {
|
||||
check_local_poller();
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (!isset($options['q']) && !$options['u']) {
|
||||
print_warning("WARNING: 0 devices discovered." . ($options['h'] !== 'new' ? " Did you specify a device that does not exist?" : ''));
|
||||
print_warning("WARNING: 0 devices discovered." . ($options['h'] !== 'new' ? " Did you specify a device that does not exist?" : ''));
|
||||
}
|
||||
|
||||
$string = $argv[0] . ": $doing - $discovered_devices devices discovered in $discovery_time secs";
|
||||
@ -264,42 +288,43 @@ logfile($string);
|
||||
|
||||
// Clean stale observium processes
|
||||
$process_sql = "SELECT * FROM `observium_processes` WHERE `poller_id` = ? AND `process_start` < ?";
|
||||
foreach (dbFetchRows($process_sql, [ $config['poller_id'], $config['time']['fourhour'] ]) as $process) {
|
||||
// We found processes in DB, check if it exist on system
|
||||
print_debug_vars($process);
|
||||
$pid_info = get_pid_info($process['process_pid']);
|
||||
if (is_array($pid_info) && str_contains($pid_info['COMMAND'], $process['process_name'])) {
|
||||
// Process still running
|
||||
} else {
|
||||
// Remove stalled DB entries
|
||||
dbDelete('observium_processes', '`process_id` = ?', array($process['process_id']));
|
||||
print_debug("Removed stale process entry from DB (cmd: '" . $process['process_command'] . "', PID: '" . $process['process_pid'] . "')");
|
||||
}
|
||||
foreach (dbFetchRows($process_sql, [ $config['poller_id'], get_time('fourhour') ]) as $process) {
|
||||
// We found processes in DB, check if it exists on a system
|
||||
print_debug_vars($process);
|
||||
$pid_info = get_pid_info($process['process_pid']);
|
||||
if (is_array($pid_info) && str_contains($pid_info['COMMAND'], $process['process_name'])) {
|
||||
// Process still running
|
||||
} else {
|
||||
// Remove stalled DB entries
|
||||
dbDelete('observium_processes', '`process_id` = ?', [$process['process_id']]);
|
||||
print_debug("Removed stale process entry from DB (cmd: '" . $process['process_command'] . "', PID: '" . $process['process_pid'] . "')");
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($options['q'])) {
|
||||
if ($config['snmp']['hide_auth']) {
|
||||
print_debug("NOTE, \$config['snmp']['hide_auth'] is set to TRUE, snmp community and snmp v3 auth hidden from debug output.");
|
||||
}
|
||||
if ($config['snmp']['hide_auth']) {
|
||||
print_debug("NOTE, \$config['snmp']['hide_auth'] is set to TRUE, snmp community and snmp v3 auth hidden from debug output.");
|
||||
}
|
||||
|
||||
print_cli_data('Devices Discovered', $discovered_devices, 0);
|
||||
print_cli_data('Discovery Time', $discovery_time . " secs", 0);
|
||||
print_cli_data('Memory usage', formatStorage(memory_get_usage(TRUE), 2, 4) .
|
||||
' (peak: ' . formatStorage(memory_get_peak_usage(TRUE), 2, 4) . ')', 0);
|
||||
print_cli_data('MySQL Usage', 'Cell[' . ($db_stats['fetchcell'] + 0) . '/' . round($db_stats['fetchcell_sec'] + 0, 3) . 's]' .
|
||||
' Row[' . ($db_stats['fetchrow'] + 0) . '/' . round($db_stats['fetchrow_sec'] + 0, 3) . 's]' .
|
||||
' Rows[' . ($db_stats['fetchrows'] + 0) . '/' . round($db_stats['fetchrows_sec'] + 0, 3) . 's]' .
|
||||
' Column[' . ($db_stats['fetchcol'] + 0) . '/' . round($db_stats['fetchcol_sec'] + 0, 3) . 's]' .
|
||||
' Update[' . ($db_stats['update'] + 0) . '/' . round($db_stats['update_sec'] + 0, 3) . 's]' .
|
||||
' Insert[' . ($db_stats['insert'] + 0) . '/' . round($db_stats['insert_sec'] + 0, 3) . 's]' .
|
||||
' Delete[' . ($db_stats['delete'] + 0) . '/' . round($db_stats['delete_sec'] + 0, 3) . 's]', 0);
|
||||
print_cli_data('Devices Discovered', $discovered_devices, 0);
|
||||
print_cli_data('Discovery Time', $discovery_time . " secs", 0);
|
||||
print_cli_data('Definitions', $defs_time . " secs", 0);
|
||||
print_cli_data('Memory usage', format_bytes(memory_get_usage(TRUE), 2, 4) .
|
||||
' (peak: ' . format_bytes(memory_get_peak_usage(TRUE), 2, 4) . ')', 0);
|
||||
print_cli_data('MySQL Usage', 'Cell[' . ($db_stats['fetchcell'] + 0) . '/' . round($db_stats['fetchcell_sec'] + 0, 3) . 's]' .
|
||||
' Row[' . ($db_stats['fetchrow'] + 0) . '/' . round($db_stats['fetchrow_sec'] + 0, 3) . 's]' .
|
||||
' Rows[' . ($db_stats['fetchrows'] + 0) . '/' . round($db_stats['fetchrows_sec'] + 0, 3) . 's]' .
|
||||
' Column[' . ($db_stats['fetchcol'] + 0) . '/' . round($db_stats['fetchcol_sec'] + 0, 3) . 's]' .
|
||||
' Update[' . ($db_stats['update'] + 0) . '/' . round($db_stats['update_sec'] + 0, 3) . 's]' .
|
||||
' Insert[' . ($db_stats['insert'] + 0) . '/' . round($db_stats['insert_sec'] + 0, 3) . 's]' .
|
||||
' Delete[' . ($db_stats['delete'] + 0) . '/' . round($db_stats['delete_sec'] + 0, 3) . 's]', 0);
|
||||
|
||||
$rrd_times = [];
|
||||
foreach ($GLOBALS['rrdtool'] as $cmd => $data) {
|
||||
$rrd_times[] = $cmd . "[" . $data['count'] . "/" . round($data['time'], 3) . "s]";
|
||||
}
|
||||
$rrd_times = [];
|
||||
foreach ($GLOBALS['rrdtool'] as $cmd => $data) {
|
||||
$rrd_times[] = $cmd . "[" . $data['count'] . "/" . round($data['time'], 3) . "s]";
|
||||
}
|
||||
|
||||
print_cli_data('RRDTool Usage', implode(" ", $rrd_times), 0);
|
||||
print_cli_data('RRDTool Usage', implode(" ", $rrd_times), 0);
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
119
housekeeping.php
@ -7,69 +7,95 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage cli
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
chdir(dirname($argv[0]));
|
||||
|
||||
$options = getopt("A:VyaselurpdbiT");
|
||||
$options = getopt("A:VyaselurpdbitxT");
|
||||
|
||||
include("includes/sql-config.inc.php");
|
||||
include("includes/observium.inc.php");
|
||||
|
||||
$cli = is_cli();
|
||||
|
||||
if (isset($options['V'])) {
|
||||
print_message(OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION);
|
||||
if (is_array($options['V'])) { print_versions(); }
|
||||
exit;
|
||||
print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
|
||||
if (is_array($options['V'])) {
|
||||
print_versions();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Prevent run housekeeping on remote pollers (that not needed)
|
||||
if ($config['poller_id'] !== 0) {
|
||||
print_message("%yHouseKeeping only needs to be run on the main node.%n\n", 'color');
|
||||
exit;
|
||||
// Prevent running housekeeping on remote pollers (not needed, won't work properly, potential data loss vector)
|
||||
if (!isset($options['f']) && $config['poller_id'] !== 0) {
|
||||
print_message("%yHousekeeping only needs to be run on the main node. Do not run housekeeping on partitioned pollers.%n\n", 'color');
|
||||
exit;
|
||||
}
|
||||
|
||||
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WHousekeeping%n\n", 'color');
|
||||
if (OBS_DEBUG) {
|
||||
print_versions();
|
||||
}
|
||||
*/
|
||||
print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WHouseKeeping%n\n", 'color');
|
||||
if (OBS_DEBUG) { print_versions(); }
|
||||
|
||||
// For interactive prompt/answer checks
|
||||
// if it is started from crontab - prompt disabled and answer always 'yes'
|
||||
if (is_cron()) {
|
||||
$prompt = FALSE;
|
||||
$prompt = FALSE;
|
||||
} else {
|
||||
$prompt = !isset($options['y']);
|
||||
$prompt = !isset($options['y']);
|
||||
}
|
||||
$answer = TRUE;
|
||||
|
||||
$modules = array();
|
||||
$modules = [];
|
||||
|
||||
if (isset($options['a']) || isset($options['s'])) {
|
||||
$modules[] = 'syslog';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['e'])) {
|
||||
$modules[] = 'eventlog';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['l'])) {
|
||||
$modules[] = 'alertlog';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['u'])) {
|
||||
$modules[] = 'authlog';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['p'])) {
|
||||
$modules[] = 'ports';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['b'])) {
|
||||
$modules[] = 'staledb';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['i'])) {
|
||||
$modules[] = 'inventory';
|
||||
}
|
||||
if (isset($options['a']) || isset($options['r'])) {
|
||||
$modules[] = 'rrd';
|
||||
}
|
||||
if (isset($options['x'])) {
|
||||
$modules[] = 'billing_data';
|
||||
}
|
||||
|
||||
if (isset($options['a']) || isset($options['s'])) { $modules[] = 'syslog'; }
|
||||
if (isset($options['a']) || isset($options['e'])) { $modules[] = 'eventlog'; }
|
||||
if (isset($options['a']) || isset($options['l'])) { $modules[] = 'alertlog'; }
|
||||
if (isset($options['a']) || isset($options['u'])) { $modules[] = 'authlog'; }
|
||||
if (isset($options['a']) || isset($options['p'])) { $modules[] = 'ports'; }
|
||||
if (isset($options['a']) || isset($options['b'])) { $modules[] = 'staledb'; }
|
||||
if (isset($options['a']) || isset($options['i'])) { $modules[] = 'inventory'; }
|
||||
if (isset($options['a']) || isset($options['r'])) { $modules[] = 'rrd'; }
|
||||
|
||||
// Get age from command line
|
||||
if (isset($options['A'])) {
|
||||
$age = age_to_seconds($options['A']);
|
||||
if ($age) {
|
||||
foreach ($modules as $module) {
|
||||
if ($module === 'ports') { $module = 'deleted_ports'; }
|
||||
$config['housekeeping'][$module]['age'] = $age;
|
||||
$age = age_to_seconds($options['A']);
|
||||
if ($age) {
|
||||
foreach ($modules as $module) {
|
||||
if ($module === 'ports') {
|
||||
$module = 'deleted_ports';
|
||||
}
|
||||
$config['housekeeping'][$module]['age'] = $age;
|
||||
}
|
||||
} else {
|
||||
print_debug("Invalid age specified '" . $options['A'] . "', skipped.");
|
||||
}
|
||||
} else {
|
||||
print_debug("Invalid age specified '" . $options['A'] . "', skipped.");
|
||||
}
|
||||
unset($age, $module);
|
||||
unset($age, $module);
|
||||
}
|
||||
|
||||
if (!count($modules)) {
|
||||
print_message("%n
|
||||
print_message("%n
|
||||
USAGE:
|
||||
$scriptname [-Vyaselrptdbu] [-A <age>]
|
||||
|
||||
@ -81,7 +107,7 @@ NOTE, by default $scriptname asks 'Are you sure want to delete (y/N)?'.
|
||||
OPTIONS:
|
||||
-V Show version and exit.
|
||||
-y Automatically answer 'yes' to prompts
|
||||
-a Maintain all modules as specified below.
|
||||
-a Maintain all modules except billing as specified below.
|
||||
-s Clean up syslog
|
||||
-e Clean up event log
|
||||
-l Clean up alert log
|
||||
@ -91,6 +117,9 @@ OPTIONS:
|
||||
-p Clean up deleted ports
|
||||
-b Clean up stale database entries
|
||||
-A <age> Specifies maximum age for all modules (overrides configuration)
|
||||
-f Force run Housekeeping on Poller ID other than 0 (main)
|
||||
|
||||
-x Clean up billing data
|
||||
|
||||
DEBUGGING OPTIONS:
|
||||
-T Testing, not do any actions, only show counts.
|
||||
@ -102,18 +131,22 @@ EXAMPLES:
|
||||
$scriptname -ya Clean up by all modules without prompts
|
||||
|
||||
%rInvalid arguments!%n", 'color', FALSE);
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
$test = isset($options['T']);
|
||||
foreach ($modules as $module) {
|
||||
if (is_file($config['install_dir'] . "/includes/housekeeping/$module.inc.php")) {
|
||||
include($config['install_dir'] . "/includes/housekeeping/$module.inc.php");
|
||||
if (!$test) { set_obs_attrib("housekeeping_lastrun_$module", time()); }
|
||||
} else {
|
||||
print_warning("Housekeeping module not found: $module");
|
||||
}
|
||||
if (is_file($config['install_dir'] . "/includes/housekeeping/$module.inc.php")) {
|
||||
include($config['install_dir'] . "/includes/housekeeping/$module.inc.php");
|
||||
if (!$test) {
|
||||
set_obs_attrib("housekeeping_lastrun_$module", time());
|
||||
}
|
||||
} else {
|
||||
print_warning("Housekeeping module not found: $module");
|
||||
}
|
||||
}
|
||||
if (!$test) {
|
||||
set_obs_attrib("housekeeping_lastrun", time());
|
||||
}
|
||||
if (!$test) { set_obs_attrib("housekeeping_lastrun", time()); }
|
||||
|
||||
// EOF
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
Options FollowSymlinks Multiviews
|
||||
|
||||
ErrorDocument 404 /error.php?404
|
||||
RedirectMatch 404 /\.
|
||||
|
||||
RewriteEngine on
|
||||
RewriteEngine On
|
||||
RewriteBase /
|
||||
#Block access to hidden files/dirs
|
||||
RewriteRule ^\..*$ - [F,L]
|
||||
|
@ -6,286 +6,249 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated'])
|
||||
{
|
||||
print_json_status('failed', 'Unauthorized.');
|
||||
exit();
|
||||
if (!$_SESSION['authenticated']) {
|
||||
print_json_status('failed', 'Unauthorized.');
|
||||
exit();
|
||||
}
|
||||
|
||||
$vars = get_vars([ 'JSON', 'POST' ]); // Got a JSON payload. Replace $var.
|
||||
|
||||
$readonly = $_SESSION['userlevel'] < 7;
|
||||
$readonly = $_SESSION['userlevel'] < 7;
|
||||
$limitwrite = $_SESSION['userlevel'] >= 9;
|
||||
$readwrite = $_SESSION['userlevel'] >= 10;
|
||||
|
||||
switch ($vars['action']) {
|
||||
case "theme":
|
||||
$pref = 'web_theme_default';
|
||||
if ($vars['value'] === 'reset') {
|
||||
session_unset_var("theme");
|
||||
if ($config['web_theme_default'] === 'system') {
|
||||
// Override default
|
||||
session_unset_var("theme_default");
|
||||
}
|
||||
case "theme":
|
||||
$pref = 'web_theme_default';
|
||||
if ($vars['value'] === 'reset') {
|
||||
session_unset_var("theme");
|
||||
if ($config['web_theme_default'] === 'system') {
|
||||
// Override default
|
||||
session_unset_var("theme_default");
|
||||
}
|
||||
|
||||
if (del_user_pref($_SESSION['user_id'], $pref)) {
|
||||
print_json_status('ok', 'Theme reset.');
|
||||
}
|
||||
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
|
||||
print_json_status('ok', 'Theme set.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid theme.');
|
||||
}
|
||||
break;
|
||||
if (del_user_pref($_SESSION['user_id'], $pref)) {
|
||||
print_json_status('ok', 'Theme reset.');
|
||||
}
|
||||
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
|
||||
print_json_status('ok', 'Theme set.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid theme.');
|
||||
}
|
||||
break;
|
||||
|
||||
case "big_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
|
||||
print_json_status('ok', 'Big graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_set_var("big_graphs", TRUE);
|
||||
//print_json_status('ok', 'Big graphs set.');
|
||||
break;
|
||||
case "big_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
|
||||
print_json_status('ok', 'Big graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
break;
|
||||
|
||||
case "normal_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
|
||||
print_json_status('ok', 'Normal graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_unset_var("big_graphs");
|
||||
//print_json_status('ok', 'Small graphs set.');
|
||||
break;
|
||||
case "normal_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
|
||||
print_json_status('ok', 'Normal graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
break;
|
||||
|
||||
case "touch_on":
|
||||
session_set_var("touch", TRUE);
|
||||
print_json_status('ok', 'Touch mode enabled.');
|
||||
break;
|
||||
case "touch_on":
|
||||
session_set_var("touch", TRUE);
|
||||
print_json_status('ok', 'Touch mode enabled.');
|
||||
break;
|
||||
|
||||
case "touch_off":
|
||||
session_unset_var("touch");
|
||||
print_json_status('ok', 'Touch mode disabled.');
|
||||
break;
|
||||
case "touch_off":
|
||||
session_unset_var("touch");
|
||||
print_json_status('ok', 'Touch mode disabled.');
|
||||
break;
|
||||
|
||||
case "set_refresh":
|
||||
session_set_var("dark_mode", TRUE);
|
||||
print_json_status('ok', 'Dark mode set.');
|
||||
break;
|
||||
case "save_grid": // Save current layout of dashboard grid
|
||||
|
||||
case "alert_assoc_edit":
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if (!$readwrite) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
foreach ($vars['grid'] as $w) {
|
||||
dbUpdate(['x' => $w['x'], 'y' => $w['y'], 'width' => $w['width'], 'height' => $w['height'],], 'dash_widgets',
|
||||
'`widget_id` = ?', [$w['id']]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
if (dbFetchRow("SELECT * FROM `alert_tests` WHERE `alert_test_id` = ?", array($vars['alert_test_id']))) {
|
||||
case "add_widget": // Add widget of 'widget_type' to dashboard 'dash_id'
|
||||
|
||||
$rows_updated = dbUpdate([ 'alert_assoc' => $vars['alert_assoc'] ], 'alert_tests', '`alert_test_id` = ?', [ $vars['alert_test_id'] ]);
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($rows_updated) {
|
||||
update_alert_table($vars['alert_test_id']);
|
||||
print_json_status('ok', '', [ 'id' => $vars['alert_test_id'],
|
||||
'redirect' => generate_url([ 'page' => 'alert_check', 'alert_test_id' => $vars['alert_test_id'] ]) ]);
|
||||
} else {
|
||||
print_json_status('failed', 'Database was not updated.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Alert Checker does not exist: [' . $vars['alert_test_id'] . ']');
|
||||
}
|
||||
break;
|
||||
if (isset($vars['dash_id']) && isset($vars['widget_type'])) {
|
||||
$widget_id = dbInsert(['dash_id' => $vars['dash_id'], 'widget_config' => json_encode([]), 'widget_type' => $vars['widget_type']],
|
||||
'dash_widgets'
|
||||
);
|
||||
}
|
||||
|
||||
case "save_grid": // Save current layout of dashboard grid
|
||||
if ($widget_id) {
|
||||
print_json_status('ok', '', ['id' => $widget_id]);
|
||||
} else {
|
||||
//print_r($vars); // For debugging
|
||||
}
|
||||
break;
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
case "delete_ap":
|
||||
|
||||
foreach ($vars['grid'] as $w) {
|
||||
dbUpdate(array('x' => $w['x'], 'y' => $w['y'], 'width' => $w['width'], 'height' => $w['height'],), 'dash_widgets',
|
||||
'`widget_id` = ?', array($w['id'])
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
case "add_widget": // Add widget of 'widget_type' to dashboard 'dash_id'
|
||||
if (is_numeric($vars['id'])) {
|
||||
$rows_deleted = dbDelete('wifi_aps', '`wifi_ap_id` = ?', [$vars['id']]);
|
||||
}
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'AP Deleted', ['id' => $vars['id']]);
|
||||
}
|
||||
|
||||
if (isset($vars['dash_id']) && isset($vars['widget_type'])) {
|
||||
$widget_id = dbInsert(array('dash_id' => $vars['dash_id'], 'widget_config' => json_encode(array()), 'widget_type' => $vars['widget_type']),
|
||||
'dash_widgets'
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
if ($widget_id) {
|
||||
print_json_status('ok', '', [ 'id' => $widget_id ]);
|
||||
} else {
|
||||
//print_r($vars); // For debugging
|
||||
}
|
||||
break;
|
||||
case "del_widget":
|
||||
|
||||
case "delete_ap":
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
if (is_numeric($vars['widget_id'])) {
|
||||
$rows_deleted = dbDelete('dash_widgets', '`widget_id` = ?', [$vars['widget_id']]);
|
||||
}
|
||||
|
||||
if (is_numeric($vars['id'])) {
|
||||
$rows_deleted = dbDelete('wifi_aps', '`wifi_ap_id` = ?', array($vars['id']));
|
||||
}
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'Widget Deleted.', ['id' => $vars['widget_id']]);
|
||||
}
|
||||
break;
|
||||
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'AP Deleted', [ 'id' => $vars['id'] ]);
|
||||
}
|
||||
case "dash_rename":
|
||||
|
||||
break;
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
case "del_widget":
|
||||
if (is_numeric($vars['dash_id'])) {
|
||||
$rows_updated = dbUpdate(['dash_name' => $vars['dash_name']], 'dashboards', '`dash_id` = ?', [$vars['dash_id']]);
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid Dashboard ID.');
|
||||
}
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
if ($rows_updated) {
|
||||
print_json_status('ok', 'Dashboard Name Updated.', ['id' => $vars['dash_id']]);
|
||||
} else {
|
||||
print_json_status('failed', 'Update Failed.');
|
||||
}
|
||||
|
||||
if (is_numeric($vars['widget_id'])) {
|
||||
$rows_deleted = dbDelete('dash_widgets', '`widget_id` = ?', array($vars['widget_id']));
|
||||
}
|
||||
break;
|
||||
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'Widget Deleted.', [ 'id' => $vars['widget_id'] ]);
|
||||
}
|
||||
break;
|
||||
case "dash_delete":
|
||||
|
||||
case "dash_rename":
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
if (is_numeric($vars['dash_id'])) {
|
||||
$rows_deleted = dbDelete('dash_widgets', '`dash_id` = ?', [$vars['dash_id']]);
|
||||
$rows_deleted += dbDelete('dashboards', '`dash_id` = ?', [$vars['dash_id']]);
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid Dashboard ID.');
|
||||
}
|
||||
|
||||
if (is_numeric($vars['dash_id'])) {
|
||||
$rows_updated = dbUpdate(array('dash_name' => $vars['dash_name']), 'dashboards', '`dash_id` = ?', array($vars['dash_id']));
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid Dashboard ID.');
|
||||
}
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'Dashboard Deleted.', ['id' => $vars['dash_id']]);
|
||||
} else {
|
||||
print_json_status('failed', 'Deletion Failed.');
|
||||
}
|
||||
|
||||
if ($rows_updated) {
|
||||
print_json_status('ok', 'Dashboard Name Updated.', [ 'id' => $vars['dash_id'] ]);
|
||||
} else {
|
||||
print_json_status('failed', 'Update Failed.');
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
case "update_widget_config":
|
||||
|
||||
case "dash_delete":
|
||||
//print_r($vars);
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (is_numeric($vars['dash_id'])) {
|
||||
$rows_deleted = dbDelete('dash_widgets', '`dash_id` = ?', array($vars['dash_id']));
|
||||
$rows_deleted += dbDelete('dashboards', '`dash_id` = ?', array($vars['dash_id']));
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid Dashboard ID.');
|
||||
}
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [$vars['widget_id']]);
|
||||
$widget['widget_config'] = safe_json_decode($widget['widget_config']);
|
||||
|
||||
if ($rows_deleted) {
|
||||
print_json_status('ok', 'Dashboard Deleted.', [ 'id' => $vars['dash_id'] ]);
|
||||
} else {
|
||||
print_json_status('failed', 'Deletion Failed.');
|
||||
}
|
||||
// Verify config value applies to this widget here
|
||||
|
||||
break;
|
||||
$default_on = ['legend'];
|
||||
|
||||
case "update_widget_config":
|
||||
if (isset($vars['config_field']) && isset($vars['config_value'])) {
|
||||
if (empty($vars['config_value']) ||
|
||||
(in_array($vars['config_field'], $default_on) && get_var_true($vars['config_value'])) ||
|
||||
(!in_array($vars['config_field'], $default_on) && get_var_false($vars['config_value']))) {
|
||||
// Just unset the value if it's empty or it's a default value.
|
||||
unset($widget['widget_config'][$vars['config_field']]);
|
||||
} else {
|
||||
$widget['widget_config'][$vars['config_field']] = $vars['config_value'];
|
||||
}
|
||||
|
||||
//print_r($vars);
|
||||
dbUpdate(['widget_config' => json_encode($widget['widget_config'])], 'dash_widgets',
|
||||
'`widget_id` = ?', [$widget['widget_id']]
|
||||
);
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if ($readonly) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
//echo dbError();
|
||||
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", array($vars['widget_id']));
|
||||
$widget['widget_config'] = safe_json_decode($widget['widget_config']);
|
||||
print_json_status('ok', 'Widget Updated.', ['id' => $widget['widget_id']]);
|
||||
} else {
|
||||
print_json_status('failed', 'Update Failed.');
|
||||
}
|
||||
|
||||
// Verify config value applies to this widget here
|
||||
break;
|
||||
|
||||
$default_on = [ 'legend' ];
|
||||
default:
|
||||
|
||||
if (isset($vars['config_field']) && isset($vars['config_value'])) {
|
||||
if ( empty($vars['config_value']) ||
|
||||
(in_array($vars['config_field'], $default_on) && get_var_true($vars['config_value'])) ||
|
||||
(!in_array($vars['config_field'], $default_on) && get_var_false($vars['config_value'])) ) {
|
||||
// Just unset the value if it's empty or it's a default value.
|
||||
unset($widget['widget_config'][$vars['config_field']]);
|
||||
} else {
|
||||
$widget['widget_config'][$vars['config_field']] = $vars['config_value'];
|
||||
}
|
||||
// Validate CSRF Token
|
||||
//r($vars);
|
||||
$json = '';
|
||||
if (!str_contains_array($vars['action'], ['widget', 'dash', 'settings_user']) && // widget & dashboard currently not send request token
|
||||
!request_token_valid($vars, $json)) {
|
||||
$json = safe_json_decode($json);
|
||||
$json['reload'] = TRUE;
|
||||
print_json_status('failed', 'CSRF Token missing. Reload page.', $json);
|
||||
exit();
|
||||
}
|
||||
unset($json);
|
||||
|
||||
dbUpdate(array('widget_config' => json_encode($widget['widget_config'])), 'dash_widgets',
|
||||
'`widget_id` = ?', array($widget['widget_id'])
|
||||
);
|
||||
|
||||
//echo dbError();
|
||||
|
||||
print_json_status('ok', 'Widget Updated.', [ 'id' => $widget['widget_id'] ]);
|
||||
} else {
|
||||
print_json_status('failed', 'Update Failed.');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
// Validate CSRF Token
|
||||
//r($vars);
|
||||
$json = '';
|
||||
if (!str_contains_array($vars['action'], [ 'widget', 'dash', 'settings_user' ]) && // widget & dashboard currently not send request token
|
||||
!request_token_valid($vars, $json)) {
|
||||
$json = safe_json_decode($json);
|
||||
$json['reload'] = TRUE;
|
||||
print_json_status('failed', 'CSRF Token missing. Reload page.', $json);
|
||||
exit();
|
||||
}
|
||||
unset($json);
|
||||
|
||||
$action_path = __DIR__ . '/actions/'. $vars['action'] . '.inc.php';
|
||||
if (is_alpha($vars['action']) && is_file($action_path))
|
||||
{
|
||||
include $action_path;
|
||||
} else {
|
||||
print_json_status('failed', 'Unknown action requested.');
|
||||
}
|
||||
$action_path = __DIR__ . '/actions/' . $vars['action'] . '.inc.php';
|
||||
if (is_alpha($vars['action']) && is_file($action_path)) {
|
||||
include $action_path;
|
||||
} else {
|
||||
print_json_status('failed', 'Unknown action requested.');
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
38
html/ajax/actions/alert_assoc_edit.inc.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
// Currently edit allowed only for Admins
|
||||
if (!$limitwrite) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($alert_test = dbFetchRow("SELECT * FROM `alert_tests` WHERE `alert_test_id` = ?", [ $vars['alert_test_id'] ])) {
|
||||
|
||||
if ($alert_test['alert_assoc'] !== $vars['alert_assoc']) {
|
||||
|
||||
if (dbUpdate([ 'alert_assoc' => $vars['alert_assoc'] ], 'alert_tests', '`alert_test_id` = ?', [ $vars['alert_test_id'] ])) {
|
||||
update_alert_table($vars['alert_test_id']);
|
||||
print_json_status('ok', 'Associations updated.',
|
||||
[ 'id' => $vars['alert_test_id'],
|
||||
'redirect' => generate_url([ 'page' => 'alert_check', 'alert_test_id' => $vars['alert_test_id'] ]) ]);
|
||||
} else {
|
||||
print_json_status('failed', 'Database was not updated.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('warning', 'Associations not changed.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Alert Checker does not exist: [' . $vars['alert_test_id'] . ']');
|
||||
}
|
||||
|
||||
// EOF
|
@ -5,64 +5,72 @@
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
// Currently allowed only for Admins
|
||||
if (!$readwrite) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
return;
|
||||
// Currently allowed only for Admins and Limit Write
|
||||
if (!$limitwrite) {
|
||||
print_json_status('failed', 'Action not allowed.');
|
||||
return;
|
||||
}
|
||||
|
||||
$ok = TRUE;
|
||||
foreach (array('entity_type', 'alert_name', 'alert_severity', 'alert_conditions') as $var) {
|
||||
if (!isset($vars[$var]) || strlen($vars[$var]) == '0') {
|
||||
$ok = FALSE;
|
||||
$failed[] = $var;
|
||||
}
|
||||
foreach ([ 'entity_type', 'alert_name', 'alert_severity', 'alert_conditions' ] as $var) {
|
||||
if (safe_empty($vars[$var])) {
|
||||
$ok = FALSE;
|
||||
$failed[] = $var;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok) {
|
||||
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [ $vars['entity_type'], $vars['alert_name'] ])) {
|
||||
print_json_status('failed', "Alert Checker '{$vars['alert_name']}' already exist.");
|
||||
return;
|
||||
}
|
||||
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [ $vars['entity_type'], $vars['alert_name'] ])) {
|
||||
print_json_status('failed', "Alert Checker '{$vars['alert_name']}' already exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
$check_array = array();
|
||||
$check_array = [];
|
||||
|
||||
$conditions = array();
|
||||
foreach (explode("\n", trim($vars['alert_conditions'])) as $cond) {
|
||||
$condition = array();
|
||||
list($condition['metric'], $condition['condition'], $condition['value']) = explode(" ", trim($cond), 3);
|
||||
$conditions[] = $condition;
|
||||
}
|
||||
$check_array['conditions'] = safe_json_encode($conditions);
|
||||
$check_array['alert_assoc'] = $vars['alert_assoc'];
|
||||
$check_array['entity_type'] = $vars['entity_type'];
|
||||
$check_array['alert_name'] = $vars['alert_name'];
|
||||
$check_array['alert_message'] = $vars['alert_message'];
|
||||
$check_array['severity'] = $vars['alert_severity'];
|
||||
$check_array['suppress_recovery'] = get_var_true($vars['alert_send_recovery']) ? 0 : 1;
|
||||
$check_array['alerter'] = NULL;
|
||||
$check_array['and'] = $vars['alert_and'];
|
||||
$check_array['delay'] = $vars['alert_delay'];
|
||||
$check_array['enable'] = '1';
|
||||
$conditions = [];
|
||||
foreach (explode("\n", trim($vars['alert_conditions'])) as $cond) {
|
||||
if (preg_match(OBS_PATTERN_XSS, $cond)) {
|
||||
print_json_status('failed', "Prevent XSS payload.");
|
||||
return;
|
||||
}
|
||||
$condition = [];
|
||||
[ $condition['metric'], $condition['condition'], $condition['value'] ] = explode(" ", trim($cond), 3);
|
||||
if (!is_alpha($condition['metric'])) {
|
||||
print_json_status('failed', "Incorrect condition metric '" . escape_html($condition['metric']) . "'");
|
||||
return;
|
||||
}
|
||||
$conditions[] = $condition;
|
||||
}
|
||||
$check_array['conditions'] = safe_json_encode($conditions);
|
||||
$check_array['alert_assoc'] = $vars['alert_assoc'];
|
||||
$check_array['entity_type'] = $vars['entity_type'];
|
||||
$check_array['alert_name'] = $vars['alert_name'];
|
||||
$check_array['alert_message'] = $vars['alert_message'];
|
||||
$check_array['severity'] = $vars['alert_severity'];
|
||||
$check_array['suppress_recovery'] = get_var_true($vars['alert_send_recovery']) ? 0 : 1;
|
||||
$check_array['alerter'] = NULL;
|
||||
$check_array['and'] = $vars['alert_and'];
|
||||
$check_array['delay'] = $vars['alert_delay'];
|
||||
$check_array['enable'] = '1';
|
||||
|
||||
$check_id = dbInsert('alert_tests', $check_array);
|
||||
$check_id = dbInsert('alert_tests', $check_array);
|
||||
|
||||
if (is_numeric($check_id)) {
|
||||
update_alert_table($check_id);
|
||||
if (is_numeric($check_id)) {
|
||||
update_alert_table($check_id);
|
||||
|
||||
print_json_status('ok', '', [ 'id' => $check_id, 'redirect' => generate_url([ 'page' => 'alert_check', 'alert_test_id' => $check_id ]) ]);
|
||||
} else {
|
||||
print_json_status('ok', '', ['id' => $check_id, 'redirect' => generate_url(['page' => 'alert_check', 'alert_test_id' => $check_id])]);
|
||||
} else {
|
||||
|
||||
print_json_status('failed', 'Alert creation failed. Please note that the alert name <b>must</b> be unique.');
|
||||
}
|
||||
print_json_status('failed', 'Alert creation failed. Please note that the alert name <b>must</b> be unique.');
|
||||
}
|
||||
} else {
|
||||
|
||||
print_json_status('failed', 'Missing required data. (' . implode(", ", $failed) . ')');
|
||||
print_json_status('failed', 'Missing required data. (' . implode(", ", $failed) . ')');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
37
html/ajax/actions/alert_entry_ignore_until_ok.inc.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
if ($_SESSION['userlevel'] >= 8) {
|
||||
|
||||
if (is_intnum($vars['value'])) {
|
||||
|
||||
$alert_entry = get_alert_entry_by_id($vars['value']);
|
||||
|
||||
if(!count($alert_entry)) {
|
||||
print_json_status('failed', 'Alert entry not found. No update performed.');
|
||||
die;
|
||||
}
|
||||
|
||||
$update_array = [];
|
||||
if ($alert_entry['ignore_until_ok'] != 1) {
|
||||
$update_array['ignore_until_ok'] = '1';
|
||||
}
|
||||
if ($alert_entry['alert_status'] == 0) {
|
||||
$update_array['alert_status'] = '3';
|
||||
}
|
||||
|
||||
if (count($update_array)) {
|
||||
//r($alert_entry);
|
||||
dbUpdate($update_array, 'alert_table', 'alert_table_id = ?', [$alert_entry['alert_table_id']]);
|
||||
$alert_device = device_by_id_cache($alert_entry['device_id']);
|
||||
//print_message("Alert entry [{$vars['form_alert_table_id']}] for device '{$alert_device['hostname']}' suppressed.");
|
||||
print_json_status('ok', 'alert '.$vars['form_alert_table_id'].' ignored until ok. status updated.', ['update_array' => $update_array]);
|
||||
}
|
||||
|
||||
unset($update_array);
|
||||
|
||||
// FIXME - eventlog? audit log?
|
||||
}
|
||||
|
||||
} else {
|
||||
print_json_status('failed', 'Action not permitted. Not performed.');
|
||||
}
|
@ -6,21 +6,23 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
if ($readonly) { return; } // Currently edit allowed only for 7+
|
||||
if ($readonly) {
|
||||
return;
|
||||
} // Currently edit allowed only for 7+
|
||||
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [ $vars['widget_id'] ]);
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [$vars['widget_id']]);
|
||||
|
||||
$widget['widget_config'] = safe_json_decode($widget['widget_config']);
|
||||
|
||||
switch ($widget['widget_type']) {
|
||||
|
||||
case "graph":
|
||||
case "graph":
|
||||
|
||||
if (safe_count($widget['widget_config'])) {
|
||||
if (safe_count($widget['widget_config'])) {
|
||||
|
||||
// echo '
|
||||
// <form onsubmit="return false">
|
||||
@ -28,121 +30,120 @@ switch ($widget['widget_type']) {
|
||||
// </form>
|
||||
// ';
|
||||
|
||||
//r($widget['widget_config']);
|
||||
//r($widget['widget_config']);
|
||||
|
||||
//r(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no');
|
||||
//r(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no');
|
||||
|
||||
$modal_args = [
|
||||
'id' => 'modal-edit_widget_' . $widget['widget_id'],
|
||||
'title' => 'Configure Widget',
|
||||
//'hide' => TRUE,
|
||||
//'fade' => TRUE,
|
||||
//'role' => 'dialog',
|
||||
//'class' => 'modal-md',
|
||||
];
|
||||
$modal_args = [
|
||||
'id' => 'modal-edit_widget_' . $widget['widget_id'],
|
||||
'title' => 'Configure Widget',
|
||||
//'hide' => TRUE,
|
||||
//'fade' => TRUE,
|
||||
//'role' => 'dialog',
|
||||
//'class' => 'modal-md',
|
||||
];
|
||||
|
||||
$form = [
|
||||
'form_only' => TRUE, // Do not add modal open/close divs (it's generated outside)
|
||||
'type' => 'horizontal',
|
||||
'id' => 'edit_widget_' . $widget['widget_id'],
|
||||
'userlevel' => 7, // Minimum user level for display form
|
||||
'modal_args' => $modal_args, // !!! This generate modal specific form
|
||||
//'help' => 'This will completely delete the rule and all associations and history.',
|
||||
'class' => '', // Clean default box class!
|
||||
//'url' => generate_url([ 'page' => 'syslog_rules' ]),
|
||||
'onsubmit' => "return false",
|
||||
];
|
||||
$form['fieldset']['body'] = [ 'class' => 'modal-body' ]; // Required this class for modal body!
|
||||
$form['fieldset']['footer'] = [ 'class' => 'modal-footer' ]; // Required this class for modal footer!
|
||||
$form = [
|
||||
'form_only' => TRUE, // Do not add modal open/close divs (it's generated outside)
|
||||
'type' => 'horizontal',
|
||||
'id' => 'edit_widget_' . $widget['widget_id'],
|
||||
'userlevel' => 7, // Minimum user level for display form
|
||||
'modal_args' => $modal_args, // !!! This generate modal specific form
|
||||
//'help' => 'This will completely delete the rule and all associations and history.',
|
||||
'class' => '', // Clean default box class!
|
||||
//'url' => generate_url([ 'page' => 'syslog_rules' ]),
|
||||
'onsubmit' => "return false",
|
||||
];
|
||||
$form['fieldset']['body'] = ['class' => 'modal-body']; // Required this class for modal body!
|
||||
$form['fieldset']['footer'] = ['class' => 'modal-footer']; // Required this class for modal footer!
|
||||
|
||||
$form['row'][1]['widget-config-title'] = [
|
||||
'type' => 'text',
|
||||
'fieldset' => 'body',
|
||||
'name' => 'Title',
|
||||
'placeholder' => 'Graph Title',
|
||||
'class' => 'input-xlarge',
|
||||
'attribs' => [
|
||||
'data-id' => $widget['widget_id'],
|
||||
'data-field' => 'title',
|
||||
'data-type' => 'text'
|
||||
],
|
||||
'value' => $widget['widget_config']['title']
|
||||
];
|
||||
$form['row'][2]['widget-config-legend'] = [
|
||||
'type' => 'checkbox',
|
||||
'fieldset' => 'body',
|
||||
'name' => 'Show Legend',
|
||||
//'placeholder' => 'Yes, please delete this rule.',
|
||||
//'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');",
|
||||
'attribs' => [
|
||||
'data-id' => $widget['widget_id'],
|
||||
'data-field' => 'legend',
|
||||
'data-type' => 'checkbox'
|
||||
],
|
||||
'value' => safe_empty($widget['widget_config']['legend']) ? 'yes' : $widget['widget_config']['legend'] //'legend'
|
||||
];
|
||||
$form['row'][1]['widget-config-title'] = [
|
||||
'type' => 'text',
|
||||
'fieldset' => 'body',
|
||||
'name' => 'Title',
|
||||
'placeholder' => 'Graph Title',
|
||||
'class' => 'input-xlarge',
|
||||
'attribs' => [
|
||||
'data-id' => $widget['widget_id'],
|
||||
'data-field' => 'title',
|
||||
'data-type' => 'text'
|
||||
],
|
||||
'value' => $widget['widget_config']['title']
|
||||
];
|
||||
$form['row'][2]['widget-config-legend'] = [
|
||||
'type' => 'checkbox',
|
||||
'fieldset' => 'body',
|
||||
'name' => 'Show Legend',
|
||||
//'placeholder' => 'Yes, please delete this rule.',
|
||||
//'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');",
|
||||
'attribs' => [
|
||||
'data-id' => $widget['widget_id'],
|
||||
'data-field' => 'legend',
|
||||
'data-type' => 'checkbox'
|
||||
],
|
||||
'value' => safe_empty($widget['widget_config']['legend']) ? 'yes' : $widget['widget_config']['legend'] //'legend'
|
||||
];
|
||||
|
||||
|
||||
$form['row'][8]['close'] = [
|
||||
'type' => 'submit',
|
||||
'fieldset' => 'footer',
|
||||
'div_class' => '', // Clean default form-action class!
|
||||
'name' => 'Close',
|
||||
'icon' => '',
|
||||
'attribs' => [
|
||||
'data-dismiss' => 'modal',
|
||||
'aria-hidden' => 'true'
|
||||
]
|
||||
];
|
||||
$form['row'][8]['close'] = [
|
||||
'type' => 'submit',
|
||||
'fieldset' => 'footer',
|
||||
'div_class' => '', // Clean default form-action class!
|
||||
'name' => 'Close',
|
||||
'icon' => '',
|
||||
'attribs' => [
|
||||
'data-dismiss' => 'modal',
|
||||
'aria-hidden' => 'true'
|
||||
]
|
||||
];
|
||||
|
||||
echo generate_form_modal($form);
|
||||
unset($form);
|
||||
echo generate_form_modal($form);
|
||||
unset($form);
|
||||
|
||||
/*
|
||||
echo '
|
||||
<form onsubmit="return false" class="form form-horizontal" style="margin-bottom: 0px;">
|
||||
<fieldset>
|
||||
<div id="purpose_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-1 -->
|
||||
<label class="control-label" for="purpose">Title</label>
|
||||
<div id="purpose_div" class="controls">
|
||||
<input type="text" placeholder="Graph Title" name="widget-config-title" class="input" data-field="title" style="width: 100%;" value="'.$widget['widget_config']['title'].'" data-id="'.$widget['widget_id'].'">
|
||||
</div>
|
||||
</div>
|
||||
/*
|
||||
echo '
|
||||
<form onsubmit="return false" class="form form-horizontal" style="margin-bottom: 0px;">
|
||||
<fieldset>
|
||||
<div id="purpose_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-1 -->
|
||||
<label class="control-label" for="purpose">Title</label>
|
||||
<div id="purpose_div" class="controls">
|
||||
<input type="text" placeholder="Graph Title" name="widget-config-title" class="input" data-field="title" style="width: 100%;" value="'.$widget['widget_config']['title'].'" data-id="'.$widget['widget_id'].'">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ignore_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-6 -->
|
||||
<label class="control-label" for="ignore">Show Legend</label>
|
||||
<div id="ignore_div" class="controls">
|
||||
<input type="checkbox" name="widget-config-legend" data-field="legend" data-type="checkbox" value="legend" '.(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no' ? '' : 'checked').' data-id="'.$widget['widget_id'].'">
|
||||
</div>
|
||||
</div>
|
||||
</fieldset> <!-- END fieldset-body -->
|
||||
<div id="ignore_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-6 -->
|
||||
<label class="control-label" for="ignore">Show Legend</label>
|
||||
<div id="ignore_div" class="controls">
|
||||
<input type="checkbox" name="widget-config-legend" data-field="legend" data-type="checkbox" value="legend" '.(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no' ? '' : 'checked').' data-id="'.$widget['widget_id'].'">
|
||||
</div>
|
||||
</div>
|
||||
</fieldset> <!-- END fieldset-body -->
|
||||
|
||||
<div class="modal-footer">
|
||||
<fieldset>
|
||||
<button id="close" name="close" type="submit" class="btn btn-default text-nowrap" value="" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||
<!-- <button id="action" name="action" type="submit" class="btn btn-primary text-nowrap" value="add_contact"><i style="margin-right: 0px;" class="icon-ok icon-white"></i> Add Contact</button> -->
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<fieldset>
|
||||
<button id="close" name="close" type="submit" class="btn btn-default text-nowrap" value="" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||
<!-- <button id="action" name="action" type="submit" class="btn btn-primary text-nowrap" value="add_contact"><i style="margin-right: 0px;" class="icon-ok icon-white"></i> Add Contact</button> -->
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
</form>';
|
||||
*/
|
||||
</form>';
|
||||
*/
|
||||
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
print_message('To add a graph to this widget, navigate to the required graph and use the "Add To Dashboard" function on the graph page.');
|
||||
print_message('To add a graph to this widget, navigate to the required graph and use the "Add To Dashboard" function on the graph page.');
|
||||
|
||||
echo '<h3>Step 1. Locate Graph and click for Graph Browser.</h3>';
|
||||
echo '<img class="img img-thumbnail" src="images/doc/add_graph_1">';
|
||||
echo '<h3>Step 1. Locate Graph and click for Graph Browser.</h3>';
|
||||
echo '<img class="img img-thumbnail" src="images/doc/add_graph_1">';
|
||||
|
||||
echo '<h3>Step 2. Select Add to Dashboard in Graph Browser.</h3>';
|
||||
echo '<img class="img" src="images/doc/add_graph_2">';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
print_vars($widget);
|
||||
echo '<h3>Step 2. Select Add to Dashboard in Graph Browser.</h3>';
|
||||
echo '<img class="img" src="images/doc/add_graph_2">';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
r($widget['widget_config']);
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -15,15 +15,14 @@ $update_ports = [];
|
||||
//r($vars);
|
||||
//$ports_attribs = get_device_entities_attribs($device_id, 'port'); // Get all attribs
|
||||
|
||||
foreach($vars['port'] as $port_id => $port_data)
|
||||
{
|
||||
foreach ($vars['port'] as $port_id => $port_data) {
|
||||
|
||||
if (is_entity_write_permitted('port', $port_id)) {
|
||||
$port = get_port_by_id_cache($port_id);
|
||||
$port = get_port_by_id_cache($port_id);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
|
||||
$updated = FALSE;
|
||||
$update_array = array();
|
||||
$updated = FALSE;
|
||||
$update_array = [];
|
||||
|
||||
$port_attribs = get_entity_attribs('port', $port['port_id']);
|
||||
|
||||
@ -32,7 +31,7 @@ foreach($vars['port'] as $port_id => $port_data)
|
||||
}
|
||||
|
||||
// Check ignored and disabled port
|
||||
foreach (array('ignore', 'disabled') as $param) {
|
||||
foreach (['ignore', 'disabled'] as $param) {
|
||||
$old_param = $port[$param] ? 1 : 0;
|
||||
$new_param = (isset($port_data[$param]) && $port_data[$param]) ? 1 : 0;
|
||||
if ($old_param != $new_param) {
|
||||
@ -41,7 +40,7 @@ foreach($vars['port'] as $port_id => $port_data)
|
||||
}
|
||||
|
||||
if (count($update_array)) {
|
||||
dbUpdate($update_array, 'ports', '`port_id` = ?', array($port_id));
|
||||
dbUpdate($update_array, 'ports', '`port_id` = ?', [$port_id]);
|
||||
$updated = TRUE;
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ foreach($vars['port'] as $port_id => $port_data)
|
||||
$old_ifSpeed_bool = isset($port['ifSpeed_custom']);
|
||||
$new_ifSpeed_bool = isset($port_data['ifSpeed_custom_bool']) && $port_data['ifSpeed_custom_bool'];
|
||||
if ($new_ifSpeed_bool) {
|
||||
$port_data['ifSpeed_custom'] = (int) unit_string_to_numeric($port_data['ifSpeed_custom'], 1000);
|
||||
$port_data['ifSpeed_custom'] = (int)unit_string_to_numeric($port_data['ifSpeed_custom'], 1000);
|
||||
if ($port_data['ifSpeed_custom'] <= 0) {
|
||||
// Wrong ifSpeed, skip
|
||||
//print_warning("Passed incorrect value for port speed: ".unit_string_to_numeric($port_data['ifSpeed_custom'], 1000));
|
||||
@ -65,7 +64,7 @@ foreach($vars['port'] as $port_id => $port_data)
|
||||
//r($vars['ifSpeed_custom_' . $port_id]); r($port['ifSpeed_custom']);
|
||||
set_entity_attrib('port', $port_id, 'ifSpeed_custom', $port_data['ifSpeed_custom'], $device['device_id']);
|
||||
$update_array['ifSpeed_custom'] = $port_data['ifSpeed_custom'];
|
||||
$updated = TRUE;
|
||||
$updated = TRUE;
|
||||
}
|
||||
} elseif ($old_ifSpeed_bool !== $new_ifSpeed_bool) {
|
||||
// Added or removed
|
||||
@ -88,9 +87,9 @@ foreach($vars['port'] as $port_id => $port_data)
|
||||
}
|
||||
// Query updated sensors array
|
||||
if ($rows_updated) {
|
||||
print_json_status('ok', $rows_updated.' port(s) updated.', [ 'update_array' => $update_ports ]);
|
||||
print_json_status('ok', $rows_updated . ' port(s) updated.', ['update_array' => $update_ports]);
|
||||
} else {
|
||||
print_json_status('failed', 'No update performed.');
|
||||
print_json_status('failed', 'No update performed.');
|
||||
}
|
||||
|
||||
unset($ports_attribs);
|
||||
|
35
html/ajax/actions/role_del.inc.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
// Currently, allowed only for Admins
|
||||
if (!$readwrite) {
|
||||
print_json_status('failed', 'Insufficient permissions to delete role.');
|
||||
return;
|
||||
}
|
||||
|
||||
$role_id = (int)$vars['role_id'];
|
||||
if ($role_id > 0) {
|
||||
$rows_deleted = dbDelete('roles', '`role_id` = ?', [$role_id]);
|
||||
//$rows_deleted = 0;
|
||||
if ($rows_deleted > 0) {
|
||||
dbDelete('roles_entity_permissions', '`role_id` = ?', [$role_id]);
|
||||
dbDelete('roles_permissions', '`role_id` = ?', [$role_id]);
|
||||
dbDelete('roles_users', '`role_id` = ?', [$role_id]);
|
||||
print_json_status('ok', 'Role deleted successfully.', ['reload' => TRUE]);
|
||||
} else {
|
||||
print_json_status('failed', 'Failed to delete role.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid role ID.');
|
||||
}
|
||||
|
||||
// EOF
|
@ -4,96 +4,96 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$rows_updated = 0;
|
||||
$rows_updated = 0;
|
||||
$update_entities = [];
|
||||
//r($vars);
|
||||
|
||||
foreach ($vars['sensors'] as $sensor_id => $sensor_update) {
|
||||
|
||||
$update_array = [];
|
||||
if (is_entity_write_permitted('sensor', $sensor_id)) {
|
||||
$update_array = [];
|
||||
if (is_entity_write_permitted('sensor', $sensor_id)) {
|
||||
|
||||
$sensor = get_sensor_by_id($sensor_id);
|
||||
$sensor = get_sensor_by_id($sensor_id);
|
||||
|
||||
$device_id = $sensor['device_id'];
|
||||
$device_id = $sensor['device_id'];
|
||||
|
||||
if (!$sensor['sensor_state']) {
|
||||
// Normal sensors
|
||||
$fields_switch = [ 'sensor_ignore', 'sensor_custom_limit' ];
|
||||
$fields_limit = [ 'sensor_limit', 'sensor_limit_warn', 'sensor_limit_low_warn', 'sensor_limit_low' ];
|
||||
if (!$sensor['sensor_state']) {
|
||||
// Normal sensors
|
||||
$fields_switch = ['sensor_ignore', 'sensor_custom_limit'];
|
||||
$fields_limit = ['sensor_limit', 'sensor_limit_warn', 'sensor_limit_low_warn', 'sensor_limit_low'];
|
||||
|
||||
} else {
|
||||
// State sensors not allow edit limits
|
||||
$fields_switch = array('sensor_ignore');
|
||||
$fields_limit = array();
|
||||
}
|
||||
|
||||
// Switch selectors
|
||||
foreach ($fields_switch as $field) {
|
||||
$sensor_update[$field] = get_var_true($sensor_update[$field]) ? '1' : '0';
|
||||
if ($sensor_update[$field] != $sensor[$field]) {
|
||||
$update_array[$field] = $sensor_update[$field];
|
||||
}
|
||||
}
|
||||
|
||||
// Limits
|
||||
if ($sensor_update['sensor_reset_limit']) {
|
||||
// Reset limits
|
||||
if ($sensor['sensor_custom_limit']) {
|
||||
$update_array['sensor_custom_limit'] = '0';
|
||||
}
|
||||
$update_array['sensor_limit_low'] = [ 'NULL' ];
|
||||
$update_array['sensor_limit_low_warn'] = [ 'NULL' ];
|
||||
$update_array['sensor_limit_warn'] = [ 'NULL' ];
|
||||
$update_array['sensor_limit'] = [ 'NULL' ];
|
||||
} elseif ($sensor_update['sensor_custom_limit']) {
|
||||
foreach ($fields_limit as $field) {
|
||||
$sensor_update[$field] = !is_numeric($sensor_update[$field]) ? [ 'NULL' ] : (float)$sensor_update[$field];
|
||||
$sensor[$field] = !is_numeric($sensor[$field]) ? [ 'NULL' ] : (float)$sensor[$field];
|
||||
if ($sensor_update[$field] !== $sensor[$field]) {
|
||||
$update_array[$field] = $sensor_update[$field];
|
||||
} else {
|
||||
// State sensors not allow edit limits
|
||||
$fields_switch = ['sensor_ignore'];
|
||||
$fields_limit = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($update_array)) {
|
||||
dbUpdate($update_array, 'sensors', '`sensor_id` = ?', array($sensor['sensor_id']));
|
||||
$msg = 'Sensor updated (custom): ' . $sensor['sensor_class'] . ' ' . $sensor['sensor_type'] . ' ' . $sensor['sensor_id'] . ' ' . escape_html($sensor['sensor_descr']) . ' ';
|
||||
if ($update_array['sensor_limit_low']) {
|
||||
$msg .= '[L: ' . $update_array['sensor_limit_low'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit_low_warn']) {
|
||||
$msg .= '[Lw: ' . $update_array['sensor_limit_low_warn'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit_warn']) {
|
||||
$msg .= '[Hw: ' . $update_array['sensor_limit_warn'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit']) {
|
||||
$msg .= '[H: ' . $update_array['sensor_limit'] . ']';
|
||||
}
|
||||
log_event($msg, $device_id, 'sensor', $sensor['sensor_id']);
|
||||
$rows_updated++;
|
||||
// Switch selectors
|
||||
foreach ($fields_switch as $field) {
|
||||
$sensor_update[$field] = get_var_true($sensor_update[$field]) ? '1' : '0';
|
||||
if ($sensor_update[$field] != $sensor[$field]) {
|
||||
$update_array[$field] = $sensor_update[$field];
|
||||
}
|
||||
}
|
||||
|
||||
$update_entities[$sensor_id] = $update_array;
|
||||
}
|
||||
// Limits
|
||||
if ($sensor_update['sensor_reset_limit']) {
|
||||
// Reset limits
|
||||
if ($sensor['sensor_custom_limit']) {
|
||||
$update_array['sensor_custom_limit'] = '0';
|
||||
}
|
||||
$update_array['sensor_limit_low'] = ['NULL'];
|
||||
$update_array['sensor_limit_low_warn'] = ['NULL'];
|
||||
$update_array['sensor_limit_warn'] = ['NULL'];
|
||||
$update_array['sensor_limit'] = ['NULL'];
|
||||
} elseif ($sensor_update['sensor_custom_limit']) {
|
||||
foreach ($fields_limit as $field) {
|
||||
$sensor_update[$field] = !is_numeric($sensor_update[$field]) ? ['NULL'] : (float)$sensor_update[$field];
|
||||
$sensor[$field] = !is_numeric($sensor[$field]) ? ['NULL'] : (float)$sensor[$field];
|
||||
if ($sensor_update[$field] !== $sensor[$field]) {
|
||||
$update_array[$field] = $sensor_update[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($update_array);
|
||||
if (count($update_array)) {
|
||||
dbUpdate($update_array, 'sensors', '`sensor_id` = ?', [$sensor['sensor_id']]);
|
||||
$msg = 'Sensor updated (custom): ' . $sensor['sensor_class'] . ' ' . $sensor['sensor_type'] . ' ' . $sensor['sensor_id'] . ' ' . escape_html($sensor['sensor_descr']) . ' ';
|
||||
if ($update_array['sensor_limit_low']) {
|
||||
$msg .= '[L: ' . $update_array['sensor_limit_low'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit_low_warn']) {
|
||||
$msg .= '[Lw: ' . $update_array['sensor_limit_low_warn'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit_warn']) {
|
||||
$msg .= '[Hw: ' . $update_array['sensor_limit_warn'] . ']';
|
||||
}
|
||||
if ($update_array['sensor_limit']) {
|
||||
$msg .= '[H: ' . $update_array['sensor_limit'] . ']';
|
||||
}
|
||||
log_event($msg, $device_id, 'sensor', $sensor['sensor_id']);
|
||||
$rows_updated++;
|
||||
|
||||
} // End write permission check
|
||||
$update_entities[$sensor_id] = $update_array;
|
||||
}
|
||||
|
||||
unset($update_array);
|
||||
|
||||
} // End write permission check
|
||||
|
||||
} // end sensors loop
|
||||
|
||||
// Query updated sensors array
|
||||
if ($rows_updated) {
|
||||
print_json_status('ok', $rows_updated.' sensor(s) updated.', [ 'update_array' => $update_entities ]);
|
||||
print_json_status('ok', $rows_updated . ' sensor(s) updated.', ['update_array' => $update_entities]);
|
||||
} else {
|
||||
print_json_status('failed', 'No update performed.');
|
||||
print_json_status('failed', 'No update performed.');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -4,9 +4,9 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -14,46 +14,46 @@
|
||||
|
||||
// Allowed only for authenticated
|
||||
if (!$_SESSION['authenticated'] || $_SESSION['user_id'] != $vars['user_id']) {
|
||||
print_json_status('failed', "Unauthenticated");
|
||||
//print_json_status('failed', var_export($vars, TRUE));
|
||||
return;
|
||||
print_json_status('failed', "Unauthenticated");
|
||||
//print_json_status('failed', var_export($vars, TRUE));
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
foreach (process_sql_vars($vars) as $param => $entry) {
|
||||
// This sets:
|
||||
// $deletes = array();
|
||||
// $sets = array();
|
||||
// $errors = array();
|
||||
// $set_attribs = array(); // set obs_attribs
|
||||
$$param = $entry;
|
||||
// This sets:
|
||||
// $deletes = array();
|
||||
// $sets = array();
|
||||
// $errors = array();
|
||||
// $set_attribs = array(); // set obs_attribs
|
||||
$$param = $entry;
|
||||
}
|
||||
|
||||
$updates = 0;
|
||||
|
||||
// Set fields that were submitted with custom value
|
||||
if (safe_count($sets)) {
|
||||
$query = 'SELECT * FROM `users_prefs` WHERE `user_id` = ?' . generate_query_values_and(array_keys($sets), 'pref');
|
||||
// Fetch current rows in config file so we know which one to UPDATE and which one to INSERT
|
||||
$in_db = [];
|
||||
foreach (dbFetchRows($query, [ $user_id ]) as $row) {
|
||||
$in_db[$row['pref']] = $row['value'];
|
||||
}
|
||||
|
||||
foreach ($sets as $key => $value) {
|
||||
$serialize = serialize($value);
|
||||
if (!isset($in_db[$key]) || $serialize !== $in_db[$key]) {
|
||||
set_user_pref($user_id, $key, $serialize);
|
||||
$updates++;
|
||||
$query = 'SELECT * FROM `users_prefs` WHERE `user_id` = ?' . generate_query_values_and(array_keys($sets), 'pref');
|
||||
// Fetch current rows in config file so we know which one to UPDATE and which one to INSERT
|
||||
$in_db = [];
|
||||
foreach (dbFetchRows($query, [$user_id]) as $row) {
|
||||
$in_db[$row['pref']] = $row['value'];
|
||||
}
|
||||
|
||||
foreach ($sets as $key => $value) {
|
||||
$serialize = serialize($value);
|
||||
if (!isset($in_db[$key]) || $serialize !== $in_db[$key]) {
|
||||
set_user_pref($user_id, $key, $serialize);
|
||||
$updates++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete fields that were reset to default
|
||||
if (safe_count($deletes)) {
|
||||
dbDelete('users_prefs', '`user_id` = ? ' . generate_query_values_and($deletes, 'pref'), [ $user_id ]);
|
||||
$updates++;
|
||||
dbDelete('users_prefs', '`user_id` = ? ' . generate_query_values_and($deletes, 'pref'), [$user_id]);
|
||||
$updates++;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -64,19 +64,19 @@ foreach ($set_attribs as $attrib => $value) {
|
||||
}
|
||||
*/
|
||||
if ($updates) {
|
||||
$status = 'ok';
|
||||
$message = "Settings updated. Please note Web UI setting takes effect only after reload the page.";
|
||||
$status = 'ok';
|
||||
$message = "Settings updated. Please note Web UI setting takes effect only after reload the page.";
|
||||
|
||||
if (safe_count($errors)) {
|
||||
$status = 'warning';
|
||||
$message .= ' Errors: ' . implode('; ', $errors) . '.';
|
||||
}
|
||||
print_json_status($status, $message, [ 'reload' => TRUE ]);
|
||||
if (safe_count($errors)) {
|
||||
$status = 'warning';
|
||||
$message .= ' Errors: ' . implode('; ', $errors) . '.';
|
||||
}
|
||||
print_json_status($status, $message, ['reload' => TRUE]);
|
||||
|
||||
} elseif (safe_count($errors)) {
|
||||
$status = 'failed';
|
||||
$message = 'Errors: ' . implode('; ', $errors) . '.';
|
||||
print_json_status($status, $message);
|
||||
$status = 'failed';
|
||||
$message = 'Errors: ' . implode('; ', $errors) . '.';
|
||||
print_json_status($status, $message);
|
||||
}
|
||||
|
||||
//process_sql_vars($vars);
|
||||
|
@ -4,63 +4,63 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
switch (str_replace('->', '|', $vars['setting'])) {
|
||||
case "theme":
|
||||
case "web_theme_default":
|
||||
$pref = 'web_theme_default';
|
||||
if ($vars['value'] === 'reset') {
|
||||
session_unset_var("theme");
|
||||
if ($config['web_theme_default'] === 'system') {
|
||||
// Override default
|
||||
session_unset_var("theme_default");
|
||||
}
|
||||
case "theme":
|
||||
case "web_theme_default":
|
||||
$pref = 'web_theme_default';
|
||||
if ($vars['value'] === 'reset') {
|
||||
session_unset_var("theme");
|
||||
if ($config['web_theme_default'] === 'system') {
|
||||
// Override default
|
||||
session_unset_var("theme_default");
|
||||
}
|
||||
|
||||
if (del_user_pref($_SESSION['user_id'], $pref)) {
|
||||
print_json_status('ok', 'Theme reset.');
|
||||
}
|
||||
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
|
||||
print_json_status('ok', 'Theme set.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid theme.');
|
||||
}
|
||||
break;
|
||||
if (del_user_pref($_SESSION['user_id'], $pref)) {
|
||||
print_json_status('ok', 'Theme reset.');
|
||||
}
|
||||
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
|
||||
print_json_status('ok', 'Theme set.');
|
||||
}
|
||||
} else {
|
||||
print_json_status('failed', 'Invalid theme.');
|
||||
}
|
||||
break;
|
||||
|
||||
case "big_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
|
||||
print_json_status('ok', 'Big graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_set_var("big_graphs", TRUE);
|
||||
//print_json_status('ok', 'Big graphs set.');
|
||||
break;
|
||||
case "big_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
|
||||
print_json_status('ok', 'Big graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_set_var("big_graphs", TRUE);
|
||||
//print_json_status('ok', 'Big graphs set.');
|
||||
break;
|
||||
|
||||
case "normal_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
|
||||
print_json_status('ok', 'Normal graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_unset_var("big_graphs");
|
||||
//print_json_status('ok', 'Small graphs set.');
|
||||
break;
|
||||
case "normal_graphs":
|
||||
$pref = 'graphs|size';
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
|
||||
print_json_status('ok', 'Normal graphs set.');
|
||||
session_unset_var("big_graphs"); // clear old
|
||||
}
|
||||
//session_unset_var("big_graphs");
|
||||
//print_json_status('ok', 'Small graphs set.');
|
||||
break;
|
||||
|
||||
case "sensors|web_measured_compact":
|
||||
// BOOL values
|
||||
$pref = $vars['setting'];
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize(get_var_true($vars['value'])))) {
|
||||
print_json_status('ok', 'Setting was set.', [ 'reload' => TRUE ]);
|
||||
}
|
||||
break;
|
||||
case "sensors|web_measured_compact":
|
||||
// BOOL values
|
||||
$pref = $vars['setting'];
|
||||
if (set_user_pref($_SESSION['user_id'], $pref, serialize(get_var_true($vars['value'])))) {
|
||||
print_json_status('ok', 'Setting was set.', ['reload' => TRUE]);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
// EOF
|
||||
|
@ -4,55 +4,55 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$rows_updated = 0;
|
||||
$rows_updated = 0;
|
||||
$update_entities = [];
|
||||
//r($vars);
|
||||
|
||||
foreach ($vars['status'] as $status_id => $status_update) {
|
||||
|
||||
$update_array = [];
|
||||
if(is_entity_write_permitted('status', $status_id)) {
|
||||
$status = get_status_by_id($status_id);
|
||||
$update_array = [];
|
||||
if (is_entity_write_permitted('status', $status_id)) {
|
||||
$status = get_status_by_id($status_id);
|
||||
|
||||
$device_id = $status['device_id'];
|
||||
$device_id = $status['device_id'];
|
||||
|
||||
$fields_switch = array('status_ignore');
|
||||
$fields_limit = array();
|
||||
$fields_switch = ['status_ignore'];
|
||||
$fields_limit = [];
|
||||
|
||||
// Switch selectors
|
||||
foreach ($fields_switch as $field) {
|
||||
$status_update[$field] = get_var_true($status_update[$field]) ? '1' : '0';
|
||||
if ($status_update[$field] != $status[$field]) {
|
||||
$update_array[$field] = $status_update[$field];
|
||||
}
|
||||
}
|
||||
// Switch selectors
|
||||
foreach ($fields_switch as $field) {
|
||||
$status_update[$field] = get_var_true($status_update[$field]) ? '1' : '0';
|
||||
if ($status_update[$field] != $status[$field]) {
|
||||
$update_array[$field] = $status_update[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($update_array)) {
|
||||
dbUpdate($update_array, 'status', '`status_id` = ?', array($status['status_id']));
|
||||
$msg = 'Status updated (custom): ' . $status['status_type'] . ' ' . $status['status_id'] . ' ' . escape_html($status['status_descr']) . ' ';
|
||||
log_event($msg, $device_id, 'status', $status['status_id']);
|
||||
$rows_updated++;
|
||||
if (count($update_array)) {
|
||||
dbUpdate($update_array, 'status', '`status_id` = ?', [$status['status_id']]);
|
||||
$msg = 'Status updated (custom): ' . $status['status_type'] . ' ' . $status['status_id'] . ' ' . escape_html($status['status_descr']) . ' ';
|
||||
log_event($msg, $device_id, 'status', $status['status_id']);
|
||||
$rows_updated++;
|
||||
|
||||
$update_entities[$status_id] = $update_array;
|
||||
}
|
||||
$update_entities[$status_id] = $update_array;
|
||||
}
|
||||
|
||||
unset($update_array);
|
||||
unset($update_array);
|
||||
|
||||
} // End write permission check
|
||||
} // End write permission check
|
||||
|
||||
} // end entity loop
|
||||
|
||||
// Query updated array
|
||||
if ($rows_updated) {
|
||||
print_json_status('ok', $rows_updated.' status(es) updated.', [ 'update_array' => $update_entities ]);
|
||||
print_json_status('ok', $rows_updated . ' status(es) updated.', ['update_array' => $update_entities]);
|
||||
} else {
|
||||
print_json_status('failed', 'No update performed.');
|
||||
print_json_status('failed', 'No update performed.');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
@ -7,55 +6,48 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
|
||||
switch ($_GET['entity_type'])
|
||||
{
|
||||
switch ($_GET['entity_type']) {
|
||||
|
||||
case "sensor":
|
||||
foreach (dbFetch("SELECT * FROM `sensors` WHERE device_id = ?", array($_GET['device_id'])) as $sensor)
|
||||
{
|
||||
if(is_entity_permitted($sensor, 'sensor'))
|
||||
{
|
||||
$string = addslashes($sensor['sensor_descr']);
|
||||
echo("obj.options[obj.options.length] = new Option('".$string."','".$sensor['sensor_id']."');\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "sensor":
|
||||
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE device_id = ?", [$_GET['device_id']]) as $sensor) {
|
||||
if (is_entity_permitted($sensor, 'sensor')) {
|
||||
$string = addslashes($sensor['sensor_descr']);
|
||||
echo("obj.options[obj.options.length] = new Option('" . $string . "','" . $sensor['sensor_id'] . "');\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "netscalervsvr":
|
||||
foreach (dbFetch("SELECT * FROM `netscaler_vservers` WHERE `device_id` = ?", array($_GET['device_id'])) as $entity)
|
||||
{
|
||||
$string = addslashes($entity['vsvr_label']);
|
||||
echo("obj.options[obj.options.length] = new Option('".$string."','".$entity['vsvr_id']."');\n");
|
||||
}
|
||||
break;
|
||||
case "netscalervsvr":
|
||||
foreach (dbFetchRows("SELECT * FROM `netscaler_vservers` WHERE `device_id` = ?", [$_GET['device_id']]) as $entity) {
|
||||
$string = addslashes($entity['vsvr_label']);
|
||||
echo("obj.options[obj.options.length] = new Option('" . $string . "','" . $entity['vsvr_id'] . "');\n");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "port":
|
||||
foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0'", array($_GET['device_id'])) as $port)
|
||||
{
|
||||
$string = addslashes($port['port_label_short']." - ".$port['ifAlias']);
|
||||
echo("obj.options[obj.options.length] = new Option('".$string."','".$port['port_id']."');\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "port":
|
||||
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0'", [$_GET['device_id']]) as $port) {
|
||||
$string = addslashes($port['port_label_short'] . " - " . $port['ifAlias']);
|
||||
echo("obj.options[obj.options.length] = new Option('" . $string . "','" . $port['port_id'] . "');\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
// EOF
|
||||
|
@ -5,42 +5,38 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (is_numeric($_GET['device_id']) && device_permitted($_GET['device_id']))
|
||||
{
|
||||
foreach (dbFetchRows("SELECT `port_id`,`port_label_short`,`ifAlias`,`ifDescr`,`ifName` FROM `ports` WHERE `device_id` = ? AND deleted = 0 ORDER BY ifIndex", array($_GET['device_id'])) as $interface)
|
||||
{
|
||||
$descr = array();
|
||||
if (empty($interface['port_label_short']))
|
||||
{
|
||||
$device = device_by_id_cache($interface['port_id']);
|
||||
process_port_label($interface, $device);
|
||||
}
|
||||
$descr[] = $interface['port_label_short'];
|
||||
if (is_numeric($_GET['device_id']) && device_permitted($_GET['device_id'])) {
|
||||
foreach (dbFetchRows("SELECT `port_id`,`port_label_short`,`ifAlias`,`ifDescr`,`ifName` FROM `ports` WHERE `device_id` = ? AND deleted = 0 ORDER BY ifIndex", [$_GET['device_id']]) as $interface) {
|
||||
$descr = [];
|
||||
if (empty($interface['port_label_short'])) {
|
||||
$device = device_by_id_cache($interface['port_id']);
|
||||
process_port_label($interface, $device);
|
||||
}
|
||||
$descr[] = $interface['port_label_short'];
|
||||
|
||||
if ($interface['ifAlias'])
|
||||
{
|
||||
// second part
|
||||
$descr[] = $interface['ifAlias'];
|
||||
if ($interface['ifAlias']) {
|
||||
// second part
|
||||
$descr[] = $interface['ifAlias'];
|
||||
}
|
||||
$string = addslashes(implode(" - ", $descr));
|
||||
echo("obj.options[obj.options.length] = new Option('" . $string . "','" . $interface['port_id'] . "');\n");
|
||||
}
|
||||
$string = addslashes(implode(" - ", $descr));
|
||||
echo("obj.options[obj.options.length] = new Option('".$string."','".$interface['port_id']."');\n");
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -5,55 +5,53 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result = [];
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
|
||||
switch ($_GET['entity_type'])
|
||||
{
|
||||
switch ($_GET['entity_type']) {
|
||||
|
||||
case "port":
|
||||
case "port":
|
||||
|
||||
$where_array = build_ports_where_array($GLOBALS['vars']);
|
||||
$where_array = build_ports_where_array($GLOBALS['vars']);
|
||||
|
||||
$where = ' WHERE 1 ';
|
||||
$where .= implode('', $where_array);
|
||||
$where = ' WHERE 1 ';
|
||||
$where .= implode('', $where_array);
|
||||
|
||||
$query = 'SELECT *, `ports`.`port_id` AS `port_id` FROM `ports`';
|
||||
//$query .= ' LEFT JOIN `ports-state` AS S ON `ports`.`port_id` = S.`port_id`';
|
||||
$query .= $where;
|
||||
$query = 'SELECT *, `ports`.`port_id` AS `port_id` FROM `ports`';
|
||||
//$query .= ' LEFT JOIN `ports-state` AS S ON `ports`.`port_id` = S.`port_id`';
|
||||
$query .= $where;
|
||||
|
||||
$ports_db = dbFetchRows($query, $param);
|
||||
port_permitted_array($ports_db);
|
||||
$ports_db = dbFetchRows($query, $param);
|
||||
port_permitted_array($ports_db);
|
||||
|
||||
foreach ($ports_db as $port) {
|
||||
humanize_port($port);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
array_push($result, [ intval($port['port_id']), $device['hostname'], $port['port_label'], $port['ifAlias'], $port['ifOperStatus'] == 'up' ? 'up' : 'down' ]);
|
||||
}
|
||||
break;
|
||||
foreach ($ports_db as $port) {
|
||||
humanize_port($port);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
array_push($result, [intval($port['port_id']), $device['hostname'], $port['port_label'], $port['ifAlias'], $port['ifOperStatus'] == 'up' ? 'up' : 'down']);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
print json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
|
||||
header('Content-Type: application/json');
|
||||
print json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,18 +6,18 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
require_once("../../includes/observium.inc.php");
|
||||
|
||||
require_once($config['install_dir']."/includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { print_error('Session expired, please log in again!'); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
print_error('Session expired, please log in again!');
|
||||
exit;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
@ -25,288 +25,268 @@ $vars = get_vars([ 'JSON', 'POST', 'GET' ]);
|
||||
|
||||
$vars['page'] = "popup";
|
||||
|
||||
if(isset($vars['debug'])) { r($vars); }
|
||||
if (isset($vars['debug'])) {
|
||||
r($vars);
|
||||
}
|
||||
|
||||
switch ($vars['entity_type']) {
|
||||
case "port":
|
||||
if (is_numeric($vars['entity_id']) && (port_permitted($vars['entity_id']))) {
|
||||
$port = get_port_by_id($vars['entity_id']);
|
||||
echo generate_port_popup($port);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
break;
|
||||
case "port":
|
||||
if (is_numeric($vars['entity_id']) && (port_permitted($vars['entity_id']))) {
|
||||
$port = get_port_by_id($vars['entity_id']);
|
||||
echo generate_port_popup($port);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "link":
|
||||
if (is_numeric($vars['entity_id_a']) && (port_permitted($vars['entity_id_a']))) {
|
||||
$port = get_port_by_id($vars['entity_id_a']);
|
||||
echo generate_port_popup($port);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
|
||||
if (is_numeric($vars['entity_id_b']) && (port_permitted($vars['entity_id_b']))) {
|
||||
$port = get_port_by_id($vars['entity_id_b']);
|
||||
echo generate_port_popup($port, '','none'); // suppress graph for b side of link
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "device":
|
||||
if (is_numeric($vars['entity_id']) && device_permitted($vars['entity_id'])) {
|
||||
$device = device_by_id_cache($vars['entity_id']);
|
||||
echo generate_device_popup($device, $vars);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this device.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "group":
|
||||
if (is_numeric($vars['entity_id']) && $_SESSION['userlevel'] >= 5) {
|
||||
$group = get_group_by_id($vars['entity_id']);
|
||||
echo generate_group_popup_header($group, array());
|
||||
} else {
|
||||
print_warning("You are not permitted to view this group.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "mac":
|
||||
if (preg_match('/^' . OBS_PATTERN_MAC . '$/i', $vars['entity_id'])) {
|
||||
$mac = format_mac($vars['entity_id']);
|
||||
// Other way by using Pear::Net_MAC, see here: http://pear.php.net/manual/en/package.networking.net-mac.importvendors.php
|
||||
$url = 'https://api.macvendors.com/' . urlencode($mac);
|
||||
$response = get_http_request($url);
|
||||
if ($response) {
|
||||
echo 'MAC vendor: ' . $response;
|
||||
} else {
|
||||
echo 'Not Found';
|
||||
}
|
||||
} else {
|
||||
echo 'Not correct MAC address';
|
||||
}
|
||||
break;
|
||||
|
||||
case "ip":
|
||||
list($ip) = explode('/', $vars['entity_id']);
|
||||
|
||||
if ($ip_version = get_ip_version($ip)) {
|
||||
$cache_key = 'response_' . $vars['entity_type'] . '_' . $ip;
|
||||
$cache_entry = get_cache_session($cache_key);
|
||||
//r($cache_entry);
|
||||
if (ishit_cache_session()) {
|
||||
//echo '<h2>CACHED!</h2>';
|
||||
echo $cache_entry;
|
||||
exit;
|
||||
}
|
||||
|
||||
$response = '';
|
||||
$reverse_dns = gethostbyaddr6($ip);
|
||||
if ($reverse_dns) {
|
||||
$response .= '<h4>' . $reverse_dns . '</h4><hr />' . PHP_EOL;
|
||||
}
|
||||
|
||||
// WHOIS
|
||||
if (!isset($config['http_proxy']) && is_executable($config['whois'])) {
|
||||
// Use direct whois cmd query (preferred)
|
||||
// NOTE, for now not tested and not supported for KRNIC, ie: 202.30.50.0, 2001:02B8:00A2::
|
||||
$cmd = $config['whois'] . ' ' . $ip;
|
||||
$whois = external_exec($cmd);
|
||||
|
||||
$multi_whois = explode('# start', $whois); // Some time whois return multiple (ie: whois 8.8.8.8), than use last
|
||||
if (safe_count($multi_whois) > 1) {
|
||||
$whois = array_pop($multi_whois);
|
||||
case "link":
|
||||
if (is_numeric($vars['entity_id_a']) && (port_permitted($vars['entity_id_a']))) {
|
||||
$port = get_port_by_id($vars['entity_id_a']);
|
||||
echo generate_port_popup($port);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
|
||||
$org = 0;
|
||||
foreach (explode("\n", $whois) as $line) {
|
||||
if (preg_match('/^(\w[\w\s\-\/]+):.*$/', $line, $matches)) {
|
||||
if (in_array($matches[1], [ 'Ref', 'source', 'nic-hdl-br' ])) {
|
||||
if ($org === 1) {
|
||||
$response .= PHP_EOL;
|
||||
$org++;
|
||||
if (is_numeric($vars['entity_id_b']) && (port_permitted($vars['entity_id_b']))) {
|
||||
$port = get_port_by_id($vars['entity_id_b']);
|
||||
echo generate_port_popup($port, '', 'none'); // suppress graph for b side of link
|
||||
} else {
|
||||
print_warning("You are not permitted to view this port.");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "device":
|
||||
if (is_numeric($vars['entity_id']) && device_permitted($vars['entity_id'])) {
|
||||
$device = device_by_id_cache($vars['entity_id']);
|
||||
echo generate_device_popup($device, $vars);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this device.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "group":
|
||||
if (is_numeric($vars['entity_id']) && $_SESSION['userlevel'] >= 5) {
|
||||
$group = get_group_by_id($vars['entity_id']);
|
||||
echo generate_group_popup_header($group);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this group.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "mac":
|
||||
if (preg_match('/^' . OBS_PATTERN_MAC . '$/i', $vars['entity_id'])) {
|
||||
// Other way by using Pear::Net_MAC, see here: http://pear.php.net/manual/en/package.networking.net-mac.importvendors.php
|
||||
if ($response = get_http_def('macvendors_mac', [ 'mac' => format_mac($vars['entity_id']) ])) {
|
||||
echo 'MAC vendor: ' . escape_html($response);
|
||||
} else {
|
||||
echo 'Not Found';
|
||||
}
|
||||
} else {
|
||||
echo 'Not correct MAC address';
|
||||
}
|
||||
break;
|
||||
|
||||
case "ip":
|
||||
$ip = explode('/', $vars['entity_id'])[0];
|
||||
|
||||
if ($ip_version = get_ip_version($ip)) {
|
||||
$cache_key = 'response_' . $vars['entity_type'] . '_' . $ip;
|
||||
$cache_entry = get_cache_session($cache_key);
|
||||
//r($cache_entry);
|
||||
if (ishit_cache_session()) {
|
||||
//echo '<h2>CACHED!</h2>';
|
||||
echo $cache_entry;
|
||||
exit;
|
||||
}
|
||||
|
||||
$response = '';
|
||||
if ($reverse_dns = gethostbyaddr6($ip)) {
|
||||
$response .= '<h4>' . escape_html($reverse_dns) . '</h4><hr />' . PHP_EOL;
|
||||
}
|
||||
|
||||
// WHOIS
|
||||
$response .= escape_html(ip_whois($ip));
|
||||
|
||||
if ($response) {
|
||||
$cache_entry = '<pre class="small">' . $response . '</pre>';
|
||||
// @session_start();
|
||||
// $_SESSION['cache']['response_' . $vars['entity_type'] . '_' . $ip] = '<pre class="small">' . $response . '</pre>';
|
||||
// session_commit();
|
||||
} else {
|
||||
$cache_entry = 'Not Found';
|
||||
//echo 'Not Found';
|
||||
}
|
||||
set_cache_session($cache_key, $cache_entry);
|
||||
echo $cache_entry;
|
||||
} else {
|
||||
echo 'Not correct IP address';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'autodiscovery':
|
||||
// if (isset($vars['autodiscovery_id']))
|
||||
// {
|
||||
// $vars['entity_id'] = $vars['autodiscovery_id'];
|
||||
// }
|
||||
//r($vars);
|
||||
if (is_numeric($vars['entity_id']) &&
|
||||
$_SESSION['userlevel'] > 7) {
|
||||
|
||||
$cache_key = 'response_' . $vars['entity_type'] . '_' . $vars['entity_id'];
|
||||
$cache_entry = get_cache_session($cache_key);
|
||||
//r($cache_entry);
|
||||
if (ishit_cache_session()) {
|
||||
//echo '<h2>CACHED!</h2>';
|
||||
echo $cache_entry;
|
||||
exit;
|
||||
}
|
||||
|
||||
$entry = dbFetchRow('SELECT `remote_hostname`, `remote_ip`, `last_reason`, UNIX_TIMESTAMP(`last_checked`) AS `last_checked_unixtime` FROM `autodiscovery` WHERE `autodiscovery_id` = ?', [$vars['entity_id']]);
|
||||
$hostname = $entry['remote_hostname'];
|
||||
$ip = $entry['remote_ip'];
|
||||
|
||||
//r($entry);
|
||||
// 'ok','no_xdp','no_fqdn','no_dns','no_ip_permit','no_ping','no_snmp','no_db','duplicated','unknown'
|
||||
switch ($entry['last_reason']) {
|
||||
case 'ok':
|
||||
$last_reason = "Remote host $hostname ($ip) successfully added to db.";
|
||||
break;
|
||||
|
||||
case 'no_xdp':
|
||||
$last_reason = 'Remote platform ignored by XDP autodiscovery configuration.';
|
||||
break;
|
||||
|
||||
case 'no_fqdn':
|
||||
$last_reason = "Remote IP $ip does not seem to have FQDN.";
|
||||
break;
|
||||
|
||||
case 'no_dns':
|
||||
$last_reason = "Remote host $hostname not resolved.";
|
||||
break;
|
||||
|
||||
case 'no_ip_permit':
|
||||
$last_reason = "Remote IP $ip not permitted in autodiscovery configuration or invalid.";
|
||||
break;
|
||||
|
||||
case 'no_ping':
|
||||
$last_reason = "Remote host $hostname not pingable.";
|
||||
break;
|
||||
|
||||
case 'no_snmp':
|
||||
$last_reason = "Remote host $hostname not SNMPable by configured auth parameters.";
|
||||
break;
|
||||
|
||||
case 'duplicated':
|
||||
$last_reason = "Remote host $hostname ($ip) already found in db.";
|
||||
break;
|
||||
|
||||
case 'no_db':
|
||||
$last_reason = "Remote host $hostname ($ip) success, but not added by an DB error.";
|
||||
break;
|
||||
|
||||
default:
|
||||
$last_reason = "Remote host $hostname ($ip) not added by unknown reason.";
|
||||
break;
|
||||
}
|
||||
$cache_entry = '<div style="width: 280px;">';
|
||||
$cache_entry .= "<h4>" . escape_html($last_reason) . "</h4><hr />";
|
||||
$cache_entry .= '<strong style="margin-left: 10px;">Autodiscovery checked:</strong> ' .
|
||||
format_uptime(get_time() - $entry['last_checked_unixtime'], 'shorter') . ' ago</span>';
|
||||
$cache_entry .= '</div>';
|
||||
//$cache_entry .= build_table_row($entry);
|
||||
set_cache_session($cache_key, $cache_entry);
|
||||
echo $cache_entry;
|
||||
} else {
|
||||
print_warning("You are not permitted to view this entry.");
|
||||
}
|
||||
break;
|
||||
|
||||
case 'latlon':
|
||||
// Check if latitude and longitude are set
|
||||
if (!isset($vars['lat'], $vars['lon'])) {
|
||||
echo "ERROR: Latitude and Longitude required";
|
||||
break;
|
||||
}
|
||||
|
||||
$location = [];
|
||||
|
||||
// Fetch devices and their locations
|
||||
$devices = dbFetchRows("SELECT * FROM `devices` LEFT JOIN `devices_locations` USING (`device_id`) " .
|
||||
generate_where_clause(generate_query_permitted_ng(['devices']),
|
||||
"location_lat = ? AND location_lon = ?"),
|
||||
[$vars['lat'], $vars['lon']]);
|
||||
|
||||
foreach ($devices as $device) {
|
||||
if (!$config['web_show_disabled'] && $device["disabled"]) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (in_array($matches[1], array('Organization', 'org', 'mnt-irt'))) {
|
||||
$org++; // has org info
|
||||
} elseif ($matches[1] === 'Comment') {
|
||||
continue; // skip comments
|
||||
|
||||
if ($device['location'] != '') {
|
||||
$location['location_name'] = $device['location'];
|
||||
}
|
||||
|
||||
// Categorize devices as up or down
|
||||
if ($device["status"] == "0" && $device["ignore"] == "0") {
|
||||
$location["down_hosts"][] = $device;
|
||||
} else {
|
||||
$location["up_hosts"][] = $device;
|
||||
}
|
||||
$response .= $line . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Use RIPE whois API query
|
||||
$whois_url = 'https://stat.ripe.net/data/whois/data.json?';
|
||||
$whois_url .= 'sourceapp=' . urlencode(OBSERVIUM_PRODUCT . '-' . get_unique_id());
|
||||
$whois_url .= '&resource=' . urlencode($ip);
|
||||
|
||||
if ($request = get_http_request($whois_url)) {
|
||||
$request = safe_json_decode($request); // Convert to array
|
||||
if ($request['status'] === 'ok' && safe_count($request['data']['records'])) {
|
||||
$whois_parts = array();
|
||||
foreach ($request['data']['records'] as $i => $parts) {
|
||||
$key = $parts[0]['key'];
|
||||
// Display location information
|
||||
if (!isset($location['location_name'])) {
|
||||
echo "Unknown Location";
|
||||
} else {
|
||||
$num_up = safe_count($location["up_hosts"]);
|
||||
$num_down = safe_count($location["down_hosts"]);
|
||||
$total_hosts = $num_up + $num_down;
|
||||
|
||||
if (in_array($key, [ 'NetRange', 'inetnum', 'inet6num' ])) {
|
||||
$org = 0;
|
||||
$state = 'unknown';
|
||||
if ($num_down > 0) {
|
||||
$state = 'down';
|
||||
} elseif ($num_up > 0) {
|
||||
$state = 'up';
|
||||
}
|
||||
|
||||
$whois_parts[0] = '';
|
||||
foreach ($parts as $part) {
|
||||
if (in_array($part['key'], [ 'Ref', 'source', 'nic-hdl-br' ])) {
|
||||
break;
|
||||
}
|
||||
if (in_array($part['key'], [ 'Organization', 'org', 'mnt-irt' ])) {
|
||||
$org = 1; // has org info
|
||||
$org_name = $part['value'];
|
||||
} elseif ($part['key'] === 'Comment') {
|
||||
continue; // skip comments
|
||||
}
|
||||
$whois_parts[0] .= sprintf('%-16s %s' . PHP_EOL, $part['key'] . ':', $part['value']);
|
||||
// Generate tooltip content
|
||||
$tooltip = "<h3>" . escape_html($location['location_name']) . "</h3><hr />";
|
||||
$tooltip .= '<p><span class="label label-success">Up ' . $num_up . '</span>
|
||||
<span class="label label-error">Down ' . $num_down . '</span></p>';
|
||||
|
||||
if($num_up < 50) {
|
||||
foreach ($location["up_hosts"] as $host) {
|
||||
$tooltip .= '<span class="label label-success">' . escape_html($host['hostname']) . '</span> ';
|
||||
}
|
||||
|
||||
} elseif ($org === 1 && $key === 'OrgName' && strpos($org_name, $parts[0]['value']) === 0) {
|
||||
|
||||
$whois_parts[1] = '';
|
||||
foreach ($parts as $part) {
|
||||
if (in_array($part['key'], [ 'Ref', 'source', 'nic-hdl-br' ])) {
|
||||
break;
|
||||
}
|
||||
if ($part['key'] === 'Comment') {
|
||||
continue; // skip comments
|
||||
}
|
||||
$whois_parts[1] .= sprintf('%-16s %s' . PHP_EOL, $part['key'] . ':', $part['value']);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
$response .= implode(PHP_EOL, $whois_parts);
|
||||
foreach ($location["down_hosts"] as $host) {
|
||||
$tooltip .= '<span class="label label-error">' . escape_html($host['hostname']) . '</span> ';
|
||||
}
|
||||
//$tooltip .= "<p><small>Coordinates: ".$vars['lat'].",".$vars['lon']."</small></p>";
|
||||
|
||||
//print_vars($request['data']['records']);
|
||||
}
|
||||
echo $tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
if ($response) {
|
||||
$cache_entry = '<pre class="small">' . $response . '</pre>';
|
||||
// @session_start();
|
||||
// $_SESSION['cache']['response_' . $vars['entity_type'] . '_' . $ip] = '<pre class="small">' . $response . '</pre>';
|
||||
// session_commit();
|
||||
} else {
|
||||
$cache_entry = 'Not Found';
|
||||
//echo 'Not Found';
|
||||
}
|
||||
set_cache_session($cache_key, $cache_entry);
|
||||
echo $cache_entry;
|
||||
} else {
|
||||
echo 'Not correct IP address';
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'autodiscovery':
|
||||
// if (isset($vars['autodiscovery_id']))
|
||||
// {
|
||||
// $vars['entity_id'] = $vars['autodiscovery_id'];
|
||||
// }
|
||||
//r($vars);
|
||||
if (is_numeric($vars['entity_id']) &&
|
||||
$_SESSION['userlevel'] > 7) {
|
||||
|
||||
$cache_key = 'response_' . $vars['entity_type'] . '_' . $vars['entity_id'];
|
||||
$cache_entry = get_cache_session($cache_key);
|
||||
//r($cache_entry);
|
||||
if (ishit_cache_session()) {
|
||||
//echo '<h2>CACHED!</h2>';
|
||||
echo $cache_entry;
|
||||
exit;
|
||||
}
|
||||
|
||||
$entry = dbFetchRow('SELECT `remote_hostname`, `remote_ip`, `last_reason`, UNIX_TIMESTAMP(`last_checked`) AS `last_checked_unixtime` FROM `autodiscovery` WHERE `autodiscovery_id` = ?', [ $vars['entity_id'] ]);
|
||||
$hostname = $entry['remote_hostname'];
|
||||
$ip = $entry['remote_ip'];
|
||||
|
||||
//r($entry);
|
||||
// 'ok','no_xdp','no_fqdn','no_dns','no_ip_permit','no_ping','no_snmp','no_db','duplicated','unknown'
|
||||
switch ($entry['last_reason']) {
|
||||
case 'ok':
|
||||
$last_reason = "Remote host $hostname ($ip) successfully added to db.";
|
||||
break;
|
||||
|
||||
case 'no_xdp':
|
||||
$last_reason = 'Remote platform ignored by XDP autodiscovery configuration.';
|
||||
break;
|
||||
|
||||
case 'no_fqdn':
|
||||
$last_reason = "Remote IP $ip does not seem to have FQDN.";
|
||||
break;
|
||||
|
||||
case 'no_dns':
|
||||
$last_reason = "Remote host $hostname not resolved.";
|
||||
break;
|
||||
|
||||
case 'no_ip_permit':
|
||||
$last_reason = "Remote IP $ip not permitted in autodiscovery configuration or invalid.";
|
||||
break;
|
||||
|
||||
case 'no_ping':
|
||||
$last_reason = "Remote host $hostname not pingable.";
|
||||
break;
|
||||
|
||||
case 'no_snmp':
|
||||
$last_reason = "Remote host $hostname not SNMPable by configured auth parameters.";
|
||||
break;
|
||||
|
||||
case 'duplicated':
|
||||
$last_reason = "Remote host $hostname ($ip) already found in db.";
|
||||
break;
|
||||
|
||||
case 'no_db':
|
||||
$last_reason = "Remote host $hostname ($ip) success, but not added by an DB error.";
|
||||
break;
|
||||
|
||||
default:
|
||||
$last_reason = "Remote host $hostname ($ip) not added by unknown reason.";
|
||||
break;
|
||||
}
|
||||
$cache_entry = '<div style="width: 280px;">';
|
||||
$cache_entry .= "<h4>$last_reason</h4><hr />";
|
||||
$cache_entry .= '<strong style="margin-left: 10px;">Autodiscovery checked:</strong> '. format_uptime(time() - $entry['last_checked_unixtime'], 'shorter') . ' ago</span>';
|
||||
$cache_entry .= '</div>';
|
||||
//$cache_entry .= build_table_row($entry);
|
||||
set_cache_session($cache_key, $cache_entry);
|
||||
echo $cache_entry;
|
||||
} else {
|
||||
print_warning("You are not permitted to view this entry.");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isset($config['entities'][$vars['entity_type']])) {
|
||||
$entity_ids = array();
|
||||
foreach (explode(',', $vars['entity_id']) as $id) {
|
||||
// Filter permitted IDs
|
||||
if (is_numeric($id) && (is_entity_permitted($id, $vars['entity_type']))) {
|
||||
$entity_ids[] = $id;
|
||||
default:
|
||||
if (isset($config['entities'][$vars['entity_type']])) {
|
||||
$entity_ids = [];
|
||||
foreach (explode(',', $vars['entity_id']) as $id) {
|
||||
// Filter permitted IDs
|
||||
if (is_numeric($id) && (is_entity_permitted($id, $vars['entity_type']))) {
|
||||
$entity_ids[] = $id;
|
||||
}
|
||||
}
|
||||
if (count($entity_ids)) {
|
||||
echo generate_entity_popup_multi($entity_ids, $vars);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this entity.");
|
||||
}
|
||||
} else {
|
||||
print_error("Unknown entity type.");
|
||||
}
|
||||
}
|
||||
if (count($entity_ids)) {
|
||||
echo generate_entity_popup_multi($entity_ids, $vars);
|
||||
//}
|
||||
//elseif (is_numeric($vars['entity_id']) && (is_entity_permitted($vars['entity_id'], $vars['entity_type'])))
|
||||
//{
|
||||
// $entity = get_entity_by_id_cache($vars['entity_type'], $vars['entity_id']);
|
||||
// echo generate_entity_popup($entity, $vars);
|
||||
} else {
|
||||
print_warning("You are not permitted to view this entity.");
|
||||
}
|
||||
} else {
|
||||
print_error("Unknown entity type.");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
exit;
|
||||
|
||||
|
95
html/ajax/geojson.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
ini_set('allow_url_fopen', 0); // Why here?
|
||||
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
include($config['html_dir'] . "/includes/cache-data.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
$vars = get_vars('GET');
|
||||
|
||||
$geo = [];
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `devices` LEFT JOIN `devices_locations` USING (`device_id`) " . generate_where_clause(generate_query_permitted_ng(['devices']))) as $device) {
|
||||
|
||||
if (!$config['web_show_disabled'] && $device["disabled"]) {
|
||||
continue;
|
||||
}
|
||||
$lat = (is_numeric($device['location_lat']) ? $device['location_lat'] : $config['geocoding']['default']['lat']);
|
||||
$lon = (is_numeric($device['location_lon']) ? $device['location_lon'] : $config['geocoding']['default']['lon']);
|
||||
if ($device["status"] == "0") {
|
||||
if ($device["ignore"] == "0") {
|
||||
$locations[$lat][$lon]["down_hosts"][] = $device;
|
||||
}
|
||||
} else {
|
||||
$locations[$lat][$lon]["up_hosts"][] = $device;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($locations as $la => $lat) {
|
||||
foreach ($lat as $lo => $lon) {
|
||||
$tooltip = "";
|
||||
$num_up = safe_count($lon["up_hosts"]);
|
||||
$num_down = safe_count($lon["down_hosts"]);
|
||||
$total_hosts = $num_up + $num_down;
|
||||
$tooltip = '<p><span class="label label-success">Up ' . $num_up . '</span> <span class="label label-error">Down ' . $num_down . '</span></p>';
|
||||
$state = 'unknown';
|
||||
$location_name = "";
|
||||
if ($num_down > 0) {
|
||||
$state = 'down';
|
||||
$location_name = ($lon['down_hosts'][0]['location'] === '' ? OBS_VAR_UNSET : $lon['down_hosts'][0]['location']);
|
||||
$location_url = generate_location_url($lon['down_hosts'][0]['location']);
|
||||
} elseif ($num_up > 0) {
|
||||
$state = 'up';
|
||||
$location_name = ($lon['up_hosts'][0]['location'] === '' ? OBS_VAR_UNSET : $lon['up_hosts'][0]['location']);
|
||||
$location_url = generate_location_url($lon['up_hosts'][0]['location']);
|
||||
}
|
||||
|
||||
$tooltip = "<h3>" . $location_name . "</h3><hr />" . $tooltip;
|
||||
foreach ($lon["down_hosts"] as $down_host) {
|
||||
$tooltip .= '<span class="label label-error">' . escape_html($down_host['hostname']) . '</span> ';
|
||||
}
|
||||
|
||||
$feature = ['geometry' => ['type' => 'Point',
|
||||
'coordinates' => [(float)$lo, (float)$la]],
|
||||
'type' => 'Feature',
|
||||
'properties' => ['name' => $location_name,
|
||||
'state' => $state,
|
||||
'id' => safename($location_name),
|
||||
//'popupContent' => $tooltip,
|
||||
'url' => $location_url]];
|
||||
$features[] = $feature;
|
||||
|
||||
//echo "[$la, $lo, $num_up, $num_down, \"$tooltip\", '$location_name', '$location_url'],\n ";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$geo = ['type' => 'FeatureCollection', 'features' => $features];
|
||||
|
||||
header('Content-type: application/javascript');
|
||||
//echo 'var geojson = ' . json_encode($geo) . ';';
|
||||
|
||||
//print_r($features);
|
||||
|
||||
echo safe_json_encode($geo);
|
||||
|
||||
//r($geo);
|
||||
|
||||
// EOF
|
93
html/ajax/get_entities.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
|
||||
$options = [];
|
||||
$device_id = filter_input(INPUT_GET, 'device_id', FILTER_SANITIZE_NUMBER_INT);
|
||||
$entity_type = filter_input(INPUT_GET, 'entity_type', FILTER_SANITIZE_STRING);
|
||||
|
||||
switch ($entity_type) {
|
||||
case "device":
|
||||
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
$options = generate_device_form_values(NULL, NULL, [ 'filter_mode' => 'exclude', 'subtext' => '%location%', 'show_disabled' => TRUE, 'show_icon' => TRUE ]);
|
||||
|
||||
break;
|
||||
|
||||
case "sensor":
|
||||
foreach (dbFetchRows("SELECT * FROM `sensors` WHERE device_id = ?", [ $device_id ]) as $sensor) {
|
||||
if (is_entity_permitted($sensor, 'sensor')) {
|
||||
|
||||
$nice_class = nicecase($sensor['sensor_class']);
|
||||
$symbol = str_replace('°', '°', $config['sensor_types'][$sensor['sensor_class']]['symbol']);
|
||||
|
||||
$options[] = [
|
||||
'value' => $sensor['sensor_id'],
|
||||
'group' => $nice_class,
|
||||
'name' => addslashes($sensor['sensor_descr']),
|
||||
'subtext' => round($sensor['sensor_value'],2) . $symbol,
|
||||
'icon' => $config['sensor_types'][$sensor['sensor_class']]['icon'],
|
||||
//'class' => 'bg-info'
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "netscalervsvr":
|
||||
// Example for netscalervsvr type
|
||||
foreach (dbFetchRows("SELECT * FROM `netscaler_vservers` WHERE device_id = ?", [ $device_id ]) as $entity) {
|
||||
$options[] = [
|
||||
'value' => $entity['vsvr_id'],
|
||||
'name' => addslashes($entity['vsvr_label']),
|
||||
//'subtext' => 'Extra details for netscalervsvr',
|
||||
//'icon' => 'netscaler-icon',
|
||||
//'class' => 'custom-class'
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case "port":
|
||||
// Example for port type
|
||||
foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND deleted = 0", [$_GET['device_id']]) as $port) {
|
||||
|
||||
humanize_port($port);
|
||||
|
||||
$port_type = $port['human_type'];
|
||||
|
||||
$options[] = [
|
||||
'value' => $port['port_id'],
|
||||
'group' => $port_type,
|
||||
'name' => addslashes($port['port_label_short']),
|
||||
//'content' => addslashes($port['port_label_short']) . ' <span class="label">'.format_si($port['ifSpeed']).'bps</span> ',
|
||||
'subtext' => '['.format_si($port['ifSpeed']).'bps] ' . addslashes($port['ifAlias']),
|
||||
'icon' => $port['icon'],
|
||||
//'class' => 'port-class'
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
echo json_encode($options, JSON_UNESCAPED_UNICODE); // Return JSON encoded data
|
||||
}
|
@ -6,148 +6,152 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
// FIXME, create api-internal for such
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { echo('<li class="nav-header">Session expired, please log in again!</li>'); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo('<li class="nav-header">Session expired, please log in again!</li>');
|
||||
exit;
|
||||
}
|
||||
|
||||
$vars = get_vars('GET');
|
||||
$array_filter = in_array($vars['field'], [ 'syslog_program' ], TRUE); // modules with cached field
|
||||
$vars = get_vars('GET');
|
||||
$array_filter = in_array($vars['field'], ['syslog_program'], TRUE); // modules with cached field
|
||||
if (!safe_empty($vars['field']) && $vars['cache'] !== 'no' && ($array_filter || safe_empty($vars['query']))) {
|
||||
$cache_key = 'options_' . $vars['field'];
|
||||
foreach ($vars as $param => $value) {
|
||||
if (in_array($param, [ 'field', 'query', 'cache' ], TRUE)) { continue; }
|
||||
$cache_key .= "_$param=$value";
|
||||
}
|
||||
$cache_key = 'options_' . $vars['field'];
|
||||
foreach ($vars as $param => $value) {
|
||||
if (in_array($param, ['field', 'query', 'cache'], TRUE)) {
|
||||
continue;
|
||||
}
|
||||
$cache_key .= "_$param=$value";
|
||||
}
|
||||
} else {
|
||||
$cache_key = '';
|
||||
$cache_key = '';
|
||||
}
|
||||
|
||||
$query = '';
|
||||
if ($cache_key && $options = get_cache_session($cache_key)) {
|
||||
// Return cached data (if not set in vars cache = 'no')
|
||||
//header("Content-type: application/json; charset=utf-8");
|
||||
//echo safe_json_encode(array('options' => $_SESSION['cache'][$cache_key]));
|
||||
//$options = $_SESSION['cache'][$cache_key];
|
||||
// Return cached data (if not set in vars cache = 'no')
|
||||
//header("Content-type: application/json; charset=utf-8");
|
||||
//echo safe_json_encode(array('options' => $_SESSION['cache'][$cache_key]));
|
||||
//$options = $_SESSION['cache'][$cache_key];
|
||||
} else {
|
||||
$params = array();
|
||||
//print_vars($vars);
|
||||
switch ($vars['field']) {
|
||||
case 'ipv4_network':
|
||||
case 'ipv6_network':
|
||||
list($ip_version) = explode('_', $vars['field']);
|
||||
$query_permitted = generate_query_permitted('ports');
|
||||
$network_permitted = dbFetchColumn('SELECT DISTINCT(`' . $ip_version . '_network_id`) FROM `' . $ip_version . '_addresses` WHERE 1' . $query_permitted);
|
||||
$query = 'SELECT `' . $ip_version . '_network` FROM `' . $ip_version . '_networks` WHERE 1 ' . generate_query_values_and($network_permitted, $ip_version . '_network_id');
|
||||
if (!safe_empty($vars['query'])) {
|
||||
//$query .= ' AND `' . $ip_version . '_network` LIKE ?';
|
||||
//$params[] = '%' . $vars['query'] . '%';
|
||||
$query .= generate_query_values_and($vars['query'], $vars['field'], '%LIKE%');
|
||||
}
|
||||
$query .= ' ORDER BY `' . $ip_version . '_network`;';
|
||||
//print_vars($query);
|
||||
break;
|
||||
$where = [];
|
||||
$params = [];
|
||||
//print_vars($vars);
|
||||
switch ($vars['field']) {
|
||||
case 'ipv4_network':
|
||||
case 'ipv6_network':
|
||||
$ip_version = explode('_', $vars['field'])[0];
|
||||
$query_permitted = generate_query_permitted_ng('ports');
|
||||
$network_permitted = dbFetchColumn('SELECT DISTINCT(`' . $ip_version . '_network_id`) FROM `' . $ip_version . '_addresses` WHERE ' . $query_permitted);
|
||||
$where[] = generate_query_values($network_permitted, $ip_version . '_network_id');
|
||||
if (!safe_empty($vars['query'])) {
|
||||
//$query .= ' AND `' . $ip_version . '_network` LIKE ?';
|
||||
//$params[] = '%' . $vars['query'] . '%';
|
||||
$where[] = generate_query_values($vars['query'], $vars['field'], '%LIKE%');
|
||||
}
|
||||
$query = 'SELECT `' . $ip_version . '_network` FROM `' . $ip_version . '_networks` ';
|
||||
$query .= generate_where_clause($where);
|
||||
$query .= ' ORDER BY `' . $ip_version . '_network`;';
|
||||
//print_vars($query);
|
||||
break;
|
||||
|
||||
case 'ifspeed':
|
||||
$query_permitted = generate_query_permitted('ports');
|
||||
$query = 'SELECT `ifSpeed`, COUNT(`ifSpeed`) as `count` FROM `ports` WHERE `ifSpeed` > 0 '. $query_permitted .' GROUP BY ifSpeed ORDER BY `count` DESC';
|
||||
$call_function = 'formatRates';
|
||||
$call_params = array(4, 4);
|
||||
break;
|
||||
case 'ifspeed':
|
||||
$query_permitted = generate_query_permitted('ports');
|
||||
$query = 'SELECT `ifSpeed`, COUNT(`ifSpeed`) as `count` FROM `ports` WHERE `ifSpeed` > 0 ' .
|
||||
$query_permitted . ' GROUP BY ifSpeed ORDER BY `count` DESC';
|
||||
$call_function = 'formatRates';
|
||||
$call_params = [4, 4];
|
||||
break;
|
||||
|
||||
case 'syslog_program':
|
||||
//$query_permitted = generate_query_permitted();
|
||||
$query = 'SELECT DISTINCT `program` FROM `syslog`';
|
||||
if (is_intnum($vars['device_id'])) {
|
||||
$query .= ' WHERE ' . generate_query_values_ng($vars['device_id'], 'device_id');
|
||||
}
|
||||
$array_filter = TRUE; // Search query string in array instead sql query (when this faster)
|
||||
break;
|
||||
case 'syslog_program':
|
||||
//$query_permitted = generate_query_permitted();
|
||||
$query = 'SELECT DISTINCT `program` FROM `syslog`';
|
||||
if (is_intnum($vars['device_id'])) {
|
||||
$query .= ' WHERE ' . generate_query_values($vars['device_id'], 'device_id');
|
||||
}
|
||||
$array_filter = TRUE; // Search query string in array instead sql query (when this faster)
|
||||
break;
|
||||
|
||||
case 'bgp_peer_as':
|
||||
$column = 'bgpPeerRemoteAs';
|
||||
$query_permitted = generate_query_permitted('devices');
|
||||
// Combine AS number and AS text into string: ASXXXX: My AS text
|
||||
$query = 'SELECT DISTINCT CONCAT(?, CONCAT_WS(?, `'.$column.'`, `astext`)) AS `'.$vars['field'].'` FROM `bgpPeers` WHERE 1 ' . $query_permitted;
|
||||
$params[] = 'AS';
|
||||
$params[] = ': ';
|
||||
//$query = 'SELECT DISTINCT `' . $column . '`, `astext` FROM `bgpPeers` WHERE 1 ' . $cache['where']['devices_permitted'] . ' ORDER BY `' . $column . '`';
|
||||
if (!safe_empty($vars['query'])) {
|
||||
$query .= ' AND (`' . $column . '` LIKE ? OR `astext` LIKE ?)';
|
||||
$params[] = '%' . $vars['query'] . '%';
|
||||
$params[] = '%' . $vars['query'] . '%';
|
||||
//$query .= generate_query_values_and($vars['query'], $vars['field'], '%LIKE%');
|
||||
}
|
||||
break;
|
||||
case 'bgp_peer_as':
|
||||
$column = 'bgpPeerRemoteAs';
|
||||
$query_permitted = generate_query_permitted('devices');
|
||||
// Combine AS number and AS text into string: ASXXXX: My AS text
|
||||
$query = 'SELECT DISTINCT CONCAT(?, CONCAT_WS(?, `' . $column . '`, `astext`)) AS `' . $vars['field'] . '` FROM `bgpPeers` WHERE 1 ' . $query_permitted;
|
||||
$params[] = 'AS';
|
||||
$params[] = ': ';
|
||||
if (!safe_empty($vars['query'])) {
|
||||
$query .= ' AND (`' . $column . '` LIKE ? OR `astext` LIKE ?)';
|
||||
$params[] = '%' . $vars['query'] . '%';
|
||||
$params[] = '%' . $vars['query'] . '%';
|
||||
//$query .= generate_query_values_and($vars['query'], $vars['field'], '%LIKE%');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'bgp_local_ip':
|
||||
case 'bgp_peer_ip':
|
||||
$columns = array('local_ip' => 'bgpPeerLocalAddr',
|
||||
'peer_ip' => 'bgpPeerRemoteAddr',
|
||||
);
|
||||
$param = str_replace('bgp_', '', $vars['field']);
|
||||
$column = $columns[$param];
|
||||
$query_permitted = generate_query_permitted('devices');
|
||||
$query = 'SELECT DISTINCT `' . $column . '` FROM `bgpPeers` WHERE 1 ' . $query_permitted;
|
||||
if (!safe_empty($vars['query'])) {
|
||||
$query .= generate_query_values_and($vars['query'], $column, '%LIKE%');
|
||||
}
|
||||
break;
|
||||
case 'bgp_local_ip':
|
||||
case 'bgp_peer_ip':
|
||||
$columns = ['local_ip' => 'bgpPeerLocalAddr',
|
||||
'peer_ip' => 'bgpPeerRemoteAddr'];
|
||||
$param = str_replace('bgp_', '', $vars['field']);
|
||||
$column = $columns[$param];
|
||||
if (!safe_empty($vars['query'])) {
|
||||
$where[] = generate_query_values($vars['query'], $column, '%LIKE%');
|
||||
}
|
||||
$query = 'SELECT DISTINCT `' . $column . '` FROM `bgpPeers`';
|
||||
$query .= generate_where_clause($where, generate_query_permitted_ng('devices'));
|
||||
break;
|
||||
|
||||
default:
|
||||
json_output('error', 'Search type unknown');
|
||||
}
|
||||
|
||||
if (strlen($query)) {
|
||||
$options = dbFetchColumn($query, $params);
|
||||
if (safe_count($options)) {
|
||||
if (isset($call_function)) {
|
||||
$call_options = array();
|
||||
foreach ($options as $option) {
|
||||
$call_options[] = call_user_func_array($call_function, array_merge(array($option), $call_params));
|
||||
}
|
||||
$options = $call_options;
|
||||
}
|
||||
|
||||
// Cache request in session var (need convert to common caching lib)
|
||||
if ($cache_key) {
|
||||
set_cache_session($cache_key, $options);
|
||||
//@session_start();
|
||||
//$_SESSION['cache'][$cache_key] = $options; // Cache query data in session for speedup
|
||||
//session_write_close();
|
||||
}
|
||||
} else {
|
||||
json_output('error', 'Data fields are empty');
|
||||
default:
|
||||
json_output('error', 'Search type unknown');
|
||||
}
|
||||
|
||||
if (!safe_empty($query)) {
|
||||
$options = dbFetchColumn($query, $params);
|
||||
if (safe_count($options)) {
|
||||
if (isset($call_function)) {
|
||||
$call_options = [];
|
||||
foreach ($options as $option) {
|
||||
$call_options[] = call_user_func_array($call_function, array_merge([$option], $call_params));
|
||||
}
|
||||
$options = $call_options;
|
||||
}
|
||||
|
||||
// Cache request in session var (need convert to common caching lib)
|
||||
if ($cache_key) {
|
||||
set_cache_session($cache_key, $options);
|
||||
//@session_start();
|
||||
//$_SESSION['cache'][$cache_key] = $options; // Cache query data in session for speedup
|
||||
//session_write_close();
|
||||
}
|
||||
} else {
|
||||
json_output('error', 'Data fields are empty');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (safe_count($options)) {
|
||||
// Filter/search query string in array, instead sql query, when this is faster (ie syslog program)
|
||||
if ($array_filter) {
|
||||
$new_options = [];
|
||||
foreach ($options as $option) {
|
||||
if (stripos($option, $vars['query']) !== FALSE) {
|
||||
$new_options[] = $option;
|
||||
}
|
||||
// Filter/search query string in array, instead sql query, when this is faster (ie syslog program)
|
||||
if ($array_filter) {
|
||||
$new_options = [];
|
||||
foreach ($options as $option) {
|
||||
if (str_contains_array($option, $vars['query'])) {
|
||||
$new_options[] = $option;
|
||||
}
|
||||
}
|
||||
$options = $new_options;
|
||||
}
|
||||
$options = $new_options;
|
||||
}
|
||||
|
||||
header("Content-type: application/json; charset=utf-8");
|
||||
echo safe_json_encode(array( 'options' => $options ));
|
||||
header("Content-type: application/json; charset=utf-8");
|
||||
echo safe_json_encode(['options' => $options]);
|
||||
} else {
|
||||
json_output('error', 'Data fields are empty');
|
||||
json_output('error', 'Data fields are empty');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -4,101 +4,90 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated']) { echo('<li class="nav-header">Session expired, please log in again!</li>'); exit; }
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo('<li class="nav-header">Session expired, please log in again!</li>');
|
||||
exit;
|
||||
}
|
||||
|
||||
include($config['html_dir'] . "/includes/cache-data.inc.php");
|
||||
|
||||
$query_limit = 8; // Limit per query
|
||||
|
||||
$vars = get_vars([ 'POST', 'GET' ]);
|
||||
$vars = get_vars(['POST', 'GET']);
|
||||
|
||||
// Is there a POST/GET query string?
|
||||
if (isset($vars['queryString'])) {
|
||||
$queryString = trim($vars['queryString']);
|
||||
$queryString = trim($vars['queryString']);
|
||||
|
||||
// Is the string length greater than 0?
|
||||
if (strlen($queryString) > 0)
|
||||
{
|
||||
$query_param = "%$queryString%";
|
||||
// Is the string length greater than 0?
|
||||
if (strlen($queryString) > 0) {
|
||||
$query_param = "%$queryString%";
|
||||
|
||||
// Start out with a clean slate
|
||||
$search_results = array();
|
||||
// Start out with a clean slate
|
||||
$search_results = [];
|
||||
|
||||
// Increase query_limit by one, so we can show "+" on result display if there are more than $query_limit entries
|
||||
$query_limit++;
|
||||
// Increase query_limit by one, so we can show "+" on result display if there are more than $query_limit entries
|
||||
$query_limit++;
|
||||
|
||||
// Prepare user permission SQL query for use in search module queries
|
||||
$query_permitted_device = $cache['where']['devices_permitted'];
|
||||
$query_permitted_port = $cache['where']['ports_permitted'];
|
||||
|
||||
// Run search modules
|
||||
foreach ($config['wui']['search_modules'] as $module)
|
||||
{
|
||||
if (is_file($config['html_dir'] . "/includes/search/$module.inc.php"))
|
||||
{
|
||||
include($config['html_dir'] . "/includes/search/$module.inc.php");
|
||||
}
|
||||
}
|
||||
|
||||
// Reset query_limit
|
||||
$query_limit--;
|
||||
|
||||
foreach ($search_results as $results)
|
||||
{
|
||||
$display_count = safe_count($results['results']);
|
||||
|
||||
// If there are more results than query_limit (can happen, as we ++'d above), cut array to desired size and add + to counter
|
||||
if ($display_count > $query_limit)
|
||||
{
|
||||
$results['results'] = array_slice($results['results'], 0, $query_limit);
|
||||
$display_count .= '+';
|
||||
}
|
||||
|
||||
echo('<li class="nav-header">' . $results['descr'] . ': '. $display_count . '</li>' . PHP_EOL);
|
||||
|
||||
foreach ($results['results'] as $result)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($result['data'] as $str) {
|
||||
$str = str_replace('| |', '|', $str);
|
||||
$data[] = rtrim($str, ' |');
|
||||
// Run search modules
|
||||
foreach ($config['wui']['search_modules'] as $module) {
|
||||
if (is_file($config['html_dir'] . "/includes/search/$module.inc.php")) {
|
||||
include($config['html_dir'] . "/includes/search/$module.inc.php");
|
||||
}
|
||||
}
|
||||
echo('<li class="divider" style="margin: 0px;"></li>' . PHP_EOL);
|
||||
echo('<li style="margin: 0px;">' . PHP_EOL . ' <a href="'.$result['url'].'">' . PHP_EOL);
|
||||
echo(' <dl style="border-left: 10px solid '.$result['colour'].'; " class="dl-horizontal dl-search">' . PHP_EOL);
|
||||
echo(' <dt style="width: 64px; text-align: center; line-height: 41.5px;">' . get_icon($result['icon']) . '</dt>' . PHP_EOL);
|
||||
echo(' <dd>' . PHP_EOL);
|
||||
echo(' <strong>'.html_highlight(escape_html($result['name']), $queryString) . PHP_EOL);
|
||||
echo(' <small>'. implode('<br />', $data) . '</small>' . PHP_EOL);
|
||||
echo(' </strong>' . PHP_EOL);
|
||||
echo(' </dd>' . PHP_EOL);
|
||||
echo('</dl>' . PHP_EOL);
|
||||
echo(' </a>' . PHP_EOL);
|
||||
echo('</li>' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!safe_count($search_results))
|
||||
{
|
||||
echo('<li class="nav-header">No search results.</li>');
|
||||
// Reset query_limit
|
||||
$query_limit--;
|
||||
|
||||
foreach ($search_results as $results) {
|
||||
$display_count = safe_count($results['results']);
|
||||
|
||||
// If there are more results than query_limit (can happen, as we ++'d above), cut array to desired size and add + to counter
|
||||
if ($display_count > $query_limit) {
|
||||
$results['results'] = array_slice($results['results'], 0, $query_limit);
|
||||
$display_count .= '+';
|
||||
}
|
||||
|
||||
echo('<li class="nav-header">' . $results['descr'] . ': ' . $display_count . '</li>' . PHP_EOL);
|
||||
|
||||
foreach ($results['results'] as $result) {
|
||||
$data = [];
|
||||
foreach ($result['data'] as $str) {
|
||||
$str = str_replace('| |', '|', $str);
|
||||
$data[] = rtrim($str, ' |');
|
||||
}
|
||||
echo('<li class="divider" style="margin: 0px;"></li>' . PHP_EOL);
|
||||
echo('<li style="margin: 0px;">' . PHP_EOL . ' <a href="' . $result['url'] . '">' . PHP_EOL);
|
||||
echo(' <dl style="border-left: 10px solid ' . $result['colour'] . '; " class="dl-horizontal dl-search">' . PHP_EOL);
|
||||
echo(' <dt style="width: 64px; text-align: center; line-height: 41.5px;">' . get_icon($result['icon']) . '</dt>' . PHP_EOL);
|
||||
echo(' <dd>' . PHP_EOL);
|
||||
echo(' <strong>' . html_highlight(escape_html($result['name']), $queryString) . PHP_EOL);
|
||||
echo(' <small>' . implode('<br />', $data) . '</small>' . PHP_EOL);
|
||||
echo(' </strong>' . PHP_EOL);
|
||||
echo(' </dd>' . PHP_EOL);
|
||||
echo('</dl>' . PHP_EOL);
|
||||
echo(' </a>' . PHP_EOL);
|
||||
echo('</li>' . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!safe_count($search_results)) {
|
||||
echo('<li class="nav-header">No search results.</li>');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// There is no queryString, we shouldn't get here.
|
||||
echo('<li class="nav-header">There should be no direct access to this script! Please reload the page.</li>');
|
||||
// There is no queryString, we shouldn't get here.
|
||||
echo('<li class="nav-header">There should be no direct access to this script! Please reload the page.</li>');
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -6,444 +6,289 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage ajax
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
$config['install_dir'] = "../..";
|
||||
include_once("../../includes/observium.inc.php");
|
||||
|
||||
include_once("../../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (!$_SESSION['authenticated'])
|
||||
{
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
if (!$_SESSION['authenticated']) {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
}
|
||||
|
||||
include_dir($config['html_dir'] . "/includes/widgets/");
|
||||
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE widget_id = ?", array($_POST['id']));
|
||||
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [ $_POST['id'] ]);
|
||||
|
||||
$widget['height'] = (is_numeric($_POST['height']) ? $_POST['height'] : '3');
|
||||
$widget['width'] = (is_numeric($_POST['width']) ? $_POST['width'] : '4');
|
||||
$widget['height'] = is_numeric($_POST['height']) ? $_POST['height'] : 3;
|
||||
$widget['width'] = is_numeric($_POST['width']) ? $_POST['width'] : 4;
|
||||
|
||||
print_dash_mod($widget);
|
||||
|
||||
function print_dash_mod ($mod)
|
||||
{
|
||||
function print_dash_mod($mod) {
|
||||
|
||||
global $config;
|
||||
global $cache;
|
||||
global $config, $cache;
|
||||
|
||||
$mod['vars'] = json_decode($mod['widget_config'], TRUE);
|
||||
$mod['vars'] = safe_json_decode($mod['widget_config']);
|
||||
|
||||
$width = (is_numeric($mod['width']) ? $mod['width'] : 1240);
|
||||
$height = (is_numeric($mod['height']) ? $mod['height'] : 80);
|
||||
$width = is_numeric($mod['width']) ? $mod['width'] : 1240;
|
||||
$height = is_numeric($mod['height']) ? $mod['height'] : 80;
|
||||
|
||||
switch ($mod['widget_type'])
|
||||
{
|
||||
switch ($mod['widget_type']) {
|
||||
|
||||
case "welcome":
|
||||
echo '<div class="box box-solid do-not-update" style="padding:10px; padding-left: 375px; background-image: url(images/login-hamster-large.png); background-position: left 10px top -100px; background-repeat: no-repeat;">';
|
||||
echo '<h3>Welcome to your new Observium dashboard!</h3>';
|
||||
if(isset($mod['vars']['converted']))
|
||||
{
|
||||
echo 'This was autogenerated based on your previous front page. It can be modified to suit your requirements.<br />';
|
||||
} else {
|
||||
echo 'This is an autogenerated default dashboard. It can be modified to suit your requirements.<br />';
|
||||
}
|
||||
echo 'Please see the <strong><a href="'.OBSERVIUM_DOCS_URL.'/dashboard/" target="_blank">documentation</a></strong> for information about how to configure this dashboard. Including how to delete this widget!';
|
||||
echo '</div>';
|
||||
break;
|
||||
case "welcome":
|
||||
echo '<div class="box box-solid do-not-update" style="padding:10px; padding-left: 375px; background-image: url(images/hamster-login.png); background-position: left 10px top -100px; background-repeat: no-repeat;">';
|
||||
echo '<h3>Welcome to your new Observium dashboard!</h3>';
|
||||
if (isset($mod['vars']['converted'])) {
|
||||
echo 'This was autogenerated based on your previous front page. It can be modified to suit your requirements.<br />';
|
||||
} else {
|
||||
echo 'This is an autogenerated default dashboard. It can be modified to suit your requirements.<br />';
|
||||
}
|
||||
echo 'Please see the <strong><a href="' . OBSERVIUM_DOCS_URL . '/dashboard/" target="_blank">documentation</a></strong> for information about how to configure this dashboard. Including how to delete this widget!';
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
case "weathermap":
|
||||
case "weathermap":
|
||||
|
||||
echo '<div class="box box-solid do-not-update">';
|
||||
echo '<div class="box box-solid do-not-update">';
|
||||
|
||||
$wmap = dbFetchRow("SELECT * FROM `weathermaps` WHERE `wmap_name` = ?", array($mod['vars']['mapname']));
|
||||
$wmap = dbFetchRow("SELECT * FROM `weathermaps` WHERE `wmap_name` = ?", [ $mod['vars']['mapname'] ]);
|
||||
|
||||
echo ' <div class="hover-hide widget-title" style="z-index: 900; position: absolute; overflow: hidden;" class="widget-title"><h4 style="wwriting-mode: vertical-lr; ttext-orientation: mixed;" class="box-title">' .
|
||||
'' . htmlentities($wmap['wmap_name']) . '</h4>' .
|
||||
'</div>' . PHP_EOL;
|
||||
echo ' <div class="hover-hide widget-title" style="z-index: 900; position: absolute; overflow: hidden;" class="widget-title"><h4 style="wwriting-mode: vertical-lr; ttext-orientation: mixed;" class="box-title">' .
|
||||
escape_html($wmap['wmap_name']) . '</h4></div>' . PHP_EOL;
|
||||
|
||||
echo ' <div class="box-content" style="overflow: hidden">';
|
||||
echo '<div style="height:100%; overflow:hidden; width: 110%;">';
|
||||
echo '<a href="'.generate_url(['page' => 'wmap', 'mapname' => $wmap['map_name']]).'">';
|
||||
echo '<img src="/weathermap.php?mapname=' . htmlentities($wmap['wmap_name']) . '&action=draw&unique=' . time() . '&width='.$width.'&height='.$height.'">';
|
||||
echo '</a>';
|
||||
echo ' <div class="box-content" style="overflow: hidden">';
|
||||
echo '<div style="height:100%; overflow:hidden; width: 110%;">';
|
||||
echo '<a href="' . generate_url([ 'page' => 'wmap', 'mapname' => $wmap['map_name'] ]) . '">';
|
||||
echo '<img src="/weathermap.php?mapname=' . escape_html($wmap['wmap_name']) . '&action=draw&unique=' . time() . '&width=' . $width . '&height=' . $height . '">';
|
||||
echo '</a>';
|
||||
|
||||
echo '</div>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
echo ' </div>';
|
||||
|
||||
echo '</div>';
|
||||
break;
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
case "map":
|
||||
echo '<div class="box box-solid do-not-update">';
|
||||
print_dash_map($mod, $width, $height);
|
||||
echo '</div>';
|
||||
break;
|
||||
case "map":
|
||||
echo '<div class="box box-solid do-not-update">';
|
||||
print_dash_map($mod, $width, $height);
|
||||
echo '</div>';
|
||||
|
||||
case "graph":
|
||||
echo '<div class="box box-solid do-not-update">';
|
||||
print_dash_graph($mod, $width, $height);
|
||||
echo '</div>';
|
||||
break;
|
||||
break;
|
||||
|
||||
case "port_percent":
|
||||
if($_SESSION['userlevel'] < 5)
|
||||
{
|
||||
echo '<div class="box box-solid" style="width: 100%; height: 100%; float:none; display: block; padding: 10px;">';
|
||||
echo '<div class="alert statusbox alert-warning" style="border-left: 1px; width: 100%; height: 100%; margin-right: 10px; float:none; display: block;">';
|
||||
echo '<div style="margin: auto; line-height: 75px; text-align: center;">You have insufficient permissions to view this widget.</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
} elseif ($height < 190) {
|
||||
echo '<div class="box box-solid alert alert-warning" style="width: 100%; height: 100%; float:none; display: block; padding: 10px;">';
|
||||
echo '<b>WARNING</b> This widget is not tall enough to display the requested content. Module <b>Port Percent</b> requires 190px or taller.';
|
||||
echo '</div>';
|
||||
} else {
|
||||
include($config['html_dir'] . "/includes/status-portpercent.inc.php");
|
||||
}
|
||||
break;
|
||||
case "port_percent":
|
||||
if ($_SESSION['userlevel'] < 5) {
|
||||
echo '<div class="box box-solid" style="width: 100%; height: 100%; float:none; display: block; padding: 10px;">';
|
||||
echo '<div class="alert statusbox alert-warning" style="border-left: 1px; width: 100%; height: 100%; margin-right: 10px; float:none; display: block;">';
|
||||
echo '<div style="margin: auto; line-height: 75px; text-align: center;">You have insufficient permissions to view this widget.</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
} elseif ($height < 190) {
|
||||
echo '<div class="box box-solid alert alert-warning" style="width: 100%; height: 100%; float:none; display: block; padding: 10px;">';
|
||||
echo '<b>WARNING</b> This widget is not tall enough to display the requested content. Module <b>Port Percent</b> requires 190px or taller.';
|
||||
echo '</div>';
|
||||
} else {
|
||||
include($config['html_dir'] . "/includes/status-portpercent.inc.php");
|
||||
}
|
||||
break;
|
||||
|
||||
case "alert_table":
|
||||
echo '<div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title">Alert Status</h3></div>';
|
||||
echo ' <div class="box-content" style="overflow:auto;">';
|
||||
print_alert_table(array('status' => 'failed',
|
||||
'pagination' => FALSE,
|
||||
'short' => TRUE)
|
||||
);
|
||||
echo ' </div>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
case "alert_table":
|
||||
echo '<div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title">Alert Status</h3></div>';
|
||||
echo ' <div class="box-content" style="height: ' . ($height - 40) . 'px; overflow: auto;">';
|
||||
//echo ' <div class="box-content" style="overflow: scroll; overflow-x:scroll;">';
|
||||
//echo ' <div class="box-content" style="overflow:auto;">';
|
||||
|
||||
case "status_summary":
|
||||
echo '<div class="row">';
|
||||
if($width > 1000) { $div_class = "col-md-6"; } else { $div_class = "col-md-12"; }
|
||||
$short = !($width > 1000);
|
||||
|
||||
if($height < 210) { $hide_group_bar = 1; }
|
||||
print_alert_table([ 'status' => 'failed', 'pagination' => FALSE, 'short' => $short ]);
|
||||
echo ' </div>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
include($config['html_dir'] . "/includes/status-summary.inc.php");
|
||||
echo '</div>';
|
||||
break;
|
||||
break;
|
||||
|
||||
case "alert_boxes":
|
||||
case "old_status_boxes":
|
||||
//r($height);
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
//$count = round(($width) / 165) * round(($height+10) / 90); // 1.5 wide
|
||||
$count = floor(($width+10) / 198) * floor(($height+10) / 96); // 1.5 wide
|
||||
echo '<div style="width: auto; height: 100%; overflow-x: visible; overflow-y: visible; margin-right: -25px;">';
|
||||
if($mod['widget_type'] == 'alert_boxes')
|
||||
{
|
||||
print_status_boxes($mod, $count);
|
||||
} else {
|
||||
print_status_boxes($config['frontpage']['device_status'], $count);
|
||||
}
|
||||
echo '</div>';
|
||||
break;
|
||||
case "status_summary":
|
||||
echo '<div class="row">';
|
||||
if ($width > 1000) {
|
||||
$div_class = "col-md-6";
|
||||
} else {
|
||||
$div_class = "col-md-12";
|
||||
}
|
||||
|
||||
case "old_status_table":
|
||||
echo '<div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title">Status Warnings and Notifications</h3></div>';
|
||||
echo ' <div class="box-content" style="height: ' . ($height - 40) .'px; overflow: auto;">';
|
||||
if ($height < 210) {
|
||||
$hide_group_bar = 1;
|
||||
}
|
||||
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
echo generate_status_table($config['frontpage']['device_status']);
|
||||
echo generate_box_close();
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
include($config['html_dir'] . "/includes/status-summary.inc.php");
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
break;
|
||||
case "alert_boxes":
|
||||
case "old_status_boxes":
|
||||
//r($height);
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
//$count = round(($width) / 165) * round(($height+10) / 90); // 1.5 wide
|
||||
$count = floor(($width + 10) / 198) * floor(($height + 10) / 96); // 1.5 wide
|
||||
echo '<div style="width: auto; height: 100%; overflow-x: visible; overflow-y: visible; margin-right: -25px;">';
|
||||
if ($mod['widget_type'] == 'alert_boxes') {
|
||||
print_status_boxes($mod, $count);
|
||||
} else {
|
||||
print_status_boxes($config['frontpage']['device_status'], $count);
|
||||
}
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
case "status_donuts":
|
||||
include($config['html_dir'] . "/includes/status-donuts.inc.php");
|
||||
break;
|
||||
case "old_status_table":
|
||||
echo '<div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title">Status Warnings and Notifications</h3></div>';
|
||||
echo ' <div class="box-content" style="height: ' . ($height - 40) . 'px; overflow: auto;">';
|
||||
|
||||
case "syslog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/syslog/">Syslog</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
include($config['html_dir'] . '/includes/cache-data.inc.php');
|
||||
echo generate_status_table($config['frontpage']['device_status']);
|
||||
echo generate_box_close();
|
||||
|
||||
$syslog_vars = $mod['vars'];
|
||||
break;
|
||||
|
||||
$syslog_vars = array_merge($syslog_vars, ['short' => TRUE, 'pagesize' => ($height - 36) / 26,
|
||||
'priority' => $config['frontpage']['syslog']['priority']]);
|
||||
case "status_donuts":
|
||||
include($config['html_dir'] . "/includes/status-donuts.inc.php");
|
||||
break;
|
||||
|
||||
print_syslogs($syslog_vars);
|
||||
case "syslog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/syslog/">Syslog</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
$short = !($width > 1000);
|
||||
|
||||
case "syslog_alerts":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/syslog_alerts/">Syslog Alerts</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
print_logalert_log(array('short' => TRUE, 'pagesize' => ($height - 36) / 26) );
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
$syslog_vars = array_merge($mod['vars'], [ 'short' => $short, 'pagesize' => ($height - 36) / 26,
|
||||
'priority' => $config['frontpage']['syslog']['priority'] ]);
|
||||
|
||||
case "alertlog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/alert_log/">Alert Log</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
print_alert_log_short(array('short' => TRUE, 'pagesize' => ($height - 36) / 26));
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
print_syslogs($syslog_vars);
|
||||
|
||||
case "eventlog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/eventlog/">Eventlog</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
$pagesize = floor(($height - 36) / 26);
|
||||
//if($width > 1000) { $pagesize -= 3; $short = FALSE; } else { $short = TRUE; }
|
||||
case "syslog_alerts":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/syslog_alerts/">Syslog Alerts</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
|
||||
print_events(array('short' => TRUE, 'pagesize' => $pagesize, 'pageno' => 1,
|
||||
'severity' => $config['frontpage']['eventlog']['severity']));
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
$short = !($width > 1000);
|
||||
|
||||
$alertlog_vars = array_merge($mod['vars'], [ 'short' => $short, 'pagesize' => ($height - 36) / 26 ]);
|
||||
|
||||
print_logalert_log($alertlog_vars);
|
||||
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
case "alertlog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/alert_log/">Alert Log</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
|
||||
$short = !($width > 1000);
|
||||
|
||||
$alertlog_vars = array_merge($mod['vars'], [ 'short' => $short, 'pagesize' => ($height - 36) / 26 ]);
|
||||
|
||||
print_alert_log($alertlog_vars);
|
||||
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
case "eventlog":
|
||||
echo ' <div class="box box-solid" style="overflow: hidden; height: auto; max-height: 100%">';
|
||||
echo ' <div class="box-header" style="cursor: hand;"><h3 class="box-title"><a href="/eventlog/">Eventlog</a></h3></div>';
|
||||
echo ' <div class="box-content" style="overflow: hidden; overflow-x:scroll;">';
|
||||
|
||||
$pagesize = floor(($height - 36) / 26);
|
||||
|
||||
$short = !($width > 1000);
|
||||
|
||||
$eventlog_vars = array_merge($mod['vars'], [ 'short' => $short, 'pagesize' => $pagesize, 'pageno' => 1,
|
||||
'severity' => $config['frontpage']['eventlog']['severity'] ]);
|
||||
|
||||
print_events($eventlog_vars);
|
||||
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
|
||||
case "realtime":
|
||||
echo ' <div class="box box-solid do-not-update" style="overflow: hidden;">';
|
||||
$realtime_link = 'graph-realtime.php?type=bits&id=430082&interval=10';
|
||||
case "realtime":
|
||||
echo ' <div class="box box-solid do-not-update" style="overflow: hidden;">';
|
||||
$realtime_link = 'graph-realtime.php?type=bits&id=430082&interval=10';
|
||||
|
||||
?>
|
||||
<object data="<?php echo($realtime_link); ?>" type="image/svg+xml" width="<?php echo $width; ?>"
|
||||
height="<?php echo $height; ?>">
|
||||
<param name="src"
|
||||
value="graph.php?type=bits&id=<?php echo($port['port_id'] . "&interval=" . $vars['interval']); ?>"/>
|
||||
Your browser does not support SVG! You need to either use Firefox or Chrome, or download the Adobe SVG
|
||||
plugin.
|
||||
</object>
|
||||
<?php
|
||||
echo '</div>';
|
||||
break;
|
||||
?>
|
||||
<object data="<?php echo($realtime_link); ?>" type="image/svg+xml" width="<?php echo $width; ?>"
|
||||
height="<?php echo $height; ?>">
|
||||
<param name="src"
|
||||
value="graph.php?type=bits&id=<?php echo($port['port_id'] . "&interval=" . $vars['interval']); ?>"/>
|
||||
Your browser does not support SVG! You need to either use Firefox or Chrome, or download the Adobe SVG
|
||||
plugin.
|
||||
</object>
|
||||
<?php
|
||||
echo '</div>';
|
||||
break;
|
||||
|
||||
default:
|
||||
echo '<div class="grid-stack-item-content box box-solid" style="overflow: hidden; justify-content: center; align-items: center;">';
|
||||
echo ' <div class="box-content" style="overflow: hidden;">';
|
||||
echo ' <h3 class="box-title">Unconfigured Module</h3>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
//echo '</div>';
|
||||
$widget_path = $config['html_dir'] . '/includes/widgets/' . $mod['widget_type'] . '.inc.php';
|
||||
|
||||
if (is_file($widget_path)) {
|
||||
include($widget_path);
|
||||
} else {
|
||||
echo '<div class="grid-stack-item-content box box-solid" style="overflow: hidden; justify-content: center; align-items: center;">';
|
||||
echo ' <div class="box-content" style="overflow: hidden;">';
|
||||
echo ' <h3 class="box-title">Unconfigured Module</h3>';
|
||||
echo ' </div>';
|
||||
echo '</div>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
function print_dash_map ($vars, $width, $height)
|
||||
function print_dash_map($mod, $width, $height)
|
||||
{
|
||||
|
||||
global $config;
|
||||
global $config;
|
||||
|
||||
?>
|
||||
?>
|
||||
<style type="text/css">
|
||||
#map<?php echo $vars['widget_id']; ?> label {
|
||||
#map<?php echo $mod['widget_id']; ?> label {
|
||||
width: auto;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
#map<?php echo $vars['widget_id']; ?> img {
|
||||
#map<?php echo $mod['widget_id']; ?> img {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
#map<?php echo $vars['widget_id']; ?> {
|
||||
#map<?php echo $mod['widget_id']; ?> {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
echo '<div id="map'.$vars['widget_id'].'"></div>';
|
||||
echo '<div id="map' . $mod['widget_id'] . '"></div>';
|
||||
|
||||
include($config['html_dir']. '/includes/map/leaflet.inc.php');
|
||||
$vars = $mod['vars']; // set the $vars array to be used mostly by geojson
|
||||
|
||||
include($config['html_dir'] . '/includes/map/leaflet.inc.php');
|
||||
|
||||
} // End show_map
|
||||
|
||||
function print_dash_graph($mod, $width, $height) {
|
||||
global $config;
|
||||
|
||||
$vars = $mod['vars'];
|
||||
|
||||
if (!isset($vars['type']))
|
||||
{
|
||||
|
||||
echo '<div style="position: relative; top: 50%; transform: perspective(1px) translateY(-50%); width: 100%; text-align: center;">
|
||||
<btn class="btn btn-primary" onclick="configWidget(' . $mod['widget_id'] . ')"><i class="icon-signal"/> Select Graph</btn>
|
||||
</div>';
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($vars['timestamp_from']) && preg_match(OBS_PATTERN_TIMESTAMP, $vars['timestamp_from'])) {
|
||||
$vars['from'] = strtotime($vars['timestamp_from']);
|
||||
unset($vars['timestamp_from']);
|
||||
}
|
||||
if (isset($vars['timestamp_to']) && preg_match(OBS_PATTERN_TIMESTAMP, $vars['timestamp_to'])) {
|
||||
$vars['to'] = strtotime($vars['timestamp_to']);
|
||||
unset($vars['timestamp_to']);
|
||||
}
|
||||
|
||||
// Period alone is sufficient
|
||||
|
||||
/*
|
||||
if (isset($vars['period']))
|
||||
{
|
||||
$vars['to'] = "now";
|
||||
$vars['from'] = "-".$vars['period'];
|
||||
}
|
||||
|
||||
if (!isset($vars['from']))
|
||||
{
|
||||
$vars['from'] = $config['time']['day'];
|
||||
}
|
||||
if (!isset($vars['to']))
|
||||
{
|
||||
$vars['to'] = $config['time']['now'];
|
||||
}
|
||||
*/
|
||||
|
||||
preg_match('/^(?P<type>[a-z0-9A-Z-]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
|
||||
|
||||
if (OBS_DEBUG) {
|
||||
print_vars($graphtype);
|
||||
}
|
||||
|
||||
$type = $graphtype['type'];
|
||||
$subtype = $graphtype['subtype'];
|
||||
|
||||
if (is_numeric($vars['device'])) {
|
||||
$device = device_by_id_cache($vars['device']);
|
||||
} elseif (!empty($vars['device'])) {
|
||||
$device = device_by_name($vars['device']);
|
||||
} elseif ($type === "device" && is_numeric($vars['id'])) {
|
||||
$device = device_by_id_cache($vars['id']);
|
||||
}
|
||||
|
||||
$preserve_id = $vars['id'];
|
||||
|
||||
if (is_file($config['html_dir'] . "/includes/graphs/" . $type . "/auth.inc.php"))
|
||||
{
|
||||
include($config['html_dir'] . "/includes/graphs/" . $type . "/auth.inc.php");
|
||||
}
|
||||
|
||||
$vars['id'] = $preserve_id;
|
||||
|
||||
if (!$auth) {
|
||||
print_error_permission();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($config['entities'][$type])) {
|
||||
$entity = get_entity_by_id_cache($type, $vars['id']);
|
||||
entity_rewrite($type, $entity);
|
||||
}
|
||||
|
||||
if ($type === 'bgp') {
|
||||
$entity = get_entity_by_id_cache('bgp_peer', $vars['id']);
|
||||
entity_rewrite('bgp_peer', $entity);
|
||||
}
|
||||
|
||||
//$device = device_by_id_cache($entity['device_id']);
|
||||
|
||||
//$graph_array['type'] = $vars['entity_type'] . '_' . $vars['graph_type'];
|
||||
//$graph_array['id'] = $vars['entity_id'];
|
||||
|
||||
// Generate navbar with subtypes
|
||||
$graph_array = $vars;
|
||||
|
||||
//$graph_array['from'] = '-1day';
|
||||
//$graph_array['to'] = 'now';
|
||||
|
||||
$graph_array['width'] = $width - 76 + 14; // RRD graphs are 75px wider than request value
|
||||
$graph_array['height'] = $height - 34; //68; // RRD graphs are taller than request value
|
||||
|
||||
if ($graph_array['width'] > 350)
|
||||
{
|
||||
$graph_array['width'] -= 6;
|
||||
} // RRD graphs > 350px are 6 px wider because of larger legend font
|
||||
if ($graph_array['width'] > 350)
|
||||
{
|
||||
$graph_array['height'] -= 6;
|
||||
} // RRD graphs > 350px are 6 px taller because of larger legend font
|
||||
|
||||
$title_div = 'top:0px; left: 0px; padding: 4px; border-top-left-radius: 4px; border: 1px solid #e5e5e5; border-left: none; border-top: none; background-color: rgba(255, 255,255, 0.75); ';
|
||||
$title_div = 'widget-title';
|
||||
|
||||
if ($height < 100)
|
||||
{
|
||||
$graph_array['height'] = $height;
|
||||
$graph_array['width'] = $width;
|
||||
$graph_array['graph_only'] = 'yes';
|
||||
|
||||
$title_div = 'top:5px; left: 5px; padding: none; border-radius: 2px; border: 1px solid #e5e5e5; background: rgba(255, 255, 255, 0.7);';
|
||||
$title_div = 'widget-title-small';
|
||||
|
||||
} else {
|
||||
$graph_array['draw_all'] = 'yes';
|
||||
}
|
||||
$t_len = $vars['width'] / 10;
|
||||
|
||||
$subtype_text = (isset($config['graph_types'][$type][$subtype]) ? $config['graph_types'][$type][$subtype]['descr'] : nicecase($subtype));
|
||||
|
||||
if (!isset($graph_array['title'])) {
|
||||
if ($type === 'global')
|
||||
{
|
||||
$title = "Global :: " . $subtype_text;
|
||||
} elseif (str_contains($type, "multi")) {
|
||||
$count = safe_count($graph_array['id']);
|
||||
$title = $count . ' ' . nicecase(str_replace("multi-", '', $type)) . ' :: ' . $subtype_text;
|
||||
} else {
|
||||
$title = device_name($device, $t_len / 2 - 2) . ($type === "device" ? ' :: ' : ' :: ' . truncate($entity['entity_shortname'], 32) . ' :: ' ) . $subtype_text;
|
||||
}
|
||||
} else {
|
||||
$title = $graph_array['title'];
|
||||
unset($graph_array['title']);
|
||||
}
|
||||
|
||||
//$graph_array['format'] = 'png';
|
||||
|
||||
//$graph_array['img_id'] = generate_random_string(5);
|
||||
//$graph_array['legend'] = 'no';
|
||||
|
||||
$graph_array['rigid_height'] = 'yes'; // Force height of graph to be same as height of graph_type.
|
||||
|
||||
$graph_array['class'] = 'image-refresh';
|
||||
|
||||
$graph = generate_graph_tag($graph_array, TRUE);
|
||||
|
||||
$link_array = $graph_array;
|
||||
$link_array['page'] = "graphs";
|
||||
unset($link_array['graph_only']);
|
||||
unset($link_array['rigid_height']);
|
||||
unset($link_array['height'], $link_array['width']);
|
||||
$link = generate_url($link_array);
|
||||
|
||||
//echo ' <div class="box-header with-border">' . $device['hostname'] . '<span class="pull-right">' . truncate($entity['entity_name'], 32) . '</span></div>';
|
||||
|
||||
echo ' <div class="hover-hide ' . $title_div . '" style="z-index: 900; position: absolute; overflow: hidden;" class="widget-title"><h4 style="wwriting-mode: vertical-lr; ttext-orientation: mixed;" class="box-title">' .
|
||||
'' . escape_html($title) . '</h4>' .
|
||||
'</div>' . PHP_EOL;
|
||||
|
||||
echo ' <div class="box-content" style="overflow: hidden">';
|
||||
echo '<div style="height:100%; overflow:hidden; width: 110%;">';
|
||||
echo '<a href="'.$link.'">'.$graph['img_tag'].'</a>';
|
||||
echo '</div>';
|
||||
echo ' </div>';
|
||||
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
Options FollowSymlinks Multiviews
|
||||
|
||||
ErrorDocument 404 /error.php?404
|
||||
RedirectMatch 404 /\.
|
||||
|
||||
RewriteEngine on
|
||||
|
@ -1,25 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage webinterface
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
ini_set('allow_url_fopen', 0);
|
||||
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
if (!$config['web_iframe'] && is_iframe()) {
|
||||
print_error_permission("Not allowed to run in a iframe!");
|
||||
die();
|
||||
}
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) { if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; } }
|
||||
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
|
||||
if (!$_SESSION['authenticated']) {
|
||||
// not authenticated
|
||||
die("Unauthenticated");
|
||||
}
|
||||
}
|
||||
require_once($config['html_dir'] . "/includes/jpgraph/src/jpgraph.php");
|
||||
require_once($config['html_dir'] . "/includes/jpgraph/src/jpgraph_line.php");
|
||||
require_once($config['html_dir'] . "/includes/jpgraph/src/jpgraph_bar.php");
|
||||
@ -28,234 +35,221 @@ require_once($config['html_dir'] . "/includes/jpgraph/src/jpgraph_date.php");
|
||||
|
||||
$vars = get_vars('GET');
|
||||
|
||||
if (is_numeric($vars['bill_id']))
|
||||
{
|
||||
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'])
|
||||
{
|
||||
if (bill_permitted($vars['bill_id']))
|
||||
{
|
||||
$bill_id = $vars['bill_id'];
|
||||
if (is_numeric($vars['bill_id'])) {
|
||||
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
|
||||
if (bill_permitted($vars['bill_id'])) {
|
||||
$bill_id = $vars['bill_id'];
|
||||
} else {
|
||||
echo("Unauthorised Access Prohibited.");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
echo("Unauthorised Access Prohibited.");
|
||||
exit;
|
||||
$bill_id = $vars['bill_id'];
|
||||
}
|
||||
} else {
|
||||
$bill_id = $vars['bill_id'];
|
||||
}
|
||||
} else {
|
||||
echo("Unauthorised Access Prohibited.");
|
||||
exit;
|
||||
echo("Unauthorised Access Prohibited.");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Workaround for JPGraph 3.5 on Ubuntu per 0015246
|
||||
if( !function_exists('imageantialias') ) {
|
||||
function imageantialias( $image, $enabled ) {
|
||||
return false;
|
||||
if (!function_exists('imageantialias')) {
|
||||
function imageantialias($image, $enabled)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$start = $vars['from'];
|
||||
$end = $vars['to'];
|
||||
$xsize = (is_numeric($vars['x']) ? $vars['x'] : "800" );
|
||||
$ysize = (is_numeric($vars['y']) ? $vars['y'] : "250" );
|
||||
$start = $vars['from'];
|
||||
$end = $vars['to'];
|
||||
$xsize = (is_numeric($vars['x']) ? $vars['x'] : "800");
|
||||
$ysize = (is_numeric($vars['y']) ? $vars['y'] : "250");
|
||||
//$count = (is_numeric($_GET['count']) ? $_GET['count'] : "0" );
|
||||
//$type = (isset($_GET['type']) ? $_GET['type'] : "date" );
|
||||
//$dur = $end - $start;
|
||||
//$datefrom = date('Ymthis', $start);
|
||||
//$dateto = date('Ymthis', $end);
|
||||
$imgtype = (isset($vars['type']) ? $vars['type'] : "historical" );
|
||||
$imgbill = (isset($vars['imgbill']) ? $vars['imgbill'] : false);
|
||||
$yaxistitle = "Bytes";
|
||||
$imgtype = $vars['type'] ?? "historical";
|
||||
$imgbill = $vars['imgbill'] ?? FALSE;
|
||||
$yaxistitle = "Bytes";
|
||||
|
||||
$in_data = array();
|
||||
$out_data = array();
|
||||
$tot_data = array();
|
||||
$allow_data = array();
|
||||
$ave_data = array();
|
||||
$overuse_data = array();
|
||||
$ticklabels = array();
|
||||
$in_data = [];
|
||||
$out_data = [];
|
||||
$tot_data = [];
|
||||
$allow_data = [];
|
||||
$ave_data = [];
|
||||
$overuse_data = [];
|
||||
$ticklabels = [];
|
||||
|
||||
if ($imgtype == "historical")
|
||||
{
|
||||
$i = "0";
|
||||
if ($imgtype === "historical") {
|
||||
$i = "0";
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12", array($bill_id)) as $data)
|
||||
{
|
||||
$datefrom = strftime("%e %b %Y", strtotime($data['bill_datefrom']));
|
||||
$dateto = strftime("%e %b %Y", strtotime($data['bill_dateto']));
|
||||
$datelabel = $datefrom."\n".$dateto;
|
||||
$traf['in'] = $data['traf_in'];
|
||||
$traf['out'] = $data['traf_out'];
|
||||
$traf['total'] = $data['traf_total'];
|
||||
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12", [$bill_id]) as $data) {
|
||||
$datefrom = strftime("%e %b %Y", strtotime($data['bill_datefrom']));
|
||||
$dateto = strftime("%e %b %Y", strtotime($data['bill_dateto']));
|
||||
$datelabel = $datefrom . "\n" . $dateto;
|
||||
$traf['in'] = $data['traf_in'];
|
||||
$traf['out'] = $data['traf_out'];
|
||||
$traf['total'] = $data['traf_total'];
|
||||
|
||||
if ($data['bill_type'] == "Quota")
|
||||
{
|
||||
$traf['allowed'] = $data['bill_allowed'];
|
||||
$traf['overuse'] = $data['bill_overuse'];
|
||||
} else {
|
||||
$traf['allowed'] = "0";
|
||||
$traf['overuse'] = "0";
|
||||
if ($data['bill_type'] === "Quota") {
|
||||
$traf['allowed'] = $data['bill_allowed'];
|
||||
$traf['overuse'] = $data['bill_overuse'];
|
||||
} else {
|
||||
$traf['allowed'] = "0";
|
||||
$traf['overuse'] = "0";
|
||||
}
|
||||
|
||||
$ticklabels[] = $datelabel;
|
||||
$in_data[] = $traf['in'];
|
||||
$out_data[] = $traf['out'];
|
||||
$tot_data[] = $traf['total'];
|
||||
$allow_data[] = $traf['allowed'];
|
||||
$overuse_data[] = $traf['overuse'];
|
||||
$i++;
|
||||
//print_vars($data);
|
||||
}
|
||||
|
||||
array_push($ticklabels, $datelabel);
|
||||
array_push($in_data, $traf['in']);
|
||||
array_push($out_data, $traf['out']);
|
||||
array_push($tot_data, $traf['total']);
|
||||
array_push($allow_data, $traf['allowed']);
|
||||
array_push($overuse_data, $traf['overuse']);
|
||||
$i++;
|
||||
//print_vars($data);
|
||||
}
|
||||
|
||||
if ($i < 12)
|
||||
{
|
||||
$y = 12 - $i;
|
||||
for ($x=0;$x<$y;$x++)
|
||||
{
|
||||
$allowed = (($x == "0") ? $traf['allowed'] : "0" );
|
||||
array_push($in_data, "0");
|
||||
array_push($out_data, "0");
|
||||
array_push($tot_data, "0");
|
||||
array_push($allow_data, $allowed);
|
||||
array_push($overuse_data, "0");
|
||||
array_push($ticklabels, "");
|
||||
}
|
||||
}
|
||||
$yaxistitle = "Gigabytes";
|
||||
$graph_name = "Historical bandwidth over the last 12 billing periods";
|
||||
if ($i < 12) {
|
||||
$y = 12 - $i;
|
||||
for ($x = 0; $x < $y; $x++) {
|
||||
$allowed = (($x == "0") ? $traf['allowed'] : "0");
|
||||
$in_data[] = "0";
|
||||
$out_data[] = "0";
|
||||
$tot_data[] = "0";
|
||||
$allow_data[] = $allowed;
|
||||
$overuse_data[] = "0";
|
||||
$ticklabels[] = "";
|
||||
}
|
||||
}
|
||||
$yaxistitle = "Gigabytes";
|
||||
$graph_name = "Historical bandwidth over the last 12 billing periods";
|
||||
} else {
|
||||
$data = array();
|
||||
$average = 0;
|
||||
if ($imgtype == "day")
|
||||
{
|
||||
foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data)
|
||||
{
|
||||
$traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0);
|
||||
$traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0);
|
||||
$traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0);
|
||||
$datelabel = strftime("%e\n%b", $data['timestamp']);
|
||||
array_push($ticklabels, $datelabel);
|
||||
array_push($in_data, $traf['in']);
|
||||
array_push($out_data, $traf['out']);
|
||||
array_push($tot_data, $traf['total']);
|
||||
$average += $data['traf_total'];
|
||||
}
|
||||
$ave_count = count($tot_data);
|
||||
if ($imgbill != false)
|
||||
{
|
||||
$days = strftime("%e", date($end - $start)) - $ave_count - 1;
|
||||
for ($x=0;$x<$days;$x++)
|
||||
{
|
||||
array_push($ticklabels, "");
|
||||
array_push($in_data, 0);
|
||||
array_push($out_data, 0);
|
||||
array_push($tot_data, 0);
|
||||
}
|
||||
}
|
||||
} elseif ($imgtype == "hour")
|
||||
{
|
||||
foreach (dbFetch("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC", array($bill_id, $start, $end)) as $data)
|
||||
{
|
||||
$traf['in'] = (isset($data['traf_in']) ? $data['traf_in'] : 0);
|
||||
$traf['out'] = (isset($data['traf_out']) ? $data['traf_out'] : 0);
|
||||
$traf['total'] = (isset($data['traf_total']) ? $data['traf_total'] : 0);
|
||||
$datelabel = strftime("%H:%M", $data['timestamp']);
|
||||
array_push($ticklabels, $datelabel);
|
||||
array_push($in_data, $traf['in']);
|
||||
array_push($out_data, $traf['out']);
|
||||
array_push($tot_data, $traf['total']);
|
||||
$average += $data['traf_total'];
|
||||
}
|
||||
$ave_count = count($tot_data);
|
||||
}
|
||||
$data = [];
|
||||
$average = 0;
|
||||
if ($imgtype === "day") {
|
||||
foreach (dbFetchRows("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC", [$bill_id, $start, $end]) as $data) {
|
||||
$traf['in'] = $data['traf_in'] ?? 0;
|
||||
$traf['out'] = $data['traf_out'] ?? 0;
|
||||
$traf['total'] = $data['traf_total'] ?? 0;
|
||||
$datelabel = strftime("%e\n%b", $data['timestamp']);
|
||||
|
||||
$decimal = 0;
|
||||
$average = $average / $ave_count;
|
||||
for ($x = 0; $x <= count($tot_data); $x++)
|
||||
{
|
||||
array_push($ave_data, $average);
|
||||
}
|
||||
$graph_name = date('M j g:ia', $start)." - ".date('M j g:ia', $end);
|
||||
$ticklabels[] = $datelabel;
|
||||
$in_data[] = $traf['in'];
|
||||
$out_data[] = $traf['out'];
|
||||
$tot_data[] = $traf['total'];
|
||||
$average += $data['traf_total'];
|
||||
}
|
||||
$ave_count = safe_count($tot_data);
|
||||
if ($imgbill) {
|
||||
$days = strftime("%e", date($end - $start)) - $ave_count - 1;
|
||||
for ($x = 0; $x < $days; $x++) {
|
||||
$ticklabels[] = "";
|
||||
$in_data[] = 0;
|
||||
$out_data[] = 0;
|
||||
$tot_data[] = 0;
|
||||
}
|
||||
}
|
||||
} elseif ($imgtype === "hour") {
|
||||
foreach (dbFetchRows("SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC", [$bill_id, $start, $end]) as $data) {
|
||||
$traf['in'] = $data['traf_in'] ?? 0;
|
||||
$traf['out'] = $data['traf_out'] ?? 0;
|
||||
$traf['total'] = $data['traf_total'] ?? 0;
|
||||
$datelabel = strftime("%H:%M", $data['timestamp']);
|
||||
|
||||
$ticklabels[] = $datelabel;
|
||||
$in_data[] = $traf['in'];
|
||||
$out_data[] = $traf['out'];
|
||||
$tot_data[] = $traf['total'];
|
||||
$average += $data['traf_total'];
|
||||
}
|
||||
$ave_count = safe_count($tot_data);
|
||||
}
|
||||
|
||||
$decimal = 0;
|
||||
$average = float_div($average, $ave_count);
|
||||
for ($x = 0, $x_max = safe_count($tot_data); $x <= $x_max; $x++) {
|
||||
$ave_data[] = $average;
|
||||
}
|
||||
$graph_name = date('M j g:ia', $start) . " - " . date('M j g:ia', $end);
|
||||
}
|
||||
|
||||
// Create the graph. These two calls are always required
|
||||
$graph = new Graph($xsize, $ysize, $graph_name);
|
||||
$graph->img->SetImgFormat("png");
|
||||
$graph -> img -> SetImgFormat("png");
|
||||
|
||||
#$graph->SetScale("textlin",0,0,$start,$end);
|
||||
|
||||
$graph->SetScale("textlin");
|
||||
$graph -> SetScale("textlin");
|
||||
#$graph->title->Set("$graph_name");
|
||||
$graph->title->SetFont(FF_FONT2, FS_BOLD, 10);
|
||||
$graph->SetMarginColor("white");
|
||||
$graph->SetFrame(false);
|
||||
$graph->SetMargin("75", "30", "30", "65");
|
||||
$graph->legend->SetFont(FF_FONT1, FS_NORMAL);
|
||||
$graph->legend->SetLayout(LEGEND_HOR);
|
||||
$graph->legend->Pos("0.52", "0.91", "center");
|
||||
$graph -> title -> SetFont(FF_FONT2, FS_BOLD, 10);
|
||||
$graph -> SetMarginColor("white");
|
||||
$graph -> SetFrame(FALSE);
|
||||
$graph -> SetMargin("75", "30", "30", "65");
|
||||
$graph -> legend -> SetFont(FF_FONT1, FS_NORMAL);
|
||||
$graph -> legend -> SetLayout(LEGEND_HOR);
|
||||
$graph -> legend -> Pos("0.52", "0.91", "center");
|
||||
|
||||
$graph->xaxis->SetFont(FF_FONT1, FS_BOLD);
|
||||
$graph->xaxis->SetPos('min');
|
||||
$graph->xaxis->SetTitleMargin(30);
|
||||
$graph->xaxis->SetTickLabels($ticklabels);
|
||||
$graph->xgrid->Show(true,true);
|
||||
$graph->xgrid->SetColor('#e0e0e0','#efefef');
|
||||
$graph -> xaxis -> SetFont(FF_FONT1, FS_BOLD);
|
||||
$graph -> xaxis -> SetPos('min');
|
||||
$graph -> xaxis -> SetTitleMargin(30);
|
||||
$graph -> xaxis -> SetTickLabels($ticklabels);
|
||||
$graph -> xgrid -> Show(TRUE, TRUE);
|
||||
$graph -> xgrid -> SetColor('#e0e0e0', '#efefef');
|
||||
|
||||
$graph->yaxis->SetFont(FF_FONT1);
|
||||
$graph->yaxis->SetTitleMargin(50);
|
||||
$graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10);
|
||||
$graph->yaxis->title->Set("Bytes Transferred");
|
||||
$graph->yaxis->SetLabelFormatCallback('format_bytes_billing');
|
||||
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#FFFFFF@0.5');
|
||||
$graph -> yaxis -> SetFont(FF_FONT1);
|
||||
$graph -> yaxis -> SetTitleMargin(50);
|
||||
$graph -> yaxis -> title -> SetFont(FF_FONT1, FS_NORMAL, 10);
|
||||
$graph -> yaxis -> title -> Set("Bytes Transferred");
|
||||
$graph -> yaxis -> SetLabelFormatCallback('format_bytes_billing');
|
||||
$graph -> ygrid -> SetFill(TRUE, '#EFEFEF@0.5', '#FFFFFF@0.5');
|
||||
|
||||
// Create the bar plots
|
||||
$barplot_tot = new BarPlot($tot_data);
|
||||
$barplot_tot->SetLegend("Traffic total");
|
||||
$barplot_tot->SetColor('darkgray');
|
||||
$barplot_tot->SetFillColor('lightgray@0.4');
|
||||
$barplot_tot->value->Show();
|
||||
$barplot_tot->value->SetFormatCallback('format_bytes_billing_short');
|
||||
$barplot_tot -> SetLegend("Traffic total");
|
||||
$barplot_tot -> SetColor('darkgray');
|
||||
$barplot_tot -> SetFillColor('lightgray@0.4');
|
||||
$barplot_tot -> value -> Show();
|
||||
$barplot_tot -> value -> SetFormatCallback('format_bytes_billing_short');
|
||||
|
||||
$barplot_in = new BarPlot($in_data);
|
||||
$barplot_in->SetLegend("Traffic In");
|
||||
$barplot_in->SetColor('#'.$config['graph_colours']['greens'][1]);
|
||||
$barplot_in->SetFillColor('#'.$config['graph_colours']['greens'][0]);
|
||||
$barplot_in->SetWeight(1);
|
||||
$barplot_in -> SetLegend("Traffic In");
|
||||
$barplot_in -> SetColor('#' . $config['graph_colours']['greens'][1]);
|
||||
$barplot_in -> SetFillColor('#' . $config['graph_colours']['greens'][0]);
|
||||
$barplot_in -> SetWeight(1);
|
||||
|
||||
$barplot_out = new BarPlot($out_data);
|
||||
$barplot_out->SetLegend("Traffic Out");
|
||||
$barplot_out->SetColor('#'.$config['graph_colours']['blues'][0]);
|
||||
$barplot_out->SetFillColor('#'.$config['graph_colours']['blues'][1]);
|
||||
$barplot_out->SetWeight(1);
|
||||
$barplot_out -> SetLegend("Traffic Out");
|
||||
$barplot_out -> SetColor('#' . $config['graph_colours']['blues'][0]);
|
||||
$barplot_out -> SetFillColor('#' . $config['graph_colours']['blues'][1]);
|
||||
$barplot_out -> SetWeight(1);
|
||||
|
||||
if ($imgtype == "historical")
|
||||
{
|
||||
$barplot_over = new BarPlot($overuse_data);
|
||||
$barplot_over->SetLegend("Traffic Overusage");
|
||||
$barplot_over->SetColor('darkred');
|
||||
$barplot_over->SetFillColor('lightred@0.4');
|
||||
$barplot_over->SetWeight(1);
|
||||
if ($imgtype === "historical") {
|
||||
$barplot_over = new BarPlot($overuse_data);
|
||||
$barplot_over -> SetLegend("Traffic Overusage");
|
||||
$barplot_over -> SetColor('darkred');
|
||||
$barplot_over -> SetFillColor('lightred@0.4');
|
||||
$barplot_over -> SetWeight(1);
|
||||
|
||||
$lineplot_allow = new LinePlot($allow_data);
|
||||
$lineplot_allow->SetLegend("Traffic Allowed");
|
||||
$lineplot_allow->SetColor('black');
|
||||
$lineplot_allow->SetWeight(1);
|
||||
$lineplot_allow = new LinePlot($allow_data);
|
||||
$lineplot_allow -> SetLegend("Traffic Allowed");
|
||||
$lineplot_allow -> SetColor('black');
|
||||
$lineplot_allow -> SetWeight(1);
|
||||
|
||||
$gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out, $barplot_over));
|
||||
$gbplot = new GroupBarPlot([$barplot_in, $barplot_tot, $barplot_out, $barplot_over]);
|
||||
} else {
|
||||
$lineplot_allow = new LinePlot($ave_data);
|
||||
//$lineplot_allow->SetLegend("Average per ".$imgtype);
|
||||
$lineplot_allow->SetLegend("Average");
|
||||
$lineplot_allow->SetColor('black');
|
||||
$lineplot_allow->SetWeight(1);
|
||||
$lineplot_allow = new LinePlot($ave_data);
|
||||
//$lineplot_allow->SetLegend("Average per ".$imgtype);
|
||||
$lineplot_allow -> SetLegend("Average");
|
||||
$lineplot_allow -> SetColor('black');
|
||||
$lineplot_allow -> SetWeight(1);
|
||||
|
||||
$gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out));
|
||||
$gbplot = new GroupBarPlot([$barplot_in, $barplot_tot, $barplot_out]);
|
||||
}
|
||||
|
||||
$graph->Add($gbplot);
|
||||
$graph->Add($lineplot_allow);
|
||||
$graph -> Add($gbplot);
|
||||
$graph -> Add($lineplot_allow);
|
||||
|
||||
// Display the graph
|
||||
$graph->Stroke();
|
||||
$graph -> Stroke();
|
||||
|
||||
// EOF
|
||||
|
30
html/css/bootstrap-toggle.min.css
vendored
@ -1,30 +0,0 @@
|
||||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
.checkbox label .toggle,.checkbox-inline .toggle{margin-left:-20px;margin-right:5px}
|
||||
.toggle{position:relative;overflow:hidden}
|
||||
.toggle input[type=checkbox]{display:none}
|
||||
.toggle-group{position:absolute;width:200%;top:0;bottom:0;left:0;transition:left .35s;-webkit-transition:left .35s;-moz-user-select:none;-webkit-user-select:none}
|
||||
.toggle.off .toggle-group{left:-100%}
|
||||
.toggle.inactive{opacity:.65;}
|
||||
.toggle.disabled .toggle-on, .toggle.disabled .toggle-off, .toggle.disabled .toggle-handle{cursor:not-allowed;}
|
||||
.toggle-on{position:absolute;top:0;bottom:0;left:0;right:50%;margin:0;border:0;border-radius:0}
|
||||
.toggle-off{position:absolute;top:0;bottom:0;left:50%;right:0;margin:0;border:0;border-radius:0}
|
||||
.toggle-handle{position:relative;vertical-align:baseline;margin:0 auto;padding-top:0;padding-bottom:0;height:100%;width:0;border-width:0 1px}
|
||||
.toggle.btn{min-width:46px;min-height:30px}
|
||||
.toggle-on.btn{padding-right:24px}
|
||||
.toggle-off.btn{padding-left:18px}
|
||||
.toggle.btn-lg{min-width:79px;min-height:40px}
|
||||
.toggle-on.btn-lg{padding-right:31px}
|
||||
.toggle-off.btn-lg{padding-left:27px}
|
||||
.toggle-handle.btn-lg{width:40px}
|
||||
.toggle.btn-sm{min-width:50px;min-height:26px}
|
||||
.toggle-on.btn-sm{padding-right:20px}
|
||||
.toggle-off.btn-sm{padding-left:14px}
|
||||
.toggle.btn-xs{min-width:35px;min-height:20px}
|
||||
.toggle-on.btn-xs{padding-right:12px}
|
||||
.toggle-off.btn-xs{padding-left:8px}
|
11743
html/css/bootstrap.css
vendored
168
html/css/bootstrap5-toggle.css
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
/* Copyright Notice
|
||||
* bootstrap5-toggle v3.7.4
|
||||
* https://palcarazm.github.io/bootstrap5-toggle/
|
||||
* @author 2011-2014 Min Hur (https://github.com/minhur)
|
||||
* @author 2018-2019 Brent Ely (https://github.com/gitbrent)
|
||||
* @author 2022 Pablo Alcaraz Martínez (https://github.com/palcarazm)
|
||||
* @funding GitHub Sponsors
|
||||
* @see https://github.com/sponsors/palcarazm
|
||||
* @license MIT
|
||||
* @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* @added 3.0.0: Return support for "*-xs" removed in Bootstrap-4
|
||||
* @see: [Comment](https://github.com/twbs/bootstrap/issues/21881#issuecomment-341972830)
|
||||
*/
|
||||
/*.btn-group-xs > .btn, .btn-xs {*/
|
||||
/* padding: .35rem .4rem .25rem .4rem;*/
|
||||
/* font-size: .875rem;*/
|
||||
/* line-height: .5;*/
|
||||
/* border-radius: .2rem;*/
|
||||
/*}*/
|
||||
|
||||
.checkbox label .toggle, .checkbox-inline .toggle {
|
||||
margin-left: -1.25rem;
|
||||
margin-right: .35rem;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.toggle:hover > .toggle-group > .toggle-handle,
|
||||
.toggle:focus > .toggle-group > .toggle-handle {
|
||||
background-color: var(--light);
|
||||
opacity: 0.5;
|
||||
}
|
||||
.toggle > input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
.toggle > .toggle-group {
|
||||
position: absolute;
|
||||
width: 200%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
transition: left 0.35s;
|
||||
-webkit-transition: left 0.35s;
|
||||
user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.toggle.btn:not(.disabled) { cursor: pointer; }
|
||||
.toggle.btn.disabled{ cursor:not-allowed; }
|
||||
.toggle >.toggle-group >.btn { cursor: inherit; }
|
||||
.toggle.off > .toggle-group {
|
||||
left: -100%;
|
||||
}
|
||||
.toggle.indeterminate > .toggle-group {
|
||||
left: -50%;
|
||||
}
|
||||
.toggle > .toggle-group > .toggle-on {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 50%;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle > .toggle-group > .toggle-off {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
box-shadow: none; /* Bootstrap 4.0 Support via (Issue #186)[https://github.com/minhur/bootstrap-toggle/issues/186]) */
|
||||
}
|
||||
.toggle > .toggle-group > .toggle-handle {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
border-width: 0 1px;
|
||||
background-color: var(--light);
|
||||
border-color: var(--light);
|
||||
}
|
||||
|
||||
/** Support for input-group
|
||||
* @author (bryan-brancotte)[https://github.com/bryan-brancotte]
|
||||
* @see https://github.com/gitbrent/bootstrap4-toggle/issues/32#issuecomment-616974580
|
||||
*/
|
||||
.input-group .toggle > .toggle-group > .toggle-on,
|
||||
.input-group .toggle > .toggle-group > .toggle-off{
|
||||
position: absolute;
|
||||
}
|
||||
.input-group:not(.has-validation)>:not(:last-child).toggle,
|
||||
.input-group.has-validation>:nth-last-child(n+3).toggle{
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
.input-group>:not(:first-child).toggle{
|
||||
margin-left: -1px;
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
|
||||
.toggle:not(:hover):not(:focus).btn-outline-primary > .toggle-group > .toggle-handle {
|
||||
background-color: var(--primary);
|
||||
border-color: var(--primary);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-secondary > .toggle-group > .toggle-handle {
|
||||
background-color: var(--secondary);
|
||||
border-color: var(--secondary);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-success > .toggle-group > .toggle-handle {
|
||||
background-color: var(--success);
|
||||
border-color: var(--success);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-danger > .toggle-group > .toggle-handle {
|
||||
background-color: var(--danger);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-warning > .toggle-group > .toggle-handle {
|
||||
background-color: var(--warning);
|
||||
border-color: var(--warning);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-info > .toggle-group > .toggle-handle {
|
||||
background-color: var(--info);
|
||||
border-color: var(--info);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-light > .toggle-group > .toggle-handle {
|
||||
background-color: var(--light);
|
||||
border-color: var(--light);
|
||||
}
|
||||
.toggle:not(:hover):not(:focus).btn-outline-dark > .toggle-group > .toggle-handle {
|
||||
background-color: var(--dark);
|
||||
border-color: var(--dark);
|
||||
}
|
||||
|
||||
/* NOTE: Must come first, so classes below override as needed */
|
||||
/* [default] (bootstrap-4.1.3 - .btn - h:38px) */
|
||||
.toggle.btn { min-width: 3.7rem; min-height: 2.15rem; }
|
||||
.toggle > .toggle-group > .toggle-on.btn { padding-right: 1.5rem; }
|
||||
.toggle > .toggle-group > .toggle-off.btn { padding-left: 1.5rem; }
|
||||
|
||||
/* `lg` (bootstrap-4.1.3 - .btn - h:48px) */
|
||||
.toggle.btn-lg { min-width: 5rem; min-height: 2.815rem; }
|
||||
.toggle > .toggle-group > .toggle-on.btn-lg { padding-right: 2rem; }
|
||||
.toggle > .toggle-group > .toggle-off.btn-lg { padding-left: 2rem; }
|
||||
.toggle > .toggle-group > .toggle-handle.btn-lg { width: 2.5rem; }
|
||||
|
||||
/* `sm` (bootstrap-4.1.3 - .btn - h:31px) */
|
||||
.toggle.btn-sm { min-width: 3.125rem; min-height: 1.938rem; }
|
||||
.toggle > .toggle-group > .toggle-on.btn-sm { padding-right: 1rem; }
|
||||
.toggle > .toggle-group > .toggle-off.btn-sm { padding-left: 1rem; }
|
||||
|
||||
/* `xs` (bootstrap-3.3 - .btn - h:22px) */
|
||||
.toggle.btn-xs { min-width: 2.19rem; min-height: 1.375rem; }
|
||||
.toggle > .toggle-group > .toggle-on.btn-xs { padding-right: .8rem; }
|
||||
.toggle > .toggle-group > .toggle-off.btn-xs { padding-left: .8rem; }
|
14
html/css/bootstrap5-toggle.min.css
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/* Copyright Notice
|
||||
* bootstrap5-toggle v3.7.4
|
||||
* https://palcarazm.github.io/bootstrap5-toggle/
|
||||
* @author 2011-2014 Min Hur (https://github.com/minhur)
|
||||
* @author 2018-2019 Brent Ely (https://github.com/gitbrent)
|
||||
* @author 2022 Pablo Alcaraz Martínez (https://github.com/palcarazm)
|
||||
* @funding GitHub Sponsors
|
||||
* @see https://github.com/sponsors/palcarazm
|
||||
* @license MIT
|
||||
* @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
.checkbox label .toggle,.checkbox-inline .toggle{margin-left:-1.25rem;margin-right:.35rem}.toggle{position:relative;overflow:hidden}.toggle:focus>.toggle-group>.toggle-handle,.toggle:hover>.toggle-group>.toggle-handle{background-color:var(--light);opacity:.5}.toggle>input[type=checkbox]{display:none}.toggle>.toggle-group{position:absolute;width:200%;top:0;bottom:0;left:0;transition:left .35s;-webkit-transition:left .35s;user-select:none;-moz-user-select:none;-webkit-user-select:none}.toggle.btn:not(.disabled){cursor:pointer}.toggle.btn.disabled{cursor:not-allowed}.toggle>.toggle-group>.btn{cursor:inherit}.toggle.off>.toggle-group{left:-100%}.toggle.indeterminate>.toggle-group{left:-50%}.toggle>.toggle-group>.toggle-on{position:absolute;top:0;bottom:0;left:0;right:50%;margin:0;border:0;border-radius:0}.toggle>.toggle-group>.toggle-off{position:absolute;top:0;bottom:0;left:50%;right:0;margin:0;border:0;border-radius:0;box-shadow:none}.toggle>.toggle-group>.toggle-handle{position:relative;margin:0 auto;padding-top:0;padding-bottom:0;height:100%;width:0;border-width:0 1px;background-color:var(--light);border-color:var(--light)}.input-group .toggle>.toggle-group>.toggle-off,.input-group .toggle>.toggle-group>.toggle-on{position:absolute}.input-group.has-validation>:nth-last-child(n+3).toggle,.input-group:not(.has-validation)>:not(:last-child).toggle{border-top-right-radius:0;border-bottom-right-radius:0}.input-group>:not(:first-child).toggle{margin-left:-1px;border-top-left-radius:0;border-bottom-left-radius:0}.toggle:not(:hover):not(:focus).btn-outline-primary>.toggle-group>.toggle-handle{background-color:var(--primary);border-color:var(--primary)}.toggle:not(:hover):not(:focus).btn-outline-secondary>.toggle-group>.toggle-handle{background-color:var(--secondary);border-color:var(--secondary)}.toggle:not(:hover):not(:focus).btn-outline-success>.toggle-group>.toggle-handle{background-color:var(--success);border-color:var(--success)}.toggle:not(:hover):not(:focus).btn-outline-danger>.toggle-group>.toggle-handle{background-color:var(--danger);border-color:var(--danger)}.toggle:not(:hover):not(:focus).btn-outline-warning>.toggle-group>.toggle-handle{background-color:var(--warning);border-color:var(--warning)}.toggle:not(:hover):not(:focus).btn-outline-info>.toggle-group>.toggle-handle{background-color:var(--info);border-color:var(--info)}.toggle:not(:hover):not(:focus).btn-outline-light>.toggle-group>.toggle-handle{background-color:var(--light);border-color:var(--light)}.toggle:not(:hover):not(:focus).btn-outline-dark>.toggle-group>.toggle-handle{background-color:var(--dark);border-color:var(--dark)}.toggle.btn{min-width:3.7rem;min-height:2.15rem}.toggle>.toggle-group>.toggle-on.btn{padding-right:1.5rem}.toggle>.toggle-group>.toggle-off.btn{padding-left:1.5rem}.toggle.btn-lg{min-width:5rem;min-height:2.815rem}.toggle>.toggle-group>.toggle-on.btn-lg{padding-right:2rem}.toggle>.toggle-group>.toggle-off.btn-lg{padding-left:2rem}.toggle>.toggle-group>.toggle-handle.btn-lg{width:2.5rem}.toggle.btn-sm{min-width:3.125rem;min-height:1.938rem}.toggle>.toggle-group>.toggle-on.btn-sm{padding-right:1rem}.toggle>.toggle-group>.toggle-off.btn-sm{padding-left:1rem}.toggle.btn-xs{min-width:2.19rem;min-height:1.375rem}.toggle>.toggle-group>.toggle-on.btn-xs{padding-right:.8rem}.toggle>.toggle-group>.toggle-off.btn-xs{padding-left:.8rem}
|
||||
/*# sourceMappingURL=bootstrap5-toggle.min.css.map */
|
2
html/css/easymde.min.css
vendored
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* easymde v2.17.0
|
||||
* easymde v2.18.0
|
||||
* Copyright Jeroen Akkerman
|
||||
* @link https://github.com/ionaru/easy-markdown-editor
|
||||
* @license MIT
|
||||
|
@ -67,6 +67,36 @@
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
:root {
|
||||
--blue: #2196F3;
|
||||
--indigo: #3F51B5;
|
||||
--purple: #9C27B0;
|
||||
--pink: #E91E63;
|
||||
--red: #b71c1c;
|
||||
--orange: #FF9800;
|
||||
--yellow: #FFEB3B;
|
||||
--green: #4CAF50;
|
||||
--teal: #20c997;
|
||||
--cyan: #17a2b8;
|
||||
--white: #fff;
|
||||
--gray: #555555;
|
||||
--gray-dark: #333333;
|
||||
--primary: #116894;
|
||||
--secondary: #6c757d;
|
||||
--success: #4d9221;
|
||||
--info: #4bb1cf;
|
||||
--warning: #f0ad4e;
|
||||
--danger: #b71c1c;
|
||||
--light: #F5F7FA;
|
||||
--dark: #434A54;
|
||||
--breakpoint-xs: 0;
|
||||
--breakpoint-sm: 576px;
|
||||
--breakpoint-md: 768px;
|
||||
--breakpoint-lg: 992px;
|
||||
--breakpoint-xl: 1200px;
|
||||
--font-family-sans-serif: 'Source Sans 3', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
--font-family-monospace: Monaco, Menlo, Consolas, "Courier New", monospace;
|
||||
}
|
||||
article,
|
||||
aside,
|
||||
details,
|
||||
@ -2044,7 +2074,7 @@ pre code {
|
||||
}
|
||||
.pre-scrollable {
|
||||
max-height: 340px;
|
||||
overflow-y: scroll;
|
||||
overflow-y: auto;
|
||||
}
|
||||
form {
|
||||
margin: 0 0 10px;
|
||||
@ -6025,6 +6055,8 @@ a .icon-flip-vertical:before {
|
||||
-webkit-background-clip: padding-box;
|
||||
-moz-background-clip: padding;
|
||||
background-clip: padding-box;
|
||||
/*scrollbar-width: thin;
|
||||
scrollbar-color: rgba(128, 128, 128, 0.2) @brand-border;*/
|
||||
}
|
||||
.dropdown-menu.pull-right {
|
||||
right: 0;
|
||||
@ -6045,16 +6077,22 @@ a .icon-flip-vertical:before {
|
||||
color: #333333;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.dropdown-menu ::-webkit-scrollbar {
|
||||
.dropdown-menu::-webkit-scrollbar-track {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.dropdown-menu::-webkit-scrollbar-corner {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.dropdown-menu::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
/* background-color: @box-header-bg; */
|
||||
}
|
||||
.dropdown-menu ::-webkit-scrollbar-track {
|
||||
-webkit-box-shadow: inset 0 0 65px rgba(0, 0, 0, 0.3);
|
||||
.dropdown-menu::-webkit-scrollbar-thumb {
|
||||
border-radius: 2px;
|
||||
}
|
||||
.dropdown-menu ::-webkit-scrollbar-thumb {
|
||||
border-radius: 2px;
|
||||
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.6);
|
||||
background-color: #dddddd;
|
||||
border: 2px solid #f9f9f9;
|
||||
/*border: 2px solid @box-header-bg;*/
|
||||
}
|
||||
/*
|
||||
.navbar-narrow .dropdown-menu {
|
||||
@ -6831,10 +6869,7 @@ i.menu-icon,
|
||||
box-shadow: none;
|
||||
}
|
||||
.box-body {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 3px;
|
||||
border-bottom-left-radius: 3px;
|
||||
border-radius: 0 0 3px 3px;
|
||||
padding: 10px;
|
||||
}
|
||||
.no-header .box-body {
|
||||
@ -6858,22 +6893,13 @@ i.menu-icon,
|
||||
margin: -9px;
|
||||
}
|
||||
.box-body .box-pane {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
border-bottom-left-radius: 3px;
|
||||
border-radius: 0 0 0 3px;
|
||||
}
|
||||
.box-body .box-pane-right {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 3px;
|
||||
border-bottom-left-radius: 0;
|
||||
border-radius: 0 0 3px 0;
|
||||
}
|
||||
.box-footer {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 3px;
|
||||
border-bottom-left-radius: 3px;
|
||||
border-radius: 0 0 3px 3px;
|
||||
border-top: 1px solid #f4f4f4;
|
||||
border-top: none;
|
||||
padding: 10px;
|
||||
@ -6890,17 +6916,41 @@ i.menu-icon,
|
||||
}
|
||||
.login-box {
|
||||
padding: 50px;
|
||||
background: url('../images/brand-observium.png');
|
||||
background: url('../images/brand-observium.svg');
|
||||
background-size: 162px 34px;
|
||||
background-position: right 10px bottom 10px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( min-device-pixel-ratio: 2), only screen and ( min-resolution: 144dpi), only screen and ( min-resolution: 2dppx) {
|
||||
.login-box {
|
||||
background: url('../images/brand-observium-x2.png');
|
||||
background-size: 162px 30px;
|
||||
background-position: right 10px bottom 10px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
.shadow-box {
|
||||
position: relative;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
width: 100%;
|
||||
box-shadow: 0 0 2px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.24);
|
||||
}
|
||||
.box-content {
|
||||
/*scrollbar-width: thin;
|
||||
scrollbar-color: rgba(128, 128, 128, 0.2) @brand-border;*/
|
||||
}
|
||||
.box-content::-webkit-scrollbar-track {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.box-content::-webkit-scrollbar-corner {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.box-content::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
/* background-color: @box-header-bg; */
|
||||
}
|
||||
.box-content::-webkit-scrollbar-thumb {
|
||||
border-radius: 2px;
|
||||
background-color: #dddddd;
|
||||
border: 2px solid #f9f9f9;
|
||||
/*border: 2px solid @box-header-bg;*/
|
||||
}
|
||||
.fade {
|
||||
opacity: 0;
|
||||
@ -8565,7 +8615,8 @@ input[type="button"].btn-block {
|
||||
text-decoration: none;
|
||||
}
|
||||
.navbar .brand-observium {
|
||||
background: url('../images/brand-observium.png');
|
||||
background: url('../images/brand-observium.svg');
|
||||
background-size: 162px 30px;
|
||||
display: inline-block;
|
||||
width: 162px;
|
||||
height: 30px;
|
||||
@ -8574,12 +8625,6 @@ input[type="button"].btn-block {
|
||||
margin: 5px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( min-device-pixel-ratio: 2), only screen and ( min-resolution: 144dpi), only screen and ( min-resolution: 2dppx) {
|
||||
.navbar .brand-observium {
|
||||
background: url('../images/brand-observium-x2.png');
|
||||
background-size: 162px 30px;
|
||||
}
|
||||
}
|
||||
.navbar-text {
|
||||
margin-bottom: 0;
|
||||
line-height: 40px;
|
||||
@ -9581,7 +9626,7 @@ a.thumbnail:focus {
|
||||
}
|
||||
.label {
|
||||
display: inline;
|
||||
padding: 0.1em 0.5em 0.2em;
|
||||
padding: 0.1em 0.5em 0.1em;
|
||||
font-size: 80%;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
@ -10635,20 +10680,6 @@ x:-o-prefocus,
|
||||
.grid-stack > .grid-stack-item > .grid-stack-item-content {
|
||||
z-index: unset!important;
|
||||
}
|
||||
.box-content::-webkit-scrollbar-track {
|
||||
background-color: #dddddd;
|
||||
}
|
||||
.box-content::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background-color: #fafafa;
|
||||
}
|
||||
.box-content::-webkit-scrollbar-thumb {
|
||||
border-radius: 10px;
|
||||
background-color: #333333;
|
||||
background-color: rgba(128, 128, 128, 0.2);
|
||||
border: 2px solid #fafafa;
|
||||
}
|
||||
.widget-title {
|
||||
top: 3px;
|
||||
left: 4px;
|
||||
@ -10948,7 +10979,7 @@ select.selectpicker {
|
||||
.bootstrap-select .dropdown-menu > .inner:focus {
|
||||
outline: none !important;
|
||||
}
|
||||
.bootstrap-select .dropdown-menu.inner {
|
||||
.bootstrap-select .dropdown-menu .inner {
|
||||
position: static;
|
||||
float: none;
|
||||
border: 0;
|
||||
@ -10957,6 +10988,25 @@ select.selectpicker {
|
||||
border-radius: 0;
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
/*scrollbar-width: thin;
|
||||
scrollbar-color: rgba(128, 128, 128, 0.2) @brand-border;*/
|
||||
}
|
||||
.bootstrap-select .dropdown-menu .inner::-webkit-scrollbar-track {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.bootstrap-select .dropdown-menu .inner::-webkit-scrollbar-corner {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
.bootstrap-select .dropdown-menu .inner::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
/* background-color: @box-header-bg; */
|
||||
}
|
||||
.bootstrap-select .dropdown-menu .inner::-webkit-scrollbar-thumb {
|
||||
border-radius: 2px;
|
||||
background-color: #dddddd;
|
||||
border: 2px solid #f9f9f9;
|
||||
/*border: 2px solid @box-header-bg;*/
|
||||
}
|
||||
.bootstrap-select .dropdown-menu li {
|
||||
position: relative;
|
||||
@ -11801,6 +11851,10 @@ svg.leaflet-image-layer.leaflet-interactive path {
|
||||
.bootstrap-select ul.inner > li.divider {
|
||||
margin: 2px 1px;
|
||||
}
|
||||
/* funny label background */
|
||||
.label-rainbow {
|
||||
background-image: linear-gradient(to right, gray, red, orange, yellow, green, blue, indigo, violet);
|
||||
}
|
||||
/* Remove hover line under links */
|
||||
a [class^="icon-"],
|
||||
a [class*=" icon-"] {
|
||||
@ -11833,6 +11887,12 @@ a [class*=" icon-"] {
|
||||
justify-content: center;
|
||||
/* Optional, to align inner flex-items horizontally within the column */
|
||||
}
|
||||
.confirmation-buttons > .btn-group {
|
||||
display: flex;
|
||||
/* Do not wrap confirmation buttons */
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.editing-only {
|
||||
display: none;
|
||||
}
|
||||
@ -12026,15 +12086,6 @@ form > button.btn-icon {
|
||||
margin-right: 5px;
|
||||
margin-top: 1px;
|
||||
}
|
||||
[class^="sprite-"],
|
||||
[class*=" sprite-"] {
|
||||
display: inline-block;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
margin-top: 2px;
|
||||
margin-right: 0.4em;
|
||||
vertical-align: text-top;
|
||||
}
|
||||
h3 > [class*=" sprite-"],
|
||||
h3 > [class^="sprite-"] {
|
||||
margin-top: 3px;
|
||||
|
1186
html/css/svg-sprite.css
Normal file
1
html/css/svg-sprite.svg
Normal file
After Width: | Height: | Size: 339 KiB |
484
html/data-pick.php
Executable file
@ -0,0 +1,484 @@
|
||||
<?php
|
||||
|
||||
// ******************************************
|
||||
// sensible defaults
|
||||
$mapdir = 'configs';
|
||||
$observium_base = '../../';
|
||||
$observium_url = '/';
|
||||
$ignore_observium = FALSE;
|
||||
$config['base_url'] = $observium_url;
|
||||
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
// Don't run if weathermap isn't enabled
|
||||
if (!$config['weathermap']['enable'] || $_SESSION['userlevel'] < 7) {
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
$config['base_url'] = $config['url_path'] ?? $observium_url;
|
||||
$observium_found = TRUE;
|
||||
|
||||
|
||||
// ******************************************
|
||||
|
||||
function js_escape($str) {
|
||||
|
||||
$str = str_replace([ '\\', "'" ], [ '\\\\', "\\\'" ], $str);
|
||||
|
||||
return ("'" . $str . "'");
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['command']) && $_REQUEST["command"] == 'link_step2') {
|
||||
$dataid = (int)$_REQUEST['dataid'];
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
function update_source_step2(graphid) {
|
||||
var graph_url, hover_url;
|
||||
|
||||
var base_url = '<?php echo isset($config['base_url']) ? $config['base_url'] : ''; ?>';
|
||||
|
||||
if (typeof window.opener == "object") {
|
||||
|
||||
graph_url = base_url + 'graph.php?height=100&width=512&device=' + graphid + '&type=device_bits&legend=no';
|
||||
info_url = base_url + 'device/device=' + graphid + '/';
|
||||
|
||||
opener.document.forms["frmMain"].node_new_name.value = 'test';
|
||||
opener.document.forms["frmMain"].node_label.value = 'testing';
|
||||
opener.document.forms["frmMain"].link_infourl.value = info_url;
|
||||
opener.document.forms["frmMain"].link_hover.value = graph_url;
|
||||
}
|
||||
self.close();
|
||||
}
|
||||
|
||||
window.onload = update_source_step2(<?php echo $graphid; ?>);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
This window should disappear in a moment.
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
// end of link step 2
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['command']) && $_REQUEST["command"] == 'link_step1') {
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function filterlist(previous) {
|
||||
var filterstring = $('input#filterstring').val();
|
||||
|
||||
if (filterstring == '') {
|
||||
$('ul#dslist > li').show();
|
||||
if ($('#ignore_desc').is(':checked')) {
|
||||
$("ul#dslist > li:contains('Desc::')").hide();
|
||||
}
|
||||
|
||||
|
||||
} else if (filterstring != previous) {
|
||||
$('ul#dslist > li').hide();
|
||||
$("ul#dslist > li:contains('" + filterstring + "')").show();
|
||||
if ($('#ignore_desc').is(':checked')) {
|
||||
$("ul#dslist > li:contains('Desc::')").hide();
|
||||
}
|
||||
|
||||
} else if (filterstring == previous) {
|
||||
if ($('#ignore_desc').is(':checked')) {
|
||||
$("ul#dslist > li:contains('Desc::')").hide();
|
||||
} else {
|
||||
$('ul#dslist > li').hide();
|
||||
$("ul#dslist > li:contains('" + filterstring + "')").show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function filterignore() {
|
||||
if ($('#ignore_desc').is(':checked')) {
|
||||
$("ul#dslist > li:contains('Desc::')").hide();
|
||||
} else {
|
||||
//$('ul#dslist > li').hide();
|
||||
$("ul#dslist > li:contains('" + previous + "')").show();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('span.filter').keyup(function () {
|
||||
var previous = $('input#filterstring').val();
|
||||
setTimeout(function () {
|
||||
filterlist(previous)
|
||||
}, 500);
|
||||
}).show();
|
||||
$('span.ignore').click(function () {
|
||||
var previous = $('input#filterstring').val();
|
||||
setTimeout(function () {
|
||||
filterlist(previous)
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
function update_source_step2(graphid, name, portid, ifAlias, ifDesc, ifIndex) {
|
||||
var graph_url, hover_url;
|
||||
|
||||
var base_url = '<?php echo isset($config['base_url']) ? $config['base_url'] : ''; ?>';
|
||||
|
||||
if (typeof window.opener == "object") {
|
||||
|
||||
graph_url = base_url + 'graph.php?height=100&width=512&id=' + portid + '&type=port_bits&legend=no';
|
||||
info_url = base_url + 'graphs/type=port_bits/id=' + portid + '/';
|
||||
|
||||
opener.document.forms["frmMain"].node_new_name.value = 'test';
|
||||
opener.document.forms["frmMain"].node_label.value = 'testing';
|
||||
opener.document.forms["frmMain"].link_infourl.value = info_url;
|
||||
opener.document.forms["frmMain"].link_hover.value = graph_url;
|
||||
}
|
||||
self.close();
|
||||
}
|
||||
|
||||
function update_source_step1(dataid, name, portid, ifAlias, ifDesc, ifIndex) {
|
||||
// This must be the section that looks after link properties
|
||||
var newlocation;
|
||||
var fullpath;
|
||||
|
||||
var rra_path = <?php echo js_escape($config['install_dir'] . '/rrd/'); ?>+name + '/port-';
|
||||
|
||||
if (typeof window.opener == "object") {
|
||||
//fullpath = rra_path + ifIndex + '.rrd:INOCTETS:OUTOCTETS';
|
||||
fullpath = 'obs_port:'+portid;
|
||||
//if (document.forms['mini'].aggregate.checked) {
|
||||
// opener.document.forms["frmMain"].link_target.value = opener.document.forms["frmMain"].link_target.value + " " + fullpath;
|
||||
//} else {
|
||||
opener.document.forms["frmMain"].link_target.value = fullpath;
|
||||
//}
|
||||
}
|
||||
if (document.forms['mini'].overlib.checked) {
|
||||
|
||||
window.onload = update_source_step2(dataid, name, portid, ifAlias, ifDesc, ifIndex);
|
||||
|
||||
} else {
|
||||
self.close();
|
||||
}
|
||||
}
|
||||
|
||||
function applyDSFilterChange(objForm) {
|
||||
strURL = '?host_id=' + objForm.host_id.value;
|
||||
strURL = strURL + '&command=link_step1';
|
||||
if (objForm.overlib.checked) {
|
||||
strURL = strURL + "&overlib=1";
|
||||
} else {
|
||||
strURL = strURL + "&overlib=0";
|
||||
}
|
||||
// document.frmMain.link_bandwidth_out_cb.checked
|
||||
if (objForm.aggregate.checked) {
|
||||
strURL = strURL + "&aggregate=1";
|
||||
} else {
|
||||
strURL = strURL + "&aggregate=0";
|
||||
}
|
||||
document.location = strURL;
|
||||
}
|
||||
|
||||
</script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
ul li.row0 {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
ul li.row1 {
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
ul li {
|
||||
border-bottom: 1px solid #aaa;
|
||||
border-top: 1px solid #eee;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
ul li a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
<title>Pick a data source</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
|
||||
$host_id = -1;
|
||||
$overlib = TRUE;
|
||||
$aggregate = FALSE;
|
||||
|
||||
if (isset($_REQUEST['aggregate'])) {
|
||||
$aggregate = ($_REQUEST['aggregate'] == 0 ? FALSE : TRUE);
|
||||
}
|
||||
if (isset($_REQUEST['overlib'])) {
|
||||
$overlib = ($_REQUEST['overlib'] == 0 ? FALSE : TRUE);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['host_id'])) {
|
||||
$host_id = (int)$_REQUEST['host_id'];
|
||||
}
|
||||
|
||||
$hosts = dbFetchRows("SELECT `device_id`,`hostname` FROM `devices` ORDER BY `hostname`");
|
||||
|
||||
?>
|
||||
|
||||
<h3>Pick an Observium port:</h3>
|
||||
|
||||
<form name="mini">
|
||||
<?php
|
||||
if (!safe_empty($hosts)) {
|
||||
print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
|
||||
|
||||
print '<option ' . ($host_id == -1 ? 'SELECTED' : '') . ' value="-1">Any</option>';
|
||||
print '<option ' . ($host_id == 0 ? 'SELECTED' : '') . ' value="0">None</option>';
|
||||
foreach ($hosts as $host) {
|
||||
print '<option ';
|
||||
if ($host_id == $host['device_id']) {
|
||||
print " SELECTED ";
|
||||
}
|
||||
print 'value="' . $host['device_id'] . '">' . $host['hostname'] . '</option>';
|
||||
}
|
||||
print '</select><br />';
|
||||
}
|
||||
|
||||
print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
|
||||
print '<input id="overlib" name="overlib" type="checkbox" value="yes" ' . ($overlib ? 'CHECKED' : '') . '> <label for="overlib">Also set OVERLIBGRAPH and INFOURL.</label><br />';
|
||||
print '<input id="aggregate" name="aggregate" type="checkbox" value="yes" ' . ($aggregate ? 'CHECKED' : '') . '> <label for="aggregate">Append TARGET to existing one (Aggregate)</label><br />';
|
||||
print '<span class="ignore"><input id="ignore_desc" name="ignore_desc" type="checkbox" value="yes"> <label for="ignore_desc">Ignore blank interface descriptions</label></span>';
|
||||
|
||||
print '</form><div class="listcontainer"><ul id="dslist">';
|
||||
|
||||
$query = "SELECT devices.device_id,hostname,ports.port_id,ports.ifAlias,ports.ifIndex,ports.ifDescr FROM devices LEFT JOIN ports ON devices.device_id=ports.device_id WHERE ports.disabled=0";
|
||||
|
||||
if ($host_id > 0) {
|
||||
$query .= " AND devices.device_id='$host_id'";
|
||||
}
|
||||
|
||||
$query .= " ORDER BY hostname,ports.ifAlias";
|
||||
|
||||
$ports = dbFetchRows($query);
|
||||
|
||||
|
||||
$i = 0;
|
||||
if (count($ports) > 0) {
|
||||
foreach ($ports as $port) {
|
||||
echo "<li class=\"row" . ($i % 2) . "\">";
|
||||
$key = $port['device_id'] . "','" . $port['hostname'] . "','" . $port['port_id'] . "','" . addslashes($port['ifAlias']) . "','" . addslashes($port['ifDescr']) . "','" . $port['ifIndex'];
|
||||
echo "<a href=\"#\" onclick=\"update_source_step1('$key')\">
|
||||
<span style='color:darkred'>" . $port['hostname'] . "</span> <b>|</b>
|
||||
<span style='color:darkblue'>" . $port['ifDescr'] . "</span> <b>|</b> " .
|
||||
$port['ifAlias'] . "</a>";
|
||||
echo "</li>\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
print "<li>No results...</li>";
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
} // end of link step 1
|
||||
|
||||
if (isset($_REQUEST['command']) && $_REQUEST["command"] == 'node_step1') {
|
||||
$host_id = -1;
|
||||
|
||||
$overlib = TRUE;
|
||||
$aggregate = FALSE;
|
||||
|
||||
if (isset($_REQUEST['aggregate'])) {
|
||||
$aggregate = ($_REQUEST['aggregate'] == 0 ? FALSE : TRUE);
|
||||
}
|
||||
if (isset($_REQUEST['overlib'])) {
|
||||
$overlib = ($_REQUEST['overlib'] == 0 ? FALSE : TRUE);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['host_id'])) {
|
||||
$host_id = (int)$_REQUEST['host_id'];
|
||||
}
|
||||
|
||||
$hosts = dbFetchRows("SELECT `device_id` AS `id`,`hostname` as `name` FROM `devices` ORDER BY `hostname`");
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="editor-resources/jquery-latest.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function filterlist(previous) {
|
||||
var filterstring = $('input#filterstring').val();
|
||||
|
||||
if (filterstring == '') {
|
||||
$('ul#dslist > li').show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (filterstring != previous) {
|
||||
$('ul#dslist > li').hide();
|
||||
$("ul#dslist > li:contains('" + filterstring + "')").show();
|
||||
//$('ul#dslist > li').contains(filterstring).show();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('span.filter').keyup(function () {
|
||||
var previous = $('input#filterstring').val();
|
||||
setTimeout(function () {
|
||||
filterlist(previous)
|
||||
}, 500);
|
||||
}).show();
|
||||
});
|
||||
|
||||
function applyDSFilterChange(objForm) {
|
||||
strURL = '?host_id=' + objForm.host_id.value;
|
||||
strURL = strURL + '&command=node_step1';
|
||||
if (objForm.overlib.checked) {
|
||||
strURL = strURL + "&overlib=1";
|
||||
} else {
|
||||
strURL = strURL + "&overlib=0";
|
||||
}
|
||||
|
||||
document.location = strURL;
|
||||
}
|
||||
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function update_source_step1(graphid, name) {
|
||||
// This is the section that sets the Node Properties
|
||||
var graph_url, hover_url;
|
||||
|
||||
var base_url = '<?php echo($config['base_url'] ?? ''); ?>';
|
||||
|
||||
if (typeof window.opener == "object") {
|
||||
|
||||
graph_url = base_url + 'graph.php?height=100&width=512&device=' + graphid + '&type=device_bits&legend=no';
|
||||
info_url = base_url + 'device/device=' + graphid + '/';
|
||||
|
||||
// only set the overlib URL unless the box is checked
|
||||
if (document.forms['mini'].overlib.checked) {
|
||||
opener.document.forms["frmMain"].node_infourl.value = info_url;
|
||||
}
|
||||
opener.document.forms["frmMain"].node_hover.value = graph_url;
|
||||
opener.document.forms["frmMain"].node_new_name.value = name;
|
||||
opener.document.forms["frmMain"].node_label.value = name;
|
||||
}
|
||||
self.close();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
ul li.row0 {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
ul li.row1 {
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
ul li {
|
||||
border-bottom: 1px solid #aaa;
|
||||
border-top: 1px solid #eee;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
ul li a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
<title>Pick a graph</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h3>Pick a graph:</h3>
|
||||
|
||||
<form name="mini">
|
||||
<?php
|
||||
if (!safe_empty($hosts)) {
|
||||
print 'Host: <select name="host_id" onChange="applyDSFilterChange(document.mini)">';
|
||||
|
||||
print '<option ' . ($host_id == -1 ? 'SELECTED' : '') . ' value="-1">Any</option>';
|
||||
print '<option ' . ($host_id == 0 ? 'SELECTED' : '') . ' value="0">None</option>';
|
||||
foreach ($hosts as $host) {
|
||||
print '<option ';
|
||||
if ($host_id == $host['id']) {
|
||||
print " SELECTED ";
|
||||
}
|
||||
print 'value="' . $host['id'] . '">' . $host['name'] . '</option>';
|
||||
}
|
||||
print '</select><br />';
|
||||
}
|
||||
|
||||
print '<span class="filter" style="display: none;">Filter: <input id="filterstring" name="filterstring" size="20"> (case-sensitive)<br /></span>';
|
||||
print '<input id="overlib" name="overlib" type="checkbox" value="yes" ' . ($overlib ? 'CHECKED' : '') . '> <label for="overlib">Set both OVERLIBGRAPH and INFOURL.</label><br />';
|
||||
|
||||
print '</form><div class="listcontainer"><ul id="dslist">';
|
||||
|
||||
if (!empty($SQL_picklist)) {
|
||||
foreach (dbFetchRows($SQL_picklist) as $queryrows) {
|
||||
echo "<li>";
|
||||
$key = $queryrows['id'];
|
||||
$name = $queryrows['name'];
|
||||
echo "<a href=\"#\" onclick=\"update_source_step1('$key','$name')\">" . $queryrows['name'] . "</a>";
|
||||
echo "</li>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
//..} else {
|
||||
// print "No results...";
|
||||
// }
|
||||
|
||||
?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
} // end of node step 1
|
||||
|
||||
// EOF
|
@ -6,32 +6,42 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
if (!$config['web_iframe'] && is_iframe()) {
|
||||
print_error_permission("Not allowed to run in a iframe!");
|
||||
die();
|
||||
}
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) {
|
||||
$port = get_port_by_id($_GET['id']);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
//$title = generate_device_link($device);
|
||||
//$title .= " :: Port ".generate_port_link($port);
|
||||
$auth = TRUE;
|
||||
$port = get_port_by_id($_GET['id']);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
//$title = generate_device_link($device);
|
||||
//$title .= " :: Port ".generate_port_link($port);
|
||||
$auth = TRUE;
|
||||
|
||||
$time = time();
|
||||
$HC = ($port['port_64bit'] ? 'HC' : '');
|
||||
if ($device['os'] === 'netapp' && is_device_mib($device, "NETAPP-MIB")) {
|
||||
$oid_in_octets = 'if64InOctets';
|
||||
$oid_out_octets = 'if64OutOctets';
|
||||
$mib = "NETAPP-MIB";
|
||||
} else {
|
||||
$oid_in_octets = $port['port_64bit'] ? 'ifHCInOctets' : 'ifInOctets';
|
||||
$oid_out_octets = $port['port_64bit'] ? 'ifHCOutOctets' : 'ifOutOctets';
|
||||
$mib = "IF-MIB";
|
||||
}
|
||||
|
||||
$data = snmp_get_multi_oid($device, "if{$HC}InOctets.".$port['ifIndex']." if{$HC}OutOctets.".$port['ifIndex'], [], "IF-MIB");
|
||||
$data = snmp_get_multi_oid($device, [ $oid_in_octets . '.' . $port['ifIndex'], $oid_out_octets . '.' . $port['ifIndex'] ], [], $mib);
|
||||
|
||||
printf("%lf|%s|%s\n", $time, $data[$port['ifIndex']]["if{$HC}InOctets"], $data[$port['ifIndex']]["if{$HC}OutOctets"]);
|
||||
printf("%lf|%s|%s\n", snmp_endtime(), $data[$port['ifIndex']][$oid_in_octets], $data[$port['ifIndex']][$oid_out_octets]);
|
||||
} else {
|
||||
echo("unauthenticated");
|
||||
exit;
|
||||
// not authenticated
|
||||
die("Unauthenticated");
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
18
html/error.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
//r(array_key_first($_GET));
|
||||
display_error_http(array_key_first($_GET));
|
||||
|
||||
// EOF
|
264
html/feed.php
@ -6,24 +6,16 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage feed
|
||||
* @author Mike Stupalov <mike@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
if (isset($_GET['debug']) && $_GET['debug'])
|
||||
{
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 0);
|
||||
ini_set('log_errors', 0);
|
||||
ini_set('allow_url_fopen', 0);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
}
|
||||
*/
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
if (is_iframe()) {
|
||||
display_error_http(403, 'Not allowed to run in a iframe');
|
||||
}
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
//include($config['html_dir'] . "/includes/authenticate.inc.php"); // not for RSS!
|
||||
|
||||
$auth = FALSE;
|
||||
@ -31,167 +23,141 @@ $vars = get_vars('GET');
|
||||
|
||||
// Auth
|
||||
if (isset($vars['hash']) && strlen($vars['hash']) >= 16 &&
|
||||
is_numeric($vars['id']) && $vars['id'] > 0)
|
||||
{
|
||||
$key = get_user_pref($vars['id'], 'atom_key');
|
||||
if ($key)
|
||||
{
|
||||
// Check hash auth
|
||||
if ($data = decrypt($vars['hash'], $key))
|
||||
{
|
||||
//var_dump($data);
|
||||
$data = explode('|', $data); // user_id|user_level|auth_mechanism
|
||||
is_numeric($vars['id']) && $vars['id'] > 0) {
|
||||
$key = get_user_pref($vars['id'], 'atom_key');
|
||||
if ($key) {
|
||||
// Check hash auth
|
||||
if ($data = decrypt($vars['hash'], $key)) {
|
||||
//var_dump($data);
|
||||
$data = explode('|', $data); // user_id|user_level|auth_mechanism
|
||||
|
||||
$data_c = count($data);
|
||||
if ($data_c == 3)
|
||||
{
|
||||
$user_id = $data[0];
|
||||
$user_level = $data[1]; // FIXME, need new way for check userlevel, because it can be changed
|
||||
$check_auth_mechanism = $config['auth_mechanism'] == $data[2];
|
||||
$data_c = count($data);
|
||||
if ($data_c == 3) {
|
||||
$user_id = $data[0];
|
||||
$user_level = $data[1]; // FIXME, need new way for check userlevel, because it can be changed
|
||||
$check_auth_mechanism = $config['auth_mechanism'] == $data[2];
|
||||
|
||||
// Now set auth
|
||||
$auth = $check_auth_mechanism && $user_level > 0 && $user_id == $vars['id'];
|
||||
}
|
||||
//else if ($data_c == 2)
|
||||
//{
|
||||
// // Force delete old keys without auth_mechanism
|
||||
//}
|
||||
// Now set auth
|
||||
$auth = $check_auth_mechanism && $user_level > 0 && $user_id == $vars['id'];
|
||||
}
|
||||
//else if ($data_c == 2)
|
||||
//{
|
||||
// // Force delete old keys without auth_mechanism
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($auth);
|
||||
if (!$auth)
|
||||
{
|
||||
//header("HTTP/1.1 401 Unauthorized"); // This force basic auth form (login/password), which unsupported here
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
|
||||
if ($vars)
|
||||
{
|
||||
?>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Unauthorized</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
|
||||
<H1>Unauthorized</H1>
|
||||
<H2>Update feed url</H2>
|
||||
</BODY>
|
||||
</HTML>
|
||||
<?php
|
||||
}
|
||||
exit;
|
||||
if (!$auth) {
|
||||
display_error_http(401, 'Update feed url');
|
||||
}
|
||||
// End auth
|
||||
|
||||
session_start();
|
||||
$_SESSION['user_id'] = $user_id;
|
||||
$_SESSION['userlevel'] = $user_level;
|
||||
session_start();
|
||||
$_SESSION['user_id'] = $user_id;
|
||||
$_SESSION['userlevel'] = $user_level;
|
||||
|
||||
$permissions = permissions_cache($_SESSION['user_id']);
|
||||
session_commit();
|
||||
$permissions = permissions_cache($_SESSION['user_id']);
|
||||
session_write_close();
|
||||
|
||||
include($config['html_dir'] . "/includes/cache-data.inc.php"); // Need for check permissions
|
||||
include($config['html_dir'] . "/includes/cache-data.inc.php"); // Need for check permissions
|
||||
|
||||
$use_rss = ($vars['v'] == 'rss' ? TRUE : FALSE); // In most cases used ATOM feed
|
||||
$param = array('short' => TRUE, 'pagesize' => 25);
|
||||
if (is_numeric($vars['size']))
|
||||
{
|
||||
$param['pagesize'] = $vars['size'];
|
||||
}
|
||||
$use_rss = $vars['v'] === 'rss'; // In most cases used ATOM feed
|
||||
$param = ['short' => TRUE, 'pagesize' => 25];
|
||||
if (is_numeric($vars['size'])) {
|
||||
$param['pagesize'] = $vars['size'];
|
||||
}
|
||||
|
||||
// base feed info
|
||||
$base_url = rtrim($GLOBALS['config']['base_url'], '/');
|
||||
$feed_generator = OBSERVIUM_PRODUCT.' '.OBSERVIUM_VERSION;
|
||||
$feed_title = 'Observium ['.$_SERVER["SERVER_NAME"].'] :: Eventlog Feed';
|
||||
$feed_description = "Latest eventlogs from observium on $base_url";
|
||||
$feed_link = $base_url.'/eventlog/';
|
||||
// base feed info
|
||||
$base_url = rtrim($GLOBALS['config']['base_url'], '/');
|
||||
$feed_generator = OBSERVIUM_PRODUCT . ' ' . OBSERVIUM_VERSION;
|
||||
$feed_title = 'Observium [' . $_SERVER["SERVER_NAME"] . '] :: Eventlog Feed';
|
||||
$feed_description = "Latest eventlogs from observium on $base_url";
|
||||
$feed_link = $base_url . '/eventlog/';
|
||||
|
||||
$events = get_events_array($param);
|
||||
if ($use_rss)
|
||||
{
|
||||
// create rss
|
||||
// See format options here: http://validator.w3.org/feed/docs/rss2.html
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"></rss>');
|
||||
$xml->addChild('channel');
|
||||
$xml->channel->addChild('title', $feed_title);
|
||||
$xml->channel->addChild('description', $feed_description);
|
||||
$xml->channel->addChild('link', $feed_link);
|
||||
$xml->channel->addChild('language', 'en-us');
|
||||
$xml->channel->addChild('generator', $feed_generator);
|
||||
$xml->channel->addChild('pubDate', date(DATE_RSS, strtotime($events['updated'])));
|
||||
$xml->channel->addChild('ttl', '5'); // a number of minutes that indicates how long a channel can be cached before refreshing
|
||||
} else {
|
||||
// create atom
|
||||
// See format options here: http://validator.w3.org/feed/docs/atom.html
|
||||
$atom_ns = 'http://www.w3.org/2005/Atom';
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><feed xml:lang="en-US" xmlns="'.$atom_ns.'"></feed>');
|
||||
$xml->addChild('title', $feed_title);
|
||||
$xml->addChild('subtitle', $feed_description);
|
||||
$xml->addChild('id', $feed_link);
|
||||
$xml->addChild('icon', $base_url.'/'.$GLOBALS['config']['favicon']);
|
||||
$xml->addChild('link');
|
||||
$xml->link->addAttribute('href', $feed_link);
|
||||
$self_link = $xml->addChild('link', '', $atom_ns);
|
||||
$self_link->addAttribute('href', $base_url.$_SERVER['REQUEST_URI']);
|
||||
$self_link->addAttribute('rel', 'self');
|
||||
$self_link->addAttribute('type', 'application/atom+xml');
|
||||
$xml->addChild('generator', $feed_generator);
|
||||
$xml->addChild('updated', date(DATE_ATOM, strtotime($events['updated'])));
|
||||
}
|
||||
$events = get_events_array($param);
|
||||
if ($use_rss) {
|
||||
// create rss
|
||||
// See format options here: http://validator.w3.org/feed/docs/rss2.html
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"></rss>');
|
||||
$xml -> addChild('channel');
|
||||
$xml -> channel -> addChild('title', $feed_title);
|
||||
$xml -> channel -> addChild('description', $feed_description);
|
||||
$xml -> channel -> addChild('link', $feed_link);
|
||||
$xml -> channel -> addChild('language', 'en-us');
|
||||
$xml -> channel -> addChild('generator', $feed_generator);
|
||||
$xml -> channel -> addChild('pubDate', date(DATE_RSS, strtotime($events['updated'])));
|
||||
$xml -> channel -> addChild('ttl', '5'); // a number of minutes that indicates how long a channel can be cached before refreshing
|
||||
} else {
|
||||
// create atom
|
||||
// See format options here: http://validator.w3.org/feed/docs/atom.html
|
||||
$atom_ns = 'http://www.w3.org/2005/Atom';
|
||||
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><feed xml:lang="en-US" xmlns="' . $atom_ns . '"></feed>');
|
||||
$xml -> addChild('title', $feed_title);
|
||||
$xml -> addChild('subtitle', $feed_description);
|
||||
$xml -> addChild('id', $feed_link);
|
||||
$xml -> addChild('icon', $base_url . '/' . $GLOBALS['config']['favicon']);
|
||||
$xml -> addChild('link');
|
||||
$xml -> link -> addAttribute('href', $feed_link);
|
||||
$self_link = $xml -> addChild('link', '', $atom_ns);
|
||||
$self_link -> addAttribute('href', $base_url . $_SERVER['REQUEST_URI']);
|
||||
$self_link -> addAttribute('rel', 'self');
|
||||
$self_link -> addAttribute('type', 'application/atom+xml');
|
||||
$xml -> addChild('generator', $feed_generator);
|
||||
$xml -> addChild('updated', date(DATE_ATOM, strtotime($events['updated'])));
|
||||
}
|
||||
|
||||
foreach ($events['entries'] as $entry)
|
||||
{
|
||||
$entry_device = device_by_id_cache($entry['device_id']);
|
||||
$entry_vars = array('page' => 'device',
|
||||
'device' => $entry['device_id'],
|
||||
'tab' => 'logs',
|
||||
'section' => 'eventlog',
|
||||
'type' => $entry['type'],
|
||||
'timestamp_from' => $entry['timestamp'],
|
||||
'timestamp_to' => $entry['timestamp']);
|
||||
$entry_title = escape_html('['.$entry_device['hostname'].'] '.$entry['message']);
|
||||
$entry_description = escape_html('['.$entry_device['hostname']."]\n".strtoupper($entry['type']).': '.$entry['message']);
|
||||
$entry_link = $base_url.'/'.generate_device_url($entry_device, $entry_vars);
|
||||
$entry_id = $entry_link.'guid='.md5($entry['event_id']);
|
||||
foreach ($events['entries'] as $entry) {
|
||||
$entry_device = device_by_id_cache($entry['device_id']);
|
||||
$entry_vars = ['page' => 'device',
|
||||
'device' => $entry['device_id'],
|
||||
'tab' => 'logs',
|
||||
'section' => 'eventlog',
|
||||
'type' => $entry['type'],
|
||||
'timestamp_from' => $entry['timestamp'],
|
||||
'timestamp_to' => $entry['timestamp']];
|
||||
$entry_title = escape_html('[' . $entry_device['hostname'] . '] ' . $entry['message']);
|
||||
$entry_description = escape_html('[' . $entry_device['hostname'] . "]\n" . strtoupper($entry['type']) . ': ' . $entry['message']);
|
||||
$entry_link = $base_url . '/' . generate_device_url($entry_device, $entry_vars);
|
||||
$entry_id = $entry_link . 'guid=' . md5($entry['event_id']);
|
||||
|
||||
if ($use_rss)
|
||||
{
|
||||
if ($use_rss) {
|
||||
// add item element for each article
|
||||
$item = $xml->channel->addChild('item');
|
||||
$item->addChild('title', $entry_title);
|
||||
$item->addChild('description', $entry_description);
|
||||
$item->addChild('guid', $entry_id);
|
||||
$item->addChild('link', $entry_link);
|
||||
$item->addChild('h:dc:creator', $entry['type']);
|
||||
$item->addChild('pubDate', date(DATE_RSS, strtotime($entry['timestamp'])));
|
||||
} else {
|
||||
$item = $xml -> channel -> addChild('item');
|
||||
$item -> addChild('title', $entry_title);
|
||||
$item -> addChild('description', $entry_description);
|
||||
$item -> addChild('guid', $entry_id);
|
||||
$item -> addChild('link', $entry_link);
|
||||
$item -> addChild('h:dc:creator', $entry['type']);
|
||||
$item -> addChild('pubDate', date(DATE_RSS, strtotime($entry['timestamp'])));
|
||||
} else {
|
||||
// add entry element for each article
|
||||
$item = $xml->addChild('entry');
|
||||
$item->addChild('title', $entry_title);
|
||||
$item->addChild('summary', $entry_description);
|
||||
$item->addChild('id', $entry_id);
|
||||
$item->addChild('link');
|
||||
$item->link->addAttribute('href', $entry_link);
|
||||
$item->addChild('author');
|
||||
$item->author->addChild('name', $entry['type']);
|
||||
$item->addChild('updated', date(DATE_ATOM, strtotime($entry['timestamp'])));
|
||||
}
|
||||
$item = $xml -> addChild('entry');
|
||||
$item -> addChild('title', $entry_title);
|
||||
$item -> addChild('summary', $entry_description);
|
||||
$item -> addChild('id', $entry_id);
|
||||
$item -> addChild('link');
|
||||
$item -> link -> addAttribute('href', $entry_link);
|
||||
$item -> addChild('author');
|
||||
$item -> author -> addChild('name', $entry['type']);
|
||||
$item -> addChild('updated', date(DATE_ATOM, strtotime($entry['timestamp'])));
|
||||
}
|
||||
}
|
||||
|
||||
// Unset & destroy session
|
||||
session_unset();
|
||||
session_destroy();
|
||||
// Unset & destroy session
|
||||
session_unset();
|
||||
session_destroy();
|
||||
|
||||
// Print feed
|
||||
header('Content-Type: text/xml; charset=utf-8');
|
||||
echo $xml->asXML();
|
||||
// Print feed
|
||||
header('Content-Type: text/xml; charset=utf-8');
|
||||
echo $xml -> asXML();
|
||||
|
||||
|
||||
// DOCME needs phpdoc block
|
||||
function content_cdata($content)
|
||||
{
|
||||
return '<![CDATA['.$content.']]>';
|
||||
return '<![CDATA[' . $content . ']]>';
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
100
html/geojson.php
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Observium
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage web
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
*
|
||||
*/
|
||||
|
||||
ini_set('allow_url_fopen', 0);
|
||||
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
include($config['html_dir'] . "/includes/cache-data.inc.php");
|
||||
|
||||
if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
|
||||
if (!$_SESSION['authenticated']) { echo("unauthenticated"); exit; }
|
||||
}
|
||||
|
||||
$vars = get_vars('GET');
|
||||
|
||||
$geo = array();
|
||||
|
||||
foreach ($GLOBALS['cache']['devices']['id'] as $device)
|
||||
{
|
||||
if (!$config['web_show_disabled'] && $device["disabled"]) { continue; }
|
||||
$lat = (is_numeric($device['location_lat']) ? $device['location_lat'] : $config['geocoding']['default']['lat']);
|
||||
$lon = (is_numeric($device['location_lon']) ? $device['location_lon'] : $config['geocoding']['default']['lon']);
|
||||
if ($device["status"] == "0")
|
||||
{
|
||||
if ($device["ignore"] == "0")
|
||||
{
|
||||
$locations[$lat][$lon]["down_hosts"][] = $device;
|
||||
}
|
||||
} else {
|
||||
$locations[$lat][$lon]["up_hosts"][] = $device;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($locations as $la => $lat)
|
||||
{
|
||||
foreach ($lat as $lo => $lon)
|
||||
{
|
||||
$tooltip = "";
|
||||
$num_up = safe_count($lon["up_hosts"]);
|
||||
$num_down = safe_count($lon["down_hosts"]);
|
||||
$total_hosts = $num_up + $num_down;
|
||||
$tooltip = '<p><span class="label label-success">Up '.$num_up.'</span> <span class="label label-error">Down '.$num_down.'</span></p>';
|
||||
$state = 'unknown';
|
||||
$location_name = "";
|
||||
if ($num_down > 0)
|
||||
{
|
||||
$state = 'down';
|
||||
$location_name = ($lon['down_hosts'][0]['location'] === '' ? OBS_VAR_UNSET : $lon['down_hosts'][0]['location']);
|
||||
$location_url = generate_location_url($lon['down_hosts'][0]['location']);
|
||||
}
|
||||
elseif ($num_up > 0)
|
||||
{
|
||||
$state = 'up';
|
||||
$location_name = ($lon['up_hosts'][0]['location'] === '' ? OBS_VAR_UNSET : $lon['up_hosts'][0]['location']);
|
||||
$location_url = generate_location_url($lon['up_hosts'][0]['location']);
|
||||
}
|
||||
|
||||
$tooltip = "<h3>".$location_name."</h3><hr />".$tooltip;
|
||||
foreach ($lon["down_hosts"] as $down_host) {
|
||||
$tooltip .= '<span class="label label-error">' . escape_html($down_host['hostname']) .'</span> ';
|
||||
}
|
||||
|
||||
$feature = array('geometry' => array('type' => 'Point',
|
||||
'coordinates' => array((float)$lo, (float)$la)),
|
||||
'type' => 'Feature',
|
||||
'properties' => array('name' => $location_name,
|
||||
'state' => $state,
|
||||
'id' => safename($location_name),
|
||||
'popupContent' => $tooltip,
|
||||
'url' => $location_url));
|
||||
$features[] = $feature;
|
||||
|
||||
//echo "[$la, $lo, $num_up, $num_down, \"$tooltip\", '$location_name', '$location_url'],\n ";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$geo = array('type' => 'FeatureCollection', 'features' => $features);
|
||||
|
||||
header('Content-type: application/javascript');
|
||||
//echo 'var geojson = ' . json_encode($geo) . ';';
|
||||
|
||||
//print_r($features);
|
||||
|
||||
echo safe_json_encode($geo);
|
||||
|
||||
//r($geo);
|
||||
|
||||
// EOF
|
@ -12,9 +12,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
if (!$config['web_iframe'] && is_iframe() &&
|
||||
!http_match_referer('!/device/device=\d+/tab=port/.*?/view=realtime/!')) {
|
||||
//bdump($_SERVER['HTTP_SEC_FETCH_DEST']);
|
||||
//bdump($_SERVER['HTTP_REFERER']); //'HTTP_SEC_FETCH_SITE' => 'same-origin'
|
||||
print_error_permission("Not allowed to run in a iframe!");
|
||||
die();
|
||||
}
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
|
||||
// Push $_GET into $vars to be compatible with web interface naming
|
||||
@ -22,66 +29,59 @@ $vars = get_vars('GET');
|
||||
|
||||
if (is_numeric($vars['id']) && ($config['allow_unauth_graphs'] || port_permitted($vars['id'])))
|
||||
{
|
||||
$port = get_port_by_id($vars['id']);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
$title = generate_device_link($device);
|
||||
$title .= " :: Port ".generate_port_link($port);
|
||||
$auth = TRUE;
|
||||
$port = get_port_by_id_cache($vars['id']);
|
||||
$device = device_by_id_cache($port['device_id']);
|
||||
$title = generate_device_link($device);
|
||||
$title .= " :: Port " . generate_port_link($port);
|
||||
$auth = TRUE;
|
||||
} else {
|
||||
|
||||
echo("Unauthenticated");
|
||||
die;
|
||||
|
||||
// not authenticated
|
||||
die("Unauthenticated");
|
||||
}
|
||||
|
||||
header("Content-type: image/svg+xml");
|
||||
|
||||
/********** HTTP GET Based Conf ***********/
|
||||
$ifnum = $port['ifIndex']; // BSD / SNMP interface name / number
|
||||
$ifname = escape_html($port['port_label']); //Interface name that will be showed on top right of graph
|
||||
$ifnum = $port['ifIndex']; // BSD / SNMP interface name / number
|
||||
$ifname = escape_html($port['port_label']); //Interface name that will be showed on top right of graph
|
||||
//$hostname = short_hostname($device['hostname']);
|
||||
$hostname = escape_html(device_name($device, TRUE));
|
||||
|
||||
if($vars['title']) { $ifname = escape_html($vars['title']); }
|
||||
if ($vars['title']) { $ifname = escape_html($vars['title']); }
|
||||
|
||||
/********* Other conf *******/
|
||||
$scale_type="follow"; //Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas
|
||||
$nb_plot=240; //NB plot in graph
|
||||
$scale_type = "follow"; // Autoscale default setup : "up" = only increase scale; "follow" = increase and decrease scale according to current graphed datas
|
||||
$nb_plot = 240; // NB plot in graph
|
||||
|
||||
if (is_numeric($vars['interval']))
|
||||
{
|
||||
$time_interval = $vars['interval'];
|
||||
} else {
|
||||
$time_interval = 1; // Refresh time Interval
|
||||
// Refresh time Interval
|
||||
$time_interval = is_numeric($vars['interval']) ? $vars['interval'] : 1;
|
||||
|
||||
$fetch_link = "data.php?id=" . $vars['id'];
|
||||
if (OBS_DEBUG) {
|
||||
$fetch_link .= '&debug=yes';
|
||||
}
|
||||
|
||||
$fetch_link = "data.php?id=".$vars['id'];
|
||||
if (OBS_DEBUG)
|
||||
{
|
||||
$fetch_link .= '&debug=yes';
|
||||
}
|
||||
|
||||
//SVG attributes
|
||||
$attribs['axis']='fill="black" stroke="black"';
|
||||
$attribs['in']='fill="green" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||
$attribs['out']='fill="blue" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||
$attribs['graph_in']='fill="none" stroke="green" stroke-opacity="0.8"';
|
||||
$attribs['graph_out']='fill="none" stroke="blue" stroke-opacity="0.8"';
|
||||
$attribs['legend']='fill="black" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||
$attribs['graphname']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="9"';
|
||||
$attribs['hostname']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
|
||||
$attribs['grid_txt']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
|
||||
$attribs['grid']='stroke="gray" stroke-opacity="0.5"';
|
||||
$attribs['switch_unit']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||
$attribs['switch_scale']='fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||
$attribs['error']='fill="blue" font-family="Arial" font-size="4"';
|
||||
$attribs['collect_initial']='fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||
// SVG attributes
|
||||
$attribs['axis'] = 'fill="black" stroke="black"';
|
||||
$attribs['in'] = 'fill="green" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||
$attribs['out'] = 'fill="blue" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="7"';
|
||||
$attribs['graph_in'] = 'fill="none" stroke="green" stroke-opacity="0.8"';
|
||||
$attribs['graph_out'] = 'fill="none" stroke="blue" stroke-opacity="0.8"';
|
||||
$attribs['legend'] = 'fill="black" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||
$attribs['graphname'] = 'fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="9"';
|
||||
$attribs['hostname'] = 'fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
|
||||
$attribs['grid_txt'] = 'fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="6"';
|
||||
$attribs['grid'] = 'stroke="gray" stroke-opacity="0.5"';
|
||||
$attribs['switch_unit'] = 'fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||
$attribs['switch_scale'] = 'fill="#435370" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4" text-decoration="underline"';
|
||||
$attribs['error'] = 'fill="blue" font-family="Arial" font-size="4"';
|
||||
$attribs['collect_initial'] = 'fill="gray" font-family="Tahoma, Verdana, Arial, Helvetica, sans-serif" font-size="4"';
|
||||
|
||||
//Error text if we cannot fetch data : depends on which method is used
|
||||
$error_text = "Can't get data about port $ifnum";
|
||||
|
||||
$height=125; //SVG internal height : do not modify
|
||||
$width=300; //SVG internal width : do not modify
|
||||
$height = 125; // SVG internal height : do not modify
|
||||
$width = 300; // SVG internal width : do not modify
|
||||
|
||||
/********* Graph DATA **************/
|
||||
print('<?xml version="1.0" encoding="iso-8859-1"?>' . PHP_EOL);
|
||||
@ -94,23 +94,23 @@ print('<?xml version="1.0" encoding="iso-8859-1"?>' . PHP_EOL);
|
||||
<line id="axis_y" x1="0" y1="100%" x2="100%" y2="100%" <?php echo($attribs['axis']) ?>/>
|
||||
<path id="graph_out" d="M0 <?php echo($height) ?> L 0 <?php echo($height); ?>" <?php echo($attribs['graph_out']) ?>/>
|
||||
<path id="graph_in" d="M0 <?php echo($height) ?> L 0 <?php echo($height); ?>" <?php echo($attribs['graph_in']) ?>/>
|
||||
<path id="grid" d="M0 <?php echo($height/4*1) ?> L <?php echo($width) ?> <?php echo($height/4*1) ?> M0 <?php echo($height/4*2) ?> L <?php echo($width) ?> <?php echo($height/4*2) ?> M0 <?php echo ($height/4*3) ?> L <?php echo($width . ' ' . ($height/4*3)) ?>" <?php echo($attribs['grid'])?>/>
|
||||
<text id="grid_txt1" x="<?php echo($width) ?>" y="<?php echo($height/4*1) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<text id="grid_txt2" x="<?php echo($width) ?>" y="<?php echo($height/4*2) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<text id="grid_txt3" x="<?php echo($width) ?>" y="<?php echo($height/4*3) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<path id="grid" d="M0 <?php echo($height / 4) ?> L <?php echo($width) ?> <?php echo($height / 4) ?> M0 <?php echo($height / 4 * 2) ?> L <?php echo($width) ?> <?php echo($height / 4 * 2) ?> M0 <?php echo ($height / 4 * 3) ?> L <?php echo($width . ' ' . ($height / 4 * 3)) ?>" <?php echo($attribs['grid'])?>/>
|
||||
<text id="grid_txt1" x="<?php echo($width) ?>" y="<?php echo($height / 4) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<text id="grid_txt2" x="<?php echo($width) ?>" y="<?php echo($height / 4 * 2) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<text id="grid_txt3" x="<?php echo($width) ?>" y="<?php echo($height / 4 * 3) ?>" <?php echo($attribs['grid_txt']) ?> text-anchor="end"> </text>
|
||||
<text id="graph_in_lbl" x="5" y="8" <?php echo($attribs['in']) ?>>In</text>
|
||||
<text id="graph_out_lbl" x="5" y="16" <?php echo($attribs['out']) ?>>Out</text>
|
||||
<text id="graph_in_txt" x="20" y="8" <?php echo($attribs['in']) ?>> </text>
|
||||
<text id="graph_out_txt" x="20" y="16" <?php echo($attribs['out']) ?>> </text>
|
||||
<text id="ifname" x="<?php echo($width-2) ?>" y="8" <?php echo($attribs['graphname']) ?> text-anchor="end"><?php echo($ifname) ?></text>
|
||||
<text id="hostname" x="<?php echo($width-2) ?>" y="14" <?php echo($attribs['hostname']) ?> text-anchor="end"><?php echo($hostname) ?></text>
|
||||
<text id="switch_unit" x="<?php echo($width*0.55) ?>" y="5" <?php echo($attribs['switch_unit']) ?>>Switch to bytes/s</text>
|
||||
<text id="switch_scale" x="<?php echo($width*0.55) ?>" y="11" <?php echo($attribs['switch_scale']) ?>>AutoScale (<?php echo($scale_type) ?>)</text>
|
||||
<text id="datetime" x="<?php echo($width*0.33) ?>" y="5" <?php echo($attribs['legend']) ?>> </text>
|
||||
<text id="graphlast" x="<?php echo($width*0.55) ?>" y="17" <?php echo($attribs['legend']) ?>>Graph shows last <?php echo($time_interval*$nb_plot) ?> seconds</text>
|
||||
<polygon id="axis_arrow_x" <?php echo($attribs['axis']) ?> points="<?php echo($width . "," . $height) ?> <?php echo(($width-2) . "," . ($height-2)) ?> <?php echo(($width-2) . "," . $height) ?>"/>
|
||||
<text id="error" x="<?php echo($width*0.5) ?>" y="<?php echo($height*0.5) ?>" visibility="hidden" <?php echo($attribs['error']) ?> text-anchor="middle"><?php echo($error_text) ?></text>
|
||||
<text id="collect_initial" x="<?php echo($width*0.5) ?>" y="<?php echo($height*0.5) ?>" visibility="hidden" <?php echo($attribs['collect_initial']) ?> text-anchor="middle">Collecting initial data, please wait...</text>
|
||||
<text id="ifname" x="<?php echo($width - 2) ?>" y="8" <?php echo($attribs['graphname']) ?> text-anchor="end"><?php echo($ifname) ?></text>
|
||||
<text id="hostname" x="<?php echo($width - 2) ?>" y="14" <?php echo($attribs['hostname']) ?> text-anchor="end"><?php echo($hostname) ?></text>
|
||||
<text id="switch_unit" x="<?php echo($width * 0.55) ?>" y="5" <?php echo($attribs['switch_unit']) ?>>Switch to bytes/s</text>
|
||||
<text id="switch_scale" x="<?php echo($width * 0.55) ?>" y="11" <?php echo($attribs['switch_scale']) ?>>AutoScale (<?php echo($scale_type) ?>)</text>
|
||||
<text id="datetime" x="<?php echo($width * 0.33) ?>" y="5" <?php echo($attribs['legend']) ?>> </text>
|
||||
<text id="graphlast" x="<?php echo($width * 0.55) ?>" y="17" <?php echo($attribs['legend']) ?>>Graph shows last <?php echo($time_interval * $nb_plot) ?> seconds</text>
|
||||
<polygon id="axis_arrow_x" <?php echo($attribs['axis']) ?> points="<?php echo($width . "," . $height) ?> <?php echo(($width - 2) . "," . ($height - 2)) ?> <?php echo(($width - 2) . "," . $height) ?>"/>
|
||||
<text id="error" x="<?php echo($width * 0.5) ?>" y="<?php echo($height * 0.5) ?>" visibility="hidden" <?php echo($attribs['error']) ?> text-anchor="middle"><?php echo($error_text) ?></text>
|
||||
<text id="collect_initial" x="<?php echo($width * 0.5) ?>" y="<?php echo($height * 0.5) ?>" visibility="hidden" <?php echo($attribs['collect_initial']) ?> text-anchor="middle">Collecting initial data, please wait...</text>
|
||||
</g>
|
||||
<script type="text/ecmascript">
|
||||
<![CDATA[
|
||||
@ -120,43 +120,45 @@ print('<?xml version="1.0" encoding="iso-8859-1"?>' . PHP_EOL);
|
||||
* popular. If getURL is undefined we spin our own by wrapping XMLHttpRequest.
|
||||
*/
|
||||
if (typeof getURL == 'undefined') {
|
||||
getURL = function(url, callback) {
|
||||
if (!url)
|
||||
throw 'No URL for getURL';
|
||||
getURL = function(url, callback) {
|
||||
if (!url)
|
||||
throw 'No URL for getURL';
|
||||
|
||||
try {
|
||||
if (typeof callback.operationComplete == 'function')
|
||||
callback = callback.operationComplete;
|
||||
} catch (e) {}
|
||||
if (typeof callback != 'function')
|
||||
throw 'No callback function for getURL';
|
||||
|
||||
var http_request = null;
|
||||
if (typeof XMLHttpRequest != 'undefined') {
|
||||
http_request = new XMLHttpRequest();
|
||||
}
|
||||
else if (typeof ActiveXObject != 'undefined'){
|
||||
try {
|
||||
http_request = new ActiveXObject('Msxml2.XMLHTTP');
|
||||
} catch (e) {
|
||||
try {
|
||||
http_request = new ActiveXObject('Microsoft.XMLHTTP');
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
if (!http_request)
|
||||
throw 'Both getURL and XMLHttpRequest are undefined';
|
||||
if (typeof callback.operationComplete == 'function')
|
||||
callback = callback.operationComplete;
|
||||
} catch (e) {
|
||||
}
|
||||
if (typeof callback != 'function')
|
||||
throw 'No callback function for getURL';
|
||||
|
||||
http_request.onreadystatechange = function() {
|
||||
if (http_request.readyState == 4) {
|
||||
callback( { success : true,
|
||||
content : http_request.responseText,
|
||||
contentType : http_request.getResponseHeader("Content-Type") } );
|
||||
}
|
||||
var http_request = null;
|
||||
if (typeof XMLHttpRequest != 'undefined') {
|
||||
http_request = new XMLHttpRequest();
|
||||
} else if (typeof ActiveXObject != 'undefined') {
|
||||
try {
|
||||
http_request = new ActiveXObject('Msxml2.XMLHTTP');
|
||||
} catch (e) {
|
||||
try {
|
||||
http_request = new ActiveXObject('Microsoft.XMLHTTP');
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!http_request)
|
||||
throw 'Both getURL and XMLHttpRequest are undefined';
|
||||
|
||||
http_request.onreadystatechange = function() {
|
||||
if (http_request.readyState === 4) {
|
||||
callback({ success: true,
|
||||
content: http_request.responseText,
|
||||
contentType: http_request.getResponseHeader("Content-Type")
|
||||
});
|
||||
}
|
||||
}
|
||||
http_request.open('GET', url, true);
|
||||
http_request.send(null);
|
||||
}
|
||||
http_request.open('GET', url, true);
|
||||
http_request.send(null);
|
||||
}
|
||||
}
|
||||
|
||||
var SVGDoc = null;
|
||||
@ -173,216 +175,216 @@ var unit = 'bits';
|
||||
var scale_type = '<?php echo($scale_type) ?>';
|
||||
|
||||
function init(evt) {
|
||||
SVGDoc = evt.target.ownerDocument;
|
||||
SVGDoc.getElementById("switch_unit").addEventListener("mousedown", switch_unit, false);
|
||||
SVGDoc.getElementById("switch_scale").addEventListener("mousedown", switch_scale, false);
|
||||
SVGDoc = evt.target.ownerDocument;
|
||||
SVGDoc.getElementById("switch_unit").addEventListener("mousedown", switch_unit, false);
|
||||
SVGDoc.getElementById("switch_scale").addEventListener("mousedown", switch_scale, false);
|
||||
|
||||
fetch_data();
|
||||
fetch_data();
|
||||
}
|
||||
|
||||
function switch_unit(event)
|
||||
{
|
||||
SVGDoc.getElementById('switch_unit').firstChild.data = 'Switch to ' + unit + '/s';
|
||||
unit = (unit == 'bits') ? 'bytes' : 'bits';
|
||||
function switch_unit(event) {
|
||||
SVGDoc.getElementById('switch_unit').firstChild.data = 'Switch to ' + unit + '/s';
|
||||
unit = (unit === 'bits') ? 'bytes' : 'bits';
|
||||
}
|
||||
|
||||
function switch_scale(event)
|
||||
{
|
||||
scale_type = (scale_type == 'up') ? 'follow' : 'up';
|
||||
SVGDoc.getElementById('switch_scale').firstChild.data = 'AutoScale (' + scale_type + ')';
|
||||
function switch_scale(event) {
|
||||
scale_type = (scale_type === 'up') ? 'follow' : 'up';
|
||||
SVGDoc.getElementById('switch_scale').firstChild.data = 'AutoScale (' + scale_type + ')';
|
||||
}
|
||||
|
||||
function fetch_data() {
|
||||
getURL('<?php echo($fetch_link) ?>', plot_data);
|
||||
getURL('<?php echo($fetch_link) ?>', plot_data);
|
||||
}
|
||||
|
||||
function plot_data(obj) {
|
||||
// Show datetimelegend
|
||||
var now = new Date();
|
||||
//var datetime = (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() + ' ' +
|
||||
// LZ(now.getHours()) + ":" + LZ(now.getMinutes()) + ":" + LZ(now.getSeconds());
|
||||
// Show datetimelegend
|
||||
var now = new Date();
|
||||
//var datetime = (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() + ' ' +
|
||||
// LZ(now.getHours()) + ":" + LZ(now.getMinutes()) + ":" + LZ(now.getSeconds());
|
||||
|
||||
datetime = now.toLocaleString();
|
||||
//datetime = now.toISOString();
|
||||
datetime = now.toLocaleString();
|
||||
//datetime = now.toISOString();
|
||||
|
||||
SVGDoc.getElementById('datetime').firstChild.data = datetime;
|
||||
SVGDoc.getElementById('datetime').firstChild.data = datetime;
|
||||
|
||||
if (!obj.success)
|
||||
return handle_error(); // getURL failed to get data
|
||||
if (!obj.success)
|
||||
return handle_error(); // getURL failed to get data
|
||||
|
||||
var t = obj.content.split("|");
|
||||
var ugmt = parseFloat(t[0]); // ugmt is an unixtimestamp style
|
||||
var ifin = parseInt(t[1]); // number of bytes received by the interface
|
||||
var ifout = parseInt(t[2]); // number of bytes sent by the interface
|
||||
var scale;
|
||||
var t = obj.content.split("|");
|
||||
var ugmt = parseFloat(t[0]); // ugmt is an unixtimestamp style
|
||||
var ifin = parseInt(t[1]); // number of bytes received by the interface
|
||||
var ifout = parseInt(t[2]); // number of bytes sent by the interface
|
||||
var scale;
|
||||
|
||||
if (!isNumber(ifin) || !isNumber(ifout))
|
||||
return handle_error();
|
||||
if (!isNumber(ifin) || !isNumber(ifout))
|
||||
return handle_error();
|
||||
|
||||
var diff_ugmt = ugmt - last_ugmt;
|
||||
var diff_ifin;
|
||||
if (ifin >= last_ifin) {
|
||||
diff_ifin = ifin - last_ifin;
|
||||
} else {
|
||||
var max = (last_ifin > Math.pow(2,32)) ? Math.pow(2,64) : Math.pow(2,32);
|
||||
diff_ifin = max - last_ifin + ifin;
|
||||
}
|
||||
var diff_ifout;
|
||||
if (ifout >= last_ifout) {
|
||||
diff_ifout = ifout - last_ifout;
|
||||
} else {
|
||||
var max = (last_ifout > Math.pow(2,32)) ? Math.pow(2,64) : Math.pow(2,32);
|
||||
diff_ifout = max - last_ifout + ifout;
|
||||
}
|
||||
|
||||
if (diff_ugmt == 0)
|
||||
diff_ugmt = 1; /* avoid division by zero */
|
||||
|
||||
last_ugmt = ugmt;
|
||||
last_ifin = ifin;
|
||||
last_ifout = ifout;
|
||||
|
||||
switch (plot_in.length) {
|
||||
case 0:
|
||||
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'visible');
|
||||
plot_in[0] = diff_ifin / diff_ugmt;
|
||||
plot_out[0] = diff_ifout / diff_ugmt;
|
||||
setTimeout('fetch_data()',<?php echo(1000*$time_interval) ?>);
|
||||
return;
|
||||
case 1:
|
||||
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'hidden');
|
||||
break;
|
||||
case max_num_points:
|
||||
// shift plot to left if the maximum number of plot points has been reached
|
||||
var i = 0;
|
||||
while (i < max_num_points) {
|
||||
plot_in[i] = plot_in[i+1];
|
||||
plot_out[i] = plot_out[++i];
|
||||
}
|
||||
plot_in.length--;
|
||||
plot_out.length--;
|
||||
}
|
||||
|
||||
plot_in[plot_in.length] = diff_ifin / diff_ugmt;
|
||||
plot_out[plot_out.length]= diff_ifout / diff_ugmt;
|
||||
var index_plot = plot_in.length - 1;
|
||||
|
||||
SVGDoc.getElementById('graph_in_txt').firstChild.data = formatSpeed(plot_in[index_plot], unit);
|
||||
SVGDoc.getElementById('graph_out_txt').firstChild.data = formatSpeed(plot_out[index_plot], unit);
|
||||
|
||||
/* determine peak for sensible scaling */
|
||||
if (scale_type == 'up') {
|
||||
if (plot_in[index_plot] > max)
|
||||
max = plot_in[index_plot];
|
||||
if (plot_out[index_plot] > max)
|
||||
max = plot_out[index_plot];
|
||||
}
|
||||
else if (scale_type == 'follow') {
|
||||
i = 0;
|
||||
max = 0;
|
||||
while (i < plot_in.length) {
|
||||
if (plot_in[i] > max)
|
||||
max = plot_in[i];
|
||||
if (plot_out[i] > max)
|
||||
max = plot_out[i];
|
||||
i++;
|
||||
var diff_ugmt = ugmt - last_ugmt;
|
||||
var diff_ifin;
|
||||
if (ifin >= last_ifin) {
|
||||
diff_ifin = ifin - last_ifin;
|
||||
} else {
|
||||
var max = (last_ifin > Math.pow(2, 32)) ? Math.pow(2, 64) : Math.pow(2, 32);
|
||||
diff_ifin = max - last_ifin + ifin;
|
||||
}
|
||||
}
|
||||
|
||||
var rmax; // max, rounded up
|
||||
|
||||
if (unit == 'bits') {
|
||||
/* round up max, such that
|
||||
100 kbps -> 200 kbps -> 400 kbps -> 800 kbps -> 1 Mbps -> 2 Mbps -> ... */
|
||||
rmax = 12500;
|
||||
i = 0;
|
||||
while (max > rmax) {
|
||||
i++;
|
||||
if (i && (i % 4 == 0))
|
||||
rmax *= 1.25;
|
||||
else
|
||||
rmax *= 2;
|
||||
var diff_ifout;
|
||||
if (ifout >= last_ifout) {
|
||||
diff_ifout = ifout - last_ifout;
|
||||
} else {
|
||||
var max = (last_ifout > Math.pow(2, 32)) ? Math.pow(2, 64) : Math.pow(2, 32);
|
||||
diff_ifout = max - last_ifout + ifout;
|
||||
}
|
||||
} else {
|
||||
/* round up max, such that
|
||||
10 KB/s -> 20 KB/s -> 40 KB/s -> 80 KB/s -> 100 KB/s -> 200 KB/s -> 400 KB/s -> 800 KB/s -> 1 MB/s ... */
|
||||
rmax = 10240;
|
||||
i = 0;
|
||||
while (max > rmax) {
|
||||
i++;
|
||||
if (i && (i % 4 == 0))
|
||||
rmax *= 1.25;
|
||||
else
|
||||
rmax *= 2;
|
||||
|
||||
if (i == 8)
|
||||
rmax *= 1.024;
|
||||
if (diff_ugmt === 0)
|
||||
diff_ugmt = 1; /* avoid division by zero */
|
||||
|
||||
last_ugmt = ugmt;
|
||||
last_ifin = ifin;
|
||||
last_ifout = ifout;
|
||||
|
||||
switch (plot_in.length) {
|
||||
case 0:
|
||||
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'visible');
|
||||
plot_in[0] = diff_ifin / diff_ugmt;
|
||||
plot_out[0] = diff_ifout / diff_ugmt;
|
||||
setTimeout('fetch_data()',<?php echo(1000 * $time_interval) ?>);
|
||||
return;
|
||||
case 1:
|
||||
SVGDoc.getElementById("collect_initial").setAttributeNS(null, 'visibility', 'hidden');
|
||||
break;
|
||||
case max_num_points:
|
||||
// shift plot to left if the maximum number of plot points has been reached
|
||||
var i = 0;
|
||||
while (i < max_num_points) {
|
||||
plot_in[i] = plot_in[i + 1];
|
||||
plot_out[i] = plot_out[++i];
|
||||
}
|
||||
plot_in.length--;
|
||||
plot_out.length--;
|
||||
}
|
||||
}
|
||||
|
||||
scale = <?php echo($height) ?> / rmax;
|
||||
plot_in[plot_in.length] = diff_ifin / diff_ugmt;
|
||||
plot_out[plot_out.length]= diff_ifout / diff_ugmt;
|
||||
var index_plot = plot_in.length - 1;
|
||||
|
||||
/* change labels accordingly */
|
||||
SVGDoc.getElementById('grid_txt1').firstChild.data = formatSpeed(3*rmax/4,unit);
|
||||
SVGDoc.getElementById('grid_txt2').firstChild.data = formatSpeed(2*rmax/4,unit);
|
||||
SVGDoc.getElementById('grid_txt3').firstChild.data = formatSpeed(rmax/4,unit);
|
||||
SVGDoc.getElementById('graph_in_txt').firstChild.data = formatSpeed(plot_in[index_plot], unit);
|
||||
SVGDoc.getElementById('graph_out_txt').firstChild.data = formatSpeed(plot_out[index_plot], unit);
|
||||
|
||||
var path_in = "M 0 " + (<?php echo($height) ?> - (plot_in[0] * scale));
|
||||
var path_out = "M 0 " + (<?php echo($height) ?> - (plot_out[0] * scale));
|
||||
for (i = 1; i < plot_in.length; i++)
|
||||
{
|
||||
var x = step * i;
|
||||
var y_in = <?php echo($height) ?> - (plot_in[i] * scale);
|
||||
var y_out = <?php echo($height) ?> - (plot_out[i] * scale);
|
||||
path_in += " L" + x + " " + y_in;
|
||||
path_out += " L" + x + " " + y_out;
|
||||
}
|
||||
/* determine peak for sensible scaling */
|
||||
if (scale_type === 'up') {
|
||||
if (plot_in[index_plot] > max)
|
||||
max = plot_in[index_plot];
|
||||
if (plot_out[index_plot] > max)
|
||||
max = plot_out[index_plot];
|
||||
} else if (scale_type === 'follow') {
|
||||
i = 0;
|
||||
max = 0;
|
||||
while (i < plot_in.length) {
|
||||
if (plot_in[i] > max)
|
||||
max = plot_in[i];
|
||||
if (plot_out[i] > max)
|
||||
max = plot_out[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'hidden');
|
||||
SVGDoc.getElementById('graph_in').setAttributeNS(null, 'd', path_in);
|
||||
SVGDoc.getElementById('graph_out').setAttributeNS(null, 'd', path_out);
|
||||
var rmax; // max, rounded up
|
||||
|
||||
setTimeout('fetch_data()',<?php echo(1000*$time_interval) ?>);
|
||||
if (unit === 'bits') {
|
||||
/* round up max, such that
|
||||
100 kbps -> 200 kbps -> 400 kbps -> 800 kbps -> 1 Mbps -> 2 Mbps -> ... */
|
||||
rmax = 12500;
|
||||
i = 0;
|
||||
while (max > rmax) {
|
||||
i++;
|
||||
if (i && (i % 4 === 0))
|
||||
rmax *= 1.25;
|
||||
else
|
||||
rmax *= 2;
|
||||
}
|
||||
} else {
|
||||
/* round up max, such that
|
||||
10 KB/s -> 20 KB/s -> 40 KB/s -> 80 KB/s -> 100 KB/s -> 200 KB/s -> 400 KB/s -> 800 KB/s -> 1 MB/s ... */
|
||||
rmax = 10240;
|
||||
i = 0;
|
||||
while (max > rmax) {
|
||||
i++;
|
||||
if (i && (i % 4 === 0))
|
||||
rmax *= 1.25;
|
||||
else
|
||||
rmax *= 2;
|
||||
|
||||
if (i === 8)
|
||||
rmax *= 1.024;
|
||||
}
|
||||
}
|
||||
|
||||
scale = <?php echo($height) ?> / rmax;
|
||||
|
||||
/* change labels accordingly */
|
||||
SVGDoc.getElementById('grid_txt1').firstChild.data = formatSpeed(3 * rmax / 4, unit);
|
||||
SVGDoc.getElementById('grid_txt2').firstChild.data = formatSpeed(2 * rmax / 4, unit);
|
||||
SVGDoc.getElementById('grid_txt3').firstChild.data = formatSpeed(rmax / 4, unit);
|
||||
|
||||
var path_in = "M 0 " + (<?php echo($height) ?> - (plot_in[0] * scale));
|
||||
var path_out = "M 0 " + (<?php echo($height) ?> - (plot_out[0] * scale));
|
||||
for (i = 1; i < plot_in.length; i++) {
|
||||
var x = step * i;
|
||||
var y_in = <?php echo($height) ?> - (plot_in[i] * scale);
|
||||
var y_out = <?php echo($height) ?> - (plot_out[i] * scale);
|
||||
path_in += " L" + x + " " + y_in;
|
||||
path_out += " L" + x + " " + y_out;
|
||||
}
|
||||
|
||||
SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'hidden');
|
||||
SVGDoc.getElementById('graph_in').setAttributeNS(null, 'd', path_in);
|
||||
SVGDoc.getElementById('graph_out').setAttributeNS(null, 'd', path_out);
|
||||
|
||||
setTimeout('fetch_data()', <?php echo(1000 * $time_interval) ?>);
|
||||
}
|
||||
|
||||
function handle_error() {
|
||||
SVGDoc.getElementById("error").setAttributeNS(null, 'visibility', 'visible');
|
||||
setTimeout('fetch_data()',<?php echo(1000*$time_interval) ?>);
|
||||
SVGDoc.getElementById("error").setAttributeNS(null, 'visibility', 'visible');
|
||||
setTimeout('fetch_data()', <?php echo(1000 * $time_interval) ?>);
|
||||
}
|
||||
|
||||
function isNumber(a) {
|
||||
return typeof a == 'number' && isFinite(a);
|
||||
return typeof a == 'number' && isFinite(a);
|
||||
}
|
||||
|
||||
function formatSpeed(speed, unit) {
|
||||
if (unit == 'bits')
|
||||
return formatSpeedBits(speed);
|
||||
if (unit == 'bytes')
|
||||
return formatSpeedBytes(speed);
|
||||
if (unit === 'bits')
|
||||
return formatSpeedBits(speed);
|
||||
if (unit === 'bytes')
|
||||
return formatSpeedBytes(speed);
|
||||
}
|
||||
|
||||
function formatSpeedBits(speed) {
|
||||
// format speed in bits/sec, input: bytes/sec
|
||||
if (speed < 125000)
|
||||
return Math.round(speed / 125) + " Kbps";
|
||||
if (speed < 125000000)
|
||||
return Math.round(speed / 1250)/100 + " Mbps";
|
||||
// else
|
||||
return Math.round(speed / 1250000)/100 + " Gbps"; /* wow! */
|
||||
// format speed in bits/sec, input: bytes/sec
|
||||
if (speed < 125000)
|
||||
return Math.round(speed / 125) + " Kbps";
|
||||
if (speed < 125000000)
|
||||
return Math.round(speed / 1250)/100 + " Mbps";
|
||||
if (speed < 125000000000)
|
||||
return Math.round(speed / 1250000)/100 + " Gbps";
|
||||
// else
|
||||
return Math.round(speed / 125000000000)/100 + " Tbps"; /* wow! */
|
||||
}
|
||||
|
||||
function formatSpeedBytes(speed) {
|
||||
// format speed in bytes/sec, input: bytes/sec
|
||||
if (speed < 1048576)
|
||||
return Math.round(speed / 10.24)/100 + " KB/s";
|
||||
if (speed < 1073741824)
|
||||
return Math.round(speed / 10485.76)/100 + " MB/s";
|
||||
// else
|
||||
return Math.round(speed / 10737418.24)/100 + " GB/s"; /* wow! */
|
||||
// format speed in bytes/sec, input: bytes/sec
|
||||
if (speed < 1048576)
|
||||
return Math.round(speed / 10.24)/100 + " KB/s";
|
||||
if (speed < 1073741824)
|
||||
return Math.round(speed / 10485.76)/100 + " MB/s";
|
||||
if (speed < 1099511627776)
|
||||
return Math.round(speed / 10737418.24)/100 + " GB/s";
|
||||
// else
|
||||
return Math.round(speed / 10995116277.76)/100 + " TB/s"; /* wow! */
|
||||
}
|
||||
|
||||
function LZ(x) {
|
||||
return (x < 0 || x > 9 ? "" : "0") + x;
|
||||
return (x < 0 || x > 9 ? "" : "0") + x;
|
||||
}
|
||||
|
||||
]]>
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage graphs
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -15,27 +15,27 @@
|
||||
// Define this is graph
|
||||
define('OBS_GRAPH', TRUE);
|
||||
|
||||
$start = microtime(TRUE); // Needs common.php
|
||||
$gstart = microtime(TRUE); // Needs common.php
|
||||
|
||||
include_once("../includes/sql-config.inc.php");
|
||||
|
||||
include($config['html_dir'] . "/includes/functions.inc.php");
|
||||
include_once("../includes/observium.inc.php");
|
||||
|
||||
if (isset($config['allow_unauth_graphs']) && $config['allow_unauth_graphs']) {
|
||||
$auth = TRUE; // hardcode auth for all with config function
|
||||
print_debug('Authentication bypassed by $config[\'allow_unauth_graphs\'].');
|
||||
$auth = TRUE; // hardcode auth for all with config function
|
||||
print_debug('Authentication bypassed by $config[\'allow_unauth_graphs\'].');
|
||||
} elseif (isset($config['allow_unauth_graphs_cidr']) && count($config['allow_unauth_graphs_cidr'])) {
|
||||
//if (match_network($_SERVER['REMOTE_ADDR'], $config['allow_unauth_graphs_cidr']))
|
||||
if (match_network(get_remote_addr($config['web_session_ip_by_header']), $config['allow_unauth_graphs_cidr'])) {
|
||||
$auth = TRUE; // hardcode authenticated for matched subnet
|
||||
print_debug("Authentication by matched CIDR.");
|
||||
}
|
||||
//if (match_network($_SERVER['REMOTE_ADDR'], $config['allow_unauth_graphs_cidr']))
|
||||
if (match_network(get_remote_addr($config['web_session_ip_by_header']), $config['allow_unauth_graphs_cidr'])) {
|
||||
$auth = TRUE; // hardcode authenticated for matched subnet
|
||||
print_debug("Authentication by matched CIDR.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($auth) || !$auth) {
|
||||
// Normal auth
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
$auth = $_SESSION['authenticated'];
|
||||
// Normal auth
|
||||
include($config['html_dir'] . "/includes/authenticate.inc.php");
|
||||
$auth = $_SESSION['authenticated'];
|
||||
} elseif (!isset($_SESSION['userlevel']) && $auth) {
|
||||
$_SESSION['userlevel'] = 7; // Set global read for session when $auth hardcoded
|
||||
}
|
||||
|
||||
// Push $_GET into $vars to be compatible with web interface naming
|
||||
@ -44,8 +44,8 @@ $vars = get_vars('GET', $auth);
|
||||
|
||||
include($config['html_dir'] . "/includes/graphs/graph.inc.php");
|
||||
|
||||
$runtime = microtime(TRUE) - $start;
|
||||
$runtime = elapsed_time($gstart);
|
||||
|
||||
print_debug("Runtime ".$runtime." secs");
|
||||
print_debug("Runtime " . $runtime . " secs");
|
||||
|
||||
// EOF
|
||||
|
Before Width: | Height: | Size: 781 B |
Before Width: | Height: | Size: 733 B |
Before Width: | Height: | Size: 523 B |
Before Width: | Height: | Size: 464 B |
Before Width: | Height: | Size: 619 B |
Before Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 610 B |
Before Width: | Height: | Size: 533 B |
Before Width: | Height: | Size: 703 B |
Before Width: | Height: | Size: 656 B |
Before Width: | Height: | Size: 467 B |
Before Width: | Height: | Size: 592 B |
Before Width: | Height: | Size: 605 B |
Before Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 612 B |
Before Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 634 B |
Before Width: | Height: | Size: 685 B |
Before Width: | Height: | Size: 670 B |
Before Width: | Height: | Size: 656 B |
Before Width: | Height: | Size: 701 B |
Before Width: | Height: | Size: 487 B |
Before Width: | Height: | Size: 525 B |
Before Width: | Height: | Size: 585 B |
Before Width: | Height: | Size: 478 B |
Before Width: | Height: | Size: 547 B |
Before Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 510 B |
Before Width: | Height: | Size: 483 B |
Before Width: | Height: | Size: 520 B |
Before Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 492 B |
Before Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 555 B |
Before Width: | Height: | Size: 476 B |
Before Width: | Height: | Size: 473 B |
Before Width: | Height: | Size: 465 B |
Before Width: | Height: | Size: 426 B |
Before Width: | Height: | Size: 507 B |
Before Width: | Height: | Size: 582 B |
Before Width: | Height: | Size: 677 B |
Before Width: | Height: | Size: 379 B |
Before Width: | Height: | Size: 600 B |
Before Width: | Height: | Size: 551 B |
Before Width: | Height: | Size: 626 B |
Before Width: | Height: | Size: 345 B |
Before Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 384 B |
Before Width: | Height: | Size: 625 B |
Before Width: | Height: | Size: 685 B |