diff options
author | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:40:15 +0100 |
---|---|---|
committer | Gerry Weißbach <gerry.w@gammaproduction.de> | 2014-12-22 10:40:15 +0100 |
commit | fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca (patch) | |
tree | 3d287ae466500a6072b84d14ff4911fa936d1479 /lib/plugins/authmysql | |
parent | de4634ec87b1a277c1686990d993dafc43db05ed (diff) | |
parent | 8da2ebf4f4261eb8f54df5704b5d9af283b5402d (diff) | |
download | rpg-fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca.tar.gz rpg-fc30ac3acbd4e17e25955ccdd0c5539ee2c9beca.tar.bz2 |
Merge branch 'master' into new_css.php
Diffstat (limited to 'lib/plugins/authmysql')
-rw-r--r-- | lib/plugins/authmysql/auth.php | 203 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/cs/settings.php | 5 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/da/settings.php | 4 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/fa/settings.php | 10 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/fi/settings.php | 11 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/hr/settings.php | 2 | ||||
-rw-r--r-- | lib/plugins/authmysql/lang/no/settings.php | 14 |
7 files changed, 200 insertions, 49 deletions
diff --git a/lib/plugins/authmysql/auth.php b/lib/plugins/authmysql/auth.php index 1e6e6a4a9..0d423b6c9 100644 --- a/lib/plugins/authmysql/auth.php +++ b/lib/plugins/authmysql/auth.php @@ -21,6 +21,9 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { /** @var int database subrevision */ protected $dbsub = 0; + /** @var array cache to avoid re-reading user info data */ + protected $cacheUserInfo = array(); + /** * Constructor * @@ -112,7 +115,8 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * Check if the given config strings are set * * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> - * @param array $keys + * + * @param string[] $keys * @param bool $wop is this a check for a write operation? * @return bool */ @@ -157,10 +161,11 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $result = $this->_queryDB($sql); if($result !== false && count($result) == 1) { - if($this->getConf('forwardClearPass') == 1) + if($this->getConf('forwardClearPass') == 1) { $rc = true; - else + } else { $rc = auth_verifyPassword($pass, $result[0]['pass']); + } } $this->_closeDB(); } @@ -174,16 +179,23 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * * @param string $user user login to get data for + * @param bool $requireGroups when true, group membership information should be included in the returned array; + * when false, it maybe included, but is not required by the caller * @return array|bool */ - public function getUserData($user) { + public function getUserData($user, $requireGroups=true) { + if($this->_cacheExists($user, $requireGroups)) { + return $this->cacheUserInfo[$user]; + } + if($this->_openDB()) { $this->_lockTables("READ"); - $info = $this->_getUserInfo($user); + $info = $this->_getUserInfo($user, $requireGroups); $this->_unlockTables(); $this->_closeDB(); - } else + } else { $info = false; + } return $info; } @@ -209,12 +221,14 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { global $conf; if($this->_openDB()) { - if(($info = $this->_getUserInfo($user)) !== false) + if(($info = $this->_getUserInfo($user)) !== false) { return false; // user already exists + } // set defaultgroup if no groups were given - if($grps == null) + if($grps == null) { $grps = array($conf['defaultgroup']); + } $this->_lockTables("WRITE"); $pwd = $this->getConf('forwardClearPass') ? $pwd : auth_cryptPassword($pwd); @@ -234,17 +248,17 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * The dataset update will be rejected if the user name should be changed * to an already existing one. * - * The password must be provides unencrypted. Pasword cryption is done + * The password must be provided unencrypted. Pasword encryption is done * automatically if configured. * - * If one or more groups could't be updated, an error would be set. In + * If one or more groups can't be updated, an error will be set. In * this case the dataset might already be changed and we can't rollback - * the changes. Transactions would be really usefull here. + * the changes. Transactions would be really useful here. * * modifyUser() may be called without SQL statements defined that are * needed to change group membership (for example if only the user profile - * should be modified). In this case we asure that we don't touch groups - * even $changes['grps'] is set by mistake. + * should be modified). In this case we assure that we don't touch groups + * even when $changes['grps'] is set by mistake. * * @author Chris Smith <chris@jalakai.co.uk> * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> @@ -256,27 +270,30 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { public function modifyUser($user, $changes) { $rc = false; - if(!is_array($changes) || !count($changes)) + if(!is_array($changes) || !count($changes)) { return true; // nothing to change + } if($this->_openDB()) { $this->_lockTables("WRITE"); - if(($uid = $this->_getUserID($user))) { - $rc = $this->_updateUserInfo($changes, $uid); + $rc = $this->_updateUserInfo($user, $changes); - if($rc && isset($changes['grps']) && $this->cando['modGroups']) { - $groups = $this->_getGroups($user); - $grpadd = array_diff($changes['grps'], $groups); - $grpdel = array_diff($groups, $changes['grps']); + if($rc && isset($changes['grps']) && $this->cando['modGroups']) { + $groups = $this->_getGroups($user); + $grpadd = array_diff($changes['grps'], $groups); + $grpdel = array_diff($groups, $changes['grps']); - foreach($grpadd as $group) - if(($this->_addUserToGroup($user, $group, 1)) == false) - $rc = false; + foreach($grpadd as $group) { + if(($this->_addUserToGroup($user, $group, true)) == false) { + $rc = false; + } + } - foreach($grpdel as $group) - if(($this->_delUserFromGroup($user, $group)) == false) - $rc = false; + foreach($grpdel as $group) { + if(($this->_delUserFromGroup($user, $group)) == false) { + $rc = false; + } } } @@ -304,8 +321,9 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { if(is_array($users) && count($users)) { $this->_lockTables("WRITE"); foreach($users as $user) { - if($this->_delUser($user)) + if($this->_delUser($user)) { $count++; + } } $this->_unlockTables(); } @@ -349,7 +367,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * * @param int $first index of first user to be returned * @param int $limit max number of users to be returned - * @param array|string $filter array of field/pattern pairs + * @param array $filter array of field/pattern pairs * @return array userinfo (refer getUserData for internal userinfo details) */ public function retrieveUsers($first = 0, $limit = 0, $filter = array()) { @@ -367,9 +385,11 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $result = $this->_queryDB($sql); if(!empty($result)) { - foreach($result as $user) - if(($info = $this->_getUserInfo($user['user']))) + foreach($result as $user) { + if(($info = $this->_getUserInfo($user['user']))) { $out[$user['user']] = $info; + } + } } $this->_unlockTables(); @@ -466,7 +486,10 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $sql = str_replace('%{user}', $this->_escape($user), $sql); $sql = str_replace('%{gid}', $this->_escape($gid), $sql); $sql = str_replace('%{group}', $this->_escape($group), $sql); - if($this->_modifyDB($sql) !== false) return true; + if($this->_modifyDB($sql) !== false) { + $this->_flushUserInfoCache($user); + return true; + } if($newgroup) { // remove previously created group on error $sql = str_replace('%{gid}', $this->_escape($gid), $this->getConf('delGroup')); @@ -501,6 +524,10 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $sql = str_replace('%{gid}', $this->_escape($gid), $sql); $sql = str_replace('%{group}', $this->_escape($group), $sql); $rc = $this->_modifyDB($sql) == 0 ? true : false; + + if ($rc) { + $this->_flushUserInfoCache($user); + } } } return $rc; @@ -526,8 +553,9 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $result = $this->_queryDB($sql); if($result !== false && count($result)) { - foreach($result as $row) + foreach($result as $row) { $groups[] = $row['group']; + } } return $groups; } @@ -585,11 +613,12 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { if($uid) { foreach($grps as $group) { - $gid = $this->_addUserToGroup($user, $group, 1); + $gid = $this->_addUserToGroup($user, $group, true); if($gid === false) break; } if($gid !== false){ + $this->_flushUserInfoCache($user); return true; } else { /* remove the new user and all group relations if a group can't @@ -614,7 +643,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * - * @param string $user user whose id is desired + * @param string $user username of the user to be deleted * @return bool */ protected function _delUser($user) { @@ -626,6 +655,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $sql = str_replace('%{uid}', $this->_escape($uid), $this->getConf('delUser')); $sql = str_replace('%{user}', $this->_escape($user), $sql); $this->_modifyDB($sql); + $this->_flushUserInfoCache($user); return true; } } @@ -633,23 +663,100 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { } /** - * getUserInfo + * Flush cached user information + * + * @author Christopher Smith <chris@jalakai.co.uk> + * + * @param string $user username of the user whose data is to be removed from the cache + * if null, empty the whole cache + */ + protected function _flushUserInfoCache($user=null) { + if (is_null($user)) { + $this->cacheUserInfo = array(); + } else { + unset($this->cacheUserInfo[$user]); + } + } + + /** + * Quick lookup to see if a user's information has been cached + * + * This test does not need a database connection or read lock * - * Gets the data for a specific user The database connection + * @author Christopher Smith <chris@jalakai.co.uk> + * + * @param string $user username to be looked up in the cache + * @param bool $requireGroups true, if cached info should include group memberships + * + * @return bool existence of required user information in the cache + */ + protected function _cacheExists($user, $requireGroups=true) { + if (isset($this->cacheUserInfo[$user])) { + if (!is_array($this->cacheUserInfo[$user])) { + return true; // user doesn't exist + } + + if (!$requireGroups || isset($this->cacheUserInfo[$user]['grps'])) { + return true; + } + } + + return false; + } + + /** + * Get a user's information + * + * The database connection must already be established for this function to work. + * + * @author Christopher Smith <chris@jalakai.co.uk> + * + * @param string $user username of the user whose information is being reterieved + * @param bool $requireGroups true if group memberships should be included + * @param bool $useCache true if ok to return cached data & to cache returned data + * + * @return mixed false|array false if the user doesn't exist + * array containing user information if user does exist + */ + protected function _getUserInfo($user, $requireGroups=true, $useCache=true) { + $info = null; + + if ($useCache && isset($this->cacheUserInfo[$user])) { + $info = $this->cacheUserInfo[$user]; + } + + if (is_null($info)) { + $info = $this->_retrieveUserInfo($user); + } + + if (($requireGroups == true) && $info && !isset($info['grps'])) { + $info['grps'] = $this->_getGroups($user); + } + + if ($useCache) { + $this->cacheUserInfo[$user] = $info; + } + + return $info; + } + + /** + * retrieveUserInfo + * + * Gets the data for a specific user. The database connection * must already be established for this function to work. * Otherwise it will return 'false'. * * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * * @param string $user user's nick to get data for - * @return bool|array false on error, user info on success + * @return false|array false on error, user info on success */ - protected function _getUserInfo($user) { + protected function _retrieveUserInfo($user) { $sql = str_replace('%{user}', $this->_escape($user), $this->getConf('getUserInfo')); $result = $this->_queryDB($sql); if($result !== false && count($result)) { $info = $result[0]; - $info['grps'] = $this->_getGroups($user); return $info; } return false; @@ -666,20 +773,25 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * The database connection has already to be established for this * function to work. Otherwise it will return 'false'. * - * The password will be crypted if necessary. + * The password will be encrypted if necessary. * + * @param string $user user's nick being updated * @param array $changes array of items to change as pairs of item and value - * @param mixed $uid user id of dataset to change, must be unique in DB * @return bool true on success or false on error * * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ - protected function _updateUserInfo($changes, $uid) { + protected function _updateUserInfo($user, $changes) { $sql = $this->getConf('updateUser')." "; $cnt = 0; $err = 0; if($this->dbcon) { + $uid = $this->_getUserID($user); + if ($uid === false) { + return false; + } + foreach($changes as $item => $value) { if($item == 'user') { if(($this->_getUserID($changes['user']))) { @@ -707,6 +819,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { $sql .= " ".str_replace('%{uid}', $uid, $this->getConf('UpdateTarget')); if(get_class($this) == 'auth_mysql') $sql .= " LIMIT 1"; //some PgSQL inheritance comp. $this->_modifyDB($sql); + $this->_flushUserInfoCache($user); } return true; } @@ -724,7 +837,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * * @param string $group group name which id is desired - * @return mixed group id + * @return false|string group id */ protected function _getGroupID($group) { if($this->dbcon) { @@ -797,7 +910,7 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> * * @param string $query SQL string that contains the query - * @return array with the result table + * @return array|false with the result table */ protected function _queryDB($query) { if($this->getConf('debug') >= 2) { @@ -888,6 +1001,8 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin { * abrogated. * * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> + * + * @return bool */ protected function _unlockTables() { if($this->dbcon) { diff --git a/lib/plugins/authmysql/lang/cs/settings.php b/lib/plugins/authmysql/lang/cs/settings.php index 350c3236b..09146a451 100644 --- a/lib/plugins/authmysql/lang/cs/settings.php +++ b/lib/plugins/authmysql/lang/cs/settings.php @@ -4,6 +4,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * * @author mkucera66@seznam.cz + * @author Jaroslav Lichtblau <jlichtblau@seznam.cz> */ $lang['server'] = 'Váš server MySQL'; $lang['user'] = 'Uživatelské jméno pro MySQL'; @@ -19,7 +20,7 @@ $lang['getGroups'] = 'Příkaz SQL pro získání uživatelovy skupi $lang['getUsers'] = 'Příkaz SQL pro seznam všech uživatelů'; $lang['FilterLogin'] = 'Příkaz SQL pro filtrování uživatelů podle přihlašovacího jména'; $lang['FilterName'] = 'Příkaz SQL pro filtrování uživatelů podle celého jména'; -$lang['FilterEmail'] = 'Příkaz SQL pro filtrování uživatelů podle adres emailů'; +$lang['FilterEmail'] = 'Příkaz SQL pro filtrování uživatelů podle adres e-mailů'; $lang['FilterGroup'] = 'Příkaz SQL pro filtrování uživatelů podle členství ve skupinách'; $lang['SortOrder'] = 'Příkaz SQL pro řazení uživatelů'; $lang['addUser'] = 'Příkaz SQL pro přidání nového uživatele'; @@ -32,7 +33,7 @@ $lang['delUserRefs'] = 'Příkaz SQL pro odstranění členství uživ $lang['updateUser'] = 'Příkaz SQL pro aktualizaci uživatelského profilu'; $lang['UpdateLogin'] = 'Klauzule pro aktualizaci přihlačovacího jména uživatele'; $lang['UpdatePass'] = 'Klauzule pro aktualizaci hesla uživatele'; -$lang['UpdateEmail'] = 'Klauzule pro aktualizaci emailové adresy uživatele'; +$lang['UpdateEmail'] = 'Klauzule pro aktualizaci e-mailové adresy uživatele'; $lang['UpdateName'] = 'Klauzule pro aktualizaci celého jména uživatele'; $lang['UpdateTarget'] = 'Omezující klauzule pro identifikaci uživatele při aktualizaci'; $lang['delUserGroup'] = 'Příkaz SQL pro zrušení členství uživatele v dané skupině'; diff --git a/lib/plugins/authmysql/lang/da/settings.php b/lib/plugins/authmysql/lang/da/settings.php index 1e38cb6b4..ed21201fb 100644 --- a/lib/plugins/authmysql/lang/da/settings.php +++ b/lib/plugins/authmysql/lang/da/settings.php @@ -2,7 +2,7 @@ /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) - * + * * @author Jens Hyllegaard <jens.hyllegaard@gmail.com> * @author soer9648 <soer9648@eucl.dk> */ @@ -11,6 +11,7 @@ $lang['user'] = 'MySQL brugernavn'; $lang['password'] = 'Kodeord til ovenstående bruger'; $lang['database'] = 'Database der skal benyttes'; $lang['charset'] = 'Tegnsæt benyttet i database'; +$lang['debug'] = 'Vis yderligere debug output'; $lang['checkPass'] = 'SQL-sætning til at kontrollere kodeord'; $lang['getUserInfo'] = 'SQL-sætning til at hente brugerinformation'; $lang['getUsers'] = 'SQL-sætning til at liste alle brugere'; @@ -21,7 +22,6 @@ $lang['delGroup'] = 'SQL-sætning til at fjerne en gruppe'; $lang['delUser'] = 'SQL-sætning til at slette en bruger'; $lang['delUserRefs'] = 'SQL-sætning til at fjerne en bruger fra alle grupper'; $lang['updateUser'] = 'SQL-sætning til at opdatere en brugerprofil'; -$lang['debug'] = 'Vis yderligere debug output'; $lang['debug_o_0'] = 'ingen'; $lang['debug_o_1'] = 'kun ved fejl'; $lang['debug_o_2'] = 'alle SQL forespørgsler'; diff --git a/lib/plugins/authmysql/lang/fa/settings.php b/lib/plugins/authmysql/lang/fa/settings.php new file mode 100644 index 000000000..68ad5ce83 --- /dev/null +++ b/lib/plugins/authmysql/lang/fa/settings.php @@ -0,0 +1,10 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Mohamad Mehdi Habibi <habibi.esf@gmail.com> + */ +$lang['server'] = 'سرور MySQL'; +$lang['user'] = 'نام کاربری MySQL'; +$lang['database'] = 'پایگاه داده مورد استفاده'; diff --git a/lib/plugins/authmysql/lang/fi/settings.php b/lib/plugins/authmysql/lang/fi/settings.php new file mode 100644 index 000000000..32517957b --- /dev/null +++ b/lib/plugins/authmysql/lang/fi/settings.php @@ -0,0 +1,11 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Jussi Takala <jussi.takala@live.fi> + */ +$lang['server'] = 'Sinun MySQL-serveri'; +$lang['user'] = 'MySQL-käyttäjänimi'; +$lang['password'] = 'Salasana yläolevalle käyttäjälle'; +$lang['charset'] = 'Käytetty merkistö tietokannassa'; diff --git a/lib/plugins/authmysql/lang/hr/settings.php b/lib/plugins/authmysql/lang/hr/settings.php index 0ef389f46..af9966999 100644 --- a/lib/plugins/authmysql/lang/hr/settings.php +++ b/lib/plugins/authmysql/lang/hr/settings.php @@ -19,7 +19,7 @@ $lang['getGroups'] = 'SQL izraz za dohvaćanje članstva u grupama'; $lang['getUsers'] = 'SQL izraz za ispis svih korisnika'; $lang['FilterLogin'] = 'SQL izraz za izdvajanje korisnika po korisničkom imenu'; $lang['FilterName'] = 'SQL izraz za izdvajanje korisnika po punom imenu'; -$lang['FilterEmail'] = 'SQL izraz za izdvajanje korisnika po email adresi'; +$lang['FilterEmail'] = 'SQL izraz za izdvajanje korisnika po adresi e-pošte'; $lang['FilterGroup'] = 'SQL izraz za izdvajanje korisnika po članstvu u grupama'; $lang['SortOrder'] = 'SQL izraz za sortiranje korisnika'; $lang['addUser'] = 'SQL izraz za dodavanje novih korisnika'; diff --git a/lib/plugins/authmysql/lang/no/settings.php b/lib/plugins/authmysql/lang/no/settings.php new file mode 100644 index 000000000..45ab09819 --- /dev/null +++ b/lib/plugins/authmysql/lang/no/settings.php @@ -0,0 +1,14 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author Patrick <spill.p@hotmail.com> + */ +$lang['server'] = 'Din MySQL-server'; +$lang['user'] = 'Ditt MySQL-brukernavn'; +$lang['password'] = 'Passord til brukeren'; +$lang['database'] = 'Database som skal brukes'; +$lang['debug_o_0'] = 'ingen'; +$lang['debug_o_1'] = 'bare ved feil'; +$lang['debug_o_2'] = 'alle SQL-forespørsler'; |