Visual Console Refactor: simplified code

Former-commit-id: 5b2f2e91733b99f8c5f18a8e34b7cec18101c242
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-09 16:36:31 +02:00
parent 54c9ac82fd
commit 0e74c8f894
2 changed files with 63 additions and 195 deletions

View File

@ -13,7 +13,7 @@
// GNU General Public License for more details.
global $config;
$legacy = (bool) get_parameter('legacy', false);
$legacy = (bool) get_parameter('legacy');
if ($legacy === false) {
include_once $config['homedir'].'/operation/visual_console/view.php';
return;

View File

@ -19,10 +19,11 @@ check_login();
require_once $config['homedir'].'/vendor/autoload.php';
require_once $config['homedir'].'/include/functions_visual_map.php';
$id_layout = (int) get_parameter(!is_metaconsole() ? 'id' : 'id_visualmap');
// Query parameters.
$visualConsoleId = (int) get_parameter(!is_metaconsole() ? 'id' : 'id_visualmap');
$pure = (bool) get_parameter('pure', $config['pure']);
// Get input parameter for layout id.
if (!$id_layout) {
if (!$visualConsoleId) {
db_pandora_audit(
'ACL Violation',
'Trying to access visual console without id layout'
@ -31,8 +32,7 @@ if (!$id_layout) {
exit;
}
$layout = db_get_row('tlayout', 'id', $id_layout);
$layout = db_get_row('tlayout', 'id', $visualConsoleId);
if (!$layout) {
db_pandora_audit(
'ACL Violation',
@ -42,15 +42,15 @@ if (!$layout) {
exit;
}
$id_group = $layout['id_group'];
$layout_name = $layout['name'];
$groupId = $layout['id_group'];
$visualConsoleName = $layout['name'];
// ACL.
$vconsole_read = check_acl($config['id_user'], $id_group, 'VR');
$vconsole_write = check_acl($config['id_user'], $id_group, 'VW');
$vconsole_manage = check_acl($config['id_user'], $id_group, 'VM');
$aclRead = check_acl($config['id_user'], $groupId, 'VR');
$aclWrite = check_acl($config['id_user'], $groupId, 'VW');
$aclManage = check_acl($config['id_user'], $groupId, 'VM');
if (!$vconsole_read && !$vconsole_write && !$vconsole_manage) {
if (!$aclRead && !$aclWrite && !$aclManage) {
db_pandora_audit(
'ACL Violation',
'Trying to access visual console without group access'
@ -59,32 +59,22 @@ if (!$vconsole_read && !$vconsole_write && !$vconsole_manage) {
exit;
}
$refr = (int) get_parameter('refr', $config['vc_refr']);
$graph_javascript = (bool) get_parameter('graph_javascript', true);
$vc_refr = false;
if (isset($config['vc_refr']) && $config['vc_refr'] != 0) {
$view_refresh = $config['vc_refr'];
} else {
$view_refresh = '300';
}
// Render map.
$options = [];
$options['consoles_list']['text'] = '<a href="index.php?sec=network&sec2=godmode/reporting/map_builder&refr='.$refr.'">'.html_print_image(
$options['consoles_list']['text'] = '<a href="index.php?sec=network&sec2=godmode/reporting/map_builder">'.html_print_image(
'images/visual_console.png',
true,
['title' => __('Visual consoles list')]
).'</a>';
if ($vconsole_write || $vconsole_manage) {
if ($aclWrite || $aclManage) {
$url_base = 'index.php?sec=network&sec2=godmode/reporting/visual_console_builder&action=';
$hash = md5($config['dbpass'].$id_layout.$config['id_user']);
$hash = md5($config['dbpass'].$visualConsoleId.$config['id_user']);
$options['public_link']['text'] = '<a href="'.ui_get_full_url(
'operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$id_layout.'&id_user='.$config['id_user']
'operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$visualConsoleId.'&id_user='.$config['id_user']
).'" target="_blank">'.html_print_image(
'images/camera_mc.png',
true,
@ -92,43 +82,51 @@ if ($vconsole_write || $vconsole_manage) {
).'</a>';
$options['public_link']['active'] = false;
$options['data']['text'] = '<a href="'.$url_base.$action.'&tab=data&id_visual_console='.$id_layout.'">'.html_print_image(
$options['data']['text'] = '<a href="'.$url_base.$action.'&tab=data&id_visual_console='.$visualConsoleId.'">'.html_print_image(
'images/op_reporting.png',
true,
['title' => __('Main data')]
).'</a>';
$options['list_elements']['text'] = '<a href="'.$url_base.$action.'&tab=list_elements&id_visual_console='.$id_layout.'">'.html_print_image(
$options['list_elements']['text'] = '<a href="'.$url_base.$action.'&tab=list_elements&id_visual_console='.$visualConsoleId.'">'.html_print_image(
'images/list.png',
true,
['title' => __('List elements')]
).'</a>';
if (enterprise_installed()) {
$options['wizard_services']['text'] = '<a href="'.$url_base.$action.'&tab=wizard_services&id_visual_console='.$id_layout.'">'.html_print_image(
$options['wizard_services']['text'] = '<a href="'.$url_base.$action.'&tab=wizard_services&id_visual_console='.$visualConsoleId.'">'.html_print_image(
'images/wand_services.png',
true,
['title' => __('Services wizard')]
).'</a>';
}
$options['wizard']['text'] = '<a href="'.$url_base.$action.'&tab=wizard&id_visual_console='.$id_layout.'">'.html_print_image(
$options['wizard']['text'] = '<a href="'.$url_base.$action.'&tab=wizard&id_visual_console='.$visualConsoleId.'">'.html_print_image(
'images/wand.png',
true,
['title' => __('Wizard')]
).'</a>';
$options['editor']['text'] = '<a href="'.$url_base.$action.'&tab=editor&id_visual_console='.$id_layout.'">'.html_print_image(
$options['editor']['text'] = '<a href="'.$url_base.$action.'&tab=editor&id_visual_console='.$visualConsoleId.'">'.html_print_image(
'images/builder.png',
true,
['title' => __('Builder')]
).'</a>';
}
$options['view']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$view_refresh.'">'.html_print_image('images/operation.png', true, ['title' => __('View')]).'</a>';
$options['view']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$visualConsoleId.'">'.html_print_image('images/operation.png', true, ['title' => __('View')]).'</a>';
$options['view']['active'] = true;
if (!is_metaconsole()) {
if (!$config['pure']) {
$options['pure']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$refr.'&pure=1">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).'</a>';
ui_print_page_header($layout_name, 'images/visual_console.png', false, '', false, $options);
$options['pure']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$visualConsoleId.'&pure=1">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).'</a>';
ui_print_page_header(
$visualConsoleName,
'images/visual_console.png',
false,
'',
false,
$options
);
}
// Set the hidden value for the javascript.
@ -140,8 +138,9 @@ if (!is_metaconsole()) {
use Models\VisualConsole\Container as VisualConsole;
// TODO: Show an error message when the models can't be loaded.
$visualConsole = VisualConsole::fromArray($layout);
$visualConsoleItems = VisualConsole::getItemsFromDB($id_layout);
$visualConsoleItems = VisualConsole::getItemsFromDB($visualConsoleId);
// TODO: Extract to a function.
$vcClientPath = 'include/visual-console-client';
@ -174,69 +173,52 @@ if (is_dir($dir)) {
echo '<div id="visual-console-container" style="margin:0px auto;position:relative;"></div>';
if ($config['pure']) {
// Floating menu - Start
if ($pure === true) {
// Floating menu - Start.
echo '<div id="vc-controls" style="z-index: 999">';
echo '<div id="menu_tab">';
echo '<ul class="mn">';
// Quit fullscreen
// Quit fullscreen.
echo '<li class="nomn">';
echo '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$id_layout.'&refr='.$refr.'">';
echo '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$visualConsoleId.'">';
echo html_print_image('images/normal_screen.png', true, ['title' => __('Back to normal mode')]);
echo '</a>';
echo '</li>';
// Countdown
// Console name.
echo '<li class="nomn">';
echo '<div class="vc-refr">';
echo '<div class="vc-countdown"></div>';
echo '<div id="vc-refr-form">';
echo __('Refresh').':';
echo html_print_select(get_refresh_time_array(), 'refr', $refr, '', '', 0, true, false, false);
echo '</div>';
echo '</div>';
echo '</li>';
// Console name
echo '<li class="nomn">';
echo '<div class="vc-title">'.$layout_name.'</div>';
echo '<div class="vc-title">'.$visualConsoleName.'</div>';
echo '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
// Floating menu - End
ui_require_jquery_file('countdown');
// Floating menu - End.
?>
<style type="text/css">
/* Avoid the main_pure container 1000px height */
body.pure {
min-height: 100px;
margin: 0px;
overflow: hidden;
height: 100%;
<?php
echo 'background-color: '.$layout['background_color'].';';
?>
}
div#main_pure {
height: 100%;
margin: 0px;
<?php
echo 'background-color: '.$layout['background_color'].';';
?>
}
</style>
<style type="text/css">
/* Avoid the main_pure container 1000px height */
body.pure {
min-height: 100px;
margin: 0px;
overflow: hidden;
height: 100%;
<?php
echo 'background-color: '.$layout['background_color'].';';
?>
}
div#main_pure {
height: 100%;
margin: 0px;
<?php
echo 'background-color: '.$layout['background_color'].';';
?>
}
</style>
<?php
}
ui_require_javascript_file('wz_jsgraphics');
ui_require_javascript_file('pandora_visual_console');
$ignored_params['refr'] = '';
?>
<script type="text/javascript">
@ -253,122 +235,8 @@ $ignored_params['refr'] = '';
}
}
$(document).ready (function () {
var refr = <?php echo (int) $refr; ?>;
var pure = <?php echo (int) $config['pure']; ?>;
var href = "<?php echo ui_get_url_refresh($ignored_params); ?>";
if (pure) {
var startCountDown = function (duration, cb) {
$('div.vc-countdown').countdown('destroy');
if (!duration) return;
var t = new Date();
t.setTime(t.getTime() + duration * 1000);
$('div.vc-countdown').countdown({
until: t,
format: 'MS',
layout: '(%M%nn%M:%S%nn%S <?php echo __('Until refresh'); ?>) ',
alwaysExpire: true,
onExpiry: function () {
$('div.vc-countdown').countdown('destroy');
//cb();
url = js_html_entity_decode( href ) + duration;
$(document).attr ("location", url);
/*$.post(window.location.href.replace("refr=300","refr="+new_count), function(respuestaSolicitud){
$('#background_<?php echo $id_layout; ?>').html(respuestaSolicitud);
});
*/
$("#main_pure").css('background-color','<?php echo $layout['background_color']; ?>');
}
});
}
startCountDown(refr, false);
var controls = document.getElementById('vc-controls');
autoHideElement(controls, 1000);
$('select#refr').change(function (event) {
refr = Number.parseInt(event.target.value, 10);
new_count = event.target.value;
startCountDown(refr, false);
});
}
else {
$('#refr').change(function () {
$('#hidden-vc_refr').val($('#refr option:selected').val());
});
}
$(".module_graph .menu_graph").css('display','none');
$(".parent_graph").each( function() {
if ($(this).css('background-color') != 'rgb(255, 255, 255)')
$(this).css('color', '#999');
});
$(".overlay").removeClass("overlay").addClass("overlaydisabled");
});
$(window).on('load', function () {
$('.item:not(.icon) img:not(.b64img)').each( function() {
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
if( $(this).parent()[0].tagName == 'DIV'){
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
}
else if ( $(this).parent()[0].tagName == 'A') {
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
}
$(this).css('margin-left','');
}
else {
if(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2 < 0){
$(this).css('margin-left','');
$(this).css('margin-top','');
} else {
if( $(this).parent()[0].tagName == 'DIV'){
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
}
else if ( $(this).parent()[0].tagName == 'A') {
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
}
$(this).css('margin-top','');
}
}
});
$('.item > div').each( function() {
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
if($(this).attr('id').indexOf('clock') || $(this).attr('id').indexOf('overlay')){
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2)+'px');
}
else{
$(this).css('margin-top',(parseInt($(this).parent().css('height'))/2-parseInt($(this).css('height'))/2-15)+'px');
}
$(this).css('margin-left','');
}
else {
$(this).css('margin-left',(parseInt($(this).parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
$(this).css('margin-top','');
}
});
$('.item > a > div').each( function() {
if ($(this).css('float')=='left' || $(this).css('float')=='right') {
$(this).css('margin-top',(parseInt($(this).parent().parent().css('height'))/2-parseInt($(this).css('height'))/2-5)+'px');
$(this).css('margin-left','');
}
else {
$(this).css('margin-left',(parseInt($(this).parent().parent().css('width'))/2-parseInt($(this).css('width'))/2)+'px');
$(this).css('margin-top','');
}
});
$(".graph:not([class~='noresizevc'])").each(function(){
height = parseInt($(this).css("height")) - 30;
$(this).css('height', height);
});
$(document).ready(function () {
var controls = document.getElementById('vc-controls');
if (controls) autoHideElement(controls, 1000);
});
</script>