source: extensions/NBC_UserAdvManager/tags/2.11.1/main.inc.php @ 3875

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

Tag 2.11.1

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