split patterns
This commit is contained in:
parent
68fcc088c6
commit
88228aedae
58
show.php
58
show.php
@ -1,31 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
$basedir = __DIR__ . "/confs/";
|
$basedir = __DIR__ . "/confs/";
|
||||||
$path = realpath($basedir . filter_input(INPUT_GET, "switch", FILTER_SANITIZE_STRING));
|
$path = realpath($basedir . filter_input(INPUT_GET, "switch", FILTER_SANITIZE_STRING));
|
||||||
if (strpos($path, $basedir) !== 0 || substr($path, -4) != ".cfg") {
|
if (strpos($path, $basedir) !== 0 || substr($path, -4) != ".cfg") {
|
||||||
header('HTTP/1.1 404 Not Found');
|
header('HTTP/1.1 404 Not Found');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
$conf = file_get_contents($path);
|
$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);
|
$startPattern = "(?<=\n)";
|
||||||
preg_match_all("/(?<=\n)interface [\w-]+(?P<member>\d+)\/0\/(?P<port>\d+)[\r\n]+(?: port hybrid (?:pvid )?vlan (?:(?P<tagged>\d+)(?: [0-9a-z ]*)? 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);
|
$NLPattern = "[\r\n]+";
|
||||||
$stack = array();
|
$vlanPvidPattern = "vlan (?P<pvid>\d+)$NLPattern";
|
||||||
foreach ($interfaces as $interface) {
|
$vlanNamePattern = " name (?P<name>.+)$NLPattern";
|
||||||
if (!isset($stack[$interface["member"]])) $stack[$interface["member"]] = [[], []];
|
$vlanDescriptionPattern = " description (?P<description>.+)$NLPattern";
|
||||||
$interface["style"] = "";
|
$otherPattern = " .*$NLPattern";
|
||||||
if (!empty($interface["pvid"])) $interface["style"] .= "--pvid: {$interface["pvid"]}; ";
|
$endPattern = "(?<!#)";
|
||||||
if (!empty($interface["tagged"])) $interface["style"] .= "--tagged: {$interface["tagged"]}; ";
|
preg_match_all("/$startPattern$vlanPvidPattern(?:$vlanNamePattern|$vlanDescriptionPattern|$otherPattern)*$endPattern/", $conf, $vlans, PREG_SET_ORDER);
|
||||||
if (!empty($interface["untagged"])) $interface["style"] .= "--untagged: {$interface["untagged"]}; ";
|
$interfaceAddressPattern = "interface [\w-]+(?P<member>\d+)\/0\/(?P<port>\d+)$NLPattern";
|
||||||
$stack[$interface["member"]][1 - $interface["port"] % 2][$interface["port"]] = $interface;
|
$portHybridPattern = " port hybrid (?:pvid )?vlan (?:(?P<tagged>\d+)(?: [0-9a-z ]*)? tagged|(?P<untagged>\d+)(?: \d+)* untagged)$NLPattern";
|
||||||
}
|
$portAccessPattern = " port (?:access |trunk |hybrid |pvid |vlan )*(?P<pvid>\d+)$NLPattern";
|
||||||
|
$voiceVlanPattern = " voice-vlan (?P<voice_vlan>\d+) enable$NLPattern";
|
||||||
/*echo ("<!--");
|
preg_match_all("/$startPattern$interfaceAddressPattern(?:$portHybridPattern|$portAccessPattern|$voiceVlanPattern|$otherPattern)*$endPattern/", $conf, $interfaces, PREG_SET_ORDER);
|
||||||
var_dump($stack);
|
$stack = array();
|
||||||
echo ("-->");*/
|
foreach ($interfaces as $interface) {
|
||||||
|
if (!isset($stack[$interface["member"]])) $stack[$interface["member"]] = [[], []];
|
||||||
|
$interface["style"] = "";
|
||||||
|
if (!empty($interface["pvid"])) $interface["style"] .= "--pvid: {$interface["pvid"]}; ";
|
||||||
|
if (!empty($interface["tagged"])) $interface["style"] .= "--tagged: {$interface["tagged"]}; ";
|
||||||
|
if (!empty($interface["untagged"])) $interface["style"] .= "--untagged: {$interface["untagged"]}; ";
|
||||||
|
$stack[$interface["member"]][1 - $interface["port"] % 2][$interface["port"]] = $interface;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*echo ("<!--");
|
||||||
|
var_dump($stack);
|
||||||
|
echo ("-->");*/
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang='fr'>
|
<html lang='fr'>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user