Skip to content

Commit

Permalink
Merge pull request #397 from peno64/master
Browse files Browse the repository at this point in the history
Extra changes needed for NordVPN. Especially if there was no user nam…
  • Loading branch information
Zomboided authored Apr 6, 2023
2 parents 3e9e04f + e533f36 commit 6f1d59e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v7.0.3
- Extra changes needed for NordVPN. Especially if there was no user name/password previously because of new setup and also fix wizard setup

v7.0.2
- Changes to NordVPN to allow to login with token instead of user name/password because of api change at NordVPN

Expand Down
28 changes: 25 additions & 3 deletions libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from libs.utility import debugTrace, infoTrace, errorTrace, ifDebug, newPrint, getID, getName, getShort, isCustom, getCustom
from libs.vpnproviders import getVPNLocation, getRegexPattern, getAddonList, provider_display, usesUserKeys, usesSingleKey, gotKeys, checkForVPNUpdates
from libs.vpnproviders import ovpnFilesAvailable, ovpnGenerated, fixOVPNFiles, getLocationFiles, removeGeneratedFiles, copyKeyAndCert, populateSupportingFromGit
from libs.vpnproviders import usesPassAuth, cleanPassFiles, isUserDefined, getKeyPass, getKeyPassName, usesKeyPass, writeKeyPass, refreshVPNFiles
from libs.vpnproviders import usesPassAuth, usesToken, cleanPassFiles, isUserDefined, getKeyPass, getKeyPassName, usesKeyPass, writeKeyPass, refreshVPNFiles
from libs.vpnproviders import setVPNProviderUpdate, setVPNProviderUpdateTime, isDeprecated, getVPNDisplay, isAlternative, allowViewSelection, updateVPNFile
from libs.vpnproviders import getAlternativePreFetch, getAlternativeFriendlyLocations, getAlternativeFriendlyServers, getAlternativeLocation, getAlternativeServer
from libs.vpnproviders import authenticateAlternative, getAlternativeUserPass, getAlternativeProfiles, allowReconnection, postConnectAlternative
Expand Down Expand Up @@ -1221,8 +1221,29 @@ def wizard():

addon = xbmcaddon.Addon(getID())
if success:
# Get the username and password
if usesPassAuth(vpn_provider):
vpn_username = ""
vpn_password = ""
vpn_token = ""
if usesToken(vpn_provider):
# Get the token
# Preload with any existing info if it's the same VPN
if not current == vpn_provider:
vpn_token = ""
else:
vpn_token = addon.getSetting("vpn_token")
# Get the token
while True:
vpn_token = xbmcgui.Dialog().input("Enter your " + vpn_provider + " token", vpn_token, type=xbmcgui.INPUT_ALPHANUM)
if vpn_token == "":
if xbmcgui.Dialog().yesno(addon_name, "You must enter the token supplied by " + vpn_provider + ". Try again or cancel setup?", nolabel="Try again", yeslabel="Cancel"):
xbmcgui.Dialog().ok(addon_name, "Setup canceled. You can run the wizard again by selecting 'Settings' in the add-on menu.")
success = False
break
else:
break

elif usesPassAuth(vpn_provider):
# Get the username and password
# Preload with any existing info if it's the same VPN
if not current == vpn_provider:
vpn_username = ""
Expand Down Expand Up @@ -1277,6 +1298,7 @@ def wizard():
addon.setSetting("vpn_provider", vpn_provider)
addon.setSetting("vpn_username", vpn_username)
addon.setSetting("vpn_password", vpn_password)
addon.setSetting("vpn_token", vpn_token)
if not xbmcgui.Dialog().yesno(addon_name, "Click ok to create a VPN connection to " + vpn_provider + " for user name " + vpn_username + ". You will be asked which connection or country you want to use during the connection process.", nolabel="Ok", yeslabel="Cancel"):
connectVPN("1", vpn_provider)
addon = xbmcaddon.Addon(getID())
Expand Down
11 changes: 11 additions & 0 deletions libs/vpnproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
# Names must match the directory names as used in providers, just above
providers_no_pass = ["AirVPN", "VPNUnlimited", "WiTopia", "VPNSecure", "NordVPN"]

# List of providers which use a token
# Names must match the directory names as used in providers, just above
providers_token = ["NordVPN"]

# **** ADD VPN PROVIDERS HERE IF THEY USE A KEY PASSWORD ****
# List of providers which secure the user key with a password to be entered during connection
# Names must match the directory names as used in providers, just above
Expand Down Expand Up @@ -362,6 +366,13 @@ def getCertName(vpn_provider, ovpn_name):
return "user_" + ovpn_name.replace(" ", "_") + ".crt"
return ""

def usesToken(vpn_provider):
# Determine if we're using a token or not
if isUserDefined(vpn_provider):
if not (xbmcaddon.Addon(getID()).getSetting("user_def_credentials") == "true"):
return False
elif vpn_provider in providers_token: return True
return False

def usesPassAuth(vpn_provider):
# Determine if we're using a user name and password or not
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<setting label="32007" type="text" id="vpn_password" enable="!eq(-6,true)" visible="!eq(-5,NordVPN)" option="hidden" default=""/>
<setting label="32008" type="action" enable="!eq(-7,true)" visible="!eq(-1,)+!eq(-6,NordVPN)" option="close" action="RunScript(special://home/addons/service.vpn.manager/passwordpopup.py)"/>
<setting label="32027" type="text" id="vpn_token" enable="!eq(-8,true)" visible="eq(-7,NordVPN)" default=""/>
<setting label="32192" type="action" visible="eq(-8,NordVPN)" />
<setting label="32192" type="action" visible="eq(-8,NordVPN)" enable="!eq(-9,true)" />
<setting label=" " type="sep"/>
<setting label="32009" type="lsep"/>
<setting label="32010" type="labelenum" id="vpn_protocol" lvalues="32011|32012|32013" default="UDP"/>
Expand Down

0 comments on commit 6f1d59e

Please sign in to comment.