global $URL_HANDLERS;
$URL_HANDLERS["admin.*"] = "GLCASAdmin";
+global $CRON_CLASSES;
+$CRON_CLASSES["GLCASAdmin"] = "GLCASAdmin";
class GLCASAdmin {
function __construct($config)
function go($url)
{
- echo "admin page";
+ error_log("repo:go called");
+
+ if(isset($_REQUEST["action"])) {
+ switch($_REQUEST["action"]) {
+ case "updaterepo":
+ error_log("in updaterepo");
+ GLCASpageBuilder($this,"doUpdateRepo");
+ return;
+ case "reponext":
+ error_log("in reponext");
+ GLCASpageBuilder($this,"doRepoNextForm");
+ return;
+ break;
+ case "addrepoapt":
+ GLCASpageBuilder($this,"doAddRepoApt");
+ return;
+ case "addrepoyum":
+ GLCASpageBuilder($this,"doAddRepoYum");
+ return;
+ case "deleterepo":
+ error_log("call delete repo");
+ GLCASpageBuilder($this, "doRemoveRepo");
+ return;
+ case "setstorage":
+ error_log("call setstorage");
+ GLCASpageBuilder($this, "setStorage");
+ return;
+ case "scanrepo":
+ break;
+ }
+ }
+ GLCASpageBuilder($this, "body");
+ }
+
+ function cron()
+ {
+ echo "ADMIN CRON: nothing to see here<br>";
+ // TODO: touch cronstamp file here
+
+ // make a backup of the config.. but.. errr. how to tell if theres an old backup?
+ // backups will occur... weekly and be called $configpath.DDMMYYYY
+ $configpath = glcas_getWebConfigPath();
+ $basepath = dirname($configpath);
+ echo "ADMIN CRON: backing up config, $configpath, $basepath<br>";
+ $nowtime = time();
+ $oneday = 3600 * 24; // 1 hour in seconds, by 24 hours
+ for($i = 0; $i < 7; $i ++) {
+ $cdatestr = strftime("%d-%h-%Y", $nowtime - ($oneday*$i));
+ $backupfile = "$configpath.$cdatestr";
+ error_log("checking for backup of config as $backupfile");
+ if(file_exists($backupfile)) {
+ error_log("backupconfig exists as $backupfile, exit");
+ echo "ADMIN CRON: backup of config is $backupfile, created $i days ago, not creating new one<br>";
+ return;
+ }
+ }
+ $nowdatestr = strftime("%d-%h-%Y");
+ $backupfile = "$configpath.$nowdatestr";
+ copy($configpath, $backupfile);
+ echo "ADMIN CRON: createing backup of config as $backupfile<br>";
+ }
+
+ function body($url)
+ {
+ // for the main admin body, we hae the following components
+
+ // 1. list of currently available repos and stuff
+
+ // 2. way to add a repo direct
+
+ // 3. way to scan for a repo given a url
+
+ // so first, lets do the main body
+ $this->mainBody($url);
+ }
+
+ function doRemoveRepo($url)
+ {
+ $repo = $_REQUEST["repo"];
+ $myRep = new GLCASRepo($this->config);
+
+
+ error_log("called delete repo on $repo");
+ $myRep->deleteRepo($repo);
+
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+ header("Location: $BASE_URL/admin/");
+ }
+
+
+ function setStorage($url)
+ {
+
+ }
+
+ function doRepoNextForm($url)
+ {
+ $myRep = new GLCASRepo($this->config);
+
+ $wasyum = false;
+ $wasapt = false;
+ if($_REQUEST["repotype"] == "yumbase") {
+ $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
+ $wasyum = true;
+ } else if($_REQUEST["repotype"] == "yummirrorlist") {
+ $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"], true);
+ $wasyum = true;
+ } else if($_REQUEST["repotype"] == "apt") {
+ $glt = $myRep->getRepoDetailsApt($_REQUEST["repourl"]);
+ $wasapt = true;
+ }
+
+ if($wasapt) {
+ error_log("in wasapt");
+ $repourl = $_REQUEST["repourl"];
+
+ if($glt === false) {
+ echo "Could not find any apt repository at $repourl<br>";
+ return;
+ }
+
+ $extratext = "";
+ $provides = "";
+ if($glt["nrepos"] > 0) {
+ $kos = getKnownOSList();
+ foreach($glt["knownrepo"] as $key => $val) {
+ $reponame = $kos["apt"][$val];
+ //echo "Fount a repo, $val which is $reponame<br>";
+ $provides .= "$reponame\n";
+ }
+ $extratext = " for ".$glt["distros"];
+ } else {
+ //echo "Looks like an apt repo, but I cant find any known distro's<br>";
+ }
+ //$existing_repos["distros"] = "Ubuntu, Debian";
+ //$existing_repos["versions"] = "8.04LTS, 9.10, 10.04LTS, 10.10, 11.04, 11.10";
+ //$existing_repos["arch"] = "x86_64, i386";
+
+
+ $distros = $glt["distros"];
+ $version = $glt["versions"];
+ $archs = $glt["arch"];
+
+ echo "<form method=\"post\" action=\"?action=addrepoapt\">";
+ echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
+ echo "<input type=\"hidden\" name=\"distro\" value=\"$distros\">";
+ echo "<input type=\"hidden\" name=\"arch\" value=\"$archs\">";
+ echo "<table>";
+ echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"APT Repo$extratext\"></td>";
+ // TODO change this "provides" bit with a bit that allows us to choose which versions
+ // of ubuntu will be made available from the ones we found
+ echo "<tr><td>Provides</td><td><textarea name=\"provides\" rows=\"".$glt["nrepos"]."\" cols=\"100\">$provides</textarea></td></tr>";
+ echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
+ echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
+ echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
+ echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
+ echo "</table>";
+ echo "</form>";
+ return true;
+ }
+
+ if($wasyum) {
+ $os = $glt["OS"];
+ $version = $glt["version"];
+ $arch = $glt["arch"];
+ $other = $glt["other"];
+ $repourl = $_REQUEST["repourl"];
+ echo "<form method=\"post\" action=\"?action=addrepoyum\">";
+ echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
+ echo "<table>";
+ echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"$os, $version, $arch - $other\"></td></tr>";
+ echo "<tr><td>OS</td><td><input type=\"text\" name=\"OS\" value=\"$os\"></td></tr>";
+ echo "<tr><td>Version</td><td><input type=\"text\" name=\"version\" value=\"$version\"></td></tr>";
+ echo "<tr><td>Architecture</td><td><input type=\"text\" name=\"arch\" value=\"$arch\"></td></tr>";
+ echo "<tr><td>Other (OS, Updates, etc)</td><td><input type=\"text\" name=\"other\" value=\"$other\"></td></tr>";
+ echo "<tr><td>Short URL</td><td><input type=\"text\" name=\"shorturl\"></td></tr>";
+ echo "<tr><td>URL Prefix (blank for none)</td><td><input type=\"text\" name=\"prefix\"></td></tr>";
+ echo "<tr><td>Do Initial Update (can take a while, but done in background)</td><td><input type=\"checkbox\" name=\"initial\" checked></td></tr>";
+ echo "<tr><td>Expire time for Meta Data</td><td><input type=\"text\" name=\"expiretime\" value=\"3\"> days</td></tr>";
+ echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
+ echo "</table>";
+ echo "</form>";
+ }
+ }
+
+ function doAddRepoApt($url)
+ {
+ $repo = new GLCASRepo($this->config);
+
+ $desc = $_REQUEST["desc"];
+ $OS = $_REQUEST["distro"];
+ $version = $_REQUEST["provides"];
+ $arch = $_REQUEST["arch"];
+ $shorturl = $_REQUEST["shorturl"];
+ $prefix = $_REQUEST["prefix"];
+ $repurl = $_REQUEST["repourl"];
+ $expiretime = $REQUEST["expiretime"];
+ $init = false;
+ if(isset($_REQUEST["initial"])) $init = true;
+
+
+
+ $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime);
+
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+ header("Location: $BASE_URL/admin/");
+ }
+
+ function doAddRepoYum($url)
+ {
+ $repo = new GLCASRepo($this->config);
+
+ $desc = $_REQUEST["desc"];
+ $OS = $_REQUEST["OS"];
+ $version = $_REQUEST["version"];
+ $arch = $_REQUEST["arch"];
+ $other = $_REQUEST["other"];
+ $shorturl = $_REQUEST["shorturl"];
+ $prefix = $_REQUEST["prefix"];
+ $repurl = $_REQUEST["repourl"];
+ $expiretime = $REQUEST["expiretime"];
+ $init = false;
+ if(isset($_REQUEST["initial"])) $init = true;
+
+
+
+ $repo->addRepo($desc, $OS, $version, $arch, $other, $shorturl, $prefix, $repurl, "YUM", $init, $expiretime);
+
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+ header("Location: $BASE_URL/admin/");
}
+ function doUpdateRepo($url)
+ {
+ $rkey = $_REQUEST["repo"];
+
+ $repo = new GLCASRepo($this->config);
+
+ $repo->updateRepo($rkey);
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+ header("Location: $BASE_URL/admin/");
+ }
+
+ function mainBody($url)
+ {
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+ // first, list available repos
+ echo "<h3>Repositories</h3>";
+ echo "<br><table border=\"1\">";
+ 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>";
+
+ // now iterate thru the repos and print them
+ $repo = new GLCASRepo($this->config);
+ $repos = $repo->getRepos();
+
+ foreach($repos as $rkey => $rval) {
+ $desc = $rval["desc"];
+ $os = $rval["os"];
+ $version = $rval["version"];
+ $arch = $rval["arch"];
+ $other = $rval["other"];
+ $repotype = $rval["repotype"];
+ $prefix = $rval["prefix"];
+ $shorturl = $rval["shorturl"];
+ if($prefix == "") $prefix = "-";
+ if($shorturl == "") $shorturl = "-";
+ 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>";
+
+ // get url
+ $browseurl = "$BASE_URL/repo/$rkey";
+ if($shorturl!="-") {
+ $brurl = $shorturl;
+ if($prefix != "-") $brurl = "$prefix/$shorturl";
+ $browseurl = "$BASE_URL/$brurl/";
+ }
+
+ echo "<td><a href=\"$browseurl\">Browse</td><td>";
+
+ // Edit
+ echo "<a href=\"?action=editrepo&repo=$rkey\">Edit</a> ";
+ // update
+ echo "<a href=\"?action=updaterepo&repo=$rkey\">Update</a> ";
+ // freeze
+ echo "<a href=\"?action=freezerepo&repo=$rkey\">Freeze</a> ";
+ // deactivate
+ echo "<a href=\"?action=disablerepo&repo=$rkey\">Disable</a> ";
+ // clean
+ echo "<a href=\"?action=cleanrepo&repo=$rkey\">Clean</a> ";
+ // Remove
+ echo "<a href=\"?action=deleterepo&repo=$rkey\">Delete</a>";
+
+ echo "</td>";
+ echo "</tr>";
+ }
+
+ echo "</table><br><hr>";
+ //echo "<pre>";
+ //if($repos !== false) print_r($repos);
+ //echo "</pre>";
+
+ // wrap all this in a table
+ echo "<table><tr><td valign=\"top\">";
+ // now, add a repo
+ echo "<h3>Add A Repo</h3>";
+ echo "<form method=\"post\" action=\"?action=reponext\">";
+ echo "Type <select name=\"repotype\">";
+ echo "<option value=\"yumbase\">YUM (Base URL)</option>";
+ echo "<option value=\"yummirrorlist\">YUM (Mirror List) - not implemented</option>";
+ echo "<option value=\"apt\">APT</option>";
+ echo "</select><br>";
+ echo "URL <input type=\"text\" name=\"repourl\"><br>";
+ echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
+ echo "</form>";
+
+ echo "</td><td valign=\"top\">";
+
+ // now scan for a repo
+ echo "<h3>Scan For Repos - not implemented</h3>";
+ echo "<form method=\"post\" action=\"?action=scanrepo\">";
+ echo "Hint <select name=\"repohint\">";
+ echo "<option value=\"fedora\">Fedora</option>";
+ echo "<option value=\"centos\">Centos</option>";
+ echo "<option value=\"ubuntu\">Ubuntu</option>";
+ echo "</select><br>";
+ echo "URL <input type=\"text\" name=\"repourl\"><br>";
+ echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
+ echo "</form>";
+
+ echo "</td></tr></table><hr>";
+
+ // repo storage location
+ echo "<h3>Storage<h3><br>";
+ echo "<form method=\"post\" action=\"?action=setstorage\">";
+ $storloc = $this->config->getConfigVar("storagelocation");
+ echo "<input type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
+ echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";
+ echo "</form>";
+ }
+
private $config;
}