diff --git a/html/ajax_rulesuggest.php b/html/ajax_rulesuggest.php new file mode 100644 index 000000000..b4f410f4a --- /dev/null +++ b/html/ajax_rulesuggest.php @@ -0,0 +1,116 @@ + + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Rule Suggestion-AJAX + * @author Daniel Preussker + * @copyright 2014 f0o, LibreNMS + * @license GPL + * @package LibreNMS/Alerts + */ + +session_start(); +if( !isset($_SESSION['authenticated']) ) { + die("Unauthorized."); +} + +require_once("../includes/defaults.inc.php"); +require_once("../config.php"); +require_once("../includes/definitions.inc.php"); +require_once("../includes/functions.php"); + +/** + * Levenshtein Sort + * @param string $base Comparisson basis + * @param array $obj Object to sort + * @return array + */ +function levsort($base, $obj) { + $ret = array(); + foreach( $obj as $elem ) { + $lev = levenshtein($base, $elem, 1, 10, 10); + if( $lev == 0 ) { + return array(array('name'=>$elem)); + } else { + while( isset($ret["$lev"]) ) { + $lev += 0.1; + } + $ret["$lev"] = array('name'=>$elem); + } + } + ksort($ret); + return $ret; +} + +$obj = array(array('name'=>'Error: No suggestions found.')); +$term = array(); +$current = false; +if( isset($_GET['term'],$_GET['device_id']) ) { + $chk = array(); + $_GET['term'] = mres($_GET['term']); + $_GET['device_id'] = mres($_GET['device_id']); + if( strstr($_GET['term'],".") ) { + $term = explode(".",$_GET['term']); + if( $config['memcached']['enable'] ) { + $chk = $memcache->get('rule-suggest_'.$term[0]); + } + if( !(sizeof($chk) > 0) || $chk === false ) { + $tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]); + foreach( $tmp as $tst ) { + if( isset($tst['Field']) ) { + $chk[] = $term[0].'.'.$tst['Field']; + } + } + } + $current = true; + } else { + if( $config['memcached']['enable'] ) { + $chk = $memcache->get('rule-suggest-toplvl'); + } + if( !(sizeof($chk) > 0) || $chk === false ) { + $tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'"); + foreach( $tmp as $tst ) { + $chk[] = $tst['TABLE_NAME'].'.'; + } + } + } + if( sizeof($chk) > 0 ) { + if( $config['memcached']['enable'] ) { + $memcache->set('rule-suggest-'.$oterm,$chk,86400); //Cache for 24h + } + $obj = levsort($_GET['term'],$chk); + $obj = array_chunk($obj,20,true); + $obj = $obj[0]; + $flds = array(); + if( $current == true ) { + foreach( $obj as $fld ) { + $flds[] = $fld['name']; + } + $qry = dbFetchRows("SELECT ".implode(", ",$flds)." FROM ".$term[0]." WHERE device_id = ?", array($_GET['device_id'])); + $ret = array(); + foreach( $obj as $lev=>$fld ) { + list($tbl, $chk) = explode(".",$fld['name']); + $val = array(); + foreach( $qry as $row ) { + $val[] = $row[$chk]; + } + $ret[$lev] = array('name'=>$fld['name'],'current'=>$val); + } + $obj = $ret; + } + } +} +die(json_encode($obj)); +?> diff --git a/html/css/jquery-ui.min.css b/html/css/jquery-ui.min.css new file mode 100644 index 000000000..243792a75 --- /dev/null +++ b/html/css/jquery-ui.min.css @@ -0,0 +1,7 @@ +/*! jQuery UI - v1.11.2 - 2014-12-02 +* http://jqueryui.com +* Includes: core.css, autocomplete.css, menu.css, theme.css +* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Helvetica%2CArial%2Csans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=2px&bgColorHeader=dddddd&bgTextureHeader=highlight_soft&bgImgOpacityHeader=50&borderColorHeader=dddddd&fcHeader=444444&iconColorHeader=0073ea&bgColorContent=ffffff&bgTextureContent=flat&bgImgOpacityContent=75&borderColorContent=dddddd&fcContent=444444&iconColorContent=ff0084&bgColorDefault=f6f6f6&bgTextureDefault=highlight_soft&bgImgOpacityDefault=100&borderColorDefault=dddddd&fcDefault=0073ea&iconColorDefault=666666&bgColorHover=0073ea&bgTextureHover=highlight_soft&bgImgOpacityHover=25&borderColorHover=0073ea&fcHover=ffffff&iconColorHover=ffffff&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=dddddd&fcActive=ff0084&iconColorActive=454545&bgColorHighlight=ffffff&bgTextureHighlight=flat&bgImgOpacityHighlight=55&borderColorHighlight=cccccc&fcHighlight=444444&iconColorHighlight=0073ea&bgColorError=ffffff&bgTextureError=flat&bgImgOpacityError=55&borderColorError=ff0084&fcError=222222&iconColorError=ff0084&bgColorOverlay=eeeeee&bgTextureOverlay=flat&bgImgOpacityOverlay=0&opacityOverlay=80&bgColorShadow=aaaaaa&bgTextureShadow=flat&bgImgOpacityShadow=0&opacityShadow=60&thicknessShadow=4px&offsetTopShadow=-4px&offsetLeftShadow=-4px&cornerRadiusShadow=0px +* Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */ + +.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-clearfix{min-height:0}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important}.ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:none}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{position:relative;margin:0;padding:3px 1em 3px .4em;cursor:pointer;min-height:0;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-widget{font-family:Helvetica,Arial,sans-serif;font-size:1.1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Helvetica,Arial,sans-serif;font-size:1em}.ui-widget-content{border:1px solid #ddd;background:#fff url("images/ui-bg_flat_75_ffffff_40x100.png") 50% 50% repeat-x;color:#444}.ui-widget-content a{color:#444}.ui-widget-header{border:1px solid #ddd;background:#ddd url("images/ui-bg_highlight-soft_50_dddddd_1x100.png") 50% 50% repeat-x;color:#444;font-weight:bold}.ui-widget-header a{color:#444}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{border:1px solid #ddd;background:#f6f6f6 url("images/ui-bg_highlight-soft_100_f6f6f6_1x100.png") 50% 50% repeat-x;font-weight:bold;color:#0073ea}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited{color:#0073ea;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus{border:1px solid #0073ea;background:#0073ea url("images/ui-bg_highlight-soft_25_0073ea_1x100.png") 50% 50% repeat-x;font-weight:bold;color:#fff}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited{color:#fff;text-decoration:none}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active{border:1px solid #ddd;background:#fff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;font-weight:bold;color:#ff0084}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#ff0084;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #ccc;background:#fff url("images/ui-bg_flat_55_ffffff_40x100.png") 50% 50% repeat-x;color:#444}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#444}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #ff0084;background:#fff url("images/ui-bg_flat_55_ffffff_40x100.png") 50% 50% repeat-x;color:#222}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#222}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#222}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_ff0084_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_0073ea_256x240.png")}.ui-state-default .ui-icon{background-image:url("images/ui-icons_666666_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-active .ui-icon{background-image:url("images/ui-icons_454545_256x240.png")}.ui-state-highlight .ui-icon{background-image:url("images/ui-icons_0073ea_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_ff0084_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-carat-1-n{background-position:0 0}.ui-icon-carat-1-ne{background-position:-16px 0}.ui-icon-carat-1-e{background-position:-32px 0}.ui-icon-carat-1-se{background-position:-48px 0}.ui-icon-carat-1-s{background-position:-64px 0}.ui-icon-carat-1-sw{background-position:-80px 0}.ui-icon-carat-1-w{background-position:-96px 0}.ui-icon-carat-1-nw{background-position:-112px 0}.ui-icon-carat-2-n-s{background-position:-128px 0}.ui-icon-carat-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-64px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-64px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:0 -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:2px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:2px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:2px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:2px}.ui-widget-overlay{background:#eee url("images/ui-bg_flat_0_eeeeee_40x100.png") 50% 50% repeat-x;opacity:.8;filter:Alpha(Opacity=80)}.ui-widget-shadow{margin:-4px 0 0 -4px;padding:4px;background:#aaa url("images/ui-bg_flat_0_aaaaaa_40x100.png") 50% 50% repeat-x;opacity:.6;filter:Alpha(Opacity=60);border-radius:0} \ No newline at end of file diff --git a/html/css/styles.css b/html/css/styles.css index 9737051ed..da910be18 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1612,3 +1612,20 @@ tr.search:nth-child(odd) { width: 250px; } +.ui-autocomplete { + max-height: 100px; + overflow-y: auto; + overflow-x: hidden; +} + +/* IE 6 doesn't support max-height +* we use height instead, but this forces the menu to always be this tall +*/ +* html .ui-autocomplete { + height: 100px; +} + +.glyphicon-large { + font-size: 2.5em; +} + diff --git a/html/css/tagmanager.css b/html/css/tagmanager.css new file mode 100644 index 000000000..02e1de944 --- /dev/null +++ b/html/css/tagmanager.css @@ -0,0 +1,21 @@ +.tagmanagerTag { + background: none repeat scroll 0 0 #cde69c; + border: 1px solid #a5d24a; + border-radius: 3px; + color: #638421; + display: block; + float: left; + font-size: 13px; + margin-bottom: 5px; + margin-right: 5px; + padding: 6px 5px 5px 5px; + text-decoration: none; + vertical-align: middle; + line-height: 18px; + height: 30px; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; +} +.tagmanagerRemoveTag { + color: #c0c0c0; + padding-left: 8px; +} diff --git a/html/forms/ack-alert.inc.php b/html/forms/ack-alert.inc.php new file mode 100644 index 000000000..3f395c415 --- /dev/null +++ b/html/forms/ack-alert.inc.php @@ -0,0 +1,28 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$alert_id = mres($_POST['alert_id']); +if(!is_numeric($alert_id)) { + echo('ERROR: No alert selected'); + exit; +} else { + if(dbUpdate(array('state' => '2'), 'alerts', 'id=?',array($alert_id))) { + echo('Alert has been acknowledged.'); + exit; + } else { + echo('ERROR: Alert has not been acknowledged.'); + exit; + } +} + diff --git a/html/forms/alert-templates.inc.php b/html/forms/alert-templates.inc.php new file mode 100644 index 000000000..21afa02fd --- /dev/null +++ b/html/forms/alert-templates.inc.php @@ -0,0 +1,78 @@ + + * 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, either version 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Alert Templates + * @author f0o + * @copyright 2014 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Alerts + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$ok = ''; +$error = ''; +$name = mres($_POST['name']); +if(!empty($name)) { + if( is_numeric($_REQUEST['template_id']) && $_REQUEST['rule_id'] ) { + //Update the template/rule mapping + + if( is_array($_REQUEST['rule_id']) ) { + $_REQUEST['rule_id'] = implode(",",$_REQUEST['rule_id']); + } + if( substr($_REQUEST['rule_id'], 0,1) != "," ){ + $_REQUEST['rule_id'] = ",".$_REQUEST['rule_id']; + } + if( substr($_REQUEST['rule_id'],-1,1) != "," ){ + $_REQUEST['rule_id'] .= ","; + } + if(dbUpdate(array('rule_id' => mres($_REQUEST['rule_id']), 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) { + $ok = "Updated template and rule id mapping"; + } else { + $error ="Failed to update the template and rule id mapping"; + } + } elseif( $_REQUEST['template'] && is_numeric($_REQUEST['template_id']) ) { + //Update template-text + + if($ret = dbUpdate(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates", "id = ?", array($_REQUEST['template_id']))) { + $ok = "Updated template"; + } else { + $error = "Failed to update the template"; + } + } elseif( $_REQUEST['template'] ) { + //Create new template + + if(dbInsert(array('template' => $_REQUEST['template'], 'name' => $name), "alert_templates")) { + $ok = "Alert template has been created."; + } else { + $error = "Could not create aler template"; + } + } else { + $error = "We could not work out what you wanted to do!"; + } +} else { + $error = "You haven't given your template a name, it feels sad :( - $name"; +} + +if(!empty( $ok )) { + die("$ok"); +} else { + die("ERROR: $error"); +} +?> diff --git a/html/forms/attach-alert-template.inc.php b/html/forms/attach-alert-template.inc.php new file mode 100644 index 000000000..373cf8d84 --- /dev/null +++ b/html/forms/attach-alert-template.inc.php @@ -0,0 +1,31 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +if(!is_numeric($_POST['template_id'])) { + echo('ERROR: No template selected'); + exit; +} else { + if(dbUpdate(array('rule_id' => mres($_POST['rule_id'])), 'alert_templates', '`id`=?', array($_POST['template_id'])) >= 0) { + echo('Alert rules have been attached to this template.'); + exit; + } else { + echo('ERROR: Alert rules have not been attached to this template.'); + exit; + } +} + diff --git a/html/forms/create-alert-item.inc.php b/html/forms/create-alert-item.inc.php new file mode 100644 index 000000000..cc7cb2bb8 --- /dev/null +++ b/html/forms/create-alert-item.inc.php @@ -0,0 +1,58 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$rule = implode(" ", $_POST['rules']); +$rule = rtrim($rule,'&&'); +$rule = rtrim($rule,'||'); +$alert_id = $_POST['alert_id']; +$count = mres($_POST['count']); +$delay = mres($_POST['delay']); +$mute = mres($_POST['mute']); + +if(empty($rule)) { + $update_message = "ERROR: No rule was generated"; +} elseif(validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1') { + $device_id = $_POST['device_id']; + if(!is_numeric($count)) { + $count='-1'; + } + $delay_sec = convert_delay($delay); + if($mute == 'on') { + $mute = true; + } else { + $mute = false; + } + $extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec); + $extra_json = json_encode($extra); + if(is_numeric($alert_id) && $alert_id > 0) { + if(dbUpdate(array('rule' => $rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json), 'alert_rules', 'id=?',array($alert_id)) >= 0) { + $update_message = "Edited Rule: ".$rule.""; + } else { + $update_message = "ERROR: Failed to edit Rule: ".$rule.""; + } + } else { + if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json),'alert_rules') ) { + $update_message = "Added Rule: ".$rule.$mute.""; + } else { + $update_message = "ERROR: Failed to add Rule: ".$rule.""; + } + } +} else { + $update_message = "ERROR: invalid device ID or not a global alert"; +} +echo $update_message; diff --git a/html/forms/delete-alert-rule.inc.php b/html/forms/delete-alert-rule.inc.php new file mode 100644 index 000000000..a15b1edbe --- /dev/null +++ b/html/forms/delete-alert-rule.inc.php @@ -0,0 +1,31 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +if(!is_numeric($_POST['alert_id'])) { + echo('ERROR: No alert selected'); + exit; +} else { + if(dbDelete('alert_rules', "`id` = ?", array($_POST['alert_id']))) { + echo('Alert rule has been deleted.'); + exit; + } else { + echo('ERROR: Alert rule has not been deleted.'); + exit; + } +} + diff --git a/html/forms/delete-alert-template.inc.php b/html/forms/delete-alert-template.inc.php new file mode 100644 index 000000000..14ebd6c5b --- /dev/null +++ b/html/forms/delete-alert-template.inc.php @@ -0,0 +1,31 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +if(!is_numeric($_POST['template_id'])) { + echo('ERROR: No template selected'); + exit; +} else { + if(dbDelete('alert_templates', "`id` = ?", array($_POST['template_id']))) { + echo('Alert template has been deleted.'); + exit; + } else { + echo('ERROR: Alert template has not been deleted.'); + exit; + } +} + diff --git a/html/forms/parse-alert-rule.inc.php b/html/forms/parse-alert-rule.inc.php new file mode 100644 index 000000000..9f33138f0 --- /dev/null +++ b/html/forms/parse-alert-rule.inc.php @@ -0,0 +1,28 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$alert_id = $_POST['alert_id']; + +if(is_numeric($alert_id) && $alert_id > 0) { + $rule = dbFetchRow("SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1",array($alert_id)); + $rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\ \"\'\!\~]+[&&||]+)/',$rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $count = count($rule_split) - 1; + $rule_split[$count] = $rule_split[$count].'&&'; + $output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'rules'=>$rule_split); + echo _json_encode($output); +} diff --git a/html/forms/parse-alert-template.inc.php b/html/forms/parse-alert-template.inc.php new file mode 100644 index 000000000..a04104a8f --- /dev/null +++ b/html/forms/parse-alert-template.inc.php @@ -0,0 +1,25 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$template_id = ($_POST['template_id']); + +if(is_numeric($template_id) && $template_id > 0) { + $template = dbFetchRow("SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id)); + $output = array('template'=>$template['template'],'name'=>$template['name']); + echo _json_encode($output); +} diff --git a/html/forms/parse-template-rules.inc.php b/html/forms/parse-template-rules.inc.php new file mode 100644 index 000000000..736698e02 --- /dev/null +++ b/html/forms/parse-template-rules.inc.php @@ -0,0 +1,26 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +$template_id = ($_POST['template_id']); + +if(is_numeric($template_id) && $template_id > 0) { + $template = dbFetchCell("SELECT `rule_id` FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id)); + $rule_id = split(",", $template); + $output = array('rule_id'=>$rule_id); + echo _json_encode($output); +} diff --git a/html/forms/update-alert-rule.inc.php b/html/forms/update-alert-rule.inc.php new file mode 100644 index 000000000..9c8de3cbc --- /dev/null +++ b/html/forms/update-alert-rule.inc.php @@ -0,0 +1,50 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +if(!is_numeric($_POST['alert_id'])) +{ + echo('ERROR: No alert selected'); + exit; +} +else +{ + if($_POST['state'] == 'true') + { + $state = 0; + } + elseif($_POST['state'] == 'false') + { + $state = 1; + } + else + { + $state = 1; + } + $update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id'])); + if(!empty($update) || $update == '0') + { + echo('Alert rule has been updated.'); + exit; + } + else + { + echo('ERROR: Alert rule has not been updated.'); + exit; + } +} + diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index fc3b0542b..76eb2cb32 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -709,4 +709,13 @@ function generate_pagination($count,$limit,$page,$links = 2) { return($return); } +function is_admin() { + if ($_SESSION['userlevel'] == '10') { + $allowed = true; + } else { + $allowed = false; + } + return $allowed; +} + ?> diff --git a/html/includes/modal/alert_template.inc.php b/html/includes/modal/alert_template.inc.php new file mode 100644 index 000000000..5ecda629f --- /dev/null +++ b/html/includes/modal/alert_template.inc.php @@ -0,0 +1,223 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +?> + + + + diff --git a/html/includes/modal/attach_alert_template.inc.php b/html/includes/modal/attach_alert_template.inc.php new file mode 100644 index 000000000..5584e81e9 --- /dev/null +++ b/html/includes/modal/attach_alert_template.inc.php @@ -0,0 +1,102 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +?> + + + + diff --git a/html/includes/modal/delete_alert_rule.inc.php b/html/includes/modal/delete_alert_rule.inc.php new file mode 100644 index 000000000..694bd01c4 --- /dev/null +++ b/html/includes/modal/delete_alert_rule.inc.php @@ -0,0 +1,70 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +?> + + + + diff --git a/html/includes/modal/delete_alert_template.inc.php b/html/includes/modal/delete_alert_template.inc.php new file mode 100644 index 000000000..bc758ec7d --- /dev/null +++ b/html/includes/modal/delete_alert_template.inc.php @@ -0,0 +1,70 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +?> + + + + diff --git a/html/includes/modal/new_alert_rule.inc.php b/html/includes/modal/new_alert_rule.inc.php new file mode 100644 index 000000000..60a7b32d9 --- /dev/null +++ b/html/includes/modal/new_alert_rule.inc.php @@ -0,0 +1,219 @@ + + * + * 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, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + +?> + + + + + + diff --git a/html/includes/print-alert-rules.php b/html/includes/print-alert-rules.php new file mode 100644 index 000000000..ed02b801a --- /dev/null +++ b/html/includes/print-alert-rules.php @@ -0,0 +1,210 @@ +
+
+ +
+
+ +
+ 0) { + $results = $_POST['results']; +} else { + $results = 50; +} + +echo '
+ + + + + + + + + + '; + +echo (' +'); + +$rulei=1; +$count_query = "SELECT COUNT(id)"; +$full_query = "SELECT *"; +$sql = ''; +$param = array(); +if(isset($device['device_id']) && $device['device_id'] > 0) { + $sql = 'WHERE (device_id=? OR device_id="-1")'; + $param = array($device['device_id']); +} +$query = " FROM alert_rules $sql ORDER BY device_id,id"; +$count_query = $count_query . $query; +$count = dbFetchCell($count_query,$param); +if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { + $page_number = 1; +} else { + $page_number = $_POST['page_number']; +} +$start = ($page_number - 1) * $results; +$full_query = $full_query . $query . " LIMIT $start,$results"; + +foreach( dbFetchRows($full_query, $param) as $rule ) { + $sub = dbFetchRows("SELECT * FROM alerts WHERE rule_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'])); + $ico = "ok"; + $col = "success"; + $extra = ""; + if( sizeof($sub) == 1 ) { + $sub = $sub[0]; + if( (int) $sub['state'] === 0 ) { + $ico = "ok"; + $col = "success"; + } elseif( (int) $sub['state'] === 1 ) { + $ico = "remove"; + $col = "danger"; + $extra = "danger"; + } elseif( (int) $sub['state'] === 2 ) { + $ico = "time"; + $col = "default"; + $extra = "warning"; + } + } + $alert_checked = ''; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; + if( $rule['disabled'] ) { + $ico = "pause"; + $col = ""; + $extra = "active"; + } else { + $alert_checked = 'checked'; + } + $rule_extra = json_decode($rule['extra'],TRUE); + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + echo ""; + echo ""; + echo ""; + echo "\r\n"; +} +if($count % $results > 0) { + echo(' + + '); +} +echo '
#RuleSeverityStatusExtraEnabledAction
'); +if ($_SESSION['userlevel'] == '10') { + echo(''); +} +echo ('
#".((int) $rulei++)."".htmlentities($rule['rule'])."".$rule['severity']." "; + if($rule_extra['mute'] === true) { + echo "Max: ".$rule_extra['count']."
Delay: ".$rule_extra['delay']."
"; + if ($_SESSION['userlevel'] == '10') { + echo ""; + } + echo ""; + if ($_SESSION['userlevel'] == '10') { + echo " "; + echo ""; + } + echo "
'. generate_pagination($count,$results,$page_number) .'
+ + + +
'; +?> + + diff --git a/html/includes/print-alert-templates.php b/html/includes/print-alert-templates.php new file mode 100644 index 000000000..001e10dd6 --- /dev/null +++ b/html/includes/print-alert-templates.php @@ -0,0 +1,84 @@ +
+
+ +
+
+ + +
+ 0) { + $results = $_POST['results']; +} else { + $results = 50; +} + +echo '
+ + + + + + + +'); + +$count_query = "SELECT COUNT(id)"; +$full_query = "SELECT *"; + +$query = " FROM `alert_templates`"; + +$count_query = $count_query . $query; +$count = dbFetchCell($count_query,$param); +if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { + $page_number = 1; +} else { + $page_number = $_POST['page_number']; +} +$start = ($page_number - 1) * $results; +$full_query = $full_query . $query . " LIMIT $start,$results"; + +foreach( dbFetchRows($full_query, $param) as $template ) { + echo ' + + + '; +} + +if($count % $results > 0) { + echo(' + + '); +} + +echo '
NameAction
'; + +if ($_SESSION['userlevel'] == '10') { + echo(''); +} + +echo '
'.$template['name'].''; + if ($_SESSION['userlevel'] == '10') { + echo " "; + echo " "; + echo ""; + } + echo '
'. generate_pagination($count,$results,$page_number) .'
+ + + +
'; diff --git a/html/includes/print-alerts.php b/html/includes/print-alerts.php new file mode 100644 index 000000000..89be0cfea --- /dev/null +++ b/html/includes/print-alerts.php @@ -0,0 +1,144 @@ +
+
+ +
+
+ +
+ 0) { + $results = $_POST['results']; +} else { + $results = 50; +} + +echo '
+ + + + + + + + + + '; + +echo (' +'); + +$rulei=1; +$count_query = "SELECT COUNT(alerts.id)"; +$full_query = "SELECT alerts.*, devices.hostname"; +$sql = ''; +$param = array(); +if(isset($device['device_id']) && $device['device_id'] > 0) { + $sql = 'AND `alerts`.`device_id`=?'; + $param = array($device['device_id']); +} +$query = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE `state`= 1 $sql ORDER BY `alerts`.`timestamp` DESC"; +$count_query = $count_query . $query; +$count = dbFetchCell($count_query,$param); +if(!isset($_POST['page_number']) && $_POST['page_number'] < 1) { + $page_number = 1; +} else { + $page_number = $_POST['page_number']; +} +$start = ($page_number - 1) * $results; +$full_query = $full_query . $query . " LIMIT $start,$results"; + +foreach( dbFetchRows($full_query, $param) as $alert ) { + $rule = dbFetchRow("SELECT * FROM alert_rules WHERE id = ? LIMIT 1", array($alert['rule_id'])); + $ico = "ok"; + $col = "green"; + $extra = ""; + if( (int) $alert['state'] === 0 ) { + $ico = "ok"; + $col = "green"; + } elseif( (int) $alert['state'] === 1 ) { + $ico = "remove"; + $col = "red"; + $extra = "danger"; + } elseif( (int) $alert['state'] === 2 ) { + $ico = "time"; + $col = "#800080"; + $extra = "warning"; + } + $alert_checked = ''; + $orig_ico = $ico; + $orig_col = $col; + $orig_class = $extra; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "\r\n"; +} +if($count % $results > 0) { + echo(' + + '); +} +echo '
#RuleHostnameTimestampSeverityStatusAcknowledge
'); +if ($_SESSION['userlevel'] == '10') { + echo(''); +} +echo ('
#".((int) $rulei++)."".htmlentities($rule['rule'])."".$alert['hostname']."".($alert['timestamp'] ? $alert['timestamp'] : "N/A")."".$rule['severity']." "; + if ($_SESSION['userlevel'] == '10') { + echo ""; + } + echo "
'. generate_pagination($count,$results,$page_number) .'
+ + + +
'; +?> + + diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index bd7325e7a..43090f279 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -41,6 +41,15 @@ if (isset($config['enable_bgp']) && $config['enable_bgp']) Overview