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 $rconfig = $conf->getConfig();
32 if($rconfig["status"] != "conf") {
33 cbfw_startinstaller();
38 if(isset($_REQUEST["q"])) {
39 $url = $_REQUEST["q"];
41 // ok, now we try and find the basics
42 $url_s = explode("/", $url);
46 $bodyFunction = "CBFWZonesPage";
49 $bodyFunction = "CBFWInterfacesPage";
52 $bodyFunction = "CBFWObjectsPage";
55 $bodyFunction = "CBFWRulesPage";
58 $bodyFunction = "CBFWAdminPage";
61 $bodyFunction = findUrl($url_s);
64 $bodyFunction = "CBFBuildHomePage";
66 CBFWpageBuilder(null, $bodyFunction);
71 function CBFWAdminPage($urls)
73 echo "im an admin page";
76 function CBFBuildHomePage($urls)
78 echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
79 echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum";
84 print_r($conf->getConfig());
86 print_r($conf->getBootConfig());
91 function CBFWMenuBuilder()
93 global $BASE_URL, $MENU_ITEMS;
97 <table border="1"><tr><th>Menu</th><td>
98 <a href="<?php echo $BASE_URL ?>">Home</a></td>
100 foreach($MENU_ITEMS as $key => $val) {
101 $link = $val["link"];
102 $name = $val["name"];
103 echo "<td><a href=$link>$name</a></td>";
109 // just a short one to call the long one
110 function gcam($m, $s)
113 CBFWAddMessage($m, $s);
116 function CBFWAddMessage($messagelev, $message)
121 function CBFWMessageBuilder()
126 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW")
128 global $WEB_ROOT_FS, $BASE_URL;
132 echo "<html><head><title>$title</title>";
135 if(file_exists("$WEB_ROOT_FS/css")) {
136 $dh = opendir("$WEB_ROOT_FS/css");
138 while(($file = readdir($dh))!==false) {
139 $mt = preg_match("/.*.css$/", $file);
141 error_log("loading css $file");
142 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
143 //echo "required $basedir/$file\n";
150 if(file_exists("$WEB_ROOT_FS/js")) {
151 $dh = opendir("$WEB_ROOT_FS/js");
153 while(($file = readdir($dh))!==false) {
154 $mt = preg_match("/.*.js$/", $file);
156 error_log("loading js $file");
157 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
158 //echo "required $basedir/$file\n";
166 echo "</head><body>";
169 echo "<h1>CBFW</h1><br>";
170 echo "<table><tr><td>";
171 CBFWMessageBuilder();
172 echo "<td></tr><tr><td>";
175 echo "<table><tr><td>";
177 echo "</td></tr><tr><td>";
180 if(isset($_REQUEST["q"])) {
181 $url = $_REQUEST["q"];
184 if($bodyClass != null) {
185 $bodyClass->$bodyFunction($url);
186 } else if( $bodyFunction != null) {
188 } else echo $bodycontent;
189 echo "</td></tr></table>";
192 // close the big wrap-around table
193 echo "</td></tr></table>";
196 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
200 function cbfw_getLastSeen($ip, $data)
204 if(!$data) return $last;
208 foreach($data as $key=>$val) {
209 $last = $val["name"];
210 error_log("got $last for $ip");
213 if($last == "never") return $last;
215 $last = cbfw_tdiffToAgo(time()-$last);
217 error_log("last for $ip set to $last");
223 function cbfw_tdiffToAgo($time_in_sec)
225 $tdiff = $time_in_sec;
226 $tdiff_min = (int)($tdiff/60);
227 $tdiff_hour = (int)($tdiff/3600);
228 $tdiff_days = (int)($tdiff/86400);
230 if($tdiff < 60) $last = "Less then a minute";
231 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
232 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
233 if($tdiff >= 86400) $last = "$tdiff_days days ago";
238 function cbfw_startInstaller()
240 global $WEB_ROOT_FS, $BASE_URL;
242 $uid = posix_geteuid();
243 $gid = posix_getegid();
244 $uid_a = posix_getpwuid($uid);
245 $uid = $uid_a["name"];
247 $gid_a = posix_getgrgid($gid);
248 $gid = $gid_a["name"];
249 error_log("user id is $uid, group id is $gid");
251 if(isset($_REQUEST["installdir"])) {
252 $c = new CBFWConfig();
253 touch($_REQUEST["installdir"]."/webconfig");
254 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
255 header("Location: index.php");
259 $underroot = realpath($WEB_ROOT_FS."/../");
263 <h1>Welcome to CBFW</h1>
264 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
265 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
266 config, cause that will make life easier.<br><br>
267 However, if this is the first time you have run this app, then all is good with the world. All I need right
268 now is a place where i can store my config. I search the following directories for the location of my
269 configuration (webconfig)<br>
272 <li> <?php echo $underroot?>/var/glcas/
275 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
276 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
278 Now, tell me where you want me to create the webconfig file:<br>
280 <select name="installdir">
281 <option value="/var/run/glcas">/var/run/glcas</option>
282 <option value="/var/lib/glcas">/var/lib/glcas</option>
283 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
285 <input type="submit" name="Go" value="Go">