config modifications and such
[CBFWR.git] / libcbfwr / config.php
index 3c7a54f..372bd04 100644 (file)
@@ -63,6 +63,7 @@ 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/bonding")) $this->config["hardware"]["netdev"][$fname]["bonding"] = true;
                                if(file_exists("/sys/class/net/$fname/bridge")) $this->config["hardware"]["netdev"][$fname]["bridge"] = true;
@@ -86,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)