Exemple #1
0
    def show_about(self):
        from pritunl_client import __version__

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_INFO)
        dialog.set_buttons(BUTTONS_OK)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_image(utils.get_logo())
        dialog.set_message(
            ("<b>%s - v%s</b>\n\n" + "Copyright (c) 2013-2014 Pritunl\n\n" + "http://pritunl.com/")
            % (APP_NAME_FORMATED, __version__)
        )
        dialog.run()
        dialog.destroy()
Exemple #2
0
    def wait_for_usb_remove(self):
        while True:
            interrupt = False
            not_has_device = []
            dialog = interface.MessageDialog()

            def refresh():
                while not interrupt:
                    time.sleep(0.025)
                    if not profile.has_usb_device():
                        not_has_device.append(True)
                        try:
                            dialog.close()
                        except:
                            pass
                        return

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

            dialog.set_type(MESSAGE_LOADING)
            dialog.set_buttons(BUTTONS_CANCEL)
            dialog.set_title(APP_NAME_FORMATED)
            dialog.set_icon(utils.get_logo())
            dialog.set_message('Remove USB key...')
            dialog.set_message_secondary('Remove Pritunl USB key')
            dialog.run()
            dialog.destroy()

            if bool(not_has_device):
                return
Exemple #3
0
 def show_about(self):
     from pritunl_client import __version__
     dialog = interface.MessageDialog()
     dialog.set_type(MESSAGE_INFO)
     dialog.set_buttons(BUTTONS_OK)
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_image(utils.get_logo())
     dialog.set_message(('<b>%s - v%s</b>\n\n' +
         'Copyright (c) 2013-2017 Pritunl\n\n' +
         'https://pritunl.com/') % (
             APP_NAME_FORMATED,
             __version__,
         ))
     dialog.run()
     dialog.destroy()
    def wait_for_usb_remove(self):
        while True:
            interrupt = False
            not_has_device = []
            dialog = interface.MessageDialog()

            def refresh():
                while not interrupt:
                    time.sleep(0.025)
                    if not profile.has_usb_device():
                        not_has_device.append(True)
                        try:
                            dialog.close()
                        except:
                            pass
                        return

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

            dialog.set_type(MESSAGE_LOADING)
            dialog.set_buttons(BUTTONS_CANCEL)
            dialog.set_title(APP_NAME_FORMATED)
            dialog.set_icon(utils.get_logo())
            dialog.set_message('Remove USB key...')
            dialog.set_message_secondary('Remove Pritunl USB key')
            dialog.run()
            dialog.destroy()

            if bool(not_has_device):
                return
Exemple #5
0
    def on_connect_profile(self, profile_id):
        passwd = None
        prfl = profile.Profile.get_profile(profile_id)
        if prfl.status in ACTIVE_STATES:
            return

        prfl.sync_conf()

        if prfl.auth_passwd:
            dialog = interface.InputDialog()
            dialog.set_title(APP_NAME_FORMATED)
            dialog.set_icon(utils.get_logo())
            dialog.set_message('Profile Authenticator Required')
            dialog.set_message_secondary('Enter authenticator key for %s' %
                                         (prfl.name))
            dialog.set_input_label('Authenticator Key:')
            dialog.set_input_width(16)
            passwd = dialog.run()
            dialog.destroy()
            if passwd is None:
                return

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_LOADING)
        dialog.set_buttons(BUTTONS_CANCEL)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Connecting to %s' % prfl.name)
        dialog.set_message_secondary('Conecting to the server...')

        def connect_callback():
            dialog.close()

        threading.Thread(target=prfl.start,
                         args=(self.on_status_change, connect_callback,
                               passwd)).start()

        response = dialog.run()
        dialog.destroy()
        if response is False:
            threading.Thread(target=prfl.stop).start()
            return

        if prfl.status in ERROR_STATES:
            self.show_connect_error(prfl, prfl.status)
