added repo remove from admin page
authorPaul J R <me@pjr.cc>
Wed, 19 Sep 2012 21:44:42 +0000 (07:44 +1000)
committerPaul J R <me@pjr.cc>
Wed, 19 Sep 2012 21:44:42 +0000 (07:44 +1000)
gwvpmini/gwvpmini_admin.php
gwvpmini/gwvpmini_auth.php
gwvpmini/gwvpmini_db.php
gwvpmini/gwvpmini_gitrepo.php

index 15db43c..e588e97 100644 (file)
@@ -33,9 +33,15 @@ function gwvpmini_AdminCallMe()
                                        if($qspl[1] == "removeuser") {
                                                return "gwvpmini_RemoveUserPage";
                                        }\r
+                                       if($qspl[1] == "removerepo") {
+                                               return "gwvpmini_RemoveRepoPage";
+                                       }
                                        if($qspl[1] == "confremoveuser") {
                                                return "gwvpmini_ConfRemoveUser";
                                        }
+                                       if($qspl[1] == "confremoverepo") {
+                                               return "gwvpmini_ConfRemoveRepo";
+                                       }
                                        if($qspl[1] == "switchenable") {
                                                return "gwvpmini_SwitchEnableUser";
                                        }
@@ -50,6 +56,13 @@ function gwvpmini_AdminCallMe()
 \r
        return false;\r
 }
+\r
+function gwvpmini_RemoveRepoPage()\r
+{\r
+       gwvpmini_goMainPage("gwvpmini_RemoveRepoPageBody");\r
+\r
+}\r
+\r
 
 function gwvpmini_RemoveUserPage()
 {
@@ -153,7 +166,13 @@ function gwvpmini_AdminMainPageBody()
                $rn = $val["name"];
                $ds = $val["desc"];
                $ow = $val["owner"];
-               echo "<tr><td><a href=\"$BASE_URL/view/$rn\">$rn</a></td><td>$ds</td><td>$ow</td><td><a href=\"$BASE_URL/admin/removeuser&id=$id\">Remove</a> <a href=\"$BASE_URL/admin/switchenable/$id\">Disable</a></td></tr>";
+               $udet = gwvpmini_getUser(null, null, $ow);
+               if(!$udet) {
+                       $owl = "Orphaned";
+               } else {
+                       $owl = $udet["username"]." (".$udet["id"].") - ".$udet["fullname"]." (".$udet["email"].") - <a href=\"mailto:".$udet["email"]."\">Email Owner</a>";
+               }
+               echo "<tr><td><a href=\"$BASE_URL/view/$rn\">$rn</a></td><td>$ds</td><td>$owl</td><td><a href=\"$BASE_URL/admin/removerepo/$id\">Remove</a> <a href=\"$BASE_URL/admin/switchenable/$id\">Disable</a></td></tr>";
        }
        echo "</table>";
 }\r
@@ -276,6 +295,78 @@ function gwvpmini_RemoveUserPageBody()
        
 }
 
+function gwvpmini_RemoveRepoPageBody()\r
+{\r
+       global $BASE_URL;\r
+\r
+       $rid = -1;
+       $uid = -1;\r
+       if(isset($_REQUEST["q"])) {\r
+               $query = $_REQUEST["q"];\r
+               $qspl = explode("/", $query);\r
+               if(isset($qspl[2])) {\r
+                       $rid = $qspl[2];\r
+               }\r
+       }
+       
+       $repdet = gwvpmini_getRepo(null, null, $rid);
+       if($repdet != false) $uid = $repdet["ownerid"];
+       $usedet = gwvpmini_getUser(null, null, $uid);\r
+       \r
+\r
+       if($rid != -1) {
+               $rname = $repdet["name"];
+               $rdesc = $repdet["desc"];
+               if($usedet == false) {
+                       $ownedby = "which is unowned (Orphaned)";
+               } else {
+                       $ownedby = "owned by <b>$username</b> ($uid) - \"$fullname\"";
+               }
+               $username = $usedet["username"];
+               $fullname = $usedet["fullname"];
+               \r
+\r
+               error_log("user dets:".print_r($details, true));\r
+\r
+               echo "<h2>Remove User?</h2>";\r
+               echo "Are you sure you wish to remove the repo, <b>$rname</b> ($rid) - \"$rdesc\" $ownedby?<br>";\r
+               echo "<a href=\"$BASE_URL/admin/confremoverepo/$rid\">Yes</a> <a href=\"$BASE_URL/admin\">No</a><br>";\r
+       } else {\r
+               echo "<h2>How?</h2>";\r
+               echo "You got here in a weird way or the uid of the repo you were trying to delete is invalid<br>";\r
+               echo "<a href=\"$BASE_URL/admin\">Go Back</a>";\r
+       }\r
+\r
+}
+
+function gwvpmini_ConfRemoveRepo()\r
+{\r
+       global $BASE_URL;\r
+
+       
+       error_log("CONF REMOVE REPO");
+       \r
+       $rid = -1;\r
+       if(isset($_REQUEST["q"])) {\r
+               $query = $_REQUEST["q"];\r
+               $qspl = explode("/", $query);\r
+               if(isset($qspl[2])) {\r
+                       $rid = $qspl[2];\r
+               }\r
+       }\r
+\r
+       if($rid > 0) {\r
+               $details = gwvpmini_getRepo(null, null, $rid);\r
+               $rname = $details["name"];\r
+               gwvpmini_RemoveRepo($rid);\r
+               gwvpmini_SendMessage("info", "Repo $rname ($rid) has been removed");\r
+       } else {\r
+               gwvpmini_SendMessage("info", "Problem deleteing repo with rid $rid");\r
+       }\r
+\r
+       header("Location: $BASE_URL/admin");\r
+}
+
 function gwvpmini_ConfRemoveUser()\r
 {\r
        global $BASE_URL;\r
index c4f1850..4fd5894 100644 (file)
@@ -160,6 +160,8 @@ function gwvpmini_authUserPass($user, $pass)
                return false;
        }
        
