X-Git-Url: http://git.pjr.cc/?p=gwvp.git;a=blobdiff_plain;f=gwvplib%2Fgwvpgitcontrol.php;h=d1b0699e68ee819290025f8e7d442bf6e75c52b3;hp=4622f27a1a5201f4b043c2f6bb2e82b6331d1cdd;hb=98ea64d926a23982b9cfb5b468be87f882268566;hpb=f985c75b4dd4a136157fc9c36b6e6b8507f510fb diff --git a/gwvplib/gwvpgitcontrol.php b/gwvplib/gwvpgitcontrol.php index 4622f27..d1b0699 100644 --- a/gwvplib/gwvpgitcontrol.php +++ b/gwvplib/gwvpgitcontrol.php @@ -27,10 +27,33 @@ function gwvp_repoPermissionCheck($repo, $user) return true; } +function gwvp_gitBackendInterface_new() +{ + // and this is where i re-code the git backend interface from scratch + global $BASE_URL; + + $repo_base = gwvp_getConfigVal("repodir"); + + $repo = ""; + $newloc = "/"; + if(isset($_REQUEST["q"])) { + $query = $_REQUEST["q"]; + $qspl = explode("/", $query); + $repo = $qspl[1]; + for($i=2; $i < count($qspl); $i++) { + $newloc .= "/".$qspl[$i]; + } + } + + +} + + function gwvp_gitBackendInterface() { - global $repo_base, $BASE_URL; + global $BASE_URL; + $repo_base = gwvp_getConfigVal("repodir"); $repo = ""; $newloc = "/"; @@ -102,6 +125,9 @@ function gwvp_gitBackendInterface() // now we need to rebuild the actual request or do we? //$basegit = "$BASE_URL/git/something.git"; //$newloc = preg_replace("/^$basegit/", "", $_SERVER["REQUEST_URI"]); + chdir("$repo_base/$repo"); + exec("/usr/bin/git update-server-info"); + if($_SERVER["REQUEST_METHOD"] == "POST") { gwvp_AskForBasicAuth(); gwvp_callGitBackend($repo); @@ -190,6 +216,8 @@ function gwvp_callGitBackend($repo) error_log("path trans'd is /tmp/$repo/$euri from $ruri with ".$_REQUEST["q"]." $strrem"); + + $pwd = "/tmp/"; @@ -249,9 +277,14 @@ function gwvp_callGitBackend($repo) // i.e. why the pointer doesnt increment over it, cause the freads above then get them again. if($firstline) { if(strlen($from_cgi_data_t)>0) { + // i dont get why this happens, and its very frustrating.. im not sure if its a bug in php + // or something the git-http-backend thing is doing.. + // TODO: find out why this happens $from_cgi_data = preg_replace("/^\r\n/", "", $from_cgi_data_t); if(strlen($from_cgi_data)!=strlen($from_cgi_data_t)) { error_log("MOOOKS - we did trunc"); + } else { + error_log("MOOOKS - we did not trunc"); } $firstline = false; } @@ -293,15 +326,19 @@ function gwvp_callGitBackend($repo) function gwvp_repoExists($name) { - global $repo_base; + $repo_base = gwvp_getConfigVal("repodir"); if(file_exists("$repo_base/$name.git")) return true; else return false; } -function gwvp_createGitRepo($name, $bundle=null) +// default perms: +// 0 - anyone can clone/read, only owner can write +// 1 - noone can clone/read, repo is visible (i.e. name), only owner can read/write repo +// 2 - only owner can see anything +function gwvp_createGitRepo($name, $ownerid, $desc, $bundle=null, $defaultperms=0) { - global $repo_base; + $repo_base = gwvp_getConfigVal("repodir"); // phew, this works, but i tell you this - bundles arent quite as nice as they should be if($bundle == null) { @@ -315,7 +352,76 @@ function gwvp_createGitRepo($name, $bundle=null) chdir("$repo_base/$name.git"); exec("/usr/bin/git update-server-info"); } + + // gwvp_AddRepo($reponame, $repodesc, $repoowner, $defaultperms = 0) + gwvp_AddRepo($name, $desc, $ownerid, $defaultperms); return true; } + +// this funciton returns one of three things, read, visible, write, none +// as +// 0 - none +// 1 - visible +// 2 - read +// 3 - write +function gwvp_resolvRepoPerms($userid, $repoid) +{ + $ownerid = gwvp_getRepoOwner($repoid); + $isadmin = gwvp_IsUserAdmin(null, null, $userid); + + if($isadmin) return 3; + + if($userid == $ownerid) return 3; + + // now we load the perms table and pray + $repoperms = gwvp_getRepoPermissions($repoid); + $usergroups = gwvp_getGroupsForUser(null, $userid); + + $maxperm = 0; + 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