summaryrefslogtreecommitdiff
path: root/utils/modules
diff options
context:
space:
mode:
Diffstat (limited to 'utils/modules')
-rw-r--r--utils/modules/user.php16
-rw-r--r--utils/modules/users.php181
2 files changed, 191 insertions, 6 deletions
diff --git a/utils/modules/user.php b/utils/modules/user.php
index 5e9c23b..bd1ce37 100644
--- a/utils/modules/user.php
+++ b/utils/modules/user.php
@@ -18,16 +18,20 @@ class UserAdm {
switch($action) {
case "set":
$user = $this->users->findUser($UID);
- if($user &&
- $user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
- $this->users->write();
+ if(!$user) return;
+ if($vars['oldpwd'] != "" &&
+ $vars['newpwd'] != "" &&
+ $vars['rptpwd'] != "") {
+ if($user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
+ $this->users->write();
+ }
}
default:
$form = new Form("set");
- $form->addWidget(new LineEdit("Old password:", "oldpwd", ""));
- $form->addWidget(new LineEdit("New password:", "newpwd", ""));
- $form->addWidget(new LineEdit("Repeat password:", "rptpwd", ""));
+ $form->addWidget(new LineEditPwd("Old password:", "oldpwd", ""));
+ $form->addWidget(new LineEditPwd("New password:", "newpwd", ""));
+ $form->addWidget(new LineEditPwd("Repeat password:", "rptpwd", ""));
$form->addWidget(new Button("Update"));
$form->render();
break;
diff --git a/utils/modules/users.php b/utils/modules/users.php
new file mode 100644
index 0000000..7e6fcd9
--- /dev/null
+++ b/utils/modules/users.php
@@ -0,0 +1,181 @@
+<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+global $UTIL_DIR;
+
+include_once($UTIL_DIR . "/user.php");
+
+class UsersAdm {
+ public $users;
+
+ // Admin config
+ public $admin_title = "Users";
+ public $admin_submodules = array("Add user" => "add",
+ "Edit user" => "edit",
+ "Delete user" => "delete");
+
+ public function admin_add($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "add":
+ $modulesel = $GLOBALS["modulesel"];
+
+ $modstr = "";
+ foreach($modulesel as $m) {
+ if($modstr != "") $modstr .= " ";
+ $modstr .= $m;
+ }
+
+ $all = true;
+ foreach(getModuleList() as $m) {
+ if(in_array($m, $modulesel) == false) $all = false;
+ }
+
+ if($all == true) $modstr = "*";
+
+ $pwd = sha1(md5($vars["password"]));
+ $user = new User($vars["username"], $pwd, $modstr);
+ $this->users->add($user);
+ $this->users->write();
+ break;
+
+ default:
+ $modules = array();
+ foreach(getModuleList() as $m) {
+ $modules[$m] = false;
+ }
+ $form = new Form("add");
+ $form->addWidget(new LineEdit("Username:", "username", ""));
+ $form->addWidget(new LineEditPwd("Password:", "password", ""));
+ $form->addWidget(new MultiList("Modules:", "modulesel",
+ $modules));
+ $form->addWidget(new Button("Add"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin_edit($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "write":
+ $modulesel = $GLOBALS["modulesel"];
+
+ $modstr = "";
+ foreach($modulesel as $m) {
+ if($modstr != "") $modstr .= " ";
+ $modstr .= $m;
+ }
+
+ $all = true;
+ foreach(getModuleList() as $m) {
+ if(in_array($m, $modulesel) == false) $all = false;
+ }
+
+ if($all == true) $modstr = "*";
+
+ $user = $this->users->findUser($vars["edtuser"]);
+
+ if($vars["password"] != "") {
+ $pwd = sha1(md5($vars["password"]));
+ $user->password = $pwd;
+ }
+ $user->modules = $modstr;
+ $this->users->write();
+ break;
+
+ case "edit":
+
+ $user = $this->users->findUser($vars["edtuser"]);
+
+ $modules = array();
+ foreach(getModuleList() as $m) {
+ $modules[$m] = $user->checkModule($m);
+ }
+ $form = new Form("write");
+ $form->addWidget(new Hidden(array("edtuser" => $user->userid)));
+ $form->addWidget(new LineEditPwd("Password:", "password", ""));
+ $form->addWidget(new MultiList("Modules:", "modulesel",
+ $modules));
+ $form->addWidget(new Button("Edit"));
+ $form->render();
+ break;
+
+ default:
+ $userlist = array();
+
+ foreach($this->users->useridList() as $u) {
+ $userlist[$u] = $u;
+ }
+
+ $form = new Form("edit");
+ $form->addWidget(new ComboBox("Select user to edit:", "edtuser", "",
+ $userlist));
+ $form->addWidget(new Button("Edit..."));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin_delete($action, $vars)
+ {
+ global $UID, $GLOBALS;
+
+ switch($action) {
+ case "delete":
+ if($vars["deluser"] == "admin") {
+ echo "<p>ERROR: You cannot delete the 'admin' user.</p>";
+ return;
+ }
+ $this->users->delete($vars["deluser"]);
+ $this->users->write();
+ break;
+
+ default:
+ $userlist = array();
+
+ foreach($this->users->useridList() as $u) {
+ $userlist[$u] = $u;
+ }
+
+ $form = new Form("delete");
+ $form->addWidget(new ComboBox("Select user to delete:", "deluser", "",
+ $userlist));
+ $form->addWidget(new Button("Delete"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin($sub, $action, $vars)
+ {
+ switch($sub) {
+ case "add":
+ $this->admin_add($action, $vars);
+ break;
+ case "edit":
+ $this->admin_edit($action, $vars);
+ break;
+ case "delete":
+ $this->admin_delete($action, $vars);
+ break;
+ }
+ }
+
+
+ public function UsersAdm($file)
+ {
+ $this->users = new Users($file);
+ }
+}
+
+function users_init()
+{
+ global $DATA_DIR;
+ return new UserSAdm($DATA_DIR . "/users.xml");
+}
+
+?> \ No newline at end of file