From dc0d12936ccdb08ea73ad36383fe277386f1744c Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 6 May 2015 22:52:54 +0100 Subject: [PATCH] Added support for Oxidized --- html/pages/device.inc.php | 3 + html/pages/device/showconfig.inc.php | 185 ++++++++++++++++----------- includes/defaults.inc.php | 2 + 3 files changed, 117 insertions(+), 73 deletions(-) diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 773f7a3b4..d888dc583 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -342,6 +342,9 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) if ($configs[strlen($configs)-1] != '/') { $configs .= '/'; } if (is_file($configs . $device['hostname'])) { $device_config_file = $configs . $device['hostname']; } } + if ($config['oxidized']['enabled'] === TRUE && isset($config['oxidized']['url'])) { + $device_config_file = TRUE; + } } if ($device_config_file) diff --git a/html/pages/device/showconfig.inc.php b/html/pages/device/showconfig.inc.php index 20cd8c999..5ce3e608c 100644 --- a/html/pages/device/showconfig.inc.php +++ b/html/pages/device/showconfig.inc.php @@ -9,82 +9,121 @@ if ($_SESSION['userlevel'] >= "7") if (!is_array($config['rancid_configs'])) { $config['rancid_configs'] = array($config['rancid_configs']); } - foreach ($config['rancid_configs'] as $configs) - { - if ($configs[strlen($configs)-1] != '/') { $configs .= '/'; } - if (is_file($configs . $device['hostname'])) { $file = $configs . $device['hostname']; } + if (isset($config['rancid_configs'][0])) { + + foreach ($config['rancid_configs'] as $configs) { + if ($configs[strlen($configs) - 1] != '/') { + $configs .= '/'; + } + if (is_file($configs . $device['hostname'])) { + $file = $configs . $device['hostname']; + } + } + + echo('
'); + + print_optionbar_start('', ''); + + echo("Config » "); + + if (!$vars['rev']) { + echo(''); + echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); + echo(""); + } else { + echo(generate_link('Latest', array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig'))); + } + + if (function_exists('svn_log')) { + + $sep = " | "; + $svnlogs = svn_log($file, SVN_REVISION_HEAD, NULL, 8); + $revlist = array(); + + foreach ($svnlogs as $svnlog) { + + echo($sep); + $revlist[] = $svnlog["rev"]; + + if ($vars['rev'] == $svnlog["rev"]) { + echo(''); + } + $linktext = "r" . $svnlog["rev"] . " " . date("d M H:i", strtotime($svnlog["date"])) . ""; + echo(generate_link($linktext, array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'showconfig', 'rev' => $svnlog["rev"]))); + + if ($vars['rev'] == $svnlog["rev"]) { + echo(""); + } + + $sep = " | "; + } + } + + print_optionbar_end(); + + if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { + list($diff, $errors) = svn_diff($file, $vars['rev'] - 1, $file, $vars['rev']); + if (!$diff) { + $text = "No Difference"; + } else { + $text = ""; + while (!feof($diff)) { + $text .= fread($diff, 8192); + } + fclose($diff); + fclose($errors); + } + + } else { + $fh = fopen($file, 'r') or die("Can't open file"); + $text = fread($fh, filesize($file)); + fclose($fh); + } + + if ($config['rancid_ignorecomments']) { + $lines = explode("\n", $text); + for ($i = 0; $i < count($lines); $i++) { + if ($lines[$i][0] == "#") { + unset($lines[$i]); + } + } + $text = join("\n", $lines); + } + } elseif ($config['oxidized']['enabled'] === TRUE && isset($config['oxidized']['url'])) { + $node_info = json_decode(file_get_contents($config['oxidized']['url']."/node/show/".$device['hostname']."?format=json"),TRUE); + $text = file_get_contents($config['oxidized']['url']."/node/fetch/".$device['hostname']); + + if (is_array($node_info)) { + echo('
+
+
+
+
Sync status: '.$node_info['last']['status'].'
+
    +
  • Node: '. $node_info['name'].'
  • +
  • IP: '. $node_info['ip'].'
  • +
  • Model: '. $node_info['model'].'
  • +
  • Last Sync: '. $node_info['last']['end'].'
  • +
+
+
+
'); + } else { + echo "
"; + print_error("We couldn't retrieve the device information from Oxidized"); + $text = ''; + } + } - echo('
'); - - print_optionbar_start('', ''); - - echo("Config » "); - - if (!$vars['rev']) { - echo(''); - echo(generate_link('Latest',array('page'=>'device','device'=>$device['device_id'],'tab'=>'showconfig'))); - echo(""); - } else { - echo(generate_link('Latest',array('page'=>'device','device'=>$device['device_id'],'tab'=>'showconfig'))); + if (!empty($text)) { + $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'); + echo($geshi->parse_code()); } - - if (function_exists('svn_log')) { - - $sep = " | "; - $svnlogs = svn_log($file, SVN_REVISION_HEAD, NULL, 8); - $revlist = array(); - - foreach ($svnlogs as $svnlog) { - - echo($sep); - $revlist[] = $svnlog["rev"]; - - if ($vars['rev'] == $svnlog["rev"]) { echo(''); } - $linktext = "r" . $svnlog["rev"] ." ". date("d M H:i", strtotime($svnlog["date"])) . ""; - echo(generate_link($linktext,array('page'=>'device','device'=>$device['device_id'],'tab'=>'showconfig','rev'=>$svnlog["rev"]))); - - if ($vars['rev'] == $svnlog["rev"]) { echo(""); } - - $sep = " | "; - } - } - - print_optionbar_end(); - - if (function_exists('svn_log') && in_array($vars['rev'], $revlist)) { - list($diff, $errors) = svn_diff($file, $vars['rev']-1, $file, $vars['rev']); - if (!$diff) { - $text = "No Difference"; - } else { - $text = ""; - while (!feof($diff)) { $text .= fread($diff, 8192); } - fclose($diff); - fclose($errors); - } - - } else { - $fh = fopen($file, 'r') or die("Can't open file"); - $text = fread($fh, filesize($file)); - fclose($fh); - } - - if ($config['rancid_ignorecomments']) - { - $lines = explode("\n",$text); - for ($i = 0;$i < count($lines);$i++) - { - if ($lines[$i][0] == "#") { unset($lines[$i]); } - } - $text = join("\n",$lines); - } - - $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'); - echo($geshi->parse_code()); } $pagetitle[] = "Config"; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 5349e919f..4c87c3bd6 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -343,6 +343,8 @@ $config['billing']['base'] = 1000; # Set the base to divider bytes $config['rancid_ignorecomments'] = 0; # Ignore lines starting with # #$config['collectd_dir'] = '/var/lib/collectd/rrd'; #$config['smokeping']['dir'] = "/var/lib/smokeping/"; +//$config['oxidized']['enabled'] = FALSE;//Set to TRUE +//$config['oxidized']['url'] = 'http://127.0.0.1:8888';// Set the Oxidized rest URL # NFSen RRD dir. $config['nfsen_enable'] = 0;