hello
[glcas.git] / plugins / admin.php
index b746ebb..609047f 100644 (file)
@@ -52,6 +52,28 @@ class GLCASAdmin {
        {
                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)
@@ -92,6 +114,7 @@ class GLCASAdmin {
                $myRep = new GLCASRepo($this->config);
                
                $wasyum = false;
+               $wasapt = false;
                if($_REQUEST["repotype"] == "yumbase") {
                        $glt = $myRep->getRepoDetailsYum($_REQUEST["repourl"]);
                        $wasyum = true;
@@ -100,8 +123,44 @@ class GLCASAdmin {
                        $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>";
+                       }
+                       
+                       echo "<form method=\"post\" action=\"?action=addrepoapt\">";
+                       echo "<input type=\"hidden\" name=\"repourl\" value=\"$repourl\">";
+                       echo "<table>";
+                       echo "<tr><td>Description</td><td><input type=\"text\" name=\"desc\" value=\"APT Repo$extratext\"></td>";
+                       echo "<tr><td>Provides</td><td><textarea name=\"provides\">$provides</text area></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\"> days</td></tr>";
+                       echo "</table>";
+                       echo "</form>";
+                       return true;
+               }
                
                if($wasyum) {
                        $os = $glt["OS"];
@@ -124,8 +183,6 @@ class GLCASAdmin {
                        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.
                }
        }