config modifications and such
[CBFWR.git] / libcbfwr / config.php
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)