1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: NBC UserAdvManager |
---|
4 | Version: 2.12.0 |
---|
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 |
---|
19 | Bug resolved on plugin activation |
---|
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) |
---|
30 | Improved code for checking author on guest comments |
---|
31 | |
---|
32 | -- 2.10.9 : Bug fixed - Missing english translation |
---|
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. |
---|
36 | |
---|
37 | -- 2.10.9a : Email provider exclusion is no longer case sensitive |
---|
38 | |
---|
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 : |
---|
46 | ereg replaced by preg_match |
---|
47 | eregi replace by preg_match with "i" moderator |
---|
48 | split replace by preg_split |
---|
49 | |
---|
50 | -- 2.10.9f : Compatibility bug fixed when used with DynamicRecentPeriod plugin |
---|
51 | |
---|
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 |
---|
54 | |
---|
55 | -- 2.11.1 : Bug fixed with install and upgrade functions |
---|
56 | Language files correction |
---|
57 | |
---|
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 | |
---|
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 added : 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. |
---|
65 | |
---|
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 | |
---|
70 | -- 2.11.5 : Bug 1195 fixed : Registration displays the good title |
---|
71 | |
---|
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. |
---|
75 | Feature 1194 "Ghost Tracker" added : New plugin tab displays users who don't comes back to the gallery since x days. Ability to send email reminders and to delete reminded but "dead" users. It's the reason why this feature is called "Ghost Tracker". |
---|
76 | */ |
---|
77 | |
---|
78 | /* |
---|
79 | |
---|
80 | ***** TODO List ***** |
---|
81 | |
---|
82 | ++ No validation needed for admins users comments (new trigger needed in comments.php ?) |
---|
83 | |
---|
84 | ++ No single email check for admins (new trigger needed in functions_user.inc.php ?) |
---|
85 | |
---|
86 | ++ Password control and enforcement |
---|
87 | ?? Can not be the same as username -> Could password score control be sufficient ? |
---|
88 | |
---|
89 | ++ Security : Blocking brut-force attacks ! |
---|
90 | |
---|
91 | ++ Opportunity to copy a registered user for new user creation |
---|
92 | ++ new copied user will (or not) belong to the same groups |
---|
93 | ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??)) |
---|
94 | ++ new copied user will (or not) get the same properties |
---|
95 | ++ new copied user will (or not) get the same language |
---|
96 | ... and so on |
---|
97 | |
---|
98 | */ |
---|
99 | |
---|
100 | |
---|
101 | if (!defined('PHPWG_ROOT_PATH')) |
---|
102 | { |
---|
103 | die('Hacking attempt!'); |
---|
104 | } |
---|
105 | |
---|
106 | define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__))); |
---|
107 | define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
108 | |
---|
109 | include_once (NBC_UserAdvManager_PATH.'include/constants.php'); |
---|
110 | include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php'); |
---|
111 | |
---|
112 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
113 | |
---|
114 | |
---|
115 | /* Plugin admin */ |
---|
116 | add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu'); |
---|
117 | |
---|
118 | function nbc_UserAdvManager_admin_menu($menu) |
---|
119 | { |
---|
120 | array_push($menu, |
---|
121 | array( |
---|
122 | 'NAME' => 'UserAdvManager', |
---|
123 | 'URL' => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php') |
---|
124 | ) |
---|
125 | ); |
---|
126 | |
---|
127 | return $menu; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | add_event_handler('loc_begin_index', 'UserAdvManager_GhostTracker'); |
---|
132 | |
---|
133 | function UserAdvManager_GhostTracker() |
---|
134 | { |
---|
135 | global $conf, $user; |
---|
136 | |
---|
137 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
138 | |
---|
139 | if (isset($conf_nbc_UserAdvManager[17]) and $conf_nbc_UserAdvManager[17] == 'true' and !is_admin() and !is_a_guest()) |
---|
140 | { |
---|
141 | |
---|
142 | $userid = get_userid($user['username']); |
---|
143 | |
---|
144 | /* Looking for existing entry in last visit table */ |
---|
145 | $query = ' |
---|
146 | SELECT * |
---|
147 | FROM '.USER_LASTVISIT_TABLE.' |
---|
148 | WHERE user_id = '.$userid.' |
---|
149 | ;'; |
---|
150 | |
---|
151 | $count = mysql_num_rows(pwg_query($query)); |
---|
152 | |
---|
153 | if ($count == 0) |
---|
154 | { |
---|
155 | /* If not, data are inserted in table */ |
---|
156 | $query = ' |
---|
157 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
---|
158 | VALUES ('.$userid.', now(), "false") |
---|
159 | ;'; |
---|
160 | pwg_query($query); |
---|
161 | } |
---|
162 | else if ($count > 0) |
---|
163 | { |
---|
164 | /* If yes, data are updated in table */ |
---|
165 | $query = ' |
---|
166 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
167 | SET lastvisit = now(), reminder = "false" |
---|
168 | WHERE user_id = '.$userid.' |
---|
169 | LIMIT 1 |
---|
170 | ;'; |
---|
171 | pwg_query($query); |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | /* User creation */ |
---|
178 | add_event_handler('register_user', 'UserAdvManager_Adduser'); |
---|
179 | |
---|
180 | function UserAdvManager_Adduser($register_user) |
---|
181 | { |
---|
182 | global $conf; |
---|
183 | |
---|
184 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
185 | |
---|
186 | /* Sending registration confirmation by email */ |
---|
187 | if ((isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
---|
188 | { |
---|
189 | SendMail2User(1, $register_user['id'], $register_user['username'], $_POST['password'], $register_user['email'], true); |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | /* User deletion */ |
---|
196 | add_event_handler('delete_user', 'UserAdvManager_Deluser'); |
---|
197 | |
---|
198 | function UserAdvManager_Deluser($user_id) |
---|
199 | { |
---|
200 | DeleteConfirmMail($user_id); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | /* Check users registration */ |
---|
205 | add_event_handler('register_user_check', 'UserAdvManager_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
206 | |
---|
207 | function UserAdvManager_RegistrationCheck($err, $user) |
---|
208 | { |
---|
209 | global $errors, $conf; |
---|
210 | |
---|
211 | $PasswordCheck = 0; |
---|
212 | |
---|
213 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
214 | |
---|
215 | /* Password enforcement control */ |
---|
216 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
---|
217 | { |
---|
218 | if (!empty($user['password']) and !is_admin()) |
---|
219 | { |
---|
220 | $PasswordCheck = testpassword($user['password']); |
---|
221 | |
---|
222 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
223 | { |
---|
224 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
225 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
226 | } |
---|
227 | } |
---|
228 | else if (!empty($user['password']) and is_admin() and isset($conf_nbc_UserAdvManager[16]) and $conf_nbc_UserAdvManager[16] == 'true') |
---|
229 | { |
---|
230 | $PasswordCheck = testpassword($user['password']); |
---|
231 | |
---|
232 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
233 | { |
---|
234 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
235 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | /* Username non case sensitive */ |
---|
241 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
---|
242 | { |
---|
243 | $new_username = NotSensibleSearchUsername($_POST['login']); |
---|
244 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
---|
245 | } |
---|
246 | |
---|
247 | /* Username without forbidden keys */ |
---|
248 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
---|
249 | { |
---|
250 | $_POST['login'] = ''; |
---|
251 | return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
---|
252 | } |
---|
253 | |
---|
254 | /* Email without forbidden domains */ |
---|
255 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address'])) |
---|
256 | { |
---|
257 | $_POST['login'] = ''; |
---|
258 | return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | if (script_basename() == 'profile') |
---|
264 | { |
---|
265 | add_event_handler('loc_begin_profile', 'UserAdvManager_Profile_Init'); |
---|
266 | |
---|
267 | function UserAdvManager_Profile_Init() |
---|
268 | { |
---|
269 | global $conf, $user, $template; |
---|
270 | |
---|
271 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
272 | |
---|
273 | if (isset($_POST['validate'])) |
---|
274 | { |
---|
275 | /* Email without forbidden domains */ |
---|
276 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address'])) |
---|
277 | { |
---|
278 | if (!ValidateEmailProvider($_POST['mail_address'])) |
---|
279 | { |
---|
280 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
281 | unset($_POST['validate']); |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | $typemail = 3; |
---|
286 | |
---|
287 | if (!empty($_POST['use_new_pwd'])) |
---|
288 | { |
---|
289 | $typemail = 2; |
---|
290 | |
---|
291 | /* Password enforcement control */ |
---|
292 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
---|
293 | { |
---|
294 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
---|
295 | |
---|
296 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
---|
297 | { |
---|
298 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
---|
299 | $template->append('errors', l10n_args($message).$conf_nbc_UserAdvManager[15]); |
---|
300 | unset($_POST['use_new_pwd']); |
---|
301 | unset($_POST['validate']); |
---|
302 | } |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | /* Sending registration confirmation by email */ |
---|
307 | if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
---|
308 | { |
---|
309 | $confirm_mail_need = false; |
---|
310 | |
---|
311 | if (!empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address'])) |
---|
312 | { |
---|
313 | $query = ' |
---|
314 | SELECT '.$conf['user_fields']['email'].' AS email |
---|
315 | FROM '.USERS_TABLE.' |
---|
316 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
317 | ;'; |
---|
318 | |
---|
319 | list($current_email) = mysql_fetch_row(pwg_query($query)); |
---|
320 | |
---|
321 | if ( $_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true') ) |
---|
322 | |
---|
323 | $confirm_mail_need = true; |
---|
324 | } |
---|
325 | |
---|
326 | if ((!empty($_POST['use_new_pwd']) and ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need) ) |
---|
327 | { |
---|
328 | $query = ' |
---|
329 | SELECT '.$conf['user_fields']['username'].' |
---|
330 | FROM '.USERS_TABLE.' |
---|
331 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
332 | ;'; |
---|
333 | |
---|
334 | list($username) = mysql_fetch_row(pwg_query($query)); |
---|
335 | |
---|
336 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | } |
---|
342 | |
---|
343 | |
---|
344 | add_event_handler('init', 'UserAdvManager_InitPage'); |
---|
345 | |
---|
346 | function UserAdvManager_InitPage() |
---|
347 | { |
---|
348 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
349 | global $conf, $template, $page, $lang, $errors; |
---|
350 | |
---|
351 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
352 | |
---|
353 | /* Username non case sensitive */ |
---|
354 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
---|
355 | { |
---|
356 | $lang['reg_err_login5'] = l10n('reg_err_login5'); |
---|
357 | } |
---|
358 | |
---|
359 | |
---|
360 | |
---|
361 | /* User identification */ |
---|
362 | if (script_basename() == 'identification') |
---|
363 | { |
---|
364 | if (isset($_POST['login'])) |
---|
365 | { |
---|
366 | /* User non case sensitive */ |
---|
367 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
---|
368 | { |
---|
369 | $new_username = NotSensibleSearchUsername($_POST['username']); |
---|
370 | $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username; |
---|
371 | } |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | /* Admin user management */ |
---|
377 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
378 | { |
---|
379 | if (isset($_POST['submit_add'])) |
---|
380 | { |
---|
381 | /* User non case sensitive */ |
---|
382 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
---|
383 | { |
---|
384 | $new_username = NotSensibleSearchUsername($_POST['login']); |
---|
385 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
---|
386 | } |
---|
387 | |
---|
388 | /* Username without forbidden keys */ |
---|
389 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
---|
390 | { |
---|
391 | $template->append('errors', l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
---|
392 | unset($_POST['submit_add']); |
---|
393 | } |
---|
394 | |
---|
395 | /* Email without forbidden domains */ |
---|
396 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email'])) |
---|
397 | { |
---|
398 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
---|
399 | unset($_POST['submit_add']); |
---|
400 | } |
---|
401 | } |
---|
402 | } |
---|
403 | } |
---|
404 | |
---|
405 | |
---|
406 | add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2); |
---|
407 | |
---|
408 | function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm) |
---|
409 | { |
---|
410 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
---|
411 | global $infos, $conf, $template; |
---|
412 | |
---|
413 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
414 | |
---|
415 | /* User creation OR update */ |
---|
416 | if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
---|
417 | { |
---|
418 | $comment_action = 'reject'; |
---|
419 | |
---|
420 | array_push($infos, l10n('UserAdvManager_Empty Author')); |
---|
421 | } |
---|
422 | |
---|
423 | return $comment_action; |
---|
424 | } |
---|
425 | |
---|
426 | ?> |
---|