def Network():
    address = requests.get('https://api.ipify.org').text
    country = xbmcgui.Window(10000).getProperty('VPNICITY_LABEL')
    
    message = 'IP Address: %s  Country: %s' % (address, country)

    utils.notify(message)
    utils.log('VPNicity location is: ' + message)
Exemple #2
0
def getPreviousTime():
    utils.log('================== in getPreviousTime ==================')
    time_object = utils.GetSetting('LOGIN_TIME')

    if time_object == '':
        time_object = '2001-01-01 00:00:00'

    previousTime = parseTime(time_object)

    return previousTime
Exemple #3
0
def getPreviousTime():
    utils.log('================== in getPreviousTime ==================')
    time_object = utils.GetSetting('LOGIN_TIME')
    
    if time_object == '':
        time_object = '2001-01-01 00:00:00'
        
    previousTime = parseTime(time_object)
    
    return previousTime
Exemple #4
0
def Main():
    import message
    message.check()
    utils.checkVersion()
    CheckPlugin()
    vpn.CheckUsername()

    if not vpn.validToRun():
        utils.log('Login Error')
        return

    # utils.checkOS()

    addDir('-- Configure %s' % TITLE, _SETTINGS, isFolder=False)

    current = xbmcgui.Window(10000).getProperty('VPNICITY_LABEL')

    if len(current) > 0:
        abrv = xbmcgui.Window(10000).getProperty('VPNICITY_ABRV')
        thumbnail = utils.DISABLE  #'os.path.join(IMAGES, abrv.lower()+'.png')
        addDir('-- Disable %s %s' % (current, TITLE),
               _KILL,
               thumbnail=thumbnail,
               isFolder=False)

    mode = _COUNTRY
    isFolder = True

    if ADDON.getSetting('AUTO') == 'true':
        mode = _VPN
        isFolder = False

    countries = vpn.GetCountries()

    CreateFile('-Remove-')

    for country in countries:
        label = country[0]
        menu = []
        menu.append((ENABLEAUTO % label, 'XBMC.RunPlugin(%s?mode=%d&abrv=%s)' %
                     (sys.argv[0], _AUTO, urllib.quote_plus(country[2]))))
        thumbnail = os.path.join(IMAGES, country[2].lower() + '.png')
        addDir(label,
               mode,
               abrv=country[1],
               thumbnail=thumbnail,
               isFolder=isFolder,
               menu=menu)

        try:
            CreateFile(country[0], country[1])
        except:
            pass
def _check():
    response = urllib2.urlopen(URL).read()

    utils.log('Response in message._check %s' % str(response))

    response = json.loads(u"" + (response))

    try:
        currentID = utils.GetSetting('messageID')
        currentID = float(currentID)
    except Exception, e:
        print str(e)
        currentID = 0
Exemple #6
0
def validToRun():
    utils.log('================== in validToRun ==================')
    previousTime = getPreviousTime()
    now = datetime.datetime.today()
    delta = now - previousTime
    nSeconds = (delta.days * 86400) + delta.seconds

    if nSeconds > 35 * 60:
        if not Login():
            return False

        ADDON.setSetting('LOGIN_TIME', str(now))

    return True
Exemple #7
0
def VPN(label, abrv, server):
    if not validToRun():
        utils.log('Login Error via Context Menu')
        return False

    authPath = os.path.join(PROFILE, 'temp')
    cfgPath = os.path.join(PROFILE, 'cfg.ovpn')

    KillVPN(silent=True)

    WriteAuthentication(authPath)
    WriteConfiguration(server, cfgPath, authPath)

    busy = utils.showBusy()

    response = OpenVPN(cfgPath)

    if busy:
        busy.close()

    success = True

    if response:
        label = label.rsplit(' (', 1)[0]
        if IsEnabled(response):
            # if utils.platform() == "android":
            #     xbmc.sleep(10000)
            message = '%s %s now enabled' % (label, TITLE)
            utils.notify(message)
            xbmcgui.Window(10000).setProperty('VPNICITY_LABEL', label)
            xbmcgui.Window(10000).setProperty('VPNICITY_ABRV', abrv)
            xbmcgui.Window(10000).setProperty('VPNICITY_SERVER', server)
            xbmcgui.Window(10000).setProperty('VPNICITY_CONNECTED', 'True')
            ipcheck.Network()

        else:
            KillVPN(silent=True)
            if utils.platform() == "android":
                xbmc.sleep(5000)
            message = '%s %s failed to start. Please check your settings.' % (
                label, TITLE)
            utils.notify(message)
            ipcheck.Network()
            success = False

    #DeleteFile(authPath)
    #DeleteFile(cfgPath)
    #DeleteFile(RESPONSE)

    return success
