def checkVPNCommand(addon):
# Issue the openvpn command and see if the output is a bunch of commands
if not fakeConnection():
p = getPlatform()
# Issue the openvpn command, expecting to get the options screen back
if p == platforms.RPI or p == platforms.LINUX:
# Issue Linux command
command = getOpenVPNPath() + " > " + getVPNLogFilePath() + " &"
if useSudo() : command = "sudo " + command
infoTrace("platform.py", "Testing openvpn with : " + command)
os.system(command)
elif p == platforms.WINDOWS:
# Issue Windows command
command=getOpenVPNPath()
infoTrace("platform.py", "Testing openvpn with : " + command)
args = shlex.split(command)
outfile = open(getVPNLogFilePath(),'w')
proc = subprocess.Popen(args, stdout=outfile, creationflags=subprocess.SW_HIDE, shell=True)
else:
errorTrace("platform.py", "Unsupported platform " + str(p))
# **** ADD MORE PLATFORMS HERE ****
# Waiting for the log file to appear
xbmc.sleep(1000)
i = 0
while not xbmcvfs.exists(getVPNLogFilePath()) and i < 10:
xbmc.sleep(1000)
i = i + 1
# If the log file appears, check it's what we expect
if xbmcvfs.exists(getVPNLogFilePath()):
log_file = open(getVPNLogFilePath(), 'r')
log_file_lines = log_file.readlines()
log_file.close()
# Look for a phrase we'd expect to see if the call
# worked and the list of options was displayed
for line in log_file_lines:
if "General Options" in line:
return True
# Write the log file in case there's something in it
errorTrace("platform.py", "Ran openvpn command and it failed")
writeVPNLog()
dialog_msg = "The OpenVPN executable isn't working. Check the log, then from a command line prompt type 'openvpn' and fix any problems reported."
else:
errorTrace("platform.py", "Ran openvpn command and VPN log didn't appear")
dialog_msg = "The OpenVPN executable isn't writing out a log. Try changing the Kodi log directory setting in Settings-Debug menu and retry."
# Display an error message
xbmcgui.Dialog().ok(addon.getAddonInfo("name"), dialog_msg)
return False
else: return True
评论列表
文章目录