Exemple #6
0
    def on_connect_profile(self, profile_id):
        passwd = None
        prfl = profile.Profile.get_profile(profile_id)
        if prfl.status in ACTIVE_STATES:
            return

        prfl.sync_conf()

        if prfl.auth_passwd:
            dialog = interface.InputDialog()
            dialog.set_title(APP_NAME_FORMATED)
            dialog.set_icon(utils.get_logo())
            dialog.set_message('Profile Authenticator Required')
            dialog.set_message_secondary('Enter authenticator key for %s' % (
                prfl.name))
            dialog.set_input_label('Authenticator Key:')
            dialog.set_input_width(16)
            passwd = dialog.run()
            dialog.destroy()
            if passwd is None:
                return

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_LOADING)
        dialog.set_buttons(BUTTONS_CANCEL)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Connecting to %s' % prfl.name)
        dialog.set_message_secondary('Conecting to the server...')

        def connect_callback():
            dialog.close()

        threading.Thread(target=prfl.start,
            args=(self.on_status_change, connect_callback, passwd)).start()

        response = dialog.run()
        dialog.destroy()
        if response is False:
            threading.Thread(target=prfl.stop).start()
            return

        if prfl.status in ERROR_STATES:
            self.show_connect_error(prfl, prfl.status)
Exemple #7
0
 def show_import_profile_error(self, message):
     dialog = interface.MessageDialog()
     dialog.set_type(MESSAGE_ERROR)
     dialog.set_buttons(BUTTONS_OK)
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Failed to import profile:')
     dialog.set_message_secondary(str(message).capitalize())
     dialog.run()
     dialog.destroy()
Exemple #8
0
 def show_import_profile_error(self, message):
     dialog = interface.MessageDialog()
     dialog.set_type(MESSAGE_ERROR)
     dialog.set_buttons(BUTTONS_OK)
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Failed to import profile:')
     dialog.set_message_secondary(str(message).capitalize())
     dialog.run()
     dialog.destroy()
Exemple #9
0
 def on_delete_profile(self, profile_id):
     prfl = profile.Profile.get_profile(profile_id)
     dialog = interface.MessageDialog()
     dialog.set_type(MESSAGE_ERROR)
     dialog.set_buttons(BUTTONS_OK_CANCEL)
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message("Delete profile")
     dialog.set_message_secondary("Are you sure you want to delete the profile %s" % prfl.name)
     response = dialog.run()
     if response:
         prfl.delete()
         self.update_menu()
     dialog.destroy()
Exemple #10
0
 def on_rename_profile(self, profile_id):
     prfl = profile.Profile.get_profile(profile_id)
     dialog = interface.InputDialog()
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message("Rename Profile")
     dialog.set_message_secondary("Enter new name for profile %s" % (prfl.name))
     dialog.set_input_label("Profile Name:")
     dialog.set_input_width(32)
     response = dialog.run()
     if response is not None:
         prfl.set_name(response[:32])
         self.update_menu()
     dialog.destroy()
Exemple #11
0
 def on_delete_profile(self, profile_id):
     prfl = profile.Profile.get_profile(profile_id)
     dialog = interface.MessageDialog()
     dialog.set_type(MESSAGE_ERROR)
     dialog.set_buttons(BUTTONS_OK_CANCEL)
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Delete profile')
     dialog.set_message_secondary(
         'Are you sure you want to delete the profile %s' % prfl.name)
     response = dialog.run()
     if response:
         prfl.delete()
         self.update_menu()
     dialog.destroy()
Exemple #12
0
 def on_rename_profile(self, profile_id):
     prfl = profile.Profile.get_profile(profile_id)
     dialog = interface.InputDialog()
     dialog.set_title(APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Rename Profile')
     dialog.set_message_secondary('Enter new name for profile %s' % (
         prfl.name))
     dialog.set_input_label('Profile Name:')
     dialog.set_input_width(32)
     response = dialog.run()
     if response is not None:
         prfl.set_name(response[:32])
         self.update_menu()
     dialog.destroy()
Exemple #13
0
    def show_connect_error(self, prfl, status):
        error_msgs = {
            ERROR: 'An error occurred while connecting to server',
            AUTH_ERROR: 'Failed to authenticate with server',
            TIMEOUT_ERROR: 'Server connection timed out',
        }

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_ERROR)
        dialog.set_buttons(BUTTONS_OK)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Unable to connect to %s' % prfl.name)
        dialog.set_message_secondary(error_msgs[status])
        dialog.run()
        dialog.destroy()
