X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=tools%2Fpostgrey_to_postlicyd.py;fp=tools%2Fpostgrey_to_postlicyd.py;h=0000000000000000000000000000000000000000;hb=ceecb2a293677667d8b099b0b32fd4adcdb22e7d;hp=53a593043d611c455dec661739e5a82903e50290;hpb=fa2d79e03036abdcc73f1be6f32ee2a1afa33d6c;p=apps%2Fpfixtools.git diff --git a/tools/postgrey_to_postlicyd.py b/tools/postgrey_to_postlicyd.py deleted file mode 100644 index 53a5930..0000000 --- a/tools/postgrey_to_postlicyd.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -# Convert the postgrey_whitelist_clients file to a format -# suitable for use with the postlicyd Postfix policy daemon - -# Copyright © 2008 Aymeric Augustin -# Released under the GPL - -import os, re, sys - - -def process(infile, outfile): - - re_domain_name = re.compile(r'[a-z0-9.\-]+\.[a-z]+') - re_ip_address = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') - - outfile.write('# Automatically converted for use by postlicyd\n\n') - - # Store each entry to avoid duplicates - entries = [] - - for line in infile: - # Comments: keep them - if line == '\n' or line[0] == '#': - outfile.write(line) - # IP addresses: keep as is - elif re_ip_address.match(line): - outfile.write(line) - # Regexps: extract final constant part - elif line[0] == '/': - line = line.rstrip(r'$/').replace(r'\.', r'.') - host = re_domain_name.findall(line)[-1] - result = host + '\n' - if result not in entries: - entries.append(result) - outfile.write(result) - # Domain names: prepend a dot if the domain name contains only one dot - elif re_domain_name.match(line): - if line.count('.') < 2: - result = '.' + line - else: - result = line - if result not in entries: - entries.append(result) - outfile.write(result) - # Unrecognized: report on stderr and comment in output - else: - outfile.write('# IGNORED: ' + line) - sys.stderr.write("Couldn't process line: %s" % line) - - -if __name__ == '__main__': - - # Check number of arguments - if len(sys.argv) > 3: - print "Usage: %s [input] [output]" % sys.argv[0] - print "If input/output is omitted or -, stdin/stdout is used." - sys.exit(1) - - # Parse first argument - if len(sys.argv) > 1 and sys.argv[1] != '-': - infile = open(sys.argv[1], 'r') - else: - infile = sys.stdin - - # Parse second argument - if len(sys.argv) > 2 and sys.argv[2] != '-': - if sys.argv[1] == sys.argv[2]: - print "Source file and destination file are identical, aborting" - sys.exit(1) - if os.path.exists(sys.argv[2]): - print "Destination file %s already exists, aborting" % sys.argv[2] - sys.exit(1) - outfile = open(sys.argv[2], 'w') - else: - outfile = sys.stdout - - # Do the processing - process(infile, outfile)