working on the interfaces page
authorpaulr <me@pjr.cc>
Mon, 3 Oct 2011 16:52:18 +0000 (03:52 +1100)
committerpaulr <me@pjr.cc>
Mon, 3 Oct 2011 16:52:18 +0000 (03:52 +1100)
doco/commands.txt
doco/configs.txt
libcbfwr/config.php
libcbfwr/fwui.php
unittests/deletechanges.php
var/fw.conf
var/fw.conf.example

index 9619cf8..58b2f12 100644 (file)
@@ -15,6 +15,8 @@ interace dev devname address6 addr/mask
 interace dev devname zone zonename
 interace dev devname mtu|speed|duplex ...
 
+interface name devname address[46]|zone|mtu|speed|duplex
+
 interface lag name <name> with <dev1> <dev2>....
 
 interface vlan <vlanid> name <name> from <dev>
index 1ba570c..55db8a2 100644 (file)
@@ -21,11 +21,13 @@ config layout is like this:
                             [mtu] = mtu
                             [speed] = speed
                             [duplex] = duplex
+
+
                             
-[lag][<lagname>][<x>] = interface
+[interface][lag][<lagname>][<x>] = interface
                 [description] = desc
                 
-[bridge][<bridgename>][<x>] = interface
+[interface][bridge][<bridgename>][<x>] = interface
                       [description]
                       
 [route4][default|<network>][address] = gateway
index e0b4f37..c0c43d1 100644 (file)
@@ -63,10 +63,20 @@ class Config {
                                        }
                                        fclose($fp);
                                }
-                               if(file_exists("/sys/class/net/$fname/mtu")) $this->config["hardware"]["netdev"][$fname]["mtu"] = file_get_contents("/sys/class/net/$fname/mtu");
-                               if(file_exists("/sys/class/net/$fname/address")) $this->config["hardware"]["netdev"][$fname]["hwaddress"] = file_get_contents("/sys/class/net/$fname/address");
+                               if(file_exists("/sys/class/net/$fname/mtu")) $this->config["hardware"]["netdev"][$fname]["mtu"] = trim(file_get_contents("/sys/class/net/$fname/mtu"));
+                               if(file_exists("/sys/class/net/$fname/address")) $this->config["hardware"]["netdev"][$fname]["hwaddress"] = trim(file_get_contents("/sys/class/net/$fname/address"));
                                if(file_exists("/sys/class/net/$fname/bonding")) $this->config["hardware"]["netdev"][$fname]["bonding"] = true;
                                if(file_exists("/sys/class/net/$fname/bridge")) $this->config["hardware"]["netdev"][$fname]["bridge"] = true;
+                               if(file_exists("/sys/class/net/$fname/duplex")) {
+                                       $myval = trim(file_get_contents("/sys/class/net/$fname/duplex"));
+                                       if($myval == null) $myval = "default";
+                                       $this->config["hardware"]["netdev"][$fname]["duplex"] = $myval; 
+                               }
+                               if(file_exists("/sys/class/net/$fname/speed")) {
+                                       $myval = trim(file_get_contents("/sys/class/net/$fname/speed"));
+                                       if($myval == null) $myval = "default";
+                                       $this->config["hardware"]["netdev"][$fname]["speed"] = $myval; 
+                               }
                        }
                }
        }
@@ -112,6 +122,27 @@ class Config {
                }
        }
        
+       function resolveInterfaceName($name)
+       {
+               // $config only ever contains real interface names
+               if(isset($this->config["interface"]["dev"][$name])) return $name;
+               
+               if(isset($this->config["interface"])) {
+                       foreach($this->config["interface"]["dev"] as $key => $var) {
+                               if(isset($var["name"])) {
+                                       if($var["name"] == $name) {
+                                               return $key;
+                                       }
+                               }
+                       }
+               } else {
+                       // have to assume its a hardware name and check /sys
+                       if(file_exists("/sys/class/net/$name")) return $name;
+               }
+               
+               return null;
+       }
+       
        function addConfigLine($line, $lineno=0)
        {
                $line_n = trim($line);
@@ -211,33 +242,40 @@ class Config {
                        case "interface":
                                switch($expl[1]) {
                                        case "dev":
-                                               $int = $expl[2];
-
+                                               $int = $this->resolveInterfaceName($expl[2]);
+                                               
+                                               if($int != $expl[2]) {
+                                                       error_log("resolved int as $int from ".$expl[2]);
+                                               }
+                                               if($int == null) {
+                                                       error_log("got config for interface ".$expl[2]." but i cannot find it, i will assume its hardware for now");
+                                                       $int = $expl[2];
+                                               }
                                                if($hasdescription) {
-                                                       $this->config["interface"][$int]["description"] = $description;
+                                                       $this->config["interface"]["dev"][$int]["description"] = $description;
                                                }
        
                                                switch($expl[3]) {
                                                        case "address4":
-                                                               $this->config["interface"]["$int"]["address4"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["address4"] = $expl[4];
                                                                break;
                                                        case "address6":
-                                                               $this->config["interface"]["$int"]["address6"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["address6"] = $expl[4];
                                                                break;
                                                        case "name":
-                                                               $this->config["interface"]["$int"]["name"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["name"] = $expl[4];
                                                                break;
                                                        case "status":
-                                                               $this->config["interface"]["$int"]["status"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["status"] = $expl[4];
                                                                break;
                                                        case "mtu":
-                                                               $this->config["interface"]["$int"]["mtu"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["mtu"] = $expl[4];
                                                                break;
                                                        case "zone":
-                                                               $this->config["interface"]["$int"]["zone"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["zone"] = $expl[4];
                                                                break;
                                                        case "speed":
-                                                               $this->config["interface"]["$int"]["speed"] = $expl[4];
+                                                               $this->config["interface"]["dev"]["$int"]["speed"] = $expl[4];
                                                                break;
                                                        case "duplex":
                                                                $this->config["interface"]["$int"]["duplex"] = $expl[4];
index 63c6613..da324e8 100644 (file)
@@ -246,9 +246,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 +273,87 @@ 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>";
+       
+       echo "config: <pre>";
+       print_r($config);
+       echo "</pre>";
 }
 
 function CBFWObjectsPage($urls)
@@ -516,8 +521,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>
index 088bb28..f2cc4a0 100644 (file)
@@ -20,7 +20,7 @@ glcas_pluginLoader();
 $comms = new Comms();
 
 $comms->deleteConfig(3);
-
+$comms->deleteConfig(5);
 $config["status"] = "nochange";
 $comms->putConfig($config, 3);
 
index 0cc139a..2ec5fe3 100644 (file)
@@ -10,5 +10,5 @@ zone name internet # this is a description
 interface dev eth0 name twatter # twatter is our outbound interface
 
 interface dev twatter address4 10.172.192.10/24
+interface dev twatter address6 2001:23:1004:dead::1/64
 interface dev twatter zone internet
-
index 2302bad..65fda05 100644 (file)
@@ -15,7 +15,7 @@ interface dev eth0 name twatter # twatter is our outbound interface
 interface dev eth1 name mixer
 
 interface dev twatter address4 10.172.192.10/24
-interface dev twatter address6 2003:12:12:12::1/64
+interface dev eth0 address6 2003:12:12:12::1/64
 interface dev twatter zone internet
 
 admin allowed on dev twatter from object/network/any via http https ssh