Exemple #14
0
    def show_import_profile(self):
        dialog = interface.FileChooserDialog()
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.add_filter('Pritunl Profile', '*.ovpn')
        dialog.add_filter('Pritunl Profile', '*.conf')
        dialog.add_filter('Pritunl Profile', '*.tar')

        response = dialog.run()
        if response:
            try:
                profile.import_file(response)
            except Exception as exception:
                self.show_import_profile_error(exception)
            self.update_menu()
        dialog.destroy()
Exemple #15
0
    def show_connect_error(self, prfl, status):
        error_msgs = {
            ERROR: 'An error occurred while connecting to server',
            AUTH_ERROR: 'Failed to authenticate with server',
            TIMEOUT_ERROR: 'Server connection timed out',
        }

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_ERROR)
        dialog.set_buttons(BUTTONS_OK)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Unable to connect to %s' % prfl.name)
        dialog.set_message_secondary(error_msgs[status])
        dialog.run()
        dialog.destroy()
Exemple #16
0
 def show_import_profile_uri(self):
     dialog = interface.InputDialog()
     dialog.set_title('%s - Import Profile URI' % APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Import Profile URI')
     dialog.set_message_secondary('Enter profile URI to import...')
     dialog.set_input_label('Profile URI:')
     dialog.set_input_width(32)
     response = dialog.run()
     if response:
         try:
             profile.import_uri(response)
         except Exception as exception:
             self.show_import_profile_error(exception)
         self.update_menu()
     dialog.destroy()
Exemple #17
0
 def show_import_profile_uri(self):
     dialog = interface.InputDialog()
     dialog.set_title('%s - Import Profile URI' % APP_NAME_FORMATED)
     dialog.set_icon(utils.get_logo())
     dialog.set_message('Import Profile URI')
     dialog.set_message_secondary('Enter profile URI to import...')
     dialog.set_input_label('Profile URI:')
     dialog.set_input_width(32)
     response = dialog.run()
     if response:
         try:
             profile.import_uri(response)
         except Exception as exception:
             self.show_import_profile_error(exception)
         self.update_menu()
     dialog.destroy()
Exemple #18
0
    def show_import_profile(self):
        dialog = interface.FileChooserDialog()
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.add_filter('Pritunl Profile', '*.ovpn')
        dialog.add_filter('Pritunl Profile', '*.conf')
        dialog.add_filter('Pritunl Profile', '*.tar')

        response = dialog.run()
        if response:
            try:
                profile.import_file(response)
            except Exception as exception:
                self.show_import_profile_error(exception)
            self.update_menu()
        dialog.destroy()
    def on_connect_profile(self, profile_id):
        passwd = None
        prfl = profile.Profile.get_profile(profile_id)
        if prfl.status in ACTIVE_STATES:
            return

        prfl.sync_conf()

        auth_type = prfl.auth_type
        if auth_type:
            passwd = ''

            if 'password' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Password Required')
                dialog.set_message_secondary('Enter password for %s' % (
                    prfl.name))
                dialog.set_input_label('Password:'******'pin' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Pin Required')
                dialog.set_message_secondary('Enter pin for %s' % (
                    prfl.name))
                dialog.set_input_label('Pin:')
                dialog.set_input_width(16)
                dialog.set_visibility(False)
                passwd += dialog.run()
                dialog.destroy()
                if passwd is None:
                    return

            if 'otp' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Authenticator Required')
                dialog.set_message_secondary(
                    'Enter authenticator key for %s' % (prfl.name))
                dialog.set_input_label('Authenticator Key:')
                dialog.set_input_width(16)
                passwd += dialog.run()
                dialog.destroy()
                if passwd is None:
                    return

        if prfl.encrypted:
            if not self.wait_for_usb_insert():
                return
            prfl.decrypt_vpv_conf()
            self.wait_for_usb_remove()

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_LOADING)
        dialog.set_buttons(BUTTONS_CANCEL)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Connecting to %s' % prfl.name)
        dialog.set_message_secondary('Conecting to the server...')

        def connect_callback():
            dialog.close()

        threading.Thread(target=prfl.start,
            args=(self.on_status_change, connect_callback, passwd)).start()

        response = dialog.run()
        dialog.destroy()
        if response is False:
            threading.Thread(target=prfl.stop).start()
            return

        if prfl.status in ERROR_STATES:
            self.show_connect_error(prfl, prfl.status)
    def on_setup_usb_key(self, profile_id):
        prfl = profile.Profile.get_profile(profile_id)

        if not profile.has_usb_device():
            devices = profile.get_usb_devices()

            if not devices:
                interrupt = False
                dialog = interface.MessageDialog()
                refresh_devices = []

                def refresh():
                    while not interrupt:
                        time.sleep(0.025)
                        devices = profile.get_usb_devices()
                        if devices:
                            refresh_devices.append(devices)
                            try:
                                dialog.close()
                            except:
                                pass
                            return

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

                dialog.set_type(MESSAGE_INFO)
                dialog.set_buttons(BUTTONS_CANCEL)
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Insert USB device...')
                dialog.set_message_secondary(
                    'Insert a USB device to use for profile key')
                dialog.run()
                dialog.destroy()

                interrupt = True
                if not refresh_devices:
                    return

                devices = refresh_devices[0]

            if not profile.has_usb_device():
                interrupt = False
                devices_map = []
                has_device = []
                dialog = interface.SelectDialog()

                def refresh():
                    while not interrupt:
                        time.sleep(0.025)
                        if profile.has_usb_device():
                            has_device.append(True)
                            try:
                                dialog.close()
                            except:
                                pass
                            return

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

                for usb_device, usb_name in devices.items():
                    devices_map.append(usb_device)
                    dialog.add_select_item(usb_name)

                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Format USB device')
                dialog.set_message_secondary(
                    'Insert existing Pritunl USB key or select a USB ' +
                    'device below to setup a new USB key. This will FORMAT ' +
                    'AND ERASE ALL DATA on the selected device.')
                response = dialog.run()
                dialog.destroy()
                interrupt = True

                if not has_device:
                    if response is None:
                        return

                    device = devices_map[response]
                    profile.format_usb_device(device)
                    time.sleep(1)

        prfl.encrypt_vpv_conf()
        self.wait_for_usb_remove()

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_INFO)
        dialog.set_buttons(BUTTONS_OK)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('USB key setup for %s complete' % prfl.name)
        dialog.set_message_secondary(
            'The profile has been sucessfully protected with USB key')
        dialog.run()
        dialog.destroy()

        self.update_menu()
