4 function goWebGitBackEnd()
6 if(!isset($_SERVER["PHP_AUTH_USER"])) {
7 header('WWW-Authenticate: Basic realm="My Realm"');
8 header('HTTP/1.0 401 Unauthorized');
12 // well, i cant believe it, but this actually freaking works... for pulls/clones anyways... commits are not working...
13 // but wow thats better then what i had hoped for
15 $k1 = print_r($_REQUEST, true);
16 $k2 = print_r($_SERVER, true);
17 $k3 = print_r($_POST, true);
22 $ruri = $_SERVER["REQUEST_URI"];
23 $euri = str_replace("test.git", "", $_REQUEST["q"]);
25 $rmeth = $_SERVER["REQUEST_METHOD"];
28 foreach($_REQUEST as $key => $var) {
30 error_log("adding, $var from $key");
31 if($qs == "") $qs.="$key=$var";
32 else $qs.="&$key=$var";
39 if($rmeth == "POST") {
40 $body = file_get_contents("php://input");
44 // this is where the fun, it ends.
51 if(isset($procenv)) unset($procenv);
52 $procenv["GATEWAY_INTERFACE"] = "CGI/1.1";
53 $procenv["PATH_TRANSLATED"] = "/var/cache/git/test.git$euri";
54 $procenv["REQUEST_METHOD"] = "$rmeth";
55 $procenv["GIT_HTTP_EXPORT_ALL"] = "1";
56 $procenv["QUERY_STRING"] = "$qs";
57 $procenv["HTTP_USER_AGENT"] = "git/1.7.1";
58 $procenv["REMOTE_USER"] = "paulr";
59 $procenv["REMOTE_ADDR"] = "1.2.3.4";
60 $procenv["CONTENT_TYPE"] = "application/x-git-upload-pack-request";
62 $pwd = "/var/cache/git";
64 error_log("openproc");
65 $proc = proc_open("/usr/lib/git-core/git-http-backend", array(array("pipe","r"),array("pipe","w"),array("file","/dev/null", "w")), $pipes, $pwd, $procenv);
66 error_log("openproc2, $proc");
71 error_log("openproc3");
74 fwrite($pipes[0], $body);
77 error_log("openproc4");
80 while(!$untilblank&&!feof($pipes[1])) {
81 $lines = rtrim(fgets($pipes[1]));
82 error_log("got line: $lines");
85 error_log("now blank");
86 } else header($lines);
87 if($lines === false) exit(0);
91 error_log("openproc5");
94 while(!feof($pipes[1])) {
95 echo fread($pipes[1], 1024);
98 error_log("openproc6");