User Manager
Allows to manage users.
Change log
20/10/2005
- Added German translation (Konrad Bauckmeier)
24/10/2005
- New add method
- Send mail to new user
20/11/2005
- Added Polish translation (Michał Tkacz)
08/01/2006
- Added Portuguese translation (Pedro Maurício Costa)
19/02/2006
- Added Dutch translation (Steven Trooster)
Source
admin.php:
<?php if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { var $disabled = false; var $users_list; /** * Constructor */ function admin_plugin_usermanager(){ global $conf; $this->setupLocale(); $this->getUsersList(); $this->disabled = (!isset($conf['authtype']) || ($conf['authtype'] != "plain")); } /** * return some info */ function getInfo(){ $disabled = ($this->disabled) ? '(disabled)' : ''; return array( 'author' => 'neolao', 'email' => 'neo@neolao.com', 'date' => '2006-03-03', 'name' => 'User Manager', 'desc' => 'Allows to manage users '.$disabled, 'url' => 'http://resources.neolao.com/php/dokuwiki/plugin_usermanager', ); } /** * return prompt for admin menu */ function getMenuText($language) { if (!$this->disabled) return parent::getMenuText($language); return $this->lang["menu"]." (plain authentication only)"; } /** * return sort order for position in admin menu */ function getMenuSort() { return 2; } /** * handle user request */ function handle() { global $ID; if ($this->disabled) return false; $cmd = $_REQUEST['acl_cmd']; switch($cmd){ case "add": $this->user_add(); header("Location: ".wl($ID)."?do=admin&page=usermanager"); break; case "delete": $this->user_delete(); header("Location: ".wl($ID)."?do=admin&page=usermanager"); break; case "deladd": $this->user_edit(); header("Location: ".wl($ID)."?do=admin&page=usermanager"); break; } } /** * Generate users list */ function getUsersList(){ $users_auth = file(DOKU_CONF.'users.auth.php'); $this->users_list = preg_grep("/^[^#][^:]+:[^:]+:[^:]+:[^:]*:[^:]*$/", $users_auth); } /** * Get user info */ function getUserInfos($userid){ return split("[:]", join("",preg_grep("/^$userid:/", $this->users_list))); } /** * Add user */ function user_add(){ global $conf; require_once(DOKU_INC.'inc/auth.php'); $userid = $_POST['userid']; $userpass = $_POST['userpass']; $userpassold = $_POST['userpassold']; $username = $_POST['username']; $usermail = $_POST['usermail']; $usergroups = $_POST['usergroups']; $sendpassword = $_POST['sendpassword']; if(empty($userid) || empty($username)){ return false; } if(empty($userpass) && !empty($userpassold)){ $userpass = $userpassold; }else{ $userpass_nocrypt = $userpass; $userpass = auth_cryptPassword($userpass); } $users_auth = join("",file(DOKU_CONF.'users.auth.php')); $new_user = "$userid:$userpass:$username:$usermail:$usergroups\n"; $new_auth = $users_auth.$new_user; io_saveFile(DOKU_CONF.'users.auth.php', $new_auth); if($sendpassword == "on"){ auth_sendPassword($userid, $userpass_nocrypt); } } /** * Delete user */ function user_delete(){ $userid = $_REQUEST['userid']; $users_auth = file(DOKU_CONF.'users.auth.php'); $new_auth = preg_grep("/^$userid:/", $users_auth, PREG_GREP_INVERT); return io_saveFile(DOKU_CONF.'users.auth.php', join('',$new_auth)); } /** * Delete user */ function user_edit(){ $this->user_delete(); $this->user_add(); } /** * output appropriate html */ function html() { global $lang; global $ID; if($this->disabled){ print "plain authentication only"; return false; } print $this->plugin_locale_xhtml('intro'); print $this->plugin_locale_xhtml('list'); print "<div class=\"level2\">"; print "<table class=\"inline\">"; print "<tr>"; print "<th>".$this->lang["user_id"]."</th><th>".$this->lang["user_pass"]."</th><th>".$this->lang["user_name"]."</th><th>".$this->lang["user_mail"]."</th><th>".$this->lang["user_groups"]."</th>"; print "</tr>"; foreach ($this->users_list as $user_index => $user) { list($user_id, $user_pass, $user_name, $user_mail, $user_groups) = split('[:]', $user); print "<tr><td>".$user_id."</td><td>".$user_pass."</td><td>".$user_name."</td><td>".$user_mail."</td><td>".$user_groups."</td></tr>"; } print "</table>"; print "</div>"; print $this->plugin_locale_xhtml('add'); print "<div class=\"level2\">"; print "<form action=\"".wl($ID)."\" method=\"post\">"; print "<table class=\"inline\">"; print "<tr><th>".$this->lang["field"]."</th><th>".$this->lang["value"]."</th></tr>"; print "<tr><td>".$this->lang["user_id"]." : </td><td><input type=\"text\" name=\"userid\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["user_pass"]." : </td><td><input type=\"text\" name=\"userpass\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["user_name"]." : </td><td><input type=\"text\" name=\"username\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["user_mail"]." : </td><td><input type=\"text\" name=\"usermail\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["user_groups"]." : </td><td><input type=\"text\" name=\"usergroups\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["send_password"]." : </td><td><input type=\"checkbox\" name=\"sendpassword\" checked=\"checked\"/></td></tr>"; print "</table>"; print "<p>"; print "<input type=\"hidden\" name=\"do\" value=\"admin\" />"; print "<input type=\"hidden\" name=\"page\" value=\"usermanager\" />"; print "<input type=\"hidden\" name=\"acl_cmd\" value=\"add\" />"; print "<input type=\"submit\" name=\"submit\" value=\"".$this->lang["add"]."\" />"; print "</p>"; print "</form>"; print "</div>"; print $this->plugin_locale_xhtml('delete'); print "<div class=\"level2\">"; print "<form action=\"".wl($ID)."\" method=\"post\">"; print "<input type=\"hidden\" name=\"do\" value=\"admin\" />"; print "<input type=\"hidden\" name=\"page\" value=\"usermanager\" />"; print "<input type=\"hidden\" name=\"acl_cmd\" value=\"delete\" />"; print "<p>"; print "<select name=\"userid\">"; reset($this->users_list); foreach ($this->users_list as $user_index => $user) { list($user_id, $user_pass, $user_name, $user_mail, $user_groups) = split('[:]', $user); print "<option value=\"".$user_id."\">".$user_id."</option>"; } print "</select>"; print "<input type=\"submit\" name=\"submit\" value=\"".$this->lang["delete"]."\" />"; print "</p>"; print "</form>"; print "</div>"; print $this->plugin_locale_xhtml('edit'); print "<div class=\"level2\">"; print "<form action=\"".wl($ID)."\" method=\"post\">"; print "<p>"; print "<input type=\"hidden\" name=\"do\" value=\"admin\" />"; print "<input type=\"hidden\" name=\"page\" value=\"usermanager\" />"; print "<input type=\"hidden\" name=\"acl_cmd\" value=\"edit\" />"; print "<select name=\"userid\">"; reset($this->users_list); foreach ($this->users_list as $user_index => $user) { list($user_id, $user_pass, $user_name, $user_mail, $user_groups) = split('[:]', $user); print "<option value=\"".$user_id."\">".$user_id."</option>"; } print "</select>"; print "<input type=\"submit\" name=\"submit\" value=\"".$this->lang["edit"]."\" />"; print "</p>"; print "</form>"; if($_REQUEST['acl_cmd'] == "edit"){ list($user_id, $user_pass, $user_name, $user_mail, $user_groups) = $this->getUserInfos($_REQUEST['userid']); print "<form action=\"".wl($ID)."\" method=\"post\">"; print "<table class=\"inline\">"; print "<tr><th>".$this->lang["field"]."</th><th>".$this->lang["value"]."</th></tr>"; print "<tr><td>".$this->lang["user_id"]." : </td><td><input type=\"text\" name=\"userid\" value=\"".$user_id."\" /></td></tr>"; print "<tr><td>".$this->lang["user_pass"]." : </td><td><input type=\"text\" name=\"userpass\" value=\"\" /></td></tr>"; print "<tr><td>".$this->lang["user_name"]." : </td><td><input type=\"text\" name=\"username\" value=\"".$user_name."\" /></td></tr>"; print "<tr><td>".$this->lang["user_mail"]." : </td><td><input type=\"text\" name=\"usermail\" value=\"".$user_mail."\" /></td></tr>"; print "<tr><td>".$this->lang["user_groups"]." : </td><td><input type=\"text\" name=\"usergroups\" value=\"".$user_groups."\" /></td></tr>"; print "</table>"; print "<p>"; print "<input type=\"hidden\" name=\"do\" value=\"admin\" />"; print "<input type=\"hidden\" name=\"page\" value=\"usermanager\" />"; print "<input type=\"hidden\" name=\"acl_cmd\" value=\"deladd\" />"; print "<input type=\"hidden\" name=\"userpassold\" value=\"".$user_pass."\" />"; print "<input type=\"submit\" name=\"submit\" value=\"".$this->lang["edit"]."\" />"; print "</p>"; print "</form>"; } print "</div>"; } }