3 bbs_dir
=$
(dirname "$0");
4 bbs_title
="Harvie's BBS";
13 chatrooms_dir
="$data_dir/chatrooms";
14 boards_dir
="$data_dir/boards";
15 archive_dir
="$data_dir/archive";
17 welcome_file
="$config_dir/welcome";
18 about_file
="$config_dir/about";
19 farewell_file
="$config_dir/farewell";
20 users_file
="$config_dir/users";
21 log_file
="$config_dir/security.log";
26 dialog
=$
(which dialog
);
27 export DIALOGOPTS
="--no-shadow --trim --title \"$bbs_title\" --backtitle \"$bbs_title\"";
28 w
(){ echo $
(tput cols
); } #dialog width
29 h
(){ echo $
(($
(tput lines
)-0)); } #dialog height (LINES-5 to display backtitle)
30 m
(){ echo $
(($
(tput lines
)-12)); } #dialog menu size
31 bbs_ssh_ip
=$
(echo $SSH_CLIENT | cut
-d' ' -f1); #Works only with OpenSSH
32 alias ls=ls; #Get rid of that 'user friendly' crap ;)
35 bbs_welcome_banner
() {
36 cat "$welcome_file" > "$tmp";
37 echo "$SSH_CLIENT" >>"$tmp"; #Works only with OpenSSH
38 $dialog --title "Welcome to $bbs_title" --exit-label "Enter" --textbox "$tmp" $
(h
) $
(w
);
39 if [ "$?" != 0 ]; then bbs_exit
; fi;
43 $dialog --title "About $bbs_title" --exit-label "Agree" --textbox "$about_file" $
(h
) $
(w
);
54 cat "$users_file" |
grep "^[^# ]" |
while read i
; do
55 login
=$
(echo "$i" | cut
-d: -f1);
56 passw
=$
(echo "$i" | cut
-d: -f2);
57 group
=$
(echo "$i" | cut
-d: -f3);
58 if [[ "$1" == "$login" && "$2" == "$passw" ]]; then
60 echo "($(date +%T)) $bbs_ssh_ip: Login to user $1 successfull" >>"$log_file";
67 then echo '[DIR]' #$(ls -A "$1"); #<- uncomment rest of the line to have directory preview
68 else echo #$(head -n1 "$1"); #<- uncomment rest of the line to have file preview
72 bbs_browse_dir
() { #brand new dialog filelisting - supposed to be secure to directory traversal!
75 #call dialog with output of ls...
76 ls -A1 --group-directories-first "$1" |
while read i
; do
77 echo -n "$i"; echo -ne "\x00";
78 echo -n $
(bbs_preview
"$1/$i"); echo -ne "\x00"
79 done |
xargs -0 $dialog --menu -- "Select the board" $
(h
) $
(w
) $
(m
) 2>"$tmp";
81 if [ "$?" != 0 ]; then
83 #$dialog --pause "HOOOPS! Sorry. None or empty directory selected..." $(h) $(w) "$fail_delay";
85 selected
=$
( echo -n "$1/"; cat "$tmp" );
86 if [[ -d "$selected" ]];
88 bbs_browse_dir
"$selected"; return "$?";
90 echo "$selected" >"$tmp"; return 0;
97 bbs_browse_dir
() { #brand new dialog filelisting - supposed to be secure to directory traversal!
100 "$utils_dir/fselect" "$1" "$tmp"
102 if [ "$?" != 7 ]; then
104 #$dialog --pause "HOOOPS! Sorry. None or empty directory selected..." $(h) $(w) "$fail_delay";
106 #$dialog --pause "HOOOPS! Sorry. None or empty directory selected..." $(h) $(w) "$fail_delay";
107 #selected=$( echo -n "$1/"; cat "$tmp" );
108 #echo "$selected" >"$tmp";
115 #bbs_file_select() { #deprecated
116 # ls -A1 $@ | while read i; do
117 # echo -n "$i"; echo -ne "\x00";
118 # echo -n $(bbs_preview "$1/$i"); echo -ne "\x00"
119 # done | xargs -0 $dialog --menu -- "Select the file" $(h) $(w) $(m);
124 #This is supposed to be a secure way to edit the file...
128 #Chat##################
131 $dialog --inputbox "Enter message" $
(h
) $
(w
) 2>"$tmp"
132 if [ "$?" != 0 ]; then return; fi;
133 message
=$
(cat "$tmp");
134 echo "($(date +%T))" "$login: $message" >>"$1"
139 $dialog --title "Chatroom $1 (esc to leave)" --exit-label "Write message" --tailbox "$1" $
(h
) $
(w
);
140 if [ "$?" != 0 ]; then return; fi;
146 bbs_browse_dir
"$chatrooms_dir";
147 if [ "$?" != 0 ]; then return; fi;
148 chatroom
=$
(cat "$tmp");
149 bbs_chat_join
"$chatroom";
154 #Mail####################
157 $dialog --pause "HOOOPS! Sorry. Mail not yet ;o)" $
(h
) $
(w
) "$fail_delay";
160 #Archive#################
163 #echo BBS_BOARD_READ "$1" | less;
165 $dialog --textbox "$1" $
(h
) $
(w
);
170 bbs_browse_dir
"$archive_dir";
173 else bbs_board_read $
(cat "$tmp");
178 #Forum###################
182 bbs_browse_dir
"$boards_dir";
185 else bbs_board_read $
(cat "$tmp");
191 #System menu#############
193 bbs_admin_console
() {
194 #While this BBS is not complete, i will give the shell to the admin group to fix-up everything ;o)
195 #bash can be replaced by chrooted SASH (ex.) to improve security...
196 $dialog --insecure --passwordbox "Enter your password" $
(h
) $
(w
) 2>"$tmp";
197 if [ "$?" != 0 ]; then return; fi;
198 repassword
=$
(cat "$tmp");
199 if [[ "$group" == "admin" && "$repassword" == "$password" ]]; then
201 echo -e "This is management console. Press ctrl+d or type exit to leave...\n";
205 $dialog --pause "Authentification failed. Check your password and/or membership in admin group." $
(h
) $
(w
) "$fail_delay";
210 if [ "$group" == "guest" ]; then
211 $dialog --pause "Users from guest group can't browse logs!" $
(h
) $
(w
) "$fail_delay";
214 $dialog --textbox "$log_file" $
(h
) $
(w
);
218 echo "LOGIN: $login" >"$tmp";
219 echo "GROUP: $group" >>"$tmp";
221 echo "IP (if any): $SSH_CLIENT" >>"$tmp"; #Works only with OpenSSH
222 echo "CONNECTION (if any): $SSH_CONNECTION" >>"$tmp"; #Works only with OpenSSH
223 $dialog --title "Userinfo for $login" --textbox "$tmp" $
(h
) $
(w
);
227 cat "$users_file" |
grep "^[^# ]" |
while read i
; do
228 login
=$
(echo "$i" | cut
-d: -f1);
229 group
=$
(echo "$i" | cut
-d: -f3);
230 echo -e "$group\t\t$login";
231 done |
sort -u >"$tmp";
232 $dialog --title "Userlist for $bbs_title" --textbox "$tmp" $
(h
) $
(w
);
235 bbs_register
() { ########################################################<-incompleteeeeeeeee
236 echo -n "$SSH_CLIENT:$ " 2>"$tmp";
237 $dialog --inputbox "Send message to admins\n\
238 eg.:\nREGISTRATION: yournick:yourpasswd CONTACT:your@adress.net Few words about you here...\n\
239 or\nSome other message..." $
(h
) $
(w
) 2>>"$tmp";
240 if [ "$?" != 0 ]; then return; fi;
243 bbs_contact_admins
() { ########################################################<-incompleteeeeeeeee
244 echo -n "$SSH_CLIENT:$ " 2>"$tmp";
245 $dialog --inputbox "Send message to admins\n\
246 eg.:\nREGISTRATION: yournick:yourpasswd CONTACT:your@adress.net Few words about you here...\n\
247 or\nSome other message..." $
(h
) $
(w
) 2>>"$tmp";
248 if [ "$?" != 0 ]; then return; fi;
253 $dialog --menu "System Menu" $
(h
) $
(w
) $
(m
)\
254 userinfo
"Info about you"\
255 userlist
"Info about other users"\
257 register
"Submit request for new account"\
258 contact
"Contact administrators"\
259 admin
"Enter admin management console..."\
260 back
"Go back to the main menu..."\
262 if [ "$?" != 0 ]; then return; fi;
266 "userinfo") bbs_user_info
;;
267 "userlist") bbs_user_list
;;
269 "register") bbs_register
;;
270 "contact") bbs_contact_admins
;;
271 "admin") bbs_admin_console
;;
273 *) echo bad choice... keep trying.
;;
278 #CODE###########################################################################
284 $dialog --inputbox "Enter your nickname" $
(h
) $
(w
) 2>"$tmp";
285 if [ "$?" != 0 ]; then bbs_exit
; fi;
287 $dialog --insecure --passwordbox "Enter your password" $
(h
) $
(w
) 2>"$tmp";
288 if [ "$?" != 0 ]; then bbs_exit
; fi;
289 password
=$
(cat "$tmp");
291 group
=$
(bbs_check_login
"$login" "$password");
297 $dialog --pause "Login failed! Press enter to continue..." $
(h
) $
(w
) "$fail_delay";
298 echo "($(date +%T)) $bbs_ssh_ip: Login to user $login failed" >>"$log_file";
301 if [[ "$group" == "guest" && -n "$bbs_ssh_ip" ]]; then
302 login
="[$bbs_ssh_ip]$login";
306 #echo Loged as "$login:$group":$(mkpasswd "$password"); bbs_exit;
309 $dialog --no-cancel --menu "Main Menu" $
(h
) $
(w
) $
(m
)\
310 chat
"Browse online chatrooms..."\
311 boards
"Browse boards..."\
312 archive
"Browse archive..."\
313 mail "Send/receive personal messages..."\
314 system
"Enter system menu..."\
315 about
"About this BBS..."\
322 "boards") bbs_board
;;
323 "archive") bbs_archive
;;
325 "system") bbs_system_menu
;;
328 *) $dialog --pause "HOOOPS! Sorry. $choice not yet ;o)" $
(h
) $
(w
) "$fail_delay";;