#!/usr/bin/env bash# By Michael Blaschek# Date 18.01.2021# CC BY 4.0 International# University of Vienna, Austria# Description:# Connect to Jet via a gateway server
help(){cat<<EOF$0 -g [gateway] -p [port] -r [remote-port] user@remoteOptions: -h Help -g [gateway] gateway server, e.g. user@login.univie.ac.at -p [port] port to forward from jet to local, e.g. VNC port -r [port] remote port if not the same as port -d debugExample: $0 -g [U:Account-Username]@login.univie.ac.at [Jet-Username]@jet01.img.univie.ac.atEOF}debug=''whilegetopts"g:p:r:hd"flag;docase"${flag}"ing)gateway=${OPTARG};;p)port=${OPTARG};;r)rport=${OPTARG};;d)debug='-v';;h|*)helpexit0;;esacdoneshift$((OPTIND-1))command=""remote=$1script=$(basename$0)if["${remote}"==""];thenecho"Remote host required: [user]@[server]"helpexit1fiif[-n"${port}"];then# -L local_port:destination_server_ip:remote_portif[-n"${rport}"];thenecho"Forwarding Port: $rport to $port"command="-L ${port}:localhost:${rport} "elseecho"Forwarding Port: $port to $port"command="-L ${port}:localhost:${port} "rport=$port# make sure we use thisfifi# Override Term information to make sure we use the ones on the servers# export TERM=xterm-256color# Check if names are in .ssh/configremote_status=falsegateway_status=falseif[-e$HOME/.ssh/config];then# check if hosts are therecat$HOME/.ssh/config|grep-i'Host ${remote}'>/dev/null
if[$?-eq0];thenremote_status=truefiif[-n${gateway}];thencat$HOME/.ssh/config|grep-i'Host ${gateway}'>/dev/null
if[$?-eq0];thengateway_status=truefififiif[-n"${gateway}"];thenecho"$gateway"|grep'@'>/dev/null
if[$?-eq1]&&[!$gateway_status];thenecho"Could fail if not: [user]@[server], trying: $gateway"fiif[-n"${port}"];thenecho"Using gateway: $gateway to $remote "midport=$(($RANDOM%1000+20000))# 20000 - 21000echo"Port Forwarding via the gateway: $port : $midport : $rport"ssh$debug-L${port}:localhost:${midport}-t$gatewayssh-L${midport}:localhost:${rport}${remote}echo"$(date) | ssh -L ${port}:localhost:${midport} -t $gateway 'ssh -L ${midport}:localhost:${rport}${remote}'">>.${script}.log
elseecho"Using gateway: $gateway to $remote "ssh$debug$command-t$gatewayssh${command}${remote}echo"$(date) | ssh $command -t $gateway 'ssh ${command}${remote}'">>.${script}.log
fielseif[!$remote_status];thenecho"Could fail if not: [user]@[server]"fiecho"Direct connection to: ${remote}"ssh$debug${command}${remote}echo"$(date) | ssh ${command}${remote}">>.${script}.log
fiecho"Command Log in .${script}.log"
#!/bin/bash# By Michael Blaschek# Date 31.07.2023# CC BY 4.0 International# University of Vienna, Austria# Department of Meteorology and Geophysics# img.univie.ac.at# Description:# Connect to VPN from the University of Vienna# You need to download the F5 VPN Client from the ZID website (zid.univie.ac.at/vpn)# The executable works only for VPN@UNIVIE. Follow the instructions on the ZID website# on how to install the package depending on your Linux distro.# Maybe this download link works directly:# https://vpn.univie.ac.at/public/share/BIGIPLinuxClient.tgz## Steps:# 1. run connect2vpn script# 1.1. Checks if it can find f5fpc exe # 1.2. Asks for credentials# 1.3. Asks for TOTP Code# 1.4. Watch connection
vpninfos(){infos=$(f5fpc--info)status=$(echo"${infos}"|grep'/Common/Remote-Access'|head-n1|cut-d' '-f3)cat<<EOF[VPN] ${status}[VPN] Connection Information. Use Ctrl+c to end.===============================================================================${infos}EOF}if[$#-eq0];thenif["${VPN_USER}"!=""];thenecho"[VPN] using '$VPN_USER'"elseread-p"[VPN] u:account username: "VPN_USER
fielseVPN_USER=$1echo"[VPN] Using ${VPN_USER} as username"fi
f5fpc-v2>/dev/null1>/dev/null
if[$?-ne0];thenecho"[VPN] Install Big-IP Edge Client. f5fpc missing"exit1elseecho"[VPN] $(f5fpc-v|head-n1)"fiechoecho"[VPN] Notice: This script will continue to run in foreground!"echoread-p"[VPN] Full (1) or split (None) tunnel? (1/None): "REPLY
if["$REPLY"==""];thenecho"[VPN] Connecting split-tunnel ..."cmd="f5fpc -s -t vpn.univie.ac.at"elseecho"[VPN] Connecting full-tunnel ..."cmd="f5fpc -s -t vpn.univie.ac.at:8443"fiecho"[VPN] Testing VPN Client..."# Show statusexport-fvpninfos
init=truewhiletrue;dof5fpc--info|grep"established">/dev/null
if[$?-ne0];thenif!$init;thenecho"[VPN] Restarting ..."f5fpc-o
fiecho"[VPN] Starting connection ..."if[-z"$VPN_PWD"];thenread-sp"[VPN] u:account password:"VPN_PWD
echofiread-p"[VPN] TOTP Code (6 digits/empty):"VPN_TOTP
if[-n"$VPN_TOTP"];theneval"${cmd} -p ${VPN_PWD} -u ${VPN_USER}@${VPN_TOTP}"elseeval"$cmd -p ${VPN_PWD} -u ${VPN_USER}"fiif$init;theninit=falsefifiwatch-n2vpninfos
read-p"[VPN] Reconnect (1) or shutdown (None): "REPLY
if["$REPLY"==""];thenbreakfidoneunsetVPN_PWDVPN_USERVPN_TOTP
echo"[VPN] Shutting down ..."# Disconnect
f5fpc-o
echo"[VPN] disconnected"