def validate_bypass_dns(): if not functions.matches_regex("^(yes|no)$", configuration_variables.BYPASS_DNS): print("Invalid 'bypass-dns' option: " + configuration_variables.BYPASS_DNS) quit() if configuration_variables.REDIRECT_ALL_TRAFFIC == "no" and configuration_variables.BYPASS_DNS != "no": print("Invalid 'bypass-dns' option: " + configuration_variables.BYPASS_DNS) print("The 'bypass-dns' option must be disabled when not redirecting all traffic.") quit()
def validate_enable_clients_passwords_array(): if len(configuration_variables.CLIENTS_ARRAY) != len(configuration_variables.ENABLE_CLIENTS_PASSWORDS_ARRAY): print("The number of clients should be equal to the number of password activation options.") quit() for i in range(len(configuration_variables.ENABLE_CLIENTS_PASSWORDS_ARRAY)): configuration_variables.ENABLE_CLIENTS_PASSWORDS_ARRAY[i] = configuration_variables.ENABLE_CLIENTS_PASSWORDS_ARRAY[i].lower() enable_password = configuration_variables.ENABLE_CLIENTS_PASSWORDS_ARRAY[i] if not functions.matches_regex("^(yes|no)$", enable_password): print("Invalid 'enable password' option: " + enable_password) quit()
def validate_clients_array(): for client in configuration_variables.CLIENTS_ARRAY: if not functions.matches_regex("^([a-zA-Z0-9_-]+)$", client): print("Invalid name: " + client) print("Please, do not use spaces or special characters.") quit()
def validate_firewall_mode(): configuration_variables.FIREWALL_MODE = configuration_variables.FIREWALL_MODE.lower() if not functions.matches_regex("^(limit|allow)$", configuration_variables.FIREWALL_MODE): print("Invalid mode: " + FIREWALL_MODE) quit()
def validate_allow_duplicate_cn(): configuration_variables.ALLOW_DUPLICATE_CN = configuration_variables.ALLOW_DUPLICATE_CN.lower() if not functions.matches_regex("^(yes|no)$", configuration_variables.ALLOW_DUPLICATE_CN): print("Invalid 'duplicate-cn' option: " + configuration_variables.ALLOW_DUPLICATE_CN) quit()
def validate_allow_client_to_client(): configuration_variables.ALLOW_CLIENT_TO_CLIENT = configuration_variables.ALLOW_CLIENT_TO_CLIENT.lower() if not functions.matches_regex("^(yes|no)$", configuration_variables.ALLOW_CLIENT_TO_CLIENT): print("Invalid 'client-to-client' option: " + configuration_variables.ALLOW_CLIENT_TO_CLIENT) quit()
def validate_redirect_all_traffic(): if not functions.matches_regex("^(yes|no)$", configuration_variables.REDIRECT_ALL_TRAFFIC): print("Invalid 'redirect-all-traffic' option: " + configuration_variables.REDIRECT_ALL_TRAFFIC) quit()
def validate_server_protocol(): configuration_variables.SERVER_PROTOCOL = configuration_variables.SERVER_PROTOCOL.lower() if not functions.matches_regex("^(udp|tcp)$", configuration_variables.SERVER_PROTOCOL): print("Invalid protocol: " + configuration_variables.SERVER_PROTOCOL) quit()
def validate_server_name(): if not functions.matches_regex("^([a-zA-Z0-9_-]+)$", configuration_variables.SERVER_NAME): print("Invalid name: " + configuration_variables.SERVER_NAME) print("Please, do not use spaces or special characters.") quit()
def validate_enable_remote_random(): configuration_variables.ENABLE_REMOTE_RANDOM = configuration_variables.ENABLE_REMOTE_RANDOM.lower() if not functions.matches_regex("^(yes|no)$", configuration_variables.ENABLE_REMOTE_RANDOM): print("Invalid 'remote-random' option: " + configuration_variables.ENABLE_REMOTE_RANDOM) quit()
def matches_regex(regex, string): return functions.matches_regex(regex, string)
def test_matches_regex(self): self.assertTrue(functions.matches_regex("^\d$", "5")) self.assertFalse(functions.matches_regex("^\d$", "a"))