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("1", "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 = $val["timestamp"];
170 $sev = $val["level"];
171 $message = $val["message"];
172 echo "<tr><td>$datetime</td><td>$sev</td><td>$message</td></tr>";
174 if($show >= $maxshow) break;
180 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
182 global $WEB_ROOT_FS, $BASE_URL;
186 echo "<html><head><title>$title</title>";
189 if(file_exists("$WEB_ROOT_FS/css")) {
190 $dh = opendir("$WEB_ROOT_FS/css");
192 while(($file = readdir($dh))!==false) {
193 $mt = preg_match("/.*.css$/", $file);
195 error_log("loading css $file");
196 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
197 //echo "required $basedir/$file\n";
204 if(file_exists("$WEB_ROOT_FS/js")) {
205 $dh = opendir("$WEB_ROOT_FS/js");
207 while(($file = readdir($dh))!==false) {
208 $mt = preg_match("/.*.js$/", $file);
210 error_log("loading js $file");
211 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
212 //echo "required $basedir/$file\n";
220 echo "</head><body>";
223 echo "<h1>CBFW</h1><br>";
224 echo "<table width=\"100%\"><tr width=\"100%\"><td>";
225 CBFWMessageBuilder();
226 echo "<td><td align=\"right\">";
228 echo "</td></tr><tr><td>";
231 echo "<table><tr><td>";
233 echo "</td></tr><tr><td>";
236 if(isset($_REQUEST["q"])) {
237 $url = $_REQUEST["q"];
240 if($bodyClass != null) {
241 $bodyClass->$bodyFunction($bodyfunctiondata);
242 } else if( $bodyFunction != null) {
243 $bodyFunction($bodyfunctiondata);
244 } else echo $bodycontent;
245 echo "</td></tr></table>";
248 // close the big wrap-around table
249 echo "</td></tr></table>";
252 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
256 function cbfw_getLastSeen($ip, $data)
260 if(!$data) return $last;
264 foreach($data as $key=>$val) {
265 $last = $val["name"];
266 error_log("got $last for $ip");
269 if($last == "never") return $last;
271 $last = cbfw_tdiffToAgo(time()-$last);
273 error_log("last for $ip set to $last");
279 function CBFWConfigStatus()
281 global $WEB_ROOT_FS, $BASE_URL;
283 $comms = new Comms();
285 $conf0 = $comms->getConfig(0);
286 $conf1 = $comms->getConfig(2);
287 $conf2 = $comms->getConfig(3);
289 if($conf1["status"] == "nochange") {
291 $running = "Current";
294 $running = "Current";
296 if($conf2["status"] == "nochange") {
299 $ch = $conf2["status"];
300 $client = "$ch Changes <a href=\"$BASE_URL/changes/show\">Show</a>";
304 echo "Saved Config: $saved<br>";
305 echo "Running Config: $running<br>";
306 echo "Client Config: $client<br>";
309 function cbfw_tdiffToAgo($time_in_sec)
311 $tdiff = $time_in_sec;
312 $tdiff_min = (int)($tdiff/60);
313 $tdiff_hour = (int)($tdiff/3600);
314 $tdiff_days = (int)($tdiff/86400);
316 if($tdiff < 60) $last = "Less then a minute";
317 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
318 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
319 if($tdiff >= 86400) $last = "$tdiff_days days ago";
324 function cbfw_startInstaller()
326 global $WEB_ROOT_FS, $BASE_URL;
328 $uid = posix_geteuid();
329 $gid = posix_getegid();
330 $uid_a = posix_getpwuid($uid);
331 $uid = $uid_a["name"];
333 $gid_a = posix_getgrgid($gid);
334 $gid = $gid_a["name"];
335 error_log("user id is $uid, group id is $gid");
337 if(isset($_REQUEST["installdir"])) {
338 $c = new CBFWConfig();
339 touch($_REQUEST["installdir"]."/webconfig");
340 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
341 header("Location: index.php");
345 $underroot = realpath($WEB_ROOT_FS."/../");
349 <h1>Welcome to CBFW</h1>
350 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
351 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
352 config, cause that will make life easier.<br><br>
353 However, if this is the first time you have run this app, then all is good with the world. All I need right
354 now is a place where i can store my config. I search the following directories for the location of my
355 configuration (webconfig)<br>
358 <li> <?php echo $underroot?>/var/glcas/
361 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
362 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
364 Now, tell me where you want me to create the webconfig file:<br>
366 <select name="installdir">
367 <option value="/var/run/glcas">/var/run/glcas</option>
368 <option value="/var/lib/glcas">/var/lib/glcas</option>
369 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
371 <input type="submit" name="Go" value="Go">
380 function cbfw_startnodir()
385 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