3 require('includes/header.php');
5 if( ! $administrator && ! $moderator)
7 add_error('You are not wise enough.', true);
10 // Validate IP address.
11 if( ! filter_var($_GET['ip'], FILTER_VALIDATE_IP
))
13 add_error('That is not a valid IP address.', true);
16 $ip_address = $_GET['ip'];
17 $hostname = gethostbyaddr($ip_address);
18 if($hostname === $ip_address)
23 $page_title = 'Information on IP address ' . $ip_address;
25 // If a ban request has been submitted...
26 if( ! empty($_POST['ban_length']))
28 if($_POST['ban_length'] == 'indefinite' |
$_POST['ban_length'] == 'infinite')
32 else if(strtotime($_POST['ban_length']) > $_SERVER['REQUEST_TIME'])
34 $new_ban_expiry = strtotime($_POST['ban_length']);
38 add_error('Invalid ban length.');
43 $ban_ip = $link->prepare('INSERT INTO ip_bans (ip_address, expiry, filed) VALUES (?, ?, UNIX_TIMESTAMP()) ON DUPLICATE KEY UPDATE expiry = ?, filed = UNIX_TIMESTAMP()');
44 $ban_ip->bind_param('sii', $ip_address, $new_ban_expiry, $new_ban_expiry);
47 $_SESSION['notice'] = 'IP address banned.';
52 $check_ban = $link->prepare('SELECT filed, expiry FROM ip_bans WHERE ip_address = ?');
53 $check_ban->bind_param('s', $ip_address);
54 $check_ban->execute();
55 $check_ban->bind_result($ban_filed, $ban_expiry);
60 if( ! empty($ban_filed))
62 if($ban_expiry == 0 ||
$ban_expiry > $_SERVER['REQUEST_TIME'])
66 else // the ban has already expired
68 remove_ip_ban($ip_address);
73 $query = "SELECT count(*) FROM topics WHERE author_ip = '" . $link->real_escape_string($ip_address) . "';";
74 $query .= "SELECT count(*) FROM replies WHERE author_ip = '" . $link->real_escape_string($ip_address) . "';";
75 $query .= "SELECT count(*) FROM users WHERE ip_address = '" . $link->real_escape_string($ip_address) . "';";
77 $link->multi_query($query);
80 $result = $link->store_result();
81 while ($row = $result->fetch_row())
86 } while ($link->next_result());
88 $ip_num_topics = $queries[0];
89 $ip_num_replies = $queries[1];
90 $ip_num_ids = $queries[2];
94 echo '<p>This IP address (';
97 echo 'host name <strong>' . $hostname . '</strong>';
101 echo 'no valid host name';
103 echo') is associated with <strong>' . $ip_num_ids . '</strong> ID' . ($ip_num_ids == 1 ?
'' : 's') . ' and has been used to post <strong>' . $ip_num_topics . '</strong> existing topic' . ($ip_num_topics == 1 ?
'' : 's') . ' and <strong>' . $ip_num_replies . '</strong> existing repl' . ($ip_num_replies == 1 ?
'y' : 'ies') . '.</p>';
106 echo '<p>It is currently <strong>banned</strong>. The ban was filed <span class="help" title="' . format_date($ban_filed) . '">' . calculate_age($ban_filed) . ' ago</span> and will ';
109 echo 'last indefinitely';
113 echo 'expire in ' . calculate_age($ban_expiry);
119 <form action
="" method
="post">
121 <label
for="ban_length" class="inline">Ban length
</label
>
122 <input type
="text" name
="ban_length" id
="ban_length" value
="<?php if( ! $banned) echo '1 week' ?>" class="inline" />
123 <input type
="submit" value
="<?php echo ($banned) ? 'Update ban length' : 'Ban' ?>" class="inline" />
124 <span
class="unimportant">(A ban length of
"indefinite" will never expire
.)</span
>
129 <?php
if($banned) echo '<li><a href="/unban_IP/' . $ip_address . '">Unban</a></li>' ?
>
130 <li
><a href
="/delete_IP_IDs/<?php echo $ip_address ?>">Delete all IDs
</a
></li
>
131 <li
><a href
="/nuke_IP/<?php echo $ip_address ?>">Delete all posts
</a
></li
>
132 <li
><a href
="http://toolserver.org/~chm/whois.php?ip=<?php echo $ip_address ?>">Whois
</a
></li
>
140 echo '<h4 class="section">IDs</h4>';
142 $stmt = $link->prepare('SELECT uid, first_seen FROM users WHERE ip_address = ? ORDER BY first_seen DESC LIMIT 5000');
143 $stmt->bind_param('s', $ip_address);
145 $stmt->bind_result($id, $id_first_seen);
147 $id_table = new table();
153 $id_table->define_columns($columns, 'ID');
155 while($stmt->fetch()) {
158 '<a href="/profile/' . $id . '">' . $id . '</a>',
159 '<span class="help" title="' . format_date($id_first_seen) . '">' . calculate_age($id_first_seen) . '</span>'
162 $id_table->row($values);
165 echo $id_table->output();
168 require('includes/footer.php');