Add new 'vpndomains' column to config file
This commit is contained in:
parent
4694cca3ca
commit
839244cd61
34
cvpn
34
cvpn
|
@ -53,7 +53,7 @@ function alias_to_cmd() {
|
|||
}
|
||||
|
||||
function load_config() {
|
||||
local CONFLINES line thisprofile thisuser thispw thisgroup thisroutes thisservercert
|
||||
local CONFLINES line thisprofile thisuser thispw thisgroup thisroutes thisdomains thisservercert
|
||||
DEFAULTPROFILE=""
|
||||
if [[ -e ${CONFFILE} ]]; then
|
||||
DEFAULTPROFILE=$(grep '^#default:' "${CONFFILE}" | sed 's/^#default://')
|
||||
|
@ -68,7 +68,8 @@ function load_config() {
|
|||
thisvpntype=$(cut -d, -f5 <<< "${line}")
|
||||
thisserver=$(cut -d, -f6 <<< "${line}")
|
||||
thisroutes=$(cut -d, -f7 <<< "${line}")
|
||||
thisservercert=$(cut -d, -f8 <<< "${line}")
|
||||
thisdomains=$(cut -d, -f8 <<< "${line}")
|
||||
thisservercert=$(cut -d, -f9 <<< "${line}")
|
||||
case $thisvpntype in
|
||||
"") thisvpntype="anyconnect";;
|
||||
"cisco") thisvpntype="anyconnect";;
|
||||
|
@ -87,6 +88,7 @@ function load_config() {
|
|||
vpntype[$nvpns]="${thisvpntype}"
|
||||
server[$nvpns]="${thisserver}"
|
||||
routes[$nvpns]="${thisroutes}"
|
||||
domains[$nvpns]="${thisdomains}"
|
||||
servercert[$nvpns]="${thisservercert}"
|
||||
nvpns=$((nvpns + 1))
|
||||
done <<< "${CONFLINES}"
|
||||
|
@ -109,10 +111,10 @@ function usage() {
|
|||
echo "Config file format:"
|
||||
echo " #Specify default profile like this:"
|
||||
echo " #default:myvpn2"
|
||||
echo " #Profile,Username,Password,VPNGroup,VPNType,ServerIP,VPNRoutes,ServerCert(script will obtain this and auto-update config file)"
|
||||
echo " myvpn1,username_1,password_1,vpngroup_1,anyconnect,3.3.3.3,10.0.0.0/24 192.168.0.0/24,"
|
||||
echo " myvpn2,username_2,password_2,vpngroup_2,anyconnect,1.1.1.1,172.16.0.0/12,"
|
||||
echo " myvpn3,username_3,password_3,,f5,1.1.1.1,172.16.0.0/12,"
|
||||
echo " #Profile,Username,Password,VPNGroup,VPNType,ServerIP,VPNRoutes,VPNDomains,ServerCert(script will obtain this and auto-update config file)"
|
||||
echo " myvpn1,username_1,password_1,vpngroup_1,anyconnect,3.3.3.3,10.0.0.0/24 192.168.0.0/24,example.com example.net,"
|
||||
echo " myvpn2,username_2,password_2,vpngroup_2,anyconnect,1.1.1.1,172.16.0.0/12,,"
|
||||
echo " myvpn3,username_3,password_3,,f5,1.1.1.1,172.16.0.0/12,example.net,"
|
||||
echo
|
||||
}
|
||||
|
||||
|
@ -243,6 +245,16 @@ elif [[ $cmd == "on" ]]; then
|
|||
curserver=${server[$id]}
|
||||
curservercert=${servercert[$id]}
|
||||
curroutes=${routes[$id]}
|
||||
curdomains=${domains[$id]}
|
||||
#echo "got curprofile=${profile[$id]}"
|
||||
#echo "got curuser=${user[$id]}"
|
||||
#echo "got curpw=${pw[$id]}"
|
||||
#echo "got curgroup=${group[$id]}"
|
||||
#echo "got curvpntype=${vpntype[$id]}"
|
||||
#echo "got curserver=${server[$id]}"
|
||||
#echo "got curservercert=${servercert[$id]}"
|
||||
#echo "got curroutes=${routes[$id]}"
|
||||
#echo "got curdomains=${domains[$id]}"
|
||||
else
|
||||
error "Could not determine VPN ID for profile ^b${PROFILE}^p."
|
||||
exit 1
|
||||
|
@ -264,7 +276,7 @@ elif [[ $cmd == "on" ]]; then
|
|||
notify "Updating configuration file ^b$CONFFILE^p"
|
||||
bakfile="${CONFFILE}".backup
|
||||
prevlines=$(cat "$CONFFILE" | awk NF | wc -l | bc)
|
||||
newconfig=$(cat "${CONFFILE}" | awk -v p="$curprofile" -v c="$foundcert" -F, '{ OFS=","; if ($1 == p) { $8 = c; } print }')
|
||||
newconfig=$(cat "${CONFFILE}" | awk -v p="$curprofile" -v c="$foundcert" -F, '{ OFS=","; if ($1 == p) { $9 = c; } print }')
|
||||
newlines=$(echo "$newconfig" | awk NF | wc -l | bc)
|
||||
|
||||
err=""
|
||||
|
@ -303,8 +315,12 @@ elif [[ $cmd == "on" ]]; then
|
|||
notify "${nstr}"
|
||||
|
||||
rm -f "$VPNPIDFILE"
|
||||
if [[ -n $curroutes ]]; then
|
||||
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg -s "$VPNSLICE $curroutes" --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
|
||||
if [[ -n $curroutes && -n $curdomains]]; then
|
||||
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg -s "$VPNSLICE --domains-vpn-dns ${curdomains// /,} $curroutes" --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
|
||||
elif [[ -n $curroutes ]]; then
|
||||
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg -s "$VPNSLICE $curroutes" --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
|
||||
elif [[ -n $curdomains ]]; then
|
||||
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg -s "$VPNSLICE --domains-vpn-dns $curdomains" --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
|
||||
else
|
||||
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue