예제 #1
0
def connectToCustomServer():
    server = config.getConfiguredServerAddress()
    if not server:
        gui.addDir(arguments, __language__(30001), _SETTINGS,  isFolder=False)
    else:
        gui.addDir(arguments, __language__(30053), _CUSTOM_CONNECT,  isFolder=False)
        gui.addDir(arguments, __language__(30002),   _KILL,      isFolder=False)
예제 #2
0
 def _stopRemoteController(self, timeout=15):
     Logger.log("Android _forceAndroidControllerStop", Logger.LOG_DEBUG)
     ret = self._runRemoteController(self.CONTROLLER_FINISH, timeout)
     if not ret:
         Logger.log("Remote Controller did not respond the FINISH command",
                    Logger.LOG_ERROR)
         gui.DialogOK(__language__(30022), __language__(30023))
예제 #3
0
def doMenu():
    folder = xbmc.getInfoLabel('Container.FolderPath')
    if config.ADDONID in folder:
        xbmc.executebuiltin('XBMC.Action(ContextMenu)')
        return
        
    choice   = 0
    path     = xbmc.getInfoLabel('ListItem.FolderPath')


    if len(path) > 0:
        menu = []
        menu.append((__language__(30009), 1))
        menu.append((__language__(30010), 2))
        menu.append((__language__(30011), 0))

        choice = contextmenu.showMenu(config.ADDONID, menu)

    if choice == None:
        return

    if choice == 0:
        xbmc.executebuiltin('XBMC.Action(ContextMenu)')
        return

    if choice == 2:
        config.ADDON.openSettings()
        return

    if choice == 1:
        runExternal(path)
예제 #4
0
def doMenu():
    folder = xbmc.getInfoLabel("Container.FolderPath")
    if config.ADDONID in folder:
        xbmc.executebuiltin("XBMC.Action(ContextMenu)")
        return

    choice = 0
    path = xbmc.getInfoLabel("ListItem.FolderPath")

    if len(path) > 0:
        menu = []
        menu.append((__language__(30009), 1))
        menu.append((__language__(30010), 2))
        menu.append((__language__(30011), 0))

        choice = contextmenu.showMenu(config.ADDONID, menu)

    if choice == None:
        return

    if choice == 0:
        xbmc.executebuiltin("XBMC.Action(ContextMenu)")
        return

    if choice == 2:
        config.ADDON.openSettings()
        return

    if choice == 1:
        runExternal(path)
예제 #5
0
    def _checkStatus(self, response):
        Logger.log("_checkStatus response:%r" % response, Logger.LOG_DEBUG)
        statusOk = False
        print repr(response)
        if response:
            if self._accessDeniedFound(response):
                Logger.log("_checkStatus access is denied", Logger.LOG_ERROR)
                title, msg1, msg2 = self._accessDeniedMessage()
                self.kill()
            elif self._authenticationFailed(response):
                Logger.log("_checkStatus authetication failed", Logger.LOG_ERROR)
                title, msg1, msg2 = __language__(30038), __language__(30005), ""
            elif self._isEnabled(response):
                Logger.log("_checkStatus enabled", Logger.LOG_DEBUG)
                title, msg1, msg2 = self._connectionOkMessage()
                statusOk = True
            elif self._isNetworkUnreachable(response):
                Logger.log("_checkStatus network unreachable", Logger.LOG_DEBUG)
                title, msg1, msg2 = __language__(30039), __language__(30004), ""
            else:
                Logger.log("_checkStatus failed other reason", Logger.LOG_DEBUG)
                self.kill()
                title, msg1, msg2 = self._connectionFailedMessage()

            if statusOk:
                self._allowActionConnected()
            else:
                self._allowActionError(title + " " + msg1)
            gui.DialogOK(title, msg1, msg2)
