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["10_Interfaces"]["link"] = "$BASE_URL/interfaces";
9 $MENU_ITEMS["10_Interfaces"]["name"] = "Interfaces";
10 $MENU_ITEMS["05_Admin"]["link"] = "$BASE_URL/admin";
11 $MENU_ITEMS["05_Admin"]["name"] = "Admin";
13 // if i believed in name spacing in php, i'd use it.
14 error_log("cbfwweb loaded");
18 function __construct()
30 $conf->loadConfig($comms->getConfig(0));
31 $rconfig = $conf->getConfig();
33 if($rconfig["status"] != "conf") {
34 if($rconfig["status"] == "nodir") {
38 cbfw_startinstaller();
43 if(isset($_REQUEST["q"])) {
44 $url = $_REQUEST["q"];
46 // ok, now we try and find the basics
47 $url_s = explode("/", $url);
52 CBFWZonesPage($url_s);
55 CBFWInterfacesPage($url_s);
58 $bodyFunction = "CBFWObjectsPage";
61 $bodyFunction = "CBFWRulesPage";
64 $bodyFunction = "CBFWAdminPage";
67 $bodyFunction = findUrl($url_s);
70 $bodyFunction = "CBFBuildHomePage";
72 if($bodyFunction != null) CBFWpageBuilder(null, $bodyFunction);
77 function CBFWAdminPage($urls)
79 echo "im an admin page";
82 function CBFBuildHomePage($urls)
84 echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
85 echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum";
90 print_r($comms->getConfig(0));
92 print_r($comms->getConfig(1));
94 print_r($comms->getConfig(2));
96 print_r($comms->getConfig(3));
101 function CBFWMenuBuilder()
103 global $BASE_URL, $MENU_ITEMS;
107 <table border="1"><tr><th>Menu</th><td>
108 <a href="<?php echo $BASE_URL ?>">Home</a></td>
110 foreach($MENU_ITEMS as $key => $val) {
111 $link = $val["link"];
112 $name = $val["name"];
113 echo "<td><a href=$link>$name</a></td>";
119 // just a short one to call the long one
120 function gcam($m, $s)
123 CBFWAddMessage($m, $s);
126 function CBFWAddMessage($messagelev, $message)
131 function CBFWMessageBuilder()
136 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW", $bodyfunctiondata=null)
138 global $WEB_ROOT_FS, $BASE_URL;
142 echo "<html><head><title>$title</title>";
145 if(file_exists("$WEB_ROOT_FS/css")) {
146 $dh = opendir("$WEB_ROOT_FS/css");
148 while(($file = readdir($dh))!==false) {
149 $mt = preg_match("/.*.css$/", $file);
151 error_log("loading css $file");
152 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
153 //echo "required $basedir/$file\n";
160 if(file_exists("$WEB_ROOT_FS/js")) {
161 $dh = opendir("$WEB_ROOT_FS/js");
163 while(($file = readdir($dh))!==false) {
164 $mt = preg_match("/.*.js$/", $file);
166 error_log("loading js $file");
167 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
168 //echo "required $basedir/$file\n";
176 echo "</head><body>";
179 echo "<h1>CBFW</h1><br>";
180 echo "<table><tr width=\"100%\"><td>";
181 CBFWMessageBuilder();
182 echo "<td><td><align=\"right\">";
184 echo "</align></td></tr><tr><td>";
187 echo "<table><tr><td>";
189 echo "</td></tr><tr><td>";
192 if(isset($_REQUEST["q"])) {
193 $url = $_REQUEST["q"];
196 if($bodyClass != null) {
197 $bodyClass->$bodyFunction($bodyfunctiondata);
198 } else if( $bodyFunction != null) {
199 $bodyFunction($bodyfunctiondata);
200 } else echo $bodycontent;
201 echo "</td></tr></table>";
204 // close the big wrap-around table
205 echo "</td></tr></table>";
208 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
212 function cbfw_getLastSeen($ip, $data)
216 if(!$data) return $last;
220 foreach($data as $key=>$val) {
221 $last = $val["name"];
222 error_log("got $last for $ip");
225 if($last == "never") return $last;
227 $last = cbfw_tdiffToAgo(time()-$last);
229 error_log("last for $ip set to $last");
235 function CBFWConfigStatus()
237 $comms = new Comms();
239 $conf0 = $comms->getConfig(0);
240 $conf1 = $comms->getConfig(2);
241 $conf2 = $comms->getConfig(3);
243 if($conf1["status"] == "nochange") {
245 $running = "Current";
248 $running = "Current";
250 if($conf2["status"] == "nochange") {
253 $ch = $conf2["status"];
254 $client = "$ch Changes";
258 echo "Saved Config: $saved<br>";
259 echo "Running Config: $running<br>";
260 echo "Client Config: $client<br>";
263 function cbfw_tdiffToAgo($time_in_sec)
265 $tdiff = $time_in_sec;
266 $tdiff_min = (int)($tdiff/60);
267 $tdiff_hour = (int)($tdiff/3600);
268 $tdiff_days = (int)($tdiff/86400);
270 if($tdiff < 60) $last = "Less then a minute";
271 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
272 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
273 if($tdiff >= 86400) $last = "$tdiff_days days ago";
278 function cbfw_startInstaller()
280 global $WEB_ROOT_FS, $BASE_URL;
282 $uid = posix_geteuid();
283 $gid = posix_getegid();
284 $uid_a = posix_getpwuid($uid);
285 $uid = $uid_a["name"];
287 $gid_a = posix_getgrgid($gid);
288 $gid = $gid_a["name"];
289 error_log("user id is $uid, group id is $gid");
291 if(isset($_REQUEST["installdir"])) {
292 $c = new CBFWConfig();
293 touch($_REQUEST["installdir"]."/webconfig");
294 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
295 header("Location: index.php");
299 $underroot = realpath($WEB_ROOT_FS."/../");
303 <h1>Welcome to CBFW</h1>
304 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
305 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
306 config, cause that will make life easier.<br><br>
307 However, if this is the first time you have run this app, then all is good with the world. All I need right
308 now is a place where i can store my config. I search the following directories for the location of my
309 configuration (webconfig)<br>
312 <li> <?php echo $underroot?>/var/glcas/
315 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
316 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
318 Now, tell me where you want me to create the webconfig file:<br>
320 <select name="installdir">
321 <option value="/var/run/glcas">/var/run/glcas</option>
322 <option value="/var/lib/glcas">/var/lib/glcas</option>
323 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
325 <input type="submit" name="Go" value="Go">
334 function cbfw_startnodir()
339 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