web config writes directly to 3 and messages cbrwrd about stuff.
config layout is like this:
+[status] = conf|noconf|nodir|changelevel
+[hostname] = hostname
+[domainname] = domainname
+[login][username] = sha1password
+[zone][<zonename>][name]=1
+[interface][<interfacename>][desciption] = desc
+ [name] = name
+ [address4] = address
+ [address6] = address
+ [zone] = zone
+ [mtu] = mtu
+ [speed] = speed
+ [duplex] = duplex
+
+[lag][<lagname>][<x>] = interface
+ [description] = desc
+
+[bridge][<bridgename>][<x>] = interface
+ [description]
+
+[route4][default|<network>][address] = gateway
+ [device] = device
+ [description]
+[route6][default|<network>][address] = gateway
+ [device] = device
+ [description]
+
+[dns][server][<x>][address] = address
+
+[ntp][server][<x>][address] = adddress
+
+[hardware][netdev][<itnerface>][name] = realname
+ [driver] = driver
+ [mtu] = mtu
+ [hwaddress] = mac address
\ No newline at end of file
function mergeConfig($configone, $configtwo)
{
- // yep
+ // yep this means apply changes in configtwo to configone
+ $newconf = $configone;
+
+ // this is gunna be tough its gunna be a meet on meet sandwitch
+ foreach($configtwo as $key => $var) {
+ if($key != "status") {
+ error_log("apply change $key");
+ foreach($var as $key2=>$var2) {
+ error_log("which is $key2");
+ $splits = explode(" ", $var2);
+
+ // find a description
+ $description = null;
+ $hasdescription = false;
+ for($i=0; $i<count($splits); $i++) {
+ if($hasdescription !== false) {
+ if($description != null) {
+ $description .= " ";
+ }
+ $description .= $splits[$i];
+ }
+ if($splits[$i] == "#") {
+ $hasdescription = $i;
+ }
+ }
+
+
+ switch($key2) {
+ case "add":
+ error_log("would add $var2");
+ $thing = $splits[0];
+ switch($thing) {
+ case "zone":
+ $newconf["zone"][$splits[1]]["name"] = 1;
+ if($hasdescription) {
+ $newconf["zone"][$splits[1]]["description"] = $description;
+ }
+ break;
+
+ }
+ break;
+ case "modify":
+ error_log("would modify $var2");
+ $thing = $splits[0];
+ switch($thing) {
+ case "zone":
+ $zonename = $splits[1];
+ if($hasdescription) {
+ $newconf["zone"][$splits[1]]["description"] = $description;
+ }
+ if($splits[2] == "rename") {
+ $newname = $splits[3];
+ $tree = $newconf["zone"][$splits[1]];
+ unset($newconf["zone"][$splits[1]]);
+ $newconf["zone"][$newname] = $tree;
+ }
+ break;
+
+ }
+ break;
+
+
+ case "delete":
+ error_log("would delete $var2");
+ $thing = $splits[0];
+ switch($thing) {
+ case "zone":
+ $deletezone = $splits[1];
+ unset($newconf["zone"][$deletezone]);
+ break;
+
+ }
+ break;
+ }
+ }
+ }
+ }
+ return $newconf;
}
function loadConfigFile($file=null)
if(isset($urls[1])) {
switch($urls[1]) {
+ case "modify":
+
+ if($_REQUEST["description"] != "") $desc = $_REQUEST["description"];
+ else $desc = null;
+
+ $oldname = $_REQUEST["oldname"];
+ $newname = $_REQUEST["zonename"];
+
+ $renewname = null;
+ if($oldname != $newname) {
+ $renewname = " rename $newname";
+ }
+
+ $oldconf = $comms->getConfig(0);
+ $olddesc = $oldconf["zone"][$oldname]["description"];
+ if($desc != $olddesc) {
+ $newdesc = " # $desc";
+ } else $newdesc = null;
+
+ //echo "confs: \"$olddesc\", \"$newdesc\", $oldname, $newname<br>";
+ //exit(0);
+
+ if($renewname == null && $newdesc == null) {
+ header("Location: $BASE_URL/zones");
+ return;
+ }
+
+
+ $conf = $comms->getConfig(3);
+ $changes = $conf["status"];
+ if($changes == "nochange") $conf["status"] = 1;
+ else $conf["status"] = $changes + 1;
+ $cnum = $conf["status"];
+
+ $conf[$cnum]["modify"] = "zone $oldname$renewname$newdesc";
+ $comms->putConfig($conf, 3);
+ header("Location: $BASE_URL/zones");
+
+ break;
+
+
case "edit":
+ CBFWpageBuilder(null, "CBFWZonesEditPage", null, null, $urls);
break;
- case "change":
+
+
+ case "delete":
+ $zonetodelete = $urls[2];
+
+ $conf = $comms->getConfig(3);
+ $changes = $conf["status"];
+ if($changes == "nochange") $conf["status"] = 1;
+ else $conf["status"] = $changes + 1;
+ $cnum = $conf["status"];
+
+ $conf[$cnum]["delete"] = "zone $zonetodelete";
+ $comms->putConfig($conf, 3);
+ header("Location: $BASE_URL/zones");
break;
+
+
case "add":
+
+ // UGLY
+ $cnum = 0;
$nametoadd = $_REQUEST["toadd"];
- $comms->sendMessage("zone add $nametoadd");
- //if($_REQUEST["desc"] != "") $comms->sendMessage("zone ")
+ $desc = $_REQUEST["desc"];
+ $descbit = "";
+ if($desc != "") $descbit = " # $desc";
+ if($nametoadd == "" || $nametoadd == null) {
+ return;
+ }
+ $conf = $comms->getConfig(3);
+ $changes = $conf["status"];
+ if($changes == "nochange") $conf["status"] = 1;
+ else $conf["status"] = $changes + 1;
+ $cnum = $conf["status"];
+ $conf[$cnum]["add"] = "zone $nametoadd$descbit";
+ $comms->putConfig($conf, 3);
header("Location: $BASE_URL/zones");
break;
+
+
default:
CBFWpageBuilder(null, "CBFWZonesPageDisplay");
}
}
}
+function CBFWZonesEditPage($urls)
+{
+ global $BASE_URL, $MENU_ITEMS;
+
+ $zone = $urls[2];
+
+ $comms = new Comms();
+ $myconf = new Config();
+
+ $config = $comms->getConfig();
+ $conf2 = $comms->getConfig(3);
+ $config = $myconf->mergeConfig($config, $conf2);
+
+
+ echo "<h2>Edit Zone $zone</h2>";
+ echo "<form method=\"post\" action=\"$BASE_URL/zones/modify/$zone\">";
+ echo "<input type=\"hidden\" name=\"oldname\" value=\"$zone\">";
+ echo "Name: <input type=\"text\" name=\"zonename\" value=\"$zone\"><br>";
+
+ if(isset($config["zone"][$zone]["description"])) $desc = $config["zone"][$zone]["description"];
+
+ echo "Description: <input type=\"text\" name=\"description\" value=\"$desc\"><br>";
+ echo "<input type=\"submit\" name=\"Go\" value=\"Go\">";
+ echo "</form>";
+}
+
function CBFWZonesPageDisplay()
{
global $BASE_URL, $MENU_ITEMS;
$comms = new Comms();
+ $myconf = new Config();
$config = $comms->getConfig();
+ $conf2 = $comms->getConfig(3);
+ $config = $myconf->mergeConfig($config, $conf2);
echo "<h2>Zones</h2>";
- echo "<table border=\"1\"><tr><th>Zone</th><th>Interfaces</th><th>Edit</th></tr>";
+ echo "<table border=\"1\"><tr><th>Zone</th><th>Interfaces</th><th>Description</th><th>Edit</th></tr>";
foreach($config["zone"] as $key => $var) {
$name = $key;
$url = "<a href=\"$BASE_URL/zones/edit/$name\">Edit</a>";
- echo "<tr><td>$name</td><td>...</td><td>$url</td></tr>";
+ $url2 = "<a href=\"$BASE_URL/zones/delete/$name\">Delete</a>";
+ $desc = $var["description"];
+ echo "<tr><td>$name</td><td>...</td><td>$desc</td><td>$url $url2</td></tr>";
}
echo "</table><br>";
function CBFWMessageBuilder()
{
-
+ echo "message";
}
function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
// page top
echo "<h1>CBFW</h1><br>";
- echo "<table><tr><td>";
+ echo "<table><tr width=\"100%\"><td>";
CBFWMessageBuilder();
- echo "<td></tr><tr><td>";
+ echo "<td><td><align=\"right\">";
+ CBFWConfigStatus();
+ echo "</align></td></tr><tr><td>";
// menu, then body
echo "<table><tr><td>";
}
+function CBFWConfigStatus()
+{
+ $comms = new Comms();
+
+ $conf0 = $comms->getConfig(0);
+ $conf1 = $comms->getConfig(2);
+ $conf2 = $comms->getConfig(3);
+
+ if($conf1["status"] == "nochange") {
+ $saved = "Current";
+ $running = "Current";
+ } else {
+ $saved = "Old";
+ $running = "Current";
+ }
+ if($conf2["status"] == "nochange") {
+ $client = "Current";
+ } else {
+ $ch = $conf2["status"];
+ $client = "$ch Changes";
+ }
+
+
+ echo "Saved Config: $saved<br>";
+ echo "Running Config: $running<br>";
+ echo "Client Config: $client<br>";
+}
+
function cbfw_tdiffToAgo($time_in_sec)
{
$tdiff = $time_in_sec;