Exemple #1
0
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 ''
Exemple #2
0
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 ''
Exemple #3
0
    display_notification(4002)

    prefix = sudo_prefix()
    cmdline = '%skillall -TERM %s' % (prefix, os.path.basename(_openvpn))
    log_debug(cmdline)
    proc = subprocess.Popen(cmdline, shell=True, stdout=subprocess.PIPE,
                            stdin=subprocess.PIPE, stderr=subprocess.PIPE)

    time.sleep(_defaultstopdelay)
    geolocation = get_geolocation()
    display_location(geolocation)

if (__name__ == '__main__'):
    vpns = get_vpns()
    if _settings.get_argc() == 1:
        index = utils.select(_settings.get_string(3000), vpns)
    else:
        index = int(_settings.get_argv(1)) - 1
    if index != -1:
        if index >= len(vpns) - 1:
            stop_openvpn()
        else:
            config = create_configuration(vpns, index)
            if 'file' in config and len(config['file']) == 0 or not os.path.exists(config['file']):
                utils.ok(_addonname, _settings.get_string(
                    3001), _settings.get_string(3002))
                xbmc.log('Configuration file does not exist: %s' %
                         config['file'], xbmc.LOGERROR)
            else:
                stop_openvpn()
                start_openvpn(config, vpns[index])