diff --git a/bridge-ctrl.php b/bridge-ctrl.php index 324523f..c5d0e1d 100644 --- a/bridge-ctrl.php +++ b/bridge-ctrl.php @@ -3,7 +3,7 @@ // file positionen define('NEWFILE', 'http://10.10.254.100/bridge/config.php?bridgeid=22'); -define('OLDFILE', '/etc/bridge/.config.old'); +define('OLDFILE', '/var/www/bridge/.config.old'); // rrdsrv on 5001/tcp define('RRDSRV', "10.10.254.100"); @@ -148,7 +148,7 @@ class BaseTables { Cmd::ebtables("-t filter -A FORWARD -i {$tunnel['device']} -j tap_block"); Cmd::ebtables("-t filter -I tap_block 1 -o {$tunnel['device']} -j DROP"); } - + // ansonsten alles in den tunnel packen foreach ($tunnels as $tunnel) Cmd::ebtables("-t filter -A FORWARD -o {$tunnel['device']} -j ACCEPT"); @@ -173,7 +173,7 @@ class ForwardTables { $address = Cmd::ip("-4 addr show dev ${file}"); if (count($address)) continue; - + Cmd::ifconfig("{$file} down"); Cmd::vconfig("rem {$file}"); } @@ -637,7 +637,7 @@ class Stats { } function get_masters($masters) { - $lines_from = Cmd::ebtables('-t nat -L hlswmaster --Lc'); + $lines_from = Cmd::ebtables('-t nat -L hlswmaster --Lc'); $lines_to = Cmd::ebtables('-t filter -L hlswmaster --Lc'); $result = array(); @@ -645,7 +645,7 @@ class Stats { foreach ($lines_from as $line) { if (strpos($line, $hlsw['ip'])) { $parts = explode(' ', $line); - $from = $parts[14]; + $from = $parts[13]; break; } } @@ -653,7 +653,7 @@ class Stats { foreach ($lines_to as $line) { if (strpos($line, $hlsw['dev'])) { $parts = explode(' ', $line); - $to = $parts[12]; + $to = $parts[11]; break; } } diff --git a/web/include.php b/web/include.php index 382a373..f4fb117 100644 --- a/web/include.php +++ b/web/include.php @@ -7,6 +7,9 @@ define('DB_USER', 'bridge'); define('DB_PASS', 'bridge'); define('DB_NAME', 'bridge'); +define('RRDTOOL', '/usr/bin/rrdtool'); +define('RRDPATH', '/var/lib/rrd'); + function __autoload($classname) { $filename = $classname.'.class.php'; diff --git a/web/include/Graphs.class.php b/web/include/Graphs.class.php new file mode 100644 index 0000000..16e8b1a --- /dev/null +++ b/web/include/Graphs.class.php @@ -0,0 +1,45 @@ + diff --git a/web/include/db_Hlsw.class.php b/web/include/db_Hlsw.class.php index b5acb8b..ef3cc2b 100644 --- a/web/include/db_Hlsw.class.php +++ b/web/include/db_Hlsw.class.php @@ -7,6 +7,7 @@ class Hlsw { public $flags; public $ip = "0.0.0.0"; public $name; + public $rrdpath; private function fromRow($row) { $retval = new Hlsw(); @@ -17,6 +18,7 @@ class Hlsw { $retval->flags = (int)$row['flags']; $retval->ip = (string)$row['ip']; $retval->name = (string)$row['name']; + $retval->rrdpath = (string)$row['rrdpath']; } return $retval; } @@ -30,9 +32,13 @@ class Hlsw { function load($id) { $dbh = Database::getInstance(); - $sql = "SELECT id, vlanid, flags, INET_NTOA(ip) AS ip, name - FROM hlsw - WHERE id = '{$id}'"; + $sql = "SELECT h.id, h.vlanid, h.flags, INET_NTOA(h.ip) AS ip, h.name, + CONCAT('bridge-', b.id, '/hlsw-', h.id, '.rrd') AS rrdpath + FROM hlsw h, vlan v, trunk t, bridge b + WHERE h.id = '{$id}' + AND v.id = h.vlanid + AND t.id = v.trunkid + AND b.id = t.bridgeid"; $dbh->query($sql); return self::fromRow($dbh->fetch_assoc()); @@ -66,9 +72,13 @@ class Hlsw { function getAll() { $dbh = Database::getInstance(); - $sql = "SELECT id, vlanid, flags, INET_NTOA(ip) AS ip, name - FROM hlsw - ORDER BY ip"; + $sql = "SELECT h.id, h.vlanid, h.flags, INET_NTOA(h.ip) AS ip, h.name, + CONCAT('bridge-', b.id, '/hlsw-', h.id, '.rrd') AS rrdpath + FROM hlsw h, vlan v, trunk t, bridge b + WHERE v.id = h.vlanid + AND t.id = v.trunkid + AND b.id = t.bridgeid + ORDER BY h.ip"; $dbh->query($sql); $retval = array(); diff --git a/web/include/db_Trunk.class.php b/web/include/db_Trunk.class.php index 685d89f..39d5be3 100644 --- a/web/include/db_Trunk.class.php +++ b/web/include/db_Trunk.class.php @@ -6,6 +6,7 @@ class Trunk { public $bridgeid; public $flags; public $name; + public $fullname; private function fromRow($row) { $retval = new Trunk(); @@ -15,6 +16,7 @@ class Trunk { $retval->bridgeid = (int)$row['bridgeid']; $retval->flags = (int)$row['flags']; $retval->name = (string)$row['name']; + $retval->fullname = (string)$row['fullname']; } return $retval; } @@ -27,9 +29,11 @@ class Trunk { function load($id) { $dbh = Database::getInstance(); - $sql = "SELECT id, bridgeid, flags, name - FROM trunk - WHERE id = '{$id}'"; + $sql = "SELECT t.id, t.bridgeid, t.flags, t.name, + CONCAT(b.name, ': ', t.name) AS fullname + FROM trunk t, bridge b + WHERE id = '{$id}' + AND b.id = t.bridgeid"; $dbh->query($sql); return self::fromRow($dbh->fetch_assoc()); @@ -67,11 +71,12 @@ class Trunk { function getAll($bridgeid = false) { $dbh = Database::getInstance(); - $sql = "SELECT id, bridgeid, flags, name - FROM trunk - ".($bridgeid ? "WHERE bridgeid = '{$bridgeid}'" : "")." - ORDER BY name"; - + $sql = "SELECT t.id, t.bridgeid, t.flags, t.name, + CONCAT(b.name, ': ', t.name) AS fullname + FROM trunk t, bridge b + WHERE ".($bridgeid ? "bridgeid = '{$bridgeid}'" : "1")." + AND b.id = t.bridgeid + ORDER BY b.name, t.name"; $dbh->query($sql); $retval = array(); diff --git a/web/include/db_Vlan.class.php b/web/include/db_Vlan.class.php index 14dc0de..33d7715 100644 --- a/web/include/db_Vlan.class.php +++ b/web/include/db_Vlan.class.php @@ -8,6 +8,8 @@ class Vlan { public $vlannum; public $bandwidth; public $mac = "00:00:00:00:00:00"; + public $rrdpath; + public $fullname; private function fromRow($row) { $retval = new Vlan(); @@ -19,6 +21,8 @@ class Vlan { $retval->vlannum = (int)$row['vlannum']; $retval->bandwidth = (int)$row['bandwidth']; $retval->mac = (string)$row['mac']; + $retval->rrdpath = (string)$row['rrdpath']; + $retval->fullname = (string)$row['fullname']; } return $retval; } @@ -33,9 +37,19 @@ class Vlan { function load($id) { $dbh = Database::getInstance(); - $sql = "SELECT id, trunkid, flags, vlannum, bandwidth, mac - FROM vlan - WHERE id = '{$id}'"; + $sql = "SELECT v.id, v.trunkid, v.flags, v.vlannum, v.bandwidth, v.mac, + IF (v.vlannum = 1, + CONCAT('bridge-', b.id, '/vlan-', t.name, '.rrd'), + CONCAT('bridge-', b.id, '/vlan-', t.name, '.', v.vlannum, '.rrd') + ) AS rrdpath, + IF (v.vlannum = 1, + CONCAT(b.name, ': ', t.name), + CONCAT(b.name, ': ', t.name, '.', v.vlannum) + ) AS fullname + FROM vlan v, trunk t, bridge b + WHERE v.id = '{$id}' + AND t.id = v.trunkid + AND b.id = t.bridgeid"; $dbh->query($sql); return self::fromRow($dbh->fetch_assoc()); @@ -69,10 +83,14 @@ class Vlan { function getAll($trunkid = false) { $dbh = Database::getInstance(); - $sql = "SELECT id, trunkid, flags, vlannum, bandwidth, mac - FROM vlan - ".($trunkid ? "WHERE trunkid = '{$trunkid}'" : "")." - ORDER BY vlannum"; + $sql = "SELECT v.id, v.trunkid, v.flags, v.vlannum, v.bandwidth, v.mac, + CONCAT('bridge-', b.id, '/vlan-', t.name, '.', v.vlannum, '.rrd') as rrdpath, + CONCAT(t.name, '.', v.vlannum) as fullname + FROM vlan v, trunk t, bridge b + WHERE ".($trunkid ? "trunkid = '{$trunkid}'" : "1")." + AND t.id = v.trunkid + AND b.id = t.bridgeid + ORDER BY b.name, t.name, v.vlannum"; $dbh->query($sql); $retval = array(); diff --git a/web/smarty/templates/hlsw.tpl b/web/smarty/templates/hlsw.tpl index 7fb7488..db8062e 100644 --- a/web/smarty/templates/hlsw.tpl +++ b/web/smarty/templates/hlsw.tpl @@ -30,7 +30,7 @@
- [fancy rrdtool stats] +