Exemple #21
0
    def on_setup_usb_key(self, profile_id):
        prfl = profile.Profile.get_profile(profile_id)

        if not profile.has_usb_device():
            devices = profile.get_usb_devices()

            if not devices:
                interrupt = False
                dialog = interface.MessageDialog()
                refresh_devices = []

                def refresh():
                    while not interrupt:
                        time.sleep(0.025)
                        devices = profile.get_usb_devices()
                        if devices:
                            refresh_devices.append(devices)
                            try:
                                dialog.close()
                            except:
                                pass
                            return

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

                dialog.set_type(MESSAGE_INFO)
                dialog.set_buttons(BUTTONS_CANCEL)
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Insert USB device...')
                dialog.set_message_secondary(
                    'Insert a USB device to use for profile key')
                dialog.run()
                dialog.destroy()

                interrupt = True
                if not refresh_devices:
                    return

                devices = refresh_devices[0]

            if not profile.has_usb_device():
                interrupt = False
                devices_map = []
                has_device = []
                dialog = interface.SelectDialog()

                def refresh():
                    while not interrupt:
                        time.sleep(0.025)
                        if profile.has_usb_device():
                            has_device.append(True)
                            try:
                                dialog.close()
                            except:
                                pass
                            return

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

                for usb_device, usb_name in devices.items():
                    devices_map.append(usb_device)
                    dialog.add_select_item(usb_name)

                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Format USB device')
                dialog.set_message_secondary(
                    'Insert existing Pritunl USB key or select a USB ' +
                    'device below to setup a new USB key. This will FORMAT ' +
                    'AND ERASE ALL DATA on the selected device.')
                response = dialog.run()
                dialog.destroy()
                interrupt = True

                if not has_device:
                    if response is None:
                        return

                    device = devices_map[response]
                    profile.format_usb_device(device)
                    time.sleep(1)

        prfl.encrypt_vpv_conf()
        self.wait_for_usb_remove()

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_INFO)
        dialog.set_buttons(BUTTONS_OK)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('USB key setup for %s complete' % prfl.name)
        dialog.set_message_secondary(
            'The profile has been sucessfully protected with USB key')
        dialog.run()
        dialog.destroy()

        self.update_menu()
