pulls/clones now work thru git-http-backend THRU my php script
authorpaulr <me@pjr.cc>
Sun, 30 Oct 2011 15:53:38 +0000 (02:53 +1100)
committerpaulr <me@pjr.cc>
Sun, 30 Oct 2011 15:53:38 +0000 (02:53 +1100)
unbelievable... and painful... but unbelievable none the less

gwvplib/gwvplib.php
gwvplib/gwvpweb.php
www/index.php

index e69de29..7e671e0 100644 (file)
@@ -0,0 +1,5 @@
+<?php
+
+require_once("gwvpweb.php");
+
+?>
\ No newline at end of file
index 8148e00..03daa77 100644 (file)
@@ -1,9 +1,108 @@
 <?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
index fb71493..cfe2386 100644 (file)
@@ -13,8 +13,9 @@ require_once("config.php");
  * 5. do we auth?
  */
 
-goWeb();
+goWebGitBackEnd();
 
+/*
 echo "<pre>";
 echo "BASEURL: $BASE_URL\n";
 echo "CUSTOM\n";
@@ -23,6 +24,6 @@ print_r($_REQUEST);
 
 
 echo "</pre>";
-
+*/
 
 ?>