Beispiel #1
0
    def process(self):
        kpconf = Conf()
        new_client_id = kpconf.get_selected_ui().RequireAssociationDecision.require_client_name()
        if new_client_id:
            kpconf.backend.create_config_key(new_client_id, self.request_dict["Key"])
            self.response_dict.update({"Id": new_client_id,
                                       "Success": True})

            self.set_verifier(new_client_id)
def main():
    # avoid: UnboundLocalError: local variable '__doc__' referenced before assignment
    doc_ = __doc__
    kpconf = Conf()

    if has_gui_support():
        doc_ += "  --gui".ljust(28) + "Use QT (PySide) for a graphical interface"

    # handle arguments
    arguments = docopt.docopt(doc_)

    is_daemon = arguments["--daemon"]
    database_path = arguments["<database_path>"]
    host = arguments["--host"]
    port = arguments["--port"]
    assert port.isdigit()
    loglevel = arguments["--loglevel"]

    gui = arguments.get("--gui", False)
    if gui:
        ui = Conf.UI.GUI
    else:
        ui = Conf.UI.CLI

    kpconf.select_ui(ui)
    kpconf.set_loglevel(loglevel)

    if not has_gui_support():
        log.debug("\nIt seems that you don't have GUI support installed. Install it with:\n"
                  "  $ pip install -e '.[GUI]'\n"
                  "or\n"
                  "  $ pip install keepass_http[GUI]\n")

    # backend
    backend = backends.BaseBackend.get_by_filepath(database_path)
    kpconf.set_backend(backend)

    success = kpconf.get_selected_ui().RequireDatabasePassphraseUi.do(MAX_TRY_COUNT)
    if success is False:
        sys.exit("Wrong or no passphrase")

    # config daemon
    run_server = partial(app.run, debug=False, host=host, port=int(port))
    if is_daemon:
        pid_file = os.path.join(kpconf.confdir, "process.pid")
        log.info("Server started as daemon on %s:%s" % (host, port))
        daemon = daemonize.Daemonize(app=APP_NAME,
                                     pid=pid_file,
                                     action=run_server,
                                     keep_fds=get_logging_filehandlers_streams_to_keep())
        daemon.start()

    else:
        log.info("Server started on %s:%s" % (host, port))
        run_server()
def main():
    # avoid: UnboundLocalError: local variable '__doc__' referenced before assignment
    doc_ = __doc__
    kpconf = Conf()

    if has_gui_support():
        doc_ += "  --gui                     Use TKinter for a graphical interface"

    # handle arguments
    arguments = docopt.docopt(doc_)

    is_daemon = arguments["--daemon"]
    database_path = arguments["<database_path>"]
    host = arguments["--host"]
    port = arguments["--port"]
    assert port.isdigit()
    loglevel = arguments["--loglevel"]

    gui = arguments.get("--gui", False)
    if gui:
        ui = Conf.UI.GUI
    else:
        ui = Conf.UI.CLI

    kpconf.select_ui(ui)
    kpconf.set_loglevel(loglevel)

    # backend
    backend = backends.BaseBackend.get_by_filepath(database_path)
    kpconf.set_backend(backend)

    success = kpconf.get_selected_ui().OpenDatabase.open(MAX_TRY_COUNT)
    if success is False:
        sys.exit("Wrong passphrase after %d attempts" % MAX_TRY_COUNT)

    # config daemon
    run_server = partial(app.run, debug=False, host=host, port=int(port))
    if is_daemon:
        pid_file = os.path.join(kpconf.confdir, "process.pid")
        log.info("Server started as daemon on %s:%s" % (host, port))
        daemon = daemonize.Daemonize(
            app=APP_NAME,
            pid=pid_file,
            action=run_server,
            keep_fds=get_logging_filehandlers_streams_to_keep())
        daemon.start()

    else:
        log.info("Server started on %s:%s" % (host, port))
        run_server()
def main():
    # avoid: UnboundLocalError: local variable '__doc__' referenced before assignment
    doc_ = __doc__
    kpconf = Conf()

    if has_gui_support():
        doc_ += "  --gui                     Use TKinter for a graphical interface"

    # handle arguments
    arguments = docopt.docopt(doc_)

    is_daemon = arguments["--daemon"]
    database_path = arguments["<database_path>"]
    host = arguments["--host"]
    port = arguments["--port"]
    assert port.isdigit()
    loglevel = arguments["--loglevel"]

    gui = arguments.get("--gui", False)
    if gui:
        ui = Conf.UI.GUI
    else:
        ui = Conf.UI.CLI

    kpconf.select_ui(ui)
    kpconf.set_loglevel(loglevel)

    # backend
    backend = backends.BaseBackend.get_by_filepath(database_path)
    kpconf.set_backend(backend)

    success = kpconf.get_selected_ui().OpenDatabase.open(MAX_TRY_COUNT)
    if success is False:
        sys.exit("Wrong passphrase after %d attempts" % MAX_TRY_COUNT)

    # config daemon
    run_server = partial(app.run, debug=False, host=host, port=int(port))
    if is_daemon:
        pid_file = os.path.join(kpconf.confdir, "process.pid")
        log.info("Server started as daemon on %s:%s" % (host, port))
        daemon = daemonize.Daemonize(app=APP_NAME,
                                     pid=pid_file,
                                     action=run_server,
                                     keep_fds=get_logging_filehandlers_streams_to_keep())
        daemon.start()

    else:
        log.info("Server started on %s:%s" % (host, port))
        run_server()