Пример #1
0
def renewNordVPN(renew):
    # Renew a user with the API and store the tokens returned
    response = ""
    try:        
        download_url = "https://api.nordvpn.com/v1/users/tokens/renew"
        download_data = "renewToken=" + renew
        if ifHTTPTrace(): infoTrace("alternativeNord.py", "Renewing authentication using " + download_url + ", " + download_data)
        else: debugTrace("Renewing authentication")
        req = Request(download_url, download_data)
        t_before = now()
        response = urlopen(req, timeout=10)
        user_data = json.load(response)
        t_after = now()
        response.close()
        if ifJSONTrace(): infoTrace("alternativeNord.py", "JSON received is \n" + json.dumps(user_data, indent=4))
        if t_after - t_before > TIME_WARN: infoTrace("alternativeNord.py", "Renewing authentication took " + str(t_after - t_before) + " seconds")
        setTokens(user_data["token"], user_data["renew_token"], None)
        return True
    except HTTPError as e:
        errorTrace("alternativeNord.py", "Couldn't renew user token")
        errorTrace("alternativeNord.py", "API call was " + download_url + ", " + download_data[:download_data.index("renewToken")+11] + "********")
        errorTrace("alternativeNord.py", "Response was " + str(e.code) + " " + e.reason)
        errorTrace("alternativeNord.py", e.read())
    except Exception as e:
        errorTrace("alternativeNord.py", "Couldn't renew user token")
        errorTrace("alternativeNord.py", "API call was " + download_url + ", " + download_data[:download_data.index("renewToken")+11] + "********")
        errorTrace("alternativeNord.py", "Response was " + str(type(e)) + " " + str(e))
    resetTokens()
    return False 
Пример #2
0
def authenticateNordVPN(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _, _, _, creds = getTokens()
    if creds == vpn_provider + userid + password:
        debugTrace("Previous authentication was good")
        return True

    response = ""
    try:
        download_url = "https://api.nordvpn.com/v1/users/tokens"
        download_data = urllib.urlencode({
            'username': userid,
            'password': password
        })
        if ifHTTPTrace():
            infoTrace(
                "alternativeNord.py", "Authenticating with VPN using " +
                download_url + ", " + download_data)
        else:
            debugTrace("Authenticating with VPN for user " + userid)
        req = urllib2.Request(download_url, download_data)
        t_before = now()
        response = urllib2.urlopen(req, timeout=10)
        user_data = json.load(response)
        t_after = now()
        response.close()
        if ifJSONTrace():
            infoTrace("alternativeNord.py",
                      "JSON received is \n" + json.dumps(user_data, indent=4))
        if t_after - t_before > TIME_WARN:
            infoTrace(
                "alternativeNord.py", "Authenticating with VPN for " + userid +
                " took " + str(t_after - t_before) + " seconds")
        setTokens(user_data["token"], user_data["renew_token"], None)
        setTokens(user_data["token"], user_data["renew_token"],
                  vpn_provider + userid + password)
        return True
    except urllib2.HTTPError as e:
        errorTrace("alternativeNord.py",
                   "Couldn't authenticate with " + vpn_provider)
        errorTrace(
            "alternativeNord.py", "API call was " + download_url + ", " +
            download_data[:download_data.index("&password") + 10] + "********")
        errorTrace("alternativeNord.py",
                   "Response was " + str(e.code) + " " + e.reason)
        errorTrace("alternativeNord.py", e.read())
    except Exception as e:
        errorTrace("alternativeNord.py",
                   "Couldn't authenticate with " + vpn_provider)
        errorTrace(
            "alternativeNord.py", "API call was " + download_url + ", " +
            download_data[:download_data.index("&password") + 10] + "********")
        errorTrace("alternativeNord.py",
                   "Response was " + str(type(e)) + " " + str(e))
    resetTokens()
    return False
Пример #3
0
def authenticateShellfire(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _,_,_, creds = getTokens()
    if creds == vpn_provider + userid + password: 
        debugTrace("Previous authentication was good")
        return True
    
    # Get the authentication token to use on future calls
    resetTokens()
    rc, api_data = sendAPI("?action=login", "Authenticating with VPN", '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return False
        
    # Extract the auth token and store it
    auth_token = api_data["data"]["token"]
    if not auth_token == None: 
        setTokens(auth_token, "", vpn_provider + userid + password)
        return True

    return False
def authenticateShellfire(vpn_provider, userid, password):
    # Authenticate with the API and store the tokens returned

    # If the same credentials have been used before, don't bother authenticating
    _, _, _, creds = getTokens()
    if creds == vpn_provider + userid + password:
        debugTrace("Previous authentication was good")
        return True

    # Get the authentication token to use on future calls
    resetTokens()
    rc, api_data = sendAPI(
        "?action=login", "Authenticating with VPN",
        '{"email":"' + userid + '", "password":"******"}', True)
    if not rc: return False

    # Extract the auth token and store it
    auth_token = api_data["data"]["token"]
    if not auth_token == None:
        setTokens(auth_token, "", vpn_provider + userid + password)
        return True

    return False