-
Notifications
You must be signed in to change notification settings - Fork 14
/
importpg.php
45 lines (36 loc) · 1.21 KB
/
importpg.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
<?
// This script downloads/adds/updates peerguardian IP ranges in the bans table.
require "include/bittorrent.php";
dbconn();
header("Content-type: text/plain");
if (get_user_class() < UC_ADMINISTRATOR) die;
$url = "http://www.bluetack.co.uk/config/antip2p.txt";
$f = @fopen($url, "r");
if (!$f)
die("Cannot download: " . htmlspecialchars($url));
mysql_query("DELETE FROM bans WHERE comment LIKE 'PeerGuardian: %'") or sqlerr(__FILE__, __LINE__);
$uid = $CURUSER["id"];
$n = 0;
$o = 0;
$dt = sqlesc(get_date_time());
while (!feof($f))
{
++$o;
$s = rtrim(fgets($f));
$i = strrpos($s, ":");
if (!$i) continue;
$comment = sqlesc("PeerGuardian: " . substr($s, 0, $i));
$s = substr($s, $i + 1);
$i = strpos($s, "-");
$first = ip2long(substr($s, 0, $i));
$last = ip2long(substr($s, $i + 1));
if ($first == -1 || $last == -1) continue;
$query = "INSERT INTO bans (added, addedby, first, last, comment) VALUES($dt, $uid, $first, $last, $comment)";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() != 1)
die("Database insertion failed (" . htmlspecialchars($query) . ").");
++$n;
}
$o -= $n;
print("Source: " . htmlspecialchars($url) . "\n$n ranges imported, $o line(s) was discarded.");
?>