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 print_r($comms->getConfig(0));
95 print_r($comms->getConfig(1));
97 print_r($comms->getConfig(2));
99 print_r($comms->getConfig(3));
101 print_r($comms->getConfig(4));
103 print_r($comms->getConfig(5));
108 function CBFWMenuBuilder()
110 global $BASE_URL, $MENU_ITEMS;
114 <table border="1"><tr><th>Menu</th><td>
115 <a href="<?php echo $BASE_URL ?>">Home</a></td>
117 foreach($MENU_ITEMS as $key => $val) {
118 $link = $val["link"];
119 $name = $val["name"];
120 echo "<td><a href=$link>$name</a></td>";
126 // just a short one to call the long one
127 function gcam($m, $s)
130 CBFWAddMessage($m, $s);
133 function CBFWAddMessage($messagelev, $message)
138 function CBFWMessageBuilder()
143 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
145 global $WEB_ROOT_FS, $BASE_URL;
149 echo "<html><head><title>$title</title>";
152 if(file_exists("$WEB_ROOT_FS/css")) {
153 $dh = opendir("$WEB_ROOT_FS/css");
155 while(($file = readdir($dh))!==false) {
156 $mt = preg_match("/.*.css$/", $file);
158 error_log("loading css $file");
159 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
160 //echo "required $basedir/$file\n";
167 if(file_exists("$WEB_ROOT_FS/js")) {
168 $dh = opendir("$WEB_ROOT_FS/js");
170 while(($file = readdir($dh))!==false) {
171 $mt = preg_match("/.*.js$/", $file);
173 error_log("loading js $file");
174 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
175 //echo "required $basedir/$file\n";
183 echo "</head><body>";
186 echo "<h1>CBFW</h1><br>";
187 echo "<table width=\"100%\"><tr width=\"100%\"><td>";
188 CBFWMessageBuilder();
189 echo "<td><td align=\"right\">";
191 echo "</td></tr><tr><td>";
194 echo "<table><tr><td>";
196 echo "</td></tr><tr><td>";
199 if(isset($_REQUEST["q"])) {
200 $url = $_REQUEST["q"];
203 if($bodyClass != null) {
204 $bodyClass->$bodyFunction($bodyfunctiondata);
205 } else if( $bodyFunction != null) {
206 $bodyFunction($bodyfunctiondata);
207 } else echo $bodycontent;
208 echo "</td></tr></table>";
211 // close the big wrap-around table
212 echo "</td></tr></table>";
215 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
219 function cbfw_getLastSeen($ip, $data)
223 if(!$data) return $last;
227 foreach($data as $key=>$val) {
228 $last = $val["name"];
229 error_log("got $last for $ip");
232 if($last == "never") return $last;
234 $last = cbfw_tdiffToAgo(time()-$last);
236 error_log("last for $ip set to $last");
242 function CBFWConfigStatus()
244 global $WEB_ROOT_FS, $BASE_URL;
246 $comms = new Comms();
248 $conf0 = $comms->getConfig(0);
249 $conf1 = $comms->getConfig(2);
250 $conf2 = $comms->getConfig(3);
252 if($conf1["status"] == "nochange") {
254 $running = "Current";
257 $running = "Current";
259 if($conf2["status"] == "nochange") {
262 $ch = $conf2["status"];
263 $client = "$ch Changes <a href=\"$BASE_URL/changes/show\">Show</a>";
267 echo "Saved Config: $saved<br>";
268 echo "Running Config: $running<br>";
269 echo "Client Config: $client<br>";
272 function cbfw_tdiffToAgo($time_in_sec)
274 $tdiff = $time_in_sec;
275 $tdiff_min = (int)($tdiff/60);
276 $tdiff_hour = (int)($tdiff/3600);
277 $tdiff_days = (int)($tdiff/86400);
279 if($tdiff < 60) $last = "Less then a minute";
280 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
281 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
282 if($tdiff >= 86400) $last = "$tdiff_days days ago";
287 function cbfw_startInstaller()
289 global $WEB_ROOT_FS, $BASE_URL;
291 $uid = posix_geteuid();
292 $gid = posix_getegid();
293 $uid_a = posix_getpwuid($uid);
294 $uid = $uid_a["name"];
296 $gid_a = posix_getgrgid($gid);
297 $gid = $gid_a["name"];
298 error_log("user id is $uid, group id is $gid");
300 if(isset($_REQUEST["installdir"])) {
301 $c = new CBFWConfig();
302 touch($_REQUEST["installdir"]."/webconfig");
303 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
304 header("Location: index.php");
308 $underroot = realpath($WEB_ROOT_FS."/../");
312 <h1>Welcome to CBFW</h1>
313 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
314 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
315 config, cause that will make life easier.<br><br>
316 However, if this is the first time you have run this app, then all is good with the world. All I need right
317 now is a place where i can store my config. I search the following directories for the location of my
318 configuration (webconfig)<br>
321 <li> <?php echo $underroot?>/var/glcas/
324 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
325 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
327 Now, tell me where you want me to create the webconfig file:<br>
329 <select name="installdir">
330 <option value="/var/run/glcas">/var/run/glcas</option>
331 <option value="/var/lib/glcas">/var/lib/glcas</option>
332 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
334 <input type="submit" name="Go" value="Go">
343 function cbfw_startnodir()
348 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