adding external link support to cacti

This commit is contained in:
cigamit committed 2016-07-10 19:02:09 -05:00
1 parent 61c59bb72c
commit 39af17cca8
19 files changed
+1095 -21

No files matched your search

+11
View File
@@ -1734,6 +1734,17 @@ INSERT INTO data_template_rrd VALUES (92,'165a0da5f461561c85d092dfe96b9551',0,0,
INSERT INTO data_template_rrd VALUES (95,'7a6ca455bbeff99ca891371bc77d5cf9',0,0,47,'','U','','0','',600,'',1,'','mem_cache','',0); INSERT INTO data_template_rrd VALUES (95,'7a6ca455bbeff99ca891371bc77d5cf9',0,0,47,'','U','','0','',600,'',1,'','mem_cache','',0);
INSERT INTO data_template_rrd VALUES (96,'224b83ea73f55f8a861bcf4c9bea0472',0,0,48,'on','100','','0','',600,'on',1,'','snmp_oid','',0); INSERT INTO data_template_rrd VALUES (96,'224b83ea73f55f8a861bcf4c9bea0472',0,0,48,'on','100','','0','',600,'on',1,'','snmp_oid','',0);
CREATE TABLE external_links (
id int(11) NOT NULL AUTO_INCREMENT,
sortorder int(11) NOT NULL DEFAULT '0',
enabled char(2) DEFAULT 'on',
contentfile varchar(255) NOT NULL default '',
title varchar(20) NOT NULL default '',
style varchar(10) NOT NULL DEFAULT '',
extendedstyle varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (id)
) ENGINE=InnoDB COMMENT='Contains pointers to external links that are embedded into Cacti';
-- --
-- Table structure for table `graph_local` -- Table structure for table `graph_local`
-- --
+7
View File
@@ -0,0 +1,7 @@
All the scripts in this folder are EXAMPLES.
They are just to show what you can do with a
little imagination and a little scripting.
They aren't end-products.
+2
View File
@@ -0,0 +1,2 @@
<h1>This is the content of my page</h1>
<p>This can be any HTML</p>
+3
View File
@@ -0,0 +1,3 @@
<p>A quick example of using iframes to embed another site (e.g. your Nagios, or some other app?). <a href="http://www.w3schools.com/tags/tag_iframe.asp">IFRAME docs</a></p>
<iframe width='100%' height='100%' frameborder="0" src="http://www.cacti.net/"></iframe>
+5
View File
@@ -0,0 +1,5 @@
<?php
header("Location:../index.php");
?>
+10
View File
@@ -0,0 +1,10 @@
Because it's being included via PHP, you can use PHP code too, which could contact a database, or cacti functions.
Here's the current time, courtesy of PHP:
<?php
echo date(DATE_RFC822);
?>
<hr>
Binary file not shown.
Binary file not shown.
+31 -11
View File
@@ -572,28 +572,28 @@ $custom_data_source_types = array(
); );
$menu = array( $menu = array(
'Create' => array( __('Create') => array(
'graphs_new.php' => __('New Graphs') 'graphs_new.php' => __('New Graphs')
), ),
'Management' => array( __('Management') => array(
'graphs.php' => __('Graphs'), 'graphs.php' => __('Graphs'),
'tree.php' => __('Trees'), 'tree.php' => __('Trees'),
'data_sources.php' => __('Data Sources'), 'data_sources.php' => __('Data Sources'),
'host.php' => __('Devices'), 'host.php' => __('Devices'),
'aggregate_graphs.php' => __('Aggregates'), 'aggregate_graphs.php' => __('Aggregates'),
), ),
'Collection Methods' => array( __('Collection Methods') => array(
'data_queries.php' => __('Data Queries'), 'data_queries.php' => __('Data Queries'),
'data_input.php' => __('Data Input Methods') 'data_input.php' => __('Data Input Methods')
), ),
'Templates' => array( __('Templates') => array(
'graph_templates.php' => __('Graph'), 'graph_templates.php' => __('Graph'),
'host_templates.php' => __('Device'), 'host_templates.php' => __('Device'),
'data_templates.php' => __('Data Source'), 'data_templates.php' => __('Data Source'),
'aggregate_templates.php' => __('Aggregate'), 'aggregate_templates.php' => __('Aggregate'),
'color_templates.php' => __('Color') 'color_templates.php' => __('Color')
), ),
'Automation' => array( __('Automation') => array(
'automation_networks.php' => __('Networks'), 'automation_networks.php' => __('Networks'),
'automation_devices.php' => __('Discovered Devices'), 'automation_devices.php' => __('Discovered Devices'),
'automation_templates.php' => __('Device Rules'), 'automation_templates.php' => __('Device Rules'),
@@ -601,21 +601,22 @@ $menu = array(
'automation_tree_rules.php' => __('Tree Rules'), 'automation_tree_rules.php' => __('Tree Rules'),
'automation_snmp.php' => __('SNMP Options'), 'automation_snmp.php' => __('SNMP Options'),
), ),
'Presets' => array( __('Presets') => array(
'data_source_profiles.php' => __('Data Profiles'), 'data_source_profiles.php' => __('Data Profiles'),
'cdef.php' => __('CDEFs'), 'cdef.php' => __('CDEFs'),
'vdef.php' => __('VDEFs'), 'vdef.php' => __('VDEFs'),
'color.php' => __('Colors'), 'color.php' => __('Colors'),
'gprint_presets.php' => __('GPRINTs') 'gprint_presets.php' => __('GPRINTs')
), ),
'Import/Export' => array( __('Import/Export') => array(
'templates_import.php' => __('Import Templates'), 'templates_import.php' => __('Import Templates'),
'templates_export.php' => __('Export Templates') 'templates_export.php' => __('Export Templates')
), ),
'Configuration' => array( __('Configuration') => array(
'settings.php' => __('Settings') 'settings.php' => __('Settings'),
'links.php' => __('External Links')
), ),
'Utilities' => array( __('Utilities') => array(
'utilities.php' => __('System Utilities'), 'utilities.php' => __('System Utilities'),
'user_admin.php' => __('Users'), 'user_admin.php' => __('Users'),
'user_group_admin.php' => __('User Groups'), 'user_group_admin.php' => __('User Groups'),
@@ -623,6 +624,23 @@ $menu = array(
) )
); );
if ((isset($_SESSION['sess_user_id']))) {
$consoles = db_fetch_assoc('SELECT id, title, extendedstyle
FROM external_links
WHERE style="CONSOLE"
AND enabled="on"
ORDER BY extendedstyle, sortorder, id');
if (sizeof($consoles)) {
foreach ($consoles as $page) {
if (is_realm_allowed($page['id']+10000)) {
$menuname = (isset($page['extendedstyle']) && $page['extendedstyle'] != '' ? $page['extendedstyle'] : __('External Links'));
$menu[$menuname]['link.php?id=' . $page['id']] = $page['title'];
}
}
}
}
$log_tail_lines = array( $log_tail_lines = array(
-1 => __('All Lines'), -1 => __('All Lines'),
10 => __('%d Lines', 10), 10 => __('%d Lines', 10),
@@ -698,6 +716,7 @@ $user_auth_realms = array(
8 => __('Console Access'), 8 => __('Console Access'),
7 => __('View Graphs'), 7 => __('View Graphs'),
20 => __('Update Profile'), 20 => __('Update Profile'),
24 => __('External Links'),
1 => __('User Management'), 1 => __('User Management'),
15 => __('Settings and Utilities'), 15 => __('Settings and Utilities'),
@@ -729,7 +748,7 @@ $user_auth_realms = array(
); );
$user_auth_roles = array( $user_auth_roles = array(
'Normal User' => array(7, 19, 20, 22), 'Normal User' => array(7, 19, 20, 22, 24),
'Template Editor' => array(8, 2, 9, 10, 11, 12, 13, 14, 16, 17), 'Template Editor' => array(8, 2, 9, 10, 11, 12, 13, 14, 16, 17),
'General Administration' => array(8, 3, 4, 5, 23, 1043), 'General Administration' => array(8, 3, 4, 5, 23, 1043),
'System Administration' => array(8, 15, 1, 18, 21, 101) 'System Administration' => array(8, 15, 1, 18, 21, 101)
@@ -764,6 +783,7 @@ $user_auth_realm_filenames = array(
'managers.php' => 15, 'managers.php' => 15,
'rrdcleaner.php' => 15, 'rrdcleaner.php' => 15,
'settings.php' => 15, 'settings.php' => 15,
'links.php' => 15,
'data_queries.php' => 13, 'data_queries.php' => 13,
'templates_export.php' => 16, 'templates_export.php' => 16,
'templates_import.php' => 17, 'templates_import.php' => 17,
+7
View File
@@ -339,6 +339,13 @@ $settings = array(
'default' => 'on', 'default' => 'on',
'method' => 'checkbox', 'method' => 'checkbox',
), ),
'hide_console' => array(
'friendly_name' => __('Hide Cacti Console'),
'description' => __('For use with Cacti\'s External Link Support. Using this setting, you can replace the Cacti Console with your own page.'),
'method' => 'drop_array',
'default' => 0,
'array' => array(0 => __('No'), 1 => __('Yes'))
),
'force_https' => array( 'force_https' => array(
'friendly_name' => __('Force Connections over HTTPS'), 'friendly_name' => __('Force Connections over HTTPS'),
'description' => __('When checked, any attempts to access Cacti will be redirected to HTTPS to insure high security.'), 'description' => __('When checked, any attempts to access Cacti will be redirected to HTTPS to insure high security.'),
+1 -1
View File
@@ -24,7 +24,7 @@
global $plugin_hooks, $plugins_integrated, $plugins; global $plugin_hooks, $plugins_integrated, $plugins;
$plugin_hooks = array(); $plugin_hooks = array();
$plugins_integrated = array('snmpagent', 'clog', 'settings', 'boost', 'dsstats', 'watermark', 'ssl', 'ugroup', 'domains', 'jqueryskin', 'secpass', 'logrotate', 'realtime', 'rrdclean', 'nectar', 'aggregate', 'autom8', 'discovery', 'spikekill'); $plugins_integrated = array('snmpagent', 'clog', 'settings', 'boost', 'dsstats', 'watermark', 'ssl', 'ugroup', 'domains', 'jqueryskin', 'secpass', 'logrotate', 'realtime', 'rrdclean', 'nectar', 'aggregate', 'autom8', 'discovery', 'spikekill', 'superlinks');
function use_plugin ($name) { function use_plugin ($name) {
global $config; global $config;
+50
View File
@@ -27,6 +27,36 @@ top_header();
api_plugin_hook('console_before'); api_plugin_hook('console_before');
function render_external_links($style = 'FRONT') {
global $config;
$consoles = db_fetch_assoc_prepared('SELECT * FROM external_links WHERE style = ?', array($style));
if (sizeof($consoles)) {
foreach($consoles as $page) {
if (is_realm_allowed($page['id']+10000)) {
if (preg_match('/^((((ht|f)tp(s?))\:\/\/){1}\S+)/i', $page['contentfile'])) {
print '<iframe class="content" src="' . $page['contentfile'] . '" frameborder="0"></iframe>';
} else {
print '<div id="content">';
$file = $config['base_path'] . "/include/content/" . $page['contentfile'];
if (file_exists($file)) {
include_once($file);
} else {
print '<h1>The file \'' . $page['contentfile'] . '\' does not exist!!</h1>';
}
print '</div>';
}
}
}
}
}
render_external_links('FRONTTOP');
if (read_config_option('hide_console') != '1') {
?> ?>
<table class='cactiTable'> <table class='cactiTable'>
<tr> <tr>
@@ -46,8 +76,28 @@ api_plugin_hook('console_before');
</table> </table>
<?php <?php
}
render_external_links('FRONT');
api_plugin_hook('console_after'); api_plugin_hook('console_after');
?>
<script type='text/javascript'>
$(function() {
resizeWindow();
$(window).resize(function() {
resizeWindow();
});
});
function resizeWindow() {
height = parseInt($('#navigation_right').height());
width = $('#main').width();
$('.content').css({'height':height+'px', 'width':width, 'margin-top':'-5px'});
}
</script>
<?php
bottom_footer(); bottom_footer();
+22
View File
@@ -1482,4 +1482,26 @@ function upgrade_to_1_0_0() {
$templates = implode(',', array_rekey(db_fetch_assoc('SELECT graph_template_id FROM plugin_spikekill_templates'), 'graph_template_id', 'graph_template_id')); $templates = implode(',', array_rekey(db_fetch_assoc('SELECT graph_template_id FROM plugin_spikekill_templates'), 'graph_template_id', 'graph_template_id'));
db_install_execute('1.0.0', "REPLACE INTO settings (name, value) VALUES('spikekill_templates','$templates')"); db_install_execute('1.0.0', "REPLACE INTO settings (name, value) VALUES('spikekill_templates','$templates')");
} }
// Migrate superlinks pages to new external links table
if (db_table_exists('superlinks_auth')) {
db_install_execute('1.0', 'RENAME TABLE superlinks_pages TO external_links');
db_install_execute('1.0', 'ALTER TABLE external_links DROP COLUMN imagecache');
db_install_execute('1.0', 'ALTER TABLE external_links ADD COLUMN enabled CHAR(2) default "on" AFTER disabled');
db_install_execute('1.0', 'UPDATE external_links SET enabled="on" WHERE disabled=""');
db_install_execute('1.0', 'UPDATE external_links SET enabled="" WHERE disabled="on"');
db_install_execute('1.0', 'DELETE FROM external_links WHERE style NOT IN ("TAB", "CONSOLE", "FRONT", "FRONTTOP")');
db_install_execute('1.0', 'ALTER TABLE external_links
DROP COLUMN disabled,
MODIFY COLUMN contentfile VARCHAR(255) NOT NULL default "",
MODIFY COLUMN title VARCHAR(20) NOT NULL default "",
MODIFY COLUMN style VARCHAR(10) NOT NULL default ""');
db_install_execute('1.0', 'DELETE FROM superlinks_auth WHERE pageid NOT IN(SELECT id FROM external_links)');
db_install_execute('1.0', 'INSERT INTO user_auth_realm (user_id, realm_id) SELECT userid, pageid+10000 FROM superlinks_auth');
db_install_execute('1.0', 'DROP TABLE superlinks_auth');
}
} }
+110 -1
View File
@@ -2717,12 +2717,20 @@ function draw_navigation_text($type = 'url') {
$tree_title = $tree_name . ($leaf_name != '' ? ' (' . $leaf_name:'') . ($leaf_sub != '' ? ':' . $leaf_sub . ')':($leaf_name != '' ? ')':'')); $tree_title = $tree_name . ($leaf_name != '' ? ' (' . $leaf_name:'') . ($leaf_sub != '' ? ':' . $leaf_sub . ')':($leaf_name != '' ? ')':''));
$current_nav .= "<li><a id='nav_title' href=#>" . htmlspecialchars($tree_title) . '</a></li></ul>'; $current_nav .= "<li><a id='nav_title' href=#>" . htmlspecialchars($tree_title) . '</a></li></ul>';
}elseif (preg_match('#link.php\?id=(\d+)#', $_SERVER['REQUEST_URI'], $matches)) {
$title = db_fetch_cell_prepared('SELECT title FROM external_links WHERE id = ?', array($matches[1]));
$tree_title = '';
if (isset($title)) {
$current_nav .= "<li><a id='link_title' href=#>" . htmlspecialchars($title) . '</a></li></ul>';
}else{
$current_nav .= '</ul>';
}
}else{ }else{
$current_nav .= '</ul>'; $current_nav .= '</ul>';
$tree_title = ''; $tree_title = '';
} }
$title .= htmlspecialchars(resolve_navigation_variables($current_array['title']) . ' ' . $tree_title); $title .= htmlspecialchars(resolve_navigation_variables($current_array['title']) . ' ' . $tree_title);
/* keep a cache for each level we encounter */ /* keep a cache for each level we encounter */
$nav_level_cache{$current_array['level']} = array('id' => $current_page . ':' . $current_action, 'url' => get_browser_query_string()); $nav_level_cache{$current_array['level']} = array('id' => $current_page . ':' . $current_action, 'url' => get_browser_query_string());
@@ -3942,3 +3950,104 @@ function get_timeinstate($host) {
return $days . 'd:' . $hours . 'h:' . $minutes . 'm'; return $days . 'd:' . $hours . 'h:' . $minutes . 'm';
} }
function get_classic_tabimage($text, $down = false) {
global $config;
$images = array(
false => 'tab_template_blue.gif',
true => 'tab_template_red.gif'
);
if ($text == '') return false;
$text = strtolower($text);
$possibles = array(
array('DejaVuSans-Bold.ttf', 9, true),
array('DejaVuSansCondensed-Bold.ttf', 9, false),
array('DejaVuSans-Bold.ttf', 9, false),
array('DejaVuSansCondensed-Bold.ttf', 9, false),
array('DejaVuSans-Bold.ttf', 8, false),
array('DejaVuSansCondensed-Bold.ttf', 8, false),
array('DejaVuSans-Bold.ttf', 7, false),
array('DejaVuSansCondensed-Bold.ttf', 7, true),
);
$y = 30;
$x = 44;
$wlimit = 72;
$wrapsize = 12;
if (file_exists($config['base_path'] . '/images/' . $images[$down])) {
$originalpath = getenv('GDFONTPATH');
putenv('GDFONTPATH="' . $config['base_path'] . '/include/fonts"');
$template = imagecreatefromgif($config['base_path'] . '/images/' . $images[$down]);
$w = imagesx($template);
$h = imagesy($template);
$tab = imagecreatetruecolor($w, $h);
imagecopy($tab, $template, 0, 0, 0, 0, $w, $h);
$txcol = imagecolorat($tab, 0, 0);
imagecolortransparent($tab,$txcol);
$white = imagecolorallocate($tab, 255, 255, 255);
foreach ($possibles as $variation) {
$font = $variation[0];
$fontsize = $variation[1];
$lines = array();
// if no wrapping is requested, or no wrapping is possible...
if((!$variation[2]) || ($variation[2] && strpos($text,' ') === false)) {
$bounds = imagettfbbox($fontsize, 0, $font, $text);
$w = $bounds[4] - $bounds[0];
$h = $bounds[1] - $bounds[5];
$realx = $x - $w/2 -1;
$lines[] = array($text, $font, $fontsize, $realx, $y);
$maxw = $w;
} else {
$texts = explode("\n", wordwrap($text, $wrapsize), 2);
$line = 1;
$maxw = 0;
foreach ($texts as $txt) {
$bounds = imagettfbbox($fontsize, 0, $font, $txt);
$w = $bounds[4] - $bounds[0];
$h = $bounds[1] - $bounds[5];
$realx = $x - $w/2 -1;
$realy = $y - $h * $line + 3;
$lines[] = array($txt, $font, $fontsize, $realx, $realy);
if ($maxw < $w) {
$maxw = $w;
}
$line--;
}
}
if($maxw<$wlimit) break;
}
foreach ($lines as $line) {
imagettftext($tab, $line[2], 0, $line[3], $line[4], $white, $line[1], $line[0]);
}
putenv('GDFONTPATH=' . $originalpath);
imagetruecolortopalette($tab, true, 256);
// generate the image an return the data directly
ob_start();
imagegif($image);
$image = ob_get_contents();
ob_end_clean();
return("data:image/gif;base64," . base64_encode($image));
}else{
return false;
}
}
+55 -5
View File
@@ -829,12 +829,20 @@ function draw_menu($user_menu = "") {
/* pass 1: see if we are allowed to view any children */ /* pass 1: see if we are allowed to view any children */
$show_header_items = false; $show_header_items = false;
foreach ($header_array as $item_url => $item_title) { foreach ($header_array as $item_url => $item_title) {
$current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0); if (preg_match('#link.php\?id=(\d+)#', $item_url, $matches)) {
if (is_realm_allowed($matches[1]+10000)) {
$show_header_items = true;
}else{
$show_header_items = false;
}
}else{
$current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0);
if (is_realm_allowed($current_realm_id)) { if (is_realm_allowed($current_realm_id)) {
$show_header_items = true; $show_header_items = true;
}elseif (api_user_realm_auth(strtok($item_url, '?'))) { }elseif (api_user_realm_auth(strtok($item_url, '?'))) {
$show_header_items = true; $show_header_items = true;
}
} }
} }
@@ -1074,6 +1082,33 @@ function html_show_tabs_left($show_console_tab) {
} }
} }
$external_links = db_fetch_assoc('SELECT id, title FROM external_links WHERE style="TAB" ORDER BY sortorder');
if (sizeof($external_links)) {
foreach($external_link_tabs as $tab) {
if (is_realm_allowed($tab['id']+10000)) {
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
$down = false;
if (trim($parsed_url['page'],'/') == 'link.php') {
if (!empty($parsed_url['query'])) {
$queries = explode('&', $parsed_url['query']);
foreach($queries as $q) {
list($var, $value) = explode('=', $q);
if ($var == 'id') {
if ($val == $tab['id']) {
$down = true;
break;
}
}
}
}
}
print '<a href="' . $config['url_path'] . 'link.php?id=' . $tab['id'] . '"><img src="' . get_classic_tabimage($tab['title'], $down) . '" alt="' . $tab['title'] . '"></a>';
}
}
}
api_plugin_hook('top_graph_header_tabs'); api_plugin_hook('top_graph_header_tabs');
}else{ }else{
if ($show_console_tab) { if ($show_console_tab) {
@@ -1110,6 +1145,21 @@ function html_show_tabs_left($show_console_tab) {
'url' => $config['url_path'] . (is_realm_allowed(18) ? 'clog.php':'clog_user.php'), 'url' => $config['url_path'] . (is_realm_allowed(18) ? 'clog.php':'clog_user.php'),
); );
$external_links = db_fetch_assoc('SELECT id, title FROM external_links WHERE style="TAB" ORDER BY sortorder');
if (sizeof($external_links)) {
foreach($external_links as $tab) {
if (is_realm_allowed($tab['id']+10000)) {
$tabs_left[] =
array(
'title' => $tab['title'],
'id' => 'maintab-anchor-link' . $tab['id'],
'image' => '',
'url' => $config['url_path'] . 'link.php?id=' . $tab['id']
);
}
}
}
// Get Plugin Text Out of Band // Get Plugin Text Out of Band
ob_start(); ob_start();
api_plugin_hook('top_graph_header_tabs'); api_plugin_hook('top_graph_header_tabs');
+65
View File
@@ -0,0 +1,65 @@
<?php
include_once("./include/global.php");
$page = db_fetch_row_prepared('SELECT
id, title, style, contentfile
FROM external_links AS el
WHERE id = ?', array(get_filter_request_var('id')));
if (!sizeof($page)) {
print 'FATAL: Page is not defined.';
} else {
global $link_nav;
if (is_realm_allowed($page['id']+10000)) {
unset ($refresh);
if ($page['style'] == 'TAB') {
$link_nav['link.php:']['title'] = $page['title'];
$link_nav['link.php:']['mapping'] = '';
general_header();
}else{
$link_nav['link.php:']['title'] = $page['title'];
$link_nav['link.php:']['mapping'] = 'index.php:';
top_header();
}
if (preg_match('/^((((ht|f)tp(s?))\:\/\/){1}\S+)/i', $page['contentfile'])) {
print '<iframe id="content" src="' . $page['contentfile'] . '" frameborder="0"></iframe>';
} else {
print '<div id="content">';
$file = $config['base_path'] . "/include/content/" . $page['contentfile'];
if (file_exists($file)) {
include_once($file);
} else {
print '<h1>The file \'' . $page['contentfile'] . '\' does not exist!!</h1>';
}
print '</div>';
}
}else{
print 'ERROR: Page is not authorized.';
}
?>
<script type='text/javascript'>
$(function() {
resizeWindow();
$(window).resize(function() {
resizeWindow();
});
});
function resizeWindow() {
height = parseInt($('#navigation_right').height());
width = $('#main').width();
$('#content').css({'height':height+'px', 'width':width, 'margin-top':'-5px'});
}
</script>
<?php
bottom_footer();
}
+611
View File
@@ -0,0 +1,611 @@
<?php
include_once('./include/auth.php');
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('order');
/* ==================================================== */
$link_actions = array(
1 => __('Delete'),
3 => __('Enable'),
2 => __('Disable')
);
set_default_action();
switch (get_request_var('action')) {
case 'actions':
form_actions();
break;
case 'delete_page':
if (isset_request_var('id') && get_filter_request_var('id')) {
page_delete(get_request_var('id'));
}
header('Location: links.php?header=false');
break;
case 'move_page_up':
if (isset_request_var('id') && get_filter_request_var('id') && isset_request_var('order') && get_filter_request_var('order')) {
page_move(get_request_var('id'), get_request_var('order'), '-1');
}
header('Location: links.php?header=false');
break;
case 'move_page_down':
if (isset_request_var('id') && get_filter_request_var('id') && isset_request_var('order') && get_filter_request_var('order')) {
page_move(get_request_var('id'), get_request_var('order'), '1');
}
header('Location: links.php?header=false');
break;
case 'save':
$save['id'] = isset_request_var('id') ? get_filter_request_var('id'):0;
$save['title'] = form_input_validate(get_nfilter_request_var('title'), 'title', '', false, 3);
$save['style'] = get_nfilter_request_var('style');
$save['enabled'] = (isset_request_var('enabled') ? 'on':'');
if (preg_match('/^((((ht|f)tp(s?))\:\/\/){1}\S+)/i', get_nfilter_request_var('fileurl')) && get_nfilter_request_var('filename') == '0') {
$save['contentfile'] = get_nfilter_request_var('fileurl');
} else {
$save['contentfile'] = preg_replace('/[^A-Za-z0-9_\.-]/','_', get_nfilter_request_var('filename'));
}
$consolesection = get_nfilter_request_var('consolesection');
$consolenewsection = get_nfilter_request_var('consolenewsection');
$extendedstyle = '';
if ($style == 'CONSOLE') {
if ($consolesection == '__NEW__') {
$extendedstyle = $consolenewsection;
}else{
$extendedstyle = $consolesection;
}
if ($extendedstyle == '') {
$extendedstyle = __('External Links');
}
}
$save['extendedstyle'] = $extendedstyle;
if (!is_error_message()){
$id = sql_save($save, 'external_links');
// always give the login account access
db_execute_prepared('REPLACE INTO user_auth_realm (user_id, realm_id) VALUES (?, ?)', array($_SESSION['sess_user_id'], $id+10000));
raise_message(1);
header('Location: links.php');
exit;
}else{
raise_message(2);
header('Location: links.php?action=edit&header=false&id=' . (isset_request_var('id') ? get_filter_request_var('id'):''));
exit;
}
break;
case 'edit':
top_header();
edit_page();
bottom_footer();
break;
default:
top_header();
pages();
bottom_footer();
break;
}
function form_actions() {
global $actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action');
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if ($_POST['drp_action'] == '3') { /* Enable Page */
for ($i=0;($i<count($selected_items));$i++) {
db_execute_prepared("UPDATE external_links SET enabled='on' WHERE id = ?", array($selected_items[$i]));
}
}elseif ($_POST['drp_action'] == '2') { /* Disable Page */
for ($i=0;($i<count($selected_items));$i++) {
db_execute_prepared("UPDATE external_links SET enabled='' WHERE id = ?", array($selected_items[$i]));
}
}elseif ($_POST['drp_action'] == '1') { /* Delete Page */
for ($i=0;($i<count($selected_items));$i++) {
db_execute_prepared('DELETE FROM external_links WHERE id = ?', array($selected_items[$i]));
db_execute_prepared('DELETE FROM user_auth_realm WHERE realm_id = ?', array($selected_items[$i]+10000));
db_execute_prepared('DELETE FROM user_auth_group_realm WHERE realm_id = ?', array($selected_items[$i]+10000));
}
}
}
header('Location: links.php?header=false');
exit;
}
/* setup some variables */
$page_list = ''; $i = 0;
/* loop through each of the pages selected on the previous page and get more info about them */
while (list($var,$val) = each($_POST)) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$page_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT title FROM external_links WHERE id = ?', array($matches[1]))) . '</li>';
$pages[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('links.php');
html_start_box($actions[get_request_var_post('drp_action')], '60%', '', '3', 'center', '');
if (isset($pages) && sizeof($pages)) {
if (get_request_var('drp_action') == '3') { /* Enable Pages */
print "<tr>
<td colspan='2' class='textArea'>
<p>" . __('Click \'Continue\' to Enable the following Page(s).') . "</p>
<ul>" . $page_list . "</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Enable Page(s)') . "'>";
}elseif (get_request_var('drp_action') == '2') { /* Disable Pages */
print "<tr>
<td colspan='2' class='textArea'>
<p>" . __('Click \'Continue\' to Disable the following Page(s).') . "</p>
<ul>" . $page_list . "</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disable Page(s)') . "'>";
}elseif (get_request_var('drp_action') == '1') { /* Delete Pages*/
print "<tr>
<td colspan='2' class='textArea'>
<p>" . __('Click \'Continue\' to Delete the following Page(s).') . "</p>
<ul>" . $page_list . "</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Page(s)') . "'>";
}
}else{
print "<tr><td><span class='textError'>" . __('You must select at least one page.') . "</span></td></tr>\n";
$save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
}
print "<tr class='saveRow'>
<td>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($pages) ? serialize($pages) : '') . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>
$save_html
</td>
</tr>\n";
html_end_box();
form_end();
bottom_footer();
}
function pages() {
global $item_rows, $config, $link_actions;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'sortorder',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_links');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
}else{
$rows = get_request_var('rows');
}
?>
<script type='text/javascript'>
function applyFilter() {
strURL = 'links.php?rows=' + $('#rows').val();
strURL += '&filter=' + $('#filter').val();
strURL += '&header=false';
loadPageNoHeader(strURL);
}
function clearFilter() {
strURL = 'links.php?clear=true&header=false';
loadPageNoHeader(strURL);
}
$(function() {
$('#links').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
</script>
<?php
html_start_box(__('External Links'), '100%', '', '3', 'center', 'links.php?action=edit');
?>
<tr class='even noprint'>
<td>
<form id='links' action='links.php' method='post'>
<table class='filterTable' cellpadding='2' cellspacing='0'>
<tr>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='textbox' id='filter' value='<?php print $_REQUEST['filter'];?>' size='25'>
</td>
<td>
<?php print __('Links');?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<option value=-1 <?php $_REQUEST['rows'] == -1 ? 'selected':'';?>><?php print __('Default');?></option>
<?php
foreach ($item_rows as $key => $row) {
echo "<option value='" . $key . "'" . ($key == $_REQUEST['rows'] ? ' selected' : '') . '>' . $row . '</option>';
}
?>
</select>
</td>
<td>
<input type='button' name='go' value='<?php print __('Go');?>' title='<?php print __('Apply Filter');?>' onClick='applyFilter()'>
</td>
<td>
<input type='button' name='clear' value='<?php print __('Clear');?>' title='<?php print __('Reset filters');?>' onClick='clearFilter()'>
</td>
</tr>
</table>
<input type='hidden' id='page' value='<?php print get_filter_request_var('page');?>'>
</form>
</td>
</tr>
<?php
html_end_box();
$style_translate = array(
'CONSOLE' => __('Console Menu'),
'TAB' => __('Top Tab'),
'FRONT' => __('Bottom of Console Page'),
'FRONTTOP' => __('Top of Console Page')
);
if (strlen(get_request_var('filter'))) {
$sql_where = " WHERE title LIKE '%" . get_request_var('filter') . "%' OR contentfile LIKE '%" . get_request_var('filter') . "%'";
}else{
$sql_where = '';
}
$limit = ' LIMIT ' . ($rows*(get_request_var('page') - 1)) . ", $rows";
$sort = ' ORDER BY ' . get_request_var('sort_column') . ' ' . (get_request_var('sort_colomn') == 'sortorder' ? 'ASC':get_request_var('sort_direction'));
$pages = db_fetch_assoc("SELECT *
FROM external_links
$sql_where
$sort
$limit");
$total_rows = db_fetch_cell('SELECT COUNT(*) FROM external_links');
form_start('links.php');
$nav = html_nav_bar('links.php', MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 8, __('External Links'), 'page', 'main');
print $nav;
html_start_box('', '100%', '', '4', 'center', '');
$display_text = array(
'nosort0' => array('display' => __('Actions'), 'align' => 'left', 'sort' => ''),
'contentfile' => array('display' => __('Page'), 'align' => 'left', 'sort' => 'ASC'),
'title' => array('display' => __('Title'), 'align' => 'left', 'sort' => 'ASC'),
'style' => array('display' => __('Style'), 'align' => 'left', 'sort' => 'ASC'),
'disabled' => array('display' => __('Enabled'), 'align' => 'left', 'sort' => 'ASC'),
'sortorder' => array('display' => __('Order'), 'align' => 'left', 'sort' => 'ASC')
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
$i = 0;
if (sizeof($pages)) {
foreach ($pages as $page) {
form_alternate_row('line' . $page['id']);
$actions = '<a class="pic" href="' . htmlspecialchars('links.php?action=edit&id='.$page['id']) . '" title="' . __('Edit Page') . '"><img src="' . $config['url_path'] . 'images/application_edit.png" alt=""></a>';
if ($page['enabled'] == 'on') {
$actions .= '<a class="pic" href="' . htmlspecialchars('link.php?id=' . $page['id']) . '" title="' . __('View Page') . '"><img src="' . $config['url_path'] . 'images/view_page.png" alt=""></a>';
}
form_selectable_cell($actions, $page['id'], '50');
form_selectable_cell(htmlspecialchars($page['contentfile']), $page['id']);
form_selectable_cell(htmlspecialchars($page['title']), $page['id']);
form_selectable_cell(htmlspecialchars($style_translate[$page['style']]) . ($page['style'] == 'CONSOLE' ? ' (' . $page['extendedstyle'].')':''), $page['id']);
form_selectable_cell(($page['enabled'] == 'on' ? 'Yes':'No'), $page['id']);
if (get_request_var('sort_column') == 'sortorder') {
if ($i != 0) {
$sort = '<a class="pic" href="' . htmlspecialchars('links.php?action=move_page_up&order=' . $page['sortorder'] . '&id='.$page['id']) . '"><img src="' . $config['url_path'] . 'images/move_up.gif" alt="" align="absmiddle"></a>';
}else{
$sort = '<img style="padding:2px;" src="' . $config['url_path'] . 'images/view_none.gif" alt="" align="absmiddle">';
}
if ($i == sizeof($pages)-1) {
$sort .= '<img src="' . $config['url_path'] . 'images/view_none.gif" alt="" align="absmiddle">';
}else{
$sort .= '<a class="pic" href="' . htmlspecialchars('links.php?action=move_page_down&order=' . $page['sortorder'] . '&id=' . $page['id']) . '"><img src="' . $config['url_path'] . 'images/move_down.gif" alt="" align="absmiddle"></a>';
}
form_selectable_cell($sort, $page['id']);
}else{
form_selectable_cell(__('Sort for Ordering'), $page['id']);
}
form_checkbox_cell($page['title'], $page['id']);
form_end_row();
$i++;
}
}else{
print "<tr><td><em>" . __('No Pages Found') . "</em></td></tr>\n";
}
html_end_box(false);
if (sizeof($pages)) {
print $nav;
}
draw_actions_dropdown($link_actions);
form_end();
}
function page_delete($id) {
db_execute_prepared('DELETE FROM external_links WHERE id = ?', array($id));
db_execute_prepared('DELETE FROM user_auth_realm WHERE real_id = ?', array($id+10000));
db_execute_prepared('DELETE FROM user_auth_group_realm WHERE real_id = ?', array($id+10000));
page_resort();
}
function page_resort() {
$pages = db_fetch_assoc("SELECT * FROM external_links ORDER BY sortorder");
$i = 1;
if (sizeof($pages)) {
foreach ($pages as $page) {
db_execute_prepared('UPDATE external_links SET sortorder = ? WHERE id = ?' . array($id, $page['id']));
$i++;
}
}
}
function page_move($pageid, $junk, $direction) {
$oldorder = db_fetch_cell_prepared('SELECT sortorder FROM external_links WHERE id = ?', array($pageid));
$neworder = $oldorder + $direction;
$otherid = db_fetch_cell_prepared('SELECT id FROM external_links WHERE sortorder = ?', array($neworder));
if (!empty($otherid)) {
db_execute_prepared('UPDATE external_links SET sortorder = ? WHERE id = ?', array($neworder, $pageid));
db_execute_prepared('UPDATE external_links SET sortorder = ? WHERE id = ?', array($oldorder, $otherid));
}
}
function edit_page() {
global $config;
$sections = db_fetch_assoc("SELECT extendedstyle
FROM external_links
WHERE style='CONSOLE'
GROUP BY extendedstyle
ORDER BY extendedstyle");
$sec_ar = array();
$sec_ar['External Links'] = __('External Links');
foreach ($sections as $sec) {
if ($sec['extendedstyle'] !='') {
$sec_ar[$sec['extendedstyle']] = $sec['extendedstyle'];
}
}
$sec_ar['__NEW__'] = 'New Name Below';
if (isset_request_var('id')) {
$data = db_fetch_row_prepared('SELECT * FROM external_links WHERE id = ?', array(get_filter_request_var('id')));
}else{
$data = array();
}
$field_array = array(
'id' => array(
'friendly_name' => __('Style'),
'method' => 'hidden',
'value' => isset_request_var('id') ? get_request_var('id'):0
),
'style' => array(
'friendly_name' => __('Style'),
'method' => 'drop_array',
'array' => array(
'TAB' => __('Top Tab'),
'CONSOLE' => __('Console Menu'),
'FRONT' => __('Bottom of Console Page'),
'FRONTTOP' => __('Top of Console Page')
),
'description' => __('Where should this page appear?'),
'value' => (isset($data['style']) ? $data['style']:'')
),
'consolesection' => array(
'friendly_name' => __('Console Menu Section'),
'method' => 'drop_array',
'array' => $sec_ar,
'description' => __('Under which Console heading should this item appear?
(All SuperLinks menus will appear between Configuration and Utilities)'),
'value' => (isset($data['extendedstyle']) ? $data['extendedstyle']:'')
),
'consolenewsection' => array(
'friendly_name' => __('--> New Console Section'),
'method' => 'textbox',
'max_length' => 20,
'description' => __('If you don\'t like any of the choices above, type a new title in here.'),
'value' => (isset($data['extendedstyle']) ? $data['extendedstyle']:'')
),
'title' => array(
'friendly_name' => __('Tab/Menu Name'),
'method' => 'textbox',
'max_length' => 20,
'description' => __('The text that will appear in the tab or menu.'),
'value' => (isset($data['title']) ? $data['title']:'')
),
'filename' => array(
'friendly_name' => __('Content File/URL'),
'method' => 'drop_files',
'directory' => $config['base_path'] . '/include/content',
'exclusions' => array('README', 'index.php'),
'none_value' => __('Web URL Below'),
'description' => __('The file that contains the content for this page. This can be a file in Cacti /include/content/ directory or a valid Website URL.'),
'value' => (isset($data['contentfile']) ? $data['contentfile']:'')
),
'fileurl' => array(
'friendly_name' => __('Web URL Location'),
'method' => 'textbox',
'description' => __('The valid URL to use as an external link. Must include the type, for example http:// or https://.'),
'max_length' => 255,
'size' => 80,
'default' => 'http://www.cacti.net',
'value' => (isset($data['contentfile']) ? $data['contentfile']:'')
),
'enabled' => array(
'friendly_name' => 'Do you want this page enabled',
'method' => 'checkbox',
'description' => "If you wish this page to be viewable immediately, please check the checkbox.",
'default' => 'on',
'value' => (isset($data['enabled']) ? 'on':'')
),
);
form_start('links.php');
if (isset($data['title'])) {
html_start_box(__('External Links [edit: %s]', $data['title']), '100%', '', '3', 'center', '');
}else{
html_start_box(__('External Links [new]'), '100%', '', '3', 'center', '');
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => $field_array
)
);
html_end_box();
form_save_button('links.php', 'save');
?>
<script type='text/javascript'>
$(function() {
// hide and show the extra console fields when necessary
$('#style').change(function() {
if ($('#style').val() != 'CONSOLE') {
$('#row_consolesection').hide();
$('#row_consolenewsection').hide();
} else {
$('#row_consolesection').show();
$('#row_consolenewsection').show();
}
}).change();
$('#filename').change(function() {
changeFilename();
}).change();
// if you change the section, make the 'new' textbox reflect it
// if you change it to 'new', then clear the textbox, and jump to it
$('#consolesection').change( function() {
if ($(this).val() == '__NEW__') {
$('#consolenewsection').val('').focus();
} else {
$('#consolenewsection').val($(this).val());
}
});
// if you just start typing in there, then change the combo to 'New'
$('#consolenewsection').change( function() {
$('#consolesection').val('__NEW__');
});
});
function changeFilename() {
if ($('#filename').val() == 0) {
$('#row_fileurl').show();
}else{
$('#row_fileurl').hide();
}
}
</script>
<?php
}
// vim:ts=4:sw=4:
?>
+54 -3
View File
@@ -1460,9 +1460,9 @@ function user_realms_edit($header_label) {
$all_realms = $user_auth_realms; $all_realms = $user_auth_realms;
print " <tr class='cactiTableTitle'> print " <tr class='cactiTable'>
<td class='textHeaderDark'><strong>" . __('User Permissions') . "</strong> $header_label</td> <td class='cactiTableTitle'>" . __('User Permissions') . " $header_label</td>
<td class='tableHeader' style='width:1%;text-align:center;'><input class='checkbox' type='checkbox' name='all' title='" . __('Select All') . "' onClick='selectAllRealms(this.checked)'></td>\n <td class='cactiTableButton' style='text-align:right;padding-bottom:5px;'><input class='checkbox' type='checkbox' name='all' title='" . __('Select All') . "' onClick='selectAllRealms(this.checked)'></td>\n
</tr>\n"; </tr>\n";
/* do cacti realms first */ /* do cacti realms first */
@@ -1513,6 +1513,57 @@ function user_realms_edit($header_label) {
print "</table></td></tr>\n"; print "</table></td></tr>\n";
} }
/* external links */
$links = db_fetch_assoc('SELECT * FROM external_links ORDER BY sortorder');
$style_translate = array(
'CONSOLE' => __('Console Menu'),
'TAB' => __('Top Tab'),
'FRONT' => __('Bottom of Console Page'),
'FRONTTOP' => __('Top of Console Page')
);
print "<tr class='tableHeader'><th colspan='2'>" . __('External Link Permissions') . "</th></tr>\n";
print "<tr class='odd'><td colspan='4'><table style='width:100%;'><tr><td class='realms'>\n";
if (sizeof($links)) {
$i = 1;
$j = 1;
foreach($links as $r) {
$break = false;
if ($j == 6) {
print "</tr><tr>\n";
$break = true;;
$j = 1;
}else{
$j++;
}
if ($break) {
print "</td><td class='realms'>\n";
}
$realm = $r['id'] + 10000;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE user_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
}else{
$old_value = '';
}
unset($all_realms[$realm]);
$description = $style_translate[$r['style']] . ' : ' . $r['title'] . ($r['style'] == 'CONSOLE' ? ' --> ' . $r['extendedstyle']:'');
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0)); print '<br>';
$i++;
}
print "</table></td></tr>\n";
}
/* do plugin realms */ /* do plugin realms */
$realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display $realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display
FROM plugin_config AS pc FROM plugin_config AS pc
+51
View File
@@ -1286,6 +1286,57 @@ function user_group_realms_edit($header_label) {
print "<script type='text/javascript'>function selectAllRealms(checked) { if (checked) { $('input[id^=\"section\"]').prop('checked', true); } else { $('input[id^=\"section\"]').prop('checked', false); } }</script>\n"; print "<script type='text/javascript'>function selectAllRealms(checked) { if (checked) { $('input[id^=\"section\"]').prop('checked', true); } else { $('input[id^=\"section\"]').prop('checked', false); } }</script>\n";
/* external links */
$links = db_fetch_assoc('SELECT * FROM external_links ORDER BY sortorder');
$style_translate = array(
'CONSOLE' => __('Console Menu'),
'TAB' => __('Top Tab'),
'FRONT' => __('Bottom of Console Page'),
'FRONTTOP' => __('Top of Console Page')
);
print "<tr class='tableHeader'><th colspan='2'>" . __('External Link Permissions') . "</th></tr>\n";
print "<tr class='odd'><td colspan='4'><table style='width:100%;'><tr><td class='realms'>\n";
if (sizeof($links)) {
$i = 1;
$j = 1;
foreach($links as $r) {
$break = false;
if ($j == 6) {
print "</tr><tr>\n";
$break = true;;
$j = 1;
}else{
$j++;
}
if ($break) {
print "</td><td class='realms'>\n";
}
$realm = $r['id'] + 10000;
if (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_group_realm WHERE group_id = ? AND realm_id = ?', array(get_request_var('id', 0), $realm))) > 0) {
$old_value = 'on';
}else{
$old_value = '';
}
unset($all_realms[$realm]);
$description = $style_translate[$r['style']] . ' : ' . $r['title'] . ($r['style'] == 'CONSOLE' ? ' --> ' . $r['extendedstyle']:'');
form_checkbox('section' . $realm, $old_value, $description, '', '', '', (!isempty_request_var('id') ? 1 : 0)); print '<br>';
$i++;
}
print "</table></td></tr>\n";
}
/* do plugin realms */ /* do plugin realms */
$realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display $realms = db_fetch_assoc('SELECT pc.name, pr.id AS realm_id, pr.display
FROM plugin_config AS pc FROM plugin_config AS pc