Beispiel #1
0
    def run(self):
        """Start up the application."""
        args = [sys.argv[0]]
        qt_options = self.options.get('qt_options', '')
        args += map(lambda s: s.strip(), qt_options.split(','))
        app = singleton(Bluepass, args)

        connect = self.options.get('connect')
        if connect:
            addr = util.parse_address(connect)
            sock = util.create_connection(addr, 5)
        else:
            bectrl = self.backend_controller = QtBackendController(self.options)
            bectrl.start()
            sock = bectrl.connect()
        if sock is None:
            sys.stderr.write('Error: could not connect to backend\n')
            return 1

        handler = singleton(QtMessageBusHandler)
        connection = singleton(QtMessageBusConnection, sock, self.auth_token,
                               handler=handler)
        backend = singleton(BackendProxy, connection)

        return app.exec_()
Beispiel #2
0
    def run(self):
        """Start up the application."""
        args = [sys.argv[0]]
        qt_options = self.options.get('qt_options', '')
        args += map(lambda s: s.strip(), qt_options.split(','))
        app = singleton(Bluepass, args)

        connect = self.options.get('connect')
        if connect:
            addr = util.parse_address(connect)
            sock = util.create_connection(addr, 5)
        else:
            bectrl = self.backend_controller = QtBackendController(
                self.options)
            bectrl.start()
            sock = bectrl.connect()
        if sock is None:
            sys.stderr.write('Error: could not connect to backend\n')
            return 1

        handler = singleton(QtMessageBusHandler)
        connection = singleton(QtMessageBusConnection,
                               sock,
                               self.auth_token,
                               handler=handler)
        backend = singleton(BackendProxy, connection)

        return app.exec_()
Beispiel #3
0
    def run(self):
        """Start up the application."""
        args = [sys.argv[0]]
        qt_options = self.options.qt_options
        args += map(lambda o: '-{0}'.format(o.strip()), qt_options.split(','))
        app = singleton(Bluepass, args)

        addr = gruvi.paddr(self.options.connect)
        ctrlapi = singleton(ControlApiClient)
        ctrlapi.connect(addr)
        ctrlapi.login(self.options.auth_token)

        return app.exec_()
Beispiel #4
0
def frontend():
    """Frontend entry point."""

    # First get the --frontend parameter so that we can its command-line
    # options.

    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('-f', '--frontend', nargs='?')
    opts, _ = parser.parse_known_args()
    frontend = opts.frontend and opts.frontend[0]

    for fe in platform.get_frontends():
        if fe.name == opts.frontend or opts.frontend is None:
            Frontend = fe
            break
    else:
        sys.stderr.write('Error: no such frontend: {}'.format(opts.frontend))
        sys.stderr.write('Use --list-frontends to list available frontends')
        return 1

    # Now build the real parser and parse arguments

    parser = argparse.ArgumentParser()
    parser.add_argument('-r', '--data-dir',
                        help='Use alternate data directory')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='Show debugging information')
    parser.add_argument('--log-stdout', action='store_true',
                        help='Log to standard output [default: backend.log]')
    parser.add_argument('-v', '--version', action='store_true',
                        help='Show version information and exit')
    parser.add_argument('-f', '--frontend',
                        help='Select frontend to use')
    parser.add_argument('--list-frontends', action='store_true',
                        help='List available frontends and exit')

    Frontend.add_args(parser)
    Backend.add_args(parser)

    opts = parser.parse_args()

    setup_logging(opts, '{}-frontend'.format(Frontend.name))

    if opts.version:
        print('Bluepass version {}'.format(_version.verion))
        return 0

    if opts.list_frontends:
        print('Available frontends:')
        for fe in platform.get_frontends():
            print('{:-10}: {}'.format(fe.name, fe.description))
        return 0

    # Create frontend and pass control to it

    frontend = singleton(Frontend, todict(opts))
    ret = frontend.run()

    return ret
Beispiel #5
0
 def exec_(self):
     ctrlapi = instance(ControlApiClient)
     config = ctrlapi.get_config('frontends.qt')
     if config is None:
         config = ctrlapi.create_config({'name': 'frontends.qt'})
     self._config = config
     mainwindow = singleton(MainWindow)
     mainwindow.show()
     return super(Bluepass, self).exec_()
