def select_ovpn(): ovpnfiles = {} with common.PLUGIN.get_storage() as storage: try: ovpnfiles = storage['ovpnfiles'] except KeyError: storage['ovpnfiles'] = ovpnfiles if len(ovpnfiles) == 0: return None else: response = vpnlib.is_running(ip, port) common.PLUGIN.log_debug('Response from is_running: [%s] [%s] [%s]' % (response[0], response[1], response[2])) if response[0]: # Le VPN est connecté print 'VPN Encore connecté, pas normal, je vais le déco' disconnect_openvpn() configs = [] ovpnfileslist = [] for name, configfilepath in ovpnfiles.iteritems(): configs.append(name) ovpnfileslist.append(configfilepath) idx = common.sp.xbmcgui.Dialog().select( common.GETTEXT('Select OpenVPN configuration to run'), configs) if idx >= 0: common.PLUGIN.log_debug('Select: [%s]' % ovpnfileslist[idx]) return ovpnfileslist[idx] else: return ''
def select_ovpn(): ovpnfiles = {} with storage.PersistentDict('vpn') as db: try: ovpnfiles = db['ovpnfiles'] except KeyError: db['ovpnfiles'] = ovpnfiles db.flush() if len(ovpnfiles) == 0: return None else: response = vpnlib.is_running(ip, port) Script.log('OpenVPN: Response from is_running: [%s] [%s] [%s]' % (response[0], response[1], response[2])) if response[0]: # Le VPN est connecté disconnect_openvpn() configs = [] ovpnfileslist = [] for name, configfilepath in list(ovpnfiles.items()): configs.append(name) ovpnfileslist.append(configfilepath) idx = xbmcgui.Dialog().select( Script.localize(LABELS['Select OpenVPN configuration to run']), configs) if idx >= 0: Script.log('OpenVPN: Select conf: [%s]' % ovpnfileslist[idx]) return ovpnfileslist[idx] else: return ''
def select_ovpn(): global _state ovpnfiles = [] for path in os.listdir(_userdata): if os.path.splitext(path)[1] == '.ovpn': log_debug('Found configuration: [%s]' % path) ovpnfiles.append(path) if len(ovpnfiles) == 0: return None else: ovpnfiles.sort() response = vpn.is_running(_ip, _port) log_debug('Response from is_running: [%s] [%s] [%s]' % (response[0], response[1], response[2])) if response[0]: _state = connected ovpnfiles.append(_settings.get_string(3014)) configs = [] for ovpn in ovpnfiles: config = os.path.splitext(ovpn)[0] if response[1] is not None and response[ 2] is not None and config == os.path.splitext( os.path.basename(response[1]))[0]: config = '%s - %s' % (config, response[2]) configs.append(config) idx = utils.select(_settings.get_string(3013), configs) if idx >= 0: log_debug('Select: [%s]' % ovpnfiles[idx]) return ovpnfiles[idx] else: return ''
def select_ovpn(): global _state ovpnfiles = [] for path in os.listdir(_userdata): if os.path.splitext(path)[1] == '.ovpn': log_debug('Found configuration: [%s]' % path) ovpnfiles.append(path) if len(ovpnfiles) == 0: return None else: ovpnfiles.sort() response = vpn.is_running(_ip, _port) log_debug('Response from is_running: [%s] [%s] [%s]' % ( response[0], response[1], response[2])) if response[0]: _state = connected ovpnfiles.append(_settings.get_string(3014)) configs = [] for ovpn in ovpnfiles: config = os.path.splitext(ovpn)[0] if response[1] is not None and response[2] is not None and config == os.path.splitext(os.path.basename(response[1]))[0]: config = '%s - %s' % (config, response[2]) configs.append(config) idx = utils.select(_settings.get_string(3013), configs) if idx >= 0: log_debug('Select: [%s]' % ovpnfiles[idx]) return ovpnfiles[idx] else: return ''
def disconnect_openvpn(): log_debug('Disconnecting OpenVPN') global _state try: _state = disconnecting response = vpn.is_running(_ip, _port) if response[0]: vpn.disconnect(_ip, _port) if response[1] is not None: display_notification(_settings.get_string(4001) % os.path.splitext(os.path.basename(response[1]))[0]) _state = disconnected log_debug('Disconnect OpenVPN successful') except vpn.OpenVPNError as exception: utils.ok(_settings.get_string( 3002), _settings.get_string(3011), exception.string) _state = failed
def vpn_item_callback(plugin): if vpnlib.is_running(IP, PORT): disconnect_openvpn() else: ovpn = select_ovpn() if ovpn is None: import_ovpn() # Case when the user cancel the import dialog if ovpn is None: return False if len(ovpn) > 0: connect_openvpn(ovpn) xbmc.executebuiltin('Container.Refresh()')
def disconnect_openvpn(): with storage.PersistentDict('vpn') as db: Script.log('OpenVPN: Disconnecting OpenVPN') try: db['status'] = "disconnecting" response = vpnlib.is_running(ip, port) if response[0]: vpnlib.disconnect(ip, port) if response[1] is not None: Script.notify('OpenVPN', Script.localize(30355)) db['status'] = "disconnected" Script.log('OpenVPN: Disconnect OpenVPN successful') except vpnlib.OpenVPNError as exception: xbmcgui.Dialog().ok('OpenVPN', Script.localize(30358)) Script.log('OpenVPN: OpenVPN error: ' + str(exception)) db['status'] = "failed" db.flush()
def disconnect_openvpn(): storage = common.sp.MemStorage('vpn') common.PLUGIN.log_debug('Disconnecting OpenVPN') try: storage['status'] = "disconnecting" response = vpnlib.is_running(ip, port) if response[0]: vpnlib.disconnect(ip, port) if response[1] is not None: utils.send_notification(_('Stopped VPN connection'), title="OpenVPN", time=3000) storage['status'] = "disconnected" common.PLUGIN.log_debug('Disconnect OpenVPN successful') except vpnlib.OpenVPNError as exception: common.sp.xbmcgui.Dialog().ok( 'OpenVPN', _('An error has occurred whilst trying to connect OpenVPN')) storage['status'] = "failed"
def delete_ovpn(*args, **kwargs): ovpnfiles = {} with storage.PersistentDict('vpn') as db: try: ovpnfiles = db['ovpnfiles'] except KeyError: db['ovpnfiles'] = ovpnfiles db.flush() if len(ovpnfiles) == 0: return None else: response = vpnlib.is_running(ip, port) Script.log('OpenVPN: Response from is_running: [%s] [%s] [%s]' % (response[0], response[1], response[2])) if response[0]: # Le VPN est connecté Script.log('OpenVPN: VPN still connected, we disconnect it') disconnect_openvpn() configs = [] ovpnfileslist = [] for name, configfilepath in list(ovpnfiles.items()): configs.append(name) ovpnfileslist.append(configfilepath) idx = xbmcgui.Dialog().select( Script.localize(LABELS['Select OpenVPN configuration to delete']), configs) if idx >= 0: Script.log('Select: [%s]' % ovpnfileslist[idx]) new_ovpnfiles = {} for name, configfilepath in list(ovpnfiles.items()): if configfilepath != ovpnfileslist[idx]: new_ovpnfiles[name] = configfilepath with storage.PersistentDict('vpn') as db: db['ovpnfiles'] = new_ovpnfiles db.flush() else: return ''