Use Config helper (#10339)

remove usage of global variable
This commit is contained in:
Tony Murray
2019-06-23 00:29:12 -05:00
committed by GitHub
parent 342acf50f1
commit f3ba8947f7
367 changed files with 1589 additions and 1857 deletions

View File

@@ -12,6 +12,7 @@
*/
use LibreNMS\Authentication\LegacyAuth;
use LibreNMS\Config;
$links = 1;
@@ -32,12 +33,8 @@ if (strpos($_SERVER['REQUEST_URI'], 'anon')) {
$anon = 1;
}
if (isset($config['branding']) && is_array($config['branding'])) {
if (isset($config['branding'][$_SERVER['SERVER_NAME']])) {
$config = array_replace_recursive($config, $config['branding'][$_SERVER['SERVER_NAME']]);
} else {
$config = array_replace_recursive($config, $config['branding']['default']);
}
if (is_array(Config::get('branding'))) {
Config::set('branding', array_replace_recursive(Config::get('branding'), Config::get('branding.' . $_SERVER['SERVER_NAME']) ?: Config::get('branding.default')));
}
$where = '';
@@ -74,7 +71,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) {
}
$loc_id = $locations[$device['location']];
$map .= "\"".$device['hostname']."\" [fontsize=20, fillcolor=\"lightblue\", group=".$loc_id." URL=\"{$config['base_url']}/device/device=".$device['device_id']."/tab=neighbours/selection=map/\" shape=box3d]\n";
$map .= "\"" . $device['hostname'] . "\" [fontsize=20, fillcolor=\"lightblue\", group=" . $loc_id . " URL=\"" . Config::get('base_url') . "/device/device=" . $device['device_id'] . "/tab=neighbours/selection=map/\" shape=box3d]\n";
}
foreach ($links as $link) {
@@ -135,24 +132,24 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) {
}
$ifdone[$src][$sif['port_id']] = 1;
} else {
$map .= "\"" . $sif['port_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/device=".$device['device_id']."/tab=port/port=$local_port_id/\"]\n";
$map .= "\"" . $sif['port_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"" . Config::get('base_url') . "/device/device=" . $device['device_id'] . "/tab=port/port=$local_port_id/\"]\n";
if (!$ifdone[$src][$sif['port_id']]) {
$map .= "\"$src\" -> \"" . $sif['port_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
$ifdone[$src][$sif['port_id']] = 1;
}
if ($dst_host) {
$map .= "\"$dst\" [URL=\"{$config['base_url']}/device/device=$dst_host/tab=neighbours/selection=map/\", fontsize=20, shape=box3d]\n";
$map .= "\"$dst\" [URL=\"" . Config::get('base_url') . "/device/device=$dst_host/tab=neighbours/selection=map/\", fontsize=20, shape=box3d]\n";
} else {
$map .= "\"$dst\" [ fontsize=20 shape=box3d]\n";
}
if ($dst_host == $device['device_id'] || $where == '') {
$map .= "\"" . $dif['port_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/device=$dst_host/tab=port/port=$remote_port_id/\"]\n";
$map .= "\"" . $dif['port_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"" . Config::get('base_url') . "/device/device=$dst_host/tab=port/port=$remote_port_id/\"]\n";
} else {
$map .= "\"" . $dif['port_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray";
if ($dst_host) {
$map .= ", URL=\"{$config['base_url']}/device/device=$dst_host/tab=port/port=$remote_port_id/\"";
$map .= ", URL=\"" . Config::get('base_url') . "/device/device=$dst_host/tab=port/port=$remote_port_id/\"";
}
$map .= "]\n";
}
@@ -192,19 +189,19 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) {
if ($links > 30) {
// Unflatten if there are more than 10 links. beyond that it gets messy
$maptool = $config['dot'];
$maptool = Config::get('dot');
} else {
$maptool = $config['dot'];
$maptool = Config::get('dot');
}
if ($where == '') {
$maptool = $config['sfdp'] . ' -Gpack -Goverlap=prism -Gcharset=latin1 -Gsize=20,20';
$maptool = $config['dot'];
$maptool = Config::get('sfdp') . ' -Gpack -Goverlap=prism -Gcharset=latin1 -Gsize=20,20';
$maptool = Config::get('dot');
}
$descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w") );
$mapfile = $config['temp_dir'] . "/" . strgen() . ".png";
$mapfile = Config::get('temp_dir') . "/" . strgen() . ".png";
$process = proc_open($maptool.' -T'.$_GET['format'], $descriptorspec, $pipes);
@@ -229,7 +226,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) {
if (LegacyAuth::check()) {
// FIXME level 10 only?
echo '<center>
<object width=1200 height=1000 data="'. $config['base_url'] . '/network-map.php?format=svg" type="image/svg+xml"></object>
<object width=1200 height=1000 data="' . Config::get('base_url') . '/network-map.php?format=svg" type="image/svg+xml"></object>
</center>
';
}