diff --git a/web/smarty/templates/siteframe.tpl b/web/smarty/templates/siteframe.tpl index d90e6c2..41f7e43 100644 --- a/web/smarty/templates/siteframe.tpl +++ b/web/smarty/templates/siteframe.tpl @@ -22,25 +22,27 @@ HLSW Master

-{* Statistics:
+{* =>  Bridges
=>  Bridge Tunnels
+*} =>  Bridge VLANs
+{* =>  Forwarding Ports
+*} =>  HLSW Server

-*}


diff --git a/web/smarty/templates/stat_hlsw.tpl b/web/smarty/templates/stat_hlsw.tpl new file mode 100644 index 0000000..8fc0e0f --- /dev/null +++ b/web/smarty/templates/stat_hlsw.tpl @@ -0,0 +1,15 @@ + + +
+ + +

+ +{foreach from=$masters item=hlsw} + +

+{/foreach} + +
diff --git a/web/smarty/templates/stat_vlan.tpl b/web/smarty/templates/stat_vlan.tpl new file mode 100644 index 0000000..3896e31 --- /dev/null +++ b/web/smarty/templates/stat_vlan.tpl @@ -0,0 +1,26 @@ +{debug} + + +
+ + +  + +

+ +{foreach from=$vlans item=vlan} + +

