178 lines
3.9 KiB
PHP
178 lines
3.9 KiB
PHP
<?php
|
|
require_once('include.php');
|
|
|
|
function add_bridge() {
|
|
$bridge = new Bridge();
|
|
$bridge->name = "New Bridge";
|
|
$bridge->save();
|
|
|
|
Helper::reload(false, "bridge-{$bridge->id}");
|
|
}
|
|
|
|
function mod_bridge() {
|
|
$bridgeid = Input::getVar('bridgeid', INP_GET | INP_INT | INP_DEFAULT, 0);
|
|
if ($bridgeid == 0)
|
|
Helper::reload();
|
|
|
|
$arr = Input::getVar('bridge', INP_POST | INP_ARRAY | INP_DEFAULT, array());
|
|
|
|
$bridge = Bridge::load($bridgeid);
|
|
$bridge->name = $arr['name'];
|
|
$bridge->ctrlip = $arr['ctrlip'];
|
|
$bridge->basemac = strtoupper($arr['basemac']);
|
|
$bridge->save();
|
|
|
|
$bridge->reorder_macs();
|
|
Helper::reload(false, "bridge-{$bridge->id}");
|
|
}
|
|
|
|
function del_bridge() {
|
|
$bridgeid = Input::getVar('bridgeid', INP_GET | INP_INT | INP_DEFAULT, 0);
|
|
if ($bridgeid == 0)
|
|
Helper::reload();
|
|
|
|
Bridge::delete($bridgeid);
|
|
Helper::reload();
|
|
}
|
|
|
|
function mod_trunk() {
|
|
$bridgeid = Input::getVar('bridgeid', INP_GET | INP_INT | INP_DEFAULT, 0);
|
|
if ($bridgeid == 0)
|
|
Helper::reload();
|
|
|
|
$bridge = Bridge::load($bridgeid);
|
|
|
|
$subaction = Input::getVar('subaction', INP_POST | INP_STRING | INP_EMPTY);
|
|
switch ($subaction) {
|
|
case 'add':
|
|
$name = Input::getVar('name', INP_POST | INP_STRING | INP_DEFAULT, "");
|
|
if (!empty($name)) {
|
|
$trunk = new Trunk();
|
|
$trunk->bridgeid = $bridge->id;
|
|
$trunk->name = $name;
|
|
$trunk->save();
|
|
}
|
|
break;;
|
|
|
|
case 'del':
|
|
$trunk_arr = Input::getVar('trunkarr', INP_POST | INP_ARRAY | INP_DEFAULT, array());
|
|
foreach ($trunk_arr as $trunkid)
|
|
Trunk::delete($trunkid);
|
|
|
|
break;
|
|
}
|
|
|
|
$bridge->reorder_macs();
|
|
Helper::reload(false, "bridge-{$bridge->id}");
|
|
}
|
|
|
|
function mod_vlan() {
|
|
$bridgeid = Input::getVar('bridgeid', INP_GET | INP_INT | INP_DEFAULT, 0);
|
|
if ($bridgeid == 0)
|
|
Helper::reload();
|
|
|
|
$bridge = Bridge::load($bridgeid);
|
|
|
|
$subaction = Input::getVar('subaction', INP_POST | INP_STRING | INP_EMPTY);
|
|
switch ($subaction) {
|
|
case 'add':
|
|
$vlannum = Input::getVar('name', INP_POST | INP_STRING | INP_DEFAULT, "");
|
|
$trunkid = Input::getVar('trunk', INP_POST | INP_INT | INP_DEFAULT, 0);
|
|
$bandwidth = Input::getVar('bandwidth', INP_POST | INP_INT | INP_DEFAULT, -1);
|
|
|
|
if (!empty($vlannum) && $trunkid != 0 && $bandwidth != -1) {
|
|
$arr = explode('-', $vlannum);
|
|
if (!isset($arr[1])) {
|
|
$vlan = new Vlan();
|
|
$vlan->trunkid = $trunkid;
|
|
$vlan->vlannum = $arr[0];
|
|
$vlan->bandwidth = $bandwidth;
|
|
$vlan->save();
|
|
|
|
} else {
|
|
for ($i = $arr[0]; $i <= $arr[1]; $i++) {
|
|
$vlan = new Vlan();
|
|
$vlan->trunkid = $trunkid;
|
|
$vlan->vlannum = $i;
|
|
$vlan->bandwidth = $bandwidth;
|
|
$vlan->save();
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'save':
|
|
$vlan_arr = Input::getVar('vlanarr', INP_POST | INP_ARRAY | INP_DEFAULT, array());
|
|
$bandwidth = Input::getVar('bandwidth', INP_POST | INP_INT | INP_DEFAULT, -1);
|
|
|
|
if ($bandwidth != -1) {
|
|
foreach ($vlan_arr as $vlanid) {
|
|
$vlan = Vlan::load($vlanid);
|
|
$vlan->bandwidth = $bandwidth;
|
|
$vlan->save();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'del':
|
|
$vlan_arr = Input::getVar('vlanarr', INP_POST | INP_ARRAY | INP_DEFAULT, array());
|
|
foreach ($vlan_arr as $vlanid)
|
|
Vlan::delete($vlanid);
|
|
|
|
break;
|
|
}
|
|
|
|
$bridge->reorder_macs();
|
|
Helper::reload(false, "bridge-{$bridge->id}");
|
|
}
|
|
|
|
function show() {
|
|
$smarty = new MySmarty();
|
|
|
|
// TODO: single query?
|
|
$bridges = Bridge::getAll();
|
|
foreach ($bridges as $bridge) {
|
|
$bridge->trunks = Trunk::getAll($bridge->id);
|
|
|
|
foreach ($bridge->trunks as $trunk) {
|
|
$trunk->vlans = Vlan::getAll($trunk->id);
|
|
$trunk->vlancnt = count($trunk->vlans);
|
|
}
|
|
}
|
|
|
|
$smarty->assign('bridges', $bridges);
|
|
$smarty->displaySite('Configuration: Bridges', 'bridge.tpl');
|
|
}
|
|
|
|
|
|
$action = Input::getVar('action', INP_GET | INP_STRING | INP_DEFAULT, "show");
|
|
switch ($action) {
|
|
|
|
case 'add_bridge':
|
|
add_bridge();
|
|
break;
|
|
|
|
case 'mod_bridge':
|
|
mod_bridge();
|
|
break;
|
|
|
|
case 'del_bridge':
|
|
del_bridge();
|
|
break;
|
|
|
|
case 'mod_trunk':
|
|
mod_trunk();
|
|
break;
|
|
|
|
case 'mod_vlan':
|
|
mod_vlan();
|
|
break;
|
|
|
|
default:
|
|
case 'show':
|
|
show();
|
|
break;
|
|
}
|
|
|
|
?>
|