3 // if i believed in name spacing in php, i'd use it.
4 error_log("glcasweb loaded");
7 $CRON_CLASSES["GLCASWeb"] = "GLCASWeb";
12 function __construct($config)
14 $this->config = $config;
17 function go($urlhandlers)
20 if(isset($_REQUEST["q"])) {
21 $url = $_REQUEST["q"];
25 $ipaddr = $_SERVER["REMOTE_ADDR"];
26 $this->config->addData("lastseen", "$ipaddr", time(), "");
28 // create a url parser
29 $urlparser = new GLCASUrlParser($urlhandlers, $this->config);
32 $call_class = $urlparser->getClass($url);
33 error_log("urldecode: ".urldecode($url));
34 $call_class->go($url);
39 echo "WEB base running cron for ipseen roll-up<br>";
40 $lastseen = $this->config->getData("lastseen");
41 foreach($lastseen as $key=>$val) {
42 $myip = $val["category"];
47 foreach($ip as $key=>$val) {
48 echo "Setting last seen for $key to $val<br>";
49 $this->config->delData("lastseen", $key);
50 $this->config->addData("lastseen", $key, $val);
58 function GLCASMenuBuilder()
60 global $BASE_URL, $MENU_ITEMS;
64 <table border="1"><tr><th>Menu</th><td>
65 <a href="<?php echo $BASE_URL ?>">Home</a></td>
67 foreach($MENU_ITEMS as $key => $val) {
70 echo "<td><a href=$link>$name</a></td>";
76 function GLCASMessageBuilder()
78 echo "<i>Messages not implemented yet</i>";
81 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="GLCAS")
83 global $WEB_ROOT_FS, $BASE_URL;
87 echo "<html><head><title>$title</title>";
90 if(file_exists("$WEB_ROOT_FS/css")) {
91 $dh = opendir("$WEB_ROOT_FS/css");
93 while(($file = readdir($dh))!==false) {
94 $mt = preg_match("/.*.css$/", $file);
96 error_log("loading css $file");
97 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
98 //echo "required $basedir/$file\n";
105 if(file_exists("$WEB_ROOT_FS/js")) {
106 $dh = opendir("$WEB_ROOT_FS/js");
108 while(($file = readdir($dh))!==false) {
109 $mt = preg_match("/.*.js$/", $file);
111 error_log("loading js $file");
112 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
113 //echo "required $basedir/$file\n";
121 echo "</head><body>";
124 echo "<h1>GLCAS</h1><br>";
125 echo "<table><tr><td>";
126 GLCASMessageBuilder();
127 echo "<td></tr><tr><td>";
130 echo "<table><tr><td>";
132 echo "</td></tr><tr><td>";
135 if(isset($_REQUEST["q"])) {
136 $url = $_REQUEST["q"];
139 if($bodyClass != null) {
140 $bodyClass->$bodyFunction($url);
141 } else if( $bodyFunction != null) {
143 } else echo $bodycontent;
144 echo "</td></tr></table>";
147 // close the big wrap-around table
148 echo "</td></tr></table>";
151 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
155 function glcas_getLastSeen($ip, $data)
159 if(!$data) return $last;
163 foreach($data as $key=>$val) {
164 $last = $val["name"];
165 error_log("got $last for $ip");
168 if($last == "never") return $last;
170 $last = glcas_tdiffToAgo(time()-$last);
172 error_log("last for $ip set to $last");
178 function glcas_tdiffToAgo($time_in_sec)
180 $tdiff = $time_in_sec;
181 $tdiff_min = (int)($tdiff/60);
182 $tdiff_hour = (int)($tdiff/3600);
183 $tdiff_days = (int)($tdiff/86400);
185 if($tdiff < 60) $last = "Less then a minute";
186 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
187 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
188 if($tdiff >= 86400) $last = "$tdiff_days days ago";
193 function glcas_isRemoteDir($url)
195 file_get_contents($url);
196 //error_log("did file_get_contents on $url");
197 foreach($http_response_header as $key => $val) {
198 //error_log("got header of $key for $val");
199 if(preg_match("/.*Location:.*/", $val)) {
200 //error_log("in details apt got location as $val from $url");
201 $realloc = preg_replace("/.*: /", "", $val);
202 $urlwithslash = $url."/";
203 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
204 if(strcasecmp($realloc,$urlwithslash)==0) {
205 //error_log("I believe $realloc is a directory redir for $url");
208 //error_log("I dont believe $realloc is a directory redir for $url");
215 function glcas_fileExists($url)
217 $fp = fopen($url, "r");
218 //error_og("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("/.*HTTP\/.*200.*/", $val)) {
232 function glcas_startInstaller()
234 global $WEB_ROOT_FS, $BASE_URL;
236 $uid = posix_geteuid();
237 $gid = posix_getegid();
238 $uid_a = posix_getpwuid($uid);
239 $uid = $uid_a["name"];
241 $gid_a = posix_getgrgid($gid);
242 $gid = $gid_a["name"];
243 error_log("user id is $uid, group id is $gid");
245 if(isset($_REQUEST["installdir"])) {
246 $c = new GLCASConfig();
247 touch($_REQUEST["installdir"]."/webconfig");
248 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
249 header("Location: index.php");
253 $underroot = realpath($WEB_ROOT_FS."/../");
257 <h1>Welcome to GLCAS</h1>
258 Welcome to GLCAS, I cant find my configuration file so im assuming you installing me for the first time<br>
259 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
260 config, cause that will make life easier.<br><br>
261 However, if this is the first time you have run this app, then all is good with the world. All I need right
262 now is a place where i can store my config. I search the following directories for the location of my
263 configuration (webconfig)<br>
266 <li> <?php echo $underroot?>/var/glcas/
269 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
270 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
272 Now, tell me where you want me to create the webconfig file:<br>
274 <select name="installdir">
275 <option value="/var/run/glcas">/var/run/glcas</option>
276 <option value="/var/lib/glcas">/var/lib/glcas</option>
277 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
279 <input type="submit" name="Go" value="Go">