예제 #6
0
    def _checkStatus(self, response):
        Logger.log("_checkStatus response:%r" % response, Logger.LOG_DEBUG)
        statusOk = False
        print repr(response)
        if response:
            if self._accessDeniedFound(response):
                Logger.log("_checkStatus access is denied", Logger.LOG_ERROR)
                title, msg1, msg2 = self._accessDeniedMessage()
                self.kill()
            elif self._authenticationFailed(response):
                Logger.log("_checkStatus authetication failed",
                           Logger.LOG_ERROR)
                title, msg1, msg2 = __language__(30038), __language__(
                    30005), ""
            elif self._isEnabled(response):
                Logger.log("_checkStatus enabled", Logger.LOG_DEBUG)
                title, msg1, msg2 = self._connectionOkMessage()
                statusOk = True
            elif self._isNetworkUnreachable(response):
                Logger.log("_checkStatus network unreachable",
                           Logger.LOG_DEBUG)
                title, msg1, msg2 = __language__(30039), __language__(
                    30004), ""
            else:
                Logger.log("_checkStatus failed other reason",
                           Logger.LOG_DEBUG)
                self.kill()
                title, msg1, msg2 = self._connectionFailedMessage()

            if statusOk:
                self._allowActionConnected()
            else:
                self._allowActionError(title + " " + msg1)
            gui.DialogOK(title, msg1, msg2)
예제 #7
0
 def _connectionOkMessage(self):
     networkInfo = GetPublicNetworkInformation()
     if networkInfo:
         ipAddress, country, city = networkInfo
         return __language__(30024), __language__(
             30025) % ipAddress, "%s, %s" % (city.title(), country.title())
     return __language__(30026) % self._countryName, '', ''
예제 #8
0
def addCitiesForCountry(countryName):
    try:
        cities = VPNServerManager.getInstance().getCities(countryName)
        for city in cities:
            label = '%s (%d)' % (city[0], city[2])
            gui.addDir(arguments, label, _VPN, thumbnail=city[1], server=city[3], isFolder=False, countryName = countryName)
    except NoConnectionError:
        gui.DialogOK(__language__(30003), __language__(30004), __language__(30005))
예제 #9
0
    def _connectAndCheckStatus(self, busy = None):

        # Erase the Remote Controller status file because if not the Controller appends into that file
        self._eraseRemoteControllerStatusFile()

        Logger.log("Android _doConnect starting ...", Logger.LOG_DEBUG)

        ret = self._runRemoteController(self.OPENVPN_CONNECT_ACTION, self._timeout)
        if not ret:
            gui.DialogOK(__language__(30017), __language__(30018), "")
            return

        statusDone = False

        startTime = time.time()
        elapsed = 0
        MAX_TIMEOUT = 60
        statusGrabbed = False
        status = ''
        while elapsed < MAX_TIMEOUT:
            status = self._getCurrentStatus()
            Logger.log("Checking Status:%s" % status, Logger.LOG_DEBUG)

            ASSIGN_IP = 'ASSIGN_IP;'

            # Check if after the ASSIGN_IP notification a CONNECTED; SUCCESS is notified
            if ASSIGN_IP in status  and 'CONNECTED; SUCCESS' in status[status.find(ASSIGN_IP):]:
                Logger.log("VPN IP assigned and connected Ok", Logger.LOG_INFO)
                msg1, msg2, msg3 = self._connectionOkMessage()
                gui.DialogOK(msg1, msg2, msg3)
                statusGrabbed = True
                break

            elif 'USER_DID_NOT_APPROVE_THE_APP' in status:
                gui.DialogOK(__language__(30019), __language__(30005), "")
                statusGrabbed = True
                break

            elif 'EXITING; auth-failure' in status:
                gui.DialogOK(__language__(30038), __language__(30037), __language__(30005))
                self.kill()
                statusGrabbed = True
                break

            xbmc.sleep(1000)
            elapsed = time.time() - startTime

        Logger.log("_GetCurrent status:::")
        print status
        if not statusGrabbed:
            gui.DialogOK(__language__(30020), __language__(30021), __language__(30005))
            Logger.log("ERROR it break the loop with timeout. Check the notification status", Logger.LOG_ERROR)

        if busy:
            busy.close()

        return statusGrabbed
예제 #10
0
def connectToCustomServer():
    server = config.getConfiguredServerAddress()
    if not server:
        gui.addDir(arguments, __language__(30001), _SETTINGS, isFolder=False)
    else:
        gui.addDir(arguments,
                   __language__(30053),
                   _CUSTOM_CONNECT,
                   isFolder=False)
        gui.addDir(arguments, __language__(30002), _KILL, isFolder=False)
예제 #11
0
def addCitiesForCountry(countryName):
    try:
        cities = VPNServerManager.getInstance().getCities(countryName)
        for city in cities:
            label = '%s (%d)' % (city[0], city[2])
            gui.addDir(arguments,
                       label,
                       _VPN,
                       thumbnail=city[1],
                       server=city[3],
                       isFolder=False,
                       countryName=countryName)
    except NoConnectionError:
        gui.DialogOK(__language__(30003), __language__(30004),
                     __language__(30005))
예제 #12
0
    def _waitUntilVPNIsDisabled(self, timeout=90, checkForSudoFailed=True):
        Logger.log("Waiting until VPN is completely disabled")
        sleep_time_s = 1
        while timeout > 0:

            ret = self._getStdErrOutput()
            if "incorrect password attempt" in ret:
                raise AccessDeniedException(__language__(30036))

            if "openvpn: no process found" in ret:
                Logger.log(
                    "openvpn process was not found, so assuming vpn is disabled",
                    Logger.LOG_DEBUG)
                return True

            xbmc.sleep(sleep_time_s * 1000)
            timeout -= sleep_time_s

            ret = self._getOpenVPNOutput()
            # Even if it is disabled or the file does not exists (because it never started running) the VPN is disabled
            if ret is None or self._isDisabled(ret):
                Logger.log("VPN is disabled now")
                return True

        Logger.log("VPN has not been disabled...", Logger.LOG_ERROR)
        print ret
        return False
예제 #13
0
    def _waitUntilVPNIsDisabled(self, timeout = 90, checkForSudoFailed = True):
        Logger.log("Waiting until VPN is completely disabled")
        sleep_time_s = 1
        while timeout > 0:

            ret = self._getStdErrOutput()
            if "incorrect password attempt" in ret:
                raise AccessDeniedException(__language__(30036))

            if "openvpn: no process found" in ret:
                Logger.log("openvpn process was not found, so assuming vpn is disabled", Logger.LOG_DEBUG)
                return True

            xbmc.sleep(sleep_time_s * 1000)
            timeout -= sleep_time_s

            ret = self._getOpenVPNOutput()
            # Even if it is disabled or the file does not exists (because it never started running) the VPN is disabled
            if ret is None or self._isDisabled(ret):
                Logger.log("VPN is disabled now")
                return True


        Logger.log("VPN has not been disabled...", Logger.LOG_ERROR)
        print ret
        return False
예제 #14
0
def Main():
    common.CheckVersion()
    common.CheckUsername()

    if config.isVPNCustom():
        connectToCustomServer()
        return

    gui.addDir(arguments, __language__(30001), _SETTINGS,  isFolder=False)
    gui.addDir(arguments, __language__(30002),   _KILL,      isFolder=False)
    gui.addDir(arguments, ' ',             _SEPARATOR, isFolder=False)

    try:
        for country in VPNServerManager.getInstance().getCountries():
            gui.addDir(arguments, country[0], _COUNTRY, abrv=country[1], thumbnail=country[2])
    except NoConnectionError:
        gui.DialogOK( __language__(30003),  __language__(30004), __language__(30005))
예제 #15
0
    def _writeAuthentication(self):
        authPath = os.path.join(config.PROFILE, 'temp')
        common.CheckUsername()

        user = self._getUsername()
        pwd  = config.getPassword()

        if user == '' or pwd == '':
            gui.DialogOK(__language__(30029), __language__(30030), '')
            return None

        f = open(authPath, mode='w')
        data = [user, '\r\n', pwd, '\r\n']
        f.writelines(data)
        f.close()

        return authPath
예제 #16
0
    def _writeAuthentication(self):
        authPath = os.path.join(config.PROFILE, 'temp')
        common.CheckUsername()

        user = self._getUsername()
        pwd = config.getPassword()

        if user == '' or pwd == '':
            gui.DialogOK(__language__(30029), __language__(30030), '')
            return None

        f = open(authPath, mode='w')
        data = [user, '\r\n', pwd, '\r\n']
        f.writelines(data)
        f.close()

        return authPath
