working on the interfaces page
[CBFWR.git] / libcbfwr / fwui.php
index 63c6613..adc9541 100644 (file)
@@ -192,6 +192,31 @@ function CBFWZonesPageDisplay()
        
 }
 
+function CBFWRoutingPage($urls)
+{
+       if(isset($urls[1])) {
+               switch($urls[1]) {
+                       case "edit":
+                               CBFWpageBuilder(null, "CBFWRoutingPageEdit", null, null, $urls[2]);
+                               break;
+                       case "change":
+                               CBFWRoutingChange();
+                               break;
+                       default:
+                               CBFWpageBuilder(null, "CBFWRoutingPageDisplay");
+               }
+       } else {
+               error_log("main interface page");
+               CBFWpageBuilder(null, "CBFWRoutingPageDisplay");
+       }
+       
+}
+
+function CBFWRoutingPageDisplay()
+{
+       echo "<h2>Routing</h2>";
+}
+
 function CBFWInterfacesPage($urls)
 {
        if(isset($urls[1])) {
@@ -216,7 +241,6 @@ function CBFWInterfacesChange()
        global $BASE_URL, $MENU_ITEMS;
        $comms = new Comms();
        
-       $comms->sendMessage("interface eth0 changename poof");
        header("Location: $BASE_URL/interfaces");
 }
 
@@ -225,16 +249,51 @@ function CBFWInterfacesPageEdit($urls)
        global $BASE_URL, $MENU_ITEMS;
        $interface = $urls;
        
+       $comms = new Comms();
+       
+       $config = getWebUserConfig();
+       $boot_config = $comms->getConfig(1);
+       
+       if(isset($config["interface"]["dev"]["$interface"]["name"])) $name = $config["interface"]["dev"]["$interface"]["name"];
+       else $name = "";
+       
+       $extra2 = "";
+       if(file_exists("/sys/class/net/$interface/address")) {
+               $extra2 = trim(file_get_contents("/sys/class/net/$interface/address"));
+       }
+       
+       $extra = "";
+       if(isset($boot_config["hardware"]["netdev"]["$interface"]["hwaddress"])) {
+               $hwaddr = $boot_config["hardware"]["netdev"]["$interface"]["hwaddress"];
+               $extra = " <i>Original address: $hwaddr</i>";
+               if($hwaddr != $extra2 && $extra2 != "") {
+                       $extra .= " <i>Current Address: $hwaddr</i>";
+               }
+       }
+       if(isset($config["interface"]["dev"]["$interface"]["hwaddress"])) $hwaddr = $config["interface"]["dev"]["$interface"]["hwaddress"];
+       
+       if(isset($config["interface"]["dev"]["$interface"]["zone"])) $zone = $config["interface"]["dev"]["$interface"]["zone"];
+       
+       if(isset($config["interface"]["dev"]["$interface"]["address4"])) $ip4 = $config["interface"]["dev"]["$interface"]["address4"];
+       
+       if(isset($config["interface"]["dev"]["$interface"]["address6"])) $ip6 = $config["interface"]["dev"]["$interface"]["address6"];
+       
+       if(isset($boot_config["hardware"]["netdev"]["$interface"]["speed"])) $speed = $boot_config["hardware"]["netdev"]["$interface"]["speed"];
+       if(isset($boot_config["hardware"]["netdev"]["$interface"]["duplex"])) $duplex = $boot_config["hardware"]["netdev"]["$interface"]["duplex"];
+       if(isset($config["interface"]["dev"]["$interface"]["speed"])) $speed = $config["interface"]["dev"]["$interface"]["speed"];
+       if(isset($config["interface"]["dev"]["$interface"]["duplex"])) $duplex = $config["interface"]["dev"]["$interface"]["duplex"];
+       
        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 "<tr><td>Name</td><td><input type=\"text\" name=\"name\" value=\"$name\"></td></tr>";
+       echo "<tr><td>HW Address</td><td><input type=\"text\" name=\"hwaddr\" value=\"$hwaddr\">$extra</td></tr>";
+       echo "<tr><td>Zone</td><td><input type=\"text\" name=\"zone\" value=\"$zone\"></td></tr>";
+       echo "<tr><td>IPv4 Address</td><td><input type=\"text\" name=\"ipv4addr\" value=\"$ip4\"></td></tr>";
+       echo "<tr><td>IPv6 Address</td><td><input type=\"text\" name=\"ipv6addr\" value=\"$ip6\"></td></tr>";
+       echo "<tr><td>Speed</td><td><select name=\"duplex\"><option value=\"auto\">Auto</option><option value=\"10\">10</option>";
+       echo "<option value=\"100\">100</option><option value=\"1000\">1000</option><option value=\"10000\">10000</option></select></td></tr>";
+       echo "<tr><td>Duplex</td><td><select name=\"duplex\"><option value=\"auto\">Auto</option><option value=\"full\">Full</option><option value=\"half\">Half</option></select></td></tr>";
        echo "</table>";
        echo "<input type=\"submit\" name=\"Change\" value=\"Change\"><br>";
        //echo "<a href=\"$BASE_URL/interfaces/\">Back</a>";
@@ -246,9 +305,16 @@ function CBFWInterfacesPageDisplay()
        global $BASE_URL, $MENU_ITEMS;
        $comms = new Comms();
        
-       $config = $comms->getConfig(0);
+       $config = getWebUserConfig();
        $boot_config = $comms->getConfig(1);
        
+       // at the top, we put in the creation bits
+       echo "<h2>Create Interface</h2>";
+       echo "<li><a href=\"$BASE_URL/interfaces/create/bond\">Link Aggregation Group (bonded/teamed interfaces)</a><br>";
+       echo "<li><a href=\"$BASE_URL/interfaces/create/vlan\">VLAN Tagged Sub Interfaces</a><br>";
+       echo "<li><a href=\"$BASE_URL/interfaces/create/bridge\">Bridged Interfaces</a><br>";
+       echo "<hr>";
+       
        // now build an interface table
        $table = array();
        foreach($boot_config["hardware"]["netdev"] as $key=>$val) {
@@ -266,89 +332,88 @@ function CBFWInterfacesPageDisplay()
                
                // 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;
-               }
+               // speed
+               if(isset($val["speed"])) $table[$key]["speed"] = $val["speed"];
+               else $table[$key]["speed"] = "default";
                
-               if(isset($config["interface"][$table[$key]["name"]]["zone"])) {
-                       $table[$key]["zone"] = $config["interface"][$table[$key]["name"]]["zone"];
-               } else {
-                       $table[$key]["zone"] = null;
-               }
+               // duplex
+               if(isset($val["duplex"])) $table[$key]["duplex"] = $val["duplex"];
+               else $table[$key]["duplex"] = "default";
        }
        
