echo "<form method=\"post\" action=\"$BASE_URL/login\">Username <input type=\"text\" name=\"username\" class=\"login\">";
echo " Passowrd <input type=\"text\" name=\"password\" class=\"login\"><input type=\"submit\" name=\"login\" value=\"Login\" class=\"loginbutton\">";
if(gwvp_IsRegistrationEnabled()) echo "<a href=\"$BASE_URL/register\">Register</a></form>";
- else echo "</form>";
+ else echo "</form><br>";
}
return $return;
}
+function gwvp_IsRepoOwner($userid, $repoid)
+{
+ $conn = gwvp_ConnectDB();
+
+ $sql = "select repos_owner from repos where repos_id='$repoid'";
+
+ $res = $conn->query($sql);
+
+ $return = false;
+ foreach($res as $u_res) {
+ $return["owner"] = $u_res["repos_owner"];
+ }
+
+ if($return == false) return false;
+ if($return["owner"] == $userid) return true;
+ else return false;
+
+
+}
function gwvp_IsUserAdmin($email=null, $username = null, $userid = null)
{
case "recreatedb":
global $db_name;
gwvp_forceDisconnect();
+ unlink("$db_name.tmp");
rename("$db_name", "$db_name.tmp");
gwvp_dbCreateSQLiteStructure("$db_name");
- //gwvp_createGroup($group_name, $is_admin, $owner_id)
- //gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
- //gwvp_addGroupMember($email, $groupname)
+
+ // admin first
gwvp_createUser("admin@localhost", "adminer", "password", "admin", "initial admin user", 0);
$adminid = gwvp_getUserId("admin@localhost");
gwvp_createGroup("admingroup", "admingroup", 1, $adminid);
error_log("adminid is $adminid");
gwvp_addGroupMember("admin@localhost", "admingroup");
- gwvp_createUser("user@localhost", "userer", "password", "user", "initial pleb user", 0);
- $userid = gwvp_getUserId("user@localhost");
- error_log("userid is $userid");
- gwvp_createGroup("usergroup", "usergroup", 0, $userid);
- gwvp_addGroupMember("user@localhost", "usergroup");
+
+ // user1
+ gwvp_createUser("user1@localhost", "userer1", "password", "user1", "initial pleb user1", 0);
+ $userid1 = gwvp_getUserId("user1@localhost");
+ error_log("userid1 is $userid1");
+ gwvp_createGroup("usergroup1", "usergroup1", 0, $userid1);
+ gwvp_addGroupMember("user1@localhost", "usergroup1");
+
+ // user2
+ gwvp_createUser("user2@localhost", "userer2", "password", "user2", "initial pleb user2", 0);
+ $userid2 = gwvp_getUserId("user2@localhost");
+ error_log("userid2 is $userid2");
+
gwvp_SendMessage("info", "blank db re-created");
- gwvp_AddRepo("repo1", "this is a test repo1", 1);
- gwvp_AddRepo("repo2", "this is a test repo2", 1);
- gwvp_AddRepo("repo2", "this is a test repo3", 1);
+ gwvp_AddRepo("repo1", "this is a test repo1", $adminid);
+ gwvp_AddRepo("repo2", "this is a test repo2", $userid1);
+ gwvp_AddRepo("repo3", "this is a test repo3", $userid2);
gwvp_setConfigVal("repodir", "/tmp/");
<a href="<?php echo $BASE_URL?>/debug/infomessage">Generate info message</a><br>
<a href="<?php echo $BASE_URL?>/debug/createusersandgroups">Create a bunch of users and groups</a><br>
<a href="<?php echo $BASE_URL?>/debug/dropallusersandgroups">Drop users/groups/groupmemberships</a><br>
- <a href="<?php echo $BASE_URL?>/debug/recreatedb">Recreate db</a><br>
+ <a href="<?php echo $BASE_URL?>/debug/recreatedb">Recreate test db</a><br>
<?php
}
//$MENU_ITEMS["20repos"]["text"] = "Repo Admin";
//$MENU_ITEMS["20repos"]["link"] = "$BASE_URL/admin/repos";
+$HOME_PAGE_PROVIDERS["gitlog"] = "gwvp_GitLogProvider";
function gwvp_gitControlCallMe()
{
}
+function gwvp_GitLogProvider()
+{
+ echo "<br>gitload provider loaded on homepage<br>";
+}
+
function gwvp_repoPermissionCheck($repo, $user)
{
return true;
}
}
+function gwvp_canManageRepo($userid, $repoid)
+{
+ // only the owner or an admin can do these tasks
+ error_log("Checking repoid, $repoid against userid $userid");
+
+ if(gwvp_IsUserAdmin(null, null, $userid)) return true;
+ if(gwvp_IsRepoOwner($userid, $repoid)) return true;
+ return false;
+}
function gwvp_callGitBackend($repo)
{
case "updateperms":
return "gwvp_UpdateRepoPerms";
break;
+ case "details":
+ return "gwvp_RepoDetailsPage";
+ break;
default:
return "gwvp_RepoAdminPage";
}
gwvp_goMainPage("gwvp_CreateRepoPageBody");
}
+function gwvp_RepoDetailsPage()
+{
+ gwvp_goMainPage("gwvp_RepoDetailsPageBody");
+}
+
+function gwvp_RepoDetailsPageBody()
+{
+ echo "I am a repo details page";
+}
+
function gwvp_UpdateRepoPerms()
{
global $LOGIN_TYPE, $BASE_URL;
// next we need a repo list - with perms checking - ug
// i must also remember that the home page will also contain a list of repos and that this page is solely for maintance
// and creation of repos - so i dont need to get over-worked about the info stored on this page outside of those activities
+ echo "<h3>All Repositories</h3>";
$rlist = gwvp_GetRepoList();
echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Repo Owner</th></tr>";
foreach($rlist as $u_res) {
$rname = $u_res["name"];
$rdesc = $u_res["description"];
$rown = gwvp_getUserName($u_res["owner"]);
- echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td><td><a href=\"$BASE_URL/admin/repos/manage/$rid\">Details</a></td></tr>";
+ $manordetslink = "details";
+ $manordets = "Details";
+ if(isset($_SESSION["id"])) {
+ if(gwvp_canManageRepo($_SESSION["id"], $rid)) {
+ $manordetslink = "manage";
+ $manordets = "Manage";
+ }
+ }
+ echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td><td><a href=\"$BASE_URL/admin/repos/$manordetslink/$rid\">$manordets</a></td></tr>";
}
echo "</table>";
echo "<input type=\"submit\" name=\"update\" value=\"Update\"><br>";
echo "</form>";
+
+ echo "<h3>Repository Permissions</h3>";
echo "<form method=\"post\" action=\"$BASE_URL/admin/repos/updateperms/$rid\">";
echo "<table>";
echo "<tr bgcolor=\"#eeeee0\"><th>Visibility</th><th>Read/Clone</th><th>Write/Push</th></tr>";
// this function is the initial insertion point for the web calls, here we need to determine where we go
global $CALL_ME_FUNCTIONS;
+// the home_page_provders bit is an array
+global $HOME_PAGE_PROVIDERS;
+
$MENU_ITEMS["00home"]["text"] = "Home";
$MENU_ITEMS["00home"]["link"] = "$BASE_URL";
ksort($MENU_ITEMS);
+ echo "\n\n\n";
echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
foreach($MENU_ITEMS as $key => $val) {
$link = $val["link"];
}
}
echo "</tr></table>";
+ echo "\n\n\n";
}
{
global $WEB_ROOT_FS, $BASE_URL;
+ echo "\n\n\n";
$login = gwvp_IsLoggedIn();
if($login === false) {
gwvp_SingleLineLoginForm();
} else {
echo "Hello, ".gwvp_GetFullName($login)." <a href=\"$BASE_URL/logout\">logout</a>";
}
+ echo "\n\n\n";
}
// builds the body structure
function gwvp_BodyBuilder()
{
- echo "I AM THE MAIN BODY, FEAR ME!!!!";
+ global $HOME_PAGE_PROVIDERS;
+
+ echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here";
+ if(isset($HOME_PAGE_PROVIDERS)) {
+ ksort($HOME_PAGE_PROVIDERS);
+ foreach($HOME_PAGE_PROVIDERS as $provider) {
+ error_log("Loading home_page_provider, $provider");
+ $provider();
+ }
+ }
}
// builds the tail structure
border: 1px solid;
}
+form {
+ margin: 0em;
+}
+
.buttons {
border: 1px solid;
}