예제 #17
0
    def _kill(self, wait = True):
        ret = False
        try:
            Logger.log("Unix trying to kill openvpn")
            # We should try with sigint so let openvpn to disconnect properly
            cmd = self._getKillCmd()
            Logger.log("Killing cmd:%r" % cmd)
            cmd = self._addSudoIfNeeded(cmd)

            shell = self._needShell()
            strErrFile  = open(config.StdErrLogFilePath, mode='w')

            ps = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE, stderr=strErrFile)
            ret = self._waitUntilVPNIsDisabled(checkForSudoFailed = True)
            strErrFile.close()
        except AccessDeniedException, e:
            gui.DialogOK(e.args[0], __language__(30037), __language__(30005))
            return False
예제 #18
0
    def _getItems(self):
        ret = self._getItemsFromBase()
        if ret:
            return ret

        try:
            html  = GetContentFromUrl(self.URL)
            return re.compile(self.REGEX).findall(html)
        except urllib2.URLError, e:
            Logger.log("There was an error while getting content from remote server")
            raise NoConnectionError(__language__(30042) )
예제 #19
0
    def _getItems(self):
        ret = self._getItemsFromBase()
        if ret:
            return ret

        try:
            html = GetContentFromUrl(self.URL)
            return re.compile(self.REGEX).findall(html)
        except urllib2.URLError, e:
            Logger.log(
                "There was an error while getting content from remote server")
            raise NoConnectionError(__language__(30042))
예제 #20
0
    def _prepareCmd(self):
        executableFile = self._getOpenVPNExecPath()
        Logger.log("OpenVPN Client should be on:%s" % executableFile)
        if not executableFile:
            Logger.log(
                'Could not find a VPN application for %s' % config.getOS(),
                Logger.LOG_ERROR)
            gui.DialogOK(config.TITLE + ' - ' + config.VERSION,
                         __language__(30031) % config.getOS(),
                         __language__(30032))
            raise OpenVPNExeNotFoundException()

        configFilePath = self._getOpenVPNConfigPath()

        cmdline = '"' + executableFile + '"'
        cmdline += ' '
        cmdline += '"' + configFilePath + '"'
        cmdline = cmdline.replace('\\', '/')
        Logger.log("Cmd line before sudo:%s" % cmdline, Logger.LOG_DEBUG)
        cmdline = self._addSudoIfNeeded(cmdline)
        return cmdline
예제 #21
0
    def _kill(self):
        ret = False
        try:
            Logger.log("Unix trying to kill openvpn")
            # We should try with sigint so let openvpn to disconnect properly
            cmd = self._getKillCmd()
            Logger.log("Killing cmd:%r" % cmd)
            cmd = self._addSudoIfNeeded(cmd)

            shell = self._needShell()
            strErrFile = open(config.StdErrLogFilePath, mode='w')

            ps = subprocess.Popen(cmd,
                                  shell=shell,
                                  stdout=subprocess.PIPE,
                                  stderr=strErrFile)
            ret = self._waitUntilVPNIsDisabled(checkForSudoFailed=True)
            strErrFile.close()
        except AccessDeniedException, e:
            gui.DialogOK(e.args[0], __language__(30037), __language__(30005))
            return False
예제 #22
0
    def kill(self, showBusy = False):
        busy = None
        if showBusy:
            busy = gui.ShowBusy()

        self._eraseRemoteControllerStatusFile()

        Logger.log("Android kill. Disconnecting first attemp...")

        # The Remote Controller needs two disconnects in case the VPN bind fails
        ret = self._disconnect(3)
        if ret!=self.DISCONNECT_OK:
            Logger.log("Android kill. Disconnecting second attemp...")
            ret = self._disconnect(30)

            if ret==self.DISCONNECT_OK:
                Logger.log("Disconnection Ok...the VPN must be disconnected now", Logger.LOG_DEBUG)
                pass
            elif ret==self.NO_RESPONSE:
                gui.DialogOK(__language__(30012)  , __language__(30013))
                Logger.log("Error when trying to Kill the VPN: No notifications received from Remote Controller", Logger.LOG_ERROR)
            elif ret==self.DISCONNECT_TIMEOUT:
                gui.DialogOK(__language__(30014), __language__(30015), __language__(30005))
                Logger.log("Error when trying to disconnect the OpenVPN: it did not disconnect", Logger.LOG_ERROR)
            else:
                gui.DialogOK(__language__(30016), "", "")
                Logger.log("Unknown Error while disconnecting", Logger.LOG_ERROR)

        self._stopRemoteController()

        if busy:
            busy.close()

        return ret==self.DISCONNECT_OK
