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()
28 $rconfig = $conf->getConfig();
30 if($rconfig["status"] != "conf") cbfw_startinstaller();
33 if(isset($_REQUEST["q"])) {
34 $url = $_REQUEST["q"];
36 // ok, now we try and find the basics
37 $url_s = explode("/", $url);
41 $bodyFunction = "CBFWZonesPage";
44 $bodyFunction = "CBFWInterfacesPage";
47 $bodyFunction = "CBFWObjectsPage";
50 $bodyFunction = "CBFWRulesPage";
53 $bodyFunction = findUrl($url_s);
56 $bodyFunction = "CBFBuildHomePage";
58 CBFWpageBuilder(null, $bodyFunction);
62 function CBFBuildHomePage($urls)
64 echo "Must remember this, gotta rules could apply to multiple zones not just one<br>";
65 echo "i.e.: add rule reject from object/host/hostname to address6/2003::123 in zones Zone/zonename/rulenum Zone/zonename/rulenum";
70 print_r($conf->getConfig());
72 print_r($conf->getBootConfig());
77 function CBFWMenuBuilder()
79 global $BASE_URL, $MENU_ITEMS;
83 <table border="1"><tr><th>Menu</th><td>
84 <a href="<?php echo $BASE_URL ?>">Home</a></td>
86 foreach($MENU_ITEMS as $key => $val) {
89 echo "<td><a href=$link>$name</a></td>";
95 // just a short one to call the long one
99 CBFWAddMessage($m, $s);
102 function CBFWAddMessage($messagelev, $message)
107 function CBFWMessageBuilder()
112 function CBFWpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="CBFW")
114 global $WEB_ROOT_FS, $BASE_URL;
118 echo "<html><head><title>$title</title>";
121 if(file_exists("$WEB_ROOT_FS/css")) {
122 $dh = opendir("$WEB_ROOT_FS/css");
124 while(($file = readdir($dh))!==false) {
125 $mt = preg_match("/.*.css$/", $file);
127 error_log("loading css $file");
128 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
129 //echo "required $basedir/$file\n";
136 if(file_exists("$WEB_ROOT_FS/js")) {
137 $dh = opendir("$WEB_ROOT_FS/js");
139 while(($file = readdir($dh))!==false) {
140 $mt = preg_match("/.*.js$/", $file);
142 error_log("loading js $file");
143 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
144 //echo "required $basedir/$file\n";
152 echo "</head><body>";
155 echo "<h1>CBFW</h1><br>";
156 echo "<table><tr><td>";
157 CBFWMessageBuilder();
158 echo "<td></tr><tr><td>";
161 echo "<table><tr><td>";
163 echo "</td></tr><tr><td>";
166 if(isset($_REQUEST["q"])) {
167 $url = $_REQUEST["q"];
170 if($bodyClass != null) {
171 $bodyClass->$bodyFunction($url);
172 } else if( $bodyFunction != null) {
174 } else echo $bodycontent;
175 echo "</td></tr></table>";
178 // close the big wrap-around table
179 echo "</td></tr></table>";
182 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
186 function cbfw_getLastSeen($ip, $data)
190 if(!$data) return $last;
194 foreach($data as $key=>$val) {
195 $last = $val["name"];
196 error_log("got $last for $ip");
199 if($last == "never") return $last;
201 $last = cbfw_tdiffToAgo(time()-$last);
203 error_log("last for $ip set to $last");
209 function cbfw_tdiffToAgo($time_in_sec)
211 $tdiff = $time_in_sec;
212 $tdiff_min = (int)($tdiff/60);
213 $tdiff_hour = (int)($tdiff/3600);
214 $tdiff_days = (int)($tdiff/86400);
216 if($tdiff < 60) $last = "Less then a minute";
217 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
218 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
219 if($tdiff >= 86400) $last = "$tdiff_days days ago";
224 function cbfw_startInstaller()
226 global $WEB_ROOT_FS, $BASE_URL;
228 $uid = posix_geteuid();
229 $gid = posix_getegid();
230 $uid_a = posix_getpwuid($uid);
231 $uid = $uid_a["name"];
233 $gid_a = posix_getgrgid($gid);
234 $gid = $gid_a["name"];
235 error_log("user id is $uid, group id is $gid");
237 if(isset($_REQUEST["installdir"])) {
238 $c = new CBFWConfig();
239 touch($_REQUEST["installdir"]."/webconfig");
240 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
241 header("Location: index.php");
245 $underroot = realpath($WEB_ROOT_FS."/../");
249 <h1>Welcome to CBFW</h1>
250 Welcome to CBFW, I cant find my configuration file so im assuming you installing me for the first time<br>
251 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
252 config, cause that will make life easier.<br><br>
253 However, if this is the first time you have run this app, then all is good with the world. All I need right
254 now is a place where i can store my config. I search the following directories for the location of my
255 configuration (webconfig)<br>
258 <li> <?php echo $underroot?>/var/glcas/
261 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
262 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
264 Now, tell me where you want me to create the webconfig file:<br>
266 <select name="installdir">
267 <option value="/var/run/glcas">/var/run/glcas</option>
268 <option value="/var/lib/glcas">/var/lib/glcas</option>
269 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
271 <input type="submit" name="Go" value="Go">