Example #1
0
def write_usb_key(id, iv, key):
    iv = base64.b64encode(iv)
    key = base64.b64encode(key)

    if PLATFORM == LINUX or PLATFORM == SHELL:
        utils.check_output([
            'pkexec',
            '/usr/bin/pritunl-client-pk-set-disk-profile',
            utils.write_env({
                'PROFILE_ID': id,
                'PROFILE_IV': iv,
                'PROFILE_KEY': key,
            }),
        ])
    else:
        pass
Example #2
0
def write_usb_key(id, iv, key):
    iv = base64.b64encode(iv)
    key = base64.b64encode(key)

    if PLATFORM == LINUX or PLATFORM == SHELL:
        utils.check_output([
            'pkexec',
            '/usr/bin/pritunl-client-pk-set-disk-profile',
            utils.write_env({
                'PROFILE_ID': id,
                'PROFILE_IV': iv,
                'PROFILE_KEY': key,
            }),
        ])
    else:
        pass
Example #3
0
def get_usb_key(id):
    if PLATFORM == LINUX or PLATFORM == SHELL:
        data = utils.check_output([
            'pkexec',
            '/usr/bin/pritunl-client-pk-get-disk-profile',
            utils.write_env({
                'PROFILE_ID': id,
            }),
        ])
        data = json.loads(data)

        iv = base64.b64decode(data['iv'])
        key = base64.b64decode(data['key'])

        return iv, key
    else:
        pass
Example #4
0
def get_usb_key(id):
    if PLATFORM == LINUX or PLATFORM == SHELL:
        data = utils.check_output([
            'pkexec',
            '/usr/bin/pritunl-client-pk-get-disk-profile',
            utils.write_env({
                'PROFILE_ID': id,
            }),
        ])
        data = json.loads(data)

        iv = base64.b64decode(data['iv'])
        key = base64.b64decode(data['key'])

        return iv, key
    else:
        pass
    def _set_profile_autostart(self, retry=0):
        retry += 1
        process = subprocess.Popen([
            'pkexec',
            '/usr/bin/pritunl-client-pk-set-autostart',
            utils.write_env({'VPN_CONF': self.get_vpn_conf()}),
        ])
        process.wait()

        # Canceled
        if process.returncode == 126:
            return False
        # Random error, retry
        elif process.returncode == -15 and retry < 10:
            time.sleep(0.1)
            process = None
            return self._set_profile_autostart(retry=retry)
        elif process.returncode != 0:
            raise ProcessCallError(
                'Pritunl polkit process returned error %s.' % (
                    process.returncode))
        return True
    def _set_profile_autostart(self):
        for _ in xrange(250):
            process = subprocess.Popen([
                'pkexec',
                '/usr/bin/pritunl-client-pk-set-autostart',
                utils.write_env({'VPN_CONF': self.get_vpn_conf()}),
            ])
            process.wait()

            # Canceled
            if process.returncode == 126:
                return False
            # Random error, retry
            elif process.returncode == -15:
                time.sleep(0.05)
                continue
            elif process.returncode != 0:
                raise ProcessCallError(
                    'Pritunl polkit process returned error %s.' %
                    (process.returncode))
            else:
                break
        return True
Example #7
0
    def _set_profile_autostart(self):
        for _ in xrange(250):
            process = subprocess.Popen([
                'pkexec',
                '/usr/bin/pritunl-client-pk-set-autostart',
                utils.write_env({'VPN_CONF': self.get_vpn_conf()}),
            ])
            process.wait()

            # Canceled
            if process.returncode == 126:
                return False
            # Random error, retry
            elif process.returncode == -15:
                time.sleep(0.05)
                continue
            elif process.returncode != 0:
                raise ProcessCallError(
                    'Pritunl polkit process returned error %s.' % (
                        process.returncode))
            else:
                break
        return True
