Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_credentials() -> None:
if not sys.__stdin__.isatty():
logger.critical("Please run %s in interactive mode", __name__)
sys.exit(1)
if root.verify_running_as_root() is False:
logger.error("Please run as 'sudo openpyn --init' the first time. \
Root access is needed to store credentials in '%s'.", credentials_file_path)
sys.exit(1)
else:
logger.info("Storing credentials in '%s' with openvpn \
compatible 'auth-user-pass' file format", credentials_file_path)
username = input("Enter your username for NordVPN, i.e youremail@yourmail.com: ")
password = getpass.getpass("Enter the password for NordVPN: ")
try:
with open(credentials_file_path, 'w') as creds:
creds.write(username + "\n")
creds.write(password + "\n")
creds.close()
# Change file permission to 600
subprocess.check_call(["sudo", "chmod", "600", credentials_file_path])
"Sudo credentials required to check if 'openvpn' is available in root's PATH")
if root_access is False:
root.obtain_root_access()
subprocess.check_output(["sudo", "which", "wget"])
subprocess.check_output(["sudo", "which", "unzip"])
# subprocess.check_output(["sudo", "which", "openvpn"])
except subprocess.CalledProcessError:
logger.error("Please Install 'openvpn' 'wget' 'unzip' first")
return 1
elif daemon:
if detected_os != "linux":
logger.error("Daemon mode is only available in GNU/Linux distros")
return 1
if not root.verify_running_as_root():
logger.error("Please run '--daemon' or '-d' mode with sudo")
return 1
openpyn_options = ""
# if only positional argument used
if country_code is None and server is None:
country_code = country # consider the positional arg e.g "us" same as "-c us"
# if either "-c" or positional arg f.e "au" is present
if country_code:
if len(country_code) > 2: # full country name
# get the country_code from the full name
country_code = api.get_country_code(full_name=country_code)
country_code = country_code.lower()
openpyn_options += country_code