+       foreach($config["interface"]["dev"] as $key => $val) {
+               // TODO construction zone
+               error_log("doing $key");
+               if(isset($val["name"])) $table[$key]["name"] = $val["name"];
+               if(isset($val["address4"])) $table[$key]["address4"] = $val["address4"];
+               if(isset($val["address6"])) $table[$key]["address6"] = $val["address6"];
+               if(isset($val["description"])) $table[$key]["description"] = $val["description"];
+               if(isset($val["zone"])) $table[$key]["zone"] = $val["zone"];
+       }
+
        
-       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>";
+       echo "<h2>Interfaces</h2><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>Description</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"];
+               if(isset($val["zone"])) {
+                       if($val["zone"] == null) $zone = "-";
+                       else $zone = $val["zone"];
+               } else $zone = "-";
                
                // mtu
-               $mtu = $val["mtu"];
+               if(isset($val["mtu"])) {
+                       $mtu = $val["mtu"];
+               } else $mtu = "-";
                
                // driver type
-               $type = $val["type"];
+               if(isset($val["type"])) { 
+                       $type = $val["type"];
+               } else $type = "-";
                
                // hardware address
-               $mac = $val["hwaddress"];
+               if(isset($val["hwaddress"])) {
+                       $mac = $val["hwaddress"];
+               } else $mac = "-";
                
                // speed and duplex
-               if($val["duplex"] == null) $dup = "default";
-               else $dup = $val["duplex"];
+               if(isset($val["duplex"])) {
+                       if($val["duplex"] == null) $dup = "default";
+                       else $dup = $val["duplex"];
+               } //else $dup = "default"; // TODO: needs to go away in fav of hardware setting
                
-               if($val["speed"] == null) $spd = "default";
-               else $spd = $val["speed"];
+               if(isset($val["speed"])) {
+                       if($val["speed"] == null) $spd = "default";
+                       else $spd = $val["speed"];
+               } //else $spd = "default"; // TODO: needs to go away inf av of hardware setting
                
                $spanddu = "$spd/$dup";
                
                // network address
-               if($val["address4"]!=null && $val["address6"]!=null) {
+               if(isset($val["address4"]) && isset($val["address6"])) {
                        $address = $val["address4"]."<br>".$val["address6"];
-               } else if($val["address4"] != null) {
+               } else if(isset($val["address4"])) {
                        $address = $val["address4"];
-               } else if($val["address6"] != null) {
+               } else if(isset($val["address6"])) {
                        $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>";
+               if(isset($val["description"])) $desc = $val["description"];
+               else $desc = "-";
+               
+               echo "<tr><th>$name</th><td>$zone</td><td>$type</td><td>$mac</td><td>$address</td><td>$mtu</td><td>$spanddu</td><td>$desc</td><td><a href=\"$BASE_URL/interfaces/edit/".$val["realname"]."\">Edit</a></td></tr>";
        }
        echo "</table>";
+       
+       // to test
+       echo "config: <pre>";
+       print_r($config);
+       echo "</pre>";
 }
 
 function CBFWObjectsPage($urls)
@@ -516,8 +581,8 @@ Description <input type="text" name="desc"><br>
 <hr>
 <h3>Add Access</h3>
 <form method="post" action="asdf">
-From <input type="text" name="from"> <i>either "any", an address (1.2.3.4) or a network (1.2.3.4/23)</i><br>
-Interface <select><option value="something">twad</option><option name="some">craw</option></select>
+From <select name="from"><option value="something">Any</option><option name="some">Intranet</option><option name="som">SomeHost</option></select><br>
+Interface <select name="interface"><option value="something">twad</option><option name="some">craw</option></select>
 Protocols <input type="checkbox" name="http">HTTP <input type="checkbox" name="http">HTTPS <input type="checkbox" name="http">SSH<br> 
 <input type="submit" name="add" value="Add"><br>
 </form>