From: paulr Date: Thu, 22 Sep 2011 16:41:01 +0000 (+1000) Subject: config modifications and such X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=60673f4f00bab805471fcbb85c8816aebb3a9582;p=CBFWR.git config modifications and such --- diff --git a/bin/cbfwrd.php b/bin/cbfwrd.php index 4abcbbd..4a9f5a5 100644 --- a/bin/cbfwrd.php +++ b/bin/cbfwrd.php @@ -1,9 +1,9 @@ ][name]=1 +[interface][][desciption] = desc + [name] = name + [address4] = address + [address6] = address + [zone] = zone + [mtu] = mtu + [speed] = speed + [duplex] = duplex + +[lag][][] = interface + [description] = desc + +[bridge][][] = interface + [description] + +[route4][default|][address] = gateway + [device] = device + [description] +[route6][default|][address] = gateway + [device] = device + [description] + +[dns][server][][address] = address + +[ntp][server][][address] = adddress + +[hardware][netdev][][name] = realname + [driver] = driver + [mtu] = mtu + [hwaddress] = mac address \ No newline at end of file diff --git a/libcbfwr/config.php b/libcbfwr/config.php index 3720d6a..372bd04 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -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; $igetConfig(0); + $olddesc = $oldconf["zone"][$oldname]["description"]; + if($desc != $olddesc) { + $newdesc = " # $desc"; + } else $newdesc = null; + + //echo "confs: \"$olddesc\", \"$newdesc\", $oldname, $newname
"; + //exit(0); + + if($renewname == null && $newdesc == null) { + header("Location: $BASE_URL/zones"); + return; + } + + + $conf = $comms->getConfig(3); + $changes = $conf["status"]; + if($changes == "nochange") $conf["status"] = 1; + else $conf["status"] = $changes + 1; + $cnum = $conf["status"]; + + $conf[$cnum]["modify"] = "zone $oldname$renewname$newdesc"; + $comms->putConfig($conf, 3); + header("Location: $BASE_URL/zones"); + + break; + + case "edit": + CBFWpageBuilder(null, "CBFWZonesEditPage", null, null, $urls); break; - case "change": + + + case "delete": + $zonetodelete = $urls[2]; + + $conf = $comms->getConfig(3); + $changes = $conf["status"]; + if($changes == "nochange") $conf["status"] = 1; + else $conf["status"] = $changes + 1; + $cnum = $conf["status"]; + + $conf[$cnum]["delete"] = "zone $zonetodelete"; + $comms->putConfig($conf, 3); + header("Location: $BASE_URL/zones"); break; + + case "add": + + // UGLY + $cnum = 0; $nametoadd = $_REQUEST["toadd"]; - $comms->sendMessage("zone add $nametoadd"); - //if($_REQUEST["desc"] != "") $comms->sendMessage("zone ") + $desc = $_REQUEST["desc"]; + $descbit = ""; + if($desc != "") $descbit = " # $desc"; + if($nametoadd == "" || $nametoadd == null) { + return; + } + $conf = $comms->getConfig(3); + $changes = $conf["status"]; + if($changes == "nochange") $conf["status"] = 1; + else $conf["status"] = $changes + 1; + $cnum = $conf["status"]; + $conf[$cnum]["add"] = "zone $nametoadd$descbit"; + $comms->putConfig($conf, 3); header("Location: $BASE_URL/zones"); break; + + default: CBFWpageBuilder(null, "CBFWZonesPageDisplay"); } @@ -25,20 +98,51 @@ function CBFWZonesPage($urls) } } +function CBFWZonesEditPage($urls) +{ + global $BASE_URL, $MENU_ITEMS; + + $zone = $urls[2]; + + $comms = new Comms(); + $myconf = new Config(); + + $config = $comms->getConfig(); + $conf2 = $comms->getConfig(3); + $config = $myconf->mergeConfig($config, $conf2); + + + echo "

Edit Zone $zone

"; + echo "
"; + echo ""; + echo "Name:
"; + + if(isset($config["zone"][$zone]["description"])) $desc = $config["zone"][$zone]["description"]; + + echo "Description:
"; + echo ""; + echo "
"; +} + function CBFWZonesPageDisplay() { global $BASE_URL, $MENU_ITEMS; $comms = new Comms(); + $myconf = new Config(); $config = $comms->getConfig(); + $conf2 = $comms->getConfig(3); + $config = $myconf->mergeConfig($config, $conf2); echo "

Zones

"; - echo ""; + echo "
ZoneInterfacesEdit
"; foreach($config["zone"] as $key => $var) { $name = $key; $url = "Edit"; - echo ""; + $url2 = "Delete"; + $desc = $var["description"]; + echo ""; } echo "
ZoneInterfacesDescriptionEdit
$name...$url
$name...$desc$url $url2

"; diff --git a/libcbfwr/web.php b/libcbfwr/web.php index 562d1db..6baae23 100644 --- a/libcbfwr/web.php +++ b/libcbfwr/web.php @@ -130,7 +130,7 @@ function CBFWAddMessage($messagelev, $message) function CBFWMessageBuilder() { - + echo "message"; } function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null) @@ -177,9 +177,11 @@ function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="C // page top echo "

CBFW


"; - echo "
"; + echo "
"; CBFWMessageBuilder(); - echo "
"; + echo ""; + CBFWConfigStatus(); + echo "
"; // menu, then body echo "
"; @@ -230,6 +232,34 @@ function cbfw_getLastSeen($ip, $data) } +function CBFWConfigStatus() +{ + $comms = new Comms(); + + $conf0 = $comms->getConfig(0); + $conf1 = $comms->getConfig(2); + $conf2 = $comms->getConfig(3); + + if($conf1["status"] == "nochange") { + $saved = "Current"; + $running = "Current"; + } else { + $saved = "Old"; + $running = "Current"; + } + if($conf2["status"] == "nochange") { + $client = "Current"; + } else { + $ch = $conf2["status"]; + $client = "$ch Changes"; + } + + + echo "Saved Config: $saved
"; + echo "Running Config: $running
"; + echo "Client Config: $client
"; +} + function cbfw_tdiffToAgo($time_in_sec) { $tdiff = $time_in_sec; diff --git a/var/fw.conf b/var/fw.conf index 732c25a..0cc139a 100644 --- a/var/fw.conf +++ b/var/fw.conf @@ -2,13 +2,13 @@ hostname hostname domainname domain.name -zone name internet +login admin auth $4$QqcI5xWa$Ty8Vs3aAVBwPF0IpKO5hvgUi4wA$ + + +zone name internet # this is a description interface dev eth0 name twatter # twatter is our outbound interface + interface dev twatter address4 10.172.192.10/24 -interface dev twatter address6 2003:12:12:12::1/64 -interface dev twatter speed 1000 -interface dev twatter duplex full interface dev twatter zone internet -interface dev twatter mtu 1400 \ No newline at end of file