From 70007a4ed44735f9d9c82fdff2d6600e2fdbfbd9 Mon Sep 17 00:00:00 2001 From: paulr Date: Tue, 8 Nov 2011 21:13:49 +1100 Subject: [PATCH] broken atm cause i've been interchably passing around repo.git and repo as names for the repo... doh --- gwvplib/gwvpauth.php | 9 ++++++++- gwvplib/gwvpdebug.php | 13 +++++++++---- gwvplib/gwvpgitcontrol.php | 34 ++++++++++++++++++++++------------ gwvplib/gwvplib.php | 2 +- gwvplib/gwvpweb.php | 2 ++ 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/gwvplib/gwvpauth.php b/gwvplib/gwvpauth.php index 086af98..e06fdde 100644 --- a/gwvplib/gwvpauth.php +++ b/gwvplib/gwvpauth.php @@ -37,6 +37,7 @@ function gwvp_AuthCallMe() function gwvp_AskForBasicAuth() { + error_log("AUTH: asking for basic auth"); if(!isset($_SERVER["PHP_AUTH_USER"])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); @@ -203,7 +204,13 @@ function gwvp_checkBasicAuthLogin() $pass = $_SERVER["PHP_AUTH_PW"]; } else return false; - return gwvp_authUserPass($user, $pass); + error_log("passing basic auth for $user, $pass to backend"); + $auth = gwvp_authUserPass($user, $pass); + if($auth !== false) { + error_log("auth passes"); + } + + return $auth; } function gwvp_IsLoggedIn() diff --git a/gwvplib/gwvpdebug.php b/gwvplib/gwvpdebug.php index 2a56674..dcc7c7a 100644 --- a/gwvplib/gwvpdebug.php +++ b/gwvplib/gwvpdebug.php @@ -114,12 +114,17 @@ function gwvp_DebugCall() gwvp_SendMessage("info", "blank db re-created"); - gwvp_AddRepo("repo1", "this is a test repo1", $adminid); - gwvp_AddRepo("repo2", "this is a test repo2", $userid1); - gwvp_AddRepo("repo3", "this is a test repo3", $userid2); - + //gwvp_createGitRepo($name, $ownerid, $desc, $bundle=null, $defaultperms=0) gwvp_setConfigVal("repodir", "/tmp/"); + // TODO change these to create not add. + system("rm -rf /tmp/repo1.git /tmp/repo2.git /tmp/repo3.git"); + gwvp_createGitRepo("repo1", $adminid, "test repo1"); + gwvp_createGitRepo("repo2", $userid1, "test repo2"); + gwvp_createGitRepo("repo3", $userid2, "test repo3"); + + + header("Location: $BASE_URL/debug"); break; case "dropallusersandgroups": diff --git a/gwvplib/gwvpgitcontrol.php b/gwvplib/gwvpgitcontrol.php index a59a02b..5ac3df6 100644 --- a/gwvplib/gwvpgitcontrol.php +++ b/gwvplib/gwvpgitcontrol.php @@ -43,23 +43,29 @@ function gwvp_gitBackendInterface() // TODO: we need to stop passing the repo name around as "repo.git", it needs to be just "repo" $repo = ""; - $repoid = -1; + $repoid = false; $newloc = "/"; if(isset($_REQUEST["q"])) { $query = $_REQUEST["q"]; $qspl = explode("/", $query); - $repo = $qspl[1]; - $repoid = gwvp_resolvRepoPerms($repo); + // TODO do this with + $repo = preg_replace("/\.git$/", "", $qspl[1]); + $repoid = gwvp_GetRepoId($repo); for($i=2; $i < count($qspl); $i++) { $newloc .= "/".$qspl[$i]; } } - if($repoid == -1) { + if($repoid == false) { gwvp_fourZeroFour(); return; } + // we do an update server cause its weird and i cant figure out when it actually needs to happen + chdir("$repo_base/$repo.git"); + exec("/usr/bin/git update-server-info"); + + // so now we have the repo // next we determine if this is a read or a write $write = false; @@ -79,12 +85,14 @@ function gwvp_gitBackendInterface() gwvp_AskForBasicAuth(); return; } else { - $perms = gwvp_resolvRepoPerms($person["id"], $repoid); + error_log("checking perms for $person against $repoid"); + $perms = gwvp_resolvRepoPerms(gwvp_getUserId($person), $repoid); if($perms < 3) { gwvp_fourZeroThree(); return; } else { // here we pass to the git backend + error_log("perms are $perms and im allowed"); gwvp_callGitBackend($person["username"], $repo); } } @@ -102,8 +110,10 @@ function gwvp_gitBackendInterface() gwvp_AskForBasicAuth(); return; } else { - $perms = gwvp_resolvRepoPerms($person["id"], $repoid); + $perms = gwvp_resolvRepoPerms(gwvp_getUserId($person), $repoid); if($perms < 3) { + $dump = print_r($person, true); + error_log("in basic read, called 403 for $perms $dump"); gwvp_fourZeroThree(); return; } @@ -111,9 +121,9 @@ function gwvp_gitBackendInterface() } // 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")) { + if(file_exists("$repo_base/$repo.git/$newloc")) { error_log("would ask $repo,$actual_repo_name for $repo/$newloc from $repo_base/$repo/$newloc"); - $fh = fopen("$repo_base/$repo/$newloc", "rb"); + $fh = fopen("$repo_base/$repo.git/$newloc", "rb"); error_log("pushing file"); while(!feof($fh)) { @@ -248,13 +258,13 @@ function gwvp_canManageRepo($userid, $repoid) return false; } -function gwvp_callGitBackend($username, $reponame) +function gwvp_callGitBackend($username, $repo) { // this is where things become a nightmare $fh = fopen('php://input', "r"); $ruri = $_SERVER["REQUEST_URI"]; - $strrem = "git/$repo"; + $strrem = "git/$repo.git"; $euri = str_replace($strrem, "", $_REQUEST["q"]); //$euri = preg_replace("/^git\/$repo\.git/", "", $_REQUEST["q"]); @@ -284,7 +294,7 @@ function gwvp_callGitBackend($username, $reponame) // setup env if(isset($procenv)) unset($procenv); $procenv["GATEWAY_INTERFACE"] = "CGI/1.1"; - $procenv["PATH_TRANSLATED"] = "/tmp/$repo/$euri"; + $procenv["PATH_TRANSLATED"] = "/tmp/$repo.git/$euri"; $procenv["REQUEST_METHOD"] = "$rmeth"; $procenv["GIT_HTTP_EXPORT_ALL"] = "1"; $procenv["QUERY_STRING"] = "$qs"; @@ -302,7 +312,7 @@ function gwvp_callGitBackend($username, $reponame) $procenv["CONTENT_LENGTH"] = $_SERVER["CONTENT_LENGTH"]; } - error_log("path trans'd is /tmp/$repo/$euri from $ruri with ".$_REQUEST["q"]." $strrem"); + error_log("path trans'd is /tmp/$repo.git/$euri from $ruri with ".$_REQUEST["q"]." $strrem"); diff --git a/gwvplib/gwvplib.php b/gwvplib/gwvplib.php index d70dc3f..824e4c4 100644 --- a/gwvplib/gwvplib.php +++ b/gwvplib/gwvplib.php @@ -17,7 +17,7 @@ require_once("gwvpemail.php"); require_once("gwvppluginloader.php"); // only enable this if you need it: -require_once("gwvpdebug.php"); +// require_once("gwvpdebug.php"); ?> \ No newline at end of file diff --git a/gwvplib/gwvpweb.php b/gwvplib/gwvpweb.php index 3cc931c..b9e7e1b 100644 --- a/gwvplib/gwvpweb.php +++ b/gwvplib/gwvpweb.php @@ -228,11 +228,13 @@ function gwvp_TailBuilder() function gwvp_fourZeroThree() { + error_log("403 called"); header("HTTP/1.0 403 Permission Denied"); } function gwvp_fourZeroFour() { + error_log("404 called"); header("HTTP/1.0 404 No Such Thing"); } -- 1.7.0.4