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";
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 $bodyFunction = "CBFWZonesPage";
36 $bodyFunction = "CBFWInterfacesPage";
39 $bodyFunction = "CBFWObjectsPage";
42 $bodyFunction = "CBFWRulesPage";
45 $bodyFunction = findUrl($url_s);
48 $bodyFunction = "CBFBuildHomePage";
50 CBFWpageBuilder(null, $bodyFunction);
54 function CBFBuildHomePage($urls)
56 echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
57 echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum";
62 print_r($conf->getConfig());
64 print_r($conf->getBootConfig());
69 function CBFWMenuBuilder()
71 global $BASE_URL, $MENU_ITEMS;
75 <table border="1"><tr><th>Menu</th><td>
76 <a href="<?php echo $BASE_URL ?>">Home</a></td>
78 foreach($MENU_ITEMS as $key => $val) {
81 echo "<td><a href=$link>$name</a></td>";
87 // just a short one to call the long one
91 CBFWAddMessage($m, $s);
94 function CBFWAddMessage($messagelev, $message)
99 function CBFWMessageBuilder()
104 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW")
106 global $WEB_ROOT_FS, $BASE_URL;
110 echo "<html><head><title>$title</title>";
113 if(file_exists("$WEB_ROOT_FS/css")) {
114 $dh = opendir("$WEB_ROOT_FS/css");
116 while(($file = readdir($dh))!==false) {
117 $mt = preg_match("/.*.css$/", $file);
119 error_log("loading css $file");
120 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
121 //echo "required $basedir/$file\n";
128 if(file_exists("$WEB_ROOT_FS/js")) {
129 $dh = opendir("$WEB_ROOT_FS/js");
131 while(($file = readdir($dh))!==false) {
132 $mt = preg_match("/.*.js$/", $file);
134 error_log("loading js $file");
135 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
136 //echo "required $basedir/$file\n";
144 echo "</head><body>";
147 echo "<h1>CBFW</h1><br>";
148 echo "<table><tr><td>";
149 CBFWMessageBuilder();
150 echo "<td></tr><tr><td>";
153 echo "<table><tr><td>";
155 echo "</td></tr><tr><td>";
158 if(isset($_REQUEST["q"])) {
159 $url = $_REQUEST["q"];
162 if($bodyClass != null) {
163 $bodyClass->$bodyFunction($url);
164 } else if( $bodyFunction != null) {
166 } else echo $bodycontent;
167 echo "</td></tr></table>";
170 // close the big wrap-around table
171 echo "</td></tr></table>";
174 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
178 function cbfw_getLastSeen($ip, $data)
182 if(!$data) return $last;
186 foreach($data as $key=>$val) {
187 $last = $val["name"];
188 error_log("got $last for $ip");
191 if($last == "never") return $last;
193 $last = cbfw_tdiffToAgo(time()-$last);
195 error_log("last for $ip set to $last");
201 function cbfw_tdiffToAgo($time_in_sec)
203 $tdiff = $time_in_sec;
204 $tdiff_min = (int)($tdiff/60);
205 $tdiff_hour = (int)($tdiff/3600);
206 $tdiff_days = (int)($tdiff/86400);
208 if($tdiff < 60) $last = "Less then a minute";
209 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
210 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
211 if($tdiff >= 86400) $last = "$tdiff_days days ago";
216 function cbfw_isRemoteDir($url)
218 file_get_contents($url);
219 //error_log("did file_get_contents on $url");
220 foreach($http_response_header as $key => $val) {
221 //error_log("got header of $key for $val");
222 if(preg_match("/.*Location:.*/", $val)) {
223 //error_log("in details apt got location as $val from $url");
224 $realloc = preg_replace("/.*: /", "", $val);
225 $urlwithslash = $url."/";
226 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
227 if(strcasecmp($realloc,$urlwithslash)==0) {
228 //error_log("I believe $realloc is a directory redir for $url");
231 //error_log("I dont believe $realloc is a directory redir for $url");
238 function cbfw_fileExists($url)
240 $fp = fopen($url, "r");
241 //error_og("did file_get_contents on $url");
243 foreach($http_response_header as $key => $val) {
244 //error_log("got header of $key for $val");
245 if(preg_match("/.*HTTP\/.*200.*/", $val)) {
255 function cbfw_startInstaller()
257 global $WEB_ROOT_FS, $BASE_URL;
259 $uid = posix_geteuid();
260 $gid = posix_getegid();
261 $uid_a = posix_getpwuid($uid);
262 $uid = $uid_a["name"];
264 $gid_a = posix_getgrgid($gid);
265 $gid = $gid_a["name"];
266 error_log("user id is $uid, group id is $gid");
268 if(isset($_REQUEST["installdir"])) {
269 $c = new CBFWConfig();
270 touch($_REQUEST["installdir"]."/webconfig");
271 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
272 header("Location: index.php");
276 $underroot = realpath($WEB_ROOT_FS."/../");
280 <h1>Welcome to CBFW</h1>
281 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
282 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
283 config, cause that will make life easier.<br><br>
284 However, if this is the first time you have run this app, then all is good with the world. All I need right
285 now is a place where i can store my config. I search the following directories for the location of my
286 configuration (webconfig)<br>
289 <li> <?php echo $underroot?>/var/glcas/
292 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
293 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
295 Now, tell me where you want me to create the webconfig file:<br>
297 <select name="installdir">
298 <option value="/var/run/glcas">/var/run/glcas</option>
299 <option value="/var/lib/glcas">/var/lib/glcas</option>
300 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
302 <input type="submit" name="Go" value="Go">