Example #8
0
    def _run_ovpn(self, status_callback, connect_callback,
            args, on_exit, wait, env=None, **kwargs):
        data = {
            'status': CONNECTING,
            'process': None,
            'status_callback': status_callback,
            'connect_callback': connect_callback,
            'started': False,
        }
        _connections[self.id] = data
        self._set_status(CONNECTING, connect_event=False)

        if env:
            args.append(utils.write_env(env))

        process = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            **kwargs
        )

        data['process'] = process
        self.pid = process.pid
        self.commit()

        def connect_thread():
            time.sleep(CONNECT_TIMEOUT)
            if not data.get('connect_callback'):
                return
            self._set_status(TIMEOUT_ERROR)
            self.stop(silent=True)

        def stderr_poll_thread():
            while True:
                line = process.stderr.readline()
                if not line:
                    if process.poll() is not None:
                        break
                    else:
                        continue
                print line.strip()
                with open(self.log_path, 'a') as log_file:
                    log_file.write(line)

        def stdout_poll_thread():
            started = False
            while True:
                line = process.stdout.readline()
                if not line:
                    if process.poll() is not None:
                        break
                    else:
                        continue
                print line.strip()
                with open(self.log_path, 'a') as log_file:
                    log_file.write(line)
                if not started:
                    started = True
                    data['started'] = True
                    thread = threading.Thread(target=connect_thread)
                    thread.daemon = True
                    thread.start()
                if 'Initialization Sequence Completed' in line:
                    self._set_status(CONNECTED)
                elif 'Inactivity timeout' in line:
                    self._set_status(RECONNECTING)
                elif 'AUTH_FAILED' in line or 'auth-failure' in line:
                    self._set_status(AUTH_ERROR)

            try:
                if os.path.exists(self.passwd_path):
                    os.remove(self.passwd_path)
            except:
                pass

            on_exit(process.returncode)

        with open(self.log_path, 'w') as _:
            pass

        thread = threading.Thread(target=stderr_poll_thread)
        thread.daemon = True
        thread.start()

        thread = threading.Thread(target=stdout_poll_thread)
        thread.daemon = True
        thread.start()

        if wait:
            for _ in xrange(300):
                time.sleep(0.1)
                if process.poll() is not None:
                    break
Example #9
0
    def _run_ovpn(self, status_callback, connect_callback,
            args, on_exit, wait, env=None, **kwargs):
        data = {
            'status': CONNECTING,
            'process': None,
            'status_callback': status_callback,
            'connect_callback': connect_callback,
            'started': False,
        }
        _connections[self.id] = data
        self._set_status(CONNECTING, connect_event=False)

        if env:
            args.append(utils.write_env(env))

        process = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            **kwargs
        )

        data['process'] = process
        self.pid = process.pid
        self.commit()

        def connect_thread():
            time.sleep(CONNECT_TIMEOUT)
            if not data.get('connect_callback'):
                return
            self._set_status(TIMEOUT_ERROR)
            self.stop(silent=True)

        def stderr_poll_thread():
            while True:
                line = process.stderr.readline()
                if not line:
                    if process.poll() is not None:
                        break
                    else:
                        continue
                print line.strip()
                with open(self.log_path, 'a') as log_file:
                    log_file.write(line)

        def stdout_poll_thread():
            started = False
            while True:
                line = process.stdout.readline()
                if not line:
                    if process.poll() is not None:
                        break
                    else:
                        continue
                print line.strip()
                with open(self.log_path, 'a') as log_file:
                    log_file.write(line)
                if not started:
                    started = True
                    data['started'] = True
                    thread = threading.Thread(target=connect_thread)
                    thread.daemon = True
                    thread.start()
                if 'Initialization Sequence Completed' in line:
                    self._set_status(CONNECTED)
                elif 'Inactivity timeout (--inactive)' in line:
                    pass
                elif 'Inactivity timeout' in line:
                    self._set_status(RECONNECTING)
                elif 'AUTH_FAILED' in line or 'auth-failure' in line:
                    self._set_status(AUTH_ERROR)

            try:
                if os.path.exists(self.passwd_path):
                    os.remove(self.passwd_path)
            except:
                pass

            on_exit(process.returncode)

        with open(self.log_path, 'w') as _:
            pass

        thread = threading.Thread(target=stderr_poll_thread)
        thread.daemon = True
        thread.start()

        thread = threading.Thread(target=stdout_poll_thread)
        thread.daemon = True
        thread.start()

        if wait:
            for _ in xrange(300):
                time.sleep(0.1)
                if process.poll() is not None:
                    break