config modifications and such
[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                                 if($oldname != $newname) {
20                                         $renewname = " rename $newname";
21                                 }
22                                 
23                                 $oldconf = $comms->getConfig(0);
24                                 $olddesc = $oldconf["zone"][$oldname]["description"];
25                                 if($desc != $olddesc) {
26                                         $newdesc = " # $desc";
27                                 } else $newdesc = null;
28                                 
29                                 //echo "confs: \"$olddesc\", \"$newdesc\", $oldname, $newname<br>";
30                                 //exit(0);
31                                 
32                                 if($renewname == null && $newdesc == null) {
33                                         header("Location: $BASE_URL/zones");
34                                         return;
35                                 }
36                                 
37                                 
38                                 $conf = $comms->getConfig(3);
39                                 $changes = $conf["status"];
40                                 if($changes == "nochange") $conf["status"] = 1;
41                                 else $conf["status"] = $changes + 1;
42                                 $cnum = $conf["status"];
43                                 
44                                 $conf[$cnum]["modify"] = "zone $oldname$renewname$newdesc";
45                                 $comms->putConfig($conf, 3);
46                                 header("Location: $BASE_URL/zones");
47                                 
48                                 break;
49                                 
50                                 
51                         case "edit":
52                                 CBFWpageBuilder(null, "CBFWZonesEditPage", null, null, $urls);
53                                 break;
54                                 
55                                 
56                         case "delete":
57                                 $zonetodelete = $urls[2];
58                                 
59                                 $conf = $comms->getConfig(3);
60                                 $changes = $conf["status"];
61                                 if($changes == "nochange") $conf["status"] = 1;
62                                 else $conf["status"] = $changes + 1;
63                                 $cnum = $conf["status"];
64                                 
65                                 $conf[$cnum]["delete"] = "zone $zonetodelete";
66                                 $comms->putConfig($conf, 3);
67                                 header("Location: $BASE_URL/zones");
68                                 break;
69                                 
70                                 
71                         case "add":
72                                 
73                                 // UGLY
74                                 $cnum = 0;
75                                 $nametoadd = $_REQUEST["toadd"];
76                                 $desc = $_REQUEST["desc"];
77                                 $descbit = "";
78                                 if($desc != "") $descbit = " # $desc";
79                                 if($nametoadd == "" || $nametoadd == null) {
80                                         return;
81                                 }
82                                 $conf = $comms->getConfig(3);
83                                 $changes = $conf["status"];
84                                 if($changes == "nochange") $conf["status"] = 1;
85                                 else $conf["status"] = $changes + 1;
86                                 $cnum = $conf["status"];
87                                 $conf[$cnum]["add"] = "zone $nametoadd$descbit";
88                                 $comms->putConfig($conf, 3);
89                                 header("Location: $BASE_URL/zones");
90                                 break;
91                                 
92                                 
93                         default:
94                                 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
95                 }
96         } else {
97                 CBFWpageBuilder(null, "CBFWZonesPageDisplay");
98         }
99 }
100
101 function CBFWZonesEditPage($urls)
102 {
103         global $BASE_URL, $MENU_ITEMS;
104         
105         $zone = $urls[2];
106         
107         $comms = new Comms();
108         $myconf = new Config();
109         
110         $config = $comms->getConfig();
111         $conf2 = $comms->getConfig(3);
112         $config = $myconf->mergeConfig($config, $conf2);
113         
114         
115         echo "<h2>Edit Zone $zone</h2>";
116         echo "<form method=\"post\" action=\"$BASE_URL/zones/modify/$zone\">";
117         echo "<input type=\"hidden\" name=\"oldname\" value=\"$zone\">";
118         echo "Name: <input type=\"text\" name=\"zonename\" value=\"$zone\"><br>";
119         
120         if(isset($config["zone"][$zone]["description"])) $desc = $config["zone"][$zone]["description"];
121         
122         echo "Description: <input type=\"text\" name=\"description\" value=\"$desc\"><br>";
123         echo "<input type=\"submit\" name=\"Go\" value=\"Go\">";
124         echo "</form>";
125 }
126
127 function CBFWZonesPageDisplay()
128 {
129         global $BASE_URL, $MENU_ITEMS;
130         
131         $comms = new Comms();
132         $myconf = new Config();
133         
134         $config = $comms->getConfig();
135         $conf2 = $comms->getConfig(3);
136         $config = $myconf->mergeConfig($config, $conf2);
137
138         echo "<h2>Zones</h2>";
139         echo "<table border=\"1\"><tr><th>Zone</th><th>Interfaces</th><th>Description</th><th>Edit</th></tr>";
140         foreach($config["zone"] as $key => $var) {
141                 $name = $key;
142                 $url = "<a href=\"$BASE_URL/zones/edit/$name\">Edit</a>";
143                 $url2 = "<a href=\"$BASE_URL/zones/delete/$name\">Delete</a>";
144                 $desc = $var["description"];
145                 echo "<tr><td>$name</td><td>...</td><td>$desc</td><td>$url $url2</td></tr>";
146         }
147                 
148         echo "</table><br>";
149         echo "<form method=\"post\" action=\"$BASE_URL/zones/add\">";
150         echo "<hr><h3>Add Zone</h3><br>";
151         echo "Name: <input type=\"text\" name=\"toadd\"><br>";
152         echo "Description: <input type=\"text\" name=\"desc\"><br>";
153         echo "<input type=\"submit\" name=\"Add\" value=\"Add\">";
154         echo "</form>";
155         
156 }
157
158 function CBFWInterfacesPage($urls)
159 {
160         if(isset($urls[1])) {
161                 switch($urls[1]) {
162                         case "edit":
163                                 CBFWpageBuilder(null, "CBFWInterfacesPageEdit", null, null, $urls[2]);
164                                 break;
165                         case "change":
166                                 CBFWInterfacesChange();
167                                 break;
168                         default:
169                                 CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
170                 }
171         } else {
172                 error_log("main interface page");
173                 CBFWpageBuilder(null, "CBFWInterfacesPageDisplay");
174         }
175 }
176
177 function CBFWInterfacesChange()
178 {
179         global $BASE_URL, $MENU_ITEMS;
180         $comms = new Comms();
181         
182         $comms->sendMessage("interface eth0 changename poof");
183         header("Location: $BASE_URL/interfaces");
184 }
185
186 function CBFWInterfacesPageEdit($urls)
187 {
188         global $BASE_URL, $MENU_ITEMS;
189         $interface = $urls;
190         
191         echo "<h3>Edit Interface $interface</h3><br>";
192         echo "<form method=\"post\" action=\"$BASE_URL/interfaces/change/$interface\">";
193         echo "<table>";
194         echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"></td></tr>";
195         echo "<tr><td>HW Address</td><td><input type=\"text\" name=\"hwaddr\"></td></tr>";
196         echo "<tr><td>Zone</td><td><input type=\"text\" name=\"zone\"></td></tr>";
197         echo "<tr><td>IPv4 Address</td><td><input type=\"text\" name=\"ipv4addr\"></td></tr>";
198         echo "<tr><td>IPv6 Address</td><td><input type=\"text\" name=\"ipv6addr\"></td></tr>";
199         echo "<tr><td>Speed</td><td><input type=\"text\" name=\"speed\"></td></tr>";
200         echo "<tr><td>Duplex</td><td><input type=\"text\" name=\"duplex\"></td></tr>";
201         echo "</table>";
202         echo "<input type=\"submit\" name=\"Change\" value=\"Change\"><br>";
203         //echo "<a href=\"$BASE_URL/interfaces/\">Back</a>";
204         echo "</form>";
205 }
206
207 function CBFWInterfacesPageDisplay()
208 {
209         global $BASE_URL, $MENU_ITEMS;
210         $comms = new Comms();
211         
212         $config = $comms->getConfig(0);
213         $boot_config = $comms->getConfig(1);
214         
215         // now build an interface table
216         $table = array();
217         foreach($boot_config["hardware"]["netdev"] as $key=>$val) {
218                 $ename = $key;
219                 $table[$key]["realname"] = $val["name"];
220                 $table[$key]["name"] = $val["name"];
221                 
222                 
223                 // driver
224                 if(isset($val["driver"])) $table[$key]["type"] = $val["driver"];
225                 else $table[$key]["type"] = "Unknown";
226                 
227                 // hw address
228                 if(isset($val["hwaddress"])) $table[$key]["hwaddress"] = $val["hwaddress"];
229                 
230                 // current mtu
231                 if(isset($val["mtu"])) $table[$key]["mtu"] = $val["mtu"];
232         }
233         
234         foreach($config["hardware"]["netdev"] as $key=>$val) {
235                 $ename = $key;
236                 if(isset($config["interface"]["$key"]["name"])) $table[$key]["name"] = $config["interface"]["$key"]["name"];
237                 $table[$key]["address4"] = null;
238                 $table[$key]["address6"] = null;
239                 
240                 if(isset($config["interface"][$table[$key]["name"]]["address4"])) {
241                         $table[$key]["address4"] = $config["interface"][$table[$key]["name"]]["address4"];
242                 }
243                 
244                 if(isset($config["interface"][$table[$key]["name"]]["address6"])) {
245                         $table[$key]["address6"] = $config["interface"][$table[$key]["name"]]["address6"];
246                 }
247                 
248                 if(isset($config["interface"][$table[$key]["name"]]["mtu"])) {
249                         $table[$key]["mtu"] = $config["interface"][$table[$key]["name"]]["mtu"];
250                 } else {
251                         $table[$key]["mtu"] = "1500"; // TODO: this needs to actually come from somewhere
252                 }
253                 
254                 if(isset($config["interface"][$table[$key]["name"]]["speed"])) {
255                         $table[$key]["speed"] = $config["interface"][$table[$key]["name"]]["speed"];
256                 } else {
257                         $table[$key]["speed"] = null;
258                 }
259
260                 if(isset($config["interface"][$table[$key]["name"]]["duplex"])) {
261                         $table[$key]["duplex"] = $config["interface"][$table[$key]["name"]]["duplex"];
262                 } else {
263                         $table[$key]["duplex"] = null;
264                 }
265                 
266                 if(isset($config["interface"][$table[$key]["name"]]["zone"])) {
267                         $table[$key]["zone"] = $config["interface"][$table[$key]["name"]]["zone"];
268                 } else {
269                         $table[$key]["zone"] = null;
270                 }
271         }
272         
273         
274         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>";
275         foreach($table as $key =>$val) {
276                 if($val["realname"] == $val["name"]) $name = $val["name"];
277                 else $name = $val["name"]." (".$val["realname"].")";
278                 
279                 // zone
280                 if($val["zone"] == null) $zone = "-";
281                 else $zone = $val["zone"];
282                 
283                 // mtu
284                 $mtu = $val["mtu"];
285                 
286                 // driver type
287                 $type = $val["type"];
288                 
289                 // hardware address
290                 $mac = $val["hwaddress"];
291                 
292                 // speed and duplex
293                 if($val["duplex"] == null) $dup = "default";
294                 else $dup = $val["duplex"];
295                 
296                 if($val["speed"] == null) $spd = "default";
297                 else $spd = $val["speed"];
298                 
299                 $spanddu = "$spd/$dup";
300                 
301                 // network address
302                 if($val["address4"]!=null && $val["address6"]!=null) {
303                         $address = $val["address4"]."<br>".$val["address6"];
304                 } else if($val["address4"] != null) {
305                         $address = $val["address4"];
306                 } else if($val["address6"] != null) {
307                         $address = $val["address6"];
308                 } else {
309                         $address = "-";
310                 }
311                 
312                 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>";
313         }
314         echo "</table>";
315 }
316
317 function CBFWObjectsPage()
318 {
319         $comms = new Comms();
320         
321         $config = $comms->getConfig();
322 }
323
324 function CBFWRulesPage()
325 {
326         $comms = new Comms();
327         
328         $config = $comms->getConfig();
329 }
330
331 function findUrl($url_s)
332 {
333         global $URL_HANDLERS;
334         
335         foreach($URL_HANDLERS as $key => $val) {
336                 
337         }
338 }
339 ?>