From c9cd2c7a60256b5d5d82610424c48706695bad5d Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 7 Aug 2011 04:32:21 +1000 Subject: [PATCH] started work on the adhoc file component --- libglcas/web.php | 1 + plugins/adhoc.php | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin.php | 35 +++++++++++- plugins/knownos.php | 9 +++ plugins/repo.php | 117 +++++++++++++++++++++++++++++------------ 5 files changed, 271 insertions(+), 36 deletions(-) create mode 100644 plugins/adhoc.php diff --git a/libglcas/web.php b/libglcas/web.php index 8c415f7..433b764 100644 --- a/libglcas/web.php +++ b/libglcas/web.php @@ -36,6 +36,7 @@ function GLCASMenuBuilder() ?> Home ">Admin +">Adhoc config = $config; + error_log("constructor for GLCASAdhoc"); + + $repostore = $this->config->getConfigVar("storagelocation"); + if(!is_dir("$repostore/adhoc")) { + error_log("Creating dir for adhoc component"); + mkdir("$repostore/adhoc"); + } + + } + + function go($url) + { + if(isset($_REQUEST["action"])) { + switch($_REQUEST["action"]) { + case "addpackage": + error_log("in updaterepo"); + GLCASpageBuilder($this,"addPackage"); + return; + } + } + + GLCASpageBuilder($this,"mainBody"); + return; + + } + + function addPackage($url) + { + $repostore = $this->config->getConfigVar("storagelocation"); + + if(!isset($_REQUEST["pkgname"])) { + echo "Error: No package name set
"; + } + if($_REQUEST["pkgname"] == "") { + echo "Error: Package name cant be blank
"; + } + + + $fname = ""; + $lname = ""; + $ultfileurl = ""; + if($_FILES["uploadedfile"]["name"] == "") { + $uploaded = false; + $ultfileurl = "uploaded"; + } else { + $fname = $_FILES["uploadedfile"]["tmp_name"]; + $lname = $_FILES["uploadedfile"]["name"]; + $uploaded = true; + } + + if($_REQUEST["fileurl"] == "") { + $fileurl = false; + $ultfileurl = $_REQUEST["fileurl"]; + } else { + $fname = $_REQUEST["fileurl"]; + $lname = basename($fname); + $fileurl = true; + } + + if(!$uploaded && !$fileurl) { + echo "Error: no uploaded file and no file url, you need one or the other buddy
"; + } + + $getfile = ""; + if($fileurl) { + $getfile = file_get_contents($_REQUEST["fileurl"]); + } + + if($uploaded||$fileurl) { + echo "Got a file named $fname, $lname"; + } + + $pkgs = unserialize($this->config->getConfigVar("adhocpackages")); + + $n = -1; + foreach($pkgs as $key => $var) { + $n = $key; + } + $n++; + + echo "Would add package as $n"; + + $pkgs[$n]["arch"] = $_REQUEST["arch"]; + $pkgs[$n]["type"] = $_REQUEST["type"]; + $pkgs[$n]["fileurl"] = $ultfileurl; + + if($uploaded) { + copy("$fname", "$repostore/adhoc/$n"); + } else { + file_put_contents("$repostore/adhoc/$n", $fetfile); + } + + $this->config->saveConfig(); + + echo "Done"; + + + echo "
";
+		print_r($_SERVER);
+		print_r($_FILES);
+		print_r($_REQUEST);
+		print_r($pkgs);
+		echo "
"; + } + + + function mainBody($url) + { + echo "

Packages

"; + + $kos = getKnownOSList(); + + echo "
"; + echo "

Add a Package


"; + echo "
"; + echo "Name
"; + echo "Arch
"; + echo "Type
"; + echo "Upload
"; + echo "From URL
"; + echo ""; + echo "
"; + } +} + +?> diff --git a/plugins/admin.php b/plugins/admin.php index 492ed29..56d86dd 100644 --- a/plugins/admin.php +++ b/plugins/admin.php @@ -44,6 +44,10 @@ class GLCASAdmin { error_log("call setstorage"); GLCASpageBuilder($this, "setStorage"); return; + case "freezerepo": + error_log("call freezerepo"); + GLCASpageBuilder($this, "freezeRepo"); + return; case "scanrepo": break; } @@ -93,6 +97,22 @@ class GLCASAdmin { $this->mainBody($url); } + function freezeRepo($url) + { + $repo = $_REQUEST["repo"]; + + + $myRep = new GLCASRepo($this->config); + + + error_log("called freeze repo on $repo"); + $myRep->freezeRepo($repo); + + global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL; + header("Location: $BASE_URL/admin/"); + + } + function doRemoveRepo($url) { $repo = $_REQUEST["repo"]; @@ -323,9 +343,18 @@ class GLCASAdmin { $repotype = $rval["repotype"]; $prefix = $rval["prefix"]; $shorturl = $rval["shorturl"]; + if(isset($rval["frozen"])) $frozen = $rval["frozen"]; + else $frozen = false; if($prefix == "") $prefix = "-"; if($shorturl == "") $shorturl = "-"; - echo "$desc$repotype$os$version$arch$other$prefix$shorturl"; + if($frozen) { + $bgcol = "bgcolor=\"#bbbbff\""; + $frotext = "Unfreeze"; + } else { + $frotext = "Freeze"; + $bgcol = ""; + } + echo "$desc$repotype$os$version$arch$other$prefix$shorturl"; // get url $browseurl = "$BASE_URL/repo/$rkey"; @@ -340,9 +369,9 @@ class GLCASAdmin { // Edit echo "Edit "; // update - echo "Update "; + if(!$frozen) echo "Update "; // freeze - echo "Freeze "; + echo "$frotext "; // deactivate echo "Disable "; // clean diff --git a/plugins/knownos.php b/plugins/knownos.php index 1a8b447..77ccc81 100644 --- a/plugins/knownos.php +++ b/plugins/knownos.php @@ -82,6 +82,15 @@ function getKnownOSList() $kos["arch"]["amd64_2"] = "amd64"; + // package archs + $kos["pkgarch"]["i386"] = "i386"; + $kos["pkgarch"]["x86_64"] = "x86_64"; + $kos["pkgarch"]["noarch"] = "noarch"; + + // package types + $kos["pkg"]["rpm"] = "RPM"; + $kos["pkg"]["deb"] = "DEB"; + return $kos; } diff --git a/plugins/repo.php b/plugins/repo.php index f794c29..0f32504 100644 --- a/plugins/repo.php +++ b/plugins/repo.php @@ -27,6 +27,13 @@ class GLCASRepo { foreach($uconf as $rkey => $repo) { echo "Repo $rkey: ".$repo["desc"]."
"; + if(isset($repo["frozen"])) { + error_log("repo froze set"); + $repofrozen = $repo["frozen"]; + } else { + error_log("repo froze not set"); + $repofrozen = false; + } if(!isset($repo["expiretime"])) { echo " - Expire time not set, setting to 2 days by default
"; $uconf[$rkey]["expiretime"] = 2; @@ -41,44 +48,54 @@ class GLCASRepo { $this->config->setConfigVar("repodata", serialize($uconf)); $this->config->saveConfig(); } else if($repo["repotype"] == "YUM") { - if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) { - echo " - Repo locked for update
"; - - } - - // we still do this next bit, even if its locked because it may be a stray file - echo " - Expire time is ".$repo["expiretime"]." days, checking repo
"; - error_log("checking $repostore/$rkey/repodata/repomd.xml"); - $tdiff = time() - filemtime("$repostore/$rkey/repodata/repomd.xml"); - $maxtdiff = $repo["expiretime"] * 24 * 3600; - if($tdiff > $maxtdiff) { - echo " - updating repo
"; - $this->updateRepo($rkey); + if($repofrozen) { + error_log("repo frozen"); + echo " - Repo Frozen
"; } else { - echo " - not updating repo
"; + if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) { + echo " - Repo locked for update
"; + + } + + // we still do this next bit, even if its locked because it may be a stray file + echo " - Expire time is ".$repo["expiretime"]." days, checking repo
"; + error_log("checking $repostore/$rkey/repodata/repomd.xml"); + $tdiff = time() - filemtime("$repostore/$rkey/repodata/repomd.xml"); + $maxtdiff = $repo["expiretime"] * 24 * 3600; + if($tdiff > $maxtdiff) { + echo " - updating repo
"; + $this->updateRepo($rkey); + } else { + echo " - not updating repo
"; + } } } else if($repo["repotype"] == "APT") { - if(file_exists("$repostore/$rkey/update.lock")) { - echo " - Repo locaked for update
"; - } - echo " - Expire time is ".$repo["expiretime"]." days, checking repo
"; - $maxtdiff = $repo["expiretime"] * 24 * 3600; - // now we check for outdated release files - $dh = opendir("$repostore/$rkey/dists/"); - $needsupdate = false; - while(($fn = readdir($dh))!==false) { - if($fn != "." && $fn != "..") { - if(file_exists("$repostore/$rkey/dists/$fn/Release")) { - $tdiff = time() - filemtime("$repostore/$rkey/dists/$fn/Release"); - if($tdiff > $maxtdiff) $needsupdate = true; + if($repofrozen) { + error_log("repo frozen"); + echo " - Repo Frozen
"; + } else { + if(file_exists("$repostore/$rkey/update.lock")) { + echo " - Repo locaked for update
"; + } + echo " - Expire time is ".$repo["expiretime"]." days, checking repo
"; + $maxtdiff = $repo["expiretime"] * 24 * 3600; + // now we check for outdated release files + $dh = opendir("$repostore/$rkey/dists/"); + $needsupdate = false; + while(($fn = readdir($dh))!==false) { + if($fn != "." && $fn != "..") { + if(file_exists("$repostore/$rkey/dists/$fn/Release")) { + $tdiff = time() - filemtime("$repostore/$rkey/dists/$fn/Release"); + if($tdiff > $maxtdiff) $needsupdate = true; + } } } - } - if($needsupdate) { - echo " - Spawn updater
"; - $this->updateRepo($rkey); - } else { - echo " - Up to date
"; + if($needsupdate) { + echo " - Spawn updater
"; + $this->updateRepo($rkey); + } else { + echo " - Up to date
"; + } } } } @@ -725,6 +742,36 @@ class GLCASRepo { return $glt; } + function freezeRepo($rkey) + { + + $uconf = $this->config->getConfigVar("repodata"); + $repostore = $this->config->getConfigVar("storagelocation"); + + if($uconf !== false) { + $conf = unserialize($uconf); + foreach($conf as $key => $vla) { + if($key == $rkey) { + if(isset($conf["$rkey"]["frozen"])) { + if($conf["$rkey"]["frozen"]) { + $conf["$rkey"]["frozen"] = false; + error_log("Unfreeze repo"); + } else { + $conf["$rkey"]["frozen"] = true; + error_log("freeze repo"); + } + } else { + $conf["$rkey"]["frozen"] = true; + } + $nconf = serialize($conf); + error_log("freeze repo as $rkey"); + $this->config->setConfigVar("repodata", $nconf); + $this->config->saveConfig(); + } + } + } + } + function deleteRepo($rkey) { $uconf = $this->config->getConfigVar("repodata"); @@ -793,6 +840,10 @@ class GLCASRepo { { // we only do yum yet $repod = $this->getRepo($repokey); + if(isset($repod["frozen"])) if($repod["frozen"]) { + error_log("in update repo for frozen repo, ignore update"); + return; + } error_log("in update repo"); -- 1.7.0.4