Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_config_files() -> None:
root.verify_root_access("Root access needed to write files in " +
"'" + __basefilepath__ + "files/" + "'")
try:
zip_archive = __basefilepath__ + "ovpn.zip"
if os.path.exists(zip_archive):
print(Fore.BLUE + "Previous update file already exists, deleting..." + Style.RESET_ALL)
os.remove(zip_archive)
subprocess.check_call(
["sudo", "wget", "https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip", "-P", __basefilepath__])
except subprocess.CalledProcessError:
logger.error("Exception occurred while wgetting zip, is the internet working? \
is nordcdn.com blocked by your ISP or Country?, If so use Privoxy \
[https://github.com/jotyGill/openpyn-nordvpn/issues/109]")
sys.exit()
try:
subprocess.check_call(
time.sleep(6)
update_config_files()
elif server_provider == "ipvanish":
vpn_config_file = __basefilepath__ + "files/" + "ipvanish/" + server
# logger.debug("ipvanish")
if test:
logger.success("Simulation end reached, \
openpyn would have connected to server: " + server + " on port: " + port + " with 'silent' mode: " + str(silent).lower())
return 0
kill_vpn_processes() # kill existing OpenVPN processes
kill_management_client()
logger.success("CONNECTING TO SERVER " + server + " ON PORT " + port)
root_access = root.verify_root_access("Sudo credentials required to run 'openvpn'")
if root_access is False:
root.obtain_root_access()
if not silent:
# notifications Don't work with 'sudo'
if detected_os == "linux" and root.running_with_sudo():
logger.warning("Desktop notifications don't work when using 'sudo', run without it, \
when asked, provide the sudo credentials")
subprocess.Popen("openpyn-management".split())
else:
subprocess.Popen("openpyn-management --do-notify".split())
use_systemd_resolved = False
use_resolvconf = False
if detected_os == "linux":
if subprocess.check_output(["/bin/uname", "-o"]).decode(sys.stdout.encoding).strip() == "ASUSWRT-Merlin":
skip_dns_patch = True
def kill_vpn_processes() -> None:
try:
subprocess.check_output(["pgrep", "openvpn"])
# When it returns "0", proceed
root.verify_root_access("Root access needed to kill openvpn process")
subprocess.call(["sudo", "killall", "openvpn"])
logger.notice("Killing the running openvpn process")
time.sleep(1)
except subprocess.CalledProcessError:
# when Exception, the openvpn_processes issued non 0 result, "not found"
pass
return
def kill_management_client() -> None:
# kill the management client if it is for some reason still alive
try:
root.verify_root_access("Root access needed to kill 'openpyn-management' process")
subprocess.check_output(["sudo", "killall", "openpyn-management"],
stderr=subprocess.DEVNULL)
logger.notice("Killing the running openvpn-management client")
time.sleep(3)
except subprocess.CalledProcessError:
# when Exception, the openvpn_processes issued non 0 result, "not found"
pass
return