/
gw_menu
executable file
·91 lines (82 loc) · 2.69 KB
/
gw_menu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#
# Copyright (c) 2016 Alex Holst, Holst Sikkerhed <href:www.holstsikkerhed.dk>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Menu wrapper for gateway machines. Ctrl-C is ignored and user input is never
# passed to the command line.
umask 077
HELP=/etc/gw_menu/help
HOSTS=/etc/gw_menu/hosts
USERHOSTS=/etc/gw_menu/hosts.$USER
GREETING=/etc/gw_menu/greeting
USERIP=`echo $SSH_CLIENT | awk '{ print $1 }'`
trap "" 2
if [ -f $GREETING ]; then
grep -v "^#" $GREETING
fi
if [ ! -f $USERHOSTS ]; then
echo Sorry, your account is not authorized to connect at this time.
echo Please ask as indicated above to have your access reinstated.
logger -i -t gw_menu $USERHOSTS does not exist: $USER login from $USERIP rejected.
exit 1
fi
if [ ! -f $HOSTS ]; then
echo Sorry, logins are not allowed at this time.
logger -i -t gw_menu $HOSTS does not exist: $USER login from $USERIP rejected.
exit 1
fi
logger -i -t gw_menu $USER logged in from $USERIP
while true
do
echo "`hostname -s`> \c"
if read line
then
case "$line" in
"") continue;;
esac
set -- $line
case "$1" in
uptime) uptime;;
time) TZ=UTC date
TZ=NZ date
date;;
finger|who|w) finger;;
help) grep -v "^#" $HELP
while read h comments; do grep "$h" $HOSTS < $USERHOSTS; done;
printf "\n";;
exit|quit|bye|logout) exit;;
motd) grep -v "^#" $GREETING;;
# If the user input is not a command, it may be a hostname to
# connect to. We do strict checking against the list of known
# hostnames, and if there's a match we connect to the system.
# Output from grep command, not user input, is passed to the
# command line.
*) if match=`grep "^$1$" $HOSTS` ; then
logger -i -t gw_menu $USER connected to $match
ssh $match
logger -i -t gw_menu $USER disconnected from $match
unset $match
else
# User input was not listed in the host file.
echo "Unknown command or host: $line."
echo "Enter 'help' for help."
logger -i -t gw_menu "$USER Unknown command or host: $line"
fi
esac
else
break
fi
done
exit