3 error_log("admin loaded");
6 $URL_HANDLERS["admin.*"] = "GLCASAdmin";
8 $CRON_CLASSES["GLCASAdmin"] = "GLCASAdmin";
11 function __construct($config)
13 $this->config = $config;
14 error_log("constructor for GLCASAdmin");
20 error_log("repo:go called");
22 if(isset($_REQUEST["action"])) {
23 switch($_REQUEST["action"]) {
25 error_log("in updaterepo");
26 GLCASpageBuilder($this,"doUpdateRepo");
29 error_log("in reponext");
30 GLCASpageBuilder($this,"doRepoNextForm");
34 GLCASpageBuilder($this,"doAddRepoApt");
37 GLCASpageBuilder($this,"doAddRepoYum");
40 error_log("call delete repo");
41 GLCASpageBuilder($this, "doRemoveRepo");
44 error_log("call setstorage");
45 GLCASpageBuilder($this, "setStorage");
51 GLCASpageBuilder($this, "body");
56 echo "ADMIN CRON: nothing to see here<br>";
57 // TODO: touch cronstamp file here
59 // make a backup of the config.. but.. errr. how to tell if theres an old backup?
60 // backups will occur... weekly and be called $configpath.DDMMYYYY
61 $configpath = glcas_getWebConfigPath();
62 $basepath = dirname($configpath);
63 echo "ADMIN CRON: backing up config, $configpath, $basepath<br>";
65 $oneday = 3600 * 24; // 1 hour in seconds, by 24 hours
66 for($i = 0; $i < 7; $i ++) {
67 $cdatestr = strftime("%d-%h-%Y", $nowtime - ($oneday*$i));
68 $backupfile = "$configpath.$cdatestr";
69 error_log("checking for backup of config as $backupfile");
70 if(file_exists($backupfile)) {
71 error_log("backupconfig exists as $backupfile, exit");
72 echo "ADMIN CRON: backup of config is $backupfile, created $i days ago, not creating new one<br>";
76 $nowdatestr = strftime("%d-%h-%Y");
77 $backupfile = "$configpath.$nowdatestr";
78 copy($configpath, $backupfile);
79 echo "ADMIN CRON: createing backup of config as $backupfile<br>";
84 // for the main admin body, we hae the following components
86 // 1. list of currently available repos and stuff
88 // 2. way to add a repo direct
90 // 3. way to scan for a repo given a url
92 // so first, lets do the main body
93 $this->mainBody($url);
96 function doRemoveRepo($url)
98 $repo = $_REQUEST["repo"];
99 $myRep = new GLCASRepo($this->config);
102 error_log("called delete repo on $repo");
103 $myRep->deleteRepo($repo);
105 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
106 header("Location: $BASE_URL/admin/");
110 function setStorage($url)
115 function doRepoNextForm($url)
117 $myRep = new GLCASRepo($this->config);
119 $kos = getKnownOSList();
123 if($_REQUEST["repotype"] == "yumbase") {
124 $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
126 } else if($_REQUEST["repotype"] == "yummirrorlist") {
127 $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"], true);
129 } else if($_REQUEST["repotype"] == "apt") {
130 $glt = $myRep->getRepoDetailsApt($_REQUEST["repourl"]);
135 error_log("in wasapt");
136 $repourl = $_REQUEST["repourl"];
139 echo "Could not find any apt repository at $repourl<br>";
145 if($glt["nrepos"] > 0) {
147 foreach($glt["knownrepo"] as $key => $val) {
148 $reponame = $kos["apt"][$val];
149 //echo "Fount a repo, $val which is $reponame<br>";
150 $provides .= "$reponame\n";
152 $extratext = " for ".$glt["distros"];
154 //echo "Looks like an apt repo, but I cant find any known distro's<br>";
156 //$existing_repos["distros"] = "Ubuntu, Debian";
157 //$existing_repos["versions"] = "8.04LTS, 9.10, 10.04LTS, 10.10, 11.04, 11.10";
158 //$existing_repos["arch"] = "x86_64, i386";
161 $distros = $glt["distros"];
162 $version = $glt["versions"];
163 $archs = $glt["arch"];
169 echo "<form method=\"post\" action=\"?action=addrepoapt\">";
170 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
171 echo "<input type=\"hidden\" name=\"distro\" value=\"$distros\">";
172 echo "<input type=\"hidden\" name=\"arch\" value=\"$archs\">";
174 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"APT Repo$extratext\"></td>";
175 // TODO change this "provides" bit with a bit that allows us to choose which versions
176 // of ubuntu will be made available from the ones we found
177 echo "<tr><td>Provides (tick those you wish to BLOCK)</td><td>";
178 foreach($glt["knownrepo"] as $key => $val) {
179 $reponame = $kos["apt"][$val["name"]];
182 if($glt["knownrepo"][$key]["i386"]) $a = "i386";
183 if($glt["knownrepo"][$key]["amd64"]) $b = "x86_64";
184 if($a != "" && $b != "") $archs = "$a/$b";
185 else $archs = "$a$b";
186 echo "<input type=\"checkbox\" name=\"$val\"> $reponame ($archs)<br>";
190 //echo "<tr><td>Provides</td><td><textarea name=\"provides\" rows=\"".$glt["nrepos"]."\" cols=\"100\">$provides</textarea></td></tr>";
191 echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
192 echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
193 echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
194 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
202 $version = $glt["version"];
203 $arch = $glt["arch"];
204 $other = $glt["other"];
205 $repourl = $_REQUEST["repourl"];
206 echo "<form method=\"post\" action=\"?action=addrepoyum\">";
207 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
209 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"$os, $version, $arch - $other\"></td></tr>";
210 echo "<tr><td>OS</td><td><input type=\"text\" name=\"OS\" value=\"$os\"></td></tr>";
211 echo "<tr><td>Version</td><td><input type=\"text\" name=\"version\" value=\"$version\"></td></tr>";
212 echo "<tr><td>Architecture</td><td><input type=\"text\" name=\"arch\" value=\"$arch\"></td></tr>";
213 echo "<tr><td>Other (OS, Updates, etc)</td><td><input type=\"text\" name=\"other\" value=\"$other\"></td></tr>";
214 echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
215 echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
216 echo "<tr><td>Do Initial Update (can take a while, but done in background)</td><td><input type=\"checkbox\" name=\"initial\" checked></td></tr>";
217 echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
218 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
224 function doAddRepoApt($url)
226 $repo = new GLCASRepo($this->config);
228 $desc = $_REQUEST["desc"];
229 $OS = $_REQUEST["distro"];
230 $version = $_REQUEST["provides"];
231 $arch = $_REQUEST["arch"];
232 $shorturl = $_REQUEST["shorturl"];
233 $prefix = $_REQUEST["prefix"];
234 $repurl = $_REQUEST["repourl"];
235 $expiretime = $REQUEST["expiretime"];
237 if(isset($_REQUEST["initial"])) $init = true;
241 $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime);
243 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
244 header("Location: $BASE_URL/admin/");
247 function doAddRepoYum($url)
249 $repo = new GLCASRepo($this->config);
251 $desc = $_REQUEST["desc"];
252 $OS = $_REQUEST["OS"];
253 $version = $_REQUEST["version"];
254 $arch = $_REQUEST["arch"];
255 $other = $_REQUEST["other"];
256 $shorturl = $_REQUEST["shorturl"];
257 $prefix = $_REQUEST["prefix"];
258 $repurl = $_REQUEST["repourl"];
259 $expiretime = $REQUEST["expiretime"];
261 if(isset($_REQUEST["initial"])) $init = true;
265 $repo->addRepo($desc, $OS, $version, $arch, $other, $shorturl, $prefix, $repurl, "YUM", $init, $expiretime);
267 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
268 header("Location: $BASE_URL/admin/");
271 function doUpdateRepo($url)
273 $rkey = $_REQUEST["repo"];
275 $repo = new GLCASRepo($this->config);
277 $repo->updateRepo($rkey);
278 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
279 header("Location: $BASE_URL/admin/");
282 function mainBody($url)
284 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
286 // first, list available repos
287 echo "<h3>Repositories</h3>";
288 echo "<br><table border=\"1\">";
289 echo "<tr><th>Name</th><th>Type</th><th>OS</th><th>Version</th><th>Architecture</th><th>Other</th><th>Prefix</th><th>Short URL</th><th>Browse</th><th>Control</th></tr>";
291 // now iterate thru the repos and print them
292 $repo = new GLCASRepo($this->config);
293 $repos = $repo->getRepos();
295 foreach($repos as $rkey => $rval) {
296 $desc = $rval["desc"];
298 $version = $rval["version"];
299 $arch = $rval["arch"];
300 $other = $rval["other"];
301 $repotype = $rval["repotype"];
302 $prefix = $rval["prefix"];
303 $shorturl = $rval["shorturl"];
304 if($prefix == "") $prefix = "-";
305 if($shorturl == "") $shorturl = "-";
306 echo "<tr><td>$desc</td><td>$repotype</td><td>$os</td><td>$version</td><td>$arch</td><td>$other</td><td>$prefix</td><td>$shorturl</td>";
309 $browseurl = "$BASE_URL/repo/$rkey";
312 if($prefix != "-") $brurl = "$prefix/$shorturl";
313 $browseurl = "$BASE_URL/$brurl/";
316 echo "<td><a href=\"$browseurl\">Browse</td><td>";
319 echo "<a href=\"?action=editrepo&repo=$rkey\">Edit</a> ";
321 echo "<a href=\"?action=updaterepo&repo=$rkey\">Update</a> ";
323 echo "<a href=\"?action=freezerepo&repo=$rkey\">Freeze</a> ";
325 echo "<a href=\"?action=disablerepo&repo=$rkey\">Disable</a> ";
327 echo "<a href=\"?action=cleanrepo&repo=$rkey\">Clean</a> ";
329 echo "<a href=\"?action=deleterepo&repo=$rkey\">Delete</a>";
335 echo "</table><br><hr>";
337 //if($repos !== false) print_r($repos);
340 // wrap all this in a table
341 echo "<table><tr><td valign=\"top\">";
343 echo "<h3>Add A Repo</h3>";
344 echo "<form method=\"post\" action=\"?action=reponext\">";
345 echo "Type <select name=\"repotype\">";
346 echo "<option value=\"yumbase\">YUM (Base URL)</option>";
347 echo "<option value=\"yummirrorlist\">YUM (Mirror List) - not implemented</option>";
348 echo "<option value=\"apt\">APT</option>";
349 echo "</select><br>";
350 echo "URL <input type=\"text\" name=\"repourl\"><br>";
351 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
354 echo "</td><td valign=\"top\">";
356 // now scan for a repo
357 echo "<h3>Scan For Repos - not implemented</h3>";
358 echo "<form method=\"post\" action=\"?action=scanrepo\">";
359 echo "Hint <select name=\"repohint\">";
360 echo "<option value=\"fedora\">Fedora</option>";
361 echo "<option value=\"centos\">Centos</option>";
362 echo "<option value=\"ubuntu\">Ubuntu</option>";
363 echo "</select><br>";
364 echo "URL <input type=\"text\" name=\"repourl\"><br>";
365 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
368 echo "</td></tr></table><hr>";
370 // repo storage location
371 echo "<h3>Storage<h3><br>";
372 echo "<form method=\"post\" action=\"?action=setstorage\">";
373 $storloc = $this->config->getConfigVar("storagelocation");
374 echo "<input type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
375 echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";