2 $URL_HANDLERS["*"] = "GLCASRepo";
4 $CRON_CLASSES["GLCASRepo"] = "GLCASRepo";
7 function __construct($config)
9 $this->config = $config;
10 if($this->config->getConfigVar("storagelocation") == false) {
12 $storloc = "$WEB_ROOT_FS/../var/glcas/cache/";
13 if(!file_exists($storloc)) mkdir($storloc);
14 $this->config->setConfigVar("storagelocation", realpath($storloc));
15 $this->config->saveConfig();
16 error_log("set storage location, $storloc");
23 $uconf = unserialize($this->config->getConfigVar("repodata"));
24 $repostore = $this->config->getConfigVar("storagelocation");
28 foreach($uconf as $rkey => $repo) {
29 echo "Repo $rkey: ".$repo["desc"]."<br>";
30 if(!isset($repo["expiretime"])) {
31 echo " - Expire time not set, setting to 2 days by default<br>";
32 $uconf[$rkey]["expiretime"] = 2;
33 $repo["expiretime"] = 2;
34 $this->config->setConfigVar("repodata", serialize($uconf));
35 $this->config->saveConfig();
38 if(!isset($repo["repotype"])) {
39 echo "<font color=\"red\">Repo type not set for repo</font><br>";
40 } else if($repo["repotype"] == "YUM") {
41 if(file_exists("$repostore/$rkey/repodata/repoupdate.lock")) {
42 echo " - <font color=\"red\">Repo locked for update</font><br>";
46 // we still do this next bit, even if its locked because it may be a stray file
47 echo " - Expire time is ".$repo["expiretime"]." days, checking repo<br>";
48 error_log("checking $repostore/$rkey/repodata/repomd.xml");
49 $tdiff = time() - filemtime("$repostore/$rkey/repodata/repomd.xml");
50 $maxtdiff = $repo["expiretime"] * 24 * 3600;
51 if($tdiff > $maxtdiff) {
52 echo " - <font color=\"green\">updating repo</font><br>";
53 $this->updateRepo($rkey);
55 echo " - not updating repo<br>";
57 } else if($repo["repotype"] == "APT") {
58 echo "<font color=\"red\">I have no idea how to spawn an update of an APT repo - apt is crap</font><br>";
65 error_log("repo:go called");
67 // figure out what we're doing
70 GLCASpageBuilder($this, "body");
73 $this->getRepoForUrl($url);
79 // this is how this will work
81 if(strncasecmp("list", $url, 4)==0) {
82 echo "i am the repo list";
85 echo "i am the repo, $url";
89 // TODO: rework this function
91 * What i need to do is have a downloader function
92 * that can cope with lots of different shit
93 * but thats a pipe dream
95 * what *THIS* function needs to do is
96 * 1) figure out the repo
97 * 2) figure out the file in the repo
98 * 2.1) if its a directory, go to print directory
99 * 3) if the file exists, give it to the user (if a range is specified give the user the range)
100 * 4) if the file does not exist
101 * - check if a tmp file exists
102 * - attempt to get an exclusive flock
103 * - if flock fails, donwload in progress
104 * - if flock succeeds, truncate file and re-start download
105 * - if a range request was made, send the range once available
106 * - if range not available, sleep for 5 and check again.
108 * I dont want to code this from scratch, but i probably need to
110 function getRepoForUrl($url)
112 $xurl = split("[/,]", $url);
114 // first get the config
115 $uconf = unserialize($this->config->getConfigVar("repodata"));
116 $repostore = $this->config->getConfigVar("storagelocation");
118 // preset matched to -1
121 // first we check for /repo/repoid as a url
123 if($xurl[0] == "repo") {
125 error_log("trying to get repo for repoid, $repid");
126 if(isset($uconf[$repid])) {
127 $matched = ((int)($repid));
128 error_log("set matched, $matched, $repid");
133 // now check for a prefix match
135 if($matched < 0) foreach($uconf as $key => $var) {
136 $pre = $var["prefix"];
139 //echo "Checking pre $pre against ".$xurl[0]."\n";
140 if(strcasecmp($pre, $xurl[0])==0) {
141 //echo "Matched pre\n";
148 // next, check for a short url match
149 if($matched < 0) foreach($uconf as $key => $var) {
150 // if we matched a pre, then we check against the second url component
152 $short = $var["shorturl"];
155 //echo "Checking short $short against ".$xurl[$startat]."\n";
156 if(strcasecmp($xurl[$startat], $short)==0) {
164 // TODO: this deterministic bit
165 // so far nothing has matched - what this next bit needs to do is try and "Determine" a repo from url
166 // for eg, if a user gets /fedora/x86_64/os we need to return something appropriate
168 echo "No such repo<br>";
169 header("HTTP/1.0 404 Not Found");
174 // something was matched, so now we reconstruct the file component of the url
176 if(count($xurl) > $startat) for($i=$startat; $i < count($xurl); $i++) {
177 $file .= "/".$xurl[$i];
180 // so, the ultimate url for the file we need is:
181 $actualfile = "$repostore/$matched/$file";
182 error_log("Atcualfile is $actualfile");
184 // if its a directory, lets do a print
185 if(is_dir($actualfile)) {
186 $this->printDir($actualfile, $file, $url);
190 // check if the file exists and serve it up
191 if(file_exists($actualfile) && !file_exists("$actualfile.size")) {
192 $this->serveUpFile($actualfile, $matched);
195 // the file does not exist, we now need to go into "download" mode
196 $remoteurl = $uconf[$matched]["url"]."/$file";
197 $this->downloadAndServe($actualfile, $matched, $remoteurl);
202 function serveUpFile($actualfile, $repoid)
204 $uconf = unserialize($this->config->getConfigVar("repodata"));
205 $repostore = $this->config->getConfigVar("storagelocation");
207 // figure out the range header garbage that centos/redhat send
208 if(isset($_SERVER["HTTP_RANGE"])) {
209 // we're using ranges - screw you stupid installer
210 $pr_range = preg_split("/[:\-=, ]+/", $_SERVER["HTTP_RANGE"]);
213 $rangestart = $pr_range[1];
214 $rangelength = $pr_range[2] - $pr_range[1] +1;
215 $rangestr = $pr_range[1]."-".$pr_range[2];
216 error_log("going ranges at $rangestart, $rangelength,".$rangesa[1].",".$rangesb[0]);
218 // now spit some headers
219 header("HTTP/1.1 206 Partial Content");
220 header("Content-Length: ".$rangelength);
223 header("Content-Range: bytes $rangestr/".filesize($actualfile));
225 // determine mime type
226 $type = mime_content_type($actualfile);
228 // set mime type header
229 header("Content-type: $type");
231 // open the local file (TODO: error check)
232 $localfile = fopen($actualfile, "r");
233 fseek($localfile, $rangestart, SEEK_SET);
235 // read in the data, god i hope its not big
236 $data = fread($localfile, $rangelength);
242 // and close the file
247 // we're not using range's - good on you installer thingy
248 header("Content-Length: ".filesize($actualfile));
250 // set the mime type header
251 $type = mime_content_type($actualfile);
252 header("Content-type: $type");
254 // open the local file
255 $localfile = fopen($actualfile, "r");
257 error_log("normal upload went barf");
261 // iterate over its length, send 8k at a time
262 while(!feof($localfile)) {
263 // read and send data
264 $data = fread($localfile, 32768);
267 // flush so the client sees the data
277 // TODO: this is the function im working on
278 // the alternative to this function is that if a file is in the process of being
279 // downloaded, we simply serve from upstream... not a good idea tho unless we create
280 // a local proxy right here - this function is a race condition waiting to be had
281 // lets hope its a good one!
282 function downloadAndServe($filename, $repoid, $remoteurl)
285 $this->startDownload($filename, $remoteurl);
287 // give the proc a minute to get going
291 // get the configurations we need
292 $uconf = unserialize($this->config->getConfigVar("repodata"));
293 $repostore = $this->config->getConfigVar("storagelocation");
297 // determine if we're ranged
302 if(isset($_SERVER["HTTP_RANGE"])) {
303 // we're using ranges - screw you stupid installer
305 $pr_range = preg_split("/[:\-=, ]+/", $_SERVER["HTTP_RANGE"]);
306 error_log("got range ".$_SERVER["HTTP_RANGE"]." and ".print_r($pr_range, true));
309 $rangestart = $pr_range[1];
310 $rangelength = $pr_range[2] - $pr_range[1] +1;
311 $rangestr = $pr_range[1]."-".$pr_range[2];
312 error_log("going ranges at $rangestart, $rangelength, $rangestr");
316 // open the local files
318 // now, lets determine what state we're in
319 // we're either - getting and sending
320 // watching and sending
321 // or a range (Getting and sending)
322 // or a range (watching and sending)
323 // TODO: it may be advicable to start the download as a seperate cli process rather then something goin on here
324 // so it definitely cant be interrupted.
326 // check for a 404 file and wait 2 if it exists - i should really check the timestamp for an updated
327 // file, but thats too much effort for now: TODO: check timestamp on 404 file
329 while(!file_exists("$filename")) {
333 error_log("Sleeping waiting for file");
335 // if 404 file exists, we wait much less time
336 if(file_exists("$filename.404") && $slept > 2) {
337 header("HTTP/1.0 404 Not Found");
341 header("HTTP/1.0 404 Not Found");
347 if(is_dir($filename)) {
349 header("Location: ".$_SERVER["REQUEST_URI"]."/");
354 // first, getting and sending - this is easy.
357 $localfile = fopen($filename, "r");
359 // this is where the fun starts - but this one isnt too bad.
360 error_log("OTHERDOWNLOAD: im another downloader, please work");
361 if(file_exists("$filename.size")) $fsize = file_get_contents("$filename.size");
362 else $fsize = filesize($filename);
363 header("Content-Length: $fsize");
365 while(!feof($localfile)) {
366 $data = fread($localfile, 2048);
368 error_log("dollardata is pair shaped");
370 $sgotten += strlen($data);
371 if($sgotten > $fsize) {
372 error_log("went plop at sgotten, $sgotten, $fsize");
381 // need to think about this in pseudo code.
382 // 1. close the file and wait for it to get to $sgotten + 2048 or $fsize
383 $cursize = filesize($filename);
385 $upload_finished = false;
386 while(!$upload_finished) {
387 while($cursize < $fsize && $cursize < ($sgotten+2048)) {
389 error_log("OTHERDOWNLOAD: halt, $cursize, $sgotten, $fsize");
390 // sleep until the the filesize is greater then what we're up to, or until the file is finished
392 $cursize = filesize($filename);
395 error_log("OTHERDOWNLOAD: continue, $sgotten, $fsize");
396 // reopen local file - if it stopped existing, we need to deal with that
397 $localfile = fopen($filename, "r");
399 // UG, we need to ff, how could i forget that
400 fseek($localfile, $sgotten);
403 error_log("OTHERDOWNLOAD: something went plop");
407 // now loop on the file until we have it at an eof
408 while(!feof($localfile)) {
409 $data = fread($localfile, 512);
411 error_log("OTHERDOWNLOAD: dollar data went plop");
413 $sgotten += strlen($data);
420 if($sgotten >= $fsize) {
421 if($sgotten > $fsize) error_log("OTHERDOWNLOADER: finished but $sgotten, $fsize doesnt make senze");
422 $upload_finished = true;
427 error_log("OTHERDOWNLOADER: done with");
436 // and here too, yay, someone else is doing the
437 // download, but we're the retards getting a range
440 $sgatlen = $rangestart+$rangelength;
442 // the problem is here
443 error_log("Downloader: going ranged as other");
445 if(file_exists($filename.".tmp.data.deleteme.size")) $contentlen = file_get_contents($filename.".tmp.data.deleteme.size");
446 else $contentlen = filesize($filename);
447 $contenttype = mime_content_type($filename);
448 header("HTTP/1.1 206 Partial Content");
449 header("Content-Length: $rangelength");
450 header("Content-Range: bytes $rangestr/$contentlen");
451 $contenttype = "Content-Type: application/x-rpm";
453 error_log("$contenttype");
454 header("$contenttype");
460 // first we wait until the file reaches $rangestart
461 while(filesize("$filename") < $rangestart) {
465 // then we open the file and ff to rangestart
466 $localfile = fopen($filename, "r");
467 fseek($localfile, $rangestart);
470 // need to think about this in pseudo code.
471 // 1. close the file and wait for it to get to $sgotten + 2048 or $fsize
472 $cursize = filesize($filename);
475 $upload_finished = false;
476 while(!$upload_finished) {
477 while($cursize < $sgatlen && $cursize < ($sgotten+2048)) {
479 error_log("OTHERDOWNLOAD: halt, $cursize, $sgotten, $contentlen");
480 // sleep until the the filesize is greater then what we're up to, or until the file is finished
482 $cursize = filesize($filename);
485 error_log("OTHERDOWNLOAD: continue, $sgotten, $contentlen");
486 // reopen local file - if it stopped existing, we need to deal with that
487 $localfile = fopen($filename, "r");
489 // UG, we need to ff, how could i forget that
490 fseek($localfile, $sgotten+$rangestart);
493 error_log("OTHERDOWNLOAD: something went plop");
497 // now loop on the file until we have it at sgatlen
498 while(!feof($localfile) && $sgotten < $rangelength) {
499 $left = $rangelength - $sgotten;
500 if($left > 512) $lenget = 512;
501 else $lenget = $left;
502 $data = fread($localfile, $lenget);
504 error_log("OTHERDOWNLOAD: dollar data went plop");
506 $sgotten += strlen($data);
513 if($sgotten >= $rangelength) {
514 if($sgotten > $rangelength) error_log("OTHERDOWNLOADER: finished but $sgotten, $fsize doesnt make senze");
515 $upload_finished = true;
520 error_log("OTHERDOWNLOADER: done with");
530 function startDownload($file, $url)
533 error_log("background downloader, start");
534 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
535 if(file_exists("$WEB_ROOT_FS/../bin/downloadfile.php")) {
536 $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/downloadfile.php '$url' '$file' > /tmp/dllog 2>&1 &";
539 error_log("cant find download helper... dieing");
543 // this is a nightmare
544 function getRepoForUrlOld($url)
546 // the way we breakdown a url is to explode it
547 $xurl = split("[/,]", $url);
549 // we first check if [0] is a prefix
550 // if now, we check for it being a shorturl (lets just do that for now)
551 $uconf = unserialize($this->config->getConfigVar("repodata"));
552 $repostore = $this->config->getConfigVar("storagelocation");
556 // first we check for /repo/repoid as a url
558 if($xurl[0] == "repo") {
560 error_log("trying to get repo for repoid, $repid");
561 if(isset($uconf[$repid])) {
562 $matched = ((int)($repid));
563 error_log("set matched, $matched, $repid");
570 if($matched < 0) foreach($uconf as $key => $var) {
571 $pre = $var["prefix"];
574 //echo "Checking pre $pre against ".$xurl[0]."\n";
575 if(strcasecmp($pre, $xurl[0])==0) {
576 //echo "Matched pre\n";
584 if($matched < 0) foreach($uconf as $key => $var) {
585 // if we matched a pre, then we check against the second url component
587 $short = $var["shorturl"];
590 //echo "Checking short $short against ".$xurl[$startat]."\n";
591 if(strcasecmp($xurl[$startat], $short)==0) {
600 echo "No such repo<br>";
605 // now we find an actual file
607 if(count($xurl) > $startat) for($i=$startat; $i < count($xurl); $i++) {
608 $file .= "/".$xurl[$i];
611 // now we want to find repostore/$matched/$file;
612 $actualfile = "$repostore/$matched/$file";
613 error_log("Atcualfile is $actualfile");
614 //echo "Start file for $actualfile\n";
616 // first check any directories in $file are in existence
617 $splfile = explode("/", $file);
618 if(count($splfile) > 1) {
619 $tomake = "$repostore/$matched/";
620 for($i = 0; $i < count($splfile)-1; $i++) {
621 $tomake .= "/".$splfile[$i];
622 //error_log("making directory $tomake");
623 if(!is_dir($tomake)) mkdir($tomake);
627 $reqhead = print_r($_REQUEST, true);
628 $sevhead = print_r($_SERVER, true);
630 error_log("req $reqhead");
631 error_log("sev $sevhead");
636 if(isset($_SERVER["HTTP_RANGE"])) {
638 $rangesa = explode("=", $_SERVER["HTTP_RANGE"]);
639 $rangesb = explode(",", $rangesa[1]);
640 $rangesstr = $rangesb[0];
641 $ranges = explode("-", $rangesb[0]);
642 $rangestart = $ranges[0];
643 $rangelength = $ranges[1] - $ranges[0] +1;
644 error_log("going ranges at $rangestart, $rangelength,".$rangesa[1].",".$rangesb[0]);
647 // i have to support http_range cause REDHAT/CENTOS IS annoying as all hell. christ, why do this?
648 if(is_file($actualfile)) {
649 // file is stored locally, away we go
650 if($rangelength != -1) {
651 header("HTTP/1.1 206 Partial Content");
652 header("Content-Length: ".$rangelength);
653 header("Content-Range: bytes $rangesstr/".filesize($actualfile));
654 //header("Content-Length: ".filesize($actualfile));
656 header("Content-Length: ".filesize($actualfile));
658 $type = mime_content_type($actualfile);
659 header("Content-type: $type");
660 $localfile = fopen($actualfile, "r");
661 if($rangestart!=-1) fseek($localfile, $rangestart, SEEK_SET);
662 while(!feof($localfile)) {
663 // cant make this high cause centos is crap
664 if($rangelength!=-1) {
665 $data = fread($localfile, $rangelength);
666 error_log("data size was ".strlen($data));
668 $data = fread($localfile, 2048);
674 if($rangelength!=-1) {
680 } else if(is_dir($actualfile)) {
681 //echo "in dir for $actualfile\n";
682 // here we print the contents of the directory
683 $this->printDir($actualfile, $file, $url);
686 //echo "in getcheck\n";
687 $remotefile = $uconf[$matched]["url"]."/$file";
689 // TODO: i should get remote contents with fopen/fread/fwrite as
690 // it should be more memory conservative and we can push to the end client
692 ignore_user_abort(true);
693 $rf = fopen($remotefile, "r");
694 error_log("attempting to get remote file $remotefile");
697 // hopefully this works. if we get a 30x message, it means we tried to get a directory
698 // i cant think of another way of dealing with it - but this is UGLY
699 // also get content length and content type
701 foreach($http_response_header as $key => $val) {
702 if(preg_match("/HTTP.*30[1-9].*/", $val)) {
703 error_log("got a 30x, must be a directory");
705 header("Location: ".$_SERVER["REQUEST_URI"]."/");
708 // get content length form upstream and print
709 if(preg_match("/^Content-Length:.*/", $val)) {
713 // get content type from upstream and print
714 if(preg_match("/^Content-Type:.*/", $val)) {
718 //error_log("repsonse: $http_response_header");
721 header("HTTP/1.0 404 Not Found");
723 $localfile = fopen($actualfile.".tmp.data.deleteme", "w");
724 $localsizefile = fopen($actualfile.".tmp.data.deleteme.size", "w");
725 fwrite($localsizefile, "$clen");
726 fclose($localsizefile);
728 $data = fread($rf, 8192);
730 fwrite($localfile, $data);
735 rename($actualfile.".tmp.data.deleteme", $actualfile);
736 //error_log("got actualfile, tried to save as $actualfile, did it work?");
740 //echo "got ".$file." for $url which is $actualfile\n";
742 //echo "</html></pre>";
745 function printDir($dir, $localfile, $baseurl)
747 $localfile = preg_replace("/\/\/+/", "/", $localfile);
748 $uri = $_SERVER["REQUEST_URI"];
751 $content .= "<html><head><title>Index of $localfile</title></head><body><h1>Index of $localfile</h1>";
752 $content .= "<table>";
756 while(($file = readdir($dh))!==false) {
757 if($file != "." && $file != "..") {
758 if(is_dir("$dir/$file")) {
759 $dirlist[$dirn++] = "$file";
761 $filelist[$filen++] = "$file";
765 if(isset($dirlist)) {
767 foreach($dirlist as $dirs) {
768 $icon = "/icons/folder.png";
769 $content .= "<tr><td><img src=\"$icon\"></td><td><a href=\"$uri/$dirs\">$dirs</a></td><td></td></tr>";
772 if(isset($filelist)) {
774 foreach($filelist as $files) {
775 $fsize = filesize("$dir/$files");
776 $icon = "/icons/text.png";
777 $content .= "<tr><td><img src=\"$icon\"></td><td><a href=\"$uri/$files\">$files</a></td><td>$fsize</td></tr>";
780 $content .= "</table></body></html>";
782 GLCASpageBuilder(null, null, $content);
787 function getRepoDetailsApt($url)
789 $action1 = $url."/dists";
791 // we just want to make sure it exists really
792 error_log("in repo details apt for $url");
793 if(!glcas_isRemoteDir($action1)) {
794 //echo "I cant find any valid APT dists's at $url<br>";
798 // ok, now scan for ubuntu dists as
799 $kos = getKnownOSList();
802 $existing_repo["isrepo"] = true;
803 foreach($kos["apt"] as $key => $val) {
804 //echo "<br>$key, $val<br>";
805 //echo "now check, $action1/$key";
806 if(glcas_isRemoteDir($action1."/$key")) {
807 $existing_repos["knownrepo"][$repos] = $key;
809 //echo "Found Distro $val<br>";
812 $existing_repos["nrepos"] = $repos;
814 // TODO: these need to be "calculated"
815 $existing_repos["distros"] = "Ubuntu, Debian";
816 $existing_repos["versions"] = "8.04LTS, 9.10, 10.04LTS, 10.10, 11.04, 11.10";
817 $existing_repos["arch"] = "x86_64, i386";
820 return $existing_repos;
824 function getRepoDetailsYum($url, $ismirrorlist=false)
826 $actionurl = $url."/repodata/repomd.xml";
828 error_log("Getting for action of $actionurl");
830 $ld = file_get_contents($actionurl);
832 // so here we try and get what this repository provides (os, version, arch), for yum this
833 // should come straight off the url... i.e. centos/6.0/os/x86_64/ (centos, 6.0, base os, 64bit arch)
835 if(!$ld) return false;
837 // ok, now we tokenize the url and try and guess at the content
838 $spurl = explode("/", $url);
840 // first, find the OS
841 $kos = getKnownOSList();
842 $glt["OS"] = "unknown";
843 $glt["verison"] = "unknown";
844 $glt["arch"] = "unknown";
845 $glt["other"] = "unknown";
846 foreach($spurl as $comp) {
849 foreach($kos["os"]["short"] as $kosname => $koslong) {
850 //error_log("Comparing $kosname and $koslong with $comp");
851 if(strcasecmp($kosname, $comp) == 0) {
852 //error_log("got $kosname, $koslong for $comp in $url");
853 //echo "<pre>inone\n"; print_r($koslong); echo "</pre>";
854 $glt["OS"] = $koslong;
858 // find a version, we assume its going to be something [numbers] and a . (optional)
859 if(preg_match("/^[0-9.]+$/", $comp)>0) {
860 //error_log("version match of $comp");
861 $glt["version"] = $comp;
864 // 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
865 foreach($kos["arch"] as $archinter => $archname ) {
866 //error_log("Comparing $archinter, $archname with $comp");
867 if(strcasecmp($archname, $comp) == 0) {
868 //error_log("arch match of $archname with $comp");
869 $glt["arch"] = $archname;
873 // other is a bt harder, we really have to guess at this one
874 if(strcasecmp("os", $comp) == 0) $glt["other"] = "OS";
875 if(strcasecmp("update", $comp) == 0) $glt["other"] = "Updates";
876 if(strcasecmp("updates", $comp) == 0) $glt["other"] = "Updates";
877 if(strcasecmp("everything", $comp) == 0) $glt["other"] = "OS";
884 function deleteRepo($rkey)
886 $uconf = $this->config->getConfigVar("repodata");
887 $repostore = $this->config->getConfigVar("storagelocation");
889 if($uconf !== false) {
890 $conf = unserialize($uconf);
891 foreach($conf as $key => $vla) {
893 unset($conf["$rkey"]);
894 $nconf = serialize($conf);
895 system("rm -rf $repostore/$key");
896 error_log("remove repo as $rkey");
897 $this->config->setConfigVar("repodata", $nconf);
898 $this->config->saveConfig();
904 function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime)
906 $uconf = $this->config->getConfigVar("repodata");
910 $cs["version"] = $version;
912 $cs["other"] = $other;
913 $cs["shorturl"] = $shorturl;
914 $cs["prefix"] = $prefix;
915 $cs["url"] = $repurl;
916 $cs["repotype"] = $repotype;
917 $cs["expiretime"] = $expiretime;
921 if($uconf !== false) {
922 $conf = unserialize($uconf);
923 foreach($conf as $key => $val) {
931 $nconf = serialize($conf);
933 error_log("add repo as $ckey");
934 $this->config->setConfigVar("repodata", $nconf);
935 $this->config->saveConfig();
937 // now create the base structure in the repo
938 $repostore = $this->config->getConfigVar("storagelocation");
941 // now call update repo
942 if($init) $this->updateRepoYum($ckey);
945 function updateRepo($repokey)
947 // we only do yum yet
948 $this->updateRepoYum($repokey);
951 function updateRepoYum($repokey)
953 $repostore = $this->config->getConfigVar("storagelocation");
955 $repod = $this->getRepo($repokey);
957 $repourl = $repod["url"];
959 if(!file_exists("$repostore/$repokey")) {
960 mkdir("$repostore/$repokey");
963 if(!file_exists("$repostore/$repokey/repodata")) {
964 mkdir("$repostore/$repokey/repodata");
967 error_log("background yum repo update, start");
968 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
969 if(file_exists("$WEB_ROOT_FS/../bin/downloadfile.php")) {
970 $scall = "/usr/bin/php $WEB_ROOT_FS/../bin/updateyumrepo.php '$repourl' '$repostore/$repokey/' > /tmp/updateyumrepo.$repokey.log 2>&1 &";
973 error_log("cant find download yum helper... dieing");
977 //ignore_user_abort(true);
980 function getRepo($id)
982 $uconf = $this->config->getConfigVar("repodata");
983 if($uconf !== false) {
984 $lconf = unserialize($uconf);
992 $uconf = $this->config->getConfigVar("repodata");
993 if($uconf !== false) {
994 return unserialize($uconf);