+       if(!gwvpmini_isUserEnabled($details["id"])) return false;
+       
        if(sha1($pass)!=$details["password"]) return false;
        
        return $details["username"];
index d75ebcd..00f20b1 100644 (file)
@@ -55,6 +55,57 @@ function gwvpmini_getUser($username=null, $email=null, $id=null)
 \r
 }
 
+function gwvpmini_getRepo($ownerid=null, $name=null, $id=null)\r
+{\r
+       $conn = gwvpmini_ConnectDB();
+       
+       /*
+        *      $reposql = '
+       CREATE TABLE "repos" (
+       "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+       "repos_name" TEXT,
+       "repos_description" TEXT,
+       "repos_owner" INTEGER,
+       "repos_readperms" TEXT,
+       UNIQUE(repos_name)
+       )';
+
+        */\r
+\r
+       if($ownerid != null) {\r
+               $res = $conn->query("select * from repos where repos_owner='$ownerid'");\r
+       } else if($name != null) {\r
+               $res = $conn->query("select * from repos where repos_name='$name'");\r
+       } else if($id != null) {\r
+               $res = $conn->query("select * from repos where repos_id='$id'");\r
+       } else return false;\r
+\r
+       $returns = false;
+       if(!$res) return false;\r
+       foreach($res as $u_res) {\r
+               $returns["id"] = $u_res["repos_id"];\r
+               $returns["name"] = $u_res["repos_name"];\r
+               $returns["desc"] = $u_res["repos_description"];\r
+               $returns["ownerid"] = $u_res["repos_owner"];\r
+               $returns["perms"] = $u_res["repos_readperms"];\r
+       }\r
+\r
+       return $returns;\r
+\r
+}
+
+function gwvpmini_RemoveRepoDB($id)
+{
+       $conn = gwvpmini_ConnectDB();\r
+       \r
+       if($id < 0) return;\r
+       \r
+       $sql = "delete from repos where repos_id='$id'";\r
+       \r
+       return $conn->query($sql);\r
+       
+}
+
 function gwvpmini_RemoveUser($uid)
 {
        $conn = gwvpmini_ConnectDB();\r
index a120da4..2b41228 100644 (file)
@@ -186,4 +186,40 @@ function gwvpmini_HaveRepo($reponame)
        if(file_exists("$repo_base/$reponame.git")) return true;
 }
 
+
+function gwvpmini_RemoveRepo($rid)
+{
+       $repo_base = gwvpmini_getConfigVal("repodir");
+       
+       $repdet = gwvpmini_getRepo(null, null, $rid);
+       
+       $rname = $repdet["name"];
+       
+       error_log("FROM PANTS:".print_r($repdet,true)." ----------- ".print_r($rname, true));
+       
+       if($repdet != false && $rname != "") {
+               if(file_exists("$repo_base/$rname.git")) {
+                       // recursive remove - frightening
+                       if(gwvpmini_RecursiveDelete("$repo_base/$rname.git")) {
+                               gwvpmini_RemoveRepoDB($rid);
+                       }
+               }
+       } return false;
+}
+
+function gwvpmini_RecursiveDelete($fpath)
+{
+       error_log("RECURSEDETELE: ".$fpath);
+       if(is_file($fpath)){\r
+               return @unlink($fpath);\r
+       }\r
+       elseif(is_dir($fpath)){\r
+               $scan = glob(rtrim($fpath,'/').'/*');\r
+               foreach($scan as $index=>$path){\r
+                       gwvpmini_RecursiveDelete($path);\r
+               }\r
+               return @rmdir($fpath);\r
+       }
+}
+       
 ?>
\ No newline at end of file