def main(daemon_enable, pid_file, settings_file=SETTINGS_FILE): # begin! config = ConfigParserPlus(DEFAULT_SETTINGS) print "Loading configuration: %s" % settings_file if not config.read(settings_file): print "Failure reading configuration file!" exit(1) print "Setting configuration values..." iptables.IPTABLES = config.get('tollgate', 'iptables') iptables.INTERN_IFACE = config.get('tollgate', 'internal_iface') iptables.EXTERN_IFACE = config.get('tollgate', 'external_iface') iptables.CAPTIVE_RULE = config.get('tollgate', 'captive_rule') iptables.ALLOWED_RULE = config.get('tollgate', 'allowed_rule') iptables.UNMETERED_RULE = config.get('tollgate', 'unmetered_rule') iptables.BLACKLIST_RULE = config.get('tollgate', 'blacklist_rule') iptables.IP4PF_RULE = config.get('tollgate', 'ip4pf_rule') iptables.USER_RULE_PREFIX = config.get('tollgate', 'user_rule_prefix') iptables.LIMIT_RULE_PREFIX = config.get('tollgate', 'limit_rule_prefix') iptables.REJECT_MODE = config.get('tollgate', 'reject_mode') iptables.REJECT_TCP_RESET = config.getboolean('tollgate', 'reject_reset_tcp') iptables.DEBUG = config.getboolean('tollgate', 'debug') iptables.CAPTIVE_ENABLED = config.getboolean('captive', 'enable') iptables.CAPTIVE_PORT = config.getint('captive', 'port') if config.has_option('tollgate', 'arp_table_size'): iptables.GC_THRESH = config.getint('tollgate', 'arp_table_size') if iptables.USER_RULE_PREFIX == iptables.LIMIT_RULE_PREFIX: raise Exception, "user rule prefix must be different to the limit rule prefix" # get unmetered firewall rules unmetered_hosts = None if config.has_section('unmetered'): unmetered_hosts = config.items('unmetered') # get blacklist blacklist_hosts = None if config.has_section('blacklist'): blacklist_hosts = config.items('blacklist') print "Creating DBUS API..." b = iptables.setup_dbus() print "Creating NAT..." iptables.create_nat() if unmetered_hosts != None: print "Setting unmetered hosts..." parse_hostlist(unmetered_hosts, iptables.add_unmetered) if blacklist_hosts != None: print "Setting blacklist hosts..." parse_hostlist(blacklist_hosts, iptables.add_blacklist) print "Starting DBUS Server (only debug messages will appear now)" try: iptables.boot_dbus(daemon_enable, b, pid_file) except KeyboardInterrupt: print "Got Control-C!" exit(0)
config = ConfigParserPlus(DEFAULT_CONFIG) try: config.readfp(open(argv[1])) except: try: config.readfp(open('twitterbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `twitterbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) SERVER = config.get('twitterbot', 'server') PORT = config.getint('twitterbot', 'port') IPV6 = config.getboolean('twitterbot', 'ipv6') NICK = config.get('twitterbot', 'nick') CHANNEL = config.get('twitterbot', 'channel') VERSION = config.get('twitterbot', 'version') + '; %s' try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE FLOOD_COOLDOWN = timedelta(seconds=config.getint('twitterbot', 'flood_cooldown')) try: NICKSERV_PASS = config.get('twitterbot', 'nickserv_pass') except: NICKSERV_PASS = None tweetURLRegex = re.compile(r"(http(s?):\/\/twitter.com\/.*\/statuse?s?\/([0-9]{0,20}))") message_buffer = []
action(host, 'udp', port) else: action(host, proto, port) # begin! config = ConfigParserPlus(DEFAULT_SETTINGS) if len(argv) >= 2: SETTINGS_FILE = argv[1] print "Loading configuration: %s" % SETTINGS_FILE config.read(SETTINGS_FILE) print "Setting configuration values..." iptables.IPTABLES = config.get('tollgate', 'iptables') iptables.INTERN_IFACE = config.get('tollgate', 'internal_iface') iptables.EXTERN_IFACE = config.get('tollgate', 'external_iface') iptables.CAPTIVE_RULE = config.get('tollgate', 'captive_rule') iptables.ALLOWED_RULE = config.get('tollgate', 'allowed_rule') iptables.UNMETERED_RULE = config.get('tollgate', 'unmetered_rule') iptables.BLACKLIST_RULE = config.get('tollgate', 'blacklist_rule') iptables.IP4PF_RULE = config.get('tollgate', 'ip4pf_rule') iptables.USER_RULE_PREFIX = config.get('tollgate', 'user_rule_prefix') iptables.LIMIT_RULE_PREFIX = config.get('tollgate', 'limit_rule_prefix') iptables.REJECT_MODE = config.get('tollgate', 'reject_mode') iptables.REJECT_TCP_RESET = config.getboolean('tollgate', 'reject_reset_tcp') iptables.DEBUG = config.getboolean('tollgate', 'debug') iptables.CAPTIVE_ENABLED = config.getboolean('captive', 'enable') iptables.CAPTIVE_PORT = config.getint('captive', 'port')
config = ConfigParserPlus(DEFAULT_SETTINGS) try: config.readfp(open(argv[1])) except: try: config.readfp(open('cbusbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `cbusbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) # get version information from git try: VERSION = config.get('cbusbot', 'version') + '; %s' except: VERSION = 'cbusbot; https://github.com/micolous/cbus/; %s' try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE ON = [ 'on', 'y', '1', 'enable', ] OFF = [ 'off', 'n',
config = ConfigParserPlus(DEFAULT_CONFIG) try: config.readfp(open(argv[1])) except: try: config.readfp(open('feedbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `feedbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) # read config SERVER = config.get('feedbot', 'server') PORT = config.getint('feedbot', 'port') IPV6 = config.getboolean('feedbot', 'ipv6') NICK = config.get('feedbot', 'nick') CHANNEL = config.get('feedbot', 'channel') VERSION = config.get('feedbot', 'version') + '; %s' try: VERSION = VERSION % Popen(["git", "branch", "-v", "--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE NICKSERV_PASS = config.get('feedbot', 'nickserv_pass') UPDATE_FREQUENCY = config.getint('feedbot', 'update_frequency')
config = ConfigParserPlus(DEFAULT_CONFIG) try: config.readfp(open(argv[1])) except: try: config.readfp(open('ethicsbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `ethicsbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) # read config SERVER = config.get('ethicsbot', 'server') PORT = config.getint('ethicsbot', 'port') IPV6 = config.getboolean('ethicsbot', 'ipv6') NICK = config.get('ethicsbot', 'nick') CHANNEL = config.get('ethicsbot', 'channel') VERSION = config.get('ethicsbot', 'version') + '; %s' try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE FLOOD_COOLDOWN = timedelta(seconds=config.getint('ethicsbot', 'flood_cooldown')) try: NICKSERV_PASS = config.get('ethicsbot', 'nickserv_pass') except: NICKSERV_PASS = None message_buffer = []
def main(daemon_enable, pid_file, settings_file=SETTINGS_FILE): # begin! config = ConfigParserPlus(DEFAULT_SETTINGS) print "Loading configuration: %s" % settings_file if not config.read(settings_file): print "Failure reading configuration file!" exit(1) print "Setting configuration values..." iptables.IPTABLES = config.get('tollgate', 'iptables') iptables.INTERN_IFACE = config.get('tollgate', 'internal_iface') iptables.EXTERN_IFACE = config.get('tollgate', 'external_iface') iptables.CAPTIVE_RULE = config.get('tollgate', 'captive_rule') iptables.ALLOWED_RULE = config.get('tollgate', 'allowed_rule') iptables.UNMETERED_RULE = config.get('tollgate', 'unmetered_rule') iptables.BLACKLIST_RULE = config.get('tollgate', 'blacklist_rule') iptables.IP4PF_RULE = config.get('tollgate', 'ip4pf_rule') iptables.USER_RULE_PREFIX = config.get('tollgate', 'user_rule_prefix') iptables.LIMIT_RULE_PREFIX = config.get('tollgate', 'limit_rule_prefix') iptables.REJECT_MODE = config.get('tollgate', 'reject_mode') iptables.REJECT_TCP_RESET = config.getboolean('tollgate', 'reject_reset_tcp') iptables.DEBUG = config.getboolean('tollgate', 'debug') iptables.CAPTIVE_ENABLED = config.getboolean('captive', 'enable') iptables.CAPTIVE_PORT = config.getint('captive', 'port') if config.has_option('tollgate', 'arp_table_size'): iptables.GC_THRESH = config.getint('tollgate', 'arp_table_size') if iptables.USER_RULE_PREFIX == iptables.LIMIT_RULE_PREFIX: raise Exception, "user rule prefix must be different to the limit rule prefix" # get unmetered firewall rules unmetered_hosts = None if config.has_section('unmetered'): unmetered_hosts = config.items('unmetered') # get blacklist blacklist_hosts = None if config.has_section('blacklist'): blacklist_hosts = config.items('blacklist') print "Creating DBUS API..." b = iptables.setup_dbus() print "Creating NAT..." iptables.create_nat() if unmetered_hosts != None: print "Setting unmetered hosts..." parse_hostlist(unmetered_hosts, iptables.add_unmetered) if blacklist_hosts != None: print "Setting blacklist hosts..." parse_hostlist(blacklist_hosts, iptables.add_blacklist) print "Starting DBUS Server (only debug messages will appear now)" try: iptables.boot_dbus(daemon_enable, b, pid_file) except KeyboardInterrupt: print "Got Control-C!" exit(0)
action(host, 'tcp', port) action(host, 'udp', port) else: action(host, proto, port) # begin! config = ConfigParserPlus(DEFAULT_SETTINGS) if len(argv) >= 2: SETTINGS_FILE = argv[1] print "Loading configuration: %s" % SETTINGS_FILE config.read(SETTINGS_FILE) print "Setting configuration values..." iptables.IPTABLES = config.get('tollgate', 'iptables') iptables.INTERN_IFACE = config.get('tollgate', 'internal_iface') iptables.EXTERN_IFACE = config.get('tollgate', 'external_iface') iptables.CAPTIVE_RULE = config.get('tollgate', 'captive_rule') iptables.ALLOWED_RULE = config.get('tollgate', 'allowed_rule') iptables.UNMETERED_RULE = config.get('tollgate', 'unmetered_rule') iptables.BLACKLIST_RULE = config.get('tollgate', 'blacklist_rule') iptables.IP4PF_RULE = config.get('tollgate', 'ip4pf_rule') iptables.USER_RULE_PREFIX = config.get('tollgate', 'user_rule_prefix') iptables.LIMIT_RULE_PREFIX = config.get('tollgate', 'limit_rule_prefix') iptables.REJECT_MODE = config.get('tollgate', 'reject_mode') iptables.REJECT_TCP_RESET = config.getboolean('tollgate', 'reject_reset_tcp') iptables.DEBUG = config.getboolean('tollgate', 'debug') iptables.CAPTIVE_ENABLED = config.getboolean('captive', 'enable') iptables.CAPTIVE_PORT = config.getint('captive', 'port')
config = ConfigParserPlus(DEFAULT_CONFIG) try: config.readfp(open(argv[1])) except: try: config.readfp(open('linkbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `linkbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) # get version information from git try: VERSION = config.get('linkbot', 'version') + '; %s' except: VERSION = 'linkbot; https://github.com/micolous/ircbots/; %s' try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE class Network(object): def __init__(self, config, section): # setup configuration. self.server = config.get(section, 'server') try: self.port = config.getint(section, 'port') except: self.port = DEFAULT_PORT
config = ConfigParserPlus(DEFAULT_CONFIG) try: config.readfp(open(argv[1])) except: try: config.readfp(open('feedbot.ini')) except: print "Syntax:" print " %s [config]" % argv[0] print "" print "If no configuration file is specified or there was an error, it will default to `feedbot.ini'." print "If there was a failure reading the configuration, it will display this message." exit(1) # read config SERVER = config.get('feedbot', 'server') PORT = config.getint('feedbot', 'port') IPV6 = config.getboolean('feedbot', 'ipv6') NICK = config.get('feedbot', 'nick') CHANNEL = config.get('feedbot', 'channel') VERSION = config.get('feedbot', 'version') + '; %s' try: VERSION = VERSION % Popen(["git","branch","-v","--contains"], stdout=PIPE).communicate()[0].strip() except: VERSION = VERSION % 'unknown' del Popen, PIPE NICKSERV_PASS = config.get('feedbot', 'nickserv_pass') UPDATE_FREQUENCY = config.getint('feedbot', 'update_frequency') feed_urls = {} if config.has_section('feeds'): for k,v in config.items('feeds'):