예제 #23
0
def Main():
    common.CheckVersion()
    common.CheckUsername()

    if config.isVPNCustom():
        connectToCustomServer()
        return

    gui.addDir(arguments, __language__(30001), _SETTINGS, isFolder=False)
    gui.addDir(arguments, __language__(30002), _KILL, isFolder=False)
    gui.addDir(arguments, ' ', _SEPARATOR, isFolder=False)

    try:
        for country in VPNServerManager.getInstance().getCountries():
            gui.addDir(arguments,
                       country[0],
                       _COUNTRY,
                       abrv=country[1],
                       thumbnail=country[2])
    except NoConnectionError:
        gui.DialogOK(__language__(30003), __language__(30004),
                     __language__(30005))
예제 #24
0
    def _writeOpenVPNConfiguration(self, authPath):
        crl = ''
        if self._isCustom:
            openVpnConfigFilePath = config.getOpenVPNCustomTemplateConfigFilePath(
            )
            if not os.path.exists(openVpnConfigFilePath):
                gui.DialogOK(__language__(30049), __language__(30050),
                             __language__(30005))
                return None

            cert = config.getCustomCertFilePath()
            if not os.path.exists(cert):
                gui.DialogOK(__language__(30051), __language__(30052),
                             __language__(30005))
                return None

            crl = config.getCustomCrlFilePath()

        else:
            openVpnConfigFilePath = config.getOpenVPNTemplateConfigFilePath()
            cert = config.getCertFilePath()

            if self._usingDathoFreeServers():
                cert = config.getDathoCertFilePath()
                Logger.log("Using datho cert:%s" % cert, Logger.LOG_DEBUG)

        file = open(openVpnConfigFilePath, mode='r')
        content = file.read()
        file.close()

        authPath = authPath.replace('\\', '/')
        cert = cert.replace('\\', '/')
        crl = crl.replace('\\', '/')

        print "SERVER ADDRESS:", self._serverAddress

        content = content.replace('#SERVER#', self._serverAddress)
        content = content.replace('#PORT#', self._port)
        content = content.replace('#CERTIFICATE#', '"' + cert + '"')
        content = content.replace('#AUTHENTICATION#', '"' + authPath + '"')
        content = content.replace('#CRL#', '"' + crl + '"')

        # Adding the log will disable the output to be written to stdout, so Windows will fail reading the status
        # so in case it is needed this should be added on the modifyOpenVPNConfigContent for the correspondent OS
        #content += "\r\nlog " +  "openvpn1.log"

        # The goal is to modify the OpenVPN Config for adding config options that may be needed for some OSs (like Linux Ubuntu)
        content = self._modifyOpenVPNConfigContent(content)

        Logger.log("OpenVPN configuration:%r" % content)

        cfgFilePath = self._getOpenVPNConfigPath()
        file = open(cfgFilePath, mode='w+')
        file.write(content)
        file.close()

        return cfgFilePath
예제 #25
0
    def _prepareCmdList(self):
        Logger.log("_prepareCmdList Preparing cmdList ...", Logger.LOG_DEBUG)

        executableFile = self._getOpenVPNExecPath()
        Logger.log("OpenVPN Client should be on:%s" % executableFile)
        if not executableFile:
            Logger.log(
                'Could not find a VPN application for %s' % config.getOS(),
                Logger.LOG_ERROR)
            gui.DialogOK(config.TITLE + ' - ' + config.VERSION,
                         __language__(30040) % config.getOS(),
                         __language__(30041))
            raise OpenVPNExeNotFoundException()

        executableFile = executableFile.replace('\\', '/')
        configFilePath = self._getOpenVPNConfigPath()
        configFilePath = configFilePath.replace('\\', '/')

        cmdList = [executableFile, configFilePath]

        Logger.log("Cmd list before sudo:%r" % cmdList, Logger.LOG_DEBUG)
        cmdList = self._addSudoIfNeeded(cmdList)
        Logger.log("Cmd list before sudo:%r" % cmdList, Logger.LOG_DEBUG)
        return cmdList
