-
Notifications
You must be signed in to change notification settings - Fork 13
/
AP_User_management.php
320 lines (281 loc) · 13.8 KB
/
AP_User_management.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
/***********************************************************************
Copyright (C) 2010 Guillaume Ferrari ([email protected])
and Quy Ton ([email protected]) based on code Copyright (C) 2005
Connor Dunn ([email protected])
Version française originale : Maximilien Thiel (www.thiel.fr)
This software is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
define('PLUGIN_VERSION', '1.5.0');
// Load the language file
if (file_exists(PUN_ROOT.'lang/'.$admin_language.'/user_management.php'))
require PUN_ROOT.'lang/'.$admin_language.'/user_management.php';
else
require PUN_ROOT.'lang/English/user_management.php';
// Load the register.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/register.php';
// Load the register.php/profile.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
if (isset($_POST['prune']))
{
// Make sure something something was entered
$days = pun_trim($_POST['days']);
if ($days == '' || preg_match('/[^0-9]/', $days))
message($lang_user_management['Days must be integer message']);
$posts = pun_trim($_POST['posts']);
if ($posts == '' || preg_match('/[^0-9]/', $posts))
message($lang_user_management['Posts must be integer message']);
if ($_POST['admods_delete'] == '1')
$admod_delete = ' AND group_id>'.PUN_UNVERIFIED;
else
{
$result = $db->query('SELECT g_id FROM '.$db->prefix.'groups WHERE g_moderator=1') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
$group_ids = array();
$group_ids[] = PUN_ADMIN;
for ($i = 0;$cur_group_id = $db->result($result, $i);$i++)
$group_ids[] = $cur_group_id;
$admod_delete = ' AND group_id NOT IN('.implode(',', $group_ids).')';
}
if ($_POST['verified'] == '1')
$verified = '';
else if ($_POST['verified'] == '0')
$verified = ' AND group_id>'.PUN_UNVERIFIED;
else
$verified = ' AND group_id='.PUN_UNVERIFIED;
$prune = ($_POST['prune_by'] == '1') ? 'registered' : 'last_visit';
$user_time = time() - ($days * 86400);
$result = $db->query('DELETE FROM '.$db->prefix.'users WHERE id>2 AND num_posts<'.$posts.' AND '.$prune.'<'.$user_time.$admod_delete.$verified, true) or error('Unable to delete users', __FILE__, __LINE__, $db->error());
$users_pruned = $db->affected_rows();
message(sprintf($lang_user_management['Pruning complete message'], $users_pruned));
}
if (isset($_POST['add_user']))
{
$username = pun_trim($_POST['username']);
$email = strtolower(pun_trim($_POST['email']));
$password2 = pun_trim($_POST['password2']);
if ($_POST['random_pass'] == '1')
$password = random_pass(8);
else
$password = pun_trim($_POST['password']);
$errors = array();
if (pun_strlen($password) < 4)
$errors[] = $lang_prof_reg['Pass too short'];
else if ($_POST['random_pass'] != '1' && $password != $password2)
$errors[] = $lang_prof_reg['Pass not match'];
check_username($username);
// Validate e-mail
require PUN_ROOT.'include/email.php';
if (!is_valid_email($email))
$errors[] = $lang_common['Invalid email'];
// Check if it's a banned email address
if (is_banned_email($email))
{
if ($pun_config['p_allow_banned_email'] == '0')
$errors[] = $lang_prof_reg['Banned email'];
}
if ($pun_config['p_allow_dupe_email'] == '0')
{
// Check if someone else already has registered with that email address
$result = $db->query('SELECT 1 FROM '.$db->prefix.'users WHERE email=\''.$db->escape($email).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
$errors[] = $lang_prof_reg['Dupe email'];
}
if (empty($errors))
{
$timezone = $pun_config['o_default_timezone'];
$language = $pun_config['o_default_lang'];
$email_setting = $pun_config['o_default_email_setting'];
// Insert the new user into the database. We do this now to get the last inserted id for later use.
$now = time();
$intial_group_id = ($_POST['random_pass'] == '0') ? $pun_config['o_default_user_group'] : PUN_UNVERIFIED;
$password_hash = pun_hash($password);
// Add the user
$db->query('INSERT INTO '.$db->prefix.'users (username, group_id, password, email, email_setting, timezone, dst, language, style, registered, registration_ip, last_visit) VALUES(\''.$db->escape($username).'\', '.$intial_group_id.', \''.$password_hash.'\', \''.$email.'\', '.$email_setting.', '.$timezone.', '.$pun_config['o_default_dst'].', \''.$language.'\', \''.$pun_config['o_default_style'].'\', '.$now.', \''.get_remote_address().'\', '.$now.')') or error('Unable to create user', __FILE__, __LINE__, $db->error());
$new_uid = $db->insert_id();
// Should we alert people on the admin mailing list that a new user has registered?
if ($pun_config['o_regs_report'] == '1')
{
$mail_subject = $lang_common['New user notification'];
$mail_message = sprintf($lang_common['New user message'], $username, get_base_url().'/')."\n";
$mail_message .= sprintf($lang_common['User profile'], get_base_url().'/profile.php?id='.$new_uid)."\n";
$mail_message .= "\n".'--'."\n".$lang_common['Email signature'];
pun_mail($pun_config['o_mailing_list'], $mail_subject, $mail_message);
}
// Must the user verify the registration or do we log him/her in right now?
if ($_POST['random_pass'] == '1')
{
// Load the "welcome" template
$mail_tpl = pun_trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/welcome.tpl'));
// The first row contains the subject
$first_crlf = strpos($mail_tpl, "\n");
$mail_subject = pun_trim(substr($mail_tpl, 8, $first_crlf-8));
$mail_message = pun_trim(substr($mail_tpl, $first_crlf));
$mail_subject = str_replace('<board_title>', $pun_config['o_board_title'], $mail_subject);
$mail_message = str_replace('<base_url>', get_base_url().'/', $mail_message);
$mail_message = str_replace('<username>', $username, $mail_message);
$mail_message = str_replace('<password>', $password, $mail_message);
$mail_message = str_replace('<login_url>', get_base_url().'/login.php', $mail_message);
$mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
pun_mail($email, $mail_subject, $mail_message);
}
// Regenerate the users info cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_users_info_cache();
message($lang_user_management['User created message']);
}
else
$error_reg = 1;
}
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div class="plugin blockform">
<h2><span><?php echo $lang_user_management['User management - v'] ?><?php echo PLUGIN_VERSION ?></span></h2>
<div class="box">
<div class="inbox">
<p><?php echo $lang_user_management['Plugin prune info'] ?></p>
<p><strong><?php echo $lang_user_management['Plugin warning'] ?></strong></p>
<p><?php echo $lang_user_management['Plugin add info'] ?></p>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span><?php echo $lang_user_management['User prune head'] ?></span></h2>
<div class="box">
<form id="example" method="post" action="">
<div class="inform">
<fieldset>
<legend><?php echo $lang_user_management['Settings subhead'] ?></legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<!--Thanks to wiseage for this function -->
<tr>
<th scope="row"><?php echo $lang_user_management['Prune by label'] ?></th>
<td>
<input type="radio" name="prune_by" value="1" checked="checked" /> <strong><?php echo $lang_user_management['Registered date'] ?></strong>   <input type="radio" name="prune_by" value="0" /> <strong><?php echo $lang_user_management['Last login'] ?></strong>
<span><?php echo $lang_user_management['Prune help'] ?></span>
</td>
</tr>
<!--/Thanks to wiseage for this function -->
<tr>
<th scope="row"><?php echo $lang_user_management['Minimum days label'] ?></th>
<td>
<input type="text" name="days" value="28" size="3" tabindex="1" />
<span><?php echo $lang_user_management['Minimum days help'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_user_management['Maximum posts label'] ?></th>
<td>
<input type="text" name="posts" value="1" size="7" tabindex="2" />
<span><?php echo $lang_user_management['Maximum posts help'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_user_management['Delete admins and mods label'] ?></th>
<td>
<input type="radio" name="admods_delete" value="1" /> <strong><?php echo $lang_admin_common['Yes'] ?></strong>   <input type="radio" name="admods_delete" value="0" checked="checked" /> <strong><?php echo $lang_admin_common['No'] ?></strong>
<span><?php echo $lang_user_management['Delete admins and mods help'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_user_management['User status label'] ?></th>
<td>
<input type="radio" name="verified" value="1" /> <strong><?php echo $lang_user_management['Delete any'] ?></strong>   <input type="radio" name="verified" value="0" checked="checked" /> <strong><?php echo $lang_user_management['Delete only verified'] ?></strong>   <input type="radio" name="verified" value="2" /> <strong><?php echo $lang_user_management['Delete only unverified'] ?></strong>
<span><?php echo $lang_user_management['User status help'] ?></span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="prune" value="<?php echo $lang_admin_common['Prune'] ?>" tabindex="3" /></p>
</form>
</div>
<h2 class="block2"><span><?php echo $lang_user_management['Add user head'] ?></span></h2>
<?php
if (isset($error_reg))
{
?>
<div id="posterror" style="border-style:none">
<div class="box">
<legend><?php echo $lang_register['Registration errors'] ?></legend>
<div class="inbox error-info infldset">
<p><?php echo $lang_register['Registration errors info'] ?></p>
<ul class="error-list">
<?php
foreach ($errors as $cur_error)
echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n";
?>
</ul>
</div>
</div>
</div>
<?php
}
?>
<div class="box">
<form id="example" method="post" action="">
<div class="inform">
<fieldset>
<legend><?php echo $lang_user_management['Settings subhead'] ?></legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row"><?php echo $lang_common['Username'] ?></th>
<td>
<input type="text" name="username" value="<?php if (isset($_POST['username'])) echo pun_htmlspecialchars($_POST['username']); ?>" size="25" tabindex="4" />
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_common['Email'] ?></th>
<td>
<input type="text" name="email" value="<?php if (isset($_POST['email'])) echo pun_htmlspecialchars($_POST['email']); ?>" size="50" tabindex="5" />
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_user_management['Generate random password label'] ?></th>
<td>
<input type="radio" name="random_pass" value="1" /> <strong><?php echo $lang_admin_common['Yes'] ?></strong>   <input type="radio" name="random_pass" value="0" checked="checked" /> <strong><?php echo $lang_admin_common['No'] ?></strong>
<span><?php echo $lang_user_management['Generate random password help'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_common['Password'] ?></th>
<td>
<input type="password" name="password" value="<?php if (isset($_POST['password'])) echo pun_htmlspecialchars($_POST['password']); ?>" size="25" tabindex="6" />
<span><?php echo $lang_user_management['Password help'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_prof_reg['Confirm pass'] ?></th>
<td>
<input type="password" name="password2" value="<?php if (isset($_POST['password2'])) echo pun_htmlspecialchars($_POST['password2']); ?>" size="25" tabindex="6" />
<span><?php echo $lang_register['Pass info'] ?></span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="add_user" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="7" /></p>
</form>
</div>
</div>