Public access using PublicLogin interface

This commit is contained in:
fbsanchez 2021-05-19 11:57:17 +02:00
parent 09ccaf254e
commit 538e7beb48
5 changed files with 43 additions and 17 deletions

View File

@ -1151,7 +1151,9 @@ function dashboardLoadVC(settings) {
300 * 1000, 300 * 1000,
handleUpdate, handleUpdate,
beforeUpdate, beforeUpdate,
settings.size settings.size,
settings.id_user,
settings.hash
); );
} }

View File

@ -1,5 +1,5 @@
// TODO: Add Artica ST header. // TODO: Add Artica ST header.
/* globals jQuery, VisualConsole, AsyncTaskManager, hash, id_user */ /* globals jQuery, VisualConsole, AsyncTaskManager */
/* /*
* ********************* * *********************
@ -17,6 +17,9 @@
* @param {function | null} onUpdate Callback which will be execuded when the Visual Console. * @param {function | null} onUpdate Callback which will be execuded when the Visual Console.
* is updated. It will receive two arguments with the old and the new Visual Console's * is updated. It will receive two arguments with the old and the new Visual Console's
* data structure. * data structure.
* @param {string|null} id_user User id given for public access.
* @param {string|null} hash Authorization hash given for public access.
*
* @return {VisualConsole | null} The Visual Console instance or a null value. * @return {VisualConsole | null} The Visual Console instance or a null value.
*/ */
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -28,7 +31,9 @@ function createVisualConsole(
updateInterval, updateInterval,
onUpdate, onUpdate,
beforeUpdate, beforeUpdate,
size size,
id_user,
hash
) { ) {
if (container == null || props == null || items == null) return null; if (container == null || props == null || items == null) return null;
if (baseUrl == null) baseUrl = ""; if (baseUrl == null) baseUrl = "";
@ -46,6 +51,8 @@ function createVisualConsole(
baseUrl, baseUrl,
visualConsoleId, visualConsoleId,
size, size,
id_user,
hash,
function(error, data) { function(error, data) {
if (error) { if (error) {
//Remove spinner change VC. //Remove spinner change VC.
@ -651,6 +658,8 @@ function createVisualConsole(
* Fetch a Visual Console's structure and its items. * Fetch a Visual Console's structure and its items.
* @param {string} baseUrl Base URL to build the API path. * @param {string} baseUrl Base URL to build the API path.
* @param {number} vcId Identifier of the Visual Console. * @param {number} vcId Identifier of the Visual Console.
* @param {string|null} id_user User id given for public access.
* @param {string|null} hash Authorization hash given for public access.
* @param {function} callback Function to be executed on request success or fail. * @param {function} callback Function to be executed on request success or fail.
* On success, the function will receive an object with the next properties: * On success, the function will receive an object with the next properties:
* - `props`: object with the Visual Console's data structure. * - `props`: object with the Visual Console's data structure.
@ -658,7 +667,7 @@ function createVisualConsole(
* @return {Object} Cancellable. Object which include and .abort([statusText]) function. * @return {Object} Cancellable. Object which include and .abort([statusText]) function.
*/ */
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function loadVisualConsoleData(baseUrl, vcId, size, callback) { function loadVisualConsoleData(baseUrl, vcId, size, id_user, hash, callback) {
// var apiPath = baseUrl + "/include/rest-api"; // var apiPath = baseUrl + "/include/rest-api";
var apiPath = baseUrl + "/ajax.php"; var apiPath = baseUrl + "/ajax.php";
var vcJqXHR = null; var vcJqXHR = null;
@ -721,8 +730,8 @@ function loadVisualConsoleData(baseUrl, vcId, size, callback) {
page: "include/rest-api/index", page: "include/rest-api/index",
getVisualConsole: 1, getVisualConsole: 1,
visualConsoleId: vcId, visualConsoleId: vcId,
id_user: id_user, id_user: typeof id_user == undefined ? id_user : null,
auth_hash: hash auth_hash: typeof hash == undefined ? hash : null
}, },
"json" "json"
) )
@ -738,8 +747,8 @@ function loadVisualConsoleData(baseUrl, vcId, size, callback) {
getVisualConsoleItems: 1, getVisualConsoleItems: 1,
size: size, size: size,
visualConsoleId: vcId, visualConsoleId: vcId,
id_user: id_user, id_user: typeof id_user == undefined ? id_user : null,
auth_hash: hash auth_hash: typeof hash == undefined ? hash : null
}, },
"json" "json"
) )

View File

@ -29,7 +29,7 @@
namespace PandoraFMS\Dashboard; namespace PandoraFMS\Dashboard;
// Load Visual Console. // Load Visual Console.
use Models\VisualConsole\Container as VisualConsole; use Models\VisualConsole\Container as VisualConsole;
use PandoraFMS\User;
/** /**
* Maps by users Widgets. * Maps by users Widgets.
*/ */
@ -498,6 +498,8 @@ class MapsMadeByUser extends Widget
'ratio' => $ratio_t, 'ratio' => $ratio_t,
'size' => $size, 'size' => $size,
'cellId' => $this->cellId, 'cellId' => $this->cellId,
'hash' => User::generatePublicHash(),
'id_user' => $config['id_user'],
] ]
); );