Beispiel #6
0
    def run(self):
        """Initialize the backend and run its main loop."""
        self.logger.debug('initializing backend components')

        self.logger.debug('initializing cryto provider')
        crypto = singleton(CryptoProvider)
        pwgen = singleton(PasswordGenerator)

        self.logger.debug('initializing database')
        fname = os.path.join(self.data_dir, 'bluepass.db')
        database = singleton(Database, fname)
        database.lock()

        self.logger.debug('initializing model')
        model = singleton(Model, database)

        self.logger.debug('initializing locator')
        locator = singleton(Locator)
        for ls in platform.get_location_sources():
            self.logger.debug('adding location source: {}'.format(ls.name))
            locator.add_source(ls())

        self.logger.debug('initializing sync API')
        listener = util.create_listener(('0.0.0.0', 0))
        listener.setblocking(False)
        app = singleton(SyncAPIApplication)
        syncapi = singleton(SyncAPIServer, listener, app)
        syncapi.start()

        self.logger.debug('initializing sync API publisher')
        publisher = singleton(SyncAPIPublisher, syncapi)
        publisher.start()

        # The syncer is started at +10 seconds so that the locator will have
        # hopefully located all neighbors by then and we can do a once-off
        # sync at startup. This is just a heuristic for optimization, the
        # correctness of our sync algorithm does not depend on this.
        if locator.sources:
            self.logger.debug('initializing background sync worker')
            syncer = singleton(Syncer)
            syncer.start_later(10)
        else:
            self.logger.warning('no location sources available')
            self.logger.warning('network synchronization is disabled')

        self.logger.debug('initializing control API')
        listener = util.create_listener(self.listen_address)
        listener.setblocking(False)
        fname = os.path.join(self.data_dir, 'backend.addr')
        addr = util.unparse_address(listener.getsockname())
        with open(fname, 'w') as fout:
            fout.write('{}\n'.format(addr))
        self.logger.info('listening on: {}'.format(addr))
        handler = SocketAPIHandler()
        messagebus = singleton(MessageBusServer, listener, self.auth_token,
                               handler)
        if self.options.get('trace'):
            fname = os.path.join(self.data_dir, 'backend.trace')
            messagebus.set_trace(fname)
        if not self.options.get('daemon'):
            def messagebus_event(event, *args):
                if event == 'LastConnectionClosed':
                    self.stop()
            messagebus.add_callback(messagebus_event)
        messagebus.start()

        self.logger.debug('installing signal handlers')
        on_signal = get_hub().loop.signal(signal.SIGTERM)
        on_signal.start(self.stop)

        monkey.patch_time() # Make Thread.join() cooperative.

        self.logger.debug('all backend components succesfully initialized')

        # This is where the backend runs (until stopped).
        self._stop_event.wait()

        self.logger.debug('backend event loop terminated')

        self.logger.debug('shutting down control API')
        messagebus.stop()

        self.logger.debug('shutting down database')
        database.close()

        self.logger.debug('stopped all backend components')
Beispiel #7
0
 def exec_(self):
     mainwindow = singleton(MainWindow)
     mainwindow.show()
     return super(Bluepass, self).exec_()
Beispiel #8
0
def frontend():
    """Frontend entry point."""

    # First get the --frontend parameter so that we can its command-line
    # options.

    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('-f', '--frontend', nargs='?')
    opts, _ = parser.parse_known_args()
    frontend = opts.frontend and opts.frontend[0]

    for fe in platform.get_frontends():
        if fe.name == opts.frontend or opts.frontend is None:
            Frontend = fe
            break
    else:
        sys.stderr.write('Error: no such frontend: {}'.format(opts.frontend))
        sys.stderr.write('Use --list-frontends to list available frontends')
        return 1

    # Now build the real parser and parse arguments

    parser = argparse.ArgumentParser()
    parser.add_argument('-r',
                        '--data-dir',
                        help='Use alternate data directory')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='Show debugging information')
    parser.add_argument('--log-stdout',
                        action='store_true',
                        help='Log to standard output [default: backend.log]')
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        help='Show version information and exit')
    parser.add_argument('-f', '--frontend', help='Select frontend to use')
    parser.add_argument('--list-frontends',
                        action='store_true',
                        help='List available frontends and exit')

    Frontend.add_args(parser)
    Backend.add_args(parser)

    opts = parser.parse_args()

    setup_logging(opts, '{}-frontend'.format(Frontend.name))

    if opts.version:
        print('Bluepass version {}'.format(_version.verion))
        return 0

    if opts.list_frontends:
        print('Available frontends:')
        for fe in platform.get_frontends():
            print('{:-10}: {}'.format(fe.name, fe.description))
        return 0

    # Create frontend and pass control to it

    frontend = singleton(Frontend, todict(opts))
    ret = frontend.run()

    return ret