3 // if i believed in name spacing in php, i'd use it.
4 error_log("glcasweb loaded");
8 function __construct($config)
10 $this->config = $config;
13 function go($urlhandlers)
16 if(isset($_REQUEST["q"])) {
17 $url = $_REQUEST["q"];
20 // create a url parser
21 $urlparser = new GLCASUrlParser($urlhandlers, $this->config);
24 $call_class = $urlparser->getClass($url);
25 error_log("urldecode: ".urldecode($url));
26 $call_class->go($url);
33 function GLCASMenuBuilder()
35 global $BASE_URL, $MENU_ITEMS;
39 <table border="1"><tr><th>Menu</th><td>
40 <a href="<?php echo $BASE_URL ?>">Home</a></td>
42 foreach($MENU_ITEMS as $key => $val) {
45 echo "<td><a href=$link>$name</a></td>";
51 function GLCASMessageBuilder()
53 echo "<i>Messages not implemented yet</i>";
56 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="GLCAS")
58 global $WEB_ROOT_FS, $BASE_URL;
62 echo "<html><head><title>$title</title>";
65 if(file_exists("$WEB_ROOT_FS/css")) {
66 $dh = opendir("$WEB_ROOT_FS/css");
68 while(($file = readdir($dh))!==false) {
69 $mt = preg_match("/.*.css$/", $file);
71 error_log("loading css $file");
72 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
73 //echo "required $basedir/$file\n";
80 if(file_exists("$WEB_ROOT_FS/js")) {
81 $dh = opendir("$WEB_ROOT_FS/js");
83 while(($file = readdir($dh))!==false) {
84 $mt = preg_match("/.*.js$/", $file);
86 error_log("loading js $file");
87 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
88 //echo "required $basedir/$file\n";
99 echo "<h1>GLCAS</h1><br>";
100 echo "<table><tr><td>";
101 GLCASMessageBuilder();
102 echo "<td></tr><tr><td>";
105 echo "<table><tr><td>";
107 echo "</td></tr><tr><td>";
110 if(isset($_REQUEST["q"])) {
111 $url = $_REQUEST["q"];
114 if($bodyClass != null) {
115 $bodyClass->$bodyFunction($url);
116 } else if( $bodyFunction != null) {
118 } else echo $bodycontent;
119 echo "</td></tr></table>";
122 // close the big wrap-around table
123 echo "</td></tr></table>";
126 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
130 function glcas_isRemoteDir($url)
132 file_get_contents($url);
133 //error_log("did file_get_contents on $url");
134 foreach($http_response_header as $key => $val) {
135 //error_log("got header of $key for $val");
136 if(preg_match("/.*Location:.*/", $val)) {
137 //error_log("in details apt got location as $val from $url");
138 $realloc = preg_replace("/.*: /", "", $val);
139 $urlwithslash = $url."/";
140 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
141 if(strcasecmp($realloc,$urlwithslash)==0) {
142 //error_log("I believe $realloc is a directory redir for $url");
145 //error_log("I dont believe $realloc is a directory redir for $url");
152 function glcas_fileExists($url)
154 $fp = fopen($url, "r");
155 //error_og("did file_get_contents on $url");
157 foreach($http_response_header as $key => $val) {
158 //error_log("got header of $key for $val");
159 if(preg_match("/.*HTTP\/.*200.*/", $val)) {
169 function glcas_startInstaller()
171 global $WEB_ROOT_FS, $BASE_URL;
173 $uid = posix_geteuid();
174 $gid = posix_getegid();
175 $uid_a = posix_getpwuid($uid);
176 $uid = $uid_a["name"];
178 $gid_a = posix_getgrgid($gid);
179 $gid = $gid_a["name"];
180 error_log("user id is $uid, group id is $gid");
184 <h1>Welcome to GLCAS</h1>
185 Welcome to GLCAS, I cant find my configuration file so im assuming you installing me for the first time<br>
186 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
187 config, cause that will make life easier.<br><br>
188 However, if this is the first time you have run this app, then all is good with the world. All I need right
189 now is a place where i can store my config. I search the following directories for the location of my
190 configuration (webconfig)<br>
193 <li> <?php echo $WEB_ROOT_FS?>/var/glcas/
196 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
197 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
199 Now, tell me where you want me to create the webconfig file:<br>
201 <select name="installdir">
202 <option value="/var/run/glcas">/var/run/glcas</option>
203 <option value="/var/lib/glcas">/var/lib/glcas</option>
204 <option value="<?php echo $WEB_ROOT_FS?>/var/glcas/"><?php echo $WEB_ROOT_FS?>/var/glcas/</option>
206 <input type="submit" name="Go" value="Go">