source: trunk/web/punbb/admin_bans.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 15.0 KB
Line 
1<?php
2/***********************************************************************
3
4  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
5
6  This file is part of PunBB.
7
8  PunBB is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published
10  by the Free Software Foundation; either version 2 of the License,
11  or (at your option) any later version.
12
13  PunBB is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  MA  02111-1307  USA
22
23************************************************************************/
24
25
26// Tell header.php to use the admin template
27define('PUN_ADMIN_CONSOLE', 1);
28
29define('PUN_ROOT', './');
30require PUN_ROOT.'include/common.php';
31require PUN_ROOT.'include/common_admin.php';
32
33
34if ($pun_user['g_id'] > PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
35        message($lang_common['No permission']);
36
37
38// Add/edit a ban (stage 1)
39if (isset($_REQUEST['add_ban']) || isset($_GET['edit_ban']))
40{
41        if (isset($_GET['add_ban']) || isset($_POST['add_ban']))
42        {
43                // If the id of the user to ban was provided through GET (a link from profile.php)
44                if (isset($_GET['add_ban']))
45                {
46                        $add_ban = intval($_GET['add_ban']);
47                        if ($add_ban < 2)
48                                message($lang_common['Bad request']);
49
50                        $user_id = $add_ban;
51
52                        $result = $db->query('SELECT group_id, username, email FROM '.$db->prefix.'users WHERE id='.$user_id) or error('Impossible de retrouver les informations utilisateur', __FILE__, __LINE__, $db->error());
53                        if ($db->num_rows($result))
54                                list($group_id, $ban_user, $ban_email) = $db->fetch_row($result);
55                        else
56                                message('Aucun utilisateur enregistré sous cet identifiant (ID).');
57                }
58                else    // Otherwise the username is in POST
59                {
60                        $ban_user = trim($_POST['new_ban_user']);
61
62                        if ($ban_user != '')
63                        {
64                                $result = $db->query('SELECT id, group_id, username, email FROM '.$db->prefix.'users WHERE username=\''.$db->escape($ban_user).'\' AND id>1') or error('Impossible de retrouver les informations utilisateur', __FILE__, __LINE__, $db->error());
65                                if ($db->num_rows($result))
66                                        list($user_id, $group_id, $ban_user, $ban_email) = $db->fetch_row($result);
67                                else
68                                        message('Aucun utilisateur enregistré sous ce nom d\'utilisateur. Si vous souhaitez ajouter un bannissement qui ne soit pas lié à un nom d\'utilisateur particulier, laissez la case vide.');
69                        }
70                }
71
72                // Make sure we're not banning an admin
73                if (isset($group_id) && $group_id == PUN_ADMIN)
74                        message('L\'utilisateur '.pun_htmlspecialchars($ban_user).' est un administrateur, il ne peut être bannis. Si vous souhaitez bannir un administrateur, vous devez d\'abord le rétrograder soit modérateur soit utilisateur.');
75
76                // If we have a $user_id, we can try to find the last known IP of that user
77                if (isset($user_id))
78                {
79                        $result = $db->query('SELECT poster_ip FROM '.$db->prefix.'posts WHERE poster_id='.$user_id.' ORDER BY posted DESC LIMIT 1') or error('Impossible de retrouver les informations des messages', __FILE__, __LINE__, $db->error());
80                        $ban_ip = ($db->num_rows($result)) ? $db->result($result) : '';
81                }
82
83                $mode = 'add';
84        }
85        else    // We are editing a ban
86        {
87                $ban_id = intval($_GET['edit_ban']);
88                if ($ban_id < 1)
89                        message($lang_common['Bad request']);
90
91                $result = $db->query('SELECT username, ip, email, message, expire FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Impossible de retrouver les informations de bannissement', __FILE__, __LINE__, $db->error());
92                if ($db->num_rows($result))
93                        list($ban_user, $ban_ip, $ban_email, $ban_message, $ban_expire) = $db->fetch_row($result);
94                else
95                        message($lang_common['Bad request']);
96
97                $ban_expire = ($ban_expire != '') ? date('Y-m-d', $ban_expire) : '';
98
99                $mode = 'edit';
100        }
101
102        $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bannissements';
103        $focus_element = array('bans2', 'ban_user');
104        require PUN_ROOT.'header.php';
105
106        generate_admin_menu('bans');
107
108
109?>
110        <div class="blockform">
111                <h2><span>Réglages de bannissement avancés</span></h2>
112                <div class="box">
113                        <form id="bans2" method="post" action="admin_bans.php">
114                                <div class="inform">
115                                <input type="hidden" name="mode" value="<?php echo $mode ?>" />
116<?php if ($mode == 'edit'): ?>                          <input type="hidden" name="ban_id" value="<?php echo $ban_id ?>" />
117<?php endif; ?>                         <fieldset>
118                                                <legend>Bannissement supplémentaire avec <acronym title="Internet Protocol" lang="en">IP</acronym> est adresse e-mail</legend>
119                                                <div class="infldset">
120                                                        <table class="aligntop" cellspacing="0">
121                                                                <tr>
122                                                                        <th scope="row">Nom d'utilisateur</th>
123                                                                        <td>
124                                                                                <input type="text" name="ban_user" size="25" maxlength="25" value="<?php if (isset($ban_user)) echo pun_htmlspecialchars($ban_user); ?>" tabindex="1" />
125                                                                                <span>Le nom d'utilisateur à bannir.</span>
126                                                                        </td>
127                                                                </tr>
128                                                                <tr>
129                                                                        <th scope="row">Adresses <acronym title="Internet Protocol" lang="en">IP</acronym></th>
130                                                                        <td>
131                                                                                <input type="text" name="ban_ip" size="45" maxlength="255" value="<?php if (isset($ban_ip)) echo $ban_ip; ?>" tabindex="2" />
132                                                                                <span>Une adresse <acronym title="Internet Protocol" lang="en">IP</acronym> ou une plage d'adresses <acronym title="Internet Protocol" lang="en">IP</acronym> que vous souhaitez bannir (<abbr title="exemple">ex.</abbr> 150.11.110.1 ou 150.11.110). Séparez les adresses par des espaces. Si une adresse <acronym title="Internet Protocol" lang="en">IP</acronym> apparaît déjà, il s'agit de la derniÚre adresse IP connue de l'utilisateur dans la base de données.<?php if ($ban_user != '' && isset($user_id)) echo ' <a href="admin_users.php?ip_stats='.$user_id.'">Cliquez ici</a> pour voir les statistiques <acronym title="Internet Protocol" lang="en">IP</acronym> de cet utilisateur.' ?></span>
133                                                                        </td>
134                                                                </tr>
135                                                                <tr>
136                                                                        <th scope="row">E-mail/domaine</th>
137                                                                        <td>
138                                                                                <input type="text" name="ban_email" size="40" maxlength="50" value="<?php if (isset($ban_email)) echo strtolower($ban_email); ?>" tabindex="3" />
139                                                                                <span>L'adresse e-mail ou le domaine e-mail que vous souhaitez bannir (<abbr title="exemple">ex.</abbr> utilisateur@domaine.com ou domaine.com). Pour plus d'informations, voir "Autoriser les adresses e-mail bannies" à la page des Permissions.</span>
140                                                                        </td>
141                                                                </tr>
142                                                        </table>
143                                                        <p class="topspace"><strong class="warntext">Vous devez êtres trÚs vigilant lorsque vous bannissez une plage d'<acronym title="Internet Protocol" lang="en">IP</acronym> car il y a fort probablement plusieurs utilisateurs qui correspondent à la même <acronym title="Internet Protocol" lang="en">IP</acronym> partielle.</strong></p>
144                                                </div>
145                                        </fieldset>
146                                </div>
147                                <div class="inform">
148                                        <fieldset>
149                                                <legend>Message et échéance d'interdiction</legend>
150                                                <div class="infldset">
151                                                        <table class="aligntop" cellspacing="0">
152                                                                <tr>
153                                                                        <th scope="row">Message d'interdiction</th>
154                                                                        <td>
155                                                                                <input type="text" name="ban_message" size="50" maxlength="255" value="<?php if (isset($ban_message)) echo pun_htmlspecialchars($ban_message); ?>" tabindex="4" />
156                                                                                <span>Le  message qui sera affiché à l'utilisateur banni lorsqu'il visitera les forums.</span>
157                                                                        </td>
158                                                                </tr>
159                                                                <tr>
160                                                                        <th scope="row">Échéance d'interdiction</th>
161                                                                        <td>
162                                                                                <input type="text" name="ban_expire" size="17" maxlength="10" value="<?php if (isset($ban_expire)) echo $ban_expire; ?>" tabindex="5" />
163                                                                                <span>La date à laquelle ce bannissement sera automatiquement supprimé (format: AAAA-MM-JJ). Pour supprimer manuellement, laissez ce champ vide.</span>
164                                                                        </td>
165                                                                </tr>
166                                                        </table>
167                                                </div>
168                                        </fieldset>
169                                </div>
170                                <p class="submitend"><input type="submit" name="add_edit_ban" value=" Enregistrer " tabindex="6" /></p>
171                        </form>
172                </div>
173        </div>
174        <div class="clearer"></div>
175</div>
176<?php
177
178        require PUN_ROOT.'footer.php';
179}
180
181
182// Add/edit a ban (stage 2)
183else if (isset($_POST['add_edit_ban']))
184{
185        confirm_referrer('admin_bans.php');
186
187        $ban_user = trim($_POST['ban_user']);
188        $ban_ip = trim($_POST['ban_ip']);
189        $ban_email = strtolower(trim($_POST['ban_email']));
190        $ban_message = trim($_POST['ban_message']);
191        $ban_expire = trim($_POST['ban_expire']);
192
193        if ($ban_user == '' && $ban_ip == '' && $ban_email == '')
194                message('Vous devez saisir au moins soit un nom d\'utilisateur, soit une adresse <acronym title="Internet Protocol" lang="en">IP</acronym> ou une adresse e-mail.');
195
196        // Validate IP/IP range (it's overkill, I know)
197        if ($ban_ip != '')
198        {
199                $ban_ip = preg_replace('/[\s]{2,}/', ' ', $ban_ip);
200                $addresses = explode(' ', $ban_ip);
201                $addresses = array_map('trim', $addresses);
202
203                for ($i = 0; $i < count($addresses); ++$i)
204                {
205                        $octets = explode('.', $addresses[$i]);
206
207                        for ($c = 0; $c < count($octets); ++$c)
208                        {
209                                $octets[$c] = (strlen($octets[$c]) > 1) ? ltrim($octets[$c], "0") : $octets[$c];
210
211                                if ($c > 3 || preg_match('/[^0-9]/', $octets[$c]) || intval($octets[$c]) > 255)
212                                        message('Vous avez saisi une <acronym title="Internet Protocol" lang="en">IP</acronym>/plage d\'<acronym title="Internet Protocol" lang="en">IP</acronym> incorrecte.');
213                        }
214
215                        $cur_address = implode('.', $octets);
216                        $addresses[$i] = $cur_address;
217                }
218
219                $ban_ip = implode(' ', $addresses);
220        }
221
222        require PUN_ROOT.'include/email.php';
223        if ($ban_email != '' && !is_valid_email($ban_email))
224        {
225                if (!preg_match('/^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $ban_email))
226                        message('L\'adresse e-mail (<abbr title="exemple">ex.</abbr> utilisateur@domaine.com) ou le domaine d\'adresse e-mail (<abbr title="exemple">ex.</abbr> domaine.com) que vous avez saisi est incorrect.');
227        }
228
229        if ($ban_expire != '' && $ban_expire != 'Never')
230        {
231                $ban_expire = strtotime($ban_expire);
232
233                if ($ban_expire == -1 || $ban_expire <= time())
234                        message('Vous avez saisi une date d\'échéance incorrecte. Le format doit être AAAA-MM-JJ et la date doit-être d\'au moins un jour dans le futur.');
235        }
236        else
237                $ban_expire = 'NULL';
238
239        $ban_user = ($ban_user != '') ? '\''.$db->escape($ban_user).'\'' : 'NULL';
240        $ban_ip = ($ban_ip != '') ? '\''.$db->escape($ban_ip).'\'' : 'NULL';
241        $ban_email = ($ban_email != '') ? '\''.$db->escape($ban_email).'\'' : 'NULL';
242        $ban_message = ($ban_message != '') ? '\''.$db->escape($ban_message).'\'' : 'NULL';
243
244        if ($_POST['mode'] == 'add')
245                $db->query('INSERT INTO '.$db->prefix.'bans (username, ip, email, message, expire) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.')') or error('Impossible d\'ajouter le bannissement', __FILE__, __LINE__, $db->error());
246        else
247                $db->query('UPDATE '.$db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($_POST['ban_id'])) or error('Impossible de modifier le bannissement', __FILE__, __LINE__, $db->error());
248
249        // Regenerate the bans cache
250        require_once PUN_ROOT.'include/cache.php';
251        generate_bans_cache();
252
253        redirect('admin_bans.php', 'Bannissement '.(($_POST['mode'] == 'edit') ? 'modifié' : 'ajouté').'. Redirection ...');
254}
255
256
257// Remove a ban
258else if (isset($_GET['del_ban']))
259{
260        confirm_referrer('admin_bans.php');
261
262        $ban_id = intval($_GET['del_ban']);
263        if ($ban_id < 1)
264                message($lang_common['Bad request']);
265
266        $db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Impossible de supprimer le bannissement', __FILE__, __LINE__, $db->error());
267
268        // Regenerate the bans cache
269        require_once PUN_ROOT.'include/cache.php';
270        generate_bans_cache();
271
272        redirect('admin_bans.php', 'Bannissement supprimé. Redirection ...');
273}
274
275
276$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bannissement';
277$focus_element = array('bans', 'new_ban_user');
278require PUN_ROOT.'header.php';
279
280generate_admin_menu('bans');
281
282?>
283        <div class="blockform">
284                <h2><span>Nouveau bannissement</span></h2>
285                <div class="box">
286                        <form id="bans" method="post" action="admin_bans.php?action=more">
287                                <div class="inform">
288                                        <fieldset>
289                                                <legend>Ajouter un bannissement</legend>
290                                                <div class="infldset">
291                                                        <table class="aligntop" cellspacing="0">
292                                                                <tr>
293                                                                        <th scope="row">Nom d'utilisateur<div><input type="submit" name="add_ban" value=" Ajouter " tabindex="2" /></div></th>
294                                                                        <td>
295                                                                                <input type="text" name="new_ban_user" size="25" maxlength="25" tabindex="1" />
296                                                                                <span>Le nom d'utilisateur à bannir (insensible à la casse). La page suivante vous permettra d'entrer une adresse <acronym title="Internet Protocol" lang="en">IP</acronym> et/ou une adresse e-mail de votre choix. Si vous souhaitez bannir une adresse <acronym title="Internet Protocol" lang="en">IP</acronym>, une plage d'adresses <acronym title="Internet Protocol" lang="en">IP</acronym> ou une adresse e-mail, laissez simplement ce champ vide.</span>
297                                                                        </td>
298                                                                </tr>
299                                                        </table>
300                                                </div>
301                                        </fieldset>
302                                </div>
303                        </form>
304                </div>
305
306                <h2 class="block2"><span>Bannissements actuels</span></h2>
307                <div class="box">
308                        <div class="fakeform">
309<?php
310
311$result = $db->query('SELECT id, username, ip, email, message, expire FROM '.$db->prefix.'bans ORDER BY id') or error('Impossible de retrouver la liste des bannissements', __FILE__, __LINE__, $db->error());
312if ($db->num_rows($result))
313{
314        while ($cur_ban = $db->fetch_assoc($result))
315        {
316                $expire = format_time($cur_ban['expire'], true);
317
318?>
319                                <div class="inform">
320                                        <fieldset>
321                                                <legend>Date d'échéance&#160;: <?php echo $expire ?></legend>
322                                                <div class="infldset">
323                                                        <table cellspacing="0">
324<?php if ($cur_ban['username'] != ''): ?>                                                               <tr>
325                                                                        <th>Nom d'utilisateur</th>
326                                                                        <td><?php echo pun_htmlspecialchars($cur_ban['username']) ?></td>
327                                                                </tr>
328<?php endif; ?><?php if ($cur_ban['email'] != ''): ?>                                                           <tr>
329                                                                        <th>E-mail</th>
330                                                                        <td><?php echo $cur_ban['email'] ?></td>
331                                                                </tr>
332<?php endif; ?><?php if ($cur_ban['ip'] != ''): ?>                                                              <tr>
333                                                                        <th><acronym title="Internet Protocol" lang="en">IP</acronym>/plage d'<acronym title="Internet Protocol" lang="en">IP</acronym></th>
334                                                                        <td><?php echo $cur_ban['ip'] ?></td>
335                                                                </tr>
336<?php endif; ?><?php if ($cur_ban['message'] != ''): ?>                                                         <tr>
337                                                                        <th>Motif</th>
338                                                                        <td><?php echo pun_htmlspecialchars($cur_ban['message']) ?></td>
339                                                                </tr>
340<?php endif; ?>                                                 </table>
341                                                        <p class="linkactions"><a href="admin_bans.php?edit_ban=<?php echo $cur_ban['id'] ?>">Modifier</a> - <a href="admin_bans.php?del_ban=<?php echo $cur_ban['id'] ?>">Supprimer</a></p>
342                                                </div>
343                                        </fieldset>
344                                </div>
345<?php
346
347        }
348}
349else
350        echo "\t\t\t\t".'<p>Aucun bannissement à lister.</p>'."\n";
351
352?>
353                        </div>
354                </div>
355        </div>
356        <div class="clearer"></div>
357</div>
358<?php
359
360require PUN_ROOT.'footer.php';
Note: See TracBrowser for help on using the repository browser.