Merge branch 'develop' of https://192.168.50.5:8081/artica/pandorafms into develop

This commit is contained in:
artica 2019-10-28 12:35:53 +01:00
commit 428c678a05
4 changed files with 119 additions and 54 deletions

View File

@ -1,16 +1,32 @@
<?php <?php
// Pandora FMS - http://pandorafms.com /**
// ================================================== * Generate charts with given parameters.
// Copyright (c) 2005-2018 Artica Soluciones Tecnologicas *
// Please see http://pandorafms.org for full contribution list * @category ChartGenerator.
// This program is free software; you can redistribute it and/or * @package Pandora FMS
// modify it under the terms of the GNU General Public License * @subpackage Opensource.
// as published by the Free Software Foundation for version 2. * @version 1.0.0
// This program is distributed in the hope that it will be useful, * @license See below
// but WITHOUT ANY WARRANTY; without even the implied warranty of *
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * ______ ___ _______ _______ ________
// GNU General Public License for more details. * | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
// Global & session manageme * | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
require_once 'config.php'; require_once 'config.php';
require_once __DIR__.'/config.php'; require_once __DIR__.'/config.php';
@ -26,6 +42,29 @@ require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_tags.php'; require_once $config['homedir'].'/include/functions_tags.php';
/**
* Echo to stdout a PhantomJS callback call.
*
* @return void
*/
function echoPhantomCallback()
{
?>
<script type="text/javascript">
$('document').ready(function () {
setTimeout(function () {
try {
var status = window.callPhantom({ status: "loaded" });
} catch (error) {
console.log("CALLBACK ERROR", error.message)
}
}, 100);
});
</script>
<?php
}
// Initialize session. // Initialize session.
global $config; global $config;
@ -48,17 +87,7 @@ if (check_login(false) === false) {
</head> </head>
<body> <body>
<h1>Access is not granted</h1> <h1>Access is not granted</h1>
<script type="text/javascript"> <?php echoPhantomCallback(); ?>
$('document').ready(function () {
setTimeout(function () {
try {
var status = window.callPhantom({ status: "loaded" });
} catch (error) {
console.log("CALLBACK ERROR", error.message)
}
}, 100);
});
</script>
</body> </body>
</html> </html>
@ -76,11 +105,18 @@ if ($config['metaconsole'] && !empty($server_id)) {
$server = metaconsole_get_connection_by_id($server_id); $server = metaconsole_get_connection_by_id($server_id);
// Error connecting. // Error connecting.
if (metaconsole_connect($server) !== NOERR) { if (metaconsole_connect($server) !== NOERR) {
echo '<html>'; ?>
echo '<body>'; <html>
ui_print_error_message(__('There was a problem connecting with the node')); <body>
echo '</body>'; <?php
echo '</html>'; ui_print_error_message(
__('There was a problem connecting with the node')
);
echoPhantomCallback();
?>
</body>
</html>
<?php
exit; exit;
} }
} }
@ -125,16 +161,18 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
<body bgcolor="#ffffff" style='background:#ffffff;'> <body bgcolor="#ffffff" style='background:#ffffff;'>
<?php <?php
$params['only_image'] = false; $params['only_image'] = false;
$params['width'] = (int) $_REQUEST['viewport_width']; $params['width'] = (int) $_REQUEST['viewport_width'];
$params['menu'] = false; $params['menu'] = false;
if ((!isset($params['width']) || ($params['width'] <= 0))) { if ((isset($params['width']) === false
|| ($params['width'] <= 0))
) {
$params['width'] = 650; $params['width'] = 650;
} }
$params_combined = json_decode($_REQUEST['data_combined'], true); $params_combined = json_decode($_REQUEST['data_combined'], true);
$module_list = json_decode($_REQUEST['data_module_list'], true); $module_list = json_decode($_REQUEST['data_module_list'], true);
$type_graph_pdf = $_REQUEST['type_graph_pdf']; $type_graph_pdf = $_REQUEST['type_graph_pdf'];
echo '<div>'; echo '<div>';
switch ($type_graph_pdf) { switch ($type_graph_pdf) {
@ -253,20 +291,7 @@ if (file_exists('languages/'.$user_language.'.mo') === true) {
} }
echo '</div>'; echo '</div>';
echoPhantomCallback();
?> ?>
<script type="text/javascript">
$('document').ready(function () {
setTimeout(function () {
try {
var status = window.callPhantom({ status: "loaded" });
} catch (error) {
console.log("CALLBACK ERROR", error.message)
}
}, 100);
});
</script>
</body> </body>
</html> </html>

View File

@ -161,7 +161,7 @@ function pandora_session_gc($max_lifetime=300)
if (isset($config['session_timeout'])) { if (isset($config['session_timeout'])) {
$session_timeout = $config['session_timeout']; $session_timeout = $config['session_timeout'];
} else { } else {
// if $config doesn`t work ... // If $config doesn`t work ...
$session_timeout = db_get_value( $session_timeout = db_get_value(
'value', 'value',
'tconfig', 'tconfig',
@ -170,9 +170,9 @@ function pandora_session_gc($max_lifetime=300)
); );
} }
if (!empty($session_timeout)) { if (empty($session_timeout) === false) {
if ($session_timeout == -1) { if ($session_timeout == -1) {
// The session expires in 10 years // The session expires in 10 years.
$session_timeout = 315576000; $session_timeout = 315576000;
} else { } else {
$session_timeout *= 60; $session_timeout *= 60;
@ -191,15 +191,14 @@ function pandora_session_gc($max_lifetime=300)
); );
// Deleting cron and empty sessions. // Deleting cron and empty sessions.
$sql = "DELETE FROM tsessions_php WHERE $sql = 'DELETE FROM tsessions_php WHERE data IS NULL';
data IS NULL OR id_session REGEXP '^cron-'";
db_process_sql($sql); db_process_sql($sql);
return $retval; return $retval;
} }
// FIXME: SAML should work with pandora session handlers // TODO: SAML should work with pandora session handlers.
if (db_get_value('value', 'tconfig', 'token', 'auth') != 'saml') { if (db_get_value('value', 'tconfig', 'token', 'auth') != 'saml') {
$result_handler = session_set_save_handler( $result_handler = session_set_save_handler(
'pandora_session_open', 'pandora_session_open',

View File

@ -50,6 +50,29 @@ if (type_graph_pdf == "combined") {
var page = require("webpage").create(); var page = require("webpage").create();
page.onResourceError = function(resourceError) {
console.log(
"Unable to load resource (#" +
resourceError.id +
"URL:" +
resourceError.url +
")"
);
console.log(
"Error code: " +
resourceError.errorCode +
". Description: " +
resourceError.errorString
);
phantom.exit(1);
};
// Not supposed to be prompted messages.
page.onPrompt = function() {
console.log("Prompt message detected.");
phantom.exit(1);
};
page.viewportSize = { page.viewportSize = {
width: viewport_width, width: viewport_width,
height: viewport_height height: viewport_height
@ -84,3 +107,21 @@ page.open(url, "POST", post_data, function(status) {
phantom.exit(); phantom.exit();
} }
}); });
phantom.onError = function(msg, trace) {
var msgStack = ["PHANTOM ERROR: " + msg];
if (trace && trace.length) {
msgStack.push("TRACE:");
trace.forEach(function(t) {
msgStack.push(
" -> " +
(t.file || t.sourceURL) +
": " +
t.line +
(t.function ? " (in function " + t.function + ")" : "")
);
});
}
console.log(msgStack.join("\n"));
phantom.exit(1);
};

View File

@ -3258,7 +3258,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$$$) {
'custom_id' => $custom_id, 'custom_id' => $custom_id,
'url_address' => $url_address, 'url_address' => $url_address,
'timezone_offset' => $timezone_offset, 'timezone_offset' => $timezone_offset,
'alias' => $alias, 'alias' => safe_input($alias),
'update_module_count' => 1, # Force to replicate in metaconsole 'update_module_count' => 1, # Force to replicate in metaconsole
}); });