<?php
-funciton goWeb()
+function goWebGitBackEnd()
{
-
+ if(!isset($_SERVER["PHP_AUTH_USER"])) {
+ header('WWW-Authenticate: Basic realm="My Realm"');
+ header('HTTP/1.0 401 Unauthorized');
+ exit(0);
+ } else {
+
+ // well, i cant believe it, but this actually freaking works... for pulls/clones anyways... commits are not working...
+ // but wow thats better then what i had hoped for
+
+ $k1 = print_r($_REQUEST, true);
+ $k2 = print_r($_SERVER, true);
+ $k3 = print_r($_POST, true);
+ error_log("k1: $k1");
+ error_log("k2: $k2");
+ error_log("k3: $k3");
+
+ $ruri = $_SERVER["REQUEST_URI"];
+ $euri = str_replace("test.git", "", $_REQUEST["q"]);
+
+ $rmeth = $_SERVER["REQUEST_METHOD"];
+
+ $qs = "";
+ foreach($_REQUEST as $key => $var) {
+ if($key != "q") {
+ error_log("adding, $var from $key");
+ if($qs == "") $qs.="$key=$var";
+ else $qs.="&$key=$var";
+ }
+ }
+
+ //sleep(2);
+
+ $body = '';
+ if($rmeth == "POST") {
+ $body = file_get_contents("php://input");
+ }
+
+
+ // this is where the fun, it ends.
+ $myoutput = "";
+ unset($myoutput);
+
+ // this be nasty!
+
+ // setup env
+ if(isset($procenv)) unset($procenv);
+ $procenv["GATEWAY_INTERFACE"] = "CGI/1.1";
+ $procenv["PATH_TRANSLATED"] = "/var/cache/git/test.git$euri";
+ $procenv["REQUEST_METHOD"] = "$rmeth";
+ $procenv["GIT_HTTP_EXPORT_ALL"] = "1";
+ $procenv["QUERY_STRING"] = "$qs";
+ $procenv["HTTP_USER_AGENT"] = "git/1.7.1";
+ $procenv["REMOTE_USER"] = "paulr";
+ $procenv["REMOTE_ADDR"] = "1.2.3.4";
+ $procenv["CONTENT_TYPE"] = "application/x-git-upload-pack-request";
+
+ $pwd = "/var/cache/git";
+
+ error_log("openproc");
+ $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);
+ error_log("openproc2, $proc");
+
+ $stdin = $pipes[0];
+ $stdout = $pipes[1];
+
+ error_log("openproc3");
+
+ if($body != "") {
+ fwrite($pipes[0], $body);
+ }
+
+ error_log("openproc4");
+
+ $untilblank = false;
+ while(!$untilblank&&!feof($pipes[1])) {
+ $lines = rtrim(fgets($pipes[1]));
+ error_log("got line: $lines");
+ if($lines == "") {
+ $untilblank = true;
+ error_log("now blank");
+ } else header($lines);
+ if($lines === false) exit(0);
+
+ }
+
+ error_log("openproc5");
+
+ // now the body
+ while(!feof($pipes[1])) {
+ echo fread($pipes[1], 1024);
+ }
+
+ error_log("openproc6");
+
+ fclose($stdout);
+ fclose($stdin);
+
+
+
+ }
}
?>
\ No newline at end of file