tidy up vpnslice args code

add a few more one-letter command aliases
This commit is contained in:
Rob Pearce 2023-10-14 08:50:15 +11:00
parent 3852304c59
commit 69fa9f3637
1 changed files with 14 additions and 12 deletions

26
cvpn
View File

@ -45,6 +45,8 @@ function alias_to_cmd() {
"d") output="off";; "d") output="off";;
"down") output="off";; "down") output="off";;
"check") output="status";; "check") output="status";;
"q") output="status";;
"s") output="status";;
"stat") output="status";; "stat") output="status";;
"info") output="status";; "info") output="status";;
"i") output="status";; "i") output="status";;
@ -362,19 +364,19 @@ elif [[ $cmd == "on" ]]; then
notify "${nstr}" notify "${nstr}"
rm -f "$curpidfile" rm -f "$curpidfile"
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 sargs=""
rv=$? if [[ -n $curdomains ]]; then
elif [[ -n $curroutes ]]; then sargs="${sargs} --domains-vpn-dns ${curdomains// /,}"
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
rv=$?
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
rv=$?
else
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
rv=$?
fi fi
if [[ -n $curroutes ]]; then
sargs="${sargs} ${curroutes}"
fi
if [[ -n ${sargs} ]]; then
sliceargs=( -s "$VPNSLICE $sargs" )
fi
printf '%s' "$curpw" | sudo ${OPENCONNECT} --background --non-inter --protocol=$curvpntype -u "$curuser" --passwd-on-stdin $grouparg "${sliceargs[@]}" --servercert "$curservercert" "$curserver" >"${LOGFILE}" 2>&1
res=$(cat "$LOGFILE") res=$(cat "$LOGFILE")
if [[ $rv -eq 0 ]]; then if [[ $rv -eq 0 ]]; then
cpid=$(pgrep -f "openconnect.* ${curserver}") cpid=$(pgrep -f "openconnect.* ${curserver}")