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");
48 error_log("call freezerepo");
49 GLCASpageBuilder($this, "freezeRepo");
55 GLCASpageBuilder($this, "body");
60 echo "ADMIN CRON: nothing to see here<br>";
61 // TODO: touch cronstamp file here
63 // make a backup of the config.. but.. errr. how to tell if theres an old backup?
64 // backups will occur... weekly and be called $configpath.DDMMYYYY
65 $configpath = glcas_getWebConfigPath();
66 $basepath = dirname($configpath);
67 echo "ADMIN CRON: backing up config, $configpath, $basepath<br>";
69 $oneday = 3600 * 24; // 1 hour in seconds, by 24 hours
70 for($i = 0; $i < 7; $i ++) {
71 $cdatestr = strftime("%d-%h-%Y", $nowtime - ($oneday*$i));
72 $backupfile = "$configpath.$cdatestr";
73 error_log("checking for backup of config as $backupfile");
74 if(file_exists($backupfile)) {
75 error_log("backupconfig exists as $backupfile, exit");
76 echo "ADMIN CRON: backup of config is $backupfile, created $i days ago, not creating new one<br>";
80 $nowdatestr = strftime("%d-%h-%Y");
81 $backupfile = "$configpath.$nowdatestr";
82 copy($configpath, $backupfile);
83 echo "ADMIN CRON: createing backup of config as $backupfile<br>";
88 // for the main admin body, we hae the following components
90 // 1. list of currently available repos and stuff
92 // 2. way to add a repo direct
94 // 3. way to scan for a repo given a url
96 // so first, lets do the main body
97 $this->mainBody($url);
100 function freezeRepo($url)
102 $repo = $_REQUEST["repo"];
105 $myRep = new GLCASRepo($this->config);
108 error_log("called freeze repo on $repo");
109 $myRep->freezeRepo($repo);
111 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
112 header("Location: $BASE_URL/admin/");
116 function doRemoveRepo($url)
118 $repo = $_REQUEST["repo"];
119 $myRep = new GLCASRepo($this->config);
122 error_log("called delete repo on $repo");
123 $myRep->deleteRepo($repo);
125 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
126 header("Location: $BASE_URL/admin/");
130 function setStorage($url)
135 function doRepoNextForm($url)
137 $myRep = new GLCASRepo($this->config);
139 $kos = getKnownOSList();
143 if($_REQUEST["repotype"] == "yumbase") {
144 $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
146 } else if($_REQUEST["repotype"] == "yummirrorlist") {
147 $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"], true);
149 } else if($_REQUEST["repotype"] == "apt") {
150 $glt = $myRep->getRepoDetailsApt($_REQUEST["repourl"]);
155 error_log("in wasapt");
156 $repourl = $_REQUEST["repourl"];
159 echo "Could not find any apt repository at $repourl<br>";
165 if($glt["nrepos"] > 0) {
167 foreach($glt["knownrepo"] as $key => $val) {
168 $reponame = $kos["apt"][$val];
169 //echo "Fount a repo, $val which is $reponame<br>";
170 $provides .= "$reponame\n";
172 $extratext = " for ".$glt["distros"];
174 //echo "Looks like an apt repo, but I cant find any known distro's<br>";
176 //$existing_repos["distros"] = "Ubuntu, Debian";
177 //$existing_repos["versions"] = "8.04LTS, 9.10, 10.04LTS, 10.10, 11.04, 11.10";
178 //$existing_repos["arch"] = "x86_64, i386";
181 $distros = $glt["distros"];
182 $version = $glt["versions"];
183 $archs = $glt["arch"];
189 echo "The joy of apt is that there could be a million distro's under the root of an apt mirror";
190 echo "if it doesn't list here, but you know its there, its still usable for glcas";
191 echo "<form method=\"post\" action=\"?action=addrepoapt\">";
192 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
193 echo "<input type=\"hidden\" name=\"distro\" value=\"$distros\">";
194 echo "<input type=\"hidden\" name=\"provides\" value=\"Multiple\">";
195 echo "<input type=\"hidden\" name=\"arch\" value=\"$archs\">";
197 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"APT Repo$extratext\"></td>";
199 // TODO: deal with block bit
200 echo "<tr><td>Provides (tick those you wish to BLOCK - not implemented)</td><td>";
201 foreach($glt["knownrepo"] as $key => $val) {
202 $reponame = $kos["apt"][$val["name"]];
205 if($glt["knownrepo"][$key]["i386"]) $a = "i386";
206 if($glt["knownrepo"][$key]["amd64"]) $b = "x86_64";
207 if($a != "" && $b != "") $archs = "$a/$b";
208 else $archs = "$a$b";
209 echo "<input type=\"checkbox\" name=\"blocked-".$val["name"]."\"> $reponame ($archs)<br>";
213 //echo "<tr><td>Provides</td><td><textarea name=\"provides\" rows=\"".$glt["nrepos"]."\" cols=\"100\">$provides</textarea></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>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
217 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
225 $version = $glt["version"];
226 $arch = $glt["arch"];
227 $other = $glt["other"];
228 $repourl = $_REQUEST["repourl"];
229 echo "<form method=\"post\" action=\"?action=addrepoyum\">";
230 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
232 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"$os, $version, $arch - $other\"></td></tr>";
233 echo "<tr><td>OS</td><td><input type=\"text\" name=\"OS\" value=\"$os\"></td></tr>";
234 echo "<tr><td>Version</td><td><input type=\"text\" name=\"version\" value=\"$version\"></td></tr>";
235 echo "<tr><td>Architecture</td><td><input type=\"text\" name=\"arch\" value=\"$arch\"></td></tr>";
236 echo "<tr><td>Other (OS, Updates, etc)</td><td><input type=\"text\" name=\"other\" value=\"$other\"></td></tr>";
237 echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
238 echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
239 echo "<tr><td>Do Initial Update (can take a while, but done in background)</td><td><input type=\"checkbox\" name=\"initial\" checked></td></tr>";
240 echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
241 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
247 function doAddRepoApt($url)
249 $repo = new GLCASRepo($this->config);
251 $desc = $_REQUEST["desc"];
252 $OS = $_REQUEST["distro"];
253 $version = $_REQUEST["provides"];
254 $arch = $_REQUEST["arch"];
255 $shorturl = $_REQUEST["shorturl"];
256 $prefix = $_REQUEST["prefix"];
257 $repurl = $_REQUEST["repourl"];
258 $expiretime = $REQUEST["expiretime"];
260 if(isset($_REQUEST["initial"])) $init = true;
264 foreach($_REQUEST as $key => $val) {
265 if(preg_match("/^blocked-*/", $key)) {
266 $blocked = preg_replace("/^blocked-/", "", $key);
267 //echo "<br>got block for $blocked<br>";
268 $blocklist[$bn] = "dists\/$blocked.*";
274 //print_r($_REQUEST);
279 $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime, $blocklist);
281 // next we need to deal with that "blocked" bit
283 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
284 header("Location: $BASE_URL/admin/");
287 function doAddRepoYum($url)
289 $repo = new GLCASRepo($this->config);
291 $desc = $_REQUEST["desc"];
292 $OS = $_REQUEST["OS"];
293 $version = $_REQUEST["version"];
294 $arch = $_REQUEST["arch"];
295 $other = $_REQUEST["other"];
296 $shorturl = $_REQUEST["shorturl"];
297 $prefix = $_REQUEST["prefix"];
298 $repurl = $_REQUEST["repourl"];
299 $expiretime = $REQUEST["expiretime"];
301 if(isset($_REQUEST["initial"])) $init = true;
305 $repo->addRepo($desc, $OS, $version, $arch, $other, $shorturl, $prefix, $repurl, "YUM", $init, $expiretime);
307 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
308 header("Location: $BASE_URL/admin/");
311 function doUpdateRepo($url)
313 $rkey = $_REQUEST["repo"];
315 error_log("would update for repo");
317 $repo = new GLCASRepo($this->config);
319 $repo->updateRepo($rkey);
320 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
321 header("Location: $BASE_URL/admin/");
324 function mainBody($url)
326 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
328 // first, list available repos
329 echo "<h3>Repositories</h3>";
330 echo "<br><table border=\"1\">";
331 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>";
333 // now iterate thru the repos and print them
334 $repo = new GLCASRepo($this->config);
335 $repos = $repo->getRepos();
337 foreach($repos as $rkey => $rval) {
338 $desc = $rval["desc"];
340 $version = $rval["version"];
341 $arch = $rval["arch"];
342 $other = $rval["other"];
343 $repotype = $rval["repotype"];
344 $prefix = $rval["prefix"];
345 $shorturl = $rval["shorturl"];
346 if(isset($rval["frozen"])) $frozen = $rval["frozen"];
347 else $frozen = false;
348 if($prefix == "") $prefix = "-";
349 if($shorturl == "") $shorturl = "-";
351 $bgcol = "bgcolor=\"#bbbbff\"";
352 $frotext = "Unfreeze";
357 echo "<tr $bgcol><td>$desc</td><td>$repotype</td><td>$os</td><td>$version</td><td>$arch</td><td>$other</td><td>$prefix</td><td>$shorturl</td>";
360 $browseurl = "$BASE_URL/repo/$rkey";
363 if($prefix != "-") $brurl = "$prefix/$shorturl";
364 $browseurl = "$BASE_URL/$brurl/";
367 echo "<td><a href=\"$browseurl\">Browse</td><td>";
370 echo "<a href=\"?action=editrepo&repo=$rkey\">Edit</a> ";
372 if(!$frozen) echo "<a href=\"?action=updaterepo&repo=$rkey\">Update</a> ";
374 echo "<a href=\"?action=freezerepo&repo=$rkey\">$frotext</a> ";
376 echo "<a href=\"?action=disablerepo&repo=$rkey\">Disable</a> ";
378 echo "<a href=\"?action=cleanrepo&repo=$rkey\">Clean</a> ";
380 echo "<a href=\"?action=deleterepo&repo=$rkey\">Delete</a>";
386 echo "</table><br><hr>";
388 //if($repos !== false) print_r($repos);
391 // wrap all this in a table
392 echo "<table border=\"1\"><tr><td valign=\"top\">";
394 echo "<h3>Add A Repo</h3>";
395 echo "<form method=\"post\" action=\"?action=reponext\">";
396 echo "Type <select name=\"repotype\">";
397 echo "<option value=\"yumbase\">YUM (Base URL)</option>";
398 echo "<option value=\"apt\">APT</option>";
399 echo "</select><br>";
400 echo "URL <input type=\"text\" name=\"repourl\"><br>";
401 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
404 echo "</td><td valign=\"top\">";
406 // now scan for a repo
407 echo "<h3>Scan For Repos - not implemented</h3>";
408 echo "<form method=\"post\" action=\"?action=scanrepo\">";
409 echo "Hint <select name=\"repohint\">";
410 echo "<option value=\"fedora\">Fedora</option>";
411 echo "<option value=\"centos\">Centos</option>";
412 echo "</select><br>";
413 echo "URL <input type=\"text\" name=\"repourl\"><br>";
414 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
417 echo "</td><td valign=\"top\">";
419 // now for mirror lists
420 echo "<h3>Via Mirrolist - not implemented</h3>";
421 echo "<form method=\"post\" action=\"?action=mirrorlist\">";
422 echo "Distro <select name=\"mirrordistro\">";
423 echo "<option value=\"fedora\">Fedora</option>";
424 echo "<option value=\"centos\">Centos</option>";
425 echo "</select><br>";
426 echo "Architecture <select name=\"arch\">";
427 echo "<option value=\"x86_64\">64 bit</option>";
428 echo "<option value=\"i386\">32 bit</option>";
429 echo "</select><br>";
430 echo "Version <input type=\"text\" name=\"version\"><br>";
431 echo "Get updates too <input type=\"checkbox\" name=\"getupdates\"><br>";
432 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
436 echo "</td></tr></table>";
438 // repo storage location
439 echo "<h3>Storage<h3><br>";
440 echo "<form method=\"post\" action=\"?action=setstorage\">";
441 $storloc = $this->config->getConfigVar("storagelocation");
442 echo "<input class=\"storage\" type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
443 echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";