From 529c11c6cfff0c2d8b857eed0b5ace7f3be054da Mon Sep 17 00:00:00 2001 From: Paul J R Date: Thu, 20 Sep 2012 07:44:42 +1000 Subject: [PATCH] added repo remove from admin page --- gwvpmini/gwvpmini_admin.php | 93 ++++++++++++++++++++++++++++++++++++++++- gwvpmini/gwvpmini_auth.php | 2 + gwvpmini/gwvpmini_db.php | 51 ++++++++++++++++++++++ gwvpmini/gwvpmini_gitrepo.php | 36 ++++++++++++++++ 4 files changed, 181 insertions(+), 1 deletions(-) diff --git a/gwvpmini/gwvpmini_admin.php b/gwvpmini/gwvpmini_admin.php index 15db43c..e588e97 100644 --- a/gwvpmini/gwvpmini_admin.php +++ b/gwvpmini/gwvpmini_admin.php @@ -33,9 +33,15 @@ function gwvpmini_AdminCallMe() if($qspl[1] == "removeuser") { return "gwvpmini_RemoveUserPage"; } + 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() return false; } + +function gwvpmini_RemoveRepoPage() +{ + gwvpmini_goMainPage("gwvpmini_RemoveRepoPageBody"); + +} + function gwvpmini_RemoveUserPage() { @@ -153,7 +166,13 @@ function gwvpmini_AdminMainPageBody() $rn = $val["name"]; $ds = $val["desc"]; $ow = $val["owner"]; - echo "$rn$ds$owRemove Disable"; + $udet = gwvpmini_getUser(null, null, $ow); + if(!$udet) { + $owl = "Orphaned"; + } else { + $owl = $udet["username"]." (".$udet["id"].") - ".$udet["fullname"]." (".$udet["email"].") - Email Owner"; + } + echo "$rn$ds$owlRemove Disable"; } echo ""; } @@ -276,6 +295,78 @@ function gwvpmini_RemoveUserPageBody() } +function gwvpmini_RemoveRepoPageBody() +{ + global $BASE_URL; + + $rid = -1; + $uid = -1; + if(isset($_REQUEST["q"])) { + $query = $_REQUEST["q"]; + $qspl = explode("/", $query); + if(isset($qspl[2])) { + $rid = $qspl[2]; + } + } + + $repdet = gwvpmini_getRepo(null, null, $rid); + if($repdet != false) $uid = $repdet["ownerid"]; + $usedet = gwvpmini_getUser(null, null, $uid); + + + if($rid != -1) { + $rname = $repdet["name"]; + $rdesc = $repdet["desc"]; + if($usedet == false) { + $ownedby = "which is unowned (Orphaned)"; + } else { + $ownedby = "owned by $username ($uid) - \"$fullname\""; + } + $username = $usedet["username"]; + $fullname = $usedet["fullname"]; + + + error_log("user dets:".print_r($details, true)); + + echo "

Remove User?

"; + echo "Are you sure you wish to remove the repo, $rname ($rid) - \"$rdesc\" $ownedby?
"; + echo "Yes No
"; + } else { + echo "

How?

"; + echo "You got here in a weird way or the uid of the repo you were trying to delete is invalid
"; + echo "Go Back"; + } + +} + +function gwvpmini_ConfRemoveRepo() +{ + global $BASE_URL; + + + error_log("CONF REMOVE REPO"); + + $rid = -1; + if(isset($_REQUEST["q"])) { + $query = $_REQUEST["q"]; + $qspl = explode("/", $query); + if(isset($qspl[2])) { + $rid = $qspl[2]; + } + } + + if($rid > 0) { + $details = gwvpmini_getRepo(null, null, $rid); + $rname = $details["name"]; + gwvpmini_RemoveRepo($rid); + gwvpmini_SendMessage("info", "Repo $rname ($rid) has been removed"); + } else { + gwvpmini_SendMessage("info", "Problem deleteing repo with rid $rid"); + } + + header("Location: $BASE_URL/admin"); +} + function gwvpmini_ConfRemoveUser() { global $BASE_URL; diff --git a/gwvpmini/gwvpmini_auth.php b/gwvpmini/gwvpmini_auth.php index c4f1850..4fd5894 100644 --- a/gwvpmini/gwvpmini_auth.php +++ b/gwvpmini/gwvpmini_auth.php @@ -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"]; diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index d75ebcd..00f20b1 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -55,6 +55,57 @@ function gwvpmini_getUser($username=null, $email=null, $id=null) } +function gwvpmini_getRepo($ownerid=null, $name=null, $id=null) +{ + $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) + )'; + + */ + + if($ownerid != null) { + $res = $conn->query("select * from repos where repos_owner='$ownerid'"); + } else if($name != null) { + $res = $conn->query("select * from repos where repos_name='$name'"); + } else if($id != null) { + $res = $conn->query("select * from repos where repos_id='$id'"); + } else return false; + + $returns = false; + if(!$res) return false; + foreach($res as $u_res) { + $returns["id"] = $u_res["repos_id"]; + $returns["name"] = $u_res["repos_name"]; + $returns["desc"] = $u_res["repos_description"]; + $returns["ownerid"] = $u_res["repos_owner"]; + $returns["perms"] = $u_res["repos_readperms"]; + } + + return $returns; + +} + +function gwvpmini_RemoveRepoDB($id) +{ + $conn = gwvpmini_ConnectDB(); + + if($id < 0) return; + + $sql = "delete from repos where repos_id='$id'"; + + return $conn->query($sql); + +} + function gwvpmini_RemoveUser($uid) { $conn = gwvpmini_ConnectDB(); diff --git a/gwvpmini/gwvpmini_gitrepo.php b/gwvpmini/gwvpmini_gitrepo.php index a120da4..2b41228 100644 --- a/gwvpmini/gwvpmini_gitrepo.php +++ b/gwvpmini/gwvpmini_gitrepo.php @@ -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)){ + return @unlink($fpath); + } + elseif(is_dir($fpath)){ + $scan = glob(rtrim($fpath,'/').'/*'); + foreach($scan as $index=>$path){ + gwvpmini_RecursiveDelete($path); + } + return @rmdir($fpath); + } +} + ?> \ No newline at end of file -- 1.7.0.4