making config changes all happen in "addConfigLine"
[CBFWR.git] / libcbfwr / fwui.php
index fb9ef70..e827c2c 100644 (file)
@@ -16,12 +16,14 @@ function CBFWZonesPage($urls)
                                $newname = $_REQUEST["zonename"];
                                
                                $renewname = null;
+                               error_log("comparing \"$oldname\" to \"$newname\"");
                                if($oldname != $newname) {
                                        $renewname = " rename $newname";
                                }
                                
-                               $oldconf = $comms->getConfig(0);
+                               $oldconf = getWebUserConfig();
                                $olddesc = $oldconf["zone"][$oldname]["description"];
+                               error_log("Comparing \"$olddesc\" and \"$desc\"");
                                if($desc != $olddesc) {
                                        $newdesc = " # $desc";
                                } else $newdesc = null;
@@ -31,6 +33,7 @@ function CBFWZonesPage($urls)
                                
                                if($renewname == null && $newdesc == null) {
                                        header("Location: $BASE_URL/zones");
+                                       error_log("no changes?");
                                        return;
                                }
                                
@@ -104,12 +107,7 @@ function CBFWZonesEditPage($urls)
        
        $zone = $urls[2];
        
-       $comms = new Comms();
-       $myconf = new Config();
-       
-       $config = $comms->getConfig();
-       $conf2 = $comms->getConfig(3);
-       $config = $myconf->mergeConfig($config, $conf2);
+       $config = getWebUserConfig();
        
        
        echo "<h2>Edit Zone $zone</h2>";
@@ -124,16 +122,38 @@ function CBFWZonesEditPage($urls)
        echo "</form>";
 }
 
-function CBFWZonesPageDisplay()
+function getWebUserConfig()
 {
-       global $BASE_URL, $MENU_ITEMS;
-       
        $comms = new Comms();
        $myconf = new Config();
        
-       $config = $comms->getConfig();
+       
+       // check to see if pre-cache config matches change level of config change buffer
+       $config = $comms->getConfig(5);
        $conf2 = $comms->getConfig(3);
-       $config = $myconf->mergeConfig($config, $conf2);
+       if(isset($config["status"])) {
+               if($config["status"] == $conf2["status"]) {
+                       // it did, return the pre-cache
+                       error_log("got pre-cache config");
+                       return $config;
+               }
+       }
+       
+       // it did not, do a new merge and cache
+       $config = $myconf->mergeConfig($comms->getConfig(), $conf2);
+       $reconfig = $config;
+       $reconfig["status"] = $conf2["status"];
+       error_log("put pre-cache config");
+       $comms->putConfig($reconfig, 5);        
+       
+       return $config;
+}
+
+function CBFWZonesPageDisplay()
+{
+       global $BASE_URL, $MENU_ITEMS;
+       
+       $config = getWebUserConfig();
 
        echo "<h2>Zones</h2>";
        echo "<table border=\"1\"><tr><th>Zone</th><th>Interfaces</th><th>Description</th><th>Edit</th></tr>";
@@ -314,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()
@@ -328,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;