Added support to show the interface traffic graphs through the metaconsole and improved the ACL

This commit is contained in:
Alejandro Gallardo Escobar 2015-03-23 14:19:46 +01:00
parent fbc4460a25
commit fa9db9010c
2 changed files with 45 additions and 42 deletions

View File

@ -484,30 +484,23 @@ function treeview_printTable($id_agente, $server_data = array()) {
$table->data = array();
foreach ($network_interfaces as $interface_name => $interface) {
if (!empty($interface['traffic'])) {
if (!empty($interface['traffic']) && check_acl($config['id_user'], $agent["id_grupo"], "RR")) {
$params = array(
'interface_name' => $interface_name,
'agent_id' => $id_agente,
'traffic_module_in' => $interface['traffic']['in'],
'traffic_module_out' => $interface['traffic']['out']
);
if (defined('METACONSOLE') && !empty($server_id))
$params["server"] = $server_id;
$params_json = json_encode($params);
$params_encoded = base64_encode($params_json);
$url = ui_get_full_url("operation/agentes/interface_traffic_graph_win.php", false, false, false);
$graph_url = "$url?params=$params_encoded";
$win_handle = dechex(crc32($interface['status_module_id'].$interface_name));
$graph_url = '';
if (!defined('METACONSOLE')) {
$graph_url = $config['homeurl'] .
"operation/agentes/interface_traffic_graph_win.php?" .
"params=$params_encoded";
}
else if (!empty($server_data)) {
$graph_url = ui_meta_get_url_console_child(
$server_data, null, null, null, null,
"operation/agentes/interface_traffic_graph_win.php?" .
"params=$params_encoded");
}
$graph_link = "<a href=\"javascript:winopeng('$graph_url','$win_handle')\">" .
html_print_image("images/chart_curve.png", true, array("title" => __('Interface traffic'))) . "</a>";
}

View File

@ -29,23 +29,27 @@ require_once ($config['homedir'] . '/include/functions_graph.php');
require_once ($config['homedir'] . '/include/functions_custom_graphs.php');
require_once ($config['homedir'] . '/include/functions_modules.php');
// Hash login process
if (! isset ($config['id_user']) && get_parameter("loginhash", 0)) {
$loginhash_data = get_parameter("loginhash_data", "");
$loginhash_user = str_rot13(get_parameter("loginhash_user", ""));
if ($config["loginhash_pwd"] != "" && $loginhash_data == md5($loginhash_user.$config["loginhash_pwd"])) {
db_logon ($loginhash_user, $_SERVER['REMOTE_ADDR']);
$_SESSION['id_usuario'] = $loginhash_user;
$config["id_user"] = $loginhash_user;
$hash_connection_data = true;
}
}
check_login();
$params_json = base64_decode((string) get_parameter('params'));
$params = json_decode($params_json, true);
// Metaconsole connection to the node
$server_id = (int) (isset($params['server']) ? $params['server'] : 0);
if (!empty($server_id) && function_exists("metaconsole_get_connection_by_id")) {
$server = metaconsole_get_connection_by_id($server_id);
// Error connecting
if (metaconsole_connect($server) !== NOERR) {
echo "<html>";
echo "<body>";
ui_print_error_message(__('There was a problem connecting with the node'));
echo "</body>";
echo "</html>";
exit;
}
}
$user_language = get_user_language($config['id_user']);
if (file_exists ('../../include/languages/'.$user_language.'.mo')) {
$l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo'));
@ -54,9 +58,6 @@ if (file_exists ('../../include/languages/'.$user_language.'.mo')) {
echo '<link rel="stylesheet" href="../../include/styles/pandora.css" type="text/css"/>';
$params_json = base64_decode((string) get_parameter('params'));
$params = json_decode($params_json, true);
$interface_name = (string) $params['interface_name'];
$agent_id = (int) $params['agent_id'];
$interface_traffic_modules = array(
@ -106,6 +107,25 @@ $interface_traffic_modules = array(
<body bgcolor="#ffffff" style='background:#ffffff;'>
<?php
// ACL
$permission = false;
$agent_group = (int) agents_get_agent_group($agent_id);
// The traffic modules should belong to the agent id
$in_agent_id = (int) db_get_value("id_agente", "tagente_modulo", "id_agente_modulo", $params['traffic_module_in']);
$out_agent_id = (int) db_get_value("id_agente", "tagente_modulo", "id_agente_modulo", $params['traffic_module_out']);
$traffic_modules_belong_to_agent = $agent_id == $in_agent_id && $agent_id == $out_agent_id;
if (!empty($agent_group) && !empty($params['traffic_module_in']) && !empty($params['traffic_module_out'])
&& $traffic_modules_belong_to_agent && check_acl($config['id_user'], $agent_group, "RR")) {
$permission = true;
}
if (!$permission) {
require ($config['homedir'] . "/general/noaccess.php");
exit;
}
// Get input parameters
$period = (int) get_parameter('period', SECONDS_1HOUR);
$width = (int) get_parameter("width", 555);
@ -165,16 +185,6 @@ $interface_traffic_modules = array(
$side_layer_params['body_text'] .= '<form method="get" action="interface_traffic_graph_win.php">';
$side_layer_params['body_text'] .= html_print_input_hidden("params", base64_encode($params_json), true);
if (isset($hash_connection_data)) {
$side_layer_params['body_text'] .=
html_print_input_hidden("loginhash", "auto", true);
$side_layer_params['body_text'] .=
html_print_input_hidden("loginhash_data", $loginhash_data, true);
$side_layer_params['body_text'] .=
html_print_input_hidden("loginhash_user",
str_rot13($loginhash_user), true);
}
// FORM TABLE
$table = html_get_predefined_table('transparent', 2);