aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--r7r_repo/css/main.css5
-rw-r--r--r7r_repo/main.php122
-rw-r--r--r7r_repo/templates/src/admin.html60
3 files changed, 187 insertions, 0 deletions
diff --git a/r7r_repo/css/main.css b/r7r_repo/css/main.css
index 089ba17..7d1178f 100644
--- a/r7r_repo/css/main.css
+++ b/r7r_repo/css/main.css
@@ -13,6 +13,11 @@ h1 {
}
h2 {
+ font-size: 14pt;
+ font-weight: bold;
+}
+
+h3 {
font-size: 12pt;
font-weight: bold;
}
diff --git a/r7r_repo/main.php b/r7r_repo/main.php
index f7a16cf..8e52af0 100644
--- a/r7r_repo/main.php
+++ b/r7r_repo/main.php
@@ -215,6 +215,128 @@ $url_handlers = array(
echo $ste->exectemplate("register.html");
},
+ "admin" => function(&$data, $url_now, &$url_next)
+ {
+ global $settings, $ste, $user;
+
+ if(($user === NULL) or (!$user->isadmin))
+ throw new NotFoundError();
+
+ $url_next = array();
+ $ste->vars["menu"] = "admin";
+ $ste->vars["title"] = "Administration";
+
+ if(isset($_POST["save_settings"]))
+ {
+ $settings["repo_name"] = $_POST["repo_name"];
+ $settings["repo_description"] = $_POST["repo_description"];
+ $settings["repo_baseurl"] = $_POST["repo_baseurl"];
+
+ if($_POST["repo_mode"] == "public")
+ $settings["repo_mode"] = "public";
+ if($_POST["repo_mode"] == "private")
+ $settings["repo_mode"] = "private";
+
+ update_repometa();
+
+ $ste->vars["success"] = "Settings saved.";
+ }
+
+ if(isset($_POST["new_user"]))
+ {
+ if(empty($_POST["username"]) or empty($_POST["password"]))
+ $ste->vars["error"] = "Formular not filled out.";
+ else
+ {
+ try
+ {
+ $u = User::by_name($_POST["username"]);
+ $ste->vars["error"] = "Username already exists.";
+ }
+ catch(DoesNotExistError $e)
+ {
+ $u = User::create($_POST["username"]);
+ $u->isadmin = False;
+ $u->pwhash = PasswordHash::create($_POST["password"]);
+ $u->save();
+ $ste->vars["success"] = "Account successfully created.";
+ }
+ }
+ }
+
+ if(isset($_POST["delete_users"]) and ($_POST["really_delete"] == "yes"))
+ {
+ foreach($_POST["users_multiselect"] as $uid)
+ {
+ try
+ {
+ $u = User::by_id($uid);
+ $u->delete();
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+
+ $ste->vars["success"] = "Users deleted.";
+ }
+
+ if(isset($_POST["make_admin"]))
+ {
+ foreach($_POST["users_multiselect"] as $uid)
+ {
+ try
+ {
+ $u = User::by_id($uid);
+ $u->isadmin = True;
+ $u->save();
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+
+ $ste->vars["success"] = "Okay.";
+ }
+
+ if(isset($_POST["make_normal_user"]))
+ {
+ foreach($_POST["users_multiselect"] as $uid)
+ {
+ try
+ {
+ $u = User::by_id($uid);
+ $u->isadmin = False;
+ $u->save();
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+
+ $ste->vars["success"] = "Okay.";
+ }
+
+ /* Fill data */
+ $ste->vars["repo"] = array(
+ "name" => $settings["repo_name"],
+ "description" => $settings["repo_description"],
+ "baseurl" => $settings["repo_baseurl"],
+ "public" => ($settings["repo_mode"] == "public")
+ );
+
+ $users = User::all();
+ $ste->vars["users"] = array_map(function($u) { return array(
+ "id" => $u->get_id(),
+ "name" => $u->get_name(),
+ "admin" => $u->isadmin
+ ); }, $users);
+
+ echo $ste->exectemplate("admin.html");
+ },
"setup" => function(&$data, $url_now, &$url_next)
{
global $settings, $ste;
diff --git a/r7r_repo/templates/src/admin.html b/r7r_repo/templates/src/admin.html
new file mode 100644
index 0000000..1f5b05c
--- /dev/null
+++ b/r7r_repo/templates/src/admin.html
@@ -0,0 +1,60 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:default_error />
+ <ste:default_success />
+
+ <h2>Administration</h2>
+
+ <form action="$rel_path_to_root/admin" method="POST" accept-charset="UTF-8">
+ <h3>Repository settings</h3>
+ <strong>Repository name:</strong> <input type="text" name="repo_name" value="<ste:escape>$repo[name]</ste:escape>" /><br />
+ <strong>Repository description:</strong> <input type="text" name="repo_description" value="<ste:escape>$repo[description]</ste:escape>" /><br />
+ <strong>Repository baseurl:</strong> <input type="text" name="repo_baseurl" value="<ste:escape>$repo[baseurl]</ste:escape>" /><br />
+ <strong>Repository mode:</strong>
+ <select name="repo_mode">
+ <option value="public"?{$repo[public]| selected="selected"|}>Public</option>
+ <option value="private"?{$repo[public]|| selected="selected"}>Private</option>
+ </select><br />
+ <input type="submit" name="save_settings" />
+ </form>
+
+ <form action="$rel_path_to_root/admin" method="POST" accept-charset="UTF-8">
+ <h3>New user</h3>
+ <strong>Username:</strong> <input type="text" name="username" /> <br />
+ <strong>Password:</strong> <input type="password" name="password" /> <br />
+ <input type="submit" name="new_user" />
+ </form>
+
+ <form action="$rel_path_to_root/admin" method="POST" accept-charset="UTF-8">
+ <h3>Users</h3>
+ <table class="listtab fullwidth">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th>Username</th>
+ <th>Administrator?</th>
+ </tr>
+ </thead>
+ <tbody>
+ <ste:foreach array="users" value="u">
+ <tr>
+ <td><input type="checkbox" name="users_multiselect[]" value="$u[id]" /></td>
+ <td><ste:escape>$u[name]</ste:escape></td>
+ <td>?{$u[admin]|<strong>Yes</strong>|No}</td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ <div>
+ <input type="submit" name="delete_users" value="Delete"/>
+ <select name="really_delete">
+ <option value="yes">Yes</option>
+ <option value="no" selected="selected">No</option>
+ </select>
+ |
+ <input type="submit" name="make_admin" value="Make an admin" />
+ |
+ <input type="submit" name="make_normal_user" value="Make a normal user" />
+ </div>
+ </form>
+</ste:block>