Exemple #8
0
def validToRun():
    utils.log('================== in validToRun ==================')
    previousTime = getPreviousTime()
    now          = datetime.datetime.today()
    delta        = now - previousTime
    nSeconds     = (delta.days * 86400) + delta.seconds
    
    if nSeconds > 35 * 60:
        if not Login():
            return False

        ADDON.setSetting('LOGIN_TIME', str(now))
        
    return True
Exemple #9
0
def Run(cmdline, timeout=0):
    if utils.platform() == "android":
        return RunAndroid(cmdline, timeout)

    utils.log('COMMAND - %s' % cmdline)

    ret = 'Error: Process failed to start'

    if timeout > 0:
        path = RESPONSE

        shell = True

        si = None
        if os.name == 'nt':
            shell = False
            si = subprocess.STARTUPINFO
            si.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
            si.wShowWindow = subprocess._subprocess.SW_HIDE

        f  = open(path, mode='w')
        ps = subprocess.Popen(cmdline, shell=shell, stdout=f, startupinfo=si)

        xbmc.sleep(5000)

        while timeout > 0:
            xbmc.sleep(1000)
            timeout -= 1

            f1  = open(path, mode='r')
            ret = f1.read()
            f1.close()

            if IsEnabled(ret) or IsDisabled(ret):
                timeout = 0

        f.close()

    else:
        ps  = subprocess.Popen(cmdline, shell=False, stdout=subprocess.PIPE)
        ret = ps.stdout.read()
        ps.stdout.close()

    #try:
    #    utils.log('RESULT - %s' % str(ret))
    #except:
    #    pass

    return ret
Exemple #10
0
def VPN(label, abrv, server):
    if not validToRun():
        utils.log('Login Error via Context Menu')
        return False

    authPath = os.path.join(PROFILE, 'temp')
    cfgPath  = os.path.join(PROFILE, 'cfg.ovpn')

    KillVPN(silent=True)

    WriteAuthentication(authPath)
    WriteConfiguration(server, cfgPath, authPath)

    busy = utils.showBusy()

    response = OpenVPN(cfgPath)

    if busy:
        busy.close()

    success = True

    if response:
        label = label.rsplit(' (', 1)[0]
        if IsEnabled(response):
            # if utils.platform() == "android":
            #     xbmc.sleep(10000)
            message = '%s %s now enabled' % (label, TITLE)
            utils.notify(message)         
            xbmcgui.Window(10000).setProperty('VPNICITY_LABEL',  label)
            xbmcgui.Window(10000).setProperty('VPNICITY_ABRV',   abrv)
            xbmcgui.Window(10000).setProperty('VPNICITY_SERVER', server)
            xbmcgui.Window(10000).setProperty('VPNICITY_CONNECTED', 'True')
            ipcheck.Network()

        else:
            KillVPN(silent=True)
            if utils.platform() == "android":
                xbmc.sleep(5000)
            message = '%s %s failed to start. Please check your settings.' % (label, TITLE)
            utils.notify(message)
            ipcheck.Network() 
            success = False

    #DeleteFile(authPath)
    #DeleteFile(cfgPath)
    #DeleteFile(RESPONSE)

    return success
Exemple #11
0
def Run(cmdline, timeout=0):
    if utils.platform() == "android":
        return RunAndroid(cmdline, timeout)

    utils.log('COMMAND - %s' % cmdline)

    ret = 'Error: Process failed to start'

    if timeout > 0:
        path = RESPONSE

        shell = True

        si = None
        if os.name == 'nt':
            shell = False
            si = subprocess.STARTUPINFO
            si.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
            si.wShowWindow = subprocess._subprocess.SW_HIDE

        f = open(path, mode='w')
        ps = subprocess.Popen(cmdline, shell=shell, stdout=f, startupinfo=si)

        xbmc.sleep(5000)

        while timeout > 0:
            xbmc.sleep(1000)
            timeout -= 1

            f1 = open(path, mode='r')
            ret = f1.read()
            f1.close()

            if IsEnabled(ret) or IsDisabled(ret):
                timeout = 0

        f.close()

    else:
        ps = subprocess.Popen(cmdline, shell=False, stdout=subprocess.PIPE)
        ret = ps.stdout.read()
        ps.stdout.close()

    #try:
    #    utils.log('RESULT - %s' % str(ret))
    #except:
    #    pass

    return ret
def Network():
    url = 'http://www.iplocation.net/'
    request = requests.get(url)
    link = request.content
    match = re.compile(
        "<td width='80'>(.+?)</td><td>(.+?) <img src='.+?'></td><td>(.+?)</td><td>.+?</td><td>(.+?)</td>"
    ).findall(link)
    count = 1

    for ip, country, region, isp in match:
        if count < 2:
            message = 'IP Address: %s  Country: %s  Region: %s' % (ip, country,
                                                                   region)
            utils.notify(message)
            utils.log('VPNicity location is: %s' % match)
            count = count + 1