+{/foreach} + +
diff --git a/web/stat_hlsw.php b/web/stat_hlsw.php new file mode 100644 index 0000000..7f5da5a --- /dev/null +++ b/web/stat_hlsw.php @@ -0,0 +1,35 @@ +rrdpath, $hlsw->name, $view, 60, 400); + break; + + default: + case 'normal': + Graphs::hlsw($hlsw->rrdpath, $hlsw->name, $view, 120, 800); + break; + } +} + +$hlswid = Input::getVar('hlswid', INP_GET | INP_INT | INP_DEFAULT, 0); +if ($hlswid != 0) { + $hlsw = Hlsw::load($hlswid); + show($hlsw); + +} else { + $view = Input::getVar('view', INP_GET | INP_INT | INP_DEFAULT, 21600); + + $smarty = new MySmarty(); + $masters = Hlsw::getAll(); + $smarty->assign('masters', $masters); + $smarty->assign('view', $view); + $smarty->assign('views', array(21600 => "6 hours", 86400 => "1 day", 604800 => "1 week")); + $smarty->displaySite('Statistics: HLSW Master Server', 'stat_hlsw.tpl'); +} + +?> diff --git a/web/stat_vlan.php b/web/stat_vlan.php new file mode 100644 index 0000000..adeed93 --- /dev/null +++ b/web/stat_vlan.php @@ -0,0 +1,48 @@ +rrdpath, $vlan->fullname, $view, 60, 400); + break; + + default: + case 'normal': + Graphs::vlan($vlan->rrdpath, $vlan->fullname, $view, 120, 800); + break; + } +} + +$vlanid = Input::getVar('vlanid', INP_GET | INP_INT | INP_DEFAULT, 0); +if ($vlanid != 0) { + $vlan = Vlan::load($vlanid); + show($vlan); + +} else { + $trunkid = Input::getVar('trunkid', INP_GET | INP_INT | INP_DEFAULT, 0); + $view = Input::getVar('view', INP_GET | INP_INT | INP_DEFAULT, 21600); + + $trunks = Trunk::getAll(); + + if ($trunkid == 0) { + foreach ($trunks as $trunk) { + $trunkid = $trunk->id; + break; + } + } + + $vlans = Vlan::getAll($trunkid); + + $smarty = new MySmarty(); + $smarty->assign('vlans', $vlans); + $smarty->assign('trunks', $trunks); + $smarty->assign('view', $view); + $smarty->assign('trunkid', $trunkid); + $smarty->assign('views', array(21600 => "6 hours", 86400 => "1 day", 604800 => "1 week")); + $smarty->displaySite('Statistics: Bridge VLANs', 'stat_vlan.tpl'); +} + +?>