예제 #26
0
def CheckVersion():
    prev = config.ADDON.getSetting('VERSION')
    curr = config.VERSION

    msg = __language__(30043) % config.VERSION

    Logger.log(msg, Logger.LOG_ERROR)

    if prev == curr:
        return

    config.ADDON.setSetting('VERSION', curr)

    if prev == '0.0.0':
        gui.DialogOK(msg)
예제 #27
0
def CheckVersion():
    prev = config.ADDON.getSetting('VERSION')
    curr = config.VERSION

    msg = __language__(30043) % config.VERSION

    Logger.log(msg, Logger.LOG_ERROR)

    if prev == curr:
        return

    config.ADDON.setSetting('VERSION', curr)


    if prev == '0.0.0':
        gui.DialogOK(msg)
예제 #28
0
    def _writeOpenVPNConfiguration(self, authPath):
        crl  = ''
        if self._isCustom:
            openVpnConfigFilePath  = config.getOpenVPNCustomTemplateConfigFilePath()
            if not os.path.exists(openVpnConfigFilePath):
                gui.DialogOK(__language__(30049), __language__(30050), __language__(30005) )
                return None

            cert    = config.getCustomCertFilePath()
            if not os.path.exists(cert):
                gui.DialogOK(__language__(30051), __language__(30052), __language__(30005) )
                return None

            crl = config.getCustomCrlFilePath()

        else:
            openVpnConfigFilePath  = config.getOpenVPNTemplateConfigFilePath()
            cert    = config.getCertFilePath()

            if self._usingDathoFreeServers():
                cert = config.getDathoCertFilePath()
                Logger.log("Using datho cert:%s" % cert, Logger.LOG_DEBUG)

        file    = open(openVpnConfigFilePath, mode='r')
        content = file.read()
        file.close()

        authPath = authPath.replace('\\', '/')
        cert     = cert.replace('\\', '/')
        crl     = crl.replace('\\', '/')

        print "SERVER ADDRESS:", self._serverAddress

        content = content.replace('#SERVER#',               self._serverAddress)
        content = content.replace('#PORT#',                 self._port)
        content = content.replace('#CERTIFICATE#',    '"' + cert     + '"')
        content = content.replace('#AUTHENTICATION#', '"' + authPath + '"')
        content = content.replace('#CRL#', '"' + crl + '"')


        # Adding the log will disable the output to be written to stdout, so Windows will fail reading the status
        # so in case it is needed this should be added on the modifyOpenVPNConfigContent for the correspondent OS
        #content += "\r\nlog " +  "openvpn1.log"

        # The goal is to modify the OpenVPN Config for adding config options that may be needed for some OSs (like Linux Ubuntu)
        content = self._modifyOpenVPNConfigContent(content)

        Logger.log("OpenVPN configuration:%r" % content)

        cfgFilePath = self._getOpenVPNConfigPath()
        file = open(cfgFilePath, mode='w+')
        file.write(content)
        file.close()

        return cfgFilePath
예제 #29
0
    def _prepareCmd(self):
        executableFile = self._getOpenVPNExecPath()
        Logger.log("OpenVPN Client should be on:%s" % executableFile)
        if not executableFile:
            Logger.log('Could not find a VPN application for %s' % config.getOS(), Logger.LOG_ERROR)
            gui.DialogOK(config.TITLE + ' - ' + config.VERSION, __language__(30031) % config.getOS(), __language__(30032))
            raise OpenVPNExeNotFoundException()


        configFilePath = self._getOpenVPNConfigPath()


        cmdline = '"' + executableFile + '"'
        cmdline += ' '
        cmdline += '"' + configFilePath + '"'
        cmdline  = cmdline.replace('\\', '/')
        Logger.log("Cmd line before sudo:%s" % cmdline, Logger.LOG_DEBUG)
        cmdline = self._addSudoIfNeeded(cmdline)
        return cmdline
