git backend stuff
[gwvp.git] / gwvplib / gwvpgitcontrol.php
1 <?php
2
3 $CALL_ME_FUNCTIONS["repoadmin"] = "gwvp_gitControlCallMe";
4
5 //$MENU_ITEMS["20repos"]["text"] = "Repo Admin";
6 //$MENU_ITEMS["20repos"]["link"] = "$BASE_URL/admin/repos";
7
8 function gwvp_gitControlCallMe()
9 {
10         if(isset($_REQUEST["q"])) {
11                 $query = $_REQUEST["q"];
12                 $qspl = explode("/", $query);
13                 if(isset($qspl[0])) {
14                         if($qspl[0] == "git") {
15                                 return "gwvp_gitBackendInterface";
16                         }
17                 } 
18                 else return false;
19         }
20         
21         return false;
22         
23 }
24
25 function gwvp_gitBackendInterface()
26 {
27         // we need to quite a bit of parsing in here. The "repo" will always be /git/repo.git
28         // but if we get here from a browser, we need to forward back to a normal repo viewer
29         // the only way i can think of doing this is to check the useragent for the word "git"
30         
31         /*
32          * here we need to
33          * 1) figure out the repo its acessing
34          * 2) figure out the perms on the repo
35          * 3) determine if its a pull or a push
36          * - if its a pull, we just serve straight from the fs
37          * - if its a push, we go thru git-http-backend
38          * 4) if it requiers auth, we push to auth
39          * 
40          */
41         $agent = "git-unknown";
42         $isgitagent = false;
43         if(isset($_SERVER["HTTP_USER_AGENT"])) {
44                 $agent = $_SERVER["HTTP_USER_AGENT"];
45                 error_log("in git backend with user agent");
46                 if(stristr($agent, "git")!==false) {
47                         $isgitagent = true;
48                 }
49         }
50         
51         $repo = "";
52         if(isset($_REQUEST["q"])) {
53                 $query = $_REQUEST["q"];
54                 $qspl = explode("/", $query);
55                 $repo = $qspl[1];
56         }
57                 
58         if($isgitagent) echo "GIT: i am a git backened interface for a repo $repo, agent $agent";
59         else echo "NOT GIT: i am a git backened interface for a repo $repo, agent $agent";
60 }
61
62 function gwvp_repoExists($name)
63 {
64         global $repo_base;
65         
66         if(file_exists("$repo_base/$name.git")) return true;
67         else return false;
68 }
69
70 function gwvp_createGitRepo($name)
71 {
72         global $repo_base;
73         
74         error_log("would create $repo_base/$name.git");
75         
76         return true;
77 }
78 ?>