moved interfaces ui into a seperate php file.
[CBFWR.git] / libcbfwr / fwui.php
1 <?php
2
3 function CBFWZonesPage($urls)
4 {
5         global $BASE_URL, $MENU_ITEMS;
6         $comms = new Comms();
7         
8         if(isset($urls[1])) {
9                 switch($urls[1]) {
10                         case "modify":
11                                 
12                                 if($_REQUEST["description"] != "") $desc = $_REQUEST["description"];
13                                 else $desc = null;
14                                 
15                                 $oldname = $_REQUEST["oldname"];
16                                 $newname = $_REQUEST["zonename"];
17                                 
18                                 $renewname = null;
19                                 error_log("comparing \"$oldname\" to \"$newname\"");
20                                 if($oldname != $newname) {
21                                         $renewname = " rename $newname";
22                                 }
23                                 
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;
30                                 
31                                 //echo "confs: \"$olddesc\", \"$newdesc\", $oldname, $newname<br>";
32                                 //exit(0);
33                                 
34                                 if($renewname == null && $newdesc == null) {
35                                         header("Location: $BASE_URL/zones");
36                                         error_log("no changes?");
37                                         return;
38                                 }
39                                 
40                                 
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"];
46                                 
47                                 $conf[$cnum]["modify"] = "zone $oldname$renewname$newdesc";
48                                 $comms->putConfig($conf, 3);
49                                 header("Location: $BASE_URL/zones");
50                                 
51                                 break;
52                                 
53                                 
54                         case "edit":
55                                 CBFWpageBuilder(null, "CBFWZonesEditPage", null, null, $urls);
56                                 break;
57                                 
58                                 
59                         case "delete":
60                                 $zonetodelete = $urls[2];
61
62                                 addWebUserChange("delete zone name $zonetodelete");
63                                 header("Location: $BASE_URL/zones");
64                                 break;
65                                 
66                                 
67                         case "add":
68                                 
69                                 // UGLY
70                                 $nametoadd = $_REQUEST["toadd"];
71                                 $desc = $_REQUEST["desc"];
72                                 
73                                 $descbit = "";
74                                 if($desc != "") $descbit = " # $desc";
75                                 if($nametoadd == "" || $nametoadd == null) {
76                                         return;
77                                 }
78                                 
79                                 addWebUserChange("zone name $nametoadd $descbit");
80                                 header("Location: $BASE_URL/zones");
81                                 break;
82                                 
83                                 
84                         default:
85                                 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
86                 }
87         } else {
88                 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
89         }
90 }
91
92 function CBFWZonesEditPage($urls)
93 {
94         global $BASE_URL, $MENU_ITEMS;
95         
96         $zone = $urls[2];
97         
98         $config = getWebUserConfig();
99         
100         
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>";
105         
106         if(isset($config["zone"][$zone]["description"])) $desc = $config["zone"][$zone]["description"];
107         
108         echo "Description: <input type=\"text\" name=\"description\" value=\"$desc\"><br>";
109         echo "<input type=\"submit\" name=\"Go\" value=\"Go\">";
110         echo "</form>";
111 }
112
113 function addWebUserChange($change)
114 {
115         $comms = new Comms();
116         $myconf = new Config();
117         
118         $conf = $comms->getConfig(3);
119         
120         if(!isset($conf["status"])) {
121                 $conf["status"] = "nochange";
122         }
123         
124         $changes = $conf["status"];
125         if($changes == "nochange") $conf["status"] = 1;
126         else $conf["status"] = $changes + 1;
127         $cnum = $conf["status"];
128         
129         $conf["changes"][$cnum] = "$change";
130         $comms->putConfig($conf, 3);
131         
132 }
133
134 // TODO: we need to really sit and think about this one
135 function getWebUserConfig()
136 {
137         $comms = new Comms();
138         $myconf = new Config();
139         
140         
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");
148                         return $config;
149                 }
150         }
151         
152         // it did not, do a new merge and cache
153         // TODO: need to do this part
154         $config = $comms->getConfig();
155         $reconfig = $config;
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);
160         }
161         $reconfig = $myconf->getConfig();
162         $reconfig["status"] = $conf2["status"];
163         error_log("put pre-cache config");
164         $comms->putConfig($reconfig, 5);        
165         
166         return $reconfig;
167 }
168
169 function CBFWZonesPageDisplay()
170 {
171         global $BASE_URL, $MENU_ITEMS;
172         
173         $config = getWebUserConfig();
174
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) {
178                 $name = $key;
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>";
183         }
184                 
185         echo "</table><br>";
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\">";
191         echo "</form>";
192         
193 }
194
195 function CBFWRoutingPage($urls)
196 {
197         if(isset($urls[1])) {
198                 switch($urls[1]) {
199                         case "edit":
200                                 CBFWpageBuilder(null, "CBFWRoutingPageEdit", null, null, $urls[2]);
201                                 break;
202                         case "change":
203                                 CBFWRoutingChange();
204                                 break;
205                         default:
206                                 CBFWpageBuilder(null, "CBFWRoutingPageDisplay");
207                 }
208         } else {
209                 error_log("main interface page");
210                 CBFWpageBuilder(null, "CBFWRoutingPageDisplay");
211         }
212         
213 }
214
215 function CBFWRoutingPageDisplay()
216 {
217         echo "<h2>Routing</h2>";
218 }
219
220 function CBFWObjectsPage($urls)
221 {
222         $comms = new Comms();
223         
224         $config = $comms->getConfig();
225         
226         CBFWpageBuilder(null, "CBFWObjectsDisplay");
227 }
228
229 function CBFWObjectsDisplay()
230 {
231         global $BASE_URL, $MENU_ITEMS;
232         $config = getWebUserConfig();
233         
234         echo "<h2>Objects</h2>";
235         
236         if(isset($config["objects"])) {
237                 echo "<table>";
238                 echo "<tr><th>Networks</th><th>Hosts</th><th>Services</th><th>Network Groups</th><th>Host Groups</th><th>Service Groups</th></tr>";
239                 echo "</table>";
240                 foreach($config["objects"] as $key => $var) {
241                 }
242         } else {
243                 echo "No objects set\n";
244         }
245         
246         echo "<hr>";
247         echo "<table cellpadding=\"20\"><tr valign=\"top\">";
248         echo "<td>";
249         echo "<h3>Create Network</h3><br>";
250         echo "<form method=\"post\" action=\"$BASE_URL/objects/network/create\">";
251         echo "Name <input type=\"text\" name=\"objname\"><br>";
252         echo "IPv4 <input type=\"text\" name=\"addr4\">/<input type=\"text\" name=\"mask4\" maxlength=\"3\" size=\"3\"><br>";
253         echo "IPv6 <input type=\"text\" name=\"addr6\">/<input type=\"text\" name=\"mask6\" maxlength=\"3\" size=\"3\"><br>";
254         echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
255         echo "</form>";
256         echo "</td>";
257         echo "<td>";
258         echo "<h3>Create Host</h3><br>";
259         echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
260         echo "Name <input type=\"text\" name=\"objname\"><br>";
261         echo "IPv4 <input type=\"text\" name=\"addr4\"><br>";
262         echo "IPv6 <input type=\"text\" name=\"addr6\"><br>";
263         echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
264         echo "</form>";
265         echo "</td>";
266         echo "<td>";
267         echo "<h3>Service</h3><br>";
268         echo "<form method=\"post\" action=\"$BASE_URL/objects/host/create\">";
269         echo "Name <input type=\"text\" name=\"objname\"><br>";
270         echo "Port <input type=\"text\" name=\"port\">";
271         echo "<select name=\"proto\"><option value=\"tcp\">TCP</option><option value=\"udp\">UDP</option></select><br>";
272         echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
273         echo "</form>";
274         echo "</td>";
275         echo "</tr><tr>";
276         echo "<td>";
277         echo "<h3>Network Group</h3>";
278         echo "<form method=\"post\" action=\"$BASE_URL/objects/networkgroup/create\">";
279         echo "Name <input type=\"text\" name=\"objname\"><br>";
280         echo "</form>";
281         echo "</td>";
282         echo "<td>";
283         echo "<h3>Host Group</h3>";
284         echo "<form method=\"post\" action=\"$BASE_URL/objects/hostgroup/create\">";
285         echo "Name <input type=\"text\" name=\"objname\"><br>";
286         echo "</form>";
287         echo "</td>";
288         echo "<td>";
289         echo "<h3>Service Group</h3>";
290         echo "<form method=\"post\" action=\"$BASE_URL/objects/servicegroup/create\">";
291         echo "Name <input type=\"text\" name=\"objname\"><br>";
292         echo "</form>";
293         echo "</td>";
294         
295         
296         echo "</tr></table>";
297         
298 }
299
300 function CBFWChangesPage($urls)
301 {
302         global $BASE_URL, $MENU_ITEMS;
303         
304         if(isset($urls[1])) {
305                 switch($urls[1]) {
306                         case "show":
307                                 CBFWpageBuilder(null, "CBFWChangesDisplay");
308                                 break;
309                         case "delete":
310                                 $delete = $urls[2];
311                                 error_log("would delete change $delete");
312                                 header("Location: $BASE_URL/changes/show");
313                                 break;
314                 }
315         }
316 }
317
318 function CBFWChangesDisplay()
319 {
320         global $BASE_URL, $MENU_ITEMS;
321         $comms = new Comms();
322         
323         $config = $comms->getConfig(3);
324         
325         echo "<h2>Changes</h2>";
326         echo "This page shows the changes on the web from the currently running configuration<br>";
327         if($config["status"] == "nochange") {
328                 echo "There are currently no changes from the running configuraiton.";
329         } else {
330                 echo "<table border=\"1\">";
331                 echo "<tr><th>Change No</th><th>Change</th><th>Control</th></tr>";
332                 foreach($config["changes"] as $key => $var) {
333                         echo "<tr><td>$key</td><td>$var</td><td><a href=\"$BASE_URL/changes/delete/$key\">Delete</a></td></tr>";
334                 }
335                 echo "</table>";
336         }
337 }
338
339 function CBFWRulesPage()
340 {
341         $comms = new Comms();
342         
343         $config = $comms->getConfig();
344 }
345
346 function CBFWAdminPage($urls)
347 {
348         $comms = new Comms();
349         
350         $config = $comms->getConfig();
351         
352         CBFWpageBuilder(null, "CBFWAdminDisplay");
353 }
354
355 function CBFWAdminDisplay()
356 {
357 ?>
358 <h2>Administration</h2>
359 <table cellpadding=10>
360 <tr valign="top">
361 <td>
362 <h3>Users</h3>
363 <table>
364 <tr><th>Username</th><th>Description</th><th>Enabled?</th></tr>
365 <tr><td>Admin</td><td>Twattle</td><td>Yes</td></tr>
366 </table>
367 <hr>
368 <h3>Add User</h3>
369 <form method="post" action="asdf">
370 Username <input type="text" name="username"><br>
371 Password <input type="password" name="pass"><br>
372 Description <input type="text" name="desc"><br>
373 <input type="submit" name="add" value="Add"><br>
374 </form>
375 </td>
376 <td>
377 <h3>Network Access</h3>
378 <table>
379 <tr><th>From</th><th>Interface</th><th>Type</th></tr>
380 <tr><td>Any</td><td>twaddle</td><td>http,https,ssh</td></tr>
381 </table>
382 <hr>
383 <h3>Add Access</h3>
384 <form method="post" action="asdf">
385 From <select name="from"><option value="something">Any</option><option name="some">Intranet</option><option name="som">SomeHost</option></select><br>
386 Interface <select name="interface"><option value="something">twad</option><option name="some">craw</option></select>
387 Protocols <input type="checkbox" name="http">HTTP <input type="checkbox" name="http">HTTPS <input type="checkbox" name="http">SSH<br> 
388 <input type="submit" name="add" value="Add"><br>
389 </form>
390 </td>
391 </tr>
392 </table>
393 <?php 
394 }
395
396
397
398 function findUrl($url_s)
399 {
400         global $URL_HANDLERS;
401         
402         foreach($URL_HANDLERS as $key => $val) {
403                 
404         }
405 }
406 ?>