Example #1
0
    def autostart(self):
        def status_callback():
            pass

        for prfl in profile.Profile.iter_profiles():
            if not prfl.autostart:
                continue

            logger.info(
                'Auto starting profile...',
                'shell',
                profile_id=prfl.id,
                profile_name=prfl.name,
            )

            def connect_callback():
                if prfl.status in ERROR_STATES:
                    logger.error(
                        'Failed to autostart server',
                        'shell',
                        profile_id=prfl.id,
                        profile_name=prfl.name,
                        profile_status=prfl.status,
                    )

            threading.Thread(target=prfl.start_autostart,
                             args=(status_callback, connect_callback)).start()
Example #2
0
    def start_server(self):
        server = BaseHTTPServer.HTTPServer(
            ('127.0.0.1', 9797),
            Request,
        )
        logger.info('Starting pritunl-client daemon...', 'shell')

        self.autostart()

        server.serve_forever()
Example #3
0
    def start_server(self):
        server = ThreadingHTTPServer(
            ('127.0.0.1', 9797),
            Request,
        )
        logger.info('Starting pritunl-client daemon...', 'shell')

        self.autostart()

        server.serve_forever()
    def start_server(self):
        try:
            server = ThreadingHTTPServer(
                ('127.0.0.1', 9797),
                Request,
            )
            logger.info('Starting pritunl-client daemon...', 'shell')

            self.autostart()

            server.serve_forever()
        except socket_error:
            logger.info('Address already in use. Make sure that port 9797 is available.', 'shell')
    def start_server(self):
        try:
            server = ThreadingHTTPServer(
                ('127.0.0.1', 9797),
                Request,
            )
            logger.info('Starting pritunl-client daemon...', 'shell')

            self.autostart()

            server.serve_forever()
        except socket_error:
            logger.info(
                'Address already in use. Make sure that port 9797 is available.',
                'shell')
Example #6
0
    def autostart(self):
        def status_callback():
            pass

        for prfl in profile.Profile.iter_profiles():
            if not prfl.autostart:
                continue

            logger.info('Auto starting profile...', 'shell',
                profile_id=prfl.id,
                profile_name=prfl.name,
            )

            def connect_callback():
                if prfl.status in ERROR_STATES:
                    logger.error('Failed to autostart server', 'shell',
                        profile_id=prfl.id,
                        profile_name=prfl.name,
                        profile_status=prfl.status,
                    )

            threading.Thread(target=prfl.start_autostart,
                args=(status_callback, connect_callback)).start()
Example #7
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200 and response.content:
                self.update_profile(response.content)
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #8
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request(
                    'get',
                    sync_host,
                    '/key/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception(
                        'Failed to sync conf',
                        'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info(
                    'Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning(
                    'Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200 and response.content:
                self.update_profile(response.content)
                return

        if status_code is not None and status_code != 200:
            logger.error(
                'Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #9
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/sync/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200:
                data = response.json()
                if not data.get('signature') or not data.get('conf'):
                    return

                conf_signature = base64.b64encode(hmac.new(
                    self.sync_secret.encode(), data.get('conf'),
                    hashlib.sha512).digest())

                if conf_signature != data.get('signature'):
                    return

                self.update_profile(data.get('conf'))
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )
Example #10
0
    def sync_conf(self):
        status_code = None
        for i, sync_host in enumerate(self.sync_hosts):
            try:
                response = utils.auth_request('get', sync_host,
                    '/key/sync/%s/%s/%s/%s' % (
                        self.org_id,
                        self.user_id,
                        self.server_id,
                        self.sync_hash,
                    ),
                    token=self.sync_token,
                    secret=self.sync_secret,
                    timeout=SYNC_CONF_TIMEOUT,
                )
                status_code = response.status_code
            except:
                if i >= len(self.sync_hosts) - 1:
                    logger.exception('Failed to sync conf', 'profile',
                        sync_host=sync_host,
                        sync_hosts=self.sync_hosts,
                        org_id=self.org_id,
                        user_id=self.user_id,
                        server_id=self.server_id,
                        sync_hash=self.sync_hash,
                    )
                    return
                else:
                    continue

            if status_code == 480:
                logger.info('Failed to sync conf, no subscription',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 404:
                logger.warning('Failed to sync conf, user not found',
                    'profile',
                    status_code=status_code,
                    sync_host=sync_host,
                    sync_hosts=self.sync_hosts,
                    org_id=self.org_id,
                    user_id=self.user_id,
                    server_id=self.server_id,
                    sync_hash=self.sync_hash,
                )
                return
            elif status_code == 200:
                data = response.json()
                if not data.get('signature') or not data.get('conf'):
                    return

                conf_signature = base64.b64encode(hmac.new(
                    self.sync_secret.encode(), data.get('conf'),
                    hashlib.sha512).digest())

                if conf_signature != data.get('signature'):
                    return

                self.update_profile(data.get('conf'))
                return

        if status_code is not None and status_code != 200:
            logger.error('Failed to sync conf, unknown error',
                'profile',
                status_code=status_code,
                sync_host=sync_host,
                sync_hosts=self.sync_hosts,
                org_id=self.org_id,
                user_id=self.user_id,
                server_id=self.server_id,
                sync_hash=self.sync_hash,
            )