error_log("set storage location, $storloc");
}
}
-
+
function go($url)
{
error_log("repo:go called");
-
- // figure out what we're doing
+
+ // figure out what we're doing
switch($url) {
case "list":
GLCASpageBuilder($this, "body");
$this->getRepoForUrl($url);
}
}
-
+
function body($url)
{
// this is how this will work
}
echo "i am the repo, $url";
}
-
-
+
+
// TODO: rework this function
/*
- * What i need to do is have a downloader function
- * that can cope with lots of different shit
- * but thats a pipe dream
- *
- * what *THIS* function needs to do is
- * 1) figure out the repo
- * 2) figure out the file in the repo
- * 2.1) if its a directory, go to print directory
- * 3) if the file exists, give it to the user (if a range is specified give the user the range)
- * 4) if the file does not exist
- * - check if a tmp file exists
- * - attempt to get an exclusive flock
- * - if flock fails, donwload in progress
- * - if flock succeeds, truncate file and re-start download
- * - if a range request was made, send the range once available
- * - if range not available, sleep for 5 and check again.
- *
- * I dont want to code this from scratch, but i probably need to
- */
+ * What i need to do is have a downloader function
+ * that can cope with lots of different shit
+ * but thats a pipe dream
+ *
+ * what *THIS* function needs to do is
+ * 1) figure out the repo
+ * 2) figure out the file in the repo
+ * 2.1) if its a directory, go to print directory
+ * 3) if the file exists, give it to the user (if a range is specified give the user the range)
+ * 4) if the file does not exist
+ * - check if a tmp file exists
+ * - attempt to get an exclusive flock
+ * - if flock fails, donwload in progress
+ * - if flock succeeds, truncate file and re-start download
+ * - if a range request was made, send the range once available
+ * - if range not available, sleep for 5 and check again.
+ *
+ * I dont want to code this from scratch, but i probably need to
+ */
function getRepoForUrl($url)
{
$xurl = split("[/,]", $url);
-
- // first get the config
+
+ // first get the config
$uconf = unserialize($this->config->getConfigVar("repodata"));
$repostore = $this->config->getConfigVar("storagelocation");
-
+
// preset matched to -1
$matched = -1;
-
+
// first we check for /repo/repoid as a url
$startat = 0;
if($xurl[0] == "repo") {
$startat +=2;
}
}
-
+
// now check for a prefix match
$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) {
}
}
}
-
+
// next, check for a short url match
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) {
}
}
}
-
+
// TODO: this deterministic bit
// so far nothing has matched - what this next bit needs to do is try and "Determine" a repo from url
// for eg, if a user gets /fedora/x86_64/os we need to return something appropriate
header("HTTP/1.0 404 Not Found");
return;
}
-
-
+
+
// something was matched, so now we reconstruct the file component of the url
$file = "/";
if(count($xurl) > $startat) for($i=$startat; $i < count($xurl); $i++) {
$file .= "/".$xurl[$i];
}
-
+
// so, the ultimate url for the file we need is:
$actualfile = "$repostore/$matched/$file";
error_log("Atcualfile is $actualfile");
-
+
// if its a directory, lets do a print
if(is_dir($actualfile)) {
$this->printDir($actualfile, $file, $url);
return;
}
-
+
// check if the file exists and serve it up
- if(file_exists($actualfile)) {
+ if(file_exists($actualfile) && !file_exists("$actualfile.size")) {
$this->serveUpFile($actualfile, $matched);
return;
} else {
return;
}
}
-
+
function serveUpFile($actualfile, $repoid)
{
$uconf = unserialize($this->config->getConfigVar("repodata"));
$repostore = $this->config->getConfigVar("storagelocation");
-
+
// figure out the range header garbage that centos/redhat send
if(isset($_SERVER["HTTP_RANGE"])) {
// we're using ranges - screw you stupid installer
$pr_range = preg_split("/[:\-=, ]+/", $_SERVER["HTTP_RANGE"]);
-
+
// cut up ranges
$rangestart = $pr_range[1];
$rangelength = $pr_range[2] - $pr_range[1] +1;
$rangestr = $pr_range[1]."-".$pr_range[2];
error_log("going ranges at $rangestart, $rangelength,".$rangesa[1].",".$rangesb[0]);
-
+
// now spit some headers
header("HTTP/1.1 206 Partial Content");
header("Content-Length: ".$rangelength);
-
+
- header("Content-Range: bytes $rangesstr/".filesize($actualfile));
-
+ header("Content-Range: bytes $rangestr/".filesize($actualfile));
+
// determine mime type
$type = mime_content_type($actualfile);
-
+
// set mime type header
header("Content-type: $type");
-
+
// open the local file (TODO: error check)
$localfile = fopen($actualfile, "r");
fseek($localfile, $rangestart, SEEK_SET);
-
+
// read in the data, god i hope its not big
$data = fread($localfile, $rangelength);
-
+
// lastly, send data
echo $data;
flush();
-
+
// and close the file
fclose($localfile);
return;
// set the mime type header
$type = mime_content_type($actualfile);
header("Content-type: $type");
-
- // open the local file
+
+ // open the local file
$localfile = fopen($actualfile, "r");
if(!$localfile) {
error_log("normal upload went barf");
return;
}
-
+
// iterate over its length, send 8k at a time
while(!feof($localfile)) {
// read and send data
$data = fread($localfile, 8192);
echo $data;
-
+
// flush so the client sees the data
flush();
}
-
+
// close the file
fclose($localfile);
return;
- }
+ }
}
-
+
// TODO: this is the function im working on
// the alternative to this function is that if a file is in the process of being
// downloaded, we simply serve from upstream... not a good idea tho unless we create
// a local proxy right here
function downloadAndServe($filename, $repoid, $remoteurl)
{
- // this is important so downloads dont die
+
+ $this->startDownload($filename, $remoteurl);
+
+ // give the proc a minute to get going
+ sleep(2);
clearstatcache();
- ignore_user_abort(true);
-
+
// get the configurations we need
$uconf = unserialize($this->config->getConfigVar("repodata"));
$repostore = $this->config->getConfigVar("storagelocation");
-
- // this is the tricky one for ranges.
-
- // check if a download exists
- $otherdownloader = false;
- if(file_exists("$filename.tmp.data.deleteme")) {
- // a download exists, does it still work
- error_log("DOWNLOADER: file exists for current download, hope it works, attempting lock");
- $localtmpfh = fopen("$filename.tmp.data.deleteme", "r");
- $lockres = flock($localtmpfh, LOCK_EX|LOCK_NB);
- if(!$lockres) {
- error_log("flock did fail, all is right with the world a download is in progress");
- $otherdownloader = true;
- } else {
- error_log("lock succeeded, dieing in the arse");
- unlink("$filename.tmp.data.deleteme");
- unlink("$filename.tmp.data.deleteme.size");
- }
- }
- // open the remote file
- $contentlen = 0;
- $contenttype = "";
- if(!$otherdownloader) {
- $remotefile = fopen($remoteurl, "r");
- $localfile = fopen($filename.".tmp.data.deleteme", "w");
- $lockres = flock($localfile, LOCK_EX);
- if(!$localfile) {
- erorr_log("something went plop");
- return;
- }
- // get the headers from the remote request and use them to hurt people
- $contentlen = 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($filename);
- header("Location: ".$_SERVER["REQUEST_URI"]."/");
- return;
- }
- // get content length form upstream and print
- if(preg_match("/^Content-Length:.*/", $val)) {
- // WARNING, THIS IS NOT RIGHT
- $clentemp = preg_split("/[: ]+/", $val);
- $contentlen = $clentemp[1];
- //header($val);
- }
- // get content type from upstream and print
- if(preg_match("/^Content-Type:.*/", $val)) {
- $contenttype = $val;
- }
- if(!$remotefile) {
- header("HTTP/1.0 404 Not Found");
- error_log("asked fore file that dont exist");
- return;
- }
-
- }
- error_log("put contentlen as $contentlen");
- file_put_contents($filename.".tmp.data.deleteme.size", $contentlen);
- } else {
- $localfile = fopen($filename.".tmp.data.deleteme", "r");
- if(!$localfile) {
- error_log("something went plop");
- return;
- }
- }
-
-
-
+
+
// determine if we're ranged
$ranged = false;
$rangestart = 0;
$rangestr="";
if(isset($_SERVER["HTTP_RANGE"])) {
// we're using ranges - screw you stupid installer
-
+
$pr_range = preg_split("/[:\-=, ]+/", $_SERVER["HTTP_RANGE"]);
error_log("got range ".$_SERVER["HTTP_RANGE"]." and ".print_r($pr_range, true));
-
+
// cut up ranges
$rangestart = $pr_range[1];
$rangelength = $pr_range[2] - $pr_range[1] +1;
$rangestr = $pr_range[1]."-".$pr_range[2];
- error_log("going ranges at $rangestart, $rangelength,");
+ error_log("going ranges at $rangestart, $rangelength, $rangestr");
$ranged = true;
}
-
+
// open the local files
-
+
// now, lets determine what state we're in
// we're either - getting and sending
// watching and sending
// or a range (watching and sending)
// TODO: it may be advicable to start the download as a seperate cli process rather then something goin on here
// so it definitely cant be interrupted.
-
-
+
+
+
// first, getting and sending - this is easy.
- if(!$ranged && !$otherdownloader) {
- while(!feof($remotefile)) {
- $data = fread($remotefile, 2048);
- echo $data;
- flush();
- fwrite($localfile, $data);
- }
- rename($filename.".tmp.data.deleteme", $filename);
- unlink($filename.".tmp.data.deleteme.size");
-
- // and we're done
- return;
-
-
-
-
- // IT WORKS!!!!!!!
- } else if ($otherdownloader && !$ranged) {
+ if (!$ranged) {
+
+ $localfile = fopen($filename, "r");
+
// this is where the fun starts - but this one isnt too bad.
error_log("OTHERDOWNLOAD: im another downloader, please work");
- $fsize = file_get_contents($filename.".tmp.data.deleteme.size");
+ $fsize = file_get_contents("$filename.size");
header("Content-Length: $fsize");
$sgotten = 0;
- while(!feof($localfile)) {
+ while(!feof($localfile)) {
error_log("OTHERDOWNLOAD: get");
$data = fread($localfile, 2048);
if(!$data) {
}
}
fclose($localfile);
-
+
// need to think about this in pseudo code.
// 1. close the file and wait for it to get to $sgotten + 2048 or $fsize
- if(file_exists($filename.".tmp.data.deleteme")) $cursize = filesize($filename.".tmp.data.deleteme");
- else if(file_exists($filename)) {
- error_log("DOTHERDOWNLOADER: namechange");
- $cursize = filesize($filename);
- } else return; // we had to bail
-
-
+ $cursize = filesize($filename);
+
$upload_finished = false;
while(!$upload_finished) {
while($cursize < $fsize && $cursize < ($sgotten+2048)) {
error_log("OTHERDOWNLOAD: halt, $cursize, $sgotten, $fsize");
// sleep until the the filesize is greater then what we're up to, or until the file is finished
sleep(1);
- if(file_exists($filename.".tmp.data.deleteme")) {
- error_log("OTHERDOWNLOADER: still same name");
- $cursize = filesize($filename.".tmp.data.deleteme");
- } else if(file_exists($filename)) {
- error_log("DOTHERDOWNLOADER: namechange");
- $cursize = filesize($filename);
- }
- else return; // we had to bail
+ $cursize = filesize($filename);
}
-
+
error_log("OTHERDOWNLOAD: continue, $sgotten, $fsize");
// reopen local file - if it stopped existing, we need to deal with that
- if(file_exists($filename.".tmp.data.deleteme")) $localfile = fopen($filename.".tmp.data.deleteme", "r");
- else if(file_exists($filename)) $localfile = fopen($filename, "r");
- else return; // we had to bail
-
+ $localfile = fopen($filename, "r");
+
// UG, we need to ff, how could i forget that
fseek($localfile, $sgotten);
-
+
if(!$localfile) {
error_log("OTHERDOWNLOAD: something went plop");
return;
}
-
+
// now loop on the file until we have it at an eof
- while(!feof($localfile)) {
+ while(!feof($localfile)) {
$data = fread($localfile, 512);
if(!$data) {
error_log("OTHERDOWNLOAD: dollar data went plop");
}
}
fclose($localfile);
-
+
if($sgotten >= $fsize) {
if($sgotten > $fsize) error_log("OTHERDOWNLOADER: finished but $sgotten, $fsize doesnt make senze");
$upload_finished = true;
}
// and we're done
-
+
}
error_log("OTHERDOWNLOADER: done with");
-
+
return;
-
-
-
- // THIS WAS JUST AWESOME CAUSE IT WORKS
- // Next painful bit
- } else if ($ranged && !$otherdownloader) {
-
+
+
+
+ // Next painful bit
+ } else {
+ // and here too, yay, someone else is doing the
+ // download, but we're the retards getting a range
$sgotten = 0;
-
-
+
+ $sgatlen = $rangestart+$rangelength;
+
// the problem is here
- error_log("Downloader: going ranged as primary");
+ error_log("Downloader: going ranged as other");
clearstatcache();
+ $contentlen = file_get_contents($filename.".tmp.data.deleteme.size");
+ $contenttype = mime_content_type($filename);
header("HTTP/1.1 206 Partial Content");
- header("Content-Length: ".$rangelength);
- header("Content-Range: bytes $rangestr/".$contentlen);
- header("Content-Type: $contenttype");
- header("Connection: close");
-
- // first, get up to $rangestart
- while(!feof($remotefile) && ftell($remotefile) < $rangestart) {
- if(($rangestart - ftell($remotefile)) < 2048) $rsize = $rangestart;
- else $rsize = 2048;
- $data = fread($remotefile, $rsize);
- if(!$data) {
- error_log("dollar data went plop");
- } else {
- $sgotten += strlen($data);
- flush();
- fwrite($localfile, $data);
- }
- }
+ header("Content-Length: $rangelength");
+ header("Content-Range: bytes $rangestr/$contentlen");
+ $contenttype = "Content-Type: application/x-rpm";
+
+ error_log("$contenttype");
+ header("$contenttype");
- error_log("should now be at rangestart: ".ftell($remotefile));
- // now start pumping out data until $rangelength
- $sgatlen = $rangelength + $rangestart;
- while(!feof($remotefile) && ftell($remotefile) < $sgatlen ) {
+ clearstatcache();
- // read only 2048
- $rsize = $sgatlen - ftell($remotefile);
- if($rsize > 2048) $rsize = 2048;
+ error_log("OTHERDOWNLOAD: im another downloader, please work for ranged");
- $data = fread($remotefile, $rsize);
- if(!$data) {
- error_log("dollar data went plop");
- } else {
- echo $data;
- $sgotten += strlen($data);
- flush();
- fwrite($localfile, $data);
- }
+
+ error_log("OTHERDOWNLOAD: im another downloader, please work");
+
+ // first we wait until the file reaches $rangestart
+ while(filesize("$filename") < $rangestart) {
+ sleep(1);
}
-
- // hopefully this works, the redhat/centos installer really is a terrible
- // piece of code.. The reasons for this is that redhat in their minds decided
- // to use ranges, and even though you send the range to the client, the client
- // just keeps listening. and you can ignore the range request, it ignores you.
-
- error_log("should now be at rangeend: $sgatlen, $rangestart, ".ftell($remotefile));
- flush();
-
- // now continue on as per normal - totally gunna work...
- while(!feof($remotefile)) {
- //error_log("back download");
- $data = fread($remotefile, 2048);
- flush();
- fwrite($localfile, $data);
+
+ // then we open the file and ff to rangestart
+ $localfile = fopen($filename, "r");
+ fseek($localfile, $rangestart);
+
+ $sgotten = 0;
+ // need to think about this in pseudo code.
+ // 1. close the file and wait for it to get to $sgotten + 2048 or $fsize
+ $cursize = filesize($filename.".tmp.data.deleteme");
+
+
+ $upload_finished = false;
+ while(!$upload_finished) {
+ while($cursize < $sgatlen && $cursize < ($sgotten+2048)) {
+ clearstatcache();
+ error_log("OTHERDOWNLOAD: halt, $cursize, $sgotten, $contentlen");
+ // sleep until the the filesize is greater then what we're up to, or until the file is finished
+ sleep(1);
+ $cursize = filesize($filename);
+ }
+
+ error_log("OTHERDOWNLOAD: continue, $sgotten, $contentlen");
+ // reopen local file - if it stopped existing, we need to deal with that
+ $localfile = fopen($filename, "r");
+
+ // UG, we need to ff, how could i forget that
+ fseek($localfile, $sgotten+$rangestart);
+
+ if(!$localfile) {
+ error_log("OTHERDOWNLOAD: something went plop");
+ return;
+ }
+
+ // now loop on the file until we have it at sgatlen
+ while(!feof($localfile) && $sgotten < $rangelength) {
+ $left = $rangelength - $sgotten;
+ if($left > 512) $lenget = 512;
+ else $lenget = $left;
+ $data = fread($localfile, $lenget);
+ if(!$data) {
+ error_log("OTHERDOWNLOAD: dollar data went plop");
+ } else {
+ $sgotten += strlen($data);
+ echo $data;
+ flush();
+ }
+ }
+ fclose($localfile);
+
+ if($sgotten >= $rangelength) {
+ if($sgotten > $rangelength) error_log("OTHERDOWNLOADER: finished but $sgotten, $fsize doesnt make senze");
+ $upload_finished = true;
+ }
+ // and we're done
+
}
-
-
- rename($filename.".tmp.data.deleteme", $filename);
- unlink($filename.".tmp.data.deleteme.size");
-
- // and we're done
+ error_log("OTHERDOWNLOADER: done with");
+
return;
-
-
-
-
-
- // and here
- } else if ($ranged && $otherdownloader) {
- // and here too, yay, someone else is doing the
- // download, but we're the retards getting a range
- $sgotten = 0;
-
-
- // the problem is here
- error_log("Downloader: going ranged as primary");
- clearstatcache();
- header("HTTP/1.1 206 Partial Content");
- header("Content-Length: ".$rangelength);
- header("Content-Range: bytes $rangestr/".$contentlen);
- header("Content-Type: $contenttype");
- clearstatcache();
-
- error_log("OTHERDOWNLOAD: im another downloader, please work for ranged");
-
+
}
-
-
+
+
return;
}
-
+
+ function startDownload($file, $url)
+ {
+
+ error_log("background downloader, 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/downloadfile.php '$url' '$file' > /dev/null 2>&1 &";
+ system($scall);
+ error_log("started as v, $v, $scall");
+ } else {
+ error_log("cant find download helper... dieing");
+ }
+ }
+
// 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") {
$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) {
}
}
}
-
-
+
+
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) {
}
}
}
-
+
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) {
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 = "";
$rangesstr = $rangesb[0];
$ranges = explode("-", $rangesb[0]);
$rangestart = $ranges[0];
- $rangelength = $ranges[1] - $ranges[0] +1;
+ $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
} else {
$data = fread($localfile, 2048);
}
-
+
echo $data;
flush();
-
+
if($rangelength!=-1) {
fclose($localfile);
exit(0);
// 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
$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
}
// get content type from upstream and print
if(preg_match("/^Content-Type:.*/", $val)) {
- header($val);
+ header($val);
}
}
//error_log("repsonse: $http_response_header");
// return 404
header("HTTP/1.0 404 Not Found");
} else {
- $localfile = fopen($actualfile.".tmp.data.deleteme", "w");
+ $localfile = fopen($actualfile.".tmp.data.deleteme", "w");
$localsizefile = fopen($actualfile.".tmp.data.deleteme.size", "w");
fwrite($localsizefile, "$clen");
- fclose($localsizefile);
+ fclose($localsizefile);
while(!feof($rf)) {
$data = fread($rf, 8192);
echo $data;
//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)
{
$localfile = preg_replace("/\/\/+/", "/", $localfile);
if($file != "." && $file != "..") $content .= "<tr><td><a href=\"$uri/$file\">$file</a></td></tr>";
}
$content .= "</table></body></html>";
-
+
GLCASpageBuilder(null, null, $content);
-
+
} else return false;
}
-
+
function getRepoDetailsYum($url, $ismirrorlist=false)
{
$actionurl = $url."/repodata/repomd.xml";
-
+
error_log("Getting for action of $actionurl");
-
+
$ld = file_get_contents($actionurl);
-
+
// so here we try and get what this repository provides (os, version, arch), for yum this
// should come straight off the url... i.e. centos/6.0/os/x86_64/ (centos, 6.0, base os, 64bit arch)
-
+
if(!$ld) return false;
-
+
// ok, now we tokenize the url and try and guess at the content
$spurl = explode("/", $url);
-
+
// first, find the OS
$kos = getKnownOSList();
$glt["OS"] = "unknown";
$glt["arch"] = "unknown";
$glt["other"] = "unknown";
foreach($spurl as $comp) {
-
+
// find a name
foreach($kos["os"]["short"] as $kosname => $koslong) {
//error_log("Comparing $kosname and $koslong with $comp");
$glt["OS"] = $koslong;
}
}
-
+
// find a version, we assume its going to be something [numbers] and a . (optional)
if(preg_match("/^[0-9.]+$/", $comp)>0) {
//error_log("version match of $comp");
$glt["version"] = $comp;
}
-
+
// now architecture, this can be either i?86 or x86_64 - can also be arm or otherwise, but lets just go with this for now
foreach($kos["arch"] as $archinter => $archname ) {
//error_log("Comparing $archinter, $archname with $comp");
$glt["arch"] = $archname;
}
}
-
+
// other is a bt harder, we really have to guess at this one
if(strcasecmp("os", $comp) == 0) $glt["other"] = "OS";
if(strcasecmp("update", $comp) == 0) $glt["other"] = "Updates";
if(strcasecmp("updates", $comp) == 0) $glt["other"] = "Updates";
if(strcasecmp("everything", $comp) == 0) $glt["other"] = "OS";
}
-
+
return $glt;
}
-
+
function deleteRepo($rkey)
{
$uconf = $this->config->getConfigVar("repodata");
$repostore = $this->config->getConfigVar("storagelocation");
-
+
if($uconf !== false) {
$conf = unserialize($uconf);
foreach($conf as $key => $vla) {
}
}
}
-
+
function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init)
{
$uconf = $this->config->getConfigVar("repodata");
-
+
$cs["desc"] = $desc;
$cs["os"] = $os;
$cs["version"] = $version;
$cs["prefix"] = $prefix;
$cs["url"] = $repurl;
$cs["repotype"] = $repotype;
-
-
+
+
$ckey = 0;
if($uconf !== false) {
$conf = unserialize($uconf);
}
$ckey++;
}
-
+
$conf[$ckey] = $cs;
-
+
$nconf = serialize($conf);
-
+
error_log("add repo as $ckey");
$this->config->setConfigVar("repodata", $nconf);
$this->config->saveConfig();
-
+
// now create the base structure in the repo
$repostore = $this->config->getConfigVar("storagelocation");
-
-
+
+
// now call update repo
if($init) $this->updateRepoYum($ckey);
}
-
+
function updateRepo($repokey)
{
// we only do yum yet
$this->updateRepoYum($repokey);
}
-
+
function updateRepoYum($repokey)
{
$repostore = $this->config->getConfigVar("storagelocation");
-
+
$repod = $this->getRepo($repokey);
-
+
$repourl = $repod["url"];
-
+
if(!file_exists("$repostore/$repokey")) {
mkdir("$repostore/$repokey");
}
-
+
if(!file_exists("$repostore/$repokey/repodata")) {
mkdir("$repostore/$repokey/repodata");
}
-
+
//ignore_user_abort(true);
$actionurl = "$repourl/repodata/repomd.xml";
$repomdxml = file_get_contents($actionurl);
file_put_contents("$repostore/$repokey/repodata/repomd.xml", $repomdxml);
-
+
$xml = simplexml_load_file("$repostore/$repokey/repodata/repomd.xml");
-
-
+
+
foreach($xml as $key => $var) {
//echo "for key $key has:\n";
//print_r($var);
}
}
}
-
+
function getRepo($id)
{
$uconf = $this->config->getConfigVar("repodata");
$lconf = unserialize($uconf);
return $lconf[$id];
} else return false;
-
+
}
-
+
function getRepos()
{
$uconf = $this->config->getConfigVar("repodata");
if($uconf !== false) {
return unserialize($uconf);
} else return false;
-
+
}
-
+
private $config;
}