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";
}
\r
return false;\r
}
+\r
+function gwvpmini_RemoveRepoPage()\r
+{\r
+ gwvpmini_goMainPage("gwvpmini_RemoveRepoPageBody");\r
+\r
+}\r
+\r
function gwvpmini_RemoveUserPage()
{
$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
}
+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
\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
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