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->delData("lastseen", "$ipaddr");
27 $this->config->addData("lastseen", "$ipaddr", time(), "");
29 // create a url parser
30 $urlparser = new GLCASUrlParser($urlhandlers, $this->config);
33 $call_class = $urlparser->getClass($url);
34 error_log("urldecode: ".urldecode($url));
35 $call_class->go($url);
40 echo "WEB base running cron for ipseen roll-up<br>";
41 $lastseen = $this->config->getData("lastseen");
42 foreach($lastseen as $key=>$val) {
43 $myip = $val["category"];
48 foreach($ip as $key=>$val) {
49 echo "Setting last seen for $key to $val<br>";
50 $this->config->delData("lastseen", $key);
51 $this->config->addData("lastseen", $key, $val);
59 function GLCASMenuBuilder()
61 global $BASE_URL, $MENU_ITEMS;
65 <table border="1"><tr><th>Menu</th><td>
66 <a href="<?php echo $BASE_URL ?>">Home</a></td>
68 foreach($MENU_ITEMS as $key => $val) {
71 echo "<td><a href=$link>$name</a></td>";
77 function GLCASMessageBuilder()
79 echo "<i>Messages not implemented yet</i>";
82 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="GLCAS")
84 global $WEB_ROOT_FS, $BASE_URL;
88 echo "<html><head><title>$title</title>";
91 if(file_exists("$WEB_ROOT_FS/css")) {
92 $dh = opendir("$WEB_ROOT_FS/css");
94 while(($file = readdir($dh))!==false) {
95 $mt = preg_match("/.*.css$/", $file);
97 error_log("loading css $file");
98 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
99 //echo "required $basedir/$file\n";
106 if(file_exists("$WEB_ROOT_FS/js")) {
107 $dh = opendir("$WEB_ROOT_FS/js");
109 while(($file = readdir($dh))!==false) {
110 $mt = preg_match("/.*.js$/", $file);
112 error_log("loading js $file");
113 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
114 //echo "required $basedir/$file\n";
122 echo "</head><body>";
125 echo "<h1>GLCAS</h1><br>";
126 echo "<table><tr><td>";
127 GLCASMessageBuilder();
128 echo "<td></tr><tr><td>";
131 echo "<table><tr><td>";
133 echo "</td></tr><tr><td>";
136 if(isset($_REQUEST["q"])) {
137 $url = $_REQUEST["q"];
140 if($bodyClass != null) {
141 $bodyClass->$bodyFunction($url);
142 } else if( $bodyFunction != null) {
144 } else echo $bodycontent;
145 echo "</td></tr></table>";
148 // close the big wrap-around table
149 echo "</td></tr></table>";
152 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
156 function glcas_getLastSeen($ip, $data)
160 if(!$data) return $last;
164 foreach($data as $key=>$val) {
165 $last = $val["name"];
166 error_log("got $last for $ip");
169 if($last == "never") return $last;
171 $last = glcas_tdiffToAgo(time()-$last);
173 error_log("last for $ip set to $last");
179 function glcas_tdiffToAgo($time_in_sec)
181 $tdiff = $time_in_sec;
182 $tdiff_min = (int)($tdiff/60);
183 $tdiff_hour = (int)($tdiff/3600);
184 $tdiff_days = (int)($tdiff/86400);
186 if($tdiff < 60) $last = "Less then a minute";
187 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
188 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
189 if($tdiff >= 86400) $last = "$tdiff_days days ago";
194 function glcas_isRemoteDir($url)
196 file_get_contents($url);
197 //error_log("did file_get_contents on $url");
198 foreach($http_response_header as $key => $val) {
199 //error_log("got header of $key for $val");
200 if(preg_match("/.*Location:.*/", $val)) {
201 //error_log("in details apt got location as $val from $url");
202 $realloc = preg_replace("/.*: /", "", $val);
203 $urlwithslash = $url."/";
204 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
205 if(strcasecmp($realloc,$urlwithslash)==0) {
206 //error_log("I believe $realloc is a directory redir for $url");
209 //error_log("I dont believe $realloc is a directory redir for $url");
216 function glcas_fileExists($url)
218 $fp = fopen($url, "r");
219 //error_og("did file_get_contents on $url");
221 foreach($http_response_header as $key => $val) {
222 //error_log("got header of $key for $val");
223 if(preg_match("/.*HTTP\/.*200.*/", $val)) {
233 function glcas_startInstaller()
235 global $WEB_ROOT_FS, $BASE_URL;
237 $uid = posix_geteuid();
238 $gid = posix_getegid();
239 $uid_a = posix_getpwuid($uid);
240 $uid = $uid_a["name"];
242 $gid_a = posix_getgrgid($gid);
243 $gid = $gid_a["name"];
244 error_log("user id is $uid, group id is $gid");
246 if(isset($_REQUEST["installdir"])) {
247 $c = new GLCASConfig();
248 touch($_REQUEST["installdir"]."/webconfig");
249 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
250 header("Location: index.php");
254 $underroot = realpath($WEB_ROOT_FS."/../");
258 <h1>Welcome to GLCAS</h1>
259 Welcome to GLCAS, I cant find my configuration file so im assuming you installing me for the first time<br>
260 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
261 config, cause that will make life easier.<br><br>
262 However, if this is the first time you have run this app, then all is good with the world. All I need right
263 now is a place where i can store my config. I search the following directories for the location of my
264 configuration (webconfig)<br>
267 <li> <?php echo $underroot?>/var/glcas/
270 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
271 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
273 Now, tell me where you want me to create the webconfig file:<br>
275 <select name="installdir">
276 <option value="/var/run/glcas">/var/run/glcas</option>
277 <option value="/var/lib/glcas">/var/lib/glcas</option>
278 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
280 <input type="submit" name="Go" value="Go">