-
Notifications
You must be signed in to change notification settings - Fork 5
/
bashchat
191 lines (153 loc) · 4.68 KB
/
bashchat
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/local/bin/bash520
# BASHCHAT a telnet chat server
# Copyright 2023 by moshix - All rights reserved. You may not make copies or use any parts of this code
# Pre-reqs:
# bashchat (this program)
# chatserver.py from github.com/moshix/relaychat
# shellfunc_telnet from github.com/moshix/relaychat
# tcpserver from ucspi-tcp (brew,apt-get,yum)
# conv
# pv
# stdbuf
#
# version 0.02 LOGON handling
# version 0.03 main menu
# version 0.04 logging all user activity into local file
# version 0.05 establish link to chatserver.py
# version 0.06 use advanced FD and timeout stuff to handle connection forwarding
init() {
HOST="localhost" # host chatserver.py
PORT=9000 # port to chatserver.py
VERSION="1.8"
# terminal handling globals
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
blink=`tput blink`
rev=`tput rev`
reset=`tput sgr0`
# echo "${red}red text ${green}green text${reset}"
#
#
source shellfunc_telnet || echo "BASHCHAT039E TELNET ERROR!!! "
echo "$TCPREMOTEIP:$TCPREMOTEPORT ++ ($$)" >&2
trap 'sf_killchildren || :; echo "$TCPREMOTEIP:$TCPREMOTEPORT -- ($$)" >&2' EXIT
# the password is "test"
testhash="9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
sf_tn_init echo || echo "BASHCHAT201E Could not initialize with sf_tn_init!!! "
# Setting some gloal variables
bootwait=0.2
diskwait=0.3
currentprompt="#>"
echo -e "\e[1m_\e[0m"
sleep 0.8
clear
echo " ${cyan}"
echo " _____ _ _ _______ " && sleep 0.2
echo " / ____| | | | /\|__ __| "
echo " | | | |__| | / \ | | "
echo " | | | __ | / /\ \ | | " && sleep 0.2
echo " | |____| | | |/ ____ \| | "
echo " \_____|_| |_/_/ \_\_| " && sleep 0.2
echo "${reset}"
echo " "
#echo "${red}CHAT ${green}v$VERSION ${red}SERVER BASH VERSION STARTING...${reset}"
echo " "
echo "THIS ACCEPTABLE USE POLICY (“AUP”) APPLIES TO ALL VISITORS AND USERS OF SERVICES PROVIDED BY BASHCHAT , INCLUDING ALL PERSONS ENTERING THE FACILITY AND USERS OF BASHCHAT IN CONNECTION WITH THE FACILITY, WHETHER THE PERSON IS A CIVILIAN OR BCHATITARY VISITOR TO THE FACILITY (“USER”). THIS AUP ALSO APPLIES TO ALL VISITOR EQUIPMENT THAT IS UNDER A USER’S CONTROL OR RESIDES IN THE FACILITY OR IS ATTACHED TO BASHCHAT EQUIPMENT UTILIZED TO PROVIDE SERVICE. THIS AUP IS INCORPORATED BY REFERENCE INTO BASHCHAT GENERAL TERMS AND CONDITIONS FOR DELIVERY OF SERVICE (“T&CS”) AND THE VISITOR ORDER. "
echo " "
echo " "
} #end of init function
login_user() {
authenticated="no"
if ! sf_tn_read -t 120 -P "Logon: " command; then
echo
exit 0
fi
if ! sf_tn_read -t 120 -P "Password: " pswd; then
echo
exit 0
fi
logconn "$TCPREMOTEIP - login attempt with user: $command"
logconn "$TCPREMOTEIP - login attempt with pwd : $pswd"
if [[ "$command" != "chat" ]] || [[ "$pswd" != "chat" ]]; then
return $authenticated
else
authenticated="yes"
fi
}
open_conn() {
# open up link to chatserver.py on port $port
# exec 3<>/dev/tcp/hostname/port
# echo "request" 1>&3
#response="$(cat <&3)"
echo "${yellow}Attempting connection to comm server..${reset}"
sleep 0.2
exec 3<>/dev/tcp/$HOST/$PORT || no_conn
timeout 0.3s cat <&3 #show immediately what's coming back
}
no_conn() {
echo "${red}Cannot establish link to communication server. Exiting...${reset}"
exit 1
}
# main input loop
init #initialize system
login_user # ask for userid and pswd
if [[ "$authenticated" = "no" ]]; then
echo "${red} authentication failed. game over. ${reset}"
exit 0
fi
open_conn # open up connection to chatserer.py
while true; do
if ! sf_tn_read -t 120 -P "${white}#" command; then
echo
exit 0
fi
echo "${reset}"
firstsix=`echo $command | head -c 6`
#logconn "$TCPREMOTEIP - $command"
case $command in
+QUIT |+quit)
sleep 0.5
echo "BCHAT991I TERMINATING SESSIONS NOW"
logconn "$TCPREMOTEIP User volunterily closing session"
sleep 1
echo "/logoff" 1>&3
exit 0
;;
/logoff | /Logoff)
echo $command 1>&3
timeout 0.3s cat <&3
echo "${yellow}Leaving BASHCHAT now. Good bye!${reset}"
exit 0
;;
+CLS | +cls | +clear | i+CLEAR)
for i in {1..24}
do
echo " "
done
;;
*)
echo $command 1>&3
#response="$(cat <&3)"
timeout 0.2s cat <&3
echo $response
;;
esac
done
while true; do
sf_tn_read -t 120 line
if (( $? == 69 )); then # interrupt
echo "Interrupted!"
elif (( $? > 128 )); then # timeout
echo "Too slow!"
fi
[[ -n "$line" ]] || break
echo "Your line: $line"
done
echo "Bye."
echo
sleep 1