<?php
-function CBFWZonesPage()
+function CBFWZonesPage($urls)
{
+ global $BASE_URL, $MENU_ITEMS;
$comms = new Comms();
- $config = $comms->getConfig();
+ 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;
+ error_log("comparing \"$oldname\" to \"$newname\"");
+ if($oldname != $newname) {
+ $renewname = " rename $newname";
+ }
+
+ $oldconf = getWebUserConfig();
+ $olddesc = $oldconf["zone"][$oldname]["description"];
+ error_log("Comparing \"$olddesc\" and \"$desc\"");
+ 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");
+ error_log("no changes?");
+ 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 "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"];
+ $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");
+ }
+ } else {
+ CBFWpageBuilder(null, "CBFWZonesPageDisplay");
+ }
}
-function CBFWInterfacesPage()
+function CBFWZonesEditPage($urls)
+{
+ global $BASE_URL, $MENU_ITEMS;
+
+ $zone = $urls[2];
+
+ $config = getWebUserConfig();
+
+
+ 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 getWebUserConfig()
{
$comms = new Comms();
+ $myconf = new Config();
- $config = $comms->getConfig();
+
+ // check to see if pre-cache config matches change level of config change buffer
+ $config = $comms->getConfig(5);
+ $conf2 = $comms->getConfig(3);
+ if(isset($config["status"])) {
+ if($config["status"] == $conf2["status"]) {
+ // it did, return the pre-cache
+ error_log("got pre-cache config");
+ return $config;
+ }
+ }
+
+ // it did not, do a new merge and cache
+ $config = $myconf->mergeConfig($comms->getConfig(), $conf2);
+ $reconfig = $config;
+ $reconfig["status"] = $conf2["status"];
+ error_log("put pre-cache config");
+ $comms->putConfig($reconfig, 5);
+
+ return $config;
+}
+
+function CBFWZonesPageDisplay()
+{
+ global $BASE_URL, $MENU_ITEMS;
+
+ $config = getWebUserConfig();
+
+ echo "<h2>Zones</h2>";
+ 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>";
+ $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>";
+ echo "<form method=\"post\" action=\"$BASE_URL/zones/add\">";
+ echo "<hr><h3>Add Zone</h3><br>";
+ echo "Name: <input type=\"text\" name=\"toadd\"><br>";
+ echo "Description: <input type=\"text\" name=\"desc\"><br>";
+ echo "<input type=\"submit\" name=\"Add\" value=\"Add\">";
+ echo "</form>";
+
+}
+
+function CBFWInterfacesPage($urls)
+{
+ if(isset($urls[1])) {
+ switch($urls[1]) {
+ case "edit":
+ CBFWpageBuilder(null, "CBFWInterfacesPageEdit", null, null, $urls[2]);
+ break;
+ case "change":
+ CBFWInterfacesChange();
+ break;
+ default:
+ CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
+ }
+ } else {
+ error_log("main interface page");
+ CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
+ }
+}
+
+function CBFWInterfacesChange()
+{
+ global $BASE_URL, $MENU_ITEMS;
+ $comms = new Comms();
+
+ $comms->sendMessage("interface eth0 changename poof");
+ header("Location: $BASE_URL/interfaces");
+}
+
+function CBFWInterfacesPageEdit($urls)
+{
+ global $BASE_URL, $MENU_ITEMS;
+ $interface = $urls;
+
+ echo "<h3>Edit Interface $interface</h3><br>";
+ echo "<form method=\"post\" action=\"$BASE_URL/interfaces/change/$interface\">";
+ echo "<table>";
+ echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"></td></tr>";
+ echo "<tr><td>HW Address</td><td><input type=\"text\" name=\"hwaddr\"></td></tr>";
+ echo "<tr><td>Zone</td><td><input type=\"text\" name=\"zone\"></td></tr>";
+ echo "<tr><td>IPv4 Address</td><td><input type=\"text\" name=\"ipv4addr\"></td></tr>";
+ echo "<tr><td>IPv6 Address</td><td><input type=\"text\" name=\"ipv6addr\"></td></tr>";
+ echo "<tr><td>Speed</td><td><input type=\"text\" name=\"speed\"></td></tr>";
+ echo "<tr><td>Duplex</td><td><input type=\"text\" name=\"duplex\"></td></tr>";
+ echo "</table>";
+ echo "<input type=\"submit\" name=\"Change\" value=\"Change\"><br>";
+ //echo "<a href=\"$BASE_URL/interfaces/\">Back</a>";
+ echo "</form>";
+}
+
+function CBFWInterfacesPageDisplay()
+{
+ global $BASE_URL, $MENU_ITEMS;
+ $comms = new Comms();
+
+ $config = $comms->getConfig(0);
+ $boot_config = $comms->getConfig(1);
+
+ // now build an interface table
+ $table = array();
+ foreach($boot_config["hardware"]["netdev"] as $key=>$val) {
+ $ename = $key;
+ $table[$key]["realname"] = $val["name"];
+ $table[$key]["name"] = $val["name"];
+
+
+ // driver
+ if(isset($val["driver"])) $table[$key]["type"] = $val["driver"];
+ else $table[$key]["type"] = "Unknown";
+
+ // hw address
+ if(isset($val["hwaddress"])) $table[$key]["hwaddress"] = $val["hwaddress"];
+
+ // current mtu
+ if(isset($val["mtu"])) $table[$key]["mtu"] = $val["mtu"];
+ }
+
+ foreach($config["hardware"]["netdev"] as $key=>$val) {
+ $ename = $key;
+ if(isset($config["interface"]["$key"]["name"])) $table[$key]["name"] = $config["interface"]["$key"]["name"];
+ $table[$key]["address4"] = null;
+ $table[$key]["address6"] = null;
+
+ if(isset($config["interface"][$table[$key]["name"]]["address4"])) {
+ $table[$key]["address4"] = $config["interface"][$table[$key]["name"]]["address4"];
+ }
+
+ if(isset($config["interface"][$table[$key]["name"]]["address6"])) {
+ $table[$key]["address6"] = $config["interface"][$table[$key]["name"]]["address6"];
+ }
+
+ if(isset($config["interface"][$table[$key]["name"]]["mtu"])) {
+ $table[$key]["mtu"] = $config["interface"][$table[$key]["name"]]["mtu"];
+ } else {
+ $table[$key]["mtu"] = "1500"; // TODO: this needs to actually come from somewhere
+ }
+
+ if(isset($config["interface"][$table[$key]["name"]]["speed"])) {
+ $table[$key]["speed"] = $config["interface"][$table[$key]["name"]]["speed"];
+ } else {
+ $table[$key]["speed"] = null;
+ }
+
+ if(isset($config["interface"][$table[$key]["name"]]["duplex"])) {
+ $table[$key]["duplex"] = $config["interface"][$table[$key]["name"]]["duplex"];
+ } else {
+ $table[$key]["duplex"] = null;
+ }
+
+ if(isset($config["interface"][$table[$key]["name"]]["zone"])) {
+ $table[$key]["zone"] = $config["interface"][$table[$key]["name"]]["zone"];
+ } else {
+ $table[$key]["zone"] = null;
+ }
+ }
+
+
+ echo "<table border=\"1\"><th>Device</th><th>Zone</th><th>Type</th><th>MAC Address</th><th>Address</th><th>MTU</th><th>Speed/Duplex</th><th>Control</th></tr>";
+ foreach($table as $key =>$val) {
+ if($val["realname"] == $val["name"]) $name = $val["name"];
+ else $name = $val["name"]." (".$val["realname"].")";
+
+ // zone
+ if($val["zone"] == null) $zone = "-";
+ else $zone = $val["zone"];
+
+ // mtu
+ $mtu = $val["mtu"];
+
+ // driver type
+ $type = $val["type"];
+
+ // hardware address
+ $mac = $val["hwaddress"];
+
+ // speed and duplex
+ if($val["duplex"] == null) $dup = "default";
+ else $dup = $val["duplex"];
+
+ if($val["speed"] == null) $spd = "default";
+ else $spd = $val["speed"];
+
+ $spanddu = "$spd/$dup";
+
+ // network address
+ if($val["address4"]!=null && $val["address6"]!=null) {
+ $address = $val["address4"]."<br>".$val["address6"];
+ } else if($val["address4"] != null) {
+ $address = $val["address4"];
+ } else if($val["address6"] != null) {
+ $address = $val["address6"];
+ } else {
+ $address = "-";
+ }
+
+ echo "<tr><th>$name</th><td>$zone</td><td>$type</td><td>$mac</td><td>$address</td><td>$mtu</td><td>$spanddu</td><td><a href=\"$BASE_URL/interfaces/edit/".$val["realname"]."\">Edit</a></td></tr>";
+ }
+ echo "</table>";
}
function CBFWObjectsPage()