def connect_openvpn(config, restart=False, sudopassword=None): with storage.PersistentDict('vpn') as db: Script.log('OpenVPN: Connecting OpenVPN configuration: [%s]' % config) if Script.setting.get_boolean('vpn.sudo') and \ Script.setting.get_boolean('vpn.sudopsw') and sudopassword is None: keyboard = xbmc.Keyboard(default='', heading=Script.localize( LABELS['Enter your sudo password']), hidden=True) keyboard.doModal() if keyboard.isConfirmed(): sudopassword = keyboard.getText() openvpn = vpnlib.OpenVPN( Script.setting.get_string('vpn.openvpnfilepath'), config, ip=ip, port=port, args=Script.setting.get_string('vpn.args'), sudo=Script.setting.get_boolean('vpn.sudo'), sudopwd=sudopassword, debug=True) try: if restart: openvpn.disconnect() db['status'] = "disconnected" openvpn.connect() utils.send_notification(Script.localize( LABELS['Started VPN connection']), title="OpenVPN", time=3000) db['status'] = "connected" except vpnlib.OpenVPNError as exception: if exception.errno == 1: db['status'] = "connected" if xbmcgui.Dialog().yesno( 'OpenVPN', Script.localize(LABELS[ 'An existing OpenVPN instance appears to be running.'] ), Script.localize(LABELS['Disconnect it?'])): Script.log('OpenVPN: User has decided to restart OpenVPN') connect_openvpn(config, True, sudopassword) else: Script.log( 'OpenVPN: User has decided not to restart OpenVPN') else: xbmcgui.Dialog().ok( 'OpenVPN', Script.localize(LABELS[ 'An error has occurred whilst trying to connect OpenVPN'] )) db['status'] = "failed" db.flush()
def connect_openvpn(config, restart=False, sudopassword=None): log_debug('Connecting OpenVPN configuration: [%s]' % config) global _state if _sudo and _sudopwdrequired and sudopassword is None: sudopassword = utils.keyboard( heading=_settings.get_string(3012), hidden=True) openvpn = vpn.OpenVPN(_openvpn, _settings.get_datapath( config), ip=_ip, port=_port, args=_args, sudo=_sudo, sudopwd=sudopassword, debug=(_settings['debug'] == 'true')) try: if restart: openvpn.disconnect() _state = disconnected openvpn.connect() display_notification(_settings.get_string(4002) % os.path.splitext(os.path.basename(config))[0]) _state = connected except vpn.OpenVPNError as exception: if exception.errno == 1: _state = connected if utils.yesno(_settings.get_string(3002), _settings.get_string(3009), _settings.get_string(3010)): log_debug('User has decided to restart OpenVPN') connect_openvpn(config, True, sudopassword) else: log_debug('User has decided not to restart OpenVPN') else: utils.ok(_settings.get_string( 3002), _settings.get_string(3011), exception.string) _state = failed
def connect_openvpn(config, sudopassword=None): Script.log('OpenVPN: Connecting OpenVPN configuration: [%s]' % config) if Script.setting.get_boolean('vpn.sudo') and \ Script.setting.get_boolean('vpn.sudopsw') and sudopassword is None: keyboard = xbmc.Keyboard() keyboard.setHeading(Script.localize(30353)) keyboard.setHiddenInput(True) keyboard.doModal() if keyboard.isConfirmed(): sudopassword = keyboard.getText() else: return openvpn = vpnlib.OpenVPN( Script.setting.get_string('vpn.openvpnfilepath'), config, ip=IP, port=PORT, args=Script.setting.get_string('vpn.args'), sudo=Script.setting.get_boolean('vpn.sudo'), sudopwd=sudopassword) try: openvpn.connect() Script.notify( "OpenVPN", Script.localize(30354), display_time=3000) except Exception as e: xbmcgui.Dialog().ok( 'OpenVPN', Script.localize(30358)) Script.log('OpenVPN: OpenVPN error: ' + str(e))
def connect_openvpn(config, restart=False, sudopassword=None): storage = common.sp.MemStorage('vpn') common.PLUGIN.log_debug('Connecting OpenVPN configuration: [%s]' % config) if common.PLUGIN.get_setting('vpn.sudo') and \ common.PLUGIN.get_setting('vpn.sudopsw') and sudopassword is None: keyboard = common.sp.xbmc.Keyboard( default='', heading=common.GETTEXT('Enter your sudo password'), hidden=True) keyboard.doModal() if keyboard.isConfirmed(): sudopassword = keyboard.getText() openvpn = vpnlib.OpenVPN(common.PLUGIN.get_setting('vpn.openvpnfilepath'), config, ip=ip, port=port, args=common.PLUGIN.get_setting('vpn.args'), sudo=common.PLUGIN.get_setting('vpn.sudo'), sudopwd=sudopassword, debug=True) try: if restart: openvpn.disconnect() storage['status'] = "disconnected" openvpn.connect() utils.send_notification(common.GETTEXT('Started VPN connection'), title="OpenVPN", time=3000) storage['status'] = "connected" except vpnlib.OpenVPNError as exception: if exception.errno == 1: storage['status'] = "connected" if common.sp.xbmcgui.Dialog().yesno( 'OpenVPN', common.GETTEXT( 'An existing OpenVPN instance appears to be running.'), common.GETTEXT('Disconnect it?')): common.PLUGIN.log_debug('User has decided to restart OpenVPN') connect_openvpn(config, True, sudopassword) else: common.PLUGIN.log_debug( 'User has decided not to restart OpenVPN') else: common.sp.xbmcgui.Dialog().ok( 'OpenVPN', common.GETTEXT( 'An error has occurred whilst trying to connect OpenVPN')) storage['status'] = "failed"
def connect_openvpn(config, restart=False, sudopassword=None): with storage.PersistentDict('vpn') as db: Script.log('OpenVPN: Connecting OpenVPN configuration: [%s]' % config) if Script.setting.get_boolean('vpn.sudo') and \ Script.setting.get_boolean('vpn.sudopsw') and sudopassword is None: keyboard = xbmc.Keyboard(default='', heading=Script.localize(30353), hidden=True) keyboard.doModal() if keyboard.isConfirmed(): sudopassword = keyboard.getText() openvpn = vpnlib.OpenVPN( Script.setting.get_string('vpn.openvpnfilepath'), config, ip=ip, port=port, args=Script.setting.get_string('vpn.args'), sudo=Script.setting.get_boolean('vpn.sudo'), sudopwd=sudopassword, debug=True) try: if restart: openvpn.disconnect() db['status'] = "disconnected" openvpn.connect() Script.notify( "OpenVPN", Script.localize(30354), display_time=3000) db['status'] = "connected" except vpnlib.OpenVPNError as exception: if exception.errno == 1: db['status'] = "connected" if xbmcgui.Dialog().yesno( 'OpenVPN', Script.localize(30356), Script.localize(30357)): Script.log('OpenVPN: User has decided to restart OpenVPN') connect_openvpn(config, True, sudopassword) else: Script.log( 'OpenVPN: User has decided not to restart OpenVPN') else: xbmcgui.Dialog().ok( 'OpenVPN', Script.localize(30358)) db['status'] = "failed" db.flush()