diff options
author | Erich Eckner <git@eckner.net> | 2016-06-01 12:24:38 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2016-06-01 12:24:38 +0200 |
commit | 1a64aab40ad6a3e0301c0790d2e19dbe38a9d642 (patch) | |
tree | 6c16e2b425365f6b40096a8ccd67deb867441674 | |
parent | ac67554889c8634761a36e0c482912058036e208 (diff) | |
download | sourceMirror-1a64aab40ad6a3e0301c0790d2e19dbe38a9d642.tar.xz |
geht erst mal
-rw-r--r-- | mirror.php | 49 |
1 files changed, 46 insertions, 3 deletions
@@ -1,9 +1,52 @@ <?php - $pfad = $_SERVER["ORIG_SCRIPT_FILENAME"]; + function myBaseEncode(&$item, $key) { + $item = base64_encode($item); + if ($item == "") + $item = "_"; + } - $pfad = substr($pfad, strlen("/srv/sourceMirror/mirror.php")+1); + function myBaseDecode(&$item, $key) { + if ($item == "_") + $item = ""; + $item = base64_decode($item); + } - echo "'".$pfad."'"; + $quelle = $_SERVER["REQUEST_URI"]; + $wurzel = dirname(__FILE__)."/daten/"; + + if (substr($quelle,0,1) != "/") + die("ungültiger Pfad!"); + + $quelle = substr($quelle,1); + + $pfad = explode("/",$quelle); + array_walk($pfad,"myBaseEncode"); + $pfad = implode("/",$pfad); + $pfad = $wurzel.$pfad; + + if (! file_exists($wurzel.$pfad)) { + $inp = popen( + "mkdir -p '".dirname($pfad)."'; ". + "wget -O - '".$quelle."' | ". + "tee \"".$pfad."\"", + "r"); + + if (! $inp) + die("kann wget nicht starten"); + + fpassthru($inp); + pclose($inp); + } + else { + $inp = fopen($wurzel.$pfad,"r"); + if (! $inp) + die("kann '".$quelle."' ('".$pfad."') nicht &oouml;ffnen,"); + fpassthru($inp); + fclose($inp); + } + +// foreach ($_SERVER as $key => $value) +// echo "'".$key."': '".$value."'<br>\n"; ?> |