Example #1
0
def connect_openvpn(config, restart=False, sudopassword=None):
    log_debug('Connecting OpenVPN configuration: [%s]' % config)
    global _state

    if _sudo 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
Example #2
0
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
Example #3
0
def delete_ovpn():
    name = select_ovpn()
    if name is not None and len(name) > 0:
        ovpn = _settings.get_datapath(name)
        log_debug('Delete: [%s]' % ovpn)
        if os.path.exists(ovpn):
            if not utils.yesno(_settings.get_string(3002), _settings.get_string(3006)):
                utils.ok(_settings.get_string(
                    3002), _settings.get_string(3007))
            else:
                log_debug('Deleting: [%s]' % (ovpn))
                os.remove(ovpn)
    elif name is None:
        utils.ok(_settings.get_string(3002), _settings.get_string(3008))
Example #4
0
def delete_ovpn():
    name = select_ovpn()
    if name is not None and len(name) > 0:
        ovpn = _settings.get_datapath(name)
        log_debug('Delete: [%s]' % ovpn)
        if os.path.exists(ovpn):
            if not utils.yesno(_settings.get_string(3002), _settings.get_string(3006)):
                utils.ok(_settings.get_string(
                    3002), _settings.get_string(3007))
            else:
                log_debug('Deleting: [%s]' % (ovpn))
                os.remove(ovpn)
    elif name is None:
        utils.ok(_settings.get_string(3002), _settings.get_string(3008))
Example #5
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(_settings.get_string(3002), _settings.get_string(3003)):
                    utils.ok(_settings.get_string(
                        3002), _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Example #6
0
def import_ovpn():
    path = utils.browse_files(_settings.get_string(3000), mask='.ovpn|.conf')
    if path and os.path.exists(path) and os.path.isfile(path):
        log_debug('Import: [%s]' % path)
        name = utils.keyboard(heading=_settings.get_string(3001))
        if name and len(name) > 0:
            ovpn = _settings.get_datapath('%s.ovpn' % name)
            if os.path.exists(ovpn) and not utils.yesno(_settings.get_string(3002), _settings.get_string(3003)):
                    utils.ok(_settings.get_string(
                        3002), _settings.get_string(3004))
            else:
                log_debug('Copying [%s] to [%s]' % (path, ovpn))
                shutil.copyfile(path, ovpn)
        else:
            utils.ok(_settings.get_string(3002), _settings.get_string(3005))
Example #7
0
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
Example #8
0
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
Example #9
0
log_debug('Addon: %s' % __addonname__, 1)
log_debug('Version: %s' % __version__, 1)
log_debug('Params: %s: %s' % (__path__, __params__), 1)

__category__ = utils.get_value(__params__, 'c')
__filter__ = utils.get_value(__params__, 'filter')
if __path__ == 'browse':
    try:
        __offset__ = utils.get_value(__params__, 'offset')
        __pivot__ = utils.get_value(__params__, 'pivot')

        # Display users presets.
        if __id__ == 'presets':
            if __username__ is None or len(__username__) == 0:
                utils.ok(__addonname__, __settings__.get_string(
                    3001), __settings__.get_string(3002))
            else:
                results = __tunein__.browse_presets(username=__username__)
                process_tunein_json(results)
                xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

        # Browse for a station/show/topic/category.
        elif len(__id__) > 0:
            results = __tunein__.browse(
                id=__id__, filter=__filter__, offset=__offset__, pivot=__pivot__, username=__username__)
            process_tunein_json(results)
            xbmcplugin.endOfDirectory(int(__settings__.get_argv(1)))

        # Display local stations and shows.
        elif __category__ == 'local':
            results = __tunein__.browse_local(
Example #10
0
    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])
    else:
        geolocation = get_geolocation()
        display_location(geolocation)