2 $MENU_ITEMS["15_Zones"]["link"] = "$BASE_URL/zones";
3 $MENU_ITEMS["15_Zones"]["name"] = "Zones";
4 $MENU_ITEMS["20_Objects"]["link"] = "$BASE_URL/objects";
5 $MENU_ITEMS["20_Objects"]["name"] = "Objects";
6 $MENU_ITEMS["30_Rules"]["link"] = "$BASE_URL/rules";
7 $MENU_ITEMS["30_Rules"]["name"] = "Rules";
8 $MENU_ITEMS["15_Routes"]["link"] = "$BASE_URL/routing";
9 $MENU_ITEMS["15_Routes"]["name"] = "Routing";
10 $MENU_ITEMS["10_Interfaces"]["link"] = "$BASE_URL/interfaces";
11 $MENU_ITEMS["10_Interfaces"]["name"] = "Interfaces";
12 $MENU_ITEMS["05_Admin"]["link"] = "$BASE_URL/admin";
13 $MENU_ITEMS["05_Admin"]["name"] = "Admin";
15 // if i believed in name spacing in php, i'd use it.
16 error_log("cbfwweb loaded");
20 function __construct()
32 $conf->loadConfig($comms->getConfig(0));
33 $rconfig = $conf->getConfig();
35 if($rconfig["status"] != "conf") {
36 if($rconfig["status"] == "nodir") {
40 cbfw_startinstaller();
45 if(isset($_REQUEST["q"])) {
46 $url = $_REQUEST["q"];
48 // ok, now we try and find the basics
49 $url_s = explode("/", $url);
54 CBFWZonesPage($url_s);
57 CBFWInterfacesPage($url_s);
60 CBFWObjectsPage($url_s);
63 CBFWRoutingPage($url_s);
66 $bodyFunction = "CBFWRulesPage";
69 CBFWChangesPage($url_s);
72 CBFWAdminPage($url_s);
75 $bodyFunction = findUrl($url_s);
78 $bodyFunction = "CBFBuildHomePage";
80 if($bodyFunction != null) CBFWpageBuilder(null, $bodyFunction);
85 function CBFBuildHomePage($urls)
87 echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
88 echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum";
93 CBFWAddMessage(rand(1,6), "i am a message");
95 print_r($comms->getConfig(0));
97 print_r($comms->getConfig(1));
99 print_r($comms->getConfig(2));
101 print_r($comms->getConfig(3));
103 print_r($comms->getConfig(4));
105 print_r($comms->getConfig(5));
110 function CBFWMenuBuilder()
112 global $BASE_URL, $MENU_ITEMS;
116 <table border="1"><tr><th>Menu</th><td>
117 <a href="<?php echo $BASE_URL ?>">Home</a></td>
119 foreach($MENU_ITEMS as $key => $val) {
120 $link = $val["link"];
121 $name = $val["name"];
122 echo "<td><a href=$link>$name</a></td>";
128 // just a short one to call the long one
129 function gcam($m, $s)
132 CBFWAddMessage($m, $s);
135 function CBFWAddMessage($messagelev, $message)
137 $comms = new Comms();
138 $msgs = $comms->getConfig(6);
141 foreach($msgs as $key=>$val) {
142 if($key >= $cnum) $cnum = $key+1;
147 $msgs[$cnum]["timestamp"] = time();
148 $msgs[$cnum]["level"] = $messagelev;
149 $msgs[$cnum]["message"] = $message;
151 $comms->putConfig($msgs, 6);
154 function CBFWMessageBuilder()
156 // show only 10 messages on this page
159 $comms = new Comms();
161 $msgs = $comms->getConfig(6);
166 if(count($msgs) > 0) {
168 foreach($msgs as $key => $val) {
169 $datetime = strftime("%c", $val["timestamp"]);
170 $sev = $val["level"];
171 $message = $val["message"];
173 $sevcolour = "#ddffdd";
176 $sevcolour = "#ffaaaa";
179 $sevcolour = "#ffdddd";
182 $sevcolour = "#ffffdd";
185 $sevcolour = "#ddffdd";
188 $sevcolour = "#aaffaa";
191 $sevcolour = "#ccaaaa";
195 echo "<tr bgcolor=\"$sevcolour\"><td><i>$datetime</i></td><td>$message ($sev)</td></tr>";
197 if($show >= $maxshow) break;
203 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
205 global $WEB_ROOT_FS, $BASE_URL;
209 echo "<html><head><title>$title</title>";
212 if(file_exists("$WEB_ROOT_FS/css")) {
213 $dh = opendir("$WEB_ROOT_FS/css");
215 while(($file = readdir($dh))!==false) {
216 $mt = preg_match("/.*.css$/", $file);
218 error_log("loading css $file");
219 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
220 //echo "required $basedir/$file\n";
227 if(file_exists("$WEB_ROOT_FS/js")) {
228 $dh = opendir("$WEB_ROOT_FS/js");
230 while(($file = readdir($dh))!==false) {
231 $mt = preg_match("/.*.js$/", $file);
233 error_log("loading js $file");
234 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
235 //echo "required $basedir/$file\n";
243 echo "</head><body>";
246 echo "<h1>CBFW</h1><br>";
247 echo "<table width=\"100%\"><tr width=\"100%\"><td>";
248 CBFWMessageBuilder();
249 echo "<td><td align=\"right\">";
251 echo "</td></tr><tr><td>";
254 echo "<table><tr><td>";
256 echo "</td></tr><tr><td>";
259 if(isset($_REQUEST["q"])) {
260 $url = $_REQUEST["q"];
263 if($bodyClass != null) {
264 $bodyClass->$bodyFunction($bodyfunctiondata);
265 } else if( $bodyFunction != null) {
266 $bodyFunction($bodyfunctiondata);
267 } else echo $bodycontent;
268 echo "</td></tr></table>";
271 // close the big wrap-around table
272 echo "</td></tr></table>";
275 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
279 function cbfw_getLastSeen($ip, $data)
283 if(!$data) return $last;
287 foreach($data as $key=>$val) {
288 $last = $val["name"];
289 error_log("got $last for $ip");
292 if($last == "never") return $last;
294 $last = cbfw_tdiffToAgo(time()-$last);
296 error_log("last for $ip set to $last");
302 function CBFWConfigStatus()
304 global $WEB_ROOT_FS, $BASE_URL;
306 $comms = new Comms();
308 $conf0 = $comms->getConfig(0);
309 $conf1 = $comms->getConfig(2);
310 $conf2 = $comms->getConfig(3);
312 if($conf1["status"] == "nochange") {
314 $running = "Current";
317 $running = "Current";
319 if($conf2["status"] == "nochange") {
322 $ch = $conf2["status"];
323 $client = "$ch Changes <a href=\"$BASE_URL/changes/show\">Show</a>";
327 echo "Saved Config: $saved<br>";
328 echo "Running Config: $running<br>";
329 echo "Client Config: $client<br>";
332 function cbfw_tdiffToAgo($time_in_sec)
334 $tdiff = $time_in_sec;
335 $tdiff_min = (int)($tdiff/60);
336 $tdiff_hour = (int)($tdiff/3600);
337 $tdiff_days = (int)($tdiff/86400);
339 if($tdiff < 60) $last = "Less then a minute";
340 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
341 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
342 if($tdiff >= 86400) $last = "$tdiff_days days ago";
347 function cbfw_startInstaller()
349 global $WEB_ROOT_FS, $BASE_URL;
351 $uid = posix_geteuid();
352 $gid = posix_getegid();
353 $uid_a = posix_getpwuid($uid);
354 $uid = $uid_a["name"];
356 $gid_a = posix_getgrgid($gid);
357 $gid = $gid_a["name"];
358 error_log("user id is $uid, group id is $gid");
360 if(isset($_REQUEST["installdir"])) {
361 $c = new CBFWConfig();
362 touch($_REQUEST["installdir"]."/webconfig");
363 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
364 header("Location: index.php");
368 $underroot = realpath($WEB_ROOT_FS."/../");
372 <h1>Welcome to CBFW</h1>
373 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
374 If this is not correct then we have a big problem that needs to be solved, i hope you have a backup of the old
375 config, cause that will make life easier.<br><br>
376 However, if this is the first time you have run this app, then all is good with the world. All I need right
377 now is a place where i can store my config. I search the following directories for the location of my
378 configuration (webconfig)<br>
381 <li> <?php echo $underroot?>/var/glcas/
384 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
385 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
387 Now, tell me where you want me to create the webconfig file:<br>
389 <select name="installdir">
390 <option value="/var/run/glcas">/var/run/glcas</option>
391 <option value="/var/lib/glcas">/var/lib/glcas</option>
392 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
394 <input type="submit" name="Go" value="Go">
403 function cbfw_startnodir()
408 There is no config and no directory where i can store one. Login to the server and either create /var/run/cbfwr or <?php echo $LIB_ROOT_FS?>/var