source: extensions/NBC_UserAdvManager/tags/2.12.2/main.inc.php @ 4161

Last change on this file since 4161 was 4161, checked in by Eric, 14 years ago

[NBC_UserAdvManager] Buld Tag 2.12.2 from Branch 2.12 :
Bug 1221 fixed - Adding of a new funtion to populate the lastvisit table on Ghost Tracker activation

Bug 1224 fixed - Error in database after plugin activation

Bug 1225 fixed - "Reminder" status don't change from "false" to "true" after the sent of a reminder email

Some code beautify (SQL requests and HTML 4 strict for tpl)

  • Property svn:eol-style set to LF
File size: 16.4 KB
Line 
1<?php
2/*
3Plugin Name: NBC UserAdvManager
4Version: 2.12.1
5Description: Permet de renforcer les possibilités de gestion des utilisateurs - Enforce users management
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216
7Author: Nicco, Eric
8Author 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-- 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-- 2.12.1 : Rollback on admin panel improvement (it was a bad idea)
78
79-- 2.12.2 : Bug 1221 fixed - Adding of a new funtion to populate the lastvisit table on Ghost Tracker activation
80            Bug 1224 fixed - Error in database after plugin activation
81            Bug 1225 fixed - "Reminder" status don't change from "false" to "true" after the sent of a reminder email
82            Some code beautify (SQL requests and HTML 4 strict for tpl)
83*/
84
85/*
86
87 ***** TODO List *****
88++ No validation needed for admins users comments (new trigger needed in comments.php ?)
89
90++ No single email check for admins (new trigger needed in functions_user.inc.php ?)
91
92++ Password control and enforcement
93  ?? Can not be the same as username -> Could password score control be sufficient ?
94 
95++ Security : Blocking brut-force attacks !
96              -> Way to do that : Count the number of failed attempts to connect and lock the targetted account after x attempts. Where x will be settable by admin.
97              To unlock the locked account :
98               -> A new table in admin's plugin panel which would display the locked accounts.
99               -> Sending an email to account owner to inform him his account is blocked due to multiple failed connexions attempts. This email could have a link with a security key to unlock the account.
100               -> Both of above solutions ?
101
102++ Opportunity to copy a registered user for new user creation
103  ++ new copied user will (or not) belong to the same groups
104  ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??))
105  ++ new copied user will (or not) get the same properties
106  ++ new copied user will (or not) get the same language
107  ... and so on
108 
109*/
110
111
112if (!defined('PHPWG_ROOT_PATH'))
113{
114  die('Hacking attempt!');
115}
116
117define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__)));
118define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
119
120include_once (NBC_UserAdvManager_PATH.'include/constants.php');
121include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php');
122
123load_language('plugin.lang', NBC_UserAdvManager_PATH);
124
125
126/* Plugin admin */
127add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu');
128
129function nbc_UserAdvManager_admin_menu($menu)
130{
131  array_push($menu,
132    array(
133      'NAME' => 'UserAdvManager',
134      'URL'  => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php')
135    )
136  );
137
138  return $menu;
139}
140
141
142add_event_handler('loc_begin_index', 'UserAdvManager_GhostTracker');
143
144function UserAdvManager_GhostTracker()
145{
146  global $conf, $user;
147 
148  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
149
150  if (isset($conf_nbc_UserAdvManager[17]) and $conf_nbc_UserAdvManager[17] == 'true' and !is_admin() and !is_a_guest())
151  {
152
153    $userid = get_userid($user['username']);
154         
155    /* Looking for existing entry in last visit table */
156    $query = '
157SELECT *
158  FROM '.USER_LASTVISIT_TABLE.'
159WHERE user_id = '.$userid.'
160;';
161       
162    $count = mysql_num_rows(pwg_query($query));
163         
164    if ($count == 0)
165    {
166      /* If not, data are inserted in table */
167      $query = '
168INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder)
169VALUES ('.$userid.', now(), "false")
170;';
171      pwg_query($query);
172    }
173    else if ($count > 0)
174    {
175      /* If yes, data are updated in table */
176      $query = '
177UPDATE '.USER_LASTVISIT_TABLE.'
178SET lastvisit = now(), reminder = "false"
179WHERE user_id = '.$userid.'
180LIMIT 1
181;';
182      pwg_query($query);
183    }
184  }
185}
186
187
188/* User creation */
189add_event_handler('register_user', 'UserAdvManager_Adduser');
190
191function UserAdvManager_Adduser($register_user)
192{
193  global $conf;
194 
195  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
196 
197  /* Sending registration confirmation by email */
198  if ((isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
199  {
200    SendMail2User(1, $register_user['id'], $register_user['username'], $_POST['password'], $register_user['email'], true);
201  }
202}
203
204
205
206/* User deletion */
207add_event_handler('delete_user', 'UserAdvManager_Deluser');
208
209function UserAdvManager_Deluser($user_id)
210{
211  /* Cleanup for ConfirmMail table */
212  DeleteConfirmMail($user_id);
213  /* Cleanup for LastVisit table */
214  DeleteLastVisit($user_id);
215}
216
217
218/* Check users registration */
219add_event_handler('register_user_check', 'UserAdvManager_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
220
221function UserAdvManager_RegistrationCheck($err, $user)
222{
223  global $errors, $conf;
224
225  $PasswordCheck = 0;
226 
227  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
228
229  /* Password enforcement control */
230  if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15]))
231  {
232    if (!empty($user['password']) and !is_admin())
233    {
234      $PasswordCheck = testpassword($user['password']);
235 
236      if ($PasswordCheck < $conf_nbc_UserAdvManager[15])
237      {
238        $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
239        return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]);
240      }
241    }
242    else if (!empty($user['password']) and is_admin() and isset($conf_nbc_UserAdvManager[16]) and $conf_nbc_UserAdvManager[16] == 'true')
243    { 
244      $PasswordCheck = testpassword($user['password']);
245 
246      if ($PasswordCheck < $conf_nbc_UserAdvManager[15])
247      {
248        $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
249        return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]);
250      }
251    }
252  }
253
254  /* Username non case sensitive */
255  if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true')
256  {
257    $new_username =  NotSensibleSearchUsername($_POST['login']);
258    $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
259  }
260
261  /* Username without forbidden keys */
262  if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
263  {
264    $_POST['login'] = '';
265    return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'");
266  }
267
268  /* Email without forbidden domains */
269  if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address']))
270  {
271    $_POST['login'] = '';
272    return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'");
273  }
274}
275
276
277if (script_basename() == 'profile')
278{
279  add_event_handler('loc_begin_profile', 'UserAdvManager_Profile_Init');
280
281  function UserAdvManager_Profile_Init()
282  {
283    global $conf, $user, $template;
284
285    $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
286
287    if (isset($_POST['validate']))
288    {
289      /* Email without forbidden domains */
290      if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']))
291      {
292        if (!ValidateEmailProvider($_POST['mail_address']))
293        {
294          $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'");
295          unset($_POST['validate']);
296        }
297      }
298
299      $typemail = 3;
300     
301      if (!empty($_POST['use_new_pwd']))
302      {
303        $typemail = 2;
304       
305        /* Password enforcement control */
306        if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15]))
307        {
308          $PasswordCheck = testpassword($_POST['use_new_pwd']);
309         
310          if ($PasswordCheck < $conf_nbc_UserAdvManager[15])
311          {
312            $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
313            $template->append('errors', l10n_args($message).$conf_nbc_UserAdvManager[15]);
314            unset($_POST['use_new_pwd']);
315            unset($_POST['validate']);
316          }
317        }
318      }
319     
320      /* Sending registration confirmation by email */
321      if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
322      {
323        $confirm_mail_need = false;
324             
325        if (!empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address']))
326        {
327          $query = '
328SELECT '.$conf['user_fields']['email'].' AS email
329FROM '.USERS_TABLE.'
330WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
331;';
332         
333          list($current_email) = mysql_fetch_row(pwg_query($query));
334     
335          if ( $_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true') )
336       
337            $confirm_mail_need = true;
338        }
339       
340        if ((!empty($_POST['use_new_pwd']) and ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need) )
341        {
342          $query = '
343SELECT '.$conf['user_fields']['username'].'
344FROM '.USERS_TABLE.'
345WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
346;';
347       
348          list($username) = mysql_fetch_row(pwg_query($query));
349
350          SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
351        }
352      }
353    }
354  }
355}
356
357
358add_event_handler('init', 'UserAdvManager_InitPage');
359 
360function UserAdvManager_InitPage()
361{
362  load_language('plugin.lang', NBC_UserAdvManager_PATH);
363  global $conf, $template, $page, $lang, $errors;
364
365  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
366 
367  /* Username non case sensitive */
368  if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true')
369  {
370    $lang['reg_err_login5'] = l10n('reg_err_login5');
371  }
372 
373
374 
375/* User identification */
376  if (script_basename() == 'identification')
377  {
378    if (isset($_POST['login']))
379    {
380      /* User non case sensitive */
381      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
382      {
383        $new_username =  NotSensibleSearchUsername($_POST['username']);
384        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
385      }
386    }
387  }
388
389
390/* Admin user management */
391  if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list')
392  {
393    if (isset($_POST['submit_add']))
394    {
395      /* User non case sensitive */
396      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
397      {
398        $new_username =  NotSensibleSearchUsername($_POST['login']);
399        $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
400      }
401
402      /* Username without forbidden keys */
403      if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
404      {
405        $template->append('errors', l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'");
406        unset($_POST['submit_add']);
407      }
408
409      /* Email without forbidden domains */
410      if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email']))
411      {
412        $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'");
413        unset($_POST['submit_add']);
414      }
415    }
416  }
417}
418
419
420add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2);
421
422function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm)
423{
424  load_language('plugin.lang', NBC_UserAdvManager_PATH);
425  global $infos, $conf, $template;
426
427  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
428
429/* User creation OR update */
430  if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
431  {
432    $comment_action = 'reject';
433
434    array_push($infos, l10n('UserAdvManager_Empty Author'));
435  }
436
437  return $comment_action;
438}
439
440?>
Note: See TracBrowser for help on using the repository browser.