summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mirror.php49
1 files changed, 46 insertions, 3 deletions
diff --git a/mirror.php b/mirror.php
index d55277b..7d82267 100644
--- a/mirror.php
+++ b/mirror.php
@@ -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&uuml;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";
?>