Exemple #22
0
    def on_connect_profile(self, profile_id):
        passwd = None
        prfl = profile.Profile.get_profile(profile_id)
        if prfl.status in ACTIVE_STATES:
            return

        prfl.sync_conf()

        auth_type = prfl.auth_type
        if auth_type:
            passwd = ''

            if 'password' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Password Required')
                dialog.set_message_secondary('Enter password for %s' % (
                    prfl.name))
                dialog.set_input_label('Password:'******'pin' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Pin Required')
                dialog.set_message_secondary('Enter pin for %s' % (
                    prfl.name))
                dialog.set_input_label('Pin:')
                dialog.set_input_width(16)
                dialog.set_visibility(False)
                resp = dialog.run()
                dialog.destroy()
                if resp is None:
                    return
                else:
                    passwd += resp

            if 'duo' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Duo Passcode Required')
                dialog.set_message_secondary(
                    'Enter Duo passcode for %s' % (prfl.name))
                dialog.set_input_label('Duo Passcode:')
                dialog.set_input_width(16)
                resp = dialog.run()
                dialog.destroy()
                if resp is None:
                    return
                else:
                    passwd += resp
            elif 'yubikey' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile YubiKey Required')
                dialog.set_message_secondary(
                    'Insert YubiKey for %s' % (prfl.name))
                dialog.set_input_label('YubiKey:')
                dialog.set_input_width(16)
                dialog.set_visibility(False)
                resp = dialog.run()
                dialog.destroy()
                if resp is None:
                    return
                else:
                    passwd += resp
            elif 'otp' in auth_type:
                dialog = interface.InputDialog()
                dialog.set_title(APP_NAME_FORMATED)
                dialog.set_icon(utils.get_logo())
                dialog.set_message('Profile Authenticator Required')
                dialog.set_message_secondary(
                    'Enter authenticator key for %s' % (prfl.name))
                dialog.set_input_label('Authenticator Key:')
                dialog.set_input_width(16)
                resp = dialog.run()
                dialog.destroy()
                if resp is None:
                    return
                else:
                    passwd += resp

        if prfl.encrypted:
            if not self.wait_for_usb_insert():
                return
            prfl.decrypt_vpv_conf()
            self.wait_for_usb_remove()

        dialog = interface.MessageDialog()
        dialog.set_type(MESSAGE_LOADING)
        dialog.set_buttons(BUTTONS_CANCEL)
        dialog.set_title(APP_NAME_FORMATED)
        dialog.set_icon(utils.get_logo())
        dialog.set_message('Connecting to %s' % prfl.name)
        dialog.set_message_secondary('Conecting to the server...')

        def connect_callback():
            dialog.close()

        threading.Thread(target=prfl.start,
            args=(self.on_status_change, connect_callback, passwd)).start()

        response = dialog.run()
        dialog.destroy()
        if response is False:
            threading.Thread(target=prfl.stop).start()
            return

        if prfl.status in ERROR_STATES:
            self.show_connect_error(prfl, prfl.status)