source: extensions/NBC_UserAdvManager/tags/2.11.4/main.inc.php @ 3984

Last change on this file since 3984 was 3984, checked in by Eric, 15 years ago

[NBC_UserAdvManager] Releas 2.11.4 - Merged from trunk to Tag 2.11.4

  • Property svn:eol-style set to LF
File size: 15.3 KB
Line 
1<?php
2/*
3Plugin Name: NBC UserAdvManager
4Version: 2.11.4
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 : 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*/
71
72/*
73
74 ***** TODO List *****
75
76++ No validation needed for admins users comments (new trigger needed in comments.php)
77
78++ No single email check for admins (new trigger needed in (functions_user.inc.php ?))
79
80++ Password control and enforcement
81  -- Empty password (done in Piwigo 2.x)
82  ++ Can not be the same as username
83  ++ complexity of the password (Numbers+Lettrers+Low and high case+Special+minimal length)
84 
85++ Security : Blocking brut-force attacks !
86
87++ Opportunity to copy a registered user for new user creation
88  ++ new copied user will (or not) belong to the same groups
89  ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??))
90  ++ new copied user will (or not) get the same properties
91  ++ new copied user will (or not) get the same language
92  ... and so on
93 
94*/
95
96
97if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
98
99define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__)));
100define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
101
102include_once (NBC_UserAdvManager_PATH.'include/constants.php');
103include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php');
104
105load_language('plugin.lang', NBC_UserAdvManager_PATH);
106
107
108/* Plugin admin */
109add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu');
110
111function nbc_UserAdvManager_admin_menu($menu)
112{
113  array_push($menu,
114    array(
115      'NAME' => 'UserAdvManager',
116      'URL'  => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php')
117    )
118  );
119
120  return $menu;
121}
122
123
124
125/* User creation */
126add_event_handler('register_user', 'UserAdvManager_Adduser');
127
128function UserAdvManager_Adduser($register_user)
129{
130  global $conf;
131 
132  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
133
134  if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
135       
136        SendMail2User(1, $register_user['id'], $register_user['username'], $_POST['password'], $register_user['email'], true);
137}
138
139
140
141/* User deletion */
142add_event_handler('delete_user', 'UserAdvManager_Deluser');
143
144function UserAdvManager_Deluser($user_id)
145{
146
147  DeleteConfirmMail($user_id);
148
149}
150
151
152
153add_event_handler('init', 'UserAdvManager_InitPage');
154 
155function UserAdvManager_InitPage()
156{
157  load_language('plugin.lang', NBC_UserAdvManager_PATH);
158  global $conf, $template, $page, $lang;
159
160  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
161 
162
163  if ( isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
164    $lang['reg_err_login5'] = l10n('reg_err_login5');
165 
166
167 
168/* User identification */
169  if (script_basename() == 'identification')
170  {
171    if (isset($_POST['login']))
172    {
173      /* User non case sensitive */
174      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
175      {
176        $new_username =  NotSensibleSearchUsername($_POST['username']);
177        $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
178      }
179    }
180  }
181
182
183
184/* Admin user management */
185  if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list')
186  {
187    if (isset($_POST['submit_add']))
188    {
189      /* User non case sensitive */
190      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' )
191      {
192        $new_username =  NotSensibleSearchUsername($_POST['login']);
193        $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
194      }
195
196
197      /* Username without forbidden keys */
198      if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
199      {
200        $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'";
201        $_POST['login'] = '';
202      }
203
204      /* Email without forbidden domains */
205      /* This don't work on call of ValidateEmailProvider() function - Why ?? -> Due to the "return = false|true" in function ?*/
206      //if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email']))
207      //{
208      //  $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
209          //  $_POST['login'] = '';
210          //}
211      /* This work with a code copy of ValidateEmailProvider() function */
212                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']))
213                        {
214                        $ncsemail = strtolower($_POST['email']);
215                        $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]);
216                        for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
217                    {
218                  $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
219                                if (preg_match($pattern, $ncsemail))
220                        {
221                        $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
222                        $_POST['login'] = '';
223                                        }
224                                }
225                        }
226    }
227  }
228
229/* User creation */
230  if (script_basename() == 'register')
231  {
232    if (isset($_POST['submit']))
233    {
234      /* Username non case sensitive */
235      if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true')
236      {
237        $new_username =  NotSensibleSearchUsername($_POST['login']);
238        $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username;
239      }
240
241
242      /* Username without forbidden keys */
243      if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login']))
244      {
245        $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'";
246        $_POST['login'] = '';
247      }
248
249
250      /* Email without forbidden domains */
251      /* This don't work on call of ValidateEmailProvider() function - Why ?? -> Due to the "return = false|true" in function ?*/
252      //if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address']))
253      //{
254      //  $lang['reg_err_mail_address'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
255      //  $_POST['mail_address'] = '';
256      //}
257      /* This work with a code copy of ValidateEmailProvider() function */
258                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']))
259                  {
260                        $ncsemail = strtolower($_POST['mail_address']);
261                    $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]);
262                                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
263                          {
264                                $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
265                                if (preg_match($pattern, $ncsemail))
266                                  {
267                                        $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
268                                                $_POST['login'] = '';
269                                  }
270                          }
271                  }
272    }
273  }
274
275/* User profile update */
276  if (script_basename() == 'profile')
277  {
278    if (isset($_POST['validate']))
279    {
280      /* Sending email to user */
281      if (( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true'))
282      {
283        global $conf, $user ;
284        $errors = array();
285 
286        $int_pattern = '/^\d+$/';
287        if (empty($_POST['nb_image_line'])
288            or (!preg_match($int_pattern, $_POST['nb_image_line'])))
289        {
290          $errors[] = l10n('nb_image_line_error');
291        }
292     
293        if (empty($_POST['nb_line_page'])
294            or (!preg_match($int_pattern, $_POST['nb_line_page'])))
295        {
296          $errors[] = l10n('nb_line_page_error');
297        }
298     
299        if ($_POST['maxwidth'] != ''
300            and (!preg_match($int_pattern, $_POST['maxwidth'])
301                 or $_POST['maxwidth'] < 50))
302        {
303          $errors[] = l10n('maxwidth_error');
304        }
305        if ($_POST['maxheight']
306             and (!preg_match($int_pattern, $_POST['maxheight'])
307                   or $_POST['maxheight'] < 50))
308        {
309          $errors[] = l10n('maxheight_error');
310        }
311
312        if (isset($_POST['mail_address']))
313        {
314          $mail_error = validate_mail_address($user['id'], $_POST['mail_address']);
315          if (!empty($mail_error))
316          {
317            $errors[] = $mail_error;
318          }
319         
320                                        if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']))
321                                {
322                                        $ncsemail = strtolower($_POST['mail_address']);
323                                $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]);
324                                                for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
325                                        {
326                                                $pattern = '/'.$conf_nbc_MailExclusion[$i].'/';
327                                                if (preg_match($pattern, $ncsemail))
328                                                {
329                                                $mail_error = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'";
330                                                }
331                                        }
332                                }
333                if (!empty($mail_error))
334          {
335            $errors[] = $mail_error;
336          }
337        }
338
339        $typemail = 3;
340       
341        if (!empty($_POST['use_new_pwd']))
342        {
343          $typemail = 2;
344
345          // password must be the same as its confirmation
346          if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
347          {
348            $errors[] = l10n('New password confirmation does not correspond');
349          }
350     
351          if ( !defined('IN_ADMIN') )
352          {// changing password requires old password
353            $query = '
354              SELECT '.$conf['user_fields']['password'].' AS password
355              FROM '.USERS_TABLE.'
356              WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
357            ;';
358            list($current_password) = mysql_fetch_row(pwg_query($query));
359       
360            if ($conf['pass_convert']($_POST['password']) != $current_password)
361            {
362              $errors[] = l10n('Current password is wrong');
363            }
364          }
365        }
366       
367        $confirm_mail_need = false;
368             
369        if (!empty($_POST['mail_address']))
370        {
371          $query = '
372            SELECT '.$conf['user_fields']['email'].' AS email
373            FROM '.USERS_TABLE.'
374            WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
375          ;';
376          list($current_email) = mysql_fetch_row(pwg_query($query));
377     
378          if ( $_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true') )
379            $confirm_mail_need = true;
380        }
381
382        if (count($errors) == 0 and (!empty($_POST['use_new_pwd']) and ( isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need) )
383        {
384          $query = '
385            SELECT '.$conf['user_fields']['username'].'
386            FROM '.USERS_TABLE.'
387            WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
388          ;';
389          list($username) = mysql_fetch_row(pwg_query($query));
390
391
392          SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
393        }
394      }
395    }
396  }
397}
398
399add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2);
400
401function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm)
402{
403  load_language('plugin.lang', NBC_UserAdvManager_PATH);
404  global $infos, $conf, $template;
405
406  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
407
408/* User creation OR update */
409  if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
410  {
411    $comment_action = 'reject';
412
413    array_push($infos, l10n('UserAdvManager_Empty Author'));
414  }
415
416  return $comment_action;
417}
418
419?>
Note: See TracBrowser for help on using the repository browser.