mirror of
https://github.com/angristan/openvpn-install.git
synced 2025-05-09 18:28:23 +02:00
Merge 1182e98aed0ec0113ece9d345997c1559351595e into e2d4990ae194e37fd5162168a8aac5e2d89e0e8d
This commit is contained in:
commit
4715fc61cc
@ -1129,10 +1129,12 @@ function newClient() {
|
|||||||
echo "Client $CLIENT added."
|
echo "Client $CLIENT added."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$CLIENT_FILEPATH" ]]; then
|
||||||
# Home directory of the user, where the client configuration will be written
|
# Home directory of the user, where the client configuration will be written
|
||||||
if [ -e "/home/${CLIENT}" ]; then
|
if [ -e "/home/${CLIENT}" ]; then
|
||||||
# if $1 is a user name
|
# if $1 is a user name
|
||||||
homeDir="/home/${CLIENT}"
|
homeDir="/home/${CLIENT}"
|
||||||
|
CLIENT_OWNER="$CLIENT"
|
||||||
elif [ "${SUDO_USER}" ]; then
|
elif [ "${SUDO_USER}" ]; then
|
||||||
# if not, use SUDO_USER
|
# if not, use SUDO_USER
|
||||||
if [ "${SUDO_USER}" == "root" ]; then
|
if [ "${SUDO_USER}" == "root" ]; then
|
||||||
@ -1141,11 +1143,15 @@ function newClient() {
|
|||||||
else
|
else
|
||||||
homeDir="/home/${SUDO_USER}"
|
homeDir="/home/${SUDO_USER}"
|
||||||
fi
|
fi
|
||||||
|
CLIENT_OWNER="$SUDO_USER"
|
||||||
else
|
else
|
||||||
# if not SUDO_USER, use /root
|
# if not SUDO_USER, use /root
|
||||||
homeDir="/root"
|
homeDir="/root"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CLIENT_FILEPATH="$homeDir/$CLIENT.ovpn"
|
||||||
|
fi
|
||||||
|
|
||||||
# Determine if we use tls-auth or tls-crypt
|
# Determine if we use tls-auth or tls-crypt
|
||||||
if grep -qs "^tls-crypt" /etc/openvpn/server.conf; then
|
if grep -qs "^tls-crypt" /etc/openvpn/server.conf; then
|
||||||
TLS_SIG="1"
|
TLS_SIG="1"
|
||||||
@ -1154,7 +1160,7 @@ function newClient() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Generates the custom client.ovpn
|
# Generates the custom client.ovpn
|
||||||
cp /etc/openvpn/client-template.txt "$homeDir/$CLIENT.ovpn"
|
cp /etc/openvpn/client-template.txt "$CLIENT_FILEPATH"
|
||||||
{
|
{
|
||||||
echo "<ca>"
|
echo "<ca>"
|
||||||
cat "/etc/openvpn/easy-rsa/pki/ca.crt"
|
cat "/etc/openvpn/easy-rsa/pki/ca.crt"
|
||||||
@ -1181,10 +1187,18 @@ function newClient() {
|
|||||||
echo "</tls-auth>"
|
echo "</tls-auth>"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
} >>"$homeDir/$CLIENT.ovpn"
|
} >>"$CLIENT_FILEPATH"
|
||||||
|
|
||||||
|
if [[ -n "$CLIENT_OWNER" ]]; then
|
||||||
|
echo "Setting owner permission for $CLIENT_FILEPATH"
|
||||||
|
CLIENT_OWNER_GROUP=$(id -gn "$CLIENT_OWNER")
|
||||||
|
|
||||||
|
chmod go-rw "$CLIENT_FILEPATH"
|
||||||
|
chown "$CLIENT_OWNER:$CLIENT_OWNER_GROUP" "$CLIENT_FILEPATH"
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "The configuration file has been written to $homeDir/$CLIENT.ovpn."
|
echo "The configuration file has been written to $CLIENT_FILEPATH."
|
||||||
echo "Download the .ovpn file and import it in your OpenVPN client."
|
echo "Download the .ovpn file and import it in your OpenVPN client."
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user