making config changes all happen in "addConfigLine"
authorpaulr <me@pjr.cc>
Sun, 2 Oct 2011 16:59:00 +0000 (03:59 +1100)
committerpaulr <me@pjr.cc>
Sun, 2 Oct 2011 16:59:00 +0000 (03:59 +1100)
libcbfwr/config.php
libcbfwr/fwui.php
libcbfwr/web.php
www/css/normal.css

index 372bd04..f2aaa52 100644 (file)
@@ -76,6 +76,10 @@ class Config {
                return $this->config;
        }
        
+       function setConfig($config) {
+               $this->config = $config;
+       }
+       
        function applyConfig()
        {
                global $AM_DAEMON;
@@ -85,87 +89,7 @@ class Config {
                return true;
        }
        
-       function mergeConfig($configone, $configtwo)
-       {
-               // 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)
        {
@@ -184,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);
                
@@ -217,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":
@@ -308,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;
                                
index 4bcfed5..e827c2c 100644 (file)
@@ -334,11 +334,84 @@ function CBFWInterfacesPageDisplay()
        echo "</table>";
 }
 
-function CBFWObjectsPage()
+function CBFWObjectsPage($urls)
 {
        $comms = new Comms();
        
        $config = $comms->getConfig();
+       
+       CBFWpageBuilder(null, "CBFWObjectsDisplay");
+}
+
+function CBFWObjectsDisplay()
+{
+       global $BASE_URL, $MENU_ITEMS;
+       $config = getWebUserConfig();
+       
+       echo "<h2>Objects</h2>";
+       
+       if(isset($config["objects"])) {
+               echo "<table>";
+               echo "<tr><th>Networks</th><th>Hosts</th><th>Services</th><th>Network Groups</th><th>Host Groups</th><th>Service Groups</th></tr>";
+               echo "</table>";
+               foreach($config["objects"] as $key => $var) {
+               }
+       } else {
+               echo "No objects set\n";
+       }
+       
+       echo "<hr>";
+       echo "<table cellpadding=\"20\"><tr valign=\"top\">";
+       echo "<td>";
+       echo "<h3>Create Network</h3><br>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/network/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "IPv4 <input type=\"text\" name=\"addr4\">/<input type=\"text\" name=\"mask4\" maxlength=\"3\" size=\"3\"><br>";
+       echo "IPv6 <input type=\"text\" name=\"addr6\">/<input type=\"text\" name=\"mask6\" maxlength=\"3\" size=\"3\"><br>";
+       echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
+       echo "</form>";
+       echo "</td>";
+       echo "<td>";
+       echo "<h3>Create Host</h3><br>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "IPv4 <input type=\"text\" name=\"addr4\"><br>";
+       echo "IPv6 <input type=\"text\" name=\"addr6\"><br>";
+       echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
+       echo "</form>";
+       echo "</td>";
+       echo "<td>";
+       echo "<h3>Service</h3><br>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "Port <input type=\"text\" name=\"port\">";
+       echo "<select name=\"proto\"><option value=\"tcp\">TCP</option><option value=\"udp\">UDP</option></select><br>";
+       echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
+       echo "</form>";
+       echo "</td>";
+       echo "</tr><tr>";
+       echo "<td>";
+       echo "<h3>Network Group</h3>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/networkgroup/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "</form>";
+       echo "</td>";
+       echo "<td>";
+       echo "<h3>Host Group</h3>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/hostgroup/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "</form>";
+       echo "</td>";
+       echo "<td>";
+       echo "<h3>Service Group</h3>";
+       echo "<form method=\"post\" action=\"$BASE_URL/objects/servicegroup/create\">";
+       echo "Name <input type=\"text\" name=\"objname\"><br>";
+       echo "</form>";
+       echo "</td>";
+       
+       
+       echo "</tr></table>";
+       
 }
 
 function CBFWRulesPage()
@@ -348,6 +421,58 @@ function CBFWRulesPage()
        $config = $comms->getConfig();
 }
 
+function CBFWAdminPage($urls)
+{
+       $comms = new Comms();
+       
+       $config = $comms->getConfig();
+       
+       CBFWpageBuilder(null, "CBFWAdminDisplay");
+}
+
+function CBFWAdminDisplay()
+{
+?>
+<h2>Administration</h2>
+<table cellpadding=10>
+<tr valign="top">
+<td>
+<h3>Users</h3>
+<table>
+<tr><th>Username</th><th>Description</th><th>Enabled?</th></tr>
+<tr><td>Admin</td><td>Twattle</td><td>Yes</td></tr>
+</table>
+<hr>
+<h3>Add User</h3>
+<form method="post" action="asdf">
+Username <input type="text" name="username"><br>
+Password <input type="password" name="pass"><br>
+Description <input type="text" name="desc"><br>
+<input type="submit" name="add" value="Add"><br>
+</form>
+</td>
+<td>
+<h3>Network Access</h3>
+<table>
+<tr><th>From</th><th>Interface</th><th>Type</th></tr>
+<tr><td>Any</td><td>twaddle</td><td>http,https,ssh</td></tr>
+</table>
+<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>
+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>
+</td>
+</tr>
+</table>
+<?php 
+}
+
+
+
 function findUrl($url_s)
 {
        global $URL_HANDLERS;
index 6baae23..f28b21f 100644 (file)
@@ -55,13 +55,13 @@ class CBFWWeb {
                                        CBFWInterfacesPage($url_s);
                                        break;
                                case "objects":
-                                       $bodyFunction = "CBFWObjectsPage";
+                                       CBFWObjectsPage($url_s);
                                        break;
                                case "rules":
                                        $bodyFunction = "CBFWRulesPage";
                                        break;
                                case "admin":
-                                       $bodyFunction = "CBFWAdminPage";
+                                       CBFWAdminPage($url_s);
                                        break;
                                default:
                                        $bodyFunction = findUrl($url_s);
@@ -74,11 +74,6 @@ class CBFWWeb {
 }
 
 
-function CBFWAdminPage($urls)
-{
-       echo "im an admin page";
-}
-
 function CBFBuildHomePage($urls)
 {
        echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
@@ -177,11 +172,11 @@ function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="C
        
        // page top
        echo "<h1>CBFW</h1><br>";
-       echo "<table><tr width=\"100%\"><td>";
+       echo "<table width=\"100%\"><tr width=\"100%\"><td>";
        CBFWMessageBuilder();
-       echo "<td><td><align=\"right\">";
+       echo "<td><td align=\"right\">";
        CBFWConfigStatus();
-       echo "</align></td></tr><tr><td>";
+       echo "</td></tr><tr><td>";
        
        // menu, then body
        echo "<table><tr><td>";
index bf63908..7c79ef7 100644 (file)
@@ -128,11 +128,6 @@ div.wrapper {
   background-color:#dadaf8;
 }
 
-input[type=text] {
-       width: 200px;
-       
-}
-
 input.storage {
        width: 400px;   
 }
\ No newline at end of file