Compare commits
No commits in common. "200e4fef6c4b5d08a9d7cec64ccd647ff9434b80" and "58c51672ca16982bb669cc49c5a569f5c35c8f15" have entirely different histories.
200e4fef6c
...
58c51672ca
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
.*journal
|
|
||||||
.*lastused
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
port=22 # default SSH port
|
|
||||||
cache=".maccess-lastused"
|
|
||||||
journal=".maccess-journal"
|
|
||||||
user_host=""
|
|
||||||
user="default"
|
|
||||||
jump=""
|
|
||||||
lock_file="lock.mutex"
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Usage: $0 [-p PORT -J jump1,jump2] user@host"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Parse command line options
|
|
||||||
while getopts ":p:J:u:" opt; do
|
|
||||||
case $opt in
|
|
||||||
p)
|
|
||||||
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]] || [ "$OPTARG" -gt 65535 ]; then
|
|
||||||
echo "Invalid port number: $OPTARG"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
port="$OPTARG"
|
|
||||||
;;
|
|
||||||
J)
|
|
||||||
jump="-J $OPTARG"
|
|
||||||
echo "ProxyJump: $jump"
|
|
||||||
;;
|
|
||||||
u)
|
|
||||||
user="$OPTARG"
|
|
||||||
;;
|
|
||||||
\?)
|
|
||||||
echo "Invalid option: -$OPTARG"
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
:)
|
|
||||||
echo "Option -$OPTARG requires an argument"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $((OPTIND -1))
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "Using $cache"
|
|
||||||
|
|
||||||
if [ -f "$cache" ]; then
|
|
||||||
{
|
|
||||||
read -r jump_cached
|
|
||||||
read -r port_cached
|
|
||||||
read -r user_host_cached
|
|
||||||
} < "$cache"
|
|
||||||
jump="$jump_cached"
|
|
||||||
port="$port_cached"
|
|
||||||
user_host="$user_host_cached"
|
|
||||||
else
|
|
||||||
echo "Error: Cache file $cache not found." >&2
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
user_host="$1"
|
|
||||||
echo "$jump" > "$cache"
|
|
||||||
echo "$port" >> "$cache"
|
|
||||||
echo "$user_host" >> "$cache"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Check if lock file exists on remote
|
|
||||||
if ssh $jump -p "$port" "$user_host" "test -e '$lock_file'"; then
|
|
||||||
echo "Error: Lock file $lock_file exists on $user_host" >&2
|
|
||||||
whoisusing=$(ssh $jump -p $port $user_host "cat $lock_file")
|
|
||||||
echo "At the moment in use by $whoisusing" >&2
|
|
||||||
echo "Session might be active. Exiting." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create lock file
|
|
||||||
ssh $jump -p "$port" "$user_host" "echo '$user' > '$lock_file'"
|
|
||||||
echo "Locked for user $user"
|
|
||||||
echo "[Start] [$(date +%Y-%m-%d-%H-%M-%S)] $user" >> $journal
|
|
||||||
cleanup() {
|
|
||||||
echo "Removing lock file..."
|
|
||||||
ssh $jump -p "$port" "$user_host" "rm -f '$lock_file'"
|
|
||||||
echo "[End] [$(date +%Y-%m-%d-%H-%M-%S)] $user" >> $journal
|
|
||||||
}
|
|
||||||
|
|
||||||
# Register cleanup trap
|
|
||||||
trap cleanup EXIT INT TERM
|
|
||||||
|
|
||||||
# Start interactive session
|
|
||||||
echo "Starting SSH session (port $port). Lock file created."
|
|
||||||
ssh $jump -p "$port" "$user_host"
|
|
||||||
|
|
||||||
16
tun.sh
16
tun.sh
@ -4,7 +4,7 @@ version=0.1
|
|||||||
idx=0
|
idx=0
|
||||||
killFlag=0
|
killFlag=0
|
||||||
endpoint="192.168.105.100"
|
endpoint="192.168.105.100"
|
||||||
user="$USER"
|
user="vptyp"
|
||||||
cacheFile=.tunLast
|
cacheFile=.tunLast
|
||||||
privateKeyLoc="~/.ssh/id_ecdsa"
|
privateKeyLoc="~/.ssh/id_ecdsa"
|
||||||
override=0
|
override=0
|
||||||
@ -46,19 +46,9 @@ function usage {
|
|||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
function about {
|
|
||||||
echo "
|
|
||||||
${scriptName} ver.${version}
|
|
||||||
Setup with next settings:
|
|
||||||
started up under user: ${user}
|
|
||||||
endpoint: ${endpoint}
|
|
||||||
cacheFile: ${cacheFile}
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
|
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
|
||||||
-a | --about )
|
-V | --version )
|
||||||
about
|
echo "$version"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
-k | --kill )
|
-k | --kill )
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user