def Main():
    import message
    message.check()
    utils.checkVersion()
    vpn.CheckUsername()
    path.getPath(utils.ADDON.getSetting('OS'), silent=True)
    CheckPlugin()
    
    if not vpn.validToRun():
        utils.log('Login Error')
        return

    # utils.checkOS()

    addDir('-- Configure %s' % TITLE,   _SETTINGS,  isFolder=False)

    current = xbmcgui.Window(10000).getProperty('VPNICITY_LABEL')

    if len(current) > 0:
        abrv      = xbmcgui.Window(10000).getProperty('VPNICITY_ABRV')
        thumbnail = utils.DISABLE #'os.path.join(IMAGES, abrv.lower()+'.png')
        addDir('-- Disable %s %s' % (current, TITLE), _KILL, thumbnail=thumbnail, isFolder=False)

    mode     = _COUNTRY
    isFolder = True

    if ADDON.getSetting('AUTO') == 'true':
        mode     = _VPN
        isFolder = False

    countries = vpn.GetCountries()

    CreateFile('-Remove-')

    for country in countries:
        label = country[0]
        menu  = []
        menu.append((ENABLEAUTO % label, 'XBMC.RunPlugin(%s?mode=%d&abrv=%s)' % (sys.argv[0], _AUTO, urllib.quote_plus(country[2]))))
        thumbnail = os.path.join(IMAGES, country[2].lower()+'.png')
        addDir(label, mode, abrv=country[1], thumbnail=thumbnail, isFolder=isFolder, menu=menu)

        try:    CreateFile(country[0], country[1])
        except: pass
Exemple #14
0
def CheckUsername():
    utils.log('================== in CheckUsername ==================')
    user = USERNAME
    pwd  = PASSWORD

    if user != '' and pwd != '':
        return True

    dlg = utils.yesno('VPNicity requires a subscription.', '', 'Would you like to enter your account details now?')

    if dlg == 1:
        user = utils.dialogKB('', 'Enter Your VPNicity Username')
        pwd  = utils.dialogKB('', 'Enter Your VPNicity Password')
        
        ADDON.setSetting('USER', user)
        ADDON.setSetting('PASS', pwd)
        
        SetupAccount()
        
    return True
Exemple #15
0
def CheckUsername():
    utils.log('================== in CheckUsername ==================')
    user = USERNAME
    pwd = PASSWORD

    if user != '' and pwd != '':
        return True

    dlg = utils.yesno('VPNicity requires a subscription.', '',
                      'Would you like to enter your account details now?')

    if dlg == 1:
        user = utils.dialogKB('', 'Enter Your VPNicity Username')
        pwd = utils.dialogKB('', 'Enter Your VPNicity Password')

        ADDON.setSetting('USER', user)
        ADDON.setSetting('PASS', pwd)

        SetupAccount()

    return True
Exemple #16
0
def OpenVPN(config):
    import path
    exe = path.getPath(ADDON.getSetting('OS'))

    if not exe:
        return None

    try:    timeout  = int(ADDON.getSetting('TIMEOUT'))
    except: timeout  = 99999

    if utils.platform() == "android":
        cmdline = "StartAndroidActivity(%s,%s,%s,%s)" % \
                    ( "com.vpnicity.openvpn.control", "com.vpnicity.openvpn.control.CONNECT", "com.vpnicity.openvpn.control.PROFILE_PATH", "file://" + config )
    else :
        cmdline  =  utils.getSudo()
        cmdline += '"' + exe + '"'
        cmdline += ' '
        cmdline += '"' + config + '"'
        cmdline  = cmdline.replace('\\', '/')

    utils.log('COMMAND - %s' % cmdline)
    return Run(cmdline, timeout)
def vpnConnect():
        try:
            install_file(filename)
        
            passed = (sfile.exists(file))
        
            if passed: 
                utils.log('Installing VPNicity Connect Plugin...PASSED')
            else:
                utils.log('Installing VPNicity Connect Plugin...FAILED')
        
            return passed
        
        except Exception, e:
            utils.log('Installing VPNicity Connect Plugin...EXCEPTION %s' % str(e))
Exemple #18
0
def vpnConnect():
        try:
            install_file(filename)
        
            passed = (sfile.exists(file))
        
            if passed: 
                utils.log('Installing VPNicity Connect Plugin...PASSED')
            else:
                utils.log('Installing VPNicity Connect Plugin...FAILED')
        
            utils.SetSetting('SFPLUGIN', 'true')
            utils.SetSetting('CONTEXT', 'false')
        
            return passed
        
        except Exception, e:
            utils.log('Installing VPNicity Connect Plugin...EXCEPTION %s' % str(e))
