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 "The joy of apt is that there could be a million distro's under the root of an apt mirror";
170 echo "if it doesn't list here, but you know its there, its still usable for glcas";
171 echo "<form method=\"post\" action=\"?action=addrepoapt\">";
172 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
173 echo "<input type=\"hidden\" name=\"distro\" value=\"$distros\">";
174 echo "<input type=\"hidden\" name=\"provides\" value=\"Multiple\">";
175 echo "<input type=\"hidden\" name=\"arch\" value=\"$archs\">";
177 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"APT Repo$extratext\"></td>";
179 // TODO: deal with block bit
180 echo "<tr><td>Provides (tick those you wish to BLOCK - not implemented)</td><td>";
181 foreach($glt["knownrepo"] as $key => $val) {
182 $reponame = $kos["apt"][$val["name"]];
185 if($glt["knownrepo"][$key]["i386"]) $a = "i386";
186 if($glt["knownrepo"][$key]["amd64"]) $b = "x86_64";
187 if($a != "" && $b != "") $archs = "$a/$b";
188 else $archs = "$a$b";
189 echo "<input type=\"checkbox\" name=\"blocked-".$val["name"]."\"> $reponame ($archs)<br>";
193 //echo "<tr><td>Provides</td><td><textarea name=\"provides\" rows=\"".$glt["nrepos"]."\" cols=\"100\">$provides</textarea></td></tr>";
194 echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
195 echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
196 echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
197 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
205 $version = $glt["version"];
206 $arch = $glt["arch"];
207 $other = $glt["other"];
208 $repourl = $_REQUEST["repourl"];
209 echo "<form method=\"post\" action=\"?action=addrepoyum\">";
210 echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
212 echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"$os, $version, $arch - $other\"></td></tr>";
213 echo "<tr><td>OS</td><td><input type=\"text\" name=\"OS\" value=\"$os\"></td></tr>";
214 echo "<tr><td>Version</td><td><input type=\"text\" name=\"version\" value=\"$version\"></td></tr>";
215 echo "<tr><td>Architecture</td><td><input type=\"text\" name=\"arch\" value=\"$arch\"></td></tr>";
216 echo "<tr><td>Other (OS, Updates, etc)</td><td><input type=\"text\" name=\"other\" value=\"$other\"></td></tr>";
217 echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
218 echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
219 echo "<tr><td>Do Initial Update (can take a while, but done in background)</td><td><input type=\"checkbox\" name=\"initial\" checked></td></tr>";
220 echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
221 echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
227 function doAddRepoApt($url)
229 $repo = new GLCASRepo($this->config);
231 $desc = $_REQUEST["desc"];
232 $OS = $_REQUEST["distro"];
233 $version = $_REQUEST["provides"];
234 $arch = $_REQUEST["arch"];
235 $shorturl = $_REQUEST["shorturl"];
236 $prefix = $_REQUEST["prefix"];
237 $repurl = $_REQUEST["repourl"];
238 $expiretime = $REQUEST["expiretime"];
240 if(isset($_REQUEST["initial"])) $init = true;
244 foreach($_REQUEST as $key => $val) {
245 if(preg_match("/^blocked-*/", $key)) {
246 $blocked = preg_replace("/^blocked-/", "", $key);
247 //echo "<br>got block for $blocked<br>";
248 $blocklist[$bn] = "dists\/$blocked.*";
254 //print_r($_REQUEST);
259 $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime, $blocklist);
261 // next we need to deal with that "blocked" bit
263 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
264 header("Location: $BASE_URL/admin/");
267 function doAddRepoYum($url)
269 $repo = new GLCASRepo($this->config);
271 $desc = $_REQUEST["desc"];
272 $OS = $_REQUEST["OS"];
273 $version = $_REQUEST["version"];
274 $arch = $_REQUEST["arch"];
275 $other = $_REQUEST["other"];
276 $shorturl = $_REQUEST["shorturl"];
277 $prefix = $_REQUEST["prefix"];
278 $repurl = $_REQUEST["repourl"];
279 $expiretime = $REQUEST["expiretime"];
281 if(isset($_REQUEST["initial"])) $init = true;
285 $repo->addRepo($desc, $OS, $version, $arch, $other, $shorturl, $prefix, $repurl, "YUM", $init, $expiretime);
287 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
288 header("Location: $BASE_URL/admin/");
291 function doUpdateRepo($url)
293 $rkey = $_REQUEST["repo"];
295 error_log("would update for repo");
297 $repo = new GLCASRepo($this->config);
299 $repo->updateRepo($rkey);
300 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
301 header("Location: $BASE_URL/admin/");
304 function mainBody($url)
306 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
308 // first, list available repos
309 echo "<h3>Repositories</h3>";
310 echo "<br><table border=\"1\">";
311 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>";
313 // now iterate thru the repos and print them
314 $repo = new GLCASRepo($this->config);
315 $repos = $repo->getRepos();
317 foreach($repos as $rkey => $rval) {
318 $desc = $rval["desc"];
320 $version = $rval["version"];
321 $arch = $rval["arch"];
322 $other = $rval["other"];
323 $repotype = $rval["repotype"];
324 $prefix = $rval["prefix"];
325 $shorturl = $rval["shorturl"];
326 if($prefix == "") $prefix = "-";
327 if($shorturl == "") $shorturl = "-";
328 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>";
331 $browseurl = "$BASE_URL/repo/$rkey";
334 if($prefix != "-") $brurl = "$prefix/$shorturl";
335 $browseurl = "$BASE_URL/$brurl/";
338 echo "<td><a href=\"$browseurl\">Browse</td><td>";
341 echo "<a href=\"?action=editrepo&repo=$rkey\">Edit</a> ";
343 echo "<a href=\"?action=updaterepo&repo=$rkey\">Update</a> ";
345 echo "<a href=\"?action=freezerepo&repo=$rkey\">Freeze</a> ";
347 echo "<a href=\"?action=disablerepo&repo=$rkey\">Disable</a> ";
349 echo "<a href=\"?action=cleanrepo&repo=$rkey\">Clean</a> ";
351 echo "<a href=\"?action=deleterepo&repo=$rkey\">Delete</a>";
357 echo "</table><br><hr>";
359 //if($repos !== false) print_r($repos);
362 // wrap all this in a table
363 echo "<table border=\"1\"><tr><td valign=\"top\">";
365 echo "<h3>Add A Repo</h3>";
366 echo "<form method=\"post\" action=\"?action=reponext\">";
367 echo "Type <select name=\"repotype\">";
368 echo "<option value=\"yumbase\">YUM (Base URL)</option>";
369 echo "<option value=\"apt\">APT</option>";
370 echo "</select><br>";
371 echo "URL <input type=\"text\" name=\"repourl\"><br>";
372 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
375 echo "</td><td valign=\"top\">";
377 // now scan for a repo
378 echo "<h3>Scan For Repos - not implemented</h3>";
379 echo "<form method=\"post\" action=\"?action=scanrepo\">";
380 echo "Hint <select name=\"repohint\">";
381 echo "<option value=\"fedora\">Fedora</option>";
382 echo "<option value=\"centos\">Centos</option>";
383 echo "</select><br>";
384 echo "URL <input type=\"text\" name=\"repourl\"><br>";
385 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
388 echo "</td><td valign=\"top\">";
390 // now for mirror lists
391 echo "<h3>Via Mirrolist - not implemented</h3>";
392 echo "<form method=\"post\" action=\"?action=mirrorlist\">";
393 echo "Distro <select name=\"mirrordistro\">";
394 echo "<option value=\"fedora\">Fedora</option>";
395 echo "<option value=\"centos\">Centos</option>";
396 echo "</select><br>";
397 echo "Architecture <select name=\"arch\">";
398 echo "<option value=\"x86_64\">64 bit</option>";
399 echo "<option value=\"i386\">32 bit</option>";
400 echo "</select><br>";
401 echo "Version <input type=\"text\" name=\"version\"><br>";
402 echo "Get updates too <input type=\"checkbox\" name=\"getupdates\"><br>";
403 echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
407 echo "</td></tr></table>";
409 // repo storage location
410 echo "<h3>Storage<h3><br>";
411 echo "<form method=\"post\" action=\"?action=setstorage\">";
412 $storloc = $this->config->getConfigVar("storagelocation");
413 echo "<input class=\"storage\" type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
414 echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";