Remove global $var access functions (#16345)

* Proxmox remove global access functions

* Apply fixes from StyleCI

---------

Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
This commit is contained in:
Tony Murray 2024-09-03 12:41:13 -05:00 committed by GitHub
parent c6cac9d90b
commit cc22a74503
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 50 deletions

View File

@ -16,40 +16,6 @@ use LibreNMS\Enum\ImageFormat;
use LibreNMS\Util\Number;
use LibreNMS\Util\Rewrite;
/**
* Compare $t with the value of $vars[$v], if that exists
*
* @param string $v Name of the var to test
* @param string $t Value to compare $vars[$v] to
* @return bool true, if values are the same, false if $vars[$v]
* is unset or values differ
*/
function var_eq($v, $t)
{
global $vars;
if (isset($vars[$v]) && $vars[$v] == $t) {
return true;
}
return false;
}
/**
* Get the value of $vars[$v], if it exists
*
* @param string $v Name of the var to get
* @return string|bool The value of $vars[$v] if it exists, false if it does not exist
*/
function var_get($v)
{
global $vars;
if (isset($vars[$v])) {
return $vars[$v];
}
return false;
}
function toner2colour($descr, $percent)
{
$colour = \LibreNMS\Util\Color::percentage(100 - $percent, null);

View File

@ -6,25 +6,25 @@ $graphs['proxmox'] = [
];
$pmxcl = dbFetchRows('SELECT DISTINCT(`app_instance`) FROM `applications` WHERE `app_type` = ?', ['proxmox']);
$instance = Request::get('instance', $pmxcl[0]['app_instance'] ?? null);
print_optionbar_start();
echo "<span style='font-weight: bold;'>Proxmox Clusters</span> &#187; ";
unset($sep);
$sep = '';
foreach ($pmxcl as $pmxc) {
if (isset($sep)) {
echo $sep;
}
echo $sep;
if (var_eq('instance', $pmxc['app_instance']) || (! isset($vars['instance']) && ! isset($sep))) {
$selected = $pmxc['app_instance'] == $instance || (empty($instance) && empty($sep));
if ($selected) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link(\LibreNMS\Util\StringHelpers::niceCase($pmxc->app_instance), ['page' => 'apps', 'app' => 'proxmox', 'instance' => $pmxc['app_instance']]);
if (var_eq('instance', $pmxc['app_instance'])) {
if ($selected) {
echo '</span>';
}
@ -36,12 +36,6 @@ print_optionbar_end();
$pagetitle[] = 'Proxmox';
$pagetitle[] = $instance;
if (! isset($vars['instance'])) {
$instance = $pmxcl[0]['app_instance'];
} else {
$instance = var_get('instance');
}
if (isset($vars['vmid'])) {
include 'includes/html/pages/apps/proxmox/vm.inc.php';
$pagetitle[] = $vars['vmid'];

View File

@ -1,6 +1,6 @@
<?php
$vm = proxmox_vm_info(var_get('vmid'), var_get('instance'));
$vm = proxmox_vm_info(Request::get('vmid'), Request::get('instance'));
$graphs = [
'proxmox_traffic' => 'Traffic',
@ -23,7 +23,7 @@ foreach ($vm['ports'] as $port) {
echo '<h3>' . $text . ' ' . $port['port'] . '@' . $vm['description'] . '</h3>';
echo "<tr bgcolor='$row_colour'><td colspan=5>";
echo '<tr><td colspan=5>';
include 'includes/html/print-graphrow.inc.php';

View File

@ -25,7 +25,7 @@ if (! \LibreNMS\Config::get('enable_proxmox')) {
'proxmox_traffic' => 'Traffic',
];
foreach (proxmox_node_vms(var_get('device')) as $nvm) {
foreach (proxmox_node_vms(Request::get('device')) as $nvm) {
$vm = proxmox_vm_info($nvm['vmid'], $nvm['cluster']);
foreach ($vm['ports'] as $port) {
@ -45,7 +45,7 @@ if (! \LibreNMS\Config::get('enable_proxmox')) {
echo '<h3>' . $text . ' ' . $port['port'] . '@' . $vm['description'] . '</h3>';
echo "<tr bgcolor='$row_colour'><td colspan=5>";
echo '<tr><td colspan=5>';
include 'includes/html/print-graphrow.inc.php';