X-Git-Url: http://git.pjr.cc/?a=blobdiff_plain;f=gwvplib%2Fgwvpgitcontrol.php;h=842d040fd630a55ae523b918c30ae3a2171c366c;hb=e9c10b0bc2d09d21b4ff0e630a140ddc58a7dccb;hp=6383f9e89c7f4644634374b5149f51480d568620;hpb=425b2ddb1c73ca601b616ff9c6ef71d2c6b58b03;p=gwvp.git diff --git a/gwvplib/gwvpgitcontrol.php b/gwvplib/gwvpgitcontrol.php index 6383f9e..842d040 100644 --- a/gwvplib/gwvpgitcontrol.php +++ b/gwvplib/gwvpgitcontrol.php @@ -4,6 +4,7 @@ $CALL_ME_FUNCTIONS["gitcontrol"] = "gwvp_gitControlCallMe"; //$MENU_ITEMS["20repos"]["text"] = "Repo Admin"; //$MENU_ITEMS["20repos"]["link"] = "$BASE_URL/admin/repos"; +$HOME_PAGE_PROVIDERS["gitlog"] = "gwvp_GitLogProvider"; function gwvp_gitControlCallMe() { @@ -22,34 +23,124 @@ function gwvp_gitControlCallMe() } +function gwvp_GitLogProvider() +{ + echo "
gitload provider loaded on homepage
"; +} + function gwvp_repoPermissionCheck($repo, $user) { 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 = false; $newloc = "/"; if(isset($_REQUEST["q"])) { $query = $_REQUEST["q"]; $qspl = explode("/", $query); - $repo = $qspl[1]; + // 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 == 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; + 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) { + error_log("is write attempt, ask for login"); + $person = gwvp_checkBasicAuthLogin(); + if($person == false) { + gwvp_AskForBasicAuth(); + return; + } else { + error_log("checking perms for $person against $repoid for repo $repo"); + $perms = gwvp_resolvRepoPerms(gwvp_getUserId(null, $person), $repoid); + if($perms < 3) { + error_log("perms are $perms and im not allowed"); + gwvp_fourZeroThree(); + exit(0); + } else { + // here we pass to the git backend + error_log("perms are $perms and im allowed"); + 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(gwvp_getUserId(null, $person), $repoid); + if($perms < 3) { + $dump = print_r($person, true); + error_log("in basic read, called 403 for $perms $dump"); + 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.git/$newloc")) { + error_log("would ask $repo for $repo.git/$newloc from $repo_base/$repo.git/$newloc"); + $fh = fopen("$repo_base/$repo.git/$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; @@ -159,14 +250,23 @@ function gwvp_gitBackendInterface() } } +function gwvp_canManageRepo($userid, $repoid) +{ + // only the owner or an admin can do these tasks + error_log("Checking repoid, $repoid against userid $userid"); + + if(gwvp_IsUserAdmin(null, null, $userid)) return true; + if(gwvp_IsRepoOwner($userid, $repoid)) return true; + return false; +} -function gwvp_callGitBackend($repo) +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"]); @@ -196,12 +296,12 @@ function gwvp_callGitBackend($repo) // 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"; $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"; @@ -214,7 +314,7 @@ function gwvp_callGitBackend($repo) $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"); @@ -370,6 +470,8 @@ function gwvp_resolvRepoPerms($userid, $repoid) $ownerid = gwvp_getRepoOwner($repoid); $isadmin = gwvp_IsUserAdmin(null, null, $userid); + error_log("USerid is $userid, ownerid $ownerid"); + if($isadmin) return 3; if($userid == $ownerid) return 3; @@ -379,12 +481,49 @@ function gwvp_resolvRepoPerms($userid, $repoid) $usergroups = gwvp_getGroupsForUser(null, $userid); $maxperm = 0; - foreach($repoperms as $perm) { + if($repoperms != false) foreach($repoperms as $perm) { // need to go thru each perm, then check it agains the user we're trying to figure // the perms on + switch($perm["type"]) { + case "read": + $permval = 2; + break; + case "visible": + $permval = 1; + break; + case "write": + $permval = 3; + break; + default: + $permval = 0; + } - + // we only var if permval is greater then current + if($permval > $maxperm) { + //error_log("going into check for $maxperm/$permval, ".$perm["ref"]); + if($perm["ref"] == "anon") { + $maxperm = $permval; + } else if($perm["ref"] == "authed") { + $maxperm = $permval; + } else { + // now we do splits + $spl = explode(":", $perm["ref"]); + $idtype = $spl[0]; + $idval = $spl[1]; + if($idtype == "group") { + // function gwvp_IsGroupMember($email, $groupname) + if(gwvp_IsGroupMemberById($userid, $idval)) $maxperm = $permval; + } else if ($idtype == "user") { + //error_log("checking $userid, $idval"); + if($userid == $idval) $maxperm = $permval; + } + } + } } + + // thats TOTALLY going to work... -_0 we should really write a unit test for this, but thats a bit + // hard given the db req's so for now, we'll leave it as is + return $maxperm; } ?> \ No newline at end of file