View File

@ -15,7 +15,11 @@
// The session is configured and started inside the config process. // The session is configured and started inside the config process.
require_once '../../include/config.php'; require_once '../../include/config.php';
// Set root on homedir, as defined in setup require_once $config['homedir'].'/vendor/autoload.php';
use PandoraFMS\User;
// Set root on homedir, as defined in setup.
chdir($config['homedir']); chdir($config['homedir']);
ob_start(); ob_start();
@ -61,10 +65,13 @@ $id_layout = (int) get_parameter('id_layout');
$graph_javascript = (bool) get_parameter('graph_javascript'); $graph_javascript = (bool) get_parameter('graph_javascript');
$config['id_user'] = get_parameter('id_user'); $config['id_user'] = get_parameter('id_user');
$myhash = md5($config['dbpass'].$id_layout.$config['id_user']); // Check input hash.
if (User::validatePublicHash($hash) !== true) {
// Check input hash db_pandora_audit(
if ($myhash != $hash) { 'Invalid public visual console',
'Trying to access public visual console'
);
include 'general/noaccess.php';
exit; exit;
} }

View File

@ -182,8 +182,6 @@ $visualConsoleItems = VisualConsole::getItemsFromDB(
var props = <?php echo (string) $visualConsole; ?>; var props = <?php echo (string) $visualConsole; ?>;
var items = <?php echo '['.implode($visualConsoleItems, ',').']'; ?>; var items = <?php echo '['.implode($visualConsoleItems, ',').']'; ?>;
var baseUrl = "<?php echo ui_get_full_url('/', false, false, false); ?>"; var baseUrl = "<?php echo ui_get_full_url('/', false, false, false); ?>";
var hash = "<?php echo get_parameter('hash', ''); ?>";
var id_user = "<?php echo get_parameter('id_user', ''); ?>";
var controls = document.getElementById('vc-controls'); var controls = document.getElementById('vc-controls');
autoHideElement(controls, 1000); autoHideElement(controls, 1000);
@ -266,7 +264,15 @@ $visualConsoleItems = VisualConsole::getItemsFromDB(
items, items,
baseUrl, baseUrl,
<?php echo ($refr * 1000); ?>, <?php echo ($refr * 1000); ?>,
handleUpdate handleUpdate,
// BeforeUpdate.
null,
// Size.
null,
// User id.
"<?php echo get_parameter('id_user', ''); ?>",
// Hash.
"<?php echo get_parameter('hash', ''); ?>"
); );
var controls = document.getElementById('vc-controls'); var controls = document.getElementById('vc-controls');