Beispiel #1
0
from subprocess import Popen, PIPE
from thread import start_new_thread

DEFAULT_CONFIG = {
    'feedbot': {
        'server': 'localhost',
        'port': DEFAULT_PORT,
        'ipv6': 'no',
        'nick': 'feedbot',
        'channel': '#test',
        'update_frequency': 300,
        'version': 'feedbot; https://github.com/micolous/ircbots/',
    }
}

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')
Beispiel #2
0
                    port = None

                if len(a2) == 2:
                    proto = a2[1]
                else:
                    proto = None

            if proto == None and port != None:
                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')
Beispiel #3
0
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)