diff --git a/openvpn-install.sh b/openvpn-install.sh index 9dbe796..ecb5ac4 100644 --- a/openvpn-install.sh +++ b/openvpn-install.sh @@ -21,6 +21,11 @@ check_ip() { printf '%s' "$1" | tr -d '\n' | grep -Eq "$IP_REGEX" } +check_pvt_ip() { + IPP_REGEX='^(10|127|172\.(1[6-9]|2[0-9]|3[0-1])|192\.168|169\.254)\.' + printf '%s' "$1" | tr -d '\n' | grep -Eq "$IPP_REGEX" +} + check_dns_name() { FQDN_REGEX='^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$' printf '%s' "$1" | tr -d '\n' | grep -Eq "$FQDN_REGEX" @@ -142,7 +147,6 @@ parse_args() { shift ;; --serveraddr) - server_addr_set=1 server_addr="$2" shift shift @@ -230,8 +234,8 @@ check_args() { exiterr "Invalid client name, or client does not exist." fi fi - if [ -n "$server_addr" ] && ! check_dns_name "$server_addr"; then - exiterr "Invalid server address. Must be a fully qualified domain name (FQDN)." + if [ -n "$server_addr" ] && { ! check_dns_name "$server_addr" && ! check_ip "$server_addr"; }; then + exiterr "Invalid server address. Must be a fully qualified domain name (FQDN) or an IPv4 address." fi if [ -n "$first_client_name" ]; then unsanitized_client="$first_client_name" @@ -361,24 +365,23 @@ Usage: bash $0 [options] Options: - --addclient [client name] add a new client - --exportclient [client name] export configuration for an existing client - --listclients list the names of existing clients - --revokeclient [client name] revoke an existing client - --uninstall remove OpenVPN and delete all configuration - -y, --yes assume "yes" as answer to prompts when revoking a client or removing OpenVPN - -h, --help show this help message and exit + --addclient [client name] add a new client + --exportclient [client name] export configuration for an existing client + --listclients list the names of existing clients + --revokeclient [client name] revoke an existing client + --uninstall remove OpenVPN and delete all configuration + -y, --yes assume "yes" as answer to prompts when revoking a client or removing OpenVPN + -h, --help show this help message and exit Install options (optional): - --auto auto install OpenVPN using default or custom options - --serveraddr [DNS name] server address, must be a fully qualified domain name (FQDN). - If not specified, the server's IPv4 address will be used. - --proto [TCP or UDP] protocol for OpenVPN (TCP or UDP, default: UDP) - --port [number] port for OpenVPN (1-65535, default: 1194) - --clientname [client name] name for the first OpenVPN client (default: client) - --dns1 [DNS server IP] primary DNS server for clients (default: Google Public DNS) - --dns2 [DNS server IP] secondary DNS server for clients + --auto auto install OpenVPN using default or custom options + --serveraddr [DNS name or IP] server address, must be a fully qualified domain name (FQDN) or an IPv4 address. + --proto [TCP or UDP] protocol for OpenVPN (TCP or UDP, default: UDP) + --port [number] port for OpenVPN (1-65535, default: 1194) + --clientname [client name] name for the first OpenVPN client (default: client) + --dns1 [DNS server IP] primary DNS server for clients (default: Google Public DNS) + --dns2 [DNS server IP] secondary DNS server for clients To customize options, you may also run this script without arguments. EOF @@ -405,10 +408,8 @@ show_welcome() { show_dns_name_note() { cat <