X-Git-Url: http://git.pjr.cc/?p=CBFWR.git;a=blobdiff_plain;f=libcbfwr%2Fconfig.php;h=f2aaa521d7f4b6d6c527eaa2fcfea8f8066684f6;hp=3720d6a30021a3e02c983a872265b1b7b9fa9b7a;hb=86842492eae6203c9df0df46363b4e809d577c70;hpb=fa4d5e8e3250b981ee563f21df08c729dd3d4c57 diff --git a/libcbfwr/config.php b/libcbfwr/config.php index 3720d6a..f2aaa52 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -76,6 +76,10 @@ class Config { return $this->config; } + function setConfig($config) { + $this->config = $config; + } + function applyConfig() { global $AM_DAEMON; @@ -85,10 +89,7 @@ class Config { return true; } - function mergeConfig($configone, $configtwo) - { - // yep - } + function loadConfigFile($file=null) { @@ -107,11 +108,11 @@ class Config { while($line = fgets($fp)) { $line = trim($line); echo "read line $line\n"; - if($line != "") $this->parseLine($line, $i++); + if($line != "") $this->addConfigLine($line, $i++); } } - function parseLine($line, $lineno) + function addConfigLine($line, $lineno=0) { $expl = preg_split("/ +/", $line); @@ -140,22 +141,51 @@ class Config { $expl = $expl_r; } + $delete = false; + // check for delete on the line + if($expl[0] == "delete") { + $delete = true; + + // re-order the array + for($i=0; $i < (count($expl)-1); $i++) { + $expl[$i] = $expl[$i+1]; + } + unset($expl[count($expl)-1]); + } + switch($expl[0]) { case "hostname": // set the hostname to $1 - $this->config["hostname"] = $expl[1]; + if($delete) { + unset($this->config["hostname"]); + } else { + $this->config["hostname"] = $expl[1]; + } break; case "domainname": // set the hostname to $1 - $this->config["domainname"] = $expl[1]; + if($delete) { + unset($this->config["domainname"]); + } else { + $this->config["domainname"] = $expl[1]; + } break; case "zone": - if($hasdescription) { - $this->config["zone"][$expl[2]]["description"] = $description; + if($delete) { + error_log("delete zone ".$expl[2]); + unset($this->config["zone"][$expl[2]]); + if(count($this->config["zone"]) < 1) { + error_log("zone now empty, delete zones"); + unset($this->config["zone"]); + } + } else { + if($hasdescription) { + $this->config["zone"][$expl[2]]["description"] = $description; + } + $this->config["zone"][$expl[2]]["name"] = true; } - $this->config["zone"][$expl[2]]["name"] = true; break; case "interface": @@ -231,54 +261,65 @@ class Config { case "login": - $this->config["login"][$expl[1]] = $expl[3]; - if($hasdescription) { - $this->config["login"][$expl[1]]["description"] = $description; + if($delete) { + unset($this->config["login"][$expl[1]]); + } else { + $this->config["login"][$expl[1]] = $expl[3]; + if($hasdescription) { + $this->config["login"][$expl[1]]["description"] = $description; + } } break; case "route4": - $route = $expl[1]; - $via = $expl[2]; - $dest = $expl[3]; - if($via == "to") { - $this->config["route4"][$route]["address"] = $dest; + if($delete) { + unset($this->config["route4"][$expl[1]]); } else { - $this->config["route4"][$route]["device"] = $dest; - } - if(isset($expl[4])) { - if($expl[4] == "dev") { - if(isset($expl[5])) { - $this->config["route4"][$route]["device"] = $expl[5]; + $route = $expl[1]; + $via = $expl[2]; + $dest = $expl[3]; + if($via == "to") { + $this->config["route4"][$route]["address"] = $dest; + } else { + $this->config["route4"][$route]["device"] = $dest; + } + if(isset($expl[4])) { + if($expl[4] == "dev") { + if(isset($expl[5])) { + $this->config["route4"][$route]["device"] = $expl[5]; + } } } - } - if($hasdescription) { - $this->config["route4"][$route]["description"] = $description; + if($hasdescription) { + $this->config["route4"][$route]["description"] = $description; + } } break; case "route6": - $route = $expl[1]; - $via = $expl[2]; - $dest = $expl[3]; - if($via == "to") { - $this->config["route6"][$route]["address"] = $dest; + if($delete) { + unset($this->config["route6"][$expl[1]]); } else { - $this->config["route6"][$route]["device"] = $dest; - } - if(isset($expl[4])) { - if($expl[4] == "dev") { - if(isset($expl[5])) { - $this->config["route6"][$route]["device"] = $expl[5]; + $route = $expl[1]; + $via = $expl[2]; + $dest = $expl[3]; + if($via == "to") { + $this->config["route6"][$route]["address"] = $dest; + } else { + $this->config["route6"][$route]["device"] = $dest; + } + if(isset($expl[4])) { + if($expl[4] == "dev") { + if(isset($expl[5])) { + $this->config["route6"][$route]["device"] = $expl[5]; + } } } + if($hasdescription) { + $this->config["route6"][$route]["description"] = $description; + } } - if($hasdescription) { - $this->config["route6"][$route]["description"] = $description; - } - // here we should check "$route" break;