blockinator/varnish.py

29 lines
764 B
Python
Raw Normal View History

2012-05-21 19:08:04 +01:00
#!/usr/bin/python
2013-07-13 08:47:15 +01:00
"""Script to create a ACL file for inclusion within Varnish."""
2012-05-21 19:08:04 +01:00
import blocklist
import sys
class VarnishBlockList(blocklist.BlockList):
"""New class to extend the main BlockList class for implementation with Varnish."""
def export(self):
2013-07-13 08:47:15 +01:00
"""Exports blocklist addresses for use within Varnish."""
print "acl block_list {"
for address in self.data.keys():
print "\t\"%s\";" % address
print "}"
2012-05-21 19:08:04 +01:00
2013-07-13 08:47:15 +01:00
def main():
"""Main program loop."""
block_list = VarnishBlockList()
2012-05-21 19:08:04 +01:00
2013-07-13 08:47:15 +01:00
block_list.read("http://server1.example.com/default/blocks.txt")
block_list.read("http://server2.example.com/default/blocks.txt")
2012-05-21 19:08:04 +01:00
2013-07-13 08:47:15 +01:00
block_list.export()
2012-05-21 19:08:04 +01:00
sys.exit(0)
2013-07-13 08:47:15 +01:00
if __name__ == "__main__":
main()