Exemplo n.º 1
0
    if args.bootstrap_from_peer:
        single_shot = True
        peering.bootstrap_from(args.bootstrap_from_peer).addCallbacks(stop_reactor, stop_reactor)

    if args.purge_legacy_addresses:
        single_shot = True
        controllers.purge_legacy_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_reported_addresses:
        single_shot = True
        controllers.purge_reported_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_ip is not None:
        single_shot = True
        controllers.purge_ip(args.purge_ip).addCallbacks(stop_reactor, stop_reactor)

    if not single_shot:
        signal.signal(signal.SIGHUP, sighup_handler)
        reactor.addSystemEventTrigger("after", "startup", database.check_database_version)
        reactor.addSystemEventTrigger("before", "shutdown", shutdown)

        start_listening()

        # Set up maintenance and legacy sync jobs
        schedule_jobs()

    # Start reactor
    logging.info("Starting denyhosts-server version {}".format(__init__.version))
    reactor.run()
Exemplo n.º 2
0
        single_shot = True
        database.evolve_database().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_legacy_addresses:
        single_shot = True
        controllers.purge_legacy_addresses().addCallbacks(
            stop_reactor, stop_reactor)

    if args.purge_reported_addresses:
        single_shot = True
        controllers.purge_reported_addresses().addCallbacks(
            stop_reactor, stop_reactor)

    if args.purge_ip is not None:
        single_shot = True
        controllers.purge_ip(args.purge_ip).addCallbacks(
            stop_reactor, stop_reactor)

    if not single_shot:
        signal.signal(signal.SIGHUP, sighup_handler)
        reactor.addSystemEventTrigger("after", "startup",
                                      database.check_database_version)
        reactor.addSystemEventTrigger("before", "shutdown", shutdown)

        start_listening()

        # Set up maintenance and legacy sync jobs
        schedule_jobs()

    # Start reactor
    logging.info("Starting denyhosts-server version {}".format(
        __init__.version))
Exemplo n.º 3
0
def run_main():
    global configfile
    global maintenance_job, legacy_sync_job
    global main_xmlrpc_handler

    parser = argparse.ArgumentParser(description="DenyHosts sync server")
    parser.add_argument("-c", "--config", default="/etc/dh_syncserver.conf", help="Configuration file")
    parser.add_argument("--recreate-database", action="store_true", help="Wipe and recreate the database")
    parser.add_argument(
        "--evolve-database", action="store_true", help="Evolve the database to the latest schema version"
    )
    parser.add_argument(
        "--purge-legacy-addresses",
        action="store_true",
        help="Purge all hosts downloaded from the legacy server. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "--purge-reported-addresses",
        action="store_true",
        help="Purge all hosts that have been reported by clients. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "--purge-ip",
        action="store",
        help="Purge ip address from both legacy and reported host lists. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "-f", "--force", action="store_true", help="Do not ask for confirmation, execute action immediately"
    )
    args = parser.parse_args()

    configfile = args.config

    config.read_config(args.config)

    configure_logging()

    Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype, **config.dbparams)
    Registry.register(models.Cracker, models.Report, models.Legacy)

    single_shot = False

    if not args.force and (
        args.recreate_database
        or args.evolve_database
        or args.purge_legacy_addresses
        or args.purge_reported_addresses
        or args.recreate_database
        or args.purge_ip is not None
    ):
        print("WARNING: do not run this method when dh_syncserver is running.")
        reply = raw_input("Are you sure you want to continue (Y/N): ")
        if not reply.upper().startswith("Y"):
            sys.exit()

    if args.recreate_database:
        single_shot = True
        database.clean_database().addCallbacks(stop_reactor, stop_reactor)

    if args.evolve_database:
        single_shot = True
        database.evolve_database().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_legacy_addresses:
        single_shot = True
        controllers.purge_legacy_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_reported_addresses:
        single_shot = True
        controllers.purge_reported_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_ip is not None:
        single_shot = True
        controllers.purge_ip(args.purge_ip).addCallbacks(stop_reactor, stop_reactor)

    if not single_shot:
        signal.signal(signal.SIGHUP, sighup_handler)
        reactor.addSystemEventTrigger("after", "startup", database.check_database_version)

        main_xmlrpc_handler = views.Server()
        if config.enable_debug_methods:
            d = debug_views.DebugServer(main_xmlrpc_handler)
            main_xmlrpc_handler.putSubHandler("debug", d)
        start_listening(config.listen_port)

        # Set up maintenance and legacy sync jobs
        schedule_jobs()

    # Start reactor
    logging.info("Starting dh_syncserver version {}".format(__init__.version))
    reactor.run()