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()
37 <a href="<?php echo $BASE_URL ?>">Home</a>
38 <a href="<?php echo $BASE_URL."/admin/"?>">Admin</a>
42 function GLCASMessageBuilder()
44 echo "<i>Messages not implemented yet</i>";
47 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="GLCAS")
49 global $WEB_ROOT_FS, $BASE_URL;
53 echo "<html><head><title>$title</title>";
56 if(file_exists("$WEB_ROOT_FS/css")) {
57 $dh = opendir("$WEB_ROOT_FS/css");
59 while(($file = readdir($dh))!==false) {
60 $mt = preg_match("/.*.css$/", $file);
62 error_log("loading css $file");
63 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
64 //echo "required $basedir/$file\n";
71 if(file_exists("$WEB_ROOT_FS/js")) {
72 $dh = opendir("$WEB_ROOT_FS/js");
74 while(($file = readdir($dh))!==false) {
75 $mt = preg_match("/.*.js$/", $file);
77 error_log("loading js $file");
78 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
79 //echo "required $basedir/$file\n";
90 echo "<h1>GLCAS</h1><br>";
91 echo "<table><tr><td>";
92 GLCASMessageBuilder();
93 echo "<td></tr><tr><td>";
96 echo "<table><tr><td>";
98 echo "</td></tr><tr><td>";
101 if(isset($_REQUEST["q"])) {
102 $url = $_REQUEST["q"];
105 if($bodyClass != null) {
106 $bodyClass->$bodyFunction($url);
107 } else if( $bodyFunction != null) {
109 } else echo $bodycontent;
110 echo "</td></tr></table>";
113 // close the big wrap-around table
114 echo "</td></tr></table>";
117 echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
121 function glcas_isRemoteDir($url)
123 file_get_contents($url);
124 //error_log("did file_get_contents on $url");
125 foreach($http_response_header as $key => $val) {
126 //error_log("got header of $key for $val");
127 if(preg_match("/.*Location:.*/", $val)) {
128 //error_log("in details apt got location as $val from $url");
129 $realloc = preg_replace("/.*: /", "", $val);
130 $urlwithslash = $url."/";
131 //echo "<br>in comp with<br>$urlwithslash<br>$realloc<br>";
132 if(strcasecmp($realloc,$urlwithslash)==0) {
133 //error_log("I believe $realloc is a directory redir for $url");
136 //error_log("I dont believe $realloc is a directory redir for $url");
143 function glcas_startInstaller()
145 global $WEB_ROOT_FS, $BASE_URL;
147 $uid = posix_geteuid();
148 $gid = posix_getegid();
149 $uid_a = posix_getpwuid($uid);
150 $uid = $uid_a["name"];
152 $gid_a = posix_getgrgid($gid);
153 $gid = $gid_a["name"];
154 error_log("user id is $uid, group id is $gid");
158 <h1>Welcome to GLCAS</h1>
159 Welcome to GLCAS, I cant find my configuration file so im assuming you installing me for the first time<br>
160 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
161 config, cause that will make life easier.<br><br>
162 However, if this is the first time you have run this app, then all is good with the world. All I need right
163 now is a place where i can store my config. I search the following directories for the location of my
164 configuration (webconfig)<br>
167 <li> <?php echo $WEB_ROOT_FS?>/var/glcas/
170 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
171 (chown <?php echo $uid?>:<?php echo $gid ?> the_path_you_choose).<br>
173 Now, tell me where you want me to create the webconfig file:<br>
175 <select name="installdir">
176 <option value="/var/run/glcas">/var/run/glcas</option>
177 <option value="/var/lib/glcas">/var/lib/glcas</option>
178 <option value="<?php echo $WEB_ROOT_FS?>/var/glcas/"><?php echo $WEB_ROOT_FS?>/var/glcas/</option>
180 <input type="submit" name="Go" value="Go">