예제 #30
0
    def _prepareCmdList(self):
        Logger.log("_prepareCmdList Preparing cmdList ...", Logger.LOG_DEBUG)

        executableFile = self._getOpenVPNExecPath()
        Logger.log("OpenVPN Client should be on:%s" % executableFile)
        if not executableFile:
            Logger.log('Could not find a VPN application for %s' % config.getOS(), Logger.LOG_ERROR)
            gui.DialogOK(config.TITLE + ' - ' + config.VERSION, __language__(30040) % config.getOS(), __language__(30041))
            raise OpenVPNExeNotFoundException()

        executableFile = executableFile.replace('\\', '/')
        configFilePath = self._getOpenVPNConfigPath()
        configFilePath = configFilePath.replace('\\', '/')

        cmdList = [executableFile, configFilePath]


        Logger.log("Cmd list before sudo:%r" % cmdList, Logger.LOG_DEBUG)
        cmdList = self._addSudoIfNeeded(cmdList)
        Logger.log("Cmd list before sudo:%r" % cmdList, Logger.LOG_DEBUG)
        return cmdList
예제 #31
0
    def kill(self, showBusy=False):
        busy = None
        if showBusy:
            busy = gui.ShowBusy()

        self._eraseRemoteControllerStatusFile()

        Logger.log("Android kill. Disconnecting first attemp...")

        # The Remote Controller needs two disconnects in case the VPN bind fails
        ret = self._disconnect(3)
        if ret != self.DISCONNECT_OK:
            Logger.log("Android kill. Disconnecting second attemp...")
            ret = self._disconnect(30)

            if ret == self.DISCONNECT_OK:
                Logger.log(
                    "Disconnection Ok...the VPN must be disconnected now",
                    Logger.LOG_DEBUG)
                pass
            elif ret == self.NO_RESPONSE:
                gui.DialogOK(__language__(30012), __language__(30013))
                Logger.log(
                    "Error when trying to Kill the VPN: No notifications received from Remote Controller",
                    Logger.LOG_ERROR)
            elif ret == self.DISCONNECT_TIMEOUT:
                gui.DialogOK(__language__(30014), __language__(30015),
                             __language__(30005))
                Logger.log(
                    "Error when trying to disconnect the OpenVPN: it did not disconnect",
                    Logger.LOG_ERROR)
            else:
                gui.DialogOK(__language__(30016), "", "")
                Logger.log("Unknown Error while disconnecting",
                           Logger.LOG_ERROR)

        self._stopRemoteController()

        if busy:
            busy.close()

        return ret == self.DISCONNECT_OK
예제 #32
0
 def _accessDeniedMessage(self):
     return __language__(30033) , __language__(30034), __language__(30035)
예제 #33
0
def CheckUsername():
    if config.CheckCredentialsEmpty():
        gui.DialogOK(__language__(30044))
        gui.ShowSettings()
예제 #34
0
 def _connectionFailedMessage(self):
     return __language__(30027) % self._countryName, __language__(30028), __language__(30005)
예제 #35
0
 def _connectionOkMessage(self):
     networkInfo = GetPublicNetworkInformation()
     if networkInfo:
         ipAddress, country, city = networkInfo
         return __language__(30024), __language__(30025) % ipAddress, "%s, %s" % (city.title(), country.title())
     return __language__(30026) % self._countryName, '', ''
예제 #36
0
 def _connectionFailedMessage(self):
     return __language__(30027) % self._countryName, __language__(
         30028), __language__(30005)
예제 #37
0
def CheckUsername():
    if config.CheckCredentialsEmpty():
        gui.DialogOK(__language__(30044))
        gui.ShowSettings()
예제 #38
0
 def _accessDeniedMessage(self):
     return __language__(30033), __language__(30034), __language__(30035)
예제 #39
0
    abrv = urllib.unquote_plus(params['abrv'])
    server = urllib.unquote_plus(params['server'])
    country = urllib.unquote_plus(params['country'])

    city = label.rsplit(' (', 1)[0]
    vpnConnector = VPNConnectorFactory.getConnector(country, city, server)
    vpnConnector.connectToVPNServer()

elif mode == _SETTINGS:
    gui.ShowSettings()

