$version = $glt["versions"];
$archs = $glt["arch"];
- echo "<pre>";
- print_r($glt);
- echo "</pre>";
+ //echo "<pre>";
+ //print_r($glt);
+ //echo "</pre>";
+ echo "The joy of apt is that there could be a million distro's under the root of an apt mirror";
+ echo "if it doesn't list here, but you know its there, its still usable for glcas";
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=\"provides\" value=\"Multiple\">";
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 (tick those you wish to BLOCK)</td><td>";
+
+ // TODO: deal with block bit
+ echo "<tr><td>Provides (tick those you wish to BLOCK - not implemented)</td><td>";
foreach($glt["knownrepo"] as $key => $val) {
$reponame = $kos["apt"][$val["name"]];
$a = "";
if($glt["knownrepo"][$key]["amd64"]) $b = "x86_64";
if($a != "" && $b != "") $archs = "$a/$b";
else $archs = "$a$b";
- echo "<input type=\"checkbox\" name=\"$val\"> $reponame ($archs)<br>";
+ echo "<input type=\"checkbox\" name=\"blocked-".$val["name"]."\"> $reponame ($archs)<br>";
}
echo "</td></tr>";
$init = false;
if(isset($_REQUEST["initial"])) $init = true;
+ $blocklist = null;
+ $bn = 0;
+ foreach($_REQUEST as $key => $val) {
+ if(preg_match("/^blocked-*/", $key)) {
+ $blocked = preg_replace("/^blocked-/", "", $key);
+ //echo "<br>got block for $blocked<br>";
+ $blocklist[$bn] = "dists\/$blocked.*";
+ $bn++;
+ }
+ }
+ //echo "<pre>";
+ //print_r($_REQUEST);
+ //echo "</pre>";
- $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime);
+ //exit(0);
+
+ $repo->addRepo($desc, $OS, $version, $arch, "-", $shorturl, $prefix, $repurl, "APT", $init, $expiretime, $blocklist);
+
+ // next we need to deal with that "blocked" bit
global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
header("Location: $BASE_URL/admin/");
function doUpdateRepo($url)
{
$rkey = $_REQUEST["repo"];
+
+ error_log("would update for repo");
$repo = new GLCASRepo($this->config);
//echo "</pre>";
// wrap all this in a table
- echo "<table><tr><td valign=\"top\">";
+ echo "<table border=\"1\"><tr><td valign=\"top\">";
// now, add a repo
echo "<h3>Add A Repo</h3>";
echo "<form method=\"post\" action=\"?action=reponext\">";
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</option>";
echo "</select><br>";
echo "URL <input type=\"text\" name=\"repourl\"><br>";
echo "Hint <select name=\"repohint\">";
echo "<option value=\"fedora\">Fedora</option>";
echo "<option value=\"centos\">Centos</option>";
- echo "<option value=\"ubuntu\">Ubuntu</option>";
echo "</select><br>";
echo "URL <input type=\"text\" name=\"repourl\"><br>";
echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
echo "</form>";
- echo "</td></tr></table><hr>";
+ echo "</td><td valign=\"top\">";
+
+ // now for mirror lists
+ echo "<h3>Via Mirrolist - not implemented</h3>";
+ echo "<form method=\"post\" action=\"?action=mirrorlist\">";
+ echo "Distro <select name=\"mirrordistro\">";
+ echo "<option value=\"fedora\">Fedora</option>";
+ echo "<option value=\"centos\">Centos</option>";
+ echo "</select><br>";
+ echo "Architecture <select name=\"arch\">";
+ echo "<option value=\"x86_64\">64 bit</option>";
+ echo "<option value=\"i386\">32 bit</option>";
+ echo "</select><br>";
+ echo "Version <input type=\"text\" name=\"version\"><br>";
+ echo "Get updates too <input type=\"checkbox\" name=\"getupdates\"><br>";
+ echo "<input type=\"submit\" name=\"Scan\" value=\"Scan\"><br>";
+ echo "</form>";
+
+
+ echo "</td></tr></table>";
// repo storage location
echo "<h3>Storage<h3><br>";
echo "<form method=\"post\" action=\"?action=setstorage\">";
$storloc = $this->config->getConfigVar("storagelocation");
- echo "<input type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
+ echo "<input class=\"storage\" type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";
echo "</form>";
}
// ubuntu bit for apt
// TODO uncomment these ones out of testing
- /*$kos["apt"]["hardy"] = "Hardy Heron (8.04 LTS)";
- $kos["apt"]["hardy-backports"] = "Hardy Heron (8.04 LTS) Backports";
- $kos["apt"]["hardy-proposed"] = "Hardy Heron (8.04 LTS) Proposed";
- $kos["apt"]["hardy-security"] = "Hardy Heron (8.04 LTS) Security";
- $kos["apt"]["hardy-updates"] = "Hardy Heron (8.04 LTS) Updates";
+ $kos["apt"]["hardy"] = "Hardy Heron (8.04 LTS)";
$kos["apt"]["karmic"] = "Karmic Koala (9.10)";
- $kos["apt"]["karmic-backports"] = "Karmic Koala (9.10) Backports";
- $kos["apt"]["karmic-proposed"] = "Karmic Koala (9.10) Proposed";
- $kos["apt"]["karmic-security"] = "Karmic Koala (9.10) Security";
- $kos["apt"]["karmic-updates"] = "Karmic Koala (9.10) Updates";
$kos["apt"]["lucid"] = "Lucid Lynx (10.04 LTS)";
- $kos["apt"]["lucid-backports"] = "Lucid Lynx (10.04 LTS) Backports";
- $kos["apt"]["lucid-proposed"] = "Lucid Lynx (10.04 LTS) Proposed";
- $kos["apt"]["lucid-security"] = "Lucid Lynx (10.04 LTS) Security";
- $kos["apt"]["lucid-updates"] = "Lucid Lynx (10.04 LTS) Updates";
$kos["apt"]["maverick"] = "Maverick Meerkat (10.10)";
- $kos["apt"]["maverick-backports"] = "Maverick Meerkat (10.10) Backports";
- $kos["apt"]["maverick-proposed"] = "Maverick Meerkat (10.10) Proposed";
- $kos["apt"]["maverick-security"] = "Maverick Meerkat (10.10) Security";
- $kos["apt"]["maverick-updates"] = "Maverick Meerkat (10.10) Updates";*/
$kos["apt"]["natty"] = "Natty Narwhal (11.04)";
- $kos["apt"]["natty-backports"] = "Natty Narwhal (11.04) Backports";
- $kos["apt"]["natty-proposed"] = "Natty Narwhal (11.04) Proposed";
- $kos["apt"]["natty-security"] = "Natty Narwhal (11.04) Security";
- $kos["apt"]["natty-updates"] = "Natty Narwhal (11.04) Updates";
- /*$kos["apt"]["oneiric"] = "Oneiric Ocelot (11.10)";
- $kos["apt"]["oneiric-backports"] = "Oneiric Ocelot (11.10) Backports";
- $kos["apt"]["oneiric-proposed"] = "Oneiric Ocelot (11.10) Proposed";
- $kos["apt"]["oneiric-security"] = "Oneiric Ocelot (11.10) Security";
- $kos["apt"]["oneiric-updates"] = "Oneiric Ocelot (11.10) Updates";
+ $kos["apt"]["oneiric"] = "Oneiric Ocelot (11.10)";
$kos["apt"]["lenny"] = "Debian Lenny";
$kos["apt"]["sid"] = "Debian Sid";
$kos["apt"]["squeeze"] = "Debian Squeeze";
$kos["apt"]["wheezy"] = "Debian Wheezy";
$kos["apt"]["stable"] = "Debian Stable";
- $kos["apt"]["unstable"] = "Debian Unstable";*/
+ $kos["apt"]["unstable"] = "Debian Unstable";
}
if(!isset($repo["repotype"])) {
- echo "<font color=\"red\">Repo type not set for repo</font><br>";
+ echo "<font color=\"red\">Repo type not set for repo, setting to yum</font><br>";
+ $uconf[$rkey]["repotype"] = "YUM";
+ $this->config->setConfigVar("repodata", serialize($uconf));
+ $this->config->saveConfig();
} else if($repo["repotype"] == "YUM") {
if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) {
echo " - <font color=\"red\">Repo locked for update</font><br>";
echo " - not updating repo<br>";
}
} else if($repo["repotype"] == "APT") {
- echo "<font color=\"red\">I have no idea how to spawn an update of an APT repo - apt is crap</font><br>";
+ if(file_exists("$repostore/$rkey/update.lock")) {
+ echo " - <font color=\"red\">Repo locaked for update</font><br>";
+ }
+ echo " - Expire time is ".$repo["expiretime"]." days, checking repo<br>";
+ $maxtdiff = $repo["expiretime"] * 24 * 3600;
+ $this->updateRepo($rkey);
}
}
}
header("HTTP/1.0 404 Not Found");
return;
}
+
// something was matched, so now we reconstruct the file component of the url
// so, the ultimate url for the file we need is:
$actualfile = "$repostore/$matched/$file";
error_log("Atcualfile is $actualfile");
-
+
+ // now check for a block in that repo
+ if(isset($uconf[$matched]["blocklist"])) {
+ foreach($uconf[$matched]["blocklist"] as $blockers) {
+ $rfile = ltrim($file, "/");
+ error_log("checking $blockers against $rfile");
+ if(preg_match("/$blockers/", $rfile) > 0) {
+ error_log("should block");
+ header("HTTP/1.0 404 Not Found");
+ return;
+ }
+ }
+ }
+
// if its a directory, lets do a print
if(is_dir($actualfile)) {
$this->printDir($actualfile, $file, $url);
}
// this is a nightmare
- function getRepoForUrlOld($url)
- {
- // the way we breakdown a url is to explode it
- $xurl = split("[/,]", $url);
-
- // we first check if [0] is a prefix
- // if now, we check for it being a shorturl (lets just do that for now)
- $uconf = unserialize($this->config->getConfigVar("repodata"));
- $repostore = $this->config->getConfigVar("storagelocation");
-
- $matched = -1;
-
- // first we check for /repo/repoid as a url
- $startat = 0;
- if($xurl[0] == "repo") {
- $repid = $xurl[1];
- error_log("trying to get repo for repoid, $repid");
- if(isset($uconf[$repid])) {
- $matched = ((int)($repid));
- error_log("set matched, $matched, $repid");
- $startat +=2;
- }
- }
-
-
- $prematch = false;
- if($matched < 0) foreach($uconf as $key => $var) {
- $pre = $var["prefix"];
-
- if($pre!="") {
- //echo "Checking pre $pre against ".$xurl[0]."\n";
- if(strcasecmp($pre, $xurl[0])==0) {
- //echo "Matched pre\n";
- $prematch = true;
- $startat++;
- }
- }
- }
-
-
- if($matched < 0) foreach($uconf as $key => $var) {
- // if we matched a pre, then we check against the second url component
-
- $short = $var["shorturl"];
-
- if($short!="") {
- //echo "Checking short $short against ".$xurl[$startat]."\n";
- if(strcasecmp($xurl[$startat], $short)==0) {
- //echo "Matched\n";
- $matched = $key;
- $startat++;
- }
- }
- }
-
- if($matched < 0) {
- echo "No such repo<br>";
- return;
- }
-
- // now we find an actual file
- $file = "/";
- if(count($xurl) > $startat) for($i=$startat; $i < count($xurl); $i++) {
- $file .= "/".$xurl[$i];
- }
-
- // now we want to find repostore/$matched/$file;
- $actualfile = "$repostore/$matched/$file";
- error_log("Atcualfile is $actualfile");
- //echo "Start file for $actualfile\n";
-
- // first check any directories in $file are in existence
- $splfile = explode("/", $file);
- if(count($splfile) > 1) {
- $tomake = "$repostore/$matched/";
- for($i = 0; $i < count($splfile)-1; $i++) {
- $tomake .= "/".$splfile[$i];
- //error_log("making directory $tomake");
- if(!is_dir($tomake)) mkdir($tomake);
- }
- }
-
- $reqhead = print_r($_REQUEST, true);
- $sevhead = print_r($_SERVER, true);
-
- error_log("req $reqhead");
- error_log("sev $sevhead");
-
- $rangestart = -1;
- $rangelength = -1;
- $rangesstr = "";
- if(isset($_SERVER["HTTP_RANGE"])) {
- // oh shit
- $rangesa = explode("=", $_SERVER["HTTP_RANGE"]);
- $rangesb = explode(",", $rangesa[1]);
- $rangesstr = $rangesb[0];
- $ranges = explode("-", $rangesb[0]);
- $rangestart = $ranges[0];
- $rangelength = $ranges[1] - $ranges[0] +1;
- error_log("going ranges at $rangestart, $rangelength,".$rangesa[1].",".$rangesb[0]);
- }
-
- // i have to support http_range cause REDHAT/CENTOS IS annoying as all hell. christ, why do this?
- if(is_file($actualfile)) {
- // file is stored locally, away we go
- if($rangelength != -1) {
- header("HTTP/1.1 206 Partial Content");
- header("Content-Length: ".$rangelength);
- header("Content-Range: bytes $rangesstr/".filesize($actualfile));
- //header("Content-Length: ".filesize($actualfile));
- } else {
- header("Content-Length: ".filesize($actualfile));
- }
- $type = mime_content_type($actualfile);
- header("Content-type: $type");
- $localfile = fopen($actualfile, "r");
- if($rangestart!=-1) fseek($localfile, $rangestart, SEEK_SET);
- while(!feof($localfile)) {
- // cant make this high cause centos is crap
- if($rangelength!=-1) {
- $data = fread($localfile, $rangelength);
- error_log("data size was ".strlen($data));
- } else {
- $data = fread($localfile, 2048);
- }
-
- echo $data;
- flush();
-
- if($rangelength!=-1) {
- fclose($localfile);
- exit(0);
- }
- }
- fclose($localfile);
- } else if(is_dir($actualfile)) {
- //echo "in dir for $actualfile\n";
- // here we print the contents of the directory
- $this->printDir($actualfile, $file, $url);
- } else {
- // ok, get the file
- //echo "in getcheck\n";
- $remotefile = $uconf[$matched]["url"]."/$file";
-
- // TODO: i should get remote contents with fopen/fread/fwrite as
- // it should be more memory conservative and we can push to the end client
- // straight away
- ignore_user_abort(true);
- $rf = fopen($remotefile, "r");
- error_log("attempting to get remote file $remotefile");
-
-
- // hopefully this works. if we get a 30x message, it means we tried to get a directory
- // i cant think of another way of dealing with it - but this is UGLY
- // also get content length and content type
- $clen = 0;
- foreach($http_response_header as $key => $val) {
- if(preg_match("/HTTP.*30[1-9].*/", $val)) {
- error_log("got a 30x, must be a directory");
- mkdir($actualfile);
- header("Location: ".$_SERVER["REQUEST_URI"]."/");
- return;
- }
- // get content length form upstream and print
- if(preg_match("/^Content-Length:.*/", $val)) {
- $clen = $val;
- header($val);
- }
- // get content type from upstream and print
- if(preg_match("/^Content-Type:.*/", $val)) {
- header($val);
- }
- }
- //error_log("repsonse: $http_response_header");
- if(!$rf) {
- // return 404
- header("HTTP/1.0 404 Not Found");
- } else {
- $localfile = fopen($actualfile.".tmp.data.deleteme", "w");
- $localsizefile = fopen($actualfile.".tmp.data.deleteme.size", "w");
- fwrite($localsizefile, "$clen");
- fclose($localsizefile);
- while(!feof($rf)) {
- $data = fread($rf, 8192);
- echo $data;
- fwrite($localfile, $data);
- flush();
- }
- fclose($localfile);
- fclose($rf);
- rename($actualfile.".tmp.data.deleteme", $actualfile);
- //error_log("got actualfile, tried to save as $actualfile, did it work?");
- }
- }
-
- //echo "got ".$file." for $url which is $actualfile\n";
-
- //echo "</html></pre>";
- }
function printDir($dir, $localfile, $baseurl)
{
}
}
- function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime)
+ function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime, $blocklist=null)
{
$uconf = $this->config->getConfigVar("repodata");
$cs["url"] = $repurl;
$cs["repotype"] = $repotype;
$cs["expiretime"] = $expiretime;
+ if($blocklist != null) {
+ $cs["blocklist"] = $blocklist;
+ }
$ckey = 0;
function updateRepo($repokey)
{
// we only do yum yet
- $this->updateRepoYum($repokey);
+ $repod = $this->getRepo($repokey);
+
+ error_log("in update repo");
+
+ if($repod["repotype"] == "YUM") $this->updateRepoYum($repokey);
+ if($repod["repotype"] == "APT") $this->updateRepoApt($repokey);
+ }
+
+ function updateRepoApt($repokey)
+ {
+ $repostore = $this->config->getConfigVar("storagelocation");
+
+ $repod = $this->getRepo($repokey);
+
+ $repourl = $repod["url"];
+
+ if(!file_exists("$repostore/$repokey")) {
+ mkdir("$repostore/$repokey");
+ }
+
+ error_log("background apt repo update, start");
+ global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+ if(file_exists("$WEB_ROOT_FS/../bin/downloadfile.php")) {
+ $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/updateaptrepo.php '$repourl' '$repostore/$repokey/' > /tmp/updateaptrepo.$repokey.log 2>&1 &";
+ system($scall);
+ } else {
+ error_log("cant find download apt helper... dieing");
+ }
}
function updateRepoYum($repokey)