· 9 years ago · Nov 29, 2016, 07:24 PM
1# coding: latin-1
2
3# Blacklist 1.2.2.0
4# © 2010-2016 RoLex
5# Thanks to Frog
6
7# Changelog:
8# -------
9# 0.0.1.0 - Initial release
10# -------
11# 1.0.0.0 - Added "find_maxres" configuration to limit number of results on find action
12# 1.0.0.0 - Added country codes of addresses in waiting feed list
13# -------
14# 1.1.0.0 - Added "time_down" configuration to specify timeout of download operation in seconds
15# -------
16# 1.1.1.0 - Added "listoff" command to disable or enable lists
17# -------
18# 1.1.2.0 - Added another read failure check
19# -------
20# 1.1.3.0 - Fixed display of item configuration old value when changing from zero
21# 1.1.3.0 - Fixed default exception file creation in wrong directory
22# 1.1.3.0 - Added translation ability with list command "lang" and update command "tran"
23# -------
24# 1.1.4.0 - Added compression file format "zip"
25# 1.1.4.0 - Added data file format "emule"
26# -------
27# 1.1.5.0 - Added "listget" command to force list load
28# -------
29# 1.1.6.0 - Added exception notifications to waiting feed list aswell
30# -------
31# 1.1.7.0 - Fixed OnTimer callback
32# -------
33# 1.1.8.0 - Added referer and user agent headers for URL requests
34# 1.1.8.0 - Added different method of validating numbers
35# 1.1.8.0 - Added different method of getting hub bot nicks
36# 1.1.8.0 - Added public proxy lookup based on number of Google search results
37# 1.1.8.0 - Added "listre" command to reload all blacklist lists
38# 1.1.8.0 - Added "del" command to delete single blacklisted item in real time
39# 1.1.8.0 - Added "code_block" configuration for space separated list of blocked country codes
40# 1.1.8.0 - Added "code_except" configuration for space separated list of excepted country codes
41# 1.1.8.0 - Added short configuration explanations
42# 1.1.8.0 - Added custom blacklist to manage with "my*" commands
43# 1.1.8.0 - Added exception list to database instead of text file
44# 1.1.8.0 - Fixed missing global variable declarations
45# -------
46# 1.2.0.0 - Added bypass of public proxy lookup for local and private IP addresses
47# 1.2.0.0 - Added four digit version numbering
48# 1.2.0.1 - Added "listact" command to set list block action
49# 1.2.0.1 - Added "action_proxy" configuration to set public proxy detection block action
50# 1.2.0.1 - Added "action_mylist" configuration to set my list item detection block action
51# 1.2.0.2 - Fixed wrong UTC time use instead of local time
52# 1.2.0.3 - Fixed login notification for slow connections
53# 1.2.0.4 - Added "nick_bot" configuration to register bot for sending notifications
54# 1.2.0.5 - Added "extry" command to search for IP address in exception list
55# -------
56# 1.2.1.0 - Fixed incorrect action status when adding new list
57# 1.2.1.0 - Fixed missing translation parameter in loading disabled list message
58# 1.2.1.0 - Added "listex" command to disable or enable list exception usage
59# 1.2.1.0 - Added "except_proxy" configuration to set public proxy detection exception usage
60# 1.2.1.0 - Added "except_mylist" configuration to set my list item detection exception usage
61# 1.2.1.1 - Added "action_extry" configuration to run exception lookup on notification actions
62# 1.2.1.1 - Added "feeddel" command to delete items from waiting feed list
63# -------
64# 1.2.2.0 - Added IP Intelligence proxy lookup instead of Google based public proxy lookup
65# -------
66
67import vh, re, urllib2, gzip, zipfile, StringIO, time, os, subprocess, socket, struct, json
68
69bl_defs = {
70 "version": "1.2.2.0", # todo: dont forget to update
71 "curlver": ["curl", "-V"],
72 "curlreq": "6375726c202d47202d4c202d2d6d61782d726564697273202573202d2d7265747279202573202d2d636f6e6e6563742d74696d656f7574202573202d6d202573202d412022257322202d652022257322202d73202d6f202225732220222573222026",
73 "ipintel": "687474703a2f2f636865636b2e6765746970696e74656c2e6e65742f636865636b2e7068703f666f726d61743d6a736f6e26636f6e746163743d25732669703d2573",
74 "referer": "68747470733a2f2f6769746875622e636f6d2f7665726c696875622f707974686f6e2f",
75 "useragent": ["426c61636b6c6973742f2573", None],
76 "botdesc": "3c426c61636b6c69737420563a25732c4d3a412c483a302f302f312c533a303e",
77 "datadir": os.path.join (vh.basedir, "blackdata"),
78 "timersec": 60,
79 "delwait": 60,
80 "prevfeed": 60
81}
82
83bl_lang = {
84 0: "Blacklist %s startup",
85 1: "Exception",
86 2: "Failed with HTTP error",
87 3: "Failed with URL error",
88 4: "Failed with unknown error",
89 5: "Failed to compile pattern",
90 6: "File is not compressed with GZIP",
91 7: "Failed to read data",
92 8: "%s items loaded",
93 9: "Unknown list type",
94 10: "Failed to open file",
95 11: "My list",
96 12: "Value too low",
97 13: "Value too high",
98 14: "Value is not a number",
99 15: "Value too short",
100 16: "Value too long",
101 17: "Item not found",
102 18: "Blacklisted connection exception from %s.%s: %s",
103 19: "Blocking blacklisted connection from %s.%s: %s",
104 20: "You don't have access to this command.",
105 21: "Blacklist statistics",
106 22: "Version: %s",
107 23: "Loaded lists: %s",
108 24: "Blacklisted items: %s",
109 25: "Excepted items: %s",
110 26: "Blocked connections: %s",
111 27: "Excepted connections: %s",
112 28: "Total connections: %s",
113 29: "Missing command parameters: %s",
114 30: "Results for IP: %s",
115 31: "No results for IP: %s",
116 32: "Results for title: %s",
117 33: "No results for title: %s",
118 34: "Blacklist list is empty.",
119 35: "Blacklist list",
120 36: "ID: %s",
121 37: "List: %s",
122 38: "Type: %s",
123 39: "Title: %s",
124 40: "Update: %s",
125 41: "On load",
126 42: "%s minute",
127 43: "%s minutes",
128 44: "Disabled: %s",
129 45: "No",
130 46: "Yes",
131 47: "Type must be one of: %s",
132 48: "Update must be in range: %s - %s",
133 49: "Item already in list",
134 50: "Item added to list",
135 51: "Status: %s",
136 52: "Item deleted from list",
137 53: "List out of item with ID: %s",
138 54: "Item now disabled",
139 55: "Item now enabled",
140 56: "Exception list is empty.",
141 57: "Exception list",
142 58: "Lower IP: %s",
143 59: "Higher IP: %s",
144 60: "Lower IP not valid: %s",
145 61: "Higher IP not valid: %s",
146 62: "Configuration list",
147 63: "Name: %s",
148 64: "Range: %s - %s",
149 65: "Value: %s",
150 66: "Item configuration",
151 67: "Old value: %s",
152 68: "New value: %s",
153 69: "Waiting feed list is empty.",
154 70: "Waiting feed list",
155 71: "IP: %s.%s",
156 72: "Expires: %s",
157 73: "Blacklist usage",
158 74: "Script statistics",
159 75: "Search in loaded lists",
160 76: "Show all lists",
161 77: "Load new list",
162 78: "Disable or enable list",
163 79: "Delete existing list",
164 80: "Show exception list",
165 81: "New exception item",
166 82: "Delete an exception",
167 83: "Show current configuration",
168 84: "Set configuration item",
169 85: "Show waiting feed list",
170 86: "value",
171 87: "item",
172 88: "id",
173 89: "addr",
174 90: "range",
175 91: "title",
176 92: "list",
177 93: "type",
178 94: "update",
179 95: "None",
180 96: "Set translation string",
181 97: "Show current translation",
182 98: "Translation list",
183 99: "Updated translation with ID: %s",
184 100: "Parameter count mismatch in translation with ID: %s",
185 101: "File is not compressed with ZIP",
186 102: "Force load of existing list",
187 103: "Item is disabled: %s",
188 104: "Item load result",
189 105: "Failed to load JSON",
190 106: "Failed to parse JSON",
191 107: "Failed to get status",
192 108: "Unexpected status: %s",
193 109: "Failed to get result",
194 110: "Failed to open URL",
195 111: "Waiting feed list out of item: %s.%s",
196 112: "Error status: %s",
197 113: "Unknown",
198 114: "Waiting feed list item deleted: %s.%s",
199 115: "Bad command parameters: %s",
200 116: "Public proxy lookup",
201 117: "Waiting feed list has been cleared.",
202 118: "Not enough matches for %s.%s: %s of %s",
203 119: "Public proxy detected: %s.%s",
204 120: "Failed proxy detection for %s.%s: %s",
205 121: "Delete blacklisted item",
206 122: "List out of item with range: %s - %s",
207 123: "Data directory: %s",
208 124: "Failed to create directory",
209 125: "Failed to execute command",
210 126: "Public proxy",
211 127: "Show waiting proxy lookups",
212 128: "Waiting proxy lookup list is empty.",
213 129: "Waiting proxy lookups",
214 130: "Time: %s",
215 131: "Users: %s",
216 132: "Feature is disabled.",
217 133: "Total: %s",
218 134: "Queued",
219 135: "Waiting",
220 136: "Failed to get version",
221 137: "%s version: %s",
222 138: "%s of %s",
223 139: "Done",
224 140: "My list is empty.",
225 141: "Reload all lists",
226 142: "My item",
227 143: "Reload results",
228 144: "Show my list",
229 145: "New my item",
230 146: "Delete my item",
231 147: "My items: %s",
232 148: "Excepted country",
233 149: "Blocked country",
234 150: "User nick to receive all feed messages",
235 151: "Space separated country codes to block",
236 152: "Space separated country codes to except",
237 153: "Minimal class to receive feed messages",
238 154: "Minimal class to access script commands",
239 155: "Minimal class to skip public proxy lookup",
240 156: "Minutes to delay same IP notifications",
241 157: "Download operation timeout in seconds",
242 158: "Enable blacklist list update notification",
243 159: "Maximum number of blacklist search results",
244 160: "Enable public proxy lookup on user login",
245 161: "Email address required for proxy lookup",
246 162: "Minimal number of public proxy matches",
247 163: "Minutes to wait after hub is started",
248 164: "Seconds to process proxy lookup queue",
249 165: "Maximum number of proxy lookups to enqueue",
250 166: "Maximum number of proxy lookups to send",
251 167: "Explanation: %s",
252 168: "Disable proxy lookup failure notifications",
253 169: "Level of proxy lookup debug information",
254 170: "User agent: %s",
255 171: "Delete from waiting feed list",
256 172: "Set list block action",
257 173: "Item now set to block",
258 174: "Item now set to notify",
259 175: "Action: %s",
260 176: "Block",
261 177: "Notify",
262 178: "Blocking blacklisted login from %s with IP %s.%s: %s",
263 179: "Notifying blacklisted connection from %s.%s: %s",
264 180: "Notifying blacklisted login from %s with IP %s.%s: %s",
265 181: "Block action on public proxy detections",
266 182: "Block action on my list item detections",
267 183: "Notified connections: %s",
268 184: "Blacklisted login exception from %s with IP %s.%s: %s",
269 185: "Bot nick to register and send notifications",
270 186: "Search in exceptions",
271 187: "Except: %s",
272 188: "Item exception now disabled",
273 189: "Item exception now enabled",
274 190: "Set list exception usage",
275 191: "Exception usage on public proxy detections",
276 192: "Exception usage on my list item detections",
277 193: "Run exception lookup on notification actions",
278 194: "Exception list out of IP %s.%s: %s"
279}
280
281bl_conf = {
282 "nick_bot": ["", "str", 0, 255, "Bot nick to register and send notifications"],
283 "nick_feed": ["", "str", 0, 255, "User nick to receive all feed messages"],
284 "code_block": ["", "str", 0, 255, "Space separated country codes to block"],
285 "code_except": ["", "str", 0, 255, "Space separated country codes to except"],
286 "class_feed": [5, "int", 0, 11, "Minimal class to receive feed messages"],
287 "class_conf": [10, "int", 3, 11, "Minimal class to access script commands"],
288 "class_skip": [3, "int", 0, 11, "Minimal class to skip public proxy lookup"],
289 "time_feed": [60, "int", 0, 1440, "Minutes to delay same IP notifications"],
290 "time_down": [5, "int", 1, 300, "Download operation timeout in seconds"],
291 "notify_update": [1, "int", 0, 1, "Enable blacklist list update notification"],
292 "find_maxres": [1000, "int", 1, 10000, "Maximum number of blacklist search results"],
293 "prox_lookup": [0, "int", 0, 1, "Enable public proxy lookup on user login"],
294 "prox_email": ["", "str", 0, 255, "Email address required for proxy lookup"],
295 "prox_match": [80, "int", 1, 100, "Minimal number of public proxy matches"],
296 "prox_start": [5, "int", 0, 30, "Minutes to wait after hub is started"],
297 "prox_timer": [3, "int", 1, 300, "Seconds to process proxy lookup queue"],
298 "prox_queue": [100, "int", 1, 10000, "Maximum number of proxy lookups to enqueue"],
299 "prox_maxreq": [1, "int", 1, 100, "Maximum number of proxy lookups to send"],
300 "prox_nofail": [0, "int", 0, 1, "Disable proxy lookup failure notifications"],
301 "prox_debug": [0, "int", 0, 2, "Level of proxy lookup debug information"],
302 "action_proxy": [1, "int", 0, 1, "Block action on public proxy detections"],
303 "action_mylist": [1, "int", 0, 1, "Block action on my list item detections"],
304 "except_proxy": [1, "int", 0, 1, "Exception usage on public proxy detections"],
305 "except_mylist": [1, "int", 0, 1, "Exception usage on my list item detections"],
306 "action_extry": [0, "int", 0, 1, "Run exception lookup on notification actions"]
307}
308
309bl_stat = {
310 "connect": 0l,
311 "block": 0l,
312 "notify": 0l,
313 "except": 0l,
314 "update": time.time (),
315 "proxy": time.time ()
316}
317
318bl_list = [
319 #["http://list.iblocklist.com/?list=ijfqtofzixtwayqovmxn&fileformat=p2p&archiveformat=gz", "gzip-p2p", "TBG - Primary", 0, 0, 1, 1, 0],
320 #["http://list.iblocklist.com/?list=xoebmbyexwuiogmbyprb&fileformat=p2p&archiveformat=gz", "gzip-p2p", "Bluetack - Proxy", 0, 0, 1, 1, 0],
321 #["http://te-home.net/blacklist.php?do=load&list=AP2P", "p2p", "TE - AP2P", 60, 0, 1, 1, 0],
322 #["http://te-home.net/blacklist.php?do=load&list=Proxy", "p2p", "TE - Proxy", 60, 0, 1, 1, 0],
323 #["http://te-home.net/blacklist.php?do=load&list=SOCKS", "p2p", "TE - SOCKS", 60, 0, 1, 1, 0],
324 #["http://ledo.feardc.net/mirror/torexit.list", "single", "Tor exit", 60, 0, 1, 1, 0],
325 #["http://ledo.feardc.net/mirror/torserver.list", "single", "Tor server", 60, 0, 1, 1, 0]
326]
327
328bl_item = []
329bl_prox = [[] for pos in xrange (256)]
330bl_myli = []
331bl_exli = []
332bl_feed = []
333
334def bl_main ():
335 global bl_defs, bl_lang, bl_conf, bl_list, bl_myli, bl_exli
336
337 vh.SQL (
338 "create table if not exists `py_bl_lang` ("\
339 "`id` bigint(20) unsigned not null primary key,"\
340 "`value` text collate utf8_unicode_ci not null"\
341 ") engine = myisam default character set utf8 collate utf8_unicode_ci"
342 )
343
344 vh.SQL (
345 "create table if not exists `py_bl_conf` ("\
346 "`name` varchar(255) collate utf8_unicode_ci not null primary key,"\
347 "`value` varchar(255) collate utf8_unicode_ci not null"\
348 ") engine = myisam default character set utf8 collate utf8_unicode_ci"
349 )
350
351 vh.SQL (
352 "create table if not exists `py_bl_list` ("\
353 "`list` varchar(255) collate utf8_unicode_ci not null primary key,"\
354 "`type` varchar(25) collate utf8_unicode_ci not null,"\
355 "`title` varchar(255) collate utf8_unicode_ci not null,"\
356 "`update` smallint(4) unsigned not null default 0,"\
357 "`off` tinyint(1) unsigned not null default 0,"\
358 "`action` tinyint(1) unsigned not null default 1,"\
359 "`except` tinyint(1) unsigned not null default 1"\
360 ") engine = myisam default character set utf8 collate utf8_unicode_ci"
361 )
362
363 vh.SQL (
364 "create table if not exists `py_bl_myli` ("\
365 "`loaddr` int(10) unsigned not null,"\
366 "`hiaddr` int(10) unsigned not null,"\
367 "`title` varchar(255) collate utf8_unicode_ci null default null,"\
368 "unique `addr_index` (`loaddr`, `hiaddr`)"\
369 ") engine = myisam default character set utf8 collate utf8_unicode_ci"
370 )
371
372 vh.SQL (
373 "create table if not exists `py_bl_exli` ("\
374 "`loaddr` int(10) unsigned not null,"\
375 "`hiaddr` int(10) unsigned not null,"\
376 "`title` varchar(255) collate utf8_unicode_ci null default null,"\
377 "unique `addr_index` (`loaddr`, `hiaddr`)"\
378 ") engine = myisam default character set utf8 collate utf8_unicode_ci"
379 )
380
381 vh.SQL ("alter ignore table `py_bl_list` add column `off` tinyint(1) unsigned not null default 0 after `update`")
382 vh.SQL ("alter ignore table `py_bl_list` add column `action` tinyint(1) unsigned not null default 1 after `off`")
383 vh.SQL ("alter ignore table `py_bl_list` add column `except` tinyint(1) unsigned not null default 1 after `action`")
384
385 for id, item in bl_lang.iteritems ():
386 vh.SQL ("insert ignore into `py_bl_lang` (`id`, `value`) values (%s, '%s')" % (str (id), bl_repsql (item)))
387 bl_lang [id] = [item, item]
388
389 sql, rows = vh.SQL ("select * from `py_bl_lang`", 300) # todo: dont forget about limit
390
391 if sql and rows:
392 for item in rows:
393 id = int (item [0])
394
395 if id >= 0 and len (bl_lang) - 1 >= id and item [1].count ("%s") == bl_lang [id][0].count ("%s"):
396 bl_lang [id][1] = item [1]
397
398 for name, value in bl_conf.iteritems ():
399 vh.SQL ("insert ignore into `py_bl_conf` (`name`, `value`) values ('%s', '%s')" % (bl_repsql (name), bl_repsql (str (value [0]))))
400
401 sql, rows = vh.SQL ("select * from `py_bl_conf`", 100) # todo: dont forget about limit
402
403 if sql and rows:
404 for item in rows:
405 bl_setconf (item [0], item [1], False)
406
407 sql, rows = vh.SQL ("select * from `py_bl_list` order by `off` asc, `action` desc, `title` asc", 100) # todo: dont forget about limit
408
409 if sql and rows:
410 for item in rows:
411 bl_list.append ([item [0], item [1], item [2], int (item [3]), int (item [4]), int (item [5]), int (item [6]), 0])
412
413 if bl_conf ["nick_bot"][0]:
414 bl_addbot (bl_conf ["nick_bot"][0])
415
416 out = (bl_getlang ("Blacklist %s startup") + ":\r\n\r\n") % bl_defs ["version"]
417 out += bl_reload ()
418 sql, rows = vh.SQL ("select * from `py_bl_myli`", 1000) # todo: dont forget about limit
419
420 if sql and rows:
421 for item in rows:
422 bl_myli.append ([int (item [0]), int (item [1]), bl_getlang ("My item") if item [2] == "NULL" else item [2]])
423
424 out += " [*] %s: %s\r\n" % (bl_getlang ("My list"), str (len (rows)))
425 sql, rows = vh.SQL ("select * from `py_bl_exli`", 1000) # todo: dont forget about limit
426
427 if sql and rows:
428 for item in rows:
429 bl_exli.append ([int (item [0]), int (item [1]), bl_getlang ("Exception") if item [2] == "NULL" else item [2]])
430
431 out += " [*] %s: %s\r\n" % (bl_getlang ("Exception"), str (len (rows)))
432
433 if bl_conf ["prox_lookup"][0]:
434 fail, res = True, bl_curlver ()
435 out += (" [*] " + bl_getlang ("%s version: %s") + "\r\n") % ("cURL", res [1])
436
437 if res [0]:
438 res = bl_makedir (bl_defs ["datadir"])
439 out += (" [*] " + bl_getlang ("Data directory: %s") + "\r\n") % res [1]
440
441 if res [0]:
442 try:
443 import fake_useragent
444 bl_defs ["useragent"][1] = fake_useragent.UserAgent ()
445 except:
446 pass
447
448 out += (" [*] " + bl_getlang ("User agent: %s") + "\r\n") % bl_useragent (True)
449 fail = False
450
451 if fail:
452 bl_setconf ("prox_lookup", "0")
453
454 bl_notify (out)
455
456def bl_import (list, type, title, action, exuse, update = False): # gzip-p2p, gzip-emule, gzip-range, gzip-single, zip-p2p, zip-emule, zip-range, zip-single, p2p, emule, range, single
457 global bl_defs, bl_conf, bl_item
458 file = None
459
460 if "://" in list:
461 try:
462 file = urllib2.urlopen (urllib2.Request (list, None, {"Referer": bl_defs ["referer"].decode ("hex"), "User-agent": bl_useragent ()}), None, bl_conf ["time_down"][0])
463 except urllib2.HTTPError:
464 return bl_getlang ("Failed with HTTP error")
465 except urllib2.URLError:
466 return bl_getlang ("Failed with URL error")
467 except:
468 return bl_getlang ("Failed with unknown error")
469 else:
470 try:
471 file = open (list, "r")
472 except:
473 pass
474
475 if not file:
476 return bl_getlang ("Failed to open URL") if "://" in list else bl_getlang ("Failed to open file")
477
478 find = None
479
480 if "p2p" in type:
481 find = "(.*)\\:(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\-(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})"
482 elif "emule" in type:
483 find = "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3}) \\- (\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3}) \\, \\d{1,3} \\, (.*)"
484 elif "range" in type:
485 find = "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\-(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})"
486 elif "single" in type:
487 find = "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})"
488
489 if not find:
490 file.close ()
491 return bl_getlang ("Unknown list type")
492
493 try:
494 find = re.compile ("^" + find + "$")
495 except:
496 file.close ()
497 return bl_getlang ("Failed to compile pattern")
498
499 if "gzip" in type or "zip" in type:
500 data = None
501
502 try:
503 data = StringIO.StringIO (file.read ())
504 except:
505 pass
506
507 file.close ()
508
509 if not data:
510 return bl_getlang ("Failed to read data")
511
512 if "gzip" in type:
513 try:
514 file = gzip.GzipFile (fileobj = data)
515 file.read (1)
516 except:
517 return bl_getlang ("File is not compressed with GZIP")
518 elif "zip" in type:
519 try:
520 arch = zipfile.ZipFile (file = data)
521 file = arch.open (arch.namelist () [0])
522 arch.close ()
523 file.read (1)
524 except:
525 return bl_getlang ("File is not compressed with ZIP")
526
527 temp = []
528
529 for line in file:
530 part = find.findall (line.replace ("\r", "").replace ("\n", ""))
531
532 if part:
533 name, loaddr, hiaddr = None, None, None
534
535 if "p2p" in type:
536 name = part [0][0] or title
537 loaddr = str (int (part [0][1])) + "." + str (int (part [0][2])) + "." + str (int (part [0][3])) + "." + str (int (part [0][4]))
538 hiaddr = str (int (part [0][5])) + "." + str (int (part [0][6])) + "." + str (int (part [0][7])) + "." + str (int (part [0][8]))
539 elif "emule" in type:
540 name = part [0][8] or title
541 loaddr = str (int (part [0][0])) + "." + str (int (part [0][1])) + "." + str (int (part [0][2])) + "." + str (int (part [0][3]))
542 hiaddr = str (int (part [0][4])) + "." + str (int (part [0][5])) + "." + str (int (part [0][6])) + "." + str (int (part [0][7]))
543 elif "range" in type:
544 name = title
545 loaddr = str (int (part [0][0])) + "." + str (int (part [0][1])) + "." + str (int (part [0][2])) + "." + str (int (part [0][3]))
546 hiaddr = str (int (part [0][4])) + "." + str (int (part [0][5])) + "." + str (int (part [0][6])) + "." + str (int (part [0][7]))
547 elif "single" in type:
548 name = title
549 loaddr = str (int (part [0][0])) + "." + str (int (part [0][1])) + "." + str (int (part [0][2])) + "." + str (int (part [0][3]))
550 hiaddr = loaddr
551
552 if name and loaddr and hiaddr and bl_validaddr (loaddr) and bl_validaddr (hiaddr):
553 temp.append ([bl_addrtoint (loaddr), bl_addrtoint (hiaddr), name.replace ("\\'", "'").replace ("\\\"", "\"").replace ("\\&", "&").replace ("\\\\", "\\"), action, exuse])
554
555 file.close ()
556
557 for item in temp:
558 for pos in xrange (item [0] >> 24, (item [1] >> 24) + 1):
559 if not update or not item in bl_item [pos]:
560 bl_item [pos].append (item)
561
562 return bl_getlang ("%s items loaded") % str (len (temp))
563
564def bl_reload ():
565 global bl_list, bl_item
566 del bl_item [:]
567 bl_item = [[] for pos in xrange (256)]
568 out = ""
569
570 for id, item in enumerate (bl_list):
571 if not item [4]:
572 out += " [*] %s: %s\r\n" % (item [2], bl_import (item [0], item [1], item [2], item [5], item [6]))
573
574 if item [3]:
575 bl_list [id][7] = time.time ()
576
577 return out
578
579def bl_lookup (data):
580 global bl_conf
581 list = None
582
583 try:
584 list = json.loads (data)
585 except:
586 return [False, bl_getlang ("Failed to load JSON")]
587
588 if not list:
589 return [False, bl_getlang ("Failed to parse JSON")]
590
591 if not "status" in list:
592 return [False, bl_getlang ("Failed to get status")]
593
594 if list ["status"] == "error":
595 return [False, bl_getlang ("Error status: %s") % str (list ["message"]) if "message" in list else bl_getlang ("Unknown")]
596
597 if list ["status"] != "success":
598 return [False, bl_getlang ("Unexpected status: %s") % str (list ["status"])]
599
600 if not "result" in list:
601 return [False, bl_getlang ("Failed to get result")]
602
603 try:
604 res = float (list ["result"])
605 except:
606 res = -1
607
608 if res < 0:
609 return [False, bl_getlang ("Failed to get result")]
610
611 res = int (res * 100)
612
613 if res >= bl_conf ["prox_match"][0]:
614 return [True, res]
615
616 return [False, res]
617
618def bl_curlver ():
619 global bl_defs
620 out = None
621
622 try:
623 out = subprocess.check_output (bl_defs ["curlver"])
624 except:
625 pass
626
627 if not out:
628 return [False, bl_getlang ("Failed to execute command")]
629
630 find = re.compile ("(\\d+[\\.\\d]+)").search (out)
631
632 if not find:
633 return [False, bl_getlang ("Failed to get version")]
634
635 return [True, find.group (1)]
636
637def bl_httpreq (url):
638 global bl_defs, bl_conf
639 file = None
640
641 try:
642 file = urllib2.urlopen (urllib2.Request (url, None, {"Referer": bl_defs ["referer"].decode ("hex"), "User-agent": bl_useragent ()}), None, bl_conf ["time_down"][0])
643 except urllib2.HTTPError:
644 return [False, bl_getlang ("Failed with HTTP error")]
645 except urllib2.URLError:
646 return [False, bl_getlang ("Failed with URL error")]
647 except:
648 return [False, bl_getlang ("Failed with unknown error")]
649
650 if not file:
651 return [False, bl_getlang ("Failed to open URL")]
652
653 data = None
654
655 try:
656 data = file.read ()
657 except:
658 pass
659
660 file.close ()
661
662 if data:
663 return [True, data]
664 else:
665 return [False, bl_getlang ("Failed to read data")]
666
667def bl_remfile (file):
668 res = True
669
670 try:
671 os.unlink (file)
672 except:
673 res = False
674
675 return res
676
677def bl_makedir (dir):
678 if not os.path.exists (dir):
679 try:
680 os.makedirs (dir)
681 except:
682 return [False, bl_getlang ("Failed to create directory")]
683 else:
684 for file in os.listdir (dir):
685 file = os.path.join (dir, file)
686
687 if os.path.isfile (file):
688 bl_remfile (file)
689
690 return [True, dir]
691
692def bl_extry (addr, code, intaddr, loaddr, hiaddr):
693 global bl_exli
694
695 for item in bl_exli:
696 if intaddr >= item [0] and intaddr <= item [1]:
697 return
698
699 bl_notify (bl_getlang ("Exception list out of IP %s.%s: %s") % (addr, code, bl_inttoaddr (loaddr) + "-" + bl_inttoaddr (hiaddr)))
700
701def bl_excheck (addr, intaddr, code, name, exuse, nick = None):
702 global bl_conf, bl_stat, bl_exli
703
704 if exuse:
705 if bl_conf ["code_except"][0] and code and str ().join ([" ", code, " "]) in str ().join ([" ", bl_conf ["code_except"][0], " "]):
706 if bl_waitfeed (addr):
707 if nick:
708 bl_notify ((bl_getlang ("Blacklisted login exception from %s with IP %s.%s: %s") + " | %s") % (nick, addr, code, name, bl_getlang ("Excepted country")))
709 else:
710 bl_notify ((bl_getlang ("Blacklisted connection exception from %s.%s: %s") + " | %s") % (addr, code, name, bl_getlang ("Excepted country")))
711
712 if not nick:
713 bl_stat ["except"] += 1
714
715 return 1
716
717 for item in bl_exli:
718 if intaddr >= item [0] and intaddr <= item [1]:
719 if bl_waitfeed (addr):
720 if nick:
721 bl_notify ((bl_getlang ("Blacklisted login exception from %s with IP %s.%s: %s") + " | %s") % (nick, addr, code, name, item [2]))
722 else:
723 bl_notify ((bl_getlang ("Blacklisted connection exception from %s.%s: %s") + " | %s") % (addr, code, name, item [2]))
724
725 if not nick:
726 bl_stat ["except"] += 1
727
728 return 1
729
730 if bl_waitfeed (addr):
731 if nick:
732 bl_notify (bl_getlang ("Blocking blacklisted login from %s with IP %s.%s: %s") % (nick, addr, code, name))
733 else:
734 bl_notify (bl_getlang ("Blocking blacklisted connection from %s.%s: %s") % (addr, code, name))
735
736 if not nick:
737 bl_stat ["block"] += 1
738
739 return 0
740
741def bl_waitfeed (addr, prev = False):
742 global bl_defs, bl_conf, bl_feed
743 mins, now = (bl_conf ["time_feed"][0] * 60), time.time ()
744
745 for id, item in enumerate (bl_feed):
746 if addr == item [0]:
747 dif = now - item [1]
748
749 if dif >= mins or (prev and dif <= bl_defs ["prevfeed"]):
750 bl_feed [id][1] = now
751 return 1
752
753 return 0
754
755 bl_feed.append ([addr, now])
756 return 1
757
758def bl_getlang (data):
759 global bl_lang
760
761 for item in bl_lang.itervalues ():
762 if data == item [0]:
763 return item [1]
764
765 return data
766
767def bl_getconf (name):
768 global bl_conf
769
770 if not name in bl_conf:
771 return None
772
773 return bl_conf [name][0]
774
775def bl_setconf (name, value, update = True):
776 global bl_defs, bl_conf, bl_prox
777
778 if not name in bl_conf:
779 return bl_getlang ("Item not found")
780
781 old, new = bl_conf [name][0], str (value)
782
783 if bl_conf [name][1] == "int":
784 if not new.isdigit ():
785 return bl_getlang ("Value is not a number")
786
787 new = int (new)
788
789 if new < bl_conf [name][2]:
790 return bl_getlang ("Value too low")
791 elif new > bl_conf [name][3]:
792 return bl_getlang ("Value too high")
793 else:
794 if len (new) < bl_conf [name][2]:
795 return bl_getlang ("Value too short")
796 elif len (new) > bl_conf [name][3]:
797 return bl_getlang ("Value too long")
798
799 if update:
800 if name == "nick_bot":
801 if new and not old:
802 bl_addbot (new)
803 elif not new and old:
804 bl_delbot (old)
805 elif new != old:
806 bl_delbot (old)
807 bl_addbot (new)
808
809 elif name == "prox_lookup":
810 if new and not old:
811 res = bl_curlver ()
812
813 if not res [0]:
814 return res [1]
815
816 bl_notify (bl_getlang ("%s version: %s") % ("cURL", res [1]))
817 res = bl_makedir (bl_defs ["datadir"])
818
819 if not res [0]:
820 return res [1]
821
822 bl_notify (bl_getlang ("Data directory: %s") % res [1])
823
824 try:
825 import fake_useragent
826 bl_defs ["useragent"][1] = fake_useragent.UserAgent ()
827 except:
828 pass
829
830 bl_notify (bl_getlang ("User agent: %s") % bl_useragent (True))
831 elif not new and old:
832 del bl_prox [:]
833 bl_prox = [[] for pos in xrange (256)]
834 bl_makedir (bl_defs ["datadir"])
835 bl_defs ["useragent"][1] = None
836
837 vh.SQL ("update `py_bl_conf` set `value` = '%s' where `name` = '%s'" % (bl_repsql (str (new)), bl_repsql (name)))
838
839 bl_conf [name][0] = new
840 return "%s -> %s" % (str (old), str (new))
841
842def bl_addrtoint (addr):
843 res = 0
844
845 try:
846 res = struct.unpack ("!L", socket.inet_aton (addr)) [0]
847 except:
848 pass
849
850 return res
851
852def bl_inttoaddr (addr):
853 res = "0.0.0.0"
854
855 try:
856 res = socket.inet_ntoa (struct.pack ("!L", int (addr)))
857 except:
858 pass
859
860 return res
861
862def bl_validaddr (addr):
863 if len (addr) < 7 or len (addr) > 15:
864 return 0
865
866 num = 0
867
868 for part in addr.split ("."):
869 if len (part) < 1 or len (part) > 3 or not part.isdigit () or int (part) < 0 or int (part) > 255:
870 return 0
871
872 num += 1
873
874 return (1 if num == 4 else 0)
875
876def bl_useragent (rand = False):
877 global bl_defs
878 res = ""
879
880 if rand and bl_defs ["useragent"][1]:
881 res = str (bl_defs ["useragent"][1]["random"])
882 else:
883 res = bl_defs ["useragent"][0].decode ("hex") % bl_defs ["version"]
884
885 return res
886
887def bl_repsql (data):
888 return data.replace (chr (92), chr (92) + chr (92)).replace (chr (34), chr (92) + chr (34)).replace (chr (39), chr (92) + chr (39))
889
890def bl_repnmdc (data, out = False):
891 if out:
892 return data.replace ("|", "|").replace ("$", "$")
893 else:
894 return data.replace ("|", "|").replace ("$", "$")
895
896def bl_reply (user, data):
897 vh.SendDataToUser ("<%s> %s|" % (vh.botname, bl_repnmdc (data)), user)
898
899def bl_notify (data):
900 global bl_conf
901
902 if bl_conf ["nick_feed"][0]:
903 vh.SendDataToUser ("$To: %s From: %s $<%s> %s|" % (bl_conf ["nick_feed"][0], vh.opchatname, vh.opchatname, bl_repnmdc (data)), bl_conf ["nick_feed"][0])
904 elif bl_conf ["nick_bot"][0]:
905 vh.SendPMToAll (bl_repnmdc (data), bl_conf ["nick_bot"][0], bl_conf ["class_feed"][0], 10)
906 else:
907 vh.SendPMToAll (bl_repnmdc (data), vh.opchatname, bl_conf ["class_feed"][0], 10)
908
909def bl_addbot (nick):
910 global bl_defs, bl_conf
911 vh.AddRobot (nick, bl_conf ["class_feed"][0], bl_defs ["botdesc"].decode ("hex") % bl_defs ["version"], chr (1), "", "0")
912
913def bl_delbot (nick):
914 vh.DelRobot (nick)
915
916def UnLoad ():
917 global bl_conf
918
919 if bl_conf ["nick_bot"][0]:
920 bl_delbot (bl_conf ["nick_bot"][0])
921
922 return 1
923
924def OnNewConn (addr):
925 global bl_conf, bl_stat, bl_item, bl_myli
926 bl_stat ["connect"] += 1
927 code = vh.GetIPCC (addr)
928
929 if bl_conf ["code_block"][0] and code and str ().join ([" ", code, " "]) in str ().join ([" ", bl_conf ["code_block"][0], " "]):
930 if bl_waitfeed (addr):
931 bl_notify (bl_getlang ("Blocking blacklisted connection from %s.%s: %s") % (addr, code, bl_getlang ("Blocked country")))
932
933 bl_stat ["block"] += 1
934 return 0
935
936 #if code == "L1" or code == "P1":
937 #return 1
938
939 intaddr = bl_addrtoint (addr)
940
941 for item in bl_item [intaddr >> 24]:
942 if intaddr >= item [0] and intaddr <= item [1]:
943 if not item [3]:
944 if bl_waitfeed (addr):
945 bl_notify (bl_getlang ("Notifying blacklisted connection from %s.%s: %s") % (addr, code, item [2]))
946
947 bl_stat ["notify"] += 1
948 return 1
949
950 return bl_excheck (addr, intaddr, code, item [2], item [4])
951
952 for item in bl_myli:
953 if intaddr >= item [0] and intaddr <= item [1]:
954 if not bl_conf ["action_mylist"][0]:
955 if bl_waitfeed (addr):
956 bl_notify (bl_getlang ("Notifying blacklisted connection from %s.%s: %s") % (addr, code, item [2]))
957
958 bl_stat ["notify"] += 1
959 return 1
960
961 return bl_excheck (addr, intaddr, code, item [2], bl_conf ["except_mylist"][0])
962
963 return 1
964
965def OnUserLogin (nick):
966 global bl_conf, bl_stat, bl_item, bl_prox, bl_myli
967 addr = vh.GetUserIP (nick)
968
969 if not addr:
970 return 1
971
972 code = vh.GetUserCC (nick)
973 intaddr = bl_addrtoint (addr)
974 addrpos = intaddr >> 24
975
976 for item in bl_item [addrpos]:
977 if intaddr >= item [0] and intaddr <= item [1]:
978 if not item [3]:
979 if bl_waitfeed (addr, True):
980 bl_notify (bl_getlang ("Notifying blacklisted login from %s with IP %s.%s: %s") % (nick, addr, code, item [2]))
981
982 if bl_conf ["action_extry"][0]:
983 bl_extry (addr, code, intaddr, item [0], item [1])
984
985 return 1
986
987 break
988
989 for item in bl_myli:
990 if intaddr >= item [0] and intaddr <= item [1]:
991 if not bl_conf ["action_mylist"][0]:
992 if bl_waitfeed (addr, True):
993 bl_notify (bl_getlang ("Notifying blacklisted login from %s with IP %s.%s: %s") % (nick, addr, code, item [2]))
994
995 if bl_conf ["action_extry"][0]:
996 bl_extry (addr, code, intaddr, item [0], item [1])
997
998 return 1
999
1000 break
1001
1002 if code == "L1" or code == "P1" or vh.GetUserClass (nick) >= bl_conf ["class_skip"][0]:
1003 return 1
1004
1005 now = time.time ()
1006
1007 if not bl_conf ["prox_lookup"][0] or now - vh.starttime < bl_conf ["prox_start"][0] * 60:
1008 return 1
1009
1010 size = 0
1011
1012 for pos in range (len (bl_prox)):
1013 for id, item in enumerate (bl_prox [pos]):
1014 if pos == addrpos and addr == item [0]:
1015 if item [2] < 2:
1016 if not nick in item [1]:
1017 bl_prox [pos][id][1].append (nick)
1018 elif item [2] == 2:
1019 if bl_waitfeed (addr):
1020 bl_notify (bl_getlang ("Blocking blacklisted login from %s with IP %s.%s: %s") % (nick, addr, code, bl_getlang ("Public proxy")))
1021
1022 bl_stat ["block"] += 1
1023 return 0
1024 #elif item [3] == 3:
1025 #pass
1026
1027 return 1
1028
1029 if not item [2]:
1030 size += 1
1031
1032 if size < bl_conf ["prox_queue"][0]:
1033 bl_prox [addrpos].append ([addr, [nick], 0, now])
1034
1035 return 1
1036
1037def OnOperatorCommand (user, data):
1038 global bl_defs, bl_lang, bl_conf, bl_stat, bl_list, bl_item, bl_prox, bl_myli, bl_exli, bl_feed
1039
1040 if data [1:3] == "bl":
1041 if vh.GetUserClass (user) < bl_conf ["class_conf"][0]:
1042 bl_reply (user, bl_getlang ("You don't have access to this command."))
1043 return 0
1044
1045 if data [4:8] == "stat":
1046 size, lists, wcurl, acurl = 0, 0, 0, 0
1047
1048 for pos in range (len (bl_item)):
1049 size += len (bl_item [pos])
1050
1051 for item in bl_list:
1052 if not item [4]:
1053 lists += 1
1054
1055 for pos in range (len (bl_prox)):
1056 acurl += len (bl_prox [pos])
1057
1058 for item in bl_prox [pos]:
1059 if item [2] < 3:
1060 wcurl += 1
1061
1062 out = bl_getlang ("Blacklist statistics") + ":\r\n"
1063 out += ("\r\n [*] " + bl_getlang ("Version: %s")) % bl_defs ["version"]
1064 out += ("\r\n [*] " + bl_getlang ("Loaded lists: %s")) % (bl_getlang ("%s of %s") % (str (lists), str (len (bl_list))))
1065 out += ("\r\n [*] " + bl_getlang ("Blacklisted items: %s")) % str (size)
1066 out += ("\r\n [*] " + bl_getlang ("My items: %s")) % str (len (bl_myli))
1067 out += ("\r\n [*] " + bl_getlang ("Excepted items: %s")) % str (len (bl_exli))
1068 out += ("\r\n [*] " + bl_getlang ("Blocked connections: %s")) % str (bl_stat ["block"])
1069 out += ("\r\n [*] " + bl_getlang ("Notified connections: %s")) % str (bl_stat ["notify"])
1070 out += ("\r\n [*] " + bl_getlang ("Excepted connections: %s")) % str (bl_stat ["except"])
1071 out += ("\r\n [*] " + bl_getlang ("Total connections: %s")) % str (bl_stat ["connect"])
1072 out += ("\r\n [*] " + bl_getlang ("Waiting proxy lookups") + ": %s") % (bl_getlang ("%s of %s") % (str (wcurl), str (acurl)))
1073 out += ("\r\n [*] " + bl_getlang ("Waiting feed list") + ": %s\r\n") % str (len (bl_feed))
1074 bl_reply (user, out)
1075 return 0
1076
1077 if data [4:8] == "prox":
1078 if not bl_conf ["prox_lookup"][0]:
1079 bl_reply (user, bl_getlang ("Feature is disabled."))
1080 return 0
1081
1082 size, out = 0, ""
1083
1084 for pos in range (len (bl_prox)):
1085 for item in bl_prox [pos]:
1086 if item [2] < 3:
1087 size += 1
1088 out += (" [*] " + bl_getlang ("IP: %s.%s") + " | " + bl_getlang ("Status: %s") + " | " + bl_getlang ("Time: %s") + " | " + bl_getlang ("Users: %s") + "\r\n") % (item [0], vh.GetIPCC (item [0]), (bl_getlang ("Queued") if not item [2] else (bl_getlang ("Waiting") if item [2] == 1 else bl_getlang ("Done"))), time.strftime ("%H:%M:%S", time.localtime (item [3])), (bl_getlang ("None") if item [2] == 2 else ", ".join (item [1])))
1089
1090 if size:
1091 out = bl_getlang ("Waiting proxy lookups") + ":\r\n\r\n" + out
1092 out += ("\r\n " + bl_getlang ("Total: %s") + "\r\n") % str (size)
1093 else:
1094 out = bl_getlang ("Waiting proxy lookup list is empty.")
1095
1096 bl_reply (user, out)
1097 return 0
1098
1099 if data [4:11] == "feedall":
1100 if not bl_feed:
1101 out = bl_getlang ("Waiting feed list is empty.")
1102 else:
1103 out, mins = (bl_getlang ("Waiting feed list") + ":\r\n\r\n"), (bl_conf ["time_feed"][0] * 60)
1104
1105 for item in bl_feed:
1106 out += (" [*] " + bl_getlang ("IP: %s.%s") + " | " + bl_getlang ("Expires: %s") + "\r\n") % (item [0], vh.GetIPCC (item [0]), time.strftime ("%d/%m %H:%M", time.localtime (item [1] + mins)))
1107
1108 out += ("\r\n " + bl_getlang ("Total: %s") + "\r\n") % str (len (bl_feed))
1109
1110 bl_reply (user, out)
1111 return 0
1112
1113 if data [4:11] == "feeddel":
1114 if not bl_feed:
1115 bl_reply (user, bl_getlang ("Waiting feed list is empty."))
1116 return 0
1117
1118 addr = data [12:]
1119
1120 if not addr:
1121 del bl_feed [:]
1122 bl_reply (user, bl_getlang ("Waiting feed list has been cleared."))
1123 return 0
1124
1125 if not bl_validaddr (addr):
1126 bl_reply (user, bl_getlang ("Bad command parameters: %s") % ("feeddel [" + bl_getlang ("addr") + "]"))
1127 return 0
1128
1129 for id, item in enumerate (bl_feed):
1130 if item [0] == addr:
1131 bl_feed.pop (id)
1132 bl_reply (user, bl_getlang ("Waiting feed list item deleted: %s.%s") % (addr, vh.GetIPCC (addr)))
1133 return 0
1134
1135 bl_reply (user, bl_getlang ("Waiting feed list out of item: %s.%s") % (addr, vh.GetIPCC (addr)))
1136 return 0
1137
1138 if data [4:8] == "find":
1139 if not data [9:]:
1140 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("find <" + bl_getlang ("item") + ">"))
1141 return 0
1142
1143 out, size = "", 0
1144
1145 if bl_validaddr (data [9:]):
1146 intaddr = bl_addrtoint (data [9:])
1147
1148 for item in bl_item [intaddr >> 24]:
1149 if intaddr >= item [0] and intaddr <= item [1]:
1150 out += " %s - %s : %s [%s]\r\n" % (bl_inttoaddr (item [0]), bl_inttoaddr (item [1]), item [2], bl_getlang ("Block") if item [3] else bl_getlang ("Notify"))
1151 size += 1
1152
1153 if size >= bl_conf ["find_maxres"][0]:
1154 break
1155
1156 if size:
1157 bl_reply (user, (bl_getlang ("Results for IP: %s") + "\r\n\r\n%s") % (data [9:], out))
1158 else:
1159 bl_reply (user, bl_getlang ("No results for IP: %s") % data [9:])
1160 else:
1161 lowdata = data [9:].lower ()
1162
1163 for pos in range (len (bl_item)):
1164 for item in bl_item [pos]:
1165 if lowdata in item [2].lower ():
1166 out += " %s - %s : %s [%s]\r\n" % (bl_inttoaddr (item [0]), bl_inttoaddr (item [1]), item [2], bl_getlang ("Block") if item [3] else bl_getlang ("Notify"))
1167 size += 1
1168
1169 if size >= bl_conf ["find_maxres"][0]:
1170 break
1171
1172 if size >= bl_conf ["find_maxres"][0]:
1173 break
1174
1175 if size:
1176 bl_reply (user, (bl_getlang ("Results for title: %s") + "\r\n\r\n%s") % (data [9:], out))
1177 else:
1178 bl_reply (user, bl_getlang ("No results for title: %s") % data [9:])
1179
1180 return 0
1181
1182 if data [4:10] == "listre":
1183 out = bl_reload ()
1184
1185 if out:
1186 out = bl_getlang ("Reload results") + ":\r\n\r\n" + out
1187 else:
1188 out = bl_getlang ("Blacklist list is empty.")
1189
1190 bl_reply (user, out)
1191 return 0
1192
1193 if data [4:7] == "del":
1194 pars = re.findall ("^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})[\\- ]*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})?$", data [8:])
1195
1196 if not pars or not pars [0][0]:
1197 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("del <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "]"))
1198 return 0
1199
1200 if not bl_validaddr (pars [0][0]):
1201 bl_reply (user, bl_getlang ("Lower IP not valid: %s") % pars [0][0])
1202 return 0
1203
1204 if pars [0][1] and not bl_validaddr (pars [0][1]):
1205 bl_reply (user, bl_getlang ("Higher IP not valid: %s") % pars [0][1])
1206 return 0
1207
1208 loaddr = bl_addrtoint (pars [0][0])
1209 hiaddr = bl_addrtoint (pars [0][1] or pars [0][0])
1210
1211 for pos in xrange (loaddr >> 24, (hiaddr >> 24) + 1):
1212 for id, item in enumerate (bl_item [pos]):
1213 if loaddr == item [0] and hiaddr == item [1]: # todo: exact match only for now
1214 bl_item [pos].pop (id)
1215
1216 out = bl_getlang ("Item deleted from list") + ":\r\n"
1217 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1218 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % pars [0][0]
1219 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s")) % (pars [0][1] or pars [0][0])
1220 out += ("\r\n [*] " + bl_getlang ("Action: %s") + "\r\n") % (bl_getlang ("Block") if item [3] else bl_getlang ("Notify"))
1221 bl_reply (user, out)
1222 return 0
1223
1224 bl_reply (user, bl_getlang ("List out of item with range: %s - %s") % (pars [0][0], pars [0][1] or pars [0][0]))
1225 return 0
1226
1227 if data [4:8] == "look":
1228 if not data [9:] or not bl_validaddr (data [9:]):
1229 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("look <" + bl_getlang ("addr") + ">"))
1230 return 0
1231
1232 res = bl_httpreq (bl_defs ["ipintel"].decode ("hex") % (bl_conf ["prox_email"][0], data [9:]))
1233
1234 if not res [0]:
1235 bl_reply (user, res [1])
1236 return 0
1237
1238 res = bl_lookup (res [1])
1239
1240 if res [0]:
1241 bl_reply (user, bl_getlang ("Public proxy detected: %s.%s") % (data [9:], vh.GetIPCC (data [9:])))
1242 else:
1243 if str (res [1]).isdigit ():
1244 bl_reply (user, bl_getlang ("Not enough matches for %s.%s: %s of %s") % (data [9:], vh.GetIPCC (data [9:]), str (res [1]), str (bl_conf ["prox_match"][0])))
1245 else:
1246 bl_reply (user, res [1])
1247
1248 return 0
1249
1250 if data [4:11] == "listall":
1251 if not bl_list:
1252 out = bl_getlang ("Blacklist list is empty.")
1253 else:
1254 out = bl_getlang ("Blacklist list") + ":\r\n"
1255
1256 for id, item in enumerate (bl_list):
1257 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1258 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1259 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1260 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1261
1262 if not item [4]:
1263 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1264 else:
1265 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1266
1267 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1268 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1269 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1270
1271 bl_reply (user, out)
1272 return 0
1273
1274 if data [4:11] == "listadd":
1275 pars = re.findall ("^(\\S+)[ ]+(\\S+)[ ]+\"(.+)\"[ ]*(\\d+)?$", data [12:])
1276
1277 if not pars or not pars [0][0] or not pars [0][1] or not pars [0][2]:
1278 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listadd <" + bl_getlang ("list") + "> <" + bl_getlang ("type") + "> <\"" + bl_getlang ("title") + "\"> [" + bl_getlang ("update") + "]"))
1279 return 0
1280
1281 types = [
1282 "gzip-p2p",
1283 "gzip-emule",
1284 "gzip-range",
1285 "gzip-single",
1286 "zip-p2p",
1287 "zip-emule",
1288 "zip-range",
1289 "zip-single",
1290 "p2p",
1291 "emule",
1292 "range",
1293 "single"
1294 ]
1295
1296 if not pars [0][1] in types:
1297 bl_reply (user, bl_getlang ("Type must be one of: %s") % ", ".join (types))
1298 return 0
1299
1300 update = 0
1301
1302 if pars [0][3].isdigit ():
1303 update = int (pars [0][3])
1304
1305 if update < 0 or update > 10800:
1306 bl_reply (user, bl_getlang ("Update must be in range: %s - %s") % (str (0), str (10800)))
1307 return 0
1308
1309 for id, item in enumerate (bl_list):
1310 if item [0].lower () == pars [0][0].lower ():
1311 out = bl_getlang ("Item already in list") + ":\r\n"
1312 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1313 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1314 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1315 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1316
1317 if not item [4]:
1318 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1319 else:
1320 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1321
1322 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1323 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1324 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1325
1326 bl_reply (user, out)
1327 return 0
1328
1329 bl_list.append ([pars [0][0], pars [0][1], pars [0][2], update, 0, 1, 1, time.time () if update else 0])
1330 vh.SQL ("insert into `py_bl_list` (`list`, `type`, `title`, `update`) values ('%s', '%s', '%s', %s)" % (bl_repsql (pars [0][0]), bl_repsql (pars [0][1]), bl_repsql (pars [0][2]), str (update)))
1331
1332 out = bl_getlang ("Item added to list") + ":\r\n"
1333 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (len (bl_list) - 1)
1334 out += ("\r\n [*] " + bl_getlang ("List: %s")) % pars [0][0]
1335 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % pars [0][1]
1336 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % pars [0][2]
1337 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not update else (bl_getlang ("%s minute") + " | %s") % (str (update), time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (update * 60)))) if update == 1 else (bl_getlang ("%s minutes") + " | %s") % (str (update), time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (update * 60)))))
1338 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % bl_getlang ("No")
1339 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % bl_getlang ("Block")
1340 out += ("\r\n [*] " + bl_getlang ("Except: %s")) % bl_getlang ("Yes")
1341 out += ("\r\n [*] " + bl_getlang ("Status: %s") + "\r\n") % bl_import (pars [0][0], pars [0][1], pars [0][2], 1, 1)
1342
1343 bl_reply (user, out)
1344 return 0
1345
1346 if data [4:11] == "listdel":
1347 if data [12:].isdigit ():
1348 id = int (data [12:])
1349 else:
1350 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listdel <" + bl_getlang ("id") + ">"))
1351 return 0
1352
1353 if id >= 0 and bl_list and len (bl_list) - 1 >= id:
1354 item = bl_list.pop (id)
1355 vh.SQL ("delete from `py_bl_list` where `list` = '%s'" % bl_repsql (item [0]))
1356
1357 out = bl_getlang ("Item deleted from list") + ":\r\n"
1358 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1359 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1360 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1361 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1362 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else ((bl_getlang ("%s minute") % item [3]) if item [3] == 1 else (bl_getlang ("%s minutes") % item [3])))
1363 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1364 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1365 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1366
1367 bl_reply (user, out)
1368 else:
1369 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1370
1371 return 0
1372
1373 if data [4:11] == "listoff":
1374 if data [12:].isdigit ():
1375 id = int (data [12:])
1376 else:
1377 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listoff <" + bl_getlang ("id") + ">"))
1378 return 0
1379
1380 if id >= 0 and bl_list and len (bl_list) - 1 >= id:
1381 item = bl_list [id]
1382
1383 if not item [4]:
1384 bl_list [id][4], bl_list [id][7] = 1, 0
1385 vh.SQL ("update `py_bl_list` set `off` = 1 where `list` = '%s'" % bl_repsql (item [0]))
1386
1387 out = bl_getlang ("Item now disabled") + ":\r\n"
1388 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1389 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1390 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1391 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1392 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else ((bl_getlang ("%s minute") % item [3]) if item [3] == 1 else (bl_getlang ("%s minutes") % item [3])))
1393 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % bl_getlang ("Yes")
1394 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1395 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1396
1397 bl_reply (user, out)
1398 else:
1399 bl_list [id][4] = 0
1400 vh.SQL ("update `py_bl_list` set `off` = 0 where `list` = '%s'" % bl_repsql (item [0]))
1401
1402 if item [3]:
1403 bl_list [id][7] = time.time ()
1404
1405 out = bl_getlang ("Item now enabled") + ":\r\n"
1406 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1407 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1408 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1409 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1410 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (item [3] * 60)))))
1411 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % bl_getlang ("No")
1412 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1413 out += ("\r\n [*] " + bl_getlang ("Except: %s")) % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1414 out += ("\r\n [*] " + bl_getlang ("Status: %s") + "\r\n") % bl_import (item [0], item [1], item [2], item [5], item [6])
1415
1416 bl_reply (user, out)
1417 else:
1418 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1419
1420 return 0
1421
1422 if data [4:11] == "listact":
1423 if data [12:].isdigit ():
1424 id = int (data [12:])
1425 else:
1426 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listact <" + bl_getlang ("id") + ">"))
1427 return 0
1428
1429 if id >= 0 and bl_list and len (bl_list) - 1 >= id:
1430 item = bl_list [id]
1431
1432 if item [5]:
1433 bl_list [id][5] = 0
1434 vh.SQL ("update `py_bl_list` set `action` = 0 where `list` = '%s'" % bl_repsql (item [0]))
1435
1436 out = bl_getlang ("Item now set to notify") + ":\r\n"
1437 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1438 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1439 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1440 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1441
1442 if not item [4]:
1443 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1444 else:
1445 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1446
1447 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1448 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % bl_getlang ("Notify")
1449 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1450
1451 bl_reply (user, out)
1452 else:
1453 bl_list [id][5] = 1
1454 vh.SQL ("update `py_bl_list` set `action` = 1 where `list` = '%s'" % bl_repsql (item [0]))
1455
1456 out = bl_getlang ("Item now set to block") + ":\r\n"
1457 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1458 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1459 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1460 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1461
1462 if not item [4]:
1463 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1464 else:
1465 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1466
1467 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1468 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % bl_getlang ("Block")
1469 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1470
1471 bl_reply (user, out)
1472 else:
1473 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1474
1475 return 0
1476
1477 if data [4:10] == "listex":
1478 if data [11:].isdigit ():
1479 id = int (data [11:])
1480 else:
1481 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listex <" + bl_getlang ("id") + ">"))
1482 return 0
1483
1484 if id >= 0 and bl_list and len (bl_list) - 1 >= id:
1485 item = bl_list [id]
1486
1487 if item [6]:
1488 bl_list [id][6] = 0
1489 vh.SQL ("update `py_bl_list` set `except` = 0 where `list` = '%s'" % bl_repsql (item [0]))
1490
1491 out = bl_getlang ("Item exception now disabled") + ":\r\n"
1492 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1493 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1494 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1495 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1496
1497 if not item [4]:
1498 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1499 else:
1500 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1501
1502 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1503 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1504 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % bl_getlang ("No")
1505
1506 bl_reply (user, out)
1507 else:
1508 bl_list [id][6] = 1
1509 vh.SQL ("update `py_bl_list` set `except` = 1 where `list` = '%s'" % bl_repsql (item [0]))
1510
1511 out = bl_getlang ("Item exception now enabled") + ":\r\n"
1512 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1513 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1514 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1515 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1516
1517 if not item [4]:
1518 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (item [7] + (item [3] * 60)))))
1519 else:
1520 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else bl_getlang ("%s minute") % item [3] if item [3] == 1 else bl_getlang ("%s minutes") % item [3])
1521
1522 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % (bl_getlang ("No") if not item [4] else bl_getlang ("Yes"))
1523 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1524 out += ("\r\n [*] " + bl_getlang ("Except: %s") + "\r\n") % bl_getlang ("Yes")
1525
1526 bl_reply (user, out)
1527 else:
1528 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1529
1530 return 0
1531
1532 if data [4:11] == "listget":
1533 if data [12:].isdigit ():
1534 id = int (data [12:])
1535 else:
1536 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("listget <" + bl_getlang ("id") + ">"))
1537 return 0
1538
1539 if id >= 0 and bl_list and len (bl_list) - 1 >= id:
1540 item = bl_list [id]
1541
1542 if not item [4]:
1543 if item [3]:
1544 bl_list [id][7] = time.time ()
1545
1546 out = bl_getlang ("Item load result") + ":\r\n"
1547 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1548 out += ("\r\n [*] " + bl_getlang ("List: %s")) % item [0]
1549 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1550 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1551 out += ("\r\n [*] " + bl_getlang ("Update: %s")) % (bl_getlang ("On load") if not item [3] else (bl_getlang ("%s minute") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (item [3] * 60)))) if item [3] == 1 else (bl_getlang ("%s minutes") + " | %s") % (item [3], time.strftime ("%d/%m %H:%M", time.localtime (time.time () + (item [3] * 60)))))
1552 out += ("\r\n [*] " + bl_getlang ("Disabled: %s")) % bl_getlang ("No")
1553 out += ("\r\n [*] " + bl_getlang ("Action: %s")) % (bl_getlang ("Block") if item [5] else bl_getlang ("Notify"))
1554 out += ("\r\n [*] " + bl_getlang ("Except: %s")) % (bl_getlang ("No") if not item [6] else bl_getlang ("Yes"))
1555 out += ("\r\n [*] " + bl_getlang ("Status: %s") + "\r\n") % bl_import (item [0], item [1], item [2], item [5], item [6])
1556
1557 bl_reply (user, out)
1558 else:
1559 bl_reply (user, bl_getlang ("Item is disabled: %s") % str (id))
1560 else:
1561 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1562
1563 return 0
1564
1565 if data [4:9] == "myall":
1566 if not bl_myli:
1567 out = bl_getlang ("My list is empty.")
1568 else:
1569 out = bl_getlang ("My list") + ":\r\n"
1570
1571 for id, item in enumerate (bl_myli):
1572 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1573 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1574 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % bl_inttoaddr (item [0])
1575 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s")) % bl_inttoaddr (item [1])
1576 out += ("\r\n [*] " + bl_getlang ("Action: %s") + "\r\n") % (bl_getlang ("Block") if bl_conf ["action_mylist"][0] else bl_getlang ("Notify"))
1577
1578 bl_reply (user, out)
1579 return 0
1580
1581 if data [4:9] == "myadd":
1582 pars = re.findall ("^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})[\\- ]*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})?[ ]*(.*)$", data [10:])
1583
1584 if not pars or not pars [0][0]:
1585 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("myadd <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "] [" + bl_getlang ("title") + "]"))
1586 return 0
1587
1588 if not bl_validaddr (pars [0][0]):
1589 bl_reply (user, bl_getlang ("Lower IP not valid: %s") % pars [0][0])
1590 return 0
1591
1592 if pars [0][1] and not bl_validaddr (pars [0][1]):
1593 bl_reply (user, bl_getlang ("Higher IP not valid: %s") % pars [0][1])
1594 return 0
1595
1596 for id, item in enumerate (bl_myli):
1597 if item [0] == bl_addrtoint (pars [0][0]) and item [1] == bl_addrtoint (pars [0][1] or pars [0][0]):
1598 out = bl_getlang ("Item already in list") + ":\r\n"
1599 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1600 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1601 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % pars [0][0]
1602 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s")) % (pars [0][1] or pars [0][0])
1603 out += ("\r\n [*] " + bl_getlang ("Action: %s") + "\r\n") % (bl_getlang ("Block") if bl_conf ["action_mylist"][0] else bl_getlang ("Notify"))
1604 bl_reply (user, out)
1605 return 0
1606
1607 loaddr = bl_addrtoint (pars [0][0])
1608 hiaddr = bl_addrtoint (pars [0][1] or pars [0][0])
1609 bl_myli.append ([loaddr, hiaddr, pars [0][2] or bl_getlang ("My item")])
1610 vh.SQL ("insert ignore into `py_bl_myli` (`loaddr`, `hiaddr`, `title`) values (%s, %s, %s)" % (str (loaddr), str (hiaddr), ("'" + bl_repsql (pars [0][2]) + "'" if pars [0][2] else "null")))
1611
1612 out = bl_getlang ("Item added to list") + ":\r\n"
1613 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (len (bl_myli) - 1)
1614 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % (pars [0][2] or bl_getlang ("My item"))
1615 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % pars [0][0]
1616 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s")) % (pars [0][1] or pars [0][0])
1617 out += ("\r\n [*] " + bl_getlang ("Action: %s") + "\r\n") % (bl_getlang ("Block") if bl_conf ["action_mylist"][0] else bl_getlang ("Notify"))
1618 bl_reply (user, out)
1619 return 0
1620
1621 if data [4:9] == "mydel":
1622 if data [10:].isdigit ():
1623 id = int (data [10:])
1624 else:
1625 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("mydel <" + bl_getlang ("id") + ">"))
1626 return 0
1627
1628 if id >= 0 and bl_myli and len (bl_myli) - 1 >= id:
1629 item, stop = bl_myli.pop (id), False
1630 vh.SQL ("delete from `py_bl_myli` where `loaddr` = %s and `hiaddr` = %s" % (str (item [0]), str (item [1])))
1631
1632 out = bl_getlang ("Item deleted from list") + ":\r\n"
1633 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1634 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1635 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % bl_inttoaddr (item [0])
1636 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s")) % bl_inttoaddr (item [1])
1637 out += ("\r\n [*] " + bl_getlang ("Action: %s") + "\r\n") % (bl_getlang ("Block") if bl_conf ["action_mylist"][0] else bl_getlang ("Notify"))
1638 bl_reply (user, out)
1639 else:
1640 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1641
1642 return 0
1643
1644 if data [4:9] == "exall":
1645 if not bl_exli:
1646 out = bl_getlang ("Exception list is empty.")
1647 else:
1648 out = bl_getlang ("Exception list") + ":\r\n"
1649
1650 for id, item in enumerate (bl_exli):
1651 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1652 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1653 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % bl_inttoaddr (item [0])
1654 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s") + "\r\n") % bl_inttoaddr (item [1])
1655
1656 bl_reply (user, out)
1657 return 0
1658
1659 if data [4:9] == "exadd":
1660 pars = re.findall ("^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})[\\- ]*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})?[ ]*(.*)$", data [10:])
1661
1662 if not pars or not pars [0][0]:
1663 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("exadd <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "] [" + bl_getlang ("title") + "]"))
1664 return 0
1665
1666 if not bl_validaddr (pars [0][0]):
1667 bl_reply (user, bl_getlang ("Lower IP not valid: %s") % pars [0][0])
1668 return 0
1669
1670 if pars [0][1] and not bl_validaddr (pars [0][1]):
1671 bl_reply (user, bl_getlang ("Higher IP not valid: %s") % pars [0][1])
1672 return 0
1673
1674 for id, item in enumerate (bl_exli):
1675 if item [0] == bl_addrtoint (pars [0][0]) and item [1] == bl_addrtoint (pars [0][1] or pars [0][0]):
1676 out = bl_getlang ("Item already in list") + ":\r\n"
1677 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1678 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1679 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % pars [0][0]
1680 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s") + "\r\n") % (pars [0][1] or pars [0][0])
1681 bl_reply (user, out)
1682 return 0
1683
1684 loaddr = bl_addrtoint (pars [0][0])
1685 hiaddr = bl_addrtoint (pars [0][1] or pars [0][0])
1686 bl_exli.append ([loaddr, hiaddr, pars [0][2] or bl_getlang ("Exception")])
1687 vh.SQL ("insert ignore into `py_bl_exli` (`loaddr`, `hiaddr`, `title`) values (%s, %s, %s)" % (str (loaddr), str (hiaddr), ("'" + bl_repsql (pars [0][2]) + "'" if pars [0][2] else "null")))
1688
1689 out = bl_getlang ("Item added to list") + ":\r\n"
1690 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (len (bl_exli) - 1)
1691 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % (pars [0][2] or bl_getlang ("Exception"))
1692 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % pars [0][0]
1693 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s") + "\r\n") % (pars [0][1] or pars [0][0])
1694 bl_reply (user, out)
1695 return 0
1696
1697 if data [4:9] == "exdel":
1698 if data [10:].isdigit ():
1699 id = int (data [10:])
1700 else:
1701 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("exdel <" + bl_getlang ("id") + ">"))
1702 return 0
1703
1704 if id >= 0 and bl_exli and len (bl_exli) - 1 >= id:
1705 item, stop = bl_exli.pop (id), False
1706 vh.SQL ("delete from `py_bl_exli` where `loaddr` = %s and `hiaddr` = %s" % (str (item [0]), str (item [1])))
1707
1708 for pos in range (len (bl_prox)):
1709 for pid, prox in enumerate (bl_prox [pos]):
1710 intaddr = bl_addrtoint (prox [0])
1711
1712 if intaddr >= item [0] and intaddr <= item [1]:
1713 bl_item [intaddr >> 24].append ([intaddr, intaddr, bl_getlang ("Public proxy"), bl_conf ["action_proxy"][0]]) # todo: also add to mysql table when we have one
1714 bl_prox [pos].pop (pid)
1715 stop = True
1716 break
1717
1718 if stop:
1719 break
1720
1721 out = bl_getlang ("Item deleted from list") + ":\r\n"
1722 out += ("\r\n [*] " + bl_getlang ("ID: %s")) % str (id)
1723 out += ("\r\n [*] " + bl_getlang ("Title: %s")) % item [2]
1724 out += ("\r\n [*] " + bl_getlang ("Lower IP: %s")) % bl_inttoaddr (item [0])
1725 out += ("\r\n [*] " + bl_getlang ("Higher IP: %s") + "\r\n") % bl_inttoaddr (item [1])
1726 bl_reply (user, out)
1727 else:
1728 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1729
1730 return 0
1731
1732 if data [4:9] == "extry":
1733 if not data [10:] or not bl_validaddr (data [10:]):
1734 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("extry <" + bl_getlang ("addr") + ">"))
1735 return 0
1736
1737 out, size = "", 0
1738 intaddr = bl_addrtoint (data [10:])
1739
1740 for item in bl_exli:
1741 if intaddr >= item [0] and intaddr <= item [1]:
1742 out += " %s - %s : %s\r\n" % (bl_inttoaddr (item [0]), bl_inttoaddr (item [1]), item [2])
1743 size += 1
1744
1745 if size >= bl_conf ["find_maxres"][0]:
1746 break
1747
1748 if size:
1749 bl_reply (user, (bl_getlang ("Results for IP: %s") + "\r\n\r\n%s") % (data [10:], out))
1750 else:
1751 bl_reply (user, bl_getlang ("No results for IP: %s") % data [10:])
1752
1753 return 0
1754
1755 if data [4:8] == "conf":
1756 out = bl_getlang ("Configuration list") + ":\r\n"
1757
1758 for name, item in sorted (bl_conf.iteritems ()):
1759 out += ("\r\n [*] " + bl_getlang ("Name: %s")) % name
1760 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % item [1]
1761 out += ("\r\n [*] " + bl_getlang ("Range: %s - %s")) % (item [2], item [3])
1762 out += ("\r\n [*] " + bl_getlang ("Value: %s")) % item [0]
1763 out += ("\r\n [*] " + bl_getlang ("Explanation: %s") + "\r\n") % bl_getlang (item [4])
1764
1765 bl_reply (user, out)
1766 return 0
1767
1768 if data [4:7] == "set":
1769 pars = re.findall ("^(\\S+)[ ]*(.*)$", data [8:])
1770
1771 if pars and pars [0][0]:
1772 out = bl_getlang ("Item configuration") + ":\r\n"
1773 out += ("\r\n [*] " + bl_getlang ("Name: %s")) % pars [0][0]
1774 out += ("\r\n [*] " + bl_getlang ("Type: %s")) % (bl_conf [pars [0][0]][1] if pars [0][0] in bl_conf else bl_getlang ("None"))
1775 out += ("\r\n [*] " + bl_getlang ("Range: %s - %s")) % ((bl_conf [pars [0][0]][2] if pars [0][0] in bl_conf else 0), (bl_conf [pars [0][0]][3] if pars [0][0] in bl_conf else 0))
1776 out += ("\r\n [*] " + bl_getlang ("Old value: %s")) % (bl_getlang ("None") if bl_getconf (pars [0][0]) == None else bl_getconf (pars [0][0]))
1777 out += ("\r\n [*] " + bl_getlang ("New value: %s")) % pars [0][1]
1778 out += ("\r\n [*] " + bl_getlang ("Status: %s")) % bl_setconf (pars [0][0], pars [0][1])
1779 out += ("\r\n [*] " + bl_getlang ("Explanation: %s") + "\r\n") % (bl_getlang (bl_conf [pars [0][0]][4]) if pars [0][0] in bl_conf else bl_getlang ("Item not found"))
1780 else:
1781 out = bl_getlang ("Missing command parameters: %s") % ("set <" + bl_getlang ("item") + "> [" + bl_getlang ("value") + "]")
1782
1783 bl_reply (user, out)
1784 return 0
1785
1786 if data [4:8] == "lang":
1787 out = bl_getlang ("Translation list") + ":\r\n\r\n"
1788
1789 for id, lang in sorted (bl_lang.iteritems ()):
1790 out += (" %s. %s = %s\r\n") % (str (id), lang [0], lang [1])
1791
1792 bl_reply (user, out)
1793 return 0
1794
1795 if data [4:8] == "tran":
1796 pars = re.findall ("^(\\S+)[ ]*(.*)$", data [9:])
1797
1798 if not pars or not pars [0][0] or not pars [0][1]:
1799 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("tran <" + bl_getlang ("id") + "> <" + bl_getlang ("value") + ">"))
1800 return 0
1801
1802 if pars [0][0].isdigit ():
1803 id = int (pars [0][0])
1804 else:
1805 bl_reply (user, bl_getlang ("Missing command parameters: %s") % ("tran <" + bl_getlang ("id") + "> <" + bl_getlang ("value") + ">"))
1806 return 0
1807
1808 if id >= 0 and len (bl_lang) - 1 >= id:
1809 if pars [0][1].count ("%s") == bl_lang [id][1].count ("%s"):
1810 vh.SQL ("update `py_bl_lang` set `value` = '%s' where `id` = %s" % (bl_repsql (pars [0][1]), str (id)))
1811 old, bl_lang [id][1] = bl_lang [id][1], pars [0][1]
1812
1813 out = (bl_getlang ("Updated translation with ID: %s") + "\r\n") % str (id)
1814 out += ("\r\n [*] " + bl_getlang ("Old value: %s")) % old
1815 out += ("\r\n [*] " + bl_getlang ("New value: %s") + "\r\n") % pars [0][1]
1816 bl_reply (user, out)
1817 else:
1818 out = (bl_getlang ("Parameter count mismatch in translation with ID: %s") + "\r\n") % str (id)
1819 out += ("\r\n [*] " + bl_getlang ("Old value: %s")) % bl_lang [id][1]
1820 out += ("\r\n [*] " + bl_getlang ("New value: %s") + "\r\n") % pars [0][1]
1821 bl_reply (user, out)
1822 else:
1823 bl_reply (user, bl_getlang ("List out of item with ID: %s") % str (id))
1824
1825 return 0
1826
1827 out = bl_getlang ("Blacklist usage") + ":\r\n\r\n"
1828
1829 out += " stat\t\t\t\t\t- " + bl_getlang ("Script statistics") + "\r\n"
1830 out += " prox\t\t\t\t\t- " + bl_getlang ("Show waiting proxy lookups") + "\r\n\r\n"
1831
1832 out += " feedall\t\t\t\t\t- " + bl_getlang ("Show waiting feed list") + "\r\n"
1833 out += " feeddel [" + bl_getlang ("addr") + "]\t\t\t\t- " + bl_getlang ("Delete from waiting feed list") + "\r\n\r\n"
1834
1835 out += " find <" + bl_getlang ("item") + ">\t\t\t\t- " + bl_getlang ("Search in loaded lists") + "\r\n"
1836 out += " del <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "]\t\t\t- " + bl_getlang ("Delete blacklisted item") + "\r\n\r\n"
1837
1838 out += " look <" + bl_getlang ("addr") + ">\t\t\t\t- " + bl_getlang ("Public proxy lookup") + "\r\n\r\n"
1839
1840 out += " listall\t\t\t\t\t- " + bl_getlang ("Show all lists") + "\r\n"
1841 out += " listadd <" + bl_getlang ("list") + "> <" + bl_getlang ("type") + "> <\"" + bl_getlang ("title") + "\"> [" + bl_getlang ("update") + "]\t- " + bl_getlang ("Load new list") + "\r\n"
1842 out += " listoff <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Disable or enable list") + "\r\n"
1843 out += " listact <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Set list block action") + "\r\n"
1844 out += " listex <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Set list exception usage") + "\r\n"
1845 out += " listget <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Force load of existing list") + "\r\n"
1846 out += " listdel <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Delete existing list") + "\r\n"
1847 out += " listre\t\t\t\t\t- " + bl_getlang ("Reload all lists") + "\r\n\r\n"
1848
1849 out += " myall\t\t\t\t\t- " + bl_getlang ("Show my list") + "\r\n"
1850 out += " myadd <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "] [" + bl_getlang ("title") + "]\t\t- " + bl_getlang ("New my item") + "\r\n"
1851 out += " mydel <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Delete my item") + "\r\n\r\n"
1852
1853 out += " exall\t\t\t\t\t- " + bl_getlang ("Show exception list") + "\r\n"
1854 out += " exadd <" + bl_getlang ("addr") + ">-[" + bl_getlang ("range") + "] [" + bl_getlang ("title") + "]\t\t\t- " + bl_getlang ("New exception item") + "\r\n"
1855 out += " exdel <" + bl_getlang ("id") + ">\t\t\t\t- " + bl_getlang ("Delete an exception") + "\r\n"
1856 out += " extry <" + bl_getlang ("addr") + ">\t\t\t\t- " + bl_getlang ("Search in exceptions") + "\r\n\r\n"
1857
1858 out += " conf\t\t\t\t\t- " + bl_getlang ("Show current configuration") + "\r\n"
1859 out += " set <" + bl_getlang ("item") + "> [" + bl_getlang ("value") + "]\t\t\t\t- " + bl_getlang ("Set configuration item") + "\r\n\r\n"
1860
1861 out += " lang\t\t\t\t\t- " + bl_getlang ("Show current translation") + "\r\n"
1862 out += " tran <" + bl_getlang ("id") + "> <" + bl_getlang ("value") + ">\t\t\t\t- " + bl_getlang ("Set translation string") + "\r\n"
1863
1864 bl_reply (user, out)
1865 return 0
1866
1867 return 1
1868
1869def OnTimer (msec):
1870 global bl_defs, bl_conf, bl_stat, bl_list, bl_item, bl_prox, bl_feed
1871 now = time.time ()
1872
1873 if now - bl_stat ["update"] >= bl_defs ["timersec"]:
1874 bl_stat ["update"], mins = now, (bl_conf ["time_feed"][0] * 60)
1875 bl_feed = [item for item in bl_feed if now - item [1] < mins]
1876
1877 for id, item in enumerate (bl_list):
1878 if not item [4] and item [3] and now - item [7] >= item [3] * 60:
1879 bl_list [id][7], out = now, bl_import (item [0], item [1], item [2], item [5], item [6], True)
1880
1881 if bl_conf ["notify_update"][0]:
1882 bl_notify ("%s: %s" % (item [2], out))
1883
1884 if bl_conf ["prox_lookup"][0] and now - bl_stat ["proxy"] >= bl_conf ["prox_timer"][0]:
1885 bl_stat ["proxy"], start, dels = now, 0, []
1886
1887 for pos in range (len (bl_prox)):
1888 for id, item in enumerate (bl_prox [pos]):
1889 if not item [2]:
1890 if start < bl_conf ["prox_maxreq"][0]:
1891 start += 1
1892
1893 try:
1894 os.system (bl_defs ["curlreq"].decode ("hex") % (str (1), str (1), str (bl_conf ["time_down"][0]), str (bl_conf ["time_down"][0] * 2), bl_useragent (True), "", os.path.join (bl_defs ["datadir"], item [0]), (bl_defs ["ipintel"].decode ("hex") % (bl_conf ["prox_email"][0], item [0])))) # bl_defs ["referer"].decode ("hex")
1895 bl_prox [pos][id][2], bl_prox [pos][id][3] = 1, now
1896 except:
1897 bl_notify (bl_getlang ("Failed proxy detection for %s.%s: %s") % (item [0], vh.GetIPCC (item [0]), bl_getlang ("Failed to execute command")))
1898 dels.insert (0, [pos, id])
1899 elif item [2] == 1:
1900 name = os.path.join (bl_defs ["datadir"], item [0])
1901 isfile = os.path.isfile (name)
1902
1903 if isfile:
1904 size = 0
1905
1906 try:
1907 size = os.path.getsize (name)
1908 except:
1909 pass
1910
1911 if size:
1912 file = None
1913
1914 try:
1915 file = open (name, "r")
1916 except:
1917 pass
1918
1919 keep = False
1920 code = vh.GetIPCC (item [0])
1921
1922 if file:
1923 data = None
1924
1925 try:
1926 data = file.read ()
1927 except:
1928 pass
1929
1930 file.close ()
1931
1932 if data:
1933 res = bl_lookup (data)
1934
1935 if res [0]:
1936 bl_notify (bl_getlang ("Public proxy detected: %s.%s") % (item [0], code))
1937 intaddr = bl_addrtoint (item [0])
1938 keep = True
1939
1940 if not bl_conf ["action_proxy"][0]:
1941 if bl_waitfeed (item [0]):
1942 bl_notify (bl_getlang ("Notifying blacklisted login from %s with IP %s.%s: %s") % (item [1][0] if len (item [1]) == 1 else ", ".join (item [1]), item [0], code, bl_getlang ("Public proxy")))
1943
1944 # todo: bl_extry if ever required
1945 bl_stat ["notify"] += 1
1946 bl_prox [pos][id][2] = 3
1947 elif bl_excheck (item [0], intaddr, code, bl_getlang ("Public proxy"), bl_conf ["except_proxy"][0], item [1][0] if len (item [1]) == 1 else ", ".join (item [1])):
1948 bl_stat ["except"] += len (item [1])
1949 bl_prox [pos][id][2] = 3
1950 else:
1951 for nick in item [1]:
1952 vh.CloseConnection (nick)
1953
1954 bl_stat ["block"] += len (item [1])
1955 bl_prox [pos][id][2] = 2
1956 bl_item [intaddr >> 24].append ([intaddr, intaddr, bl_getlang ("Public proxy"), bl_conf ["action_proxy"][0]]) # todo: also add to mysql table when we have one
1957 else:
1958 if str (res [1]).isdigit ():
1959 keep = True
1960 bl_prox [pos][id][2] = 3
1961
1962 if (bl_conf ["prox_debug"][0] and int (res [1])) or bl_conf ["prox_debug"][0] > 1:
1963 bl_notify (bl_getlang ("Not enough matches for %s.%s: %s of %s") % (item [0], code, str (res [1]), str (bl_conf ["prox_match"][0])))
1964 elif not bl_conf ["prox_nofail"][0]:
1965 bl_notify (bl_getlang ("Failed proxy detection for %s.%s: %s") % (item [0], code, res [1]))
1966 else:
1967 bl_notify (bl_getlang ("Failed proxy detection for %s.%s: %s") % (item [0], code, bl_getlang ("Failed to read data")))
1968 else:
1969 bl_notify (bl_getlang ("Failed proxy detection for %s.%s: %s") % (item [0], code, bl_getlang ("Failed to open file")))
1970
1971 if keep:
1972 del bl_prox [pos][id][1][:]
1973 bl_prox [pos][id][3] = now
1974 else:
1975 dels.insert (0, [pos, id])
1976
1977 bl_remfile (name)
1978 continue
1979
1980 if now - item [3] >= (bl_conf ["time_down"][0] * 2) + (bl_conf ["prox_timer"][0] * 2):
1981 dels.insert (0, [pos, id])
1982
1983 if isfile:
1984 bl_remfile (name)
1985 elif item [2] == 2:
1986 if now - item [3] >= bl_defs ["delwait"]:
1987 dels.insert (0, [pos, id])
1988 #elif item [2] == 3:
1989 #pass
1990
1991 for item in dels:
1992 bl_prox [item [0]].pop (item [1])
1993
1994bl_main ()
1995
1996# end of file