elif mode == _KILL:
    vpnConnector = VPNConnectorFactory.getConnector()
    ret = vpnConnector.kill(showBusy=True)
    if ret:
        gui.DialogOK(__language__(30006))
    else:
        gui.DialogOK(__language__(30007), __language__(30008))

elif mode == _CUSTOM_CONNECT:
    server = config.getConfiguredServerAddress()
    gui.DialogOK(__language__(30045), __language__(30046) % server, "")
    vpnConnector = VPNConnectorFactory.getConnector(serverAddress=server,
                                                    custom=True)
    vpnConnector.connectToVPNServer()

elif mode == _SEPARATOR:
    pass

else:
    Main()
예제 #40
0
    country = urllib.unquote_plus(params['country'])

    city = label.rsplit(' (', 1)[0]
    vpnConnector = VPNConnectorFactory.getConnector(country, city, server)
    vpnConnector.connectToVPNServer()
    vpnConnector.stopThreads()

elif mode == _SETTINGS:
    gui.ShowSettings()

elif mode == _KILL:
    vpnConnector = VPNConnectorFactory.getConnector()
    ret = vpnConnector.kill(showBusy=True)
    vpnConnector.stopThreads()
    if ret:
        gui.DialogOK(__language__(30006))
    else:
        gui.DialogOK(__language__(30007), __language__(30008))

elif mode == _CUSTOM_CONNECT:
    server = config.getConfiguredServerAddress()
    gui.DialogOK( __language__(30045),  __language__(30046) % server, "")
    vpnConnector = VPNConnectorFactory.getConnector(serverAddress = server, custom=True)
    vpnConnector.connectToVPNServer()
    vpnConnector.stopThreads()


elif mode == _SEPARATOR:
    pass

else:
예제 #41
0
    def _connectAndCheckStatus(self, busy=None):

        # Erase the Remote Controller status file because if not the Controller appends into that file
        self._eraseRemoteControllerStatusFile()

        Logger.log("Android _doConnect starting ...", Logger.LOG_DEBUG)

        ret = self._runRemoteController(self.OPENVPN_CONNECT_ACTION,
                                        self._timeout)
        if not ret:
            gui.DialogOK(__language__(30017), __language__(30018), "")
            return

        statusDone = False

        startTime = time.time()
        elapsed = 0
        MAX_TIMEOUT = 60
        statusGrabbed = False
        status = ''
        while elapsed < MAX_TIMEOUT:
            status = self._getCurrentStatus()
            Logger.log("Checking Status:%s" % status, Logger.LOG_DEBUG)

            ASSIGN_IP = 'ASSIGN_IP;'

            # Check if after the ASSIGN_IP notification a CONNECTED; SUCCESS is notified
            if ASSIGN_IP in status and 'CONNECTED; SUCCESS' in status[
                    status.find(ASSIGN_IP):]:
                Logger.log("VPN IP assigned and connected Ok", Logger.LOG_INFO)
                msg1, msg2, msg3 = self._connectionOkMessage()
                gui.DialogOK(msg1, msg2, msg3)
                statusGrabbed = True
                break

            elif 'USER_DID_NOT_APPROVE_THE_APP' in status:
                gui.DialogOK(__language__(30019), __language__(30005), "")
                statusGrabbed = True
                break

            elif 'EXITING; auth-failure' in status:
                gui.DialogOK(__language__(30038), __language__(30037),
                             __language__(30005))
                self.kill()
                statusGrabbed = True
                break

            xbmc.sleep(1000)
            elapsed = time.time() - startTime

        Logger.log("_GetCurrent status:::")
        print status
        if not statusGrabbed:
            gui.DialogOK(__language__(30020), __language__(30021),
                         __language__(30005))
            Logger.log(
                "ERROR it break the loop with timeout. Check the notification status",
                Logger.LOG_ERROR)

        if busy:
            busy.close()

        return statusGrabbed
예제 #42
0
 def _stopRemoteController(self, timeout = 15):
     Logger.log("Android _forceAndroidControllerStop", Logger.LOG_DEBUG)
     ret = self._runRemoteController(self.CONTROLLER_FINISH, timeout)
     if not ret:
         Logger.log("Remote Controller did not respond the FINISH command", Logger.LOG_ERROR)
         gui.DialogOK(__language__(30022), __language__(30023))