Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# only clear/touch FW Rules if "-f" used
elif force_fw_rules:
firewall.clear_fw_rules()
# check if OpenVPN config files exist if not download them.
check_config_files()
# 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:
# ask for and store credentials if not present, skip if "--test"
if not test:
if credentials.check_credentials() is False:
credentials.save_credentials()
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()
# keep trying to connect to new servers
for tries in range(3): # pylint: disable=W0612
better_servers_list = find_better_servers(
country_code, area, max_load, top_servers, tcp, p2p,
dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix, location, stats)
pinged_servers_list = ping_servers(better_servers_list, pings, stats)
chosen_servers = choose_best_servers(pinged_servers_list, stats)
# connect to chosen_servers, if one fails go to next
# if "-f" used apply firewall rules
if force_fw_rules:
network_interfaces = get_network_interfaces()
vpn_server_ip = get_vpn_server_ip(aserver, port)
firewall.apply_fw_rules(network_interfaces, vpn_server_ip, skip_dns_patch)
if internally_allowed:
firewall.internally_allow_ports(network_interfaces, internally_allowed)
if nvram:
# TODO return 0 on success else 1 in asus.run()
asus.run(aserver, country_code, nvram, "All", "adaptive", "Strict", tcp, test)
logger.success("SAVED SERVER " + aserver + " ON PORT " + port + " TO NVRAM")
return(connect(aserver, port, silent, test, skip_dns_patch, openvpn_options))
elif server:
# ask for and store credentials if not present, skip if "--test"
if not test:
if credentials.check_credentials() is False:
credentials.save_credentials()
server = server.lower()
# if "-f" used apply firewall rules
if force_fw_rules:
network_interfaces = get_network_interfaces()
vpn_server_ip = get_vpn_server_ip(server, port)
firewall.apply_fw_rules(network_interfaces, vpn_server_ip, skip_dns_patch)
if internally_allowed:
firewall.internally_allow_ports(network_interfaces, internally_allowed)
if nvram:
asus.run(server, country_code, nvram, "All", "adaptive", "Strict", tcp, test)
logger.success("SAVED SERVER " + server + " ON PORT " + port + " TO NVRAM")
return 0
for i in range(20): # pylint: disable=W0612
return(connect(server, port, silent, test, skip_dns_patch, openvpn_options))