[3742] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: NBC UserAdvManager |
---|
[4061] | 4 | Version: 2.11.5 |
---|
[3742] | 5 | Description: Permet de renforcer les possibilités de gestion des utilisateurs - Enforce users management |
---|
| 6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216 |
---|
| 7 | Author: Nicco, Eric |
---|
| 8 | Author URI: http://gallery-nicco.no-ip.org, http://www.infernoweb.net |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /* |
---|
| 12 | ***** Plugin history (branch 2.10)***** |
---|
| 13 | |
---|
| 14 | -- 2.10.0-beta : Initial beta release for Piwigo compatibility |
---|
| 15 | -- 2.10.1-beta : Small correction on generated path |
---|
| 16 | -- 2.10.2-beta : Bug resolved on register validation page |
---|
| 17 | |
---|
| 18 | -- 2.10.3 : Final and fully functional release |
---|
[3982] | 19 | Bug resolved on plugin activation |
---|
[3742] | 20 | |
---|
| 21 | -- 2.10.4 : Bug fixed on profiles update |
---|
| 22 | |
---|
| 23 | -- 2.10.5 : Improved code on profiles update |
---|
| 24 | |
---|
| 25 | -- 2.10.6 : Old language packs (iso) deleted (forget from PWG 1.7.x version) |
---|
| 26 | |
---|
| 27 | -- 2.10.7 : Bug fixed on user's validation email sending |
---|
| 28 | |
---|
| 29 | -- 2.10.8 : ConfirmMail page looks better (Sylvia theme only) |
---|
[3982] | 30 | Improved code for checking author on guest comments |
---|
[3742] | 31 | |
---|
| 32 | -- 2.10.9 : Bug fixed - Missing english translation |
---|
[3982] | 33 | Bug fixed - Notice on forbidden characters function use |
---|
| 34 | Bug fixed - Audit on forbidden characters in username didn't work |
---|
| 35 | Adding of email provider exclusion (like *@hotmail.com) - Warning ! -> Known bug : This feature doesn't work on user profile page. So, already registered users can change their email address to a forbiden one. |
---|
[3742] | 36 | |
---|
| 37 | -- 2.10.9a : Email provider exclusion is no longer case sensitive |
---|
| 38 | |
---|
[3775] | 39 | -- 2.10.9b : Bug fixed - Home icon wasn't linked to gallery url in ConfirmMail page. If GALLERY_URL is not set, Home icon gets the pwg root path. |
---|
| 40 | |
---|
| 41 | -- 2.10.9c : Bug fixed - If Email provider exclusion is set off, new registered user will have a PHP notice on "Undefined variable: ncsemail" |
---|
| 42 | |
---|
| 43 | -- 2.10.9d : Code simplification - need no more ""template"" sub-directory in plugin directory for enhance "back link" icon in ConfirMail.tpl |
---|
| 44 | |
---|
| 45 | -- 2.10.9e : Compatibility improvement with PHP 5.3 - Some old functions will be deprecated like : |
---|
[3982] | 46 | ereg replaced by preg_match |
---|
| 47 | eregi replace by preg_match with "i" moderator |
---|
| 48 | split replace by preg_split |
---|
[3775] | 49 | |
---|
| 50 | -- 2.10.9f : Compatibility bug fixed when used with DynamicRecentPeriod plugin |
---|
| 51 | |
---|
[3858] | 52 | -- 2.11.0 : New tabsheet menu to manage ConfirMail functions (setting a timeout without validation, Cleanup expired user's accounts, Force confirmation, Renew validation key, list unvalidated users,...) |
---|
| 53 | Beautify plugin's main admin panel |
---|
[3872] | 54 | |
---|
| 55 | -- 2.11.1 : Bug fixed with install and upgrade functions |
---|
| 56 | Language files correction |
---|
[3742] | 57 | |
---|
[3881] | 58 | -- 2.11.2 : Bug fixed on bad query for unvalidated users display in unvalidated users list |
---|
| 59 | Bug fixed : Sql syntax error on plugin activation |
---|
| 60 | |
---|
[3982] | 61 | -- 2.11.3 : On Patricia's request (french forum and bug 1173), the unvalidated users management tab shows users according with the settings of unvalidated group and / or unvalidated status. |
---|
| 62 | Feature 1172 : Email providers exclusion list can be set with CR/LF between each entry. The comma seperator (,) is still mandatory. |
---|
| 63 | Bug 1175 fixed : Bad translation tag in french language file. |
---|
| 64 | Improvement of unvalidated users management tab (feature 1174)- Expired users are displayed in red color text. |
---|
[3896] | 65 | |
---|
[3982] | 66 | -- 2.11.4 : Bug 1177 fixed : Width of excluded email providers list reset to ancient value (80 col) |
---|
| 67 | Bug 1179 fixed : Adding a notice in plugin inline documentation for use of validation groups and status. A default group must be set in Piwigo's groups settings and the "Guest" (or another user) must be set as default for status values. |
---|
| 68 | Bug 1182 fixed : Language tag missing in confirmation email generation |
---|
| 69 | |
---|
[4061] | 70 | -- 2.11.5 : Bug 1195 fixed : Registration displays the good title |
---|
| 71 | |
---|
[4124] | 72 | -- pre 2.12.0 : Bug 1206 fixed : All plugin functionnalities work in user's profile page |
---|
| 73 | Plugin's core code and admin panel refactoring |
---|
| 74 | Password control and enforcement : A complexity score is computed on user registration. If this score is less than the goal set by admin, the password choosen is rejected. |
---|
[3742] | 75 | */ |
---|
| 76 | |
---|
| 77 | /* |
---|
| 78 | |
---|
| 79 | ***** TODO List ***** |
---|
| 80 | |
---|
| 81 | ++ No validation needed for admins users comments (new trigger needed in comments.php) |
---|
| 82 | |
---|
| 83 | ++ No single email check for admins (new trigger needed in (functions_user.inc.php ?)) |
---|
| 84 | |
---|
| 85 | ++ Password control and enforcement |
---|
[4124] | 86 | ?? Can not be the same as username -> Could password score control be sufficient ? |
---|
[3742] | 87 | |
---|
| 88 | ++ Security : Blocking brut-force attacks ! |
---|
| 89 | |
---|
| 90 | ++ Opportunity to copy a registered user for new user creation |
---|
| 91 | ++ new copied user will (or not) belong to the same groups |
---|
| 92 | ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??)) |
---|
| 93 | ++ new copied user will (or not) get the same properties |
---|
| 94 | ++ new copied user will (or not) get the same language |
---|
| 95 | ... and so on |
---|
| 96 | |
---|
| 97 | */ |
---|
| 98 | |
---|
| 99 | |
---|
[4124] | 100 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 101 | { |
---|
| 102 | die('Hacking attempt!'); |
---|
| 103 | } |
---|
[3742] | 104 | |
---|
| 105 | define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__))); |
---|
| 106 | define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[3858] | 107 | |
---|
[3742] | 108 | include_once (NBC_UserAdvManager_PATH.'include/constants.php'); |
---|
| 109 | include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php'); |
---|
[3858] | 110 | |
---|
[3742] | 111 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | /* Plugin admin */ |
---|
| 115 | add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu'); |
---|
| 116 | |
---|
| 117 | function nbc_UserAdvManager_admin_menu($menu) |
---|
| 118 | { |
---|
| 119 | array_push($menu, |
---|
| 120 | array( |
---|
| 121 | 'NAME' => 'UserAdvManager', |
---|
| 122 | 'URL' => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php') |
---|
| 123 | ) |
---|
| 124 | ); |
---|
| 125 | |
---|
| 126 | return $menu; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /* User creation */ |
---|
| 132 | add_event_handler('register_user', 'UserAdvManager_Adduser'); |
---|
| 133 | |
---|
| 134 | function UserAdvManager_Adduser($register_user) |
---|
| 135 | { |
---|
| 136 | global $conf; |
---|
| 137 | |
---|
| 138 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
[4124] | 139 | |
---|
| 140 | /* Sending registration confirmation by email */ |
---|
| 141 | if ((isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
---|
| 142 | { |
---|
| 143 | SendMail2User(1, $register_user['id'], $register_user['username'], $_POST['password'], $register_user['email'], true); |
---|
| 144 | } |
---|
[3742] | 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | /* User deletion */ |
---|
| 150 | add_event_handler('delete_user', 'UserAdvManager_Deluser'); |
---|
| 151 | |
---|
| 152 | function UserAdvManager_Deluser($user_id) |
---|
| 153 | { |
---|
| 154 | DeleteConfirmMail($user_id); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
[4124] | 158 | /* Check users registration */ |
---|
| 159 | add_event_handler('register_user_check', 'UserAdvManager_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[3742] | 160 | |
---|
[4124] | 161 | function UserAdvManager_RegistrationCheck($err, $user) |
---|
[3742] | 162 | { |
---|
[4124] | 163 | global $errors, $conf; |
---|
| 164 | |
---|
| 165 | $PasswordCheck = 0; |
---|
[4061] | 166 | |
---|
[3742] | 167 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
| 168 | |
---|
[4124] | 169 | /* Password enforcement control */ |
---|
| 170 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
---|
[3742] | 171 | { |
---|
[4124] | 172 | if (!empty($user['password']) and !is_admin()) |
---|
[3742] | 173 | { |
---|
[4124] | 174 | $PasswordCheck = testpassword($user['password']); |
---|
| 175 | |
---|
| 176 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
[3742] | 177 | { |
---|
[4124] | 178 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
| 179 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
[3742] | 180 | } |
---|
| 181 | } |
---|
[4124] | 182 | else if (!empty($user['password']) and is_admin() and isset($conf_nbc_UserAdvManager[16]) and $conf_nbc_UserAdvManager[16] == 'true') |
---|
| 183 | { |
---|
| 184 | $PasswordCheck = testpassword($user['password']); |
---|
| 185 | |
---|
| 186 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
| 187 | { |
---|
| 188 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
| 189 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
| 190 | } |
---|
| 191 | } |
---|
[3742] | 192 | } |
---|
| 193 | |
---|
[4124] | 194 | /* Username non case sensitive */ |
---|
| 195 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
---|
| 196 | { |
---|
| 197 | $new_username = NotSensibleSearchUsername($_POST['login']); |
---|
| 198 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
---|
| 199 | } |
---|
[3742] | 200 | |
---|
[4124] | 201 | /* Username without forbidden keys */ |
---|
| 202 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
---|
[3742] | 203 | { |
---|
[4124] | 204 | $_POST['login'] = ''; |
---|
| 205 | return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
---|
[3742] | 206 | } |
---|
| 207 | |
---|
[4124] | 208 | /* Email without forbidden domains */ |
---|
| 209 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address'])) |
---|
[3742] | 210 | { |
---|
[4124] | 211 | $_POST['login'] = ''; |
---|
| 212 | return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
| 213 | } |
---|
| 214 | } |
---|
[3742] | 215 | |
---|
| 216 | |
---|
[4124] | 217 | if (script_basename() == 'profile') |
---|
| 218 | { |
---|
| 219 | add_event_handler('loc_begin_profile', 'UserAdvManager_Profile_Init'); |
---|
[3742] | 220 | |
---|
[4124] | 221 | function UserAdvManager_Profile_Init() |
---|
| 222 | { |
---|
| 223 | global $conf, $user, $template; |
---|
[3742] | 224 | |
---|
[4124] | 225 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
[4061] | 226 | |
---|
[3742] | 227 | if (isset($_POST['validate'])) |
---|
| 228 | { |
---|
[4124] | 229 | /* Email without forbidden domains */ |
---|
| 230 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address'])) |
---|
[3742] | 231 | { |
---|
[4124] | 232 | if (!ValidateEmailProvider($_POST['mail_address'])) |
---|
[3742] | 233 | { |
---|
[4124] | 234 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
| 235 | unset($_POST['validate']); |
---|
[3742] | 236 | } |
---|
[4124] | 237 | } |
---|
| 238 | |
---|
| 239 | $typemail = 3; |
---|
[3742] | 240 | |
---|
[4124] | 241 | if (!empty($_POST['use_new_pwd'])) |
---|
| 242 | { |
---|
| 243 | $typemail = 2; |
---|
[3742] | 244 | |
---|
[4124] | 245 | /* Password enforcement control */ |
---|
| 246 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
---|
[3742] | 247 | { |
---|
[4124] | 248 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
---|
| 249 | |
---|
| 250 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
[3742] | 251 | { |
---|
[4124] | 252 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
| 253 | $template->append('errors', l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
| 254 | unset($_POST['use_new_pwd']); |
---|
| 255 | unset($_POST['validate']); |
---|
[3742] | 256 | } |
---|
| 257 | } |
---|
[4124] | 258 | } |
---|
| 259 | |
---|
| 260 | /* Sending registration confirmation by email */ |
---|
| 261 | if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
---|
| 262 | { |
---|
[3742] | 263 | $confirm_mail_need = false; |
---|
| 264 | |
---|
[4124] | 265 | if (!empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address'])) |
---|
[3742] | 266 | { |
---|
| 267 | $query = ' |
---|
| 268 | SELECT '.$conf['user_fields']['email'].' AS email |
---|
[4124] | 269 | FROM '.USERS_TABLE.' |
---|
[3742] | 270 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
[4124] | 271 | ;'; |
---|
| 272 | |
---|
[3742] | 273 | list($current_email) = mysql_fetch_row(pwg_query($query)); |
---|
| 274 | |
---|
| 275 | if ( $_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true') ) |
---|
[4124] | 276 | |
---|
[3742] | 277 | $confirm_mail_need = true; |
---|
| 278 | } |
---|
[4124] | 279 | |
---|
| 280 | if ((!empty($_POST['use_new_pwd']) and ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need) ) |
---|
[3742] | 281 | { |
---|
| 282 | $query = ' |
---|
| 283 | SELECT '.$conf['user_fields']['username'].' |
---|
[4124] | 284 | FROM '.USERS_TABLE.' |
---|
[3742] | 285 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
[4124] | 286 | ;'; |
---|
| 287 | |
---|
[3742] | 288 | list($username) = mysql_fetch_row(pwg_query($query)); |
---|
| 289 | |
---|
| 290 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | |
---|
[4124] | 297 | |
---|
| 298 | add_event_handler('init', 'UserAdvManager_InitPage'); |
---|
| 299 | |
---|
| 300 | function UserAdvManager_InitPage() |
---|
| 301 | { |
---|
| 302 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
| 303 | global $conf, $template, $page, $lang, $errors; |
---|
| 304 | |
---|
| 305 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
| 306 | |
---|
| 307 | /* Username non case sensitive */ |
---|
| 308 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
---|
| 309 | { |
---|
| 310 | $lang['reg_err_login5'] = l10n('reg_err_login5'); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | /* User identification */ |
---|
| 316 | if (script_basename() == 'identification') |
---|
| 317 | { |
---|
| 318 | if (isset($_POST['login'])) |
---|
| 319 | { |
---|
| 320 | /* User non case sensitive */ |
---|
| 321 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
---|
| 322 | { |
---|
| 323 | $new_username = NotSensibleSearchUsername($_POST['username']); |
---|
| 324 | $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username; |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | /* Admin user management */ |
---|
| 331 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
| 332 | { |
---|
| 333 | if (isset($_POST['submit_add'])) |
---|
| 334 | { |
---|
| 335 | /* User non case sensitive */ |
---|
| 336 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
---|
| 337 | { |
---|
| 338 | $new_username = NotSensibleSearchUsername($_POST['login']); |
---|
| 339 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | /* Username without forbidden keys */ |
---|
| 343 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
---|
| 344 | { |
---|
| 345 | $template->append('errors', l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
---|
| 346 | unset($_POST['submit_add']); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | /* Email without forbidden domains */ |
---|
| 350 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email'])) |
---|
| 351 | { |
---|
| 352 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
| 353 | unset($_POST['submit_add']); |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
[3742] | 359 | add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2); |
---|
| 360 | |
---|
| 361 | function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm) |
---|
| 362 | { |
---|
| 363 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
| 364 | global $infos, $conf, $template; |
---|
| 365 | |
---|
| 366 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
| 367 | |
---|
| 368 | /* User creation OR update */ |
---|
| 369 | if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
---|
| 370 | { |
---|
| 371 | $comment_action = 'reject'; |
---|
| 372 | |
---|
| 373 | array_push($infos, l10n('UserAdvManager_Empty Author')); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | return $comment_action; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | ?> |
---|