#!/bin/bash # # Script to add/update a VPN user for both IPsec/L2TP and Cisco IPsec # # Copyright (C) 2018-2021 Lin Song # # This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 # Unported License: http://creativecommons.org/licenses/by-sa/3.0/ # # Attribution required: please include my name in any derivative and let me # know how you have improved it! export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" SYS_DT=$(date +%F-%T | tr ':' '_') exiterr() { echo "Error: $1" >&2; exit 1; } conf_bk() { /bin/cp -f "$1" "$1.old-$SYS_DT" 2>/dev/null; } add_vpn_user() { if [ "$(id -u)" != 0 ]; then exiterr "Script must be run as root. Try 'sudo sh $0'" fi if ! grep -qs "hwdsl2 VPN script" /etc/sysctl.conf \ || [ ! -f /etc/ppp/chap-secrets ] || [ ! -f /etc/ipsec.d/passwd ]; then cat 1>&2 <<'EOF' Error: Your must first set up the IPsec VPN server before adding VPN users. See: https://github.com/hwdsl2/setup-ipsec-vpn EOF exit 1 fi command -v openssl >/dev/null 2>&1 || exiterr "'openssl' not found. Abort." VPN_USER=$1 VPN_PASSWORD=$2 if [ -z "$VPN_USER" ] || [ -z "$VPN_PASSWORD" ]; then cat 1>&2 <> /etc/ppp/chap-secrets <> /etc/ipsec.d/passwd <