Exemple #19
0
def Login():
    utils.log('================ VPNicity Login ================')
    with requests.Session() as s:
        try:
            s.get(LOGINURL)
        except: 
            return False
        
        USER     = ADDON.getSetting('USER')
        PASS     = ADDON.getSetting('PASS')
        PAYLOAD  = { 'log' : USER, 'pwd' : PASS, 'wp-submit' : 'Log In' }
        response = 'login_error'
        code     =  0

        if USER and PASS:
            login    = s.post(LOGINURL, data=PAYLOAD)
            response = login.content
            # code     = login.status_code
            # saveCookies(s.cookies, cookiefile)
        
        if 'no-access-redirect' in response:
            error   = '301 - No Access.'
            message = 'It appears that your subscription has expired.'
            utils.log(message + ' : ' + error)
            utils.dialogOK(message, error, 'Please check your account at www.vpnicity.com')

            KillVPN(silent=True)
            
            return False
            
        areLost    = 'Are you lost' in response
        loginError = 'login_error' in response
        okay       =  (not areLost) and (not loginError)
        
        if okay:
            message = 'Logged into VPNicity'
            utils.log(message)
            utils.notify(message)
            return True
            
        try:
            error = re.compile('<div id="login_error">(.+?)<br />').search(response).groups(1)[0]
            error = error.replace('<strong>',  '')
            error = error.replace('</strong>', '')
            error = error.replace('<a href="https://www.vpnicity.com/wp-login.php?action=lostpassword">Lost your password?</a>', '')
            error = error.strip()
            print error
        except:
            error = ''
            
        message = 'There was a problem logging into VPNicity'
        
        utils.log('************ VPNicity Error ************')
        utils.log(message + ' : ' + error)
        utils.log('****************************************')
        utils.dialogOK(message, error, 'Please check your account at www.vpnicity.com')
        
        KillVPN(silent=True)
        
    return False
Exemple #20
0
def Login():
    utils.log('================ VPNicity Login ================')
    with requests.Session() as s:
        try:
            s.get(LOGINURL)
        except:
            return False

        USER = ADDON.getSetting('USER')
        PASS = ADDON.getSetting('PASS')
        PAYLOAD = {'log': USER, 'pwd': PASS, 'wp-submit': 'Log In'}
        response = 'login_error'
        code = 0

        if USER and PASS:
            login = s.post(LOGINURL, data=PAYLOAD)
            response = login.content
            # code     = login.status_code
            # saveCookies(s.cookies, cookiefile)

        if 'no-access-redirect' in response:
            error = '301 - No Access.'
            message = 'It appears that your subscription has expired.'
            utils.log(message + ' : ' + error)
            utils.dialogOK(message, error,
                           'Please check your account at www.vpnicity.com')

            KillVPN(silent=True)

            return False

        areLost = 'Are you lost' in response
        loginError = 'login_error' in response
        okay = (not areLost) and (not loginError)

        if okay:
            message = 'Logged into VPNicity'
            utils.log(message)
            utils.notify(message)
            return True

        try:
            error = re.compile('<div id="login_error">(.+?)<br />').search(
                response).groups(1)[0]
            error = error.replace('<strong>', '')
            error = error.replace('</strong>', '')
            error = error.replace(
                '<a href="https://www.vpnicity.com/wp-login.php?action=lostpassword">Lost your password?</a>',
                '')
            error = error.strip()
            print error
        except:
            error = ''

        message = 'There was a problem logging into VPNicity'

        utils.log('************ VPNicity Error ************')
        utils.log(message + ' : ' + error)
        utils.log('****************************************')
        utils.dialogOK(message, error,
                       'Please check your account at www.vpnicity.com')

        KillVPN(silent=True)

    return False
Exemple #21
0
def check(path):
    path = path.replace('/', os.sep)
    utils.log('VPNicity binary path is: ' + path)
    return os.path.exists(path)
def check():
    try:
        return _check()
    except Exception, e:
        utils.log('Error in message.check %s' % str(e))
        return False
def parseDate(dateString):
    try:
        return datetime.datetime.strptime(dateString, '%d/%m/%Y')
    except Exception, e:
        utils.log('Error in parseDate %s' % str(dateString))
        utils.log(e)
    expires = parseDate(response['Expires'])

    now = datetime.datetime.now()

    if live > now:
        return False

    if now > expires:
        return False

    try:    title = response['Title']
    except: title = getString(1)

    try:    line1 = response['Line1']
    except: line1 = ''

    try:    line2 = response['Line2']
    except: line2 = ''

    try:    line3 = response['Line3']
    except: line3 = ''    

    utils.log('Displaying announcement %s' % str(newID))
    utils.log(title)
    utils.log(line1)
    utils.log(line2)
    utils.log(line3)

    dlg = xbmcgui.Dialog()
    dlg.ok(title, line1, line2, line3)
    return True