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 $tdiff = time()-$last;
171 $tdiff_min = (int)($tdiff/60);
172 $tdiff_hour = (int)($tdiff/3600);
173 $tdiff_days = (int)($tdiff/86400);
175 if($tdiff < 60) $last = "Less then a minute";
176 if($tdiff >= 60 && $tdiff < 7200) $last = "$tdiff_min minutes ago";
177 if($tdiff >= 7200 && $tdiff < 86400) $last = "$tdiff_hour hours ago";
178 if($tdiff >= 86400) $last = "$tdiff_days days ago";
180 error_log("last for $ip set to $last");
186 function glcas_isRemoteDir($url)
188 file_get_contents($url);
189 //error_log("did file_get_contents on $url");
190 foreach($http_response_header as $key => $val) {
191 //error_log("got header of $key for $val");
192 if(preg_match("/.*Location:.*/", $val)) {
193 //error_log("in details apt got location as $val from $url");
194 $realloc = preg_replace("/.*: /", "", $val);
195 $urlwithslash = $url."/";
196 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
197 if(strcasecmp($realloc,$urlwithslash)==0) {
198 //error_log("I believe $realloc is a directory redir for $url");
201 //error_log("I dont believe $realloc is a directory redir for $url");
208 function glcas_fileExists($url)
210 $fp = fopen($url, "r");
211 //error_og("did file_get_contents on $url");
213 foreach($http_response_header as $key => $val) {
214 //error_log("got header of $key for $val");
215 if(preg_match("/.*HTTP\/.*200.*/", $val)) {
225 function glcas_startInstaller()
227 global $WEB_ROOT_FS, $BASE_URL;
229 $uid = posix_geteuid();
230 $gid = posix_getegid();
231 $uid_a = posix_getpwuid($uid);
232 $uid = $uid_a["name"];
234 $gid_a = posix_getgrgid($gid);
235 $gid = $gid_a["name"];
236 error_log("user id is $uid, group id is $gid");
238 if(isset($_REQUEST["installdir"])) {
239 $c = new GLCASConfig();
240 touch($_REQUEST["installdir"]."/webconfig");
241 $c->loadConfig($_REQUEST["installdir"]."/webconfig");
242 header("Location: index.php");
246 $underroot = realpath($WEB_ROOT_FS."/../");
250 <h1>Welcome to GLCAS</h1>
251 Welcome to GLCAS, I cant find my configuration file so im assuming you installing me for the first time<br>
252 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
253 config, cause that will make life easier.<br><br>
254 However, if this is the first time you have run this app, then all is good with the world. All I need right
255 now is a place where i can store my config. I search the following directories for the location of my
256 configuration (webconfig)<br>
259 <li> <?php echo $underroot?>/var/glcas/
262 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
263 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
265 Now, tell me where you want me to create the webconfig file:<br>
267 <select name="installdir">
268 <option value="/var/run/glcas">/var/run/glcas</option>
269 <option value="/var/lib/glcas">/var/lib/glcas</option>
270 <option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
272 <input type="submit" name="Go" value="Go">