3 function CBFWZonesPage($urls)
5 global $BASE_URL, $MENU_ITEMS;
12 if($_REQUEST["description"] != "") $desc = $_REQUEST["description"];
15 $oldname = $_REQUEST["oldname"];
16 $newname = $_REQUEST["zonename"];
19 error_log("comparing \"$oldname\" to \"$newname\"");
20 if($oldname != $newname) {
21 $renewname = " rename $newname";
24 $oldconf = getWebUserConfig();
25 $olddesc = $oldconf["zone"][$oldname]["description"];
26 error_log("Comparing \"$olddesc\" and \"$desc\"");
27 if($desc != $olddesc) {
28 $newdesc = " # $desc";
29 } else $newdesc = null;
31 //echo "confs: \"$olddesc\", \"$newdesc\", $oldname, $newname<br>";
34 if($renewname == null && $newdesc == null) {
35 header("Location: $BASE_URL/zones");
36 error_log("no changes?");
41 $conf = $comms->getConfig(3);
42 $changes = $conf["status"];
43 if($changes == "nochange") $conf["status"] = 1;
44 else $conf["status"] = $changes + 1;
45 $cnum = $conf["status"];
47 $conf[$cnum]["modify"] = "zone $oldname$renewname$newdesc";
48 $comms->putConfig($conf, 3);
49 header("Location: $BASE_URL/zones");
55 CBFWpageBuilder(null, "CBFWZonesEditPage", null, null, $urls);
60 $zonetodelete = $urls[2];
62 addWebUserChange("delete zone name $zonetodelete");
63 header("Location: $BASE_URL/zones");
70 $nametoadd = $_REQUEST["toadd"];
71 $desc = $_REQUEST["desc"];
74 if($desc != "") $descbit = " # $desc";
75 if($nametoadd == "" || $nametoadd == null) {
79 addWebUserChange("zone name $nametoadd $descbit");
80 header("Location: $BASE_URL/zones");
85 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
88 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
92 function CBFWZonesEditPage($urls)
94 global $BASE_URL, $MENU_ITEMS;
98 $config = getWebUserConfig();
101 echo "<h2>Edit Zone $zone</h2>";
102 echo "<form method=\"post\" action=\"$BASE_URL/zones/modify/$zone\">";
103 echo "<input type=\"hidden\" name=\"oldname\" value=\"$zone\">";
104 echo "Name: <input type=\"text\" name=\"zonename\" value=\"$zone\"><br>";
106 if(isset($config["zone"][$zone]["description"])) $desc = $config["zone"][$zone]["description"];
108 echo "Description: <input type=\"text\" name=\"description\" value=\"$desc\"><br>";
109 echo "<input type=\"submit\" name=\"Go\" value=\"Go\">";
113 function addWebUserChange($change)
115 $comms = new Comms();
116 $myconf = new Config();
118 $conf = $comms->getConfig(3);
120 if(!isset($conf["status"])) {
121 $conf["status"] = "nochange";
124 $changes = $conf["status"];
125 if($changes == "nochange") $conf["status"] = 1;
126 else $conf["status"] = $changes + 1;
127 $cnum = $conf["status"];
129 $conf["changes"][$cnum] = "$change";
130 $comms->putConfig($conf, 3);
134 // TODO: we need to really sit and think about this one
135 function getWebUserConfig()
137 $comms = new Comms();
138 $myconf = new Config();
141 // check to see if pre-cache config matches change level of config change buffer
142 $config = $comms->getConfig(5);
143 $conf2 = $comms->getConfig(3);
144 if(isset($config["status"])) {
145 if($config["status"] == $conf2["status"]) {
146 // it did, return the pre-cache
147 error_log("got pre-cache config");
152 // it did not, do a new merge and cache
153 // TODO: need to do this part
154 $config = $comms->getConfig();
156 $myconf->setConfig($config);
157 if(isset($conf2["changes"])) foreach($conf2["changes"] as $key => $var) {
158 error_log("Adding config line $key, $var");
159 $myconf->addConfigLine($var);
161 $reconfig = $myconf->getConfig();
162 $reconfig["status"] = $conf2["status"];
163 error_log("put pre-cache config");
164 $comms->putConfig($reconfig, 5);
169 function CBFWZonesPageDisplay()
171 global $BASE_URL, $MENU_ITEMS;
173 $config = getWebUserConfig();
175 echo "<h2>Zones</h2>";
176 echo "<table border=\"1\"><tr><th>Zone</th><th>Interfaces</th><th>Description</th><th>Edit</th></tr>";
177 foreach($config["zone"] as $key => $var) {
179 $url = "<a href=\"$BASE_URL/zones/edit/$name\">Edit</a>";
180 $url2 = "<a href=\"$BASE_URL/zones/delete/$name\">Delete</a>";
181 $desc = $var["description"];
182 echo "<tr><td>$name</td><td>...</td><td>$desc</td><td>$url $url2</td></tr>";
186 echo "<form method=\"post\" action=\"$BASE_URL/zones/add\">";
187 echo "<hr><h3>Add Zone</h3><br>";
188 echo "Name: <input type=\"text\" name=\"toadd\"><br>";
189 echo "Description: <input type=\"text\" name=\"desc\"><br>";
190 echo "<input type=\"submit\" name=\"Add\" value=\"Add\">";
195 function CBFWInterfacesPage($urls)
197 if(isset($urls[1])) {
200 CBFWpageBuilder(null, "CBFWInterfacesPageEdit", null, null, $urls[2]);
203 CBFWInterfacesChange();
206 CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
209 error_log("main interface page");
210 CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
214 function CBFWInterfacesChange()
216 global $BASE_URL, $MENU_ITEMS;
217 $comms = new Comms();
219 $comms->sendMessage("interface eth0 changename poof");
220 header("Location: $BASE_URL/interfaces");
223 function CBFWInterfacesPageEdit($urls)
225 global $BASE_URL, $MENU_ITEMS;
228 echo "<h3>Edit Interface $interface</h3><br>";
229 echo "<form method=\"post\" action=\"$BASE_URL/interfaces/change/$interface\">";
231 echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"></td></tr>";
232 echo "<tr><td>HW Address</td><td><input type=\"text\" name=\"hwaddr\"></td></tr>";
233 echo "<tr><td>Zone</td><td><input type=\"text\" name=\"zone\"></td></tr>";
234 echo "<tr><td>IPv4 Address</td><td><input type=\"text\" name=\"ipv4addr\"></td></tr>";
235 echo "<tr><td>IPv6 Address</td><td><input type=\"text\" name=\"ipv6addr\"></td></tr>";
236 echo "<tr><td>Speed</td><td><input type=\"text\" name=\"speed\"></td></tr>";
237 echo "<tr><td>Duplex</td><td><input type=\"text\" name=\"duplex\"></td></tr>";
239 echo "<input type=\"submit\" name=\"Change\" value=\"Change\"><br>";
240 //echo "<a href=\"$BASE_URL/interfaces/\">Back</a>";
244 function CBFWInterfacesPageDisplay()
246 global $BASE_URL, $MENU_ITEMS;
247 $comms = new Comms();
249 $config = $comms->getConfig(0);
250 $boot_config = $comms->getConfig(1);
252 // now build an interface table
254 foreach($boot_config["hardware"]["netdev"] as $key=>$val) {
256 $table[$key]["realname"] = $val["name"];
257 $table[$key]["name"] = $val["name"];
261 if(isset($val["driver"])) $table[$key]["type"] = $val["driver"];
262 else $table[$key]["type"] = "Unknown";
265 if(isset($val["hwaddress"])) $table[$key]["hwaddress"] = $val["hwaddress"];
268 if(isset($val["mtu"])) $table[$key]["mtu"] = $val["mtu"];
271 foreach($config["hardware"]["netdev"] as $key=>$val) {
273 if(isset($config["interface"]["$key"]["name"])) $table[$key]["name"] = $config["interface"]["$key"]["name"];
274 $table[$key]["address4"] = null;
275 $table[$key]["address6"] = null;
277 if(isset($config["interface"][$table[$key]["name"]]["address4"])) {
278 $table[$key]["address4"] = $config["interface"][$table[$key]["name"]]["address4"];
281 if(isset($config["interface"][$table[$key]["name"]]["address6"])) {
282 $table[$key]["address6"] = $config["interface"][$table[$key]["name"]]["address6"];
285 if(isset($config["interface"][$table[$key]["name"]]["mtu"])) {
286 $table[$key]["mtu"] = $config["interface"][$table[$key]["name"]]["mtu"];
288 $table[$key]["mtu"] = "1500"; // TODO: this needs to actually come from somewhere
291 if(isset($config["interface"][$table[$key]["name"]]["speed"])) {
292 $table[$key]["speed"] = $config["interface"][$table[$key]["name"]]["speed"];
294 $table[$key]["speed"] = null;
297 if(isset($config["interface"][$table[$key]["name"]]["duplex"])) {
298 $table[$key]["duplex"] = $config["interface"][$table[$key]["name"]]["duplex"];
300 $table[$key]["duplex"] = null;
303 if(isset($config["interface"][$table[$key]["name"]]["zone"])) {
304 $table[$key]["zone"] = $config["interface"][$table[$key]["name"]]["zone"];
306 $table[$key]["zone"] = null;
311 echo "<table border=\"1\"><th>Device</th><th>Zone</th><th>Type</th><th>MAC Address</th><th>Address</th><th>MTU</th><th>Speed/Duplex</th><th>Control</th></tr>";
312 foreach($table as $key =>$val) {
313 if($val["realname"] == $val["name"]) $name = $val["name"];
314 else $name = $val["name"]." (".$val["realname"].")";
317 if($val["zone"] == null) $zone = "-";
318 else $zone = $val["zone"];
324 $type = $val["type"];
327 $mac = $val["hwaddress"];
330 if($val["duplex"] == null) $dup = "default";
331 else $dup = $val["duplex"];
333 if($val["speed"] == null) $spd = "default";
334 else $spd = $val["speed"];
336 $spanddu = "$spd/$dup";
339 if($val["address4"]!=null && $val["address6"]!=null) {
340 $address = $val["address4"]."<br>".$val["address6"];
341 } else if($val["address4"] != null) {
342 $address = $val["address4"];
343 } else if($val["address6"] != null) {
344 $address = $val["address6"];
349 echo "<tr><th>$name</th><td>$zone</td><td>$type</td><td>$mac</td><td>$address</td><td>$mtu</td><td>$spanddu</td><td><a href=\"$BASE_URL/interfaces/edit/".$val["realname"]."\">Edit</a></td></tr>";
354 function CBFWObjectsPage($urls)
356 $comms = new Comms();
358 $config = $comms->getConfig();
360 CBFWpageBuilder(null, "CBFWObjectsDisplay");
363 function CBFWObjectsDisplay()
365 global $BASE_URL, $MENU_ITEMS;
366 $config = getWebUserConfig();
368 echo "<h2>Objects</h2>";
370 if(isset($config["objects"])) {
372 echo "<tr><th>Networks</th><th>Hosts</th><th>Services</th><th>Network Groups</th><th>Host Groups</th><th>Service Groups</th></tr>";
374 foreach($config["objects"] as $key => $var) {
377 echo "No objects set\n";
381 echo "<table cellpadding=\"20\"><tr valign=\"top\">";
383 echo "<h3>Create Network</h3><br>";
384 echo "<form method=\"post\" action=\"$BASE_URL/objects/network/create\">";
385 echo "Name <input type=\"text\" name=\"objname\"><br>";
386 echo "IPv4 <input type=\"text\" name=\"addr4\">/<input type=\"text\" name=\"mask4\" maxlength=\"3\" size=\"3\"><br>";
387 echo "IPv6 <input type=\"text\" name=\"addr6\">/<input type=\"text\" name=\"mask6\" maxlength=\"3\" size=\"3\"><br>";
388 echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
392 echo "<h3>Create Host</h3><br>";
393 echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
394 echo "Name <input type=\"text\" name=\"objname\"><br>";
395 echo "IPv4 <input type=\"text\" name=\"addr4\"><br>";
396 echo "IPv6 <input type=\"text\" name=\"addr6\"><br>";
397 echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
401 echo "<h3>Service</h3><br>";
402 echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
403 echo "Name <input type=\"text\" name=\"objname\"><br>";
404 echo "Port <input type=\"text\" name=\"port\">";
405 echo "<select name=\"proto\"><option value=\"tcp\">TCP</option><option value=\"udp\">UDP</option></select><br>";
406 echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
411 echo "<h3>Network Group</h3>";
412 echo "<form method=\"post\" action=\"$BASE_URL/objects/networkgroup/create\">";
413 echo "Name <input type=\"text\" name=\"objname\"><br>";
417 echo "<h3>Host Group</h3>";
418 echo "<form method=\"post\" action=\"$BASE_URL/objects/hostgroup/create\">";
419 echo "Name <input type=\"text\" name=\"objname\"><br>";
423 echo "<h3>Service Group</h3>";
424 echo "<form method=\"post\" action=\"$BASE_URL/objects/servicegroup/create\">";
425 echo "Name <input type=\"text\" name=\"objname\"><br>";
430 echo "</tr></table>";
434 function CBFWChangesPage($urls)
436 global $BASE_URL, $MENU_ITEMS;
438 if(isset($urls[1])) {
441 CBFWpageBuilder(null, "CBFWChangesDisplay");
445 error_log("would delete change $delete");
446 header("Location: $BASE_URL/changes/show");
452 function CBFWChangesDisplay()
454 global $BASE_URL, $MENU_ITEMS;
455 $comms = new Comms();
457 $config = $comms->getConfig(3);
459 echo "<h2>Changes</h2>";
460 echo "This page shows the changes on the web from the currently running configuration<br>";
461 if($config["status"] == "nochange") {
462 echo "There are currently no changes from the running configuraiton.";
464 echo "<table border=\"1\">";
465 echo "<tr><th>Change No</th><th>Change</th><th>Control</th></tr>";
466 foreach($config["changes"] as $key => $var) {
467 echo "<tr><td>$key</td><td>$var</td><td><a href=\"$BASE_URL/changes/delete/$key\">Delete</a></td></tr>";
473 function CBFWRulesPage()
475 $comms = new Comms();
477 $config = $comms->getConfig();
480 function CBFWAdminPage($urls)
482 $comms = new Comms();
484 $config = $comms->getConfig();
486 CBFWpageBuilder(null, "CBFWAdminDisplay");
489 function CBFWAdminDisplay()
492 <h2>Administration</h2>
493 <table cellpadding=10>
498 <tr><th>Username</th><th>Description</th><th>Enabled?</th></tr>
499 <tr><td>Admin</td><td>Twattle</td><td>Yes</td></tr>
503 <form method="post" action="asdf">
504 Username <input type="text" name="username"><br>
505 Password <input type="password" name="pass"><br>
506 Description <input type="text" name="desc"><br>
507 <input type="submit" name="add" value="Add"><br>
511 <h3>Network Access</h3>
513 <tr><th>From</th><th>Interface</th><th>Type</th></tr>
514 <tr><td>Any</td><td>twaddle</td><td>http,https,ssh</td></tr>
518 <form method="post" action="asdf">
519 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>
520 Interface <select><option value="something">twad</option><option name="some">craw</option></select>
521 Protocols <input type="checkbox" name="http">HTTP <input type="checkbox" name="http">HTTPS <input type="checkbox" name="http">SSH<br>
522 <input type="submit" name="add" value="Add"><br>
532 function findUrl($url_s)
534 global $URL_HANDLERS;
536 foreach($URL_HANDLERS as $key => $val) {