Skip to content

Commit

Permalink
Handle AUTH_FAILED by disconnect, and connect with forced dialog for …
Browse files Browse the repository at this point in the history
…password input
  • Loading branch information
grzegorz-gutowski committed Apr 12, 2024
1 parent 3c76b47 commit b2cf70d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/openvpn3_indicator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
# If not, see <https://www.gnu.org/licenses/>.
#

import logging
import sys
import traceback

from openvpn3_indicator.about import APPLICATION_NAME
from openvpn3_indicator.application import Application

###
#
# Main
#
###


def main():
def main(args=None):
import logging
import sys
import traceback
from openvpn3_indicator.about import APPLICATION_NAME
from openvpn3_indicator.application import Application
try:
import setproctitle
setproctitle.setproctitle(f'{APPLICATION_NAME}')
except ImportError:
logging.debug(traceback.format_exc())
logging.error('Failed to import setproctitle module')
application = Application()
application.run(sys.argv)
if args is None:
args = sys.argv
application.run(args)


if __name__ == '__main__':
Expand Down
27 changes: 19 additions & 8 deletions src/openvpn3_indicator/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
# If not, see <https://www.gnu.org/licenses/>.
#

import argparse
import gettext
import logging
import sys
import time
import traceback
import uuid

import dbus
from dbus.mainloop.glib import DBusGMainLoop
Expand Down Expand Up @@ -143,7 +140,7 @@ def on_startup(self, data):
self.name_configs = dict()
self.config_sessions = dict()
self.session_configs = dict()
self.session_failed_authentications = set()
self.failed_authentications = set()
self.session_dialogs = dict()
self.session_statuses = dict()

Expand Down Expand Up @@ -223,8 +220,8 @@ def refresh_ui(self):

def refresh_sessions(self):
if self.invalid_sessions:
new_session_ids = set()
try:
new_session_ids = set()
new_sessions = dict()
for session in self.session_manager.FetchAvailableSessions():
session_id = str(session.GetPath())
Expand Down Expand Up @@ -368,7 +365,7 @@ def construct_idle_menu(self):
for session_id in session_ids:
#TODO: Add some information on session status to menu items (perhaps in the title?)
session = self.sessions[session_id]
session_menu = self.construct_menu_session(config_id, session_id)
session_menu = self.construct_menu_session(session_id)
menu_item = Gtk.MenuItem.new_with_label(config_name)
menu_item.set_submenu(session_menu)
menu.append(menu_item)
Expand Down Expand Up @@ -486,7 +483,17 @@ def on_session_event(self, session_id, major, minor, message):
if openvpn3.StatusMajor.CONNECTION == major and openvpn3.StatusMinor.CONN_AUTH_FAILED == minor:
#TODO: Notify authentication failure
#TODO: Record authentication failure

self.action_session_disconnect(None, session_id)
config_id = self.session_configs.get(session_id, None)
if config_id is not None:
self.failed_authentications.add(config_id)
self.action_config_connect(None, config_id)
if openvpn3.StatusMajor.CONNECTION == major and openvpn3.StatusMinor.CONN_CONNECTED == minor:
config_id = self.session_configs.get(session_id, None)
if config_id is not None and config_id in self.failed_authentications:
self.failed_authentications.remove(config_id)

if openvpn3.StatusMajor.CONNECTION == major and openvpn3.StatusMinor.CONN_FAILED == minor:
#TODO: Notify connection failure
#TODO: Record connection failure
Expand All @@ -504,14 +511,18 @@ def on_session_event(self, session_id, major, minor, message):
description = str(input_slot.GetLabel())
mask = bool(input_slot.GetInputMask())
required_credentials.append((description, mask))
force_ui = False
config_id = self.session_configs.get(session_id, None)
if config_id is not None:
if config_id in self.failed_authentications:
force_ui = True
self.action_get_credentials(None, session_id, required_credentials, force_ui=force_ui)
except: #TODO: Catch only expected exceptions
logging.debug(traceback.format_exc())
#TODO: Catch only expected exceptions
#TODO: Notify authentication failure
#TODO: Record authentication failure
self.action_session_disconnect(None, session_id)

self.action_get_credentials(None, session_id, required_credentials)#, force_ui=True)
self.notify_session_change(session_id)

def action_auth_url(self, _object, session_id, url):
Expand Down

0 comments on commit b2cf70d

Please sign in to comment.