From 671e643949bab1c87d175bfc98ff086deb9c44ff Mon Sep 17 00:00:00 2001 From: paulr Date: Wed, 3 Aug 2011 12:12:45 +1000 Subject: [PATCH] hello --- libglcas/config.php | 15 ++++++++++++ libglcas/lib.php | 13 ----------- libglcas/web.php | 22 ++++++++++++++++++ plugins/admin.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++- plugins/knownos.php | 43 ++++++++++++++++++++++++++++++++++++ plugins/repo.php | 33 +++++++++++++++++++++++++++ 6 files changed, 172 insertions(+), 15 deletions(-) diff --git a/libglcas/config.php b/libglcas/config.php index 506a0b3..2009823 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -74,4 +74,19 @@ class GLCASConfig { } +function glcas_getWebConfigPath() +{ + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + + // if you wish to add more places to find webconfig, add them here. + $configpath = false; + if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig"); + if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig"); + if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig"); + + return $configpath; + //return false; +} + + ?> \ No newline at end of file diff --git a/libglcas/lib.php b/libglcas/lib.php index ef329be..76e0f9c 100644 --- a/libglcas/lib.php +++ b/libglcas/lib.php @@ -46,18 +46,5 @@ function glcas_pluginLoader($path="") } } -function glcas_getWebConfigPath() -{ - global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; - - // if you wish to add more places to find webconfig, add them here. - $configpath = false; - if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) return realpath($WEB_ROOT_FS."/../var/glcas/webconfig"); - if(file_exists("/var/lib/glcas/webconfig")) return realpath("/var/lib/glcas/webconfig"); - if(file_exists("/var/run/glcas/webconfig")) return realpath("/var/run/glcas/webconfig"); - - return $configpath; - //return false; -} ?> \ No newline at end of file diff --git a/libglcas/web.php b/libglcas/web.php index 0d812d9..f2182f3 100644 --- a/libglcas/web.php +++ b/libglcas/web.php @@ -118,6 +118,28 @@ function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title=" } +function glcas_isRemoteDir($url) +{ + file_get_contents($url); + //error_log("did file_get_contents on $url"); + foreach($http_response_header as $key => $val) { + //error_log("got header of $key for $val"); + if(preg_match("/.*Location:.*/", $val)) { + //error_log("in details apt got location as $val from $url"); + $realloc = preg_replace("/.*: /", "", $val); + $urlwithslash = $url."/"; + //echo "
in comp with
$urlwithslash
$realloc
"; + if(strcasecmp($realloc,$urlwithslash)==0) { + //error_log("I believe $realloc is a directory redir for $url"); + return true; + } else { + //error_log("I dont believe $realloc is a directory redir for $url"); + } + } + } + return false; +} + function glcas_startInstaller() { global $WEB_ROOT_FS, $BASE_URL; diff --git a/plugins/admin.php b/plugins/admin.php index b746ebb..609047f 100644 --- a/plugins/admin.php +++ b/plugins/admin.php @@ -52,6 +52,28 @@ class GLCASAdmin { { 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) @@ -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
"; + 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 "
"; + echo ""; + echo ""; + echo ""; + echo "
Description
Provides