stuff
authorpaulr <me@pjr.cc>
Fri, 23 Sep 2011 05:00:12 +0000 (15:00 +1000)
committerpaulr <me@pjr.cc>
Fri, 23 Sep 2011 05:00:12 +0000 (15:00 +1000)
libcbfwr/comms.php
libcbfwr/fwui.php

index 7f89650..8e7ed32 100644 (file)
@@ -49,6 +49,9 @@ class Comms {
        // type = 1 for the boot hardware config
        // type = 2 for running config
        // type = 3 for web config
+       
+       // type = 4 for merged running config cache
+       // type = 5 for merged web config cache
        function putConfig($config, $type=0)
        {
                global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY, $CONF_STORE_SIZE;
index fb9ef70..4bcfed5 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>";