Skip to content

Commit

Permalink
Add ucsf_vpn_log() for hook scripts to use
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed May 17, 2024
1 parent 72ff1c5 commit 21e1a1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
19 changes: 12 additions & 7 deletions bin/ucsf-vpn
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
### * UCSF Managing Your Passwords:
### - https://it.ucsf.edu/services/managing-your-passwords
###
### Version: 5.7.0-9033
### Version: 5.7.0-9034
### Copyright: Henrik Bengtsson (2016-2024)
### License: GPL (>= 2.1) [https://www.gnu.org/licenses/gpl.html]
### Source: https://github.com/HenrikBengtsson/ucsf-vpn
Expand Down Expand Up @@ -1328,7 +1328,7 @@ function openconnect_start() {
mdebug "token: <not specified>"
fi
mdebug "opts: [n=${#opts[@]}] ${opts[*]}"
mdebug "call: sudo UCSF_VPN_VERSION=$(version) UCSF_VPN_FLAVOR=$(flavor_home) UCSF_VPN_LOGPATH=$(logpath) openconnect ${opts[*]} --authgroup=\"$realm\""
mdebug "call: sudo UCSF_VPN_VERSION=$(version) UCSF_VPN_FLAVOR=$(flavor_home) UCSF_VPN_LOGFILE=$(logfile) openconnect ${opts[*]} --authgroup=\"$realm\""

if [[ $token == "push" ]]; then
mnote "Open the Duo Mobile app on your smartphone or tablet to confirm ..."
Expand Down Expand Up @@ -1363,10 +1363,10 @@ function openconnect_start() {
;;
esac
# shellcheck disable=SC2086
sudo echo -e "$two_pwds" | sudo UCSF_VPN_VERSION="$(version)" UCSF_VPN_FLAVOR="$(flavor_home)" UCSF_VPN_LOGPATH="$(logpath)" openconnect "${opts[@]}" --authgroup="$realm" 2> "$fh_stderr" 1> "$fh_stdout"
sudo echo -e "$two_pwds" | sudo UCSF_VPN_VERSION="$(version)" UCSF_VPN_FLAVOR="$(flavor_home)" UCSF_VPN_LOGFILE="$(logfile)" openconnect "${opts[@]}" --authgroup="$realm" 2> "$fh_stderr" 1> "$fh_stdout"
else
# shellcheck disable=SC2086
sudo UCSF_VPN_VERSION="$(version)" UCSF_VPN_FLAVOR="$(flavor_home)" UCSF_VPN_LOGPATH="$(logpath)" openconnect "${opts[@]}" --authgroup="$realm" 2> "$fh_stderr" 1> "$fh_stdout"
sudo UCSF_VPN_VERSION="$(version)" UCSF_VPN_FLAVOR="$(flavor_home)" UCSF_VPN_LOGFILE="$(logfile)" openconnect "${opts[@]}" --authgroup="$realm" 2> "$fh_stderr" 1> "$fh_stdout"
fi

## Update IP-info file
Expand Down Expand Up @@ -1657,15 +1657,20 @@ function flavor_home() {
}


function logpath() {
local path
function logfile() {
local path file

path="$(xdg_state_path)/logs"
if [ ! -d "$path" ]; then
mkdir -p "$path"
fi

echo "${path}"
file="${path}"/ucsf-vpn.log

## Create log file
touch "${file}"

echo "${file}"
}


Expand Down
13 changes: 10 additions & 3 deletions vpnc/connect.d/ucsf-vpn-flavors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@

## Called via 'ucsf-vpn'?
if [ -n "${UCSF_VPN_VERSION}" ]; then
file="${UCSF_VPN_FLAVOR}"/pre-connect.sh
if [ -f "${file}" ]; then
. "${file}"
ucsf_vpn_log() {
echo "[$(date --iso-8601=seconds)] $@" >> "${UCSF_VPN_LOGFILE}"
}

_hook_file_="${UCSF_VPN_FLAVOR}"/pre-connect.sh
if [ -f "${_hook_file_}" ]; then
ucsf_vpn_log "${_hook_file_} ..."
_hook_status_="done"
. "${_hook_file_}" || _hook_status_="error"
ucsf_vpn_log "${_hook_file_} ... ${_hook_status_}"
fi
fi

0 comments on commit 21e1a1d

Please sign in to comment.