return true;
}
-function gwvp_gitBackendInterface_new()
+function gwvp_gitBackendInterface()
{
// and this is where i re-code the git backend interface from scratch
global $BASE_URL;
$repo_base = gwvp_getConfigVal("repodir");
+ // TODO: we need to stop passing the repo name around as "repo.git", it needs to be just "repo"
+
$repo = "";
+ $repoid = -1;
$newloc = "/";
if(isset($_REQUEST["q"])) {
$query = $_REQUEST["q"];
$qspl = explode("/", $query);
$repo = $qspl[1];
+ $repoid = gwvp_resolvRepoPerms($repo);
for($i=2; $i < count($qspl); $i++) {
$newloc .= "/".$qspl[$i];
}
}
+ if($repoid == -1) {
+ gwvp_fourZeroFour();
+ return;
+ }
+
+ // so now we have the repo
+ // next we determine if this is a read or a write
+ $write = false;
+ if(isset($_REQUEST["service"])) {
+ if($_REQUEST["service"] == "git-receive-pack") {
+ $write = true;
+ }
+ }
+ if($_SERVER["REQUEST_METHOD"] == "POST") {
+ $write = true;
+ }
+
+ // if its a write, we push for authentication
+ if($write) {
+ $person = gwvp_checkBasicAuthLogin();
+ if($person == false) {
+ gwvp_AskForBasicAuth();
+ return;
+ } else {
+ $perms = gwvp_resolvRepoPerms($person["id"], $repoid);
+ if($perms < 3) {
+ gwvp_fourZeroThree();
+ return;
+ } else {
+ // here we pass to the git backend
+ gwvp_callGitBackend($person["username"], $repo);
+ }
+ }
+ return;
+ }
+
+ // if not we figure out the anon permissions for a repo
+ $perms = gwvp_resolvRepoPerms(-1, $repoid);
+
+ // if they're less then read, we need to then check the user auth permissions
+ if($perms < 2) {
+ // we ask for auth
+ $person = gwvp_checkBasicAuthLogin();
+ if($person == false) {
+ gwvp_AskForBasicAuth();
+ return;
+ } else {
+ $perms = gwvp_resolvRepoPerms($person["id"], $repoid);
+ if($perms < 3) {
+ gwvp_fourZeroThree();
+ return;
+ }
+ }
+ }
+
+ // if we made it this far, we a read and we have permissions to do so, just search the file from the repo
+ if(file_exists("$repo_base/$repo/$newloc")) {
+ error_log("would ask $repo,$actual_repo_name for $repo/$newloc from $repo_base/$repo/$newloc");
+ $fh = fopen("$repo_base/$repo/$newloc", "rb");
+
+ error_log("pushing file");
+ while(!feof($fh)) {
+ echo fread($fh, 8192);
+ }
+ } else {
+ //echo "would ask $repo,$actual_repo_name for $repo/$newloc from $repo_base/$repo/$newloc, NE";
+ gwvp_fourZeroFour();
+ return;
+ }
}
-function gwvp_gitBackendInterface()
+function gwvp_gitBackendInterface_old()
{
global $BASE_URL;
return false;
}
-function gwvp_callGitBackend($repo)
+function gwvp_callGitBackend($username, $reponame)
{
// this is where things become a nightmare
$fh = fopen('php://input', "r");
$procenv["GIT_HTTP_EXPORT_ALL"] = "1";
$procenv["QUERY_STRING"] = "$qs";
$procenv["HTTP_USER_AGENT"] = "git/1.7.1";
- $procenv["REMOTE_USER"] = "user";
+ $procenv["REMOTE_USER"] = "$username";
$procenv["REMOTE_ADDR"] = "1.2.3.4";
$procenv["AUTH_TYPE"] = "Basic";