2 $MENU_ITEMS["Zones"]["link"] = "$BASE_URL/zones";
3 $MENU_ITEMS["Zones"]["name"] = "Zones";
4 $MENU_ITEMS["Interfaces"]["link"] = "$BASE_URL/interfaces";
5 $MENU_ITEMS["Interfaces"]["name"] = "Interfaces";
6 $MENU_ITEMS["Objects"]["link"] = "$BASE_URL/objects";
7 $MENU_ITEMS["Objects"]["name"] = "Objects";
8 $MENU_ITEMS["Rules"]["link"] = "$BASE_URL/rules";
9 $MENU_ITEMS["Rules"]["name"] = "Rules";
11 // if i believed in name spacing in php, i'd use it.
12 error_log("cbfwweb loaded");
16 function __construct()
25 if(isset($_REQUEST["q"])) {
26 $url = $_REQUEST["q"];
28 // ok, now we try and find the basics
29 $url_s = explode("/", $url);
33 $bodycontent = CBFWZonesPage($url_s);
36 $bodycontent = CBFWInterfacesPage($url_s);
39 $bodycontent = CBFWObjectsPage($url_s);
42 $bodycontent = CBFWRulesPage($url_s);
45 $bodycontent = findUrl($url_s);
48 CBFWpageBuilder(null, null, $bodycontent);
52 function CBFWMenuBuilder()
54 global $BASE_URL, $MENU_ITEMS;
58 <table border="1"><tr><th>Menu</th><td>
59 <a href="<?php echo $BASE_URL ?>">Home</a></td>
61 foreach($MENU_ITEMS as $key => $val) {
64 echo "<td><a href=$link>$name</a></td>";
70 // just a short one to call the long one
74 CBFWAddMessage($m, $s);
77 function CBFWAddMessage($messagelev, $message)
82 function CBFWMessageBuilder()
87 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW")
89 global $WEB_ROOT_FS, $BASE_URL;
93 echo "<html><head><title>$title</title>";
96 if(file_exists("$WEB_ROOT_FS/css")) {
97 $dh = opendir("$WEB_ROOT_FS/css");
99 while(($file = readdir($dh))!==false) {
100 $mt = preg_match("/.*.css$/", $file);
102 error_log("loading css $file");
103 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
104 //echo "required $basedir/$file\n";
111 if(file_exists("$WEB_ROOT_FS/js")) {
112 $dh = opendir("$WEB_ROOT_FS/js");
114 while(($file = readdir($dh))!==false) {
115 $mt = preg_match("/.*.js$/", $file);
117 error_log("loading js $file");
118 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
119 //echo "required $basedir/$file\n";
127 echo "</head><body>";
130 echo "<h1>CBFW</h1><br>";
131 echo "<table><tr><td>";
132 CBFWMessageBuilder();
133 echo "<td></tr><tr><td>";
136 echo "<table><tr><td>";
138 echo "</td></tr><tr><td>";
141 if(isset($_REQUEST["q"])) {
142 $url = $_REQUEST["q"];
145 if($bodyClass != null) {
146 $bodyClass->$bodyFunction($url);
147 } else if( $bodyFunction != null) {
149 } else echo $bodycontent;
150 echo "</td></tr></table>";
153 // close the big wrap-around table
154 echo "</td></tr></table>";
157 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
161 function cbfw_getLastSeen($ip, $data)
165 if(!$data) return $last;
169 foreach($data as $key=>$val) {
170 $last = $val["name"];
171 error_log("got $last for $ip");
174 if($last == "never") return $last;
176 $last = cbfw_tdiffToAgo(time()-$last);
178 error_log("last for $ip set to $last");
184 function cbfw_tdiffToAgo($time_in_sec)
186 $tdiff = $time_in_sec;
187 $tdiff_min = (int)($tdiff/60);
188 $tdiff_hour = (int)($tdiff/3600);
189 $tdiff_days = (int)($tdiff/86400);
191 if($tdiff < 60) $last = "Less then a minute";
192 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
193 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
194 if($tdiff >= 86400) $last = "$tdiff_days days ago";
199 function cbfw_isRemoteDir($url)
201 file_get_contents($url);
202 //error_log("did file_get_contents on $url");
203 foreach($http_response_header as $key => $val) {
204 //error_log("got header of $key for $val");
205 if(preg_match("/.*Location:.*/", $val)) {
206 //error_log("in details apt got location as $val from $url");
207 $realloc = preg_replace("/.*: /", "", $val);
208 $urlwithslash = $url."/";
209 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
210 if(strcasecmp($realloc,$urlwithslash)==0) {
211 //error_log("I believe $realloc is a directory redir for $url");
214 //error_log("I dont believe $realloc is a directory redir for $url");
221 function cbfw_fileExists($url)
223 $fp = fopen($url, "r");
224 //error_og("did file_get_contents on $url");
226 foreach($http_response_header as $key => $val) {
227 //error_log("got header of $key for $val");
228 if(preg_match("/.*HTTP\/.*200.*/", $val)) {
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">