diff --git a/doc/Extensions/Oxidized.md b/doc/Extensions/Oxidized.md index e74bf5c3cd..9123c2ed80 100644 --- a/doc/Extensions/Oxidized.md +++ b/doc/Extensions/Oxidized.md @@ -12,14 +12,13 @@ $config['oxidized']['enabled'] = TRUE; $config['oxidized']['url'] = 'http://127.0.0.1:8888'; ``` -We also support config versioning within Oxidized, this will allow you to see the old configs stored. - +LibreNMS supports config versioning if Oxidized does. This is known to work with the git output module. ```php $config['oxidized']['features']['versioning'] = true; ``` Oxidized supports various ways to utilise credentials to login to devices, you can specify global username/password within Oxidized, Group level username/password or per device. -We currently support sending groups back to Oxidized so that you can then define group credentials within Oxidized. To enable this support please switch on 'Enable the return of groups to Oxidized': +LibreNMS currently supports sending groups back to Oxidized so that you can then define group credentials within Oxidized. To enable this support please switch on 'Enable the return of groups to Oxidized': ```php $config['oxidized']['group_support'] = true; @@ -35,7 +34,7 @@ $config['oxidized']['default_group'] = 'default'; Oxidized has support for feeding devices into it via an API call, support for Oxidized has been added to the LibreNMS API. A sample config for Oxidized is provided below. -You will need to configure default credentials for your devices, LibreNMS doesn't provide login credentials at this time. +You will need to configure default credentials for your devices in the Oxidized config, LibreNMS doesn't provide login credentials at this time. ```bash source: @@ -61,7 +60,7 @@ $config['oxidized']['reload_nodes'] = TRUE; ``` -### Using Groups +#### Using Groups To return a group to Oxidized you can do this by matching a regex for either hostname or location. The order is hostname is matched first, if nothing is found then location is attempted. The first match found will be used. To match on the device hostnames that contain 'lon-sw' or if the location contains 'London' then you would place the following within config.php: @@ -80,7 +79,7 @@ groups: password: ``` -### Miscellaneous +#### Miscellaneous If you have devices which you do not wish to appear in Oxidized then you can edit those devices in Device -> Edit -> Misc and enable "Exclude from Oxidized?" diff --git a/doc/General/Acknowledgement.md b/doc/General/Acknowledgement.md index 328a8f8677..dca40023e1 100644 --- a/doc/General/Acknowledgement.md +++ b/doc/General/Acknowledgement.md @@ -24,6 +24,7 @@ LibreNMS 3rd party acknowledgements - TW Sack (https://code.google.com/p/tw-sack/): GPLv3 - Gridster (http://gridster.net/): MIT - Pure PHP radius class (http://developer.sysco.ch/php/): GPLv3 + - GeSHi - Generic Syntax Highlighter (http://qbnz.com/highlighter/): GPLv2+ #### 3rd Party GPLv3 Non-compliant diff --git a/html/includes/geshi/geshi/diff.php b/html/includes/geshi/geshi/diff.php new file mode 100644 index 0000000000..e4bfc6f470 --- /dev/null +++ b/html/includes/geshi/geshi/diff.php @@ -0,0 +1,194 @@ + 'Diff', + 'COMMENT_SINGLE' => array(), + 'COMMENT_MULTI' => array(), + 'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE, + 'QUOTEMARKS' => array(), + 'ESCAPE_CHAR' => ' ', + 'KEYWORDS' => array( + 1 => array( + '\ No newline at end of file' + ), +// 2 => array( +// '***************' /* This only seems to works in some cases? */ +// ), + ), + 'SYMBOLS' => array( + ), + 'CASE_SENSITIVE' => array( + 1 => false, +// 2 => false + ), + 'STYLES' => array( + 'KEYWORDS' => array( + 1 => 'color: #aaaaaa; font-style: italic;', +// 2 => 'color: #dd6611;', + ), + 'COMMENTS' => array( + ), + 'ESCAPE_CHAR' => array( + 0 => '' + ), + 'BRACKETS' => array( + 0 => '' + ), + 'STRINGS' => array( + 0 => '' + ), + 'NUMBERS' => array( + 0 => '' + ), + 'METHODS' => array( + 0 => '' + ), + 'SYMBOLS' => array( + 0 => '' + ), + 'SCRIPT' => array( + 0 => '' + ), + 'REGEXPS' => array( + 0 => 'color: #440088;', + 1 => 'color: #991111;', + 2 => 'color: #00b000;', + 3 => 'color: #888822;', + 4 => 'color: #888822;', + 5 => 'color: #0011dd;', + 6 => 'color: #440088;', + 7 => 'color: #991111;', + 8 => 'color: #00b000;', + 9 => 'color: #888822;', + ), + ), + 'URLS' => array( + 1 => '', +// 2 => '' + ), + 'OOLANG' => false, + 'OBJECT_SPLITTERS' => array(), + 'REGEXPS' => array( + 0 => "[0-9,]+[acd][0-9,]+", + //Removed lines + 1 => array( + GESHI_SEARCH => '(^|(?<=\A\s))\\<.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Inserted lines + 2 => array( + GESHI_SEARCH => '(^|(?<=\A\s))\\>.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Location line + 3 => array( + GESHI_SEARCH => '(^|(?<=\A\s))-{3}\\s.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Inserted line + 4 => array( + GESHI_SEARCH => '(^|(?<=\A\s))(\\+){3}\\s.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Modified line + 5 => array( + GESHI_SEARCH => '(^|(?<=\A\s))\\!.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //File specification + 6 => array( + GESHI_SEARCH => '(^|(?<=\A\s))[\\@]{2}.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Removed line + 7 => array( + GESHI_SEARCH => '(^|(?<=\A\s))\\-.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //Inserted line + 8 => array( + GESHI_SEARCH => '(^|(?<=\A\s))\\+.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + //File specification + 9 => array( + GESHI_SEARCH => '(^|(?<=\A\s))(\\*){3}\\s.*$', + GESHI_REPLACE => '\\0', + GESHI_MODIFIERS => 'm', + GESHI_BEFORE => '', + GESHI_AFTER => '' + ), + ), + 'STRICT_MODE_APPLIES' => GESHI_NEVER, + 'SCRIPT_DELIMITERS' => array( + ), + 'HIGHLIGHT_STRICT_BLOCK' => array( + ) +); diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 212c228d9e..9517dd96cf 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -314,7 +314,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { '; } - if ($_SESSION['userlevel'] >= '7') { + if (is_admin()) { if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } @@ -405,7 +405,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
  • https Launch
  • ssh SSH
  • telnet Telnet
  • '; - if ($_SESSION['userlevel'] >= '7') { + if (is_admin()) { echo '
  • diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 1ba06bbfc4..917e85f1bb 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -3,7 +3,7 @@ require 'includes/geshi/geshi.php'; // FIXME svn stuff still using optc etc, won't work, needs updating! -if ($_SESSION['userlevel'] >= '7') { +if (is_admin()) { if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } @@ -103,19 +103,68 @@ if ($_SESSION['userlevel'] >= '7') { } } else if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) { + // fetch info about the node and then a list of versions for that node $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true); - if ($config['oxidized']['features']['versioning'] === true && isset($_POST['config'])) { - list($oid,$date,$version) = explode('|',mres($_POST['config'])); - $text = file_get_contents($config['oxidized']['url'].'/node/version/view?node='.$device['hostname'].'&group='.(!empty($node_info['group']) ? $node_info['group'] : '').'&oid='.$oid.'&date='.urlencode($date).'&num='.$version.'&format=text'); - } - else { - $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname']); - } - if ($config['oxidized']['features']['versioning'] === true) { - $config_versions = json_decode(file_get_contents($config['oxidized']['url'].'/node/version?node_full='.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname'].'&format=json'), true); + if ($config['oxidized']['features']['versioning'] === true) { // fetch a list of versions + $config_versions = json_decode(file_get_contents($config['oxidized']['url'].'/node/version?node_full='.(isset($node_info['full_name']) ? $node_info['full_name'] : $device['hostname']).'&format=json'), true); } - if (is_array($node_info) || is_array($config_versions)) { + $config_total = 1; + if (is_array($config_versions)) { + $config_total = count($config_versions); + } + + if ($config_total > 1) { + // populate current_version + if (isset($_POST['config'])) { + list($oid,$date,$version) = explode('|',mres($_POST['config'])); + $current_config = array('oid'=>$oid, 'date'=>$date, 'version'=>$version); + } + else { // no version selected + $current_config = array('oid'=>$config_versions[0]['oid'], 'date'=>$current_config[0]['date'], 'version'=>$config_total); + } + + // populate previous_version + if (isset($_POST['diff'])) { // diff requested + list($oid,$date,$version) = explode('|',mres($_POST['prevconfig'])); + if (isset($oid) && $oid != $current_config['oid']) { + $previous_config = array('oid'=>$oid, 'date'=>$date, 'version'=>$version); + } + else if ($current_config['version'] != 1) { // assume previous, unless current is first config + foreach ($config_versions as $key => $version) { + if ($version['oid'] == $current_config['oid']) { + $prev_key = $key + 1; + $previous_config['oid'] = $config_versions[$prev_key]['oid']; + $previous_config['date'] = $config_versions[$prev_key]['date']; + $previous_config['version'] = $config_total - $prev_key; + break; + } + } + } + else { + print_error('No previous version, please select a different version.'); + } + } + + if (isset($previous_config)) { + $url = $config['oxidized']['url'].'/node/version/diffs?node='.$device['hostname'].'&group='; + if (!empty($node_info['group'])) { + $url .= $node_info['group']; + } + $url .= '&oid='.$current_config['oid'].'&date='.urlencode($current_config['date']).'&num='.$current_config['version'].'&oid2='.$previous_config['oid'].'&format=text'; + + $text = file_get_contents($url); // fetch diff + } else { + // fetch current_version + $text = file_get_contents($config['oxidized']['url'].'/node/version/view?node='.$device['hostname'].'&group='.(!empty($node_info['group']) ? $node_info['group'] : '').'&oid='.$current_config['oid'].'&date='.urlencode($current_config['date']).'&num='.$current_config['version'].'&format=text'); + } + } + else { // just fetch the only version + $text = file_get_contents($config['oxidized']['url'].'/node/fetch/'.(!empty($node_info['group']) ? $node_info['group'].'/' : '').$device['hostname']); + + } + + if (is_array($node_info) || $config_total > 1) { echo '
    '; @@ -136,7 +185,7 @@ if ($_SESSION['userlevel'] >= '7') { '; } - if (is_array($config_versions)) { + if ($config_total > 1) { echo '
    @@ -144,13 +193,27 @@ if ($_SESSION['userlevel'] >= '7') {
    + +
    @@ -177,8 +244,12 @@ if ($_SESSION['userlevel'] >= '7') { }//end if if (!empty($text)) { - $language = 'ios'; - $geshi = new GeSHi($text, $language); + if (isset($previous_config)) { + $language = 'diff'; + } else { + $language = 'ios'; + } + $geshi = new GeSHi($text, $language); $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); $geshi->set_overall_style('color: black;'); // $geshi->set_line_style('color: #999999');