Updates for PEP8.
This commit is contained in:
parent
dfc8e231af
commit
396501a0f4
14
apache.py
14
apache.py
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
"""Script to create a simple mod_access style list for inclusion within Apache."""
|
||||||
|
|
||||||
import blocklist
|
import blocklist
|
||||||
import sys
|
import sys
|
||||||
|
@ -12,13 +13,16 @@ class ApacheBlockList(blocklist.BlockList):
|
||||||
print "\tDeny from %s/32" % address
|
print "\tDeny from %s/32" % address
|
||||||
print "\tAllow from all"
|
print "\tAllow from all"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
blocklist = ApacheBlockList()
|
"""Main program loop."""
|
||||||
|
block_list = ApacheBlockList()
|
||||||
|
|
||||||
blocklist.read("http://server1.example.com/default/blocks.txt")
|
block_list.read("http://server1.example.com/default/blocks.txt")
|
||||||
blocklist.read("http://server2.example.com/default/blocks.txt")
|
block_list.read("http://server2.example.com/default/blocks.txt")
|
||||||
|
|
||||||
blocklist.export()
|
block_list.export()
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
27
sqlite.py
27
sqlite.py
|
@ -1,10 +1,11 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
"""Script to create a SQLite DB from the blocklist data."""
|
||||||
|
|
||||||
import blocklist
|
import blocklist
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
if sys.version_info >= (2,5):
|
if sys.version_info >= (2, 5):
|
||||||
import sqlite3
|
import sqlite3
|
||||||
else:
|
else:
|
||||||
from pysqlite2 import dbapi2 as sqlite3
|
from pysqlite2 import dbapi2 as sqlite3
|
||||||
|
@ -15,27 +16,31 @@ class SQLiteBlockList(blocklist.BlockList):
|
||||||
"""Exports blocklist criteria to a SQLite file."""
|
"""Exports blocklist criteria to a SQLite file."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db = sqlite3.connect(self.config.get("sqlite", "database"))
|
database = sqlite3.connect(self.config.get("sqlite", "database"))
|
||||||
cur = db.cursor()
|
cur = database.cursor()
|
||||||
|
|
||||||
cur.execute("CREATE TABLE IF NOT EXISTS blocklist(remote_ip VARCHAR(15), forwarded_ip VARCHAR(15), useragent VARCHAR(256), cookie VARCHAR(1024), PRIMARY KEY(remote_ip))")
|
cur.execute("CREATE TABLE IF NOT EXISTS blocklist(remote_ip VARCHAR(15), forwarded_ip VARCHAR(15), useragent VARCHAR(256), cookie VARCHAR(1024), PRIMARY KEY(remote_ip))")
|
||||||
|
|
||||||
cur.execute("DELETE FROM blocklist")
|
cur.execute("DELETE FROM blocklist")
|
||||||
|
|
||||||
for key,item in self.data.iteritems():
|
for item in self.data.values():
|
||||||
if item["useragent"] == 'NULL':
|
if item["useragent"] == 'NULL':
|
||||||
item["useragent"] = '(null)'
|
item["useragent"] = '(null)'
|
||||||
cur.execute("INSERT INTO blocklist VALUES ('%s', '%s', '%s', '%s')" % (item["remote_ip"], item["forwarded_ip"], item["useragent"], item["cookie"]))
|
cur.execute("INSERT INTO blocklist VALUES ('%s', '%s', '%s', '%s')" % (item["remote_ip"], item["forwarded_ip"], item["useragent"], item["cookie"]))
|
||||||
db.commit()
|
database.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
except Exception, e:
|
except sqlite3.Error, error:
|
||||||
logging.error("There was a problem exporting the data to SQLite. %s" % e)
|
logging.error("There was a problem exporting the data to SQLite. %s", error)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main():
|
||||||
blocklist = SQLiteBlockList()
|
"""Main program loop."""
|
||||||
|
block_list = SQLiteBlockList()
|
||||||
|
|
||||||
blocklist.read("http://example.com/default/blocks.txt")
|
block_list.read("http://example.com/default/blocks.txt")
|
||||||
|
|
||||||
blocklist.export()
|
block_list.export()
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue