better shutdown and voice-vlan detection

This commit is contained in:
Adrien MALINGREY 2025-03-27 16:55:18 +01:00
parent 26dc6b3b28
commit 25f0f7cd91
2 changed files with 154 additions and 114 deletions

@ -12,7 +12,7 @@ main > table {
margin: auto; margin: auto;
} }
td { td {
text-align: left text-align: left;
} }
.member { .member {
border-spacing: 0; border-spacing: 0;
@ -36,20 +36,31 @@ td {
print-color-adjust: exact; print-color-adjust: exact;
} }
.vlan { .vlan {
background-color: hsl(calc(var(--k)*var(--pvid)) 100% 60%); background-color: hsl(calc(var(--k) * var(--pvid)) 100% 60%);
} }
.trunk { .trunk {
font-weight: bold; font-weight: bold;
border: 4px solid !important; border: 4px solid !important;
border-image-slice: 1 !important; border-image-slice: 1 !important;
border-image-source: linear-gradient(127deg, red, orange, yellow, green, blue, violet) !important; border-image-source: linear-gradient(
127deg,
red,
orange,
yellow,
green,
blue,
violet
) !important;
padding: 0; padding: 0;
} }
.hybrid { .hybrid {
background-image: linear-gradient(135deg, hsl(calc(var(--k)*var(--tagged)) 100% 60%) 50%, hsl(calc(var(--k)*var(--untagged)) 100% 60%) 50%); background-image: linear-gradient(
135deg,
hsl(calc(var(--k) * var(--tagged)) 100% 60%) 50%,
hsl(calc(var(--k) * var(--untagged)) 100% 60%) 50%
);
} }
.shutdown { .shutdown:not([class*="loopback-detection action shutdown"]) {
background-color: lightgray !important; background-color: lightgray !important;
background-image: none !important; background-image: none !important;
color: gray !important; color: gray !important;
@ -61,7 +72,7 @@ td {
top: 0; top: 0;
left: 0; left: 0;
} }
.voice-vlan::after { .voice_vlan::after {
content: "📞"; content: "📞";
font-size: 0.7em; font-size: 0.7em;
position: absolute; position: absolute;

137
vlans.php

@ -11,81 +11,110 @@ $conf = file_get_contents($path);
preg_match("/ sysname ([\w-]+)/", $conf, $sysname); preg_match("/ sysname ([\w-]+)/", $conf, $sysname);
preg_match("/ip address ([\d.]+)/", $conf, $address); preg_match("/ip address ([\d.]+)/", $conf, $address);
preg_match_all("/(?<=\n)vlan (?P<pvid>\d+)[\r\n]+(?: name (?P<name>.+)[\r\n]+| description (?P<description>.+)[\r\n]+| .*[\r\n]+)*/", $conf, $vlans, PREG_SET_ORDER); preg_match_all("/(?<=\n)vlan (?P<pvid>\d+)[\r\n]+(?: name (?P<name>.+)[\r\n]+| description (?P<description>.+)[\r\n]+| .*[\r\n]+)*/", $conf, $vlans, PREG_SET_ORDER);
preg_match_all("/(?<=\n)interface [\w-]+(?P<member>\d+)\/0\/(?P<port>\d+)[\r\n]+(?: port hybrid (?:pvid )?vlan (?:(?P<tagged>\d+) tagged|(?P<untagged>\d+)(?: \d+)* untagged)[\r\n]+| port (?:access |trunk |hybrid |pvid |vlan )*(?P<pvid>\d+)[\r\n]+| .*[\r\n]+)*(?<!#)/", $conf, $interfaces, PREG_SET_ORDER); preg_match_all("/(?<=\n)interface [\w-]+(?P<member>\d+)\/0\/(?P<port>\d+)[\r\n]+(?: port hybrid (?:pvid )?vlan (?:(?P<tagged>\d+) tagged|(?P<untagged>\d+)(?: \d+)* untagged)[\r\n]+| port (?:access |trunk |hybrid |pvid |vlan )*(?P<pvid>\d+)[\r\n]+| voice-vlan (?P<voice_vlan>\d+) enable[\r\n]+| .*[\r\n]+)*(?<!#)/", $conf, $interfaces, PREG_SET_ORDER);
$stack = array(); $stack = array();
foreach ($interfaces as $interface) { foreach ($interfaces as $interface) {
if (!isset($stack[$interface["member"]])) $stack[$interface["member"]] = array(); if (!isset($stack[$interface["member"]])) $stack[$interface["member"]] = array();
$interface["style"] = ""; $interface["style"] = "";
if (!empty($interface["pvid"])) $interface["style"] .= "--pvid: ${interface["pvid"]}; "; if (!empty($interface["pvid"])) $interface["style"] .= "--pvid: {$interface["pvid"]}; ";
if (!empty($interface["tagged"])) $interface["style"] .= "--tagged: ${interface["tagged"]}; "; if (!empty($interface["tagged"])) $interface["style"] .= "--tagged: {$interface["tagged"]}; ";
if (!empty($interface["untagged"])) $interface["style"] .= "--untagged: ${interface["untagged"]}; "; if (!empty($interface["untagged"])) $interface["style"] .= "--untagged: {$interface["untagged"]}; ";
$stack[$interface["member"]][$interface["port"]] = $interface; $stack[$interface["member"]][$interface["port"]] = $interface;
} }
/* echo ("<!--"); echo ("<!--");
var_dump($stack); var_dump($interfaces);
echo ("-->"); */ echo ("-->");
?> ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html lang='fr'> <html lang='fr'>
<head>
<title><?=$sysname[1] ?? "Switch sans nom"?> - Tableau des VLANs</title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<header>
<h1>
<div><?=$sysname[1] ?? "Switch sans nom"?></div>
<small><a href="https://<?=$address[1]?>" target="_blank"><?=$address[1]?></a></small>
</h1>
</header>
<main>
<table>
<caption><h2>Interfaces</h2></caption>
<tbody>
<?php
function display_interface($interface, $odd) {
if ($interface["port"] % 2 == $odd) {
echo "<td class='${interface[0]}' title='${interface[0]}' style='${interface["style"]}'>${interface["port"]}</td>\n";
}
}
foreach ($stack as $member => $interfaces) { <head>
<title><?= $sysname[1] ?? "Switch sans nom" ?> - Tableau des VLANs</title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<header>
<h1>
<div><?= $sysname[1] ?? "Switch sans nom" ?></div>
<small><a href="https://<?= $address[1] ?>" target="_blank"><?= $address[1] ?></a></small>
</h1>
</header>
<main>
<table>
<caption>
<h2>Interfaces</h2>
</caption>
<tbody>
<?php
function display_interface($interface, $odd)
{
if ($interface["port"] % 2 == $odd) {
echo "<td class='{$interface[0]}" . (isset($interface["voice_vlan"]) ? " voice_vlan" : "") . "' title='{$interface[0]}' style='{$interface["style"]}'>{$interface["port"]}</td>\n";
}
}
foreach ($stack as $member => $interfaces) {
echo "<tr>\n<th>$member</th>\n<td>\n<table class='member'>\n<tbody>\n<tr>\n"; echo "<tr>\n<th>$member</th>\n<td>\n<table class='member'>\n<tbody>\n<tr>\n";
foreach ($interfaces as $interface) display_interface($interface, 1); foreach ($interfaces as $interface) display_interface($interface, 1);
echo "</tr>\n<tr>\n"; echo "</tr>\n<tr>\n";
foreach ($interfaces as $interface) display_interface($interface, 0); foreach ($interfaces as $interface) display_interface($interface, 0);
echo "</tr>\n</tbody>\n</table>\n</td>\n</tr>\n"; echo "</tr>\n</tbody>\n</table>\n</td>\n</tr>\n";
} }
?> ?>
</tbody> </tbody>
</table> </table>
<table class='legend'> <table class='legend'>
<caption><h2>Légende</h2></caption> <caption>
<thead><tr><th>PVID</th><th>Nom</th><th>Description</th></tr></thead> <h2>Légende</h2>
<tbody> </caption>
<?php <thead>
foreach ($vlans as $vlan) { <tr>
<th>PVID</th>
<th>Nom</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
foreach ($vlans as $vlan) {
if (isset($vlan["pvid"]) and $vlan["pvid"] != 1) { if (isset($vlan["pvid"]) and $vlan["pvid"] != 1) {
$name = $vlan["name"] ?? ""; $name = $vlan["name"] ?? "";
$description = $vlan["description"] ?? ""; $description = $vlan["description"] ?? "";
echo "<tr title='${vlan[0]}'><td class='interface vlan' style='--pvid: ${vlan["pvid"]}'>${vlan["pvid"]}</td><td>$name</td><td>$description</td></tr>"; echo "<tr title='{$vlan[0]}'><td class='interface vlan' style='--pvid: {$vlan["pvid"]}'>{$vlan["pvid"]}</td><td>$name</td><td>$description</td></tr>";
} }
} }
?> ?>
<tr><td class='interface trunk'></td><td colspan='2'>Trunk</td></tr> <tr>
<tr><td class='interface hybrid' style='--tagged:60; --untagged:0'></td><td colspan='2'>Hybride (tagged/untagged)</td></tr> <td class='interface trunk'></td>
<tr><td class='interface poe'></td><td colspan='2'>Power on Ethernet</td></tr> <td colspan='2'>Trunk</td>
<tr><td class='interface voice-vlan'></td><td colspan='2'>Voice-VLAN</td></tr> </tr>
<tr><td class='interface shutdown'></td><td colspan='2'>Interface désactivée</td></tr> <tr>
</tbody> <td class='interface hybrid' style='--tagged:60; --untagged:0'></td>
</table> <td colspan='2'>Hybride (tagged/untagged)</td>
</main> </tr>
<footer> <tr>
<label id="colorSliderLabel" for="colorSlider">Changer les couleurs</label> <td class='interface poe'></td>
<input id="colorSlider" type="range" min="0" max="2000000" step="0.000000001" value="1353651.53435435" <td colspan='2'>Power on Ethernet</td>
</tr>
<tr>
<td class='interface voice_vlan'></td>
<td colspan='2'>ToIP (voice-vlan)</td>
</tr>
<tr>
<td class='interface shutdown'></td>
<td colspan='2'>Interface désactivée</td>
</tr>
</tbody>
</table>
</main>
<footer>
<label id="colorSliderLabel" for="colorSlider">Changer les couleurs</label>
<input id="colorSlider" type="range" min="0" max="2000000" step="0.000000001" value="1353651.53435435"
oninput="document.documentElement.style.setProperty('--k', this.value);"> oninput="document.documentElement.style.setProperty('--k', this.value);">
</footer> </footer>
</body> </body>
</html> </html>