X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=plugins%2Fadmin.php;h=609047f56c4ce723a7e4906ff34671aaa53e491e;hb=671e643949bab1c87d175bfc98ff086deb9c44ff;hp=4e2466552472c25d0669c4dc4f77b98ad95bbfd7;hpb=17d5412ef5bdde749ce57dbdd627243eb0d701a8;p=glcas.git
diff --git a/plugins/admin.php b/plugins/admin.php
index 4e24665..609047f 100644
--- a/plugins/admin.php
+++ b/plugins/admin.php
@@ -4,6 +4,8 @@ error_log("admin loaded");
global $URL_HANDLERS;
$URL_HANDLERS["admin.*"] = "GLCASAdmin";
+global $CRON_CLASSES;
+$CRON_CLASSES["GLCASAdmin"] = "GLCASAdmin";
class GLCASAdmin {
function __construct($config)
@@ -15,9 +17,307 @@ class GLCASAdmin {
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 "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
";
+ // 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
";
+ $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
";
+ return;
+ }
+ }
+ $nowdatestr = strftime("%d-%h-%Y");
+ $backupfile = "$configpath.$nowdatestr";
+ copy($configpath, $backupfile);
+ echo "ADMIN CRON: createing backup of config as $backupfile
";
+ }
+
+ 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
";
+ 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
";
+ $provides .= "$reponame\n";
+ }
+ $extratext = " for ".$glt["distros"];
+ } else {
+ //echo "Looks like an apt repo, but I cant find any known distro's
";
+ }
+
+ echo "
";
+ return true;
+ }
+
+ if($wasyum) {
+ $os = $glt["OS"];
+ $version = $glt["version"];
+ $arch = $glt["arch"];
+ $other = $glt["other"];
+ $repourl = $_REQUEST["repourl"];
+ echo "";
+ }
+ }
+
+ 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 "Repositories
";
+ echo "
";
+ echo "Name | Type | OS | Version | Architecture | Other | Prefix | Short URL | Browse | Control |
";
+
+ // 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 "$desc | $repotype | $os | $version | $arch | $other | $prefix | $shorturl | ";
+
+ // get url
+ $browseurl = "$BASE_URL/repo/$rkey";
+ if($shorturl!="-") {
+ $brurl = $shorturl;
+ if($prefix != "-") $brurl = "$prefix/$shorturl";
+ $browseurl = "$BASE_URL/$brurl/";
+ }
+
+ echo "Browse | ";
+
+ // Edit
+ echo "Edit ";
+ // update
+ echo "Update ";
+ // freeze
+ echo "Freeze ";
+ // deactivate
+ echo "Disable ";
+ // clean
+ echo "Clean ";
+ // Remove
+ echo "Delete";
+
+ echo " | ";
+ echo "
";
+ }
+
+ echo "
";
+ //echo "";
+ //if($repos !== false) print_r($repos);
+ //echo "
";
+
+ // wrap all this in a table
+ echo "
";
+
+ // repo storage location
+ echo "Storage
";
+ echo "
";
+ }
+
private $config;
}