global $URL_HANDLERS;
$URL_HANDLERS["admin.*"] = "GLCASAdmin";
+global $CRON_CLASSES;
+$CRON_CLASSES["GLCASAdmin"] = "GLCASAdmin";
class GLCASAdmin {
function __construct($config)
GLCASpageBuilder($this,"doRepoNextForm");
return;
break;
+ case "addrepoapt":
+ GLCASpageBuilder($this,"doAddRepoApt");
+ return;
case "addrepoyum":
GLCASpageBuilder($this,"doAddRepoYum");
return;
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
$myRep = new GLCASRepo($this->config);
$wasyum = false;
+ $wasapt = false;
if($_REQUEST["repotype"] == "yumbase") {
$glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
$wasyum = 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"];
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\"> days</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>";
- } else {
- // apt is much tricker cause one repo can provide multiple versions, OS's and architectures.
}
}
+
+ 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)
{
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 - 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>";