config modifications and such
authorpaulr <me@pjr.cc>
Thu, 22 Sep 2011 16:41:01 +0000 (02:41 +1000)
committerpaulr <me@pjr.cc>
Thu, 22 Sep 2011 16:41:01 +0000 (02:41 +1000)
bin/cbfwrd.php
doco/configs.txt
libcbfwr/config.php
libcbfwr/fwui.php
libcbfwr/web.php
var/fw.conf

index 4abcbbd..4a9f5a5 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 $CMD_ROOT_FS = realpath(dirname(__FILE__));
 $AM_DAEMON = true;
+$MOCKUP = true;
 
-global $CMD_ROOT_FS;
-global $AM_DAEMON;
+global $CMD_ROOT_FS, $AM_DAEMON, $MOCKUP;
 
 // add libglcas as if it were a path in ../libglcas
 if(file_exists("../libcbfwr")) {
index 47d3e5b..1ba570c 100644 (file)
@@ -8,4 +8,39 @@ there are 3 areas in shared memory reserved for configuration.
 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
index 3720d6a..372bd04 100644 (file)
@@ -87,7 +87,84 @@ class Config {
        
        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)
index 5d78f38..fb9ef70 100644 (file)
@@ -7,16 +7,89 @@ function CBFWZonesPage($urls)
        
        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");
                }
@@ -25,20 +98,51 @@ function CBFWZonesPage($urls)
        }
 }
 
+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>";
index 562d1db..6baae23 100644 (file)
@@ -130,7 +130,7 @@ function CBFWAddMessage($messagelev, $message)
 
 function CBFWMessageBuilder()
 {
-
+       echo "message";
 }
 
 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
@@ -177,9 +177,11 @@ function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="C
        
        // 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>";
@@ -230,6 +232,34 @@ function cbfw_getLastSeen($ip, $data)
        
 }
 
+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;
index 732c25a..0cc139a 100644 (file)
@@ -2,13 +2,13 @@ hostname hostname
 
 domainname domain.name
 
-zone name internet
+login admin auth $4$QqcI5xWa$Ty8Vs3aAVBwPF0IpKO5hvgUi4wA$
+
+
+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 2003:12:12:12::1/64
-interface dev twatter speed 1000
-interface dev twatter duplex full
 interface dev twatter zone internet
 
-interface dev twatter mtu 1400
\ No newline at end of file