aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/admin/admin_users.php
blob: bbc5a29bb4a9163d9f53c523d9342ebf576c4df3 (plain)
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
/***************************************************************************
 *                              admin_users.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id$
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program 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.
 *
 ***************************************************************************/

if ( !empty($setmodules) )
{
	if ( !$auth->acl_get('a_user') )
	{
		return;
	}

	$filename = basename(__FILE__);
	$module['Users']['Manage'] = $filename . $SID;

	return;
}

define('IN_PHPBB', 1);

// Include files
$phpbb_root_path = '../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);
require($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
require($phpbb_root_path . 'includes/functions_validate.'.$phpEx);

// Do we have forum admin permissions?
if ( !$auth->acl_get('a_user') )
{
	trigger_error($user->lang['No_admin']);
}

echo $mode;

// Set mode
if( isset( $_POST['mode'] ) || isset( $_GET['mode'] ) )
{
	$mode = ( isset( $_POST['mode']) ) ? $_POST['mode'] : $_GET['mode'];
}
else
{
	$mode = 'main';
}

// Begin program
if (  isset($_POST['username']) || isset($_GET['u']) || isset( $_POST['u']) )
{

	// Grab relevant userdata
	if( isset( $_GET['u']) || isset( $_POST['u']) )
	{
		$user_id = ( isset( $_POST['u']) ) ? intval( $_POST['u']) : intval( $_GET['u']);

		if( !($userdata = get_userdata($user_id)) )
		{
			trigger_error($user->lang['No_user_id_specified'] );
		}
	}
	else
	{
		if( !$userdata = get_userdata( $_POST['username'] ) )
		{
			trigger_error($user->lang['No_user_id_specified'] );
		}
	}

	// Update entry in DB
	if( $_POST['deleteuser'] && !$userdata['user_founder'] && $auth->acl_get('a_userdel') )
	{
		$db->sql_transaction();

		$sql = "UPDATE " . POSTS_TABLE . "
			SET poster_id = " . ANONYMOUS . ", post_username = '$username'
			WHERE poster_id = $user_id";
		$db->sql_query($sql);

		$sql = "UPDATE " . TOPICS_TABLE . "
			SET topic_poster = " . ANONYMOUS . "
			WHERE topic_poster = $user_id";
		$db->sql_query($sql);

		$sql = "DELETE FROM " . USERS_TABLE . "
			WHERE user_id = $user_id";
		$db->sql_query($sql);

		$sql = "DELETE FROM " . USER_GROUP_TABLE . "
			WHERE user_id = $user_id";
		$db->sql_query($sql);

		$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
			WHERE user_id = $user_id";
		$db->sql_query($sql);

		$sql = "DELETE FROM " . ACL_USERS_TABLE . "
			WHERE user_id = $user_id";
		$db->sql_query($sql);

		$db->sql_transaction('commit');

		trigger_error($user->lang['User_deleted']);
	}


	// Output relevant page
	page_header($user->lang['Manage']);

?>

<form method="post" action="admin_users.<?php echo $phpEx . $SID; ?>&amp;mode=<?php echo $mode; ?>&amp;u=<?php echo $userdata['user_id']; ?>"><table width="90%" cellspacing="3" cellpadding="0" border="0" align="center">
	<tr>
		<td align="right"><b>Main</b> | <a href="admin_users.<?php echo $phpEx . $SID; ?>&amp;u=<?php echo $userdata['user_id']; ?>&amp;mode=profile">Profile</a> | <a href="admin_users.<?php echo $phpEx . $SID; ?>&amp;u=<?php echo $userdata['user_id']; ?>&amp;mode=pref">Preferences</a> | <a href="admin_users.<?php echo $phpEx . $SID; ?>&amp;u=<?php echo $userdata['user_id']; ?>&amp;mode=avatar">Avatar</a> | <a href="admin_users.<?php echo $phpEx . $SID; ?>&amp;u=<?php echo $userdata['user_id']; ?>&amp;mode=permissions">Permissions</a></td>
	</tr>
	<tr>
		<td><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0">
			<tr>
				<th colspan="2"><?php echo $user->lang[$mode]; ?></td>
			</tr>
<?php

	switch ($mode)
	{
		case 'main':

?>
			<tr>
				<td class="row1">Username: <br /><span class="gensmall">Click profile to edit</span></td>
				<td class="row2"><?php echo $userdata['username']; ?> [ <a href="admin_ban.<?php echo $phpEx . $SID; ?>&amp;mode=user&amp;ban=<?php echo $userdata['username']; ?>&amp;bansubmit=true">Ban</a> ]</td>
			</tr>
			<tr>
				<td class="row1">Registered: </td>
				<td class="row2"><?php echo $user->format_date($userdata['user_regdate']); ?></td>
			</tr>
			<tr>
				<td class="row1">Registered from IP: </td>
				<td class="row2"><?php if ( $userdata['user_ip'] ) { echo $userdata['user_ip']; ?> [ <a href="admin_users.<?php echo $phpEx . $SID; ?>&amp;u=<?php echo $userdata['user_id']; ?>&amp;mode=main&amp;do=iplookup">Lookup</a> | <a href="admin_ban.<?php echo $phpEx . $SID; ?>&amp;mode=ip&amp;ban=<?php echo $userdata['user_ip']; ?>&amp;bansubmit=true">Ban</a> ] <?php } else { echo 'Unknown'; } ?></td>
			</tr>
<?php

			if ( isset($_GET['do']) && $_GET['do'] == 'iplookup' )
			{
				if ( $userdata['user_ip'] != '' && $domain = gethostbyaddr($userdata['user_ip']) )
				{
?>
			<tr>
				<th colspan="2">IP whois for <?php echo $domain; ?></th>
			</tr>
			<tr>
				<td class="row1" colspan="2"><?php

					if ( $ipwhois = ipwhois($userdata['user_ip']) )
					{
						echo '<br /><pre align="left">' . trim($ipwhois) . '</pre>';
					}
?></td>
			</tr>
<?php

				}
			}

?>
			<tr>
				<td class="row1">Total/Average posts by this user: </td>
				<td class="row2"></td>
			</tr>
			<tr>
				<td class="row1"></td>
				<td class="row2"></td>
			</tr>
		</table></td>
	</tr>
</table></form>

<?php

			break;

		case 'permissions':

			$userauth = new auth();
			$userauth->acl($userdata);

			foreach ($acl_options['global'] as $option_name => $option_id)
			{
				$type = substr($option_name, 0, strpos('_', $option_name) +1 );
				$global[$type][$option_name] = $userauth->acl_get($option_name);
			}

			$sql = "SELECT forum_id, forum_name
				FROM " . FORUMS_TABLE . "
				ORDER BY left_id";
			$result = $db->sql_query($sql);

			$permissions = array();
			while( $row = $db->sql_fetchrow($result) )
			{
				$forum_data[$row['forum_id']] = $row['forum_name'];

				foreach ($acl_options['local'] as $option_name => $option_id)
				{
					$local[$row['forum_id']][$option_name] = $userauth->acl_get($option_name, $row['forum_id']);
				}
			}

?>
			<tr>
				<td colspan="2"><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center">
					<tr>
						<th>&nbsp;<?php echo $user->lang['Option']; ?>&nbsp;</th>
						<th>&nbsp;<?php echo $user->lang['Allow']; ?>&nbsp;</th>
						<th>&nbsp;<?php echo $user->lang['Deny']; ?>&nbsp;</th>
					</tr>
<?php
			$type_lang = array(
				'f' => 'Forum',
				'a' => 'Administrator',
				'm' => 'Moderator',
				'u' => 'User',
			);

			foreach ($global as $type => $auth_ary)
			{
?>
					<tr>
						<td class="cat" colspan="3"><?php echo $type_lang[$type]; ?></td>
					</tr>
<?php

			foreach ($auth_ary as $option => $allow)
			{
				if ( $option != $type .'_' )
				{
					$row_class = ( $row_class == 'row1' ) ? 'row2' : 'row1';

					$l_can_cell = ( !empty($user->lang['acl_' . $option]) ) ? $user->lang['acl_' . $option] : ucfirst(preg_replace('#.*?_#', '', $option));

					$allow_type = ( $allow == ACL_ALLOW ) ? ' checked="checked"' : '';
					$deny_type = ( $allow == ACL_DENY ) ? ' checked="checked"' : '';
?>
				<tr>
					<td class="<?php echo $row_class; ?>"><?php echo $l_can_cell; ?></td>
					<td class="<?php echo $row_class; ?>" align="center"><input type="radio"<?php echo $allow_type; ?> /></td>
					<td class="<?php echo $row_class; ?>" align="center"><input type="radio"<?php echo $deny_type; ?> /></td>
				</tr>
<?php
			}
			}
			}

?>
				</table></td>
			</tr>
			<tr>
<?php

			foreach ($local as $forum_id => $auth_ary)
			{

?>
				<td class="row1"><?php echo $forum_data[$forum_id]; ?></td>
				<td><table cellspacing="1" cellpadding="0" border="0">
<?php

				foreach ($auth_ary as $option => $allow)
				{
					echo '<tr><td>' . $user->lang['acl_' . $option] . ' => ' . ( ( $allow ) ? 'Allowed' : 'Denied' ) . '</td></tr>';
				}

?>
				</table></td>
			</tr>
<?php

			}

			break;

	}

	page_footer();

}
else
{

	page_header($user->lang['Manage']);

?>

<h1><?php echo $user->lang['User_admin']; ?></h1>

<p><?php echo $user->lang['User_admin_explain']; ?></p>

<form method="post" name="post" action="<?php echo "admin_users.$phpEx$SID"; ?>"><table class="bg" cellspacing="1" cellpadding="4" border="0" align="center">
	<tr>
		<th align="center"><?php echo $user->lang['Select_a_User']; ?></th>
	</tr>
	<tr>
		<td class="row1" align="center"><input type="text" class="post" name="username" maxlength="50" size="20" /> <input type="submit" name="submituser" value="<?php echo $user->lang['Look_up_user']; ?>" class="mainoption" /> <input type="submit" name="usersubmit" value="<?php echo $user->lang['Find_username']; ?>" class="liteoption" onClick="window.open('<?php echo "../memberslist.$phpEx$SID&amp;mode=searchuser&amp;field=username"; ?>', '_phpbbsearch', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=650');return false;" /></td>
	</tr>
</table></form>

<?php

}

page_footer();

//
//
function ipwhois($ip)
{
	$ipwhois = '';

	$match = array(
		'#RIPE\.NET#is' => 'whois.ripe.net',
		'#whois\.apnic\.net#is' => 'whois.apnic.net',
		'#nic\.ad\.jp#is' => 'whois.nic.ad.jp',
		'#whois\.registro\.br#is' => 'whois.registro.br'
	);

	if ( ($fsk = fsockopen('whois.arin.net', 43)) )
	{
		@fputs($fsk, "$ip\n");
		while (!feof($fsk) )
		{
			$ipwhois .= fgets($fsk, 1024);
		}
		fclose($fsk);
	}

	foreach ( array_keys($match) as $server )
	{
		if ( preg_match($server, $ipwhois) )
		{
			$ipwhois = '';
			if ( ($fsk = fsockopen($match[$server], 43)) )
			{
				@fputs($fsk, "$ip\n");
				while (!feof($fsk) )
				{
					$ipwhois .= fgets($fsk, 1024);
				}
				fclose($fsk);
			}
			break;
		}
	}

	return $ipwhois;
}
//
//

?>