diff --git a/.gitignore b/.gitignore index f15af53..f08cf15 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,6 @@ core docs/site utils/reset_pass/reset_pass .vscode +last10v2.dat +utils/filecenter/filecenter +utils/dosbox_shim/shim diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..7582e2a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ +image: gcc + +before_script: + - apt-get update -qq && apt-get install -y -qq build-essential libsqlite3-dev libreadline-dev git libssh-dev libssl1.0-dev libncurses5-dev libmicrohttpd-dev libdbd-sqlite3-perl sed + +magicka: + script: + - make www \ No newline at end of file diff --git a/STRINGS.CHANGES b/STRINGS.CHANGES index fff2b32..63ba386 100644 --- a/STRINGS.CHANGES +++ b/STRINGS.CHANGES @@ -4,6 +4,88 @@ If you are using your own custom strings file, you will need to add / modify the new string on the line specified. Be sure to remove the start and end quotation marks. +Changes from v0.9-alpha -> v0.10-alpha +-------------------------------------------------------------- + +LINE: 275 NEW +OLDSTRING: (NONE) +NEWSTRING: "\r\n\e[1;31mError executing archiver.\r\n\e[0m" + +LINE: 276 NEW +OLDSTRING: (NONE) +NEWSTRING: "\r\n\r\n\e[1;37m(\e[1;32mV\e[1;37m)iew or \e[1;37m(\e[1;32mU\e[1;37m)pdate Automessage or \e[1;37m(\e[1;31mQ\e[1;37m)uit: \e[0m" + +LINE: 204 MODIFIED +OLDSTRING: "\e[1;31mUser not found! Assuming new user...\e[0m\r\n\r\n" +NEWSTRING: "\r\n\e[1;31mUser not found!\e[0m\r\n\r\n" + +LINE: 277 NEW +OLDSTRING: (NONE) +NEWSTRING: "\r\nScan for new personal mail? (Y/N/S): " + +LINE: 278 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;32mConference: \e[1;37m%d. %s\e[0m\r\n" + +LINE: 279 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;32m Area: \e[1;37m%d. %s \e[1;33m(%d New Messages)\e[0m\r\n\r\n" + +LINE: 280 NEW +OLDSTRING: (NONE) +NEWSTRING: "Read Now ? (Y / N): " + +LINE: 5 MODIFIED +OLDSTRING: "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n" +NEWSTRING: "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d \e[1;33m%c\e[0m\r\n" + +LINE: 281 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;33mSystem Blog\e[0m\r\n" + +LINE: 282 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n" + +LINE: 283 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[0mNo Entries...\r\n" + +LINE: 284 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;37m%s (by \e[1;36m%s\e[1;37m)\r\n" + +LINE: 285 NEW +OLDSTRING: (NONE) +NEWSTRING: "\e[1;35m%d:%02d%s %s, %s %d %d\r\n" + +LINE: 286 NEW +OLDSTRING: (NONE) +NEWSTRING: "\r\n\r\n\e[1;37mEnter a title:\e[0m " + +LINE 128 MODIFIED +OLDSTRING: "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" +NEWSTRING: "\e[1;30m[\e[1;34m%5d\e[1;30m]\e[1;32m*\e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" + +LINE 129 MODIFIED +OLDSTRING: "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" +NEWSTRING: "\e[1;30m[\e[1;34m%5d\e[1;30m] \e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" + +LINE 189 MODIFIED +OLDSTRING: "\e[1;30m[\e[1;34;44m%4d\e[1;30;40m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" +NEWSTRING: "\e[1;30m[\e[1;34;44m%5d\e[1;30;40m]\e[1;32m*\e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" + +LINE 190 MODIFIED +OLDSTRING: "\e[1;30m[\e[1;34;44m%4d\e[1;30;40m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" +NEWSTRING: "\e[1;30m[\e[1;34;44m%5d\e[1;30;40m] \e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n" + +LINE 115 MODIFIED +OLDSTRING: "\r\n\r\nReplying to: %s\r\n" +NEWSTRING: "\r\n\r\n\e[1;32m To: \e[0m" + +LINE 116 MODIFIED +OLDSTRING: "Change Subject? (Y/N) " +NEWSTRING: "\r\n\e[1;32mSubject: \e[0m" Changes from v0.8-alpha -> v0.9-alpha -------------------------------------------------------------- diff --git a/deps/aha/aha.c b/deps/aha/aha.c index faa53de..bac96b0 100644 --- a/deps/aha/aha.c +++ b/deps/aha/aha.c @@ -572,6 +572,6 @@ char * aha(char *input) //Footer if ((fc!=-1) || (bc!=-1) || (ul!=0) || (bo!=0) || (bl!=0)) append_output(&output, "\n", &size, &outat); - + free(unmangle_out); return output; } diff --git a/deps/lua/Makefile b/deps/lua/Makefile index 89cf618..8faa179 100644 --- a/deps/lua/Makefile +++ b/deps/lua/Makefile @@ -49,7 +49,7 @@ ALL_A= $(LUA_A) # Targets start here. default: $(PLAT) -all: $(ALL_T) +all: $(ALL_A) o: $(ALL_O) diff --git a/dist/ansis/bulletin1.ans b/dist/ansis/bulletin1.ans index 04be840..8769136 100644 Binary files a/dist/ansis/bulletin1.ans and b/dist/ansis/bulletin1.ans differ diff --git a/dist/ansis/mainmenu.ans b/dist/ansis/mainmenu.ans index 8d0f1a4..7bf2e1f 100644 Binary files a/dist/ansis/mainmenu.ans and b/dist/ansis/mainmenu.ans differ diff --git a/dist/config/bbs.ini b/dist/config/bbs.ini index 1e0c3e0..0da2382 100644 --- a/dist/config/bbs.ini +++ b/dist/config/bbs.ini @@ -14,6 +14,7 @@ External Editor stdio = true External Editor Codepage = CP437 Automessage Write Level = 10 Fork = false +Run As User = USERNAME Enable WWW = false WWW Port = 8080 WWW URL = http://127.0.0.1:8080/ diff --git a/dist/config/filesgen.ini b/dist/config/filesgen.ini index 8d210f1..ec292da 100644 --- a/dist/config/filesgen.ini +++ b/dist/config/filesgen.ini @@ -1,5 +1,6 @@ [main] Visible Sec Level = 10 +Visible on Web = false [Misc] Database = files_misc diff --git a/dist/magicka.strings b/dist/magicka.strings index 5b7b778..6c653cf 100644 --- a/dist/magicka.strings +++ b/dist/magicka.strings @@ -2,7 +2,7 @@ \r\n\r\nTimeout waiting for input..\r\n \r\n\e[1;37mLast 10 callers:\r\n \e[1;30m-------------------------------------------------------------------------------\r\n -\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n +\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d \e[1;33m%c\e[0m\r\n \e[1;30m-------------------------------------------------------------------------------\e[0m\r\n \e[1;37mPress any key to continue...\e[0m\r\n \r\n\r\n\e[1;37mSystem Information\r\n @@ -112,8 +112,8 @@ Quoting Cancelled\r\n \e[1;30m-------------------------------------------------------------------------------\e[0m\r\n \r\n\e[1;37mPress \e[1;36mR \e[1;37mto reply, \e[1;36mQ \e[1;37mto quit, \e[1;36mB \e[1;37mto go Back, \e[1;36mSPACE \e[1;37mfor Next Mesage... \r\nSorry, you are not allowed to post in this area\r\n -\r\n\r\nReplying to: %s\r\n -Change Subject? (Y/N) +\r\n\r\n\e[1;32m To: \e[0m +\r\n\e[1;32mSubject: \e[0m \r\nNew subject: \r\nOk, not changing the subject line... \r\n\r\nNo more messages\r\n @@ -125,8 +125,8 @@ Read message [1-%d] or N for New: \r\nMailing to @%d\r\n Start at message [1-%d] or N for New? \e[2J\e[1;1H\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m -\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n -\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n +\e[1;30m[\e[1;34m%5d\e[1;30m]\e[1;32m*\e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n +\e[1;30m[\e[1;34m%5d\e[1;30m] \e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n (#) Read Message # (Q) Quit (ENTER) Continue\r\n \r\nThere is no mail in this area\r\n \r\n\r\nMail Conferences:\r\n\r\n @@ -186,8 +186,8 @@ Is this Correct? (Y/N) \e[1;37mPress any key to continue...\e[0m \e[24;1H\e[1;32mUp / Down \e[1;37mto Scroll, \e[1;32mLeft / Right \e[1;37mChange Message, \e[1;32mR \e[1;37mReply, \e[1;32mQ \e[1;37mQuit\e[K\e[0m \e[23;1H\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n -\e[1;30m[\e[1;34;44m%4d\e[1;30;40m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n -\e[1;30m[\e[1;34;44m%4d\e[1;30;40m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n +\e[1;30m[\e[1;34;44m%5d\e[1;30;40m]\e[1;32m*\e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n +\e[1;30m[\e[1;34;44m%5d\e[1;30;40m] \e[1;37m%-24.24s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n \e[24;1H\e[1;37;44mUp/Down to Scroll, Enter to read, Q to quit\e[K\e[0m \e[24;1H\e[1;32mUp / Down \e[1;37mto Scroll, \e[1;32mLeft / Right \e[1;37mto Change Message, \e[1;32mR \e[1;37mreply, \e[1;32mD \e[1;37mDelete, \e[1;32mQ \e[1;37mquit\e[K\e[0m \e[1;30m[\e[1;34;44m%4d\e[1;30;40m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[K\e[0m\r\n @@ -201,7 +201,7 @@ Is this Correct? (Y/N) \r\nPlease enter a description:\r\n ...Found!\r\n\r\n \e[1;32mUpload Successful!\e[0m\r\n -\e[1;31mUser not found! Assuming new user...\e[0m\r\n\r\n +\r\n\e[1;31mUser not found!\e[0m\r\n\r\n \e[1;32mSuccesfully processed \e[1;37m%d \e[1;32mmessages!\r\n\e[0m \e[0;36mA. \e[1;37mDefault Archiver (\e[1;33m%s\e[1;37m)\r\n \r\n\e[1;32mSelect an archiver...\e[0m\r\n\r\n @@ -272,3 +272,15 @@ File exists!\r\n \e[24;1H\e[1;37;44mUp / Down to Select, A to Add, D to Delete, Q to Quit\e[K \e[8;28H\e[1;31;40mNo BBSes in the list! \e[10;22H\e[1;37mPress \e[1;33mA \e[1;37m to Add yours or \e[1;33mQ \e[1;37mto Quit\e[0m +\r\n\e[1;31mError executing archiver.\r\n\e[0m +\r\n\r\n\e[1;37m(\e[1;32mV\e[1;37m)iew or \e[1;37m(\e[1;32mU\e[1;37m)pdate Automessage or \e[1;37m(\e[1;31mQ\e[1;37m)uit: \e[0m +\r\nScan for new personal mail? (Y/N/S): +\e[1;32mConference: \e[1;37m%d. %s\e[0m\r\n +\e[1;32m Area: \e[1;37m%d. %s \e[1;33m(%d New Messages)\e[0m\r\n\r\n +Read Now ? (Y / N): +\e[1;33mSystem Blog\e[0m\r\n +\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n +\e[0mNo Entries...\r\n +\e[1;37m%s (by \e[1;36m%s\e[1;37m)\r\n +\e[1;35m%d:%02d%s %s, %s %d %d\r\n +\r\n\r\n\e[1;37mEnter a title:\e[0m diff --git a/dist/menus/main.mnu b/dist/menus/main.mnu index dd47711..8061a8d 100644 --- a/dist/menus/main.mnu +++ b/dist/menus/main.mnu @@ -2,7 +2,7 @@ LUASCRIPT mainmenu ANSIFILE mainmenu HOTKEY O -COMMAND AUTOMESSAGE_WRITE +COMMAND AUTOMESSAGE HOTKEY A COMMAND TEXTFILES diff --git a/dist/scripts/login_stanza.lua b/dist/scripts/login_stanza.lua index 99ef565..153cff8 100644 --- a/dist/scripts/login_stanza.lua +++ b/dist/scripts/login_stanza.lua @@ -30,6 +30,9 @@ while(true) do i = i + 1; end +-- Display Blog +bbs_display_blog(); + -- Display Info local bbsname; local sysopname; @@ -60,9 +63,13 @@ bbs_write_string("\r\n\r\n\027[1;37mLast 10 callers:\r\n"); bbs_write_string("\027[1;30m-------------------------------------------------------------------------------\r\n"); while (i < 10) do - user, location, ltime = bbs_read_last10(i); + user, location, ltime, calls = bbs_read_last10(i); if (user ~= nil) then - bbs_write_string(string.format("\027[1;37m%-16s \027[1;36m%-32s \027[1;32m%s\r\n", user, location, os.date("%H:%M %d-%m-%y" ,ltime))); + if calls == 1 then + bbs_write_string(string.format("\027[1;37m%-16s \027[1;36m%-32s \027[1;32m%s \027[1;33mN\r\n", user, location, os.date("%H:%M %d-%m-%y" ,ltime))); + else + bbs_write_string(string.format("\027[1;37m%-16s \027[1;36m%-32s \027[1;32m%s\r\n", user, location, os.date("%H:%M %d-%m-%y" ,ltime))); + end end i = i + 1; @@ -83,6 +90,8 @@ end bbs_mail_scan(); +bbs_personal_mail_scan(); + bbs_file_scan(); -- Display Auto Message diff --git a/dist/www-bootstrap/header.tpl b/dist/www-bootstrap/header.tpl index a2db158..a3c86d4 100644 --- a/dist/www-bootstrap/header.tpl +++ b/dist/www-bootstrap/header.tpl @@ -65,6 +65,9 @@ + @@ -74,6 +77,9 @@ + diff --git a/dist/www-bootstrap/static/newuser.png b/dist/www-bootstrap/static/newuser.png new file mode 100644 index 0000000..5950e99 Binary files /dev/null and b/dist/www-bootstrap/static/newuser.png differ diff --git a/dist/www-bootstrap/static/style-mobile.css b/dist/www-bootstrap/static/style-mobile.css index c2388a1..d7a6f6c 100644 --- a/dist/www-bootstrap/static/style-mobile.css +++ b/dist/www-bootstrap/static/style-mobile.css @@ -341,6 +341,37 @@ max-width: 100%; } +.last10-new { + position: relative; + width: 100%; + min-height: 1px; + padding-right: 15px; + padding-left: 15px; + + -webkit-box-flex: 0; + -ms-flex: 100%; + flex: 0 0 100%; + max-width: 100%; +} + +.blog-header { + border: 1px solid #666666; + background-color: #eee; + padding: 5px; +} + +.blog-date { + font-size: small; +} + +.blog-author { + font-size: small; +} + +.blog-entry { + padding: 25px; +} + #msgbody { background-color: black; color: gray; @@ -363,4 +394,40 @@ textarea { padding: 0px; max-width: 100%; overflow-x: none; +} + +.filedesc { + background-color: black; + color: gray; + font-family: 'pxplus_ibm_vga8regular'; + line-height: 1; + padding: 5px; +} + +table { + width: 100%; + border-collapse: collapse; +} + +thead { + color: #eee; + background-color: #666666; +} + +thead th:nth-child(1) { + width: 5%; +} + +thead th:nth-child(2) { + width: 5%; +} + +thead th:nth-child(3) { + width: 90%; +} + +th, td { + vertical-align: top; + padding: 20px; + border-top: 1px solid #666; } \ No newline at end of file diff --git a/dist/www-bootstrap/static/style.css b/dist/www-bootstrap/static/style.css index 1b8ee14..367919b 100644 --- a/dist/www-bootstrap/static/style.css +++ b/dist/www-bootstrap/static/style.css @@ -288,6 +288,25 @@ background-color: #111111; } +.blog-header { + border: 1px solid #666666; + background-color: #eee; + padding: 5px; +} + +.blog-date { + float: right; + font-size: small; +} + +.blog-author { + font-size: small; +} + +.blog-entry { + padding: 25px; +} + .last10-row { background-color: #eee; display: -webkit-box; @@ -331,9 +350,22 @@ padding-left: 15px; -webkit-box-flex: 0; - -ms-flex: 0 0 33.333333%; - flex: 0 0 33.333333%; - max-width: 33.333333%; + -ms-flex: 0 0 23.333333%; + flex: 0 0 23.333333%; + max-width: 23.333333%; +} + +.last10-new { + position: relative; + width: 100%; + min-height: 1px; + padding-right: 15px; + padding-left: 15px; + + -webkit-box-flex: 0; + -ms-flex: 0 0 10%; + flex: 0 0 10%; + max-width: 10%; } #msgbody { @@ -343,3 +375,39 @@ line-height: 1; padding: 5px; } + +.filedesc { + background-color: black; + color: gray; + font-family: 'pxplus_ibm_vga8regular'; + line-height: 1; + padding: 5px; +} + +table { + width: 100%; + border-collapse: collapse; +} + +thead { + color: #eee; + background-color: #666666; +} + +thead th:nth-child(1) { + width: 30%; +} + +thead th:nth-child(2) { + width: 10%; +} + +thead th:nth-child(3) { + width: 60%; +} + +th, td { + vertical-align: top; + padding: 20px; + border-top: 1px solid #666; +} \ No newline at end of file diff --git a/docs/docs/guide/doors/dosbox.md b/docs/docs/guide/doors/dosbox.md index 68aa66f..feee069 100644 --- a/docs/docs/guide/doors/dosbox.md +++ b/docs/docs/guide/doors/dosbox.md @@ -38,47 +38,54 @@ These commands will compile and install DosBox into /usr/local/bin. ## Create Configuration File -Next you will need to create a config file which enables the serial port for socket inheritance, and also mounts drives so that DosBox can access both your doors and your BBS drop files. +Next you will need to create a config file which enables the serial port, and also mounts drives so that DosBox can access both your doors and your BBS drop files. -An example setup is here: [dosbox.conf](https://gist.github.com/apamment/98e42db83c452105b3e21a8bc062c5c3) +An example setup is here: [dosbox.conf](https://gist.github.com/apamment/2e5b00eda2f304f2bc7d298a0487bd9b) In this example, drive C: is the location where my doors are stored, dropfiles will be copied to the door directory. +Be sure to change the port for each door. In this example the port is 9999. + ## Create Shell Script to Invoke DosBox The shell script you need will vary from system to system, but basically, you want to: - * ensure no one else is using the door before you start it * Copy the dropfile to the door directory * make DosBox not use an X11 window, - * ensure that the dropfiles have DOS line endings * launch DosBox with the command to start the batch file in the next section. Here is an example script I use for Freshwater Fishing: #!/bin/bash export SDL_VIDEODRIVER="dummy" - NODE=$1 - SOCKET=$2 + NODE=$2 + PORT=$1 trap '' 2 - if [ ! -e /home/pi/MagickaBBS/doors/ffs.inuse ]; then - touch /home/pi/MagickaBBS/doors/ffs.inuse - cp /home/pi/MagickaBBS/node${NODE}/door.sys /home/pi/MagickaBBS/doors/ffs/ - /usr/local/bin/dosbox -socket $SOCKET -c "C:\ffs\ffs.bat ${NODE}" -conf /home/pi/MagickaBBS/doors/dosbox.conf - rm /home/pi/MagickaBBS/doors/ffs.inuse - fi + cp /home/pi/MagickaBBS/node${NODE}/door.sys /home/pi/MagickaBBS/doors/ffs/ + /usr/local/bin/dosbox -c "C:\ffs\ffs.bat ${NODE}" -conf /home/pi/MagickaBBS/doors/dosbox-ffs.conf > /dev/null 2>&1 trap 2 - -This will just dump the user back to the BBS if the door is in use. You could get fancy and use the 'inuse' door I created which will display an in-use message and then quit ([INUSE Door](https://github.com/apamment/inuse)), but that is outside the scope of this document. - You will also need to make the bash script executable: chmod +x ffs.sh +## Create Shell Script to Invoke the DosBox Shim + + #!/bin/bash + + if [ ! -e /home/pi/MagickaBBS/doors/ffs.inuse ]; then + touch /home/pi/MagickaBBS/doors/ffs.inuse + /home/pi/MagickaBBS/utils/dosbox_shim/shim 9999 $NODE /home/andrew/MagickaBBS/doors/ffs.sh + rm /home/pi/MagickaBBS/doors/ffs.inuse + fi + +This will just dump the user back to the BBS if the door is in use. You could get fancy and use the 'inuse' door I created which will display an in-use message and then quit ([INUSE Door](https://github.com/apamment/inuse)), but that is outside the scope of this document. + +Again be sure to change the port to match the dosbox config for this door. + ## Create Batch File to Start Door Please note, you will need to setup your doors using DosBox in the normal fashion, either you set them up on a machine where you have a monitor attached and transfer the files over, or you run DosBox directly from your PI with either remote X11 or a local monitor. @@ -101,13 +108,13 @@ This loads BNU, then launches the door with the drop file. ## Setup BBS -Finally, you will want to setup your BBS to call the script you made in Step 6. You also need to pass the node number and socket handle. +Finally, you will want to setup your BBS to call the dosbox shim script. In doors.ini, something like [Freshwater Fishing] - command = /home/pi/MagickaBBS/doors/ffs.sh - stdio = false + command = /home/pi/MagickaBBS/doors/ffs-shim.sh + stdio = true codepage = CP437 Then, add a command to your doors menu: diff --git a/docs/docs/guide/files/config.md b/docs/docs/guide/files/config.md index cca4b63..f3f1b5d 100644 --- a/docs/docs/guide/files/config.md +++ b/docs/docs/guide/files/config.md @@ -6,6 +6,7 @@ File directories and subdirectories are similar to message conferences and areas [main] Visible Sec Level = 10 + Visible On Web = false [Area One] Database = area_one @@ -19,7 +20,11 @@ File directories and subdirectories are similar to message conferences and areas Upload Sec Level = 99 Upload Path = /path/to/MagickaBBS/files/area_two -In the main section there is just one variable that applies to the whole directory, **Visible Sec Level** is the security level required to view the directory. +In the main section variables apply to the whole directory, + +**Visible Sec Level** is the security level required to view the directory. + +**Visible On Web** is either true or false if you want it visible and the files downloadable via the website. The section name for the sub-directory is the name of the sub directory. @@ -33,9 +38,10 @@ The section name for the sub-directory is the name of the sub directory. ## Uploading Files -When a user (or the sysop) uploads a file, they are not *approved* by default, so they will not be shown in the listings. To approve uploaded files, the sysop should run the fileapprove utility on the database. +When a user (or the sysop) uploads a file, they are not *approved* by default, so they will not be shown in the listings. To approve uploaded files, the sysop should run the filecenter utility on the database. - ./utils/fileapprove/fileapprove -d database.sq3 + cd utils/filecenter + ./filecenter -c ../../config/bbs.ini This will list all the files in the database, and allow the sysop to toggle the approved status, or remove the file entirely. diff --git a/docs/docs/guide/ini/bbs.md b/docs/docs/guide/ini/bbs.md index 94daea5..6489357 100644 --- a/docs/docs/guide/ini/bbs.md +++ b/docs/docs/guide/ini/bbs.md @@ -18,6 +18,7 @@ This is the main bbs INI file and contains the following sections * **External Editor Codepage** The codepage the external editor uses (CP437 for magiedit) (Only required if External Editor CMD is set) * **Automessage Write Level** The security level a user needs to change the automessage (Required) * **Fork** True if you want the BBS to run in daemon mode false if not. (Required) + * **Run as User** Which user to run at if invoked as root. (Required if running as root) * **Enable WWW** True to enable the WWW server, false if not. (Required) * **WWW Port** Port to listen for HTTP connections (Required if WWW is enabled) * **WWW URL** Public facing url of the BBS (Required if WWW is enabled) diff --git a/docs/docs/guide/installation.md b/docs/docs/guide/installation.md index e191a2d..9505741 100644 --- a/docs/docs/guide/installation.md +++ b/docs/docs/guide/installation.md @@ -24,10 +24,12 @@ should work on debian and debian derivatives. ## Install Magicka -Clone the repo +Clone the repo and checkout the branch you want, eg. v0.9-patch. git clone https://github.com/MagickaBBS/MagickaBBS + git checkout v0.9-patch + Build the BBS make www diff --git a/docs/docs/guide/menus.md b/docs/docs/guide/menus.md index 5ca93a8..03b5d02 100644 --- a/docs/docs/guide/menus.md +++ b/docs/docs/guide/menus.md @@ -32,6 +32,17 @@ Next is a DATA command, this specifies the DATA associated with the COMMAND comm Finally, an optional SECLEVEL command indicates the required security level for a user to be able to trigger a command. +## Chaining Commands + +As of v0.10 commands can be chained one after the other under a single hotkey. For example, a menu that would display a text file then run a door might look like this: + + HOTKEY A + COMMAND DISPLAYTEXTFILE + DATA sometextfile + COMMAND RUNDOOR + DATA door to run + SECLEVEL 10 + ## List of COMMANDs **SUBMENU** loads a new menu. DATA is the name of the submenu @@ -118,7 +129,7 @@ Finally, an optional SECLEVEL command indicates the required security level for **FILESCAN** Scan for new files. -**FULLMAILSCAN** Scan for new messages and display them. +**FULLMAILSCAN** Scan for new messages and display them. Optional DATA PERSONAL for personal mail scan. **FILESEARCH** Search for a file. @@ -131,3 +142,7 @@ Finally, an optional SECLEVEL command indicates the required security level for **NLBROWSER** Browse the nodelist for the current conference. **SENDFEEDBACK** Send feedback to the Sysop. + +**BLOGDISPLAY** Display the System Blog. + +**BLOGWRITE** Add an entry to the System Blog. \ No newline at end of file diff --git a/docs/docs/guide/scripting.md b/docs/docs/guide/scripting.md index 571f34b..a7a486e 100644 --- a/docs/docs/guide/scripting.md +++ b/docs/docs/guide/scripting.md @@ -96,6 +96,8 @@ Where data is the name of the lua script to call without the extension. **bbs_full_mail_scan** Performs a full mail scan (like a mail scan but also displays new messages) +**bbs_personal_mail_scan** Performs a full mail scan (like a full mail scan but only displays personal messages) + **bbs_get_userhandle** Returns the logged in user's handle **bbs_message_found** Takes three numbers, the conference, area and the message number, returns one number, 1 if found, 0 if not. @@ -111,3 +113,5 @@ Where data is the name of the lua script to call without the extension. **bbs_data_path** Returns a path for script data storage. This is shared with all scripts, so make sure your filenames are unique. **bbs_user_security** Returns the current user's security level. + +**bbs_display_blog** Display the System Blog. diff --git a/docs/docs/guide/updating.md b/docs/docs/guide/updating.md index 4ae6531..1a85f5a 100644 --- a/docs/docs/guide/updating.md +++ b/docs/docs/guide/updating.md @@ -18,7 +18,7 @@ Assuming you've installed Magicka BBS from via git rather than use a ZIP file or make cleanwww make www -Where branch is the branch you're updating to, for example v0.9-alpha. +Where branch is the branch you're updating to, for example v0.9-patch. ## Step 3. Update Scripts diff --git a/file_id.diz b/file_id.diz index 95d964a..b2808fb 100644 --- a/file_id.diz +++ b/file_id.diz @@ -1,6 +1,6 @@ . . . .__ .__ __. |\/| _. _ * _.;_/ _. [__)[__)(__ -| |(_](_]|(_.| \(_] [__)[__).__) v0.9a +| |(_](_]|(_.| \(_] [__)[__).__) v0.10a -------._|---------------------------------- Magicka BBS is a Free BBS System for Linux, macOS, FreeBSD, NetBSD, OpenIndiana, diff --git a/setup.sh b/setup.sh index 298a02e..49da63b 100755 --- a/setup.sh +++ b/setup.sh @@ -69,9 +69,11 @@ else SED=sed fi + $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/bbs.ini $SED -i "s/BBS Name = Magicka BBS/BBS Name = ${bbsname}/g" config/bbs.ini $SED -i "s/Sysop Name = sysop/Sysop Name = ${handle}/g" config/bbs.ini +$SED -i "s/USERNAME/${USERNAME}/g" config/bbs.ini $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/localmail.ini $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/filesgen.ini $SED -i "s@/home/andrew/MagickaBBS@${PWD}@g" config/happynet.ini diff --git a/src/Makefile.freebsd b/src/Makefile.freebsd index 412f879..56c8f15 100644 --- a/src/Makefile.freebsd +++ b/src/Makefile.freebsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile freebsd MAKEFLAGS= @@ -29,7 +29,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -51,8 +51,11 @@ magichat: $(JSMN) mgpost: $(JAMLIB) cd ../utils/mgpost && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,6 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.freebsd.WWW b/src/Makefile.freebsd.WWW index c4864e4..fad558e 100644 --- a/src/Makefile.freebsd.WWW +++ b/src/Makefile.freebsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile freebsd MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_blog.o www_files.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.linux b/src/Makefile.linux index 45e93af..ad62edc 100644 --- a/src/Makefile.linux +++ b/src/Makefile.linux @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile linux MAKEFLAGS= @@ -30,7 +30,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.linux.WWW b/src/Makefile.linux.WWW index 4010a2a..11cec93 100644 --- a/src/Makefile.linux.WWW +++ b/src/Makefile.linux.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile linux MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_blog.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.netbsd b/src/Makefile.netbsd index 781b4d7..2392299 100644 --- a/src/Makefile.netbsd +++ b/src/Makefile.netbsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -29,7 +29,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -51,8 +51,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,6 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.netbsd.WWW b/src/Makefile.netbsd.WWW index b681baf..543830c 100644 --- a/src/Makefile.netbsd.WWW +++ b/src/Makefile.netbsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o www_blog.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.openbsd b/src/Makefile.openbsd index bfcccd8..f72b5fc 100644 --- a/src/Makefile.openbsd +++ b/src/Makefile.openbsd @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -29,7 +29,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -51,8 +51,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -74,7 +77,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean - + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.openbsd.WWW b/src/Makefile.openbsd.WWW index 2a1fb21..43d984a 100644 --- a/src/Makefile.openbsd.WWW +++ b/src/Makefile.openbsd.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile bsd MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o www_blog.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,7 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean - + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.osx b/src/Makefile.osx index 0aa7f59..653589e 100644 --- a/src/Makefile.osx +++ b/src/Makefile.osx @@ -8,9 +8,9 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile macosx MAKEFLAGS= @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.osx.WWW b/src/Makefile.osx.WWW index a1a69df..f6cfbf4 100644 --- a/src/Makefile.osx.WWW +++ b/src/Makefile.osx.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile macosx MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o www_files.o www_blog.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -79,6 +82,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean \ No newline at end of file diff --git a/src/Makefile.sunos b/src/Makefile.sunos index c0205a4..7cb0971 100644 --- a/src/Makefile.sunos +++ b/src/Makefile.sunos @@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter dosbox_shim magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= @@ -30,7 +30,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -52,8 +52,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -f Makefile.sunos -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -75,6 +78,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/Makefile.sunos.WWW b/src/Makefile.sunos.WWW index 13fa7b5..902751f 100644 --- a/src/Makefile.sunos.WWW +++ b/src/Makefile.sunos.WWW @@ -10,7 +10,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a JSMN = ../deps/jsmn/libjsmn.a CDK = ../deps/cdk-5-20161210/libcdk.a -all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass +all: magicka magimail magiedit ticproc mgpost magichat filecenter magiftpd reset_pass ${LUA}: cd ../deps/lua && $(MAKE) -f Makefile solaris MAKEFLAGS= @@ -34,7 +34,7 @@ $(CDK): cd ../deps/cdk-5.0-20161210/ && ./configure cd ../deps/cdk-5.0-20161210/ && $(MAKE) -OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o +OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o www_email.o www_msgs.o www_last10.o bluewave.o www_files.o www_blog.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o blog.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) @@ -56,8 +56,11 @@ mgpost: $(JAMLIB) magichat: $(JSMN) cd ../utils/magichat && $(MAKE) -f Makefile.sunos -fileapprove: $(CDK) - cd ../utils/fileapprove && $(MAKE) +filecenter: $(CDK) + cd ../utils/filecenter && $(MAKE) + +dosbox_shim: + cd ../utils/dosbox_shim && $(MAKE) magiftpd: cd ../utils/magiftpd && $(MAKE) @@ -80,6 +83,7 @@ clean: cd ../utils/mgpost && $(MAKE) clean cd ../utils/magichat && $(MAKE) clean cd ../deps/cdk-5.0-20161210 && $(MAKE) clean - cd ../utils/fileapprove && $(MAKE) clean + cd ../utils/filecenter && $(MAKE) clean cd ../utils/magiftpd && $(MAKE) clean - cd ../utils/reset_pass && $(MAKE) clean \ No newline at end of file + cd ../utils/reset_pass && $(MAKE) clean + cd ../utils/dosbox_shim && $(MAKE) clean diff --git a/src/bbs.c b/src/bbs.c index 870764e..83d0ec0 100644 --- a/src/bbs.c +++ b/src/bbs.c @@ -256,12 +256,18 @@ void s_putchar(char c) { size_t inc; size_t ouc; size_t sz; + int ret; if (!should_convert_utf8()) { if (sshBBS) { putchar(c); } else { - write(gSocket, &c, 1); + ret = send(gSocket, &c, 1, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } } else { ic = iconv_open("UTF-8", "CP437"); @@ -277,7 +283,12 @@ void s_putchar(char c) { if (sshBBS) { fprintf(stdout, "%s", ptr1); } else { - write(gSocket, ptr1, outbuf - ptr1); + ret = send(gSocket, ptr1, outbuf - ptr1, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } iconv_close(ic); free(ptr1); @@ -294,11 +305,17 @@ void s_putstring(char *c) { size_t sz; char *ptr1; char *ptr2; + int ret; if (!should_convert_utf8()) { if (sshBBS) { fprintf(stdout, "%s", c); } else { - write(gSocket, c, strlen(c)); + ret = send(gSocket, c, strlen(c), 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } } else { ic = iconv_open("UTF-8", "CP437"); @@ -313,7 +330,12 @@ void s_putstring(char *c) { if (sshBBS) { fprintf(stdout, "%s", ptr1); } else { - write(gSocket, ptr1, outbuf - ptr1); + ret = send(gSocket, ptr1, outbuf - ptr1, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } iconv_close(ic); free(ptr1); @@ -395,22 +417,25 @@ char s_getchar() { char iac_binary_do[] = {IAC, IAC_DO, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_wont[] = {IAC, IAC_WONT, IAC_TRANSMIT_BINARY, '\0'}; char iac_binary_dont[] = {IAC, IAC_DONT, IAC_TRANSMIT_BINARY, '\0'}; - + int ret; do { if (sshBBS) { c = getchar(); } else { - len = read(gSocket, &c, 1); - - if (len == 0) { + do { + len = read(gSocket, &c, 1); + } while (len == -1 && errno == EINTR); + if (len <= 0) { disconnect("Socket Closed"); } } if (!sshBBS) { while (c == IAC) { - len = read(gSocket, &c, 1); + do { + len = read(gSocket, &c, 1); + } while (len == -1 && errno == EINTR); if (len == 0) { disconnect("Socket Closed"); } else if (c == IAC) { @@ -418,8 +443,10 @@ char s_getchar() { return c; } if (c == IAC_WILL || c == IAC_WONT || c == IAC_DO || c == IAC_DONT) { - len = read(gSocket, &d, 1); - if (len == 0) { + do { + len = read(gSocket, &c, 1); + } while (len == -1 && errno == EINTR); + if (len <= 0) { disconnect("Socket Closed"); } @@ -428,7 +455,12 @@ char s_getchar() { if (d == 0) { if (telnet_bin_mode != 1) { telnet_bin_mode = 1; - write(gSocket, iac_binary_do, 3); + ret = send(gSocket, iac_binary_do, 3, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } } break; @@ -436,7 +468,12 @@ char s_getchar() { if (d == 0) { if (telnet_bin_mode != 0) { telnet_bin_mode = 0; - write(gSocket, iac_binary_dont, 3); + ret = send(gSocket, iac_binary_dont, 3, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } } break; @@ -444,7 +481,13 @@ char s_getchar() { if (d == 0) { if (telnet_bin_mode != 1) { telnet_bin_mode = 1; - write(gSocket, iac_binary_will, 3); + ret = send(gSocket, iac_binary_will, 3, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } + } } break; @@ -452,22 +495,31 @@ char s_getchar() { if (d == 0) { if (telnet_bin_mode != 0) { telnet_bin_mode = 0; - write(gSocket, iac_binary_wont, 3); + ret = send(gSocket, iac_binary_wont, 3, 0); + if (ret == -1) { + if (errno == ECONNRESET) { + disconnect("Disconnected"); + } + } } } break; } } else if (c == 250) { do { - len = read(gSocket, &c, 1); - if (len == 0) { + do { + len = read(gSocket, &c, 1); + } while (len == -1 && errno == EINTR); + if (len <= 0) { disconnect("Socket Closed"); } } while(c != 240); } - len = read(gSocket, &c, 1); - if (len == 0) { + do { + len = read(gSocket, &c, 1); + } while (len == -1 && errno == EINTR); + if (len <= 0) { disconnect("Socket Closed"); } } @@ -485,6 +537,49 @@ char s_getc() { return (char)c; } +void s_readstring_inject(char *buffer, int max, char *inject) { + int i; + char c; + + memset(buffer, 0, max); + + if (strlen(inject) > max) { + return; + } + + strcpy(buffer, inject); + + s_printf("%s", inject); + + for (i=strlen(buffer);i 0) { + buffer[i-1] = '\0'; + i -= 2; + s_printf("\e[D \e[D"); + continue; + } else if (c == '\b' || c == 127) { + i -= 1; + continue; + } else if (c == 27) { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + } + i -= 1; + continue; + } + + if (c == '\n' || c == '\r') { + return; + } + s_putchar(c); + buffer[i] = c; + buffer[i+1] = '\0'; + } +} + void s_readstring(char *buffer, int max) { int i; char c; @@ -577,7 +672,7 @@ void record_last10_callers(struct user_record *user) { struct last10_callers callers[10]; int i,j; - FILE *fptr = fopen("last10.dat", "rb"); + FILE *fptr = fopen("last10v2.dat", "rb"); if (fptr != NULL) { for (i=0;i<10;i++) { @@ -595,13 +690,13 @@ void record_last10_callers(struct user_record *user) { strcpy(new_entry.name, user->loginname); strcpy(new_entry.location, user->location); new_entry.time = time(NULL); - + new_entry.calls = user->timeson; if (i == 10) { j = 1; } else { j = 0; } - fptr = fopen("last10.dat", "wb"); + fptr = fopen("last10v2.dat", "wb"); for (;jsec_level >= conf.automsgwritelvl) { + if (gUser->sec_level >= conf.automsgwritelvl) { timen = time(NULL); localtime_r(&timen, &timenow); - sprintf(automsg, get_string(15), user->loginname, asctime(&timenow)); + sprintf(automsg, get_string(15), gUser->loginname, asctime(&timenow)); automsg[strlen(automsg) - 1] = '\r'; automsg[strlen(automsg)] = '\n'; @@ -733,6 +828,24 @@ void automessage_display() { s_getc(); } +void automessage() { + char c; + s_printf(get_string(275)); + c = s_getchar(); + s_printf("\r\n"); + switch(tolower(c)) { + case 'v': + automessage_display(); + break; + case 'u': + automessage_write(); + break; + default: + break; + } + return; +} + void runbbs_real(int socket, char *ip, int ssh) { char buffer[PATH_MAX]; char password[17]; @@ -754,25 +867,27 @@ void runbbs_real(int socket, char *ip, int ssh) { int do_internal_login = 0; int usernotfound; int tries; - + int fno; + atexit(exit_bbs); - ipaddress = ip; + usertimeout = 10; + timeoutpaused = 0; - if (!ssh) { - gUser = NULL; - sshBBS = 0; - if (write(socket, iac_echo, 3) != 3) { - dolog("Failed to send iac_echo"); - exit(0); - } - if (write(socket, iac_sga, 3) != 3) { - dolog("Failed to send iac_sga"); - exit(0); - } - } else { - sshBBS = 1; - } + + memset (&sa, 0, sizeof (sa)); + sa.sa_handler = &timer_handler; + sa.sa_flags = SA_RESTART; + sigaction (SIGALRM, &sa, 0); + + itime.it_interval.tv_sec = 60; + itime.it_interval.tv_usec = 0; + itime.it_value.tv_sec = 60; + itime.it_value.tv_usec = 0; + + setitimer (ITIMER_REAL, &itime, 0); + + ipaddress = ip; st.sa_handler = sigterm_handler2; sigemptyset(&st.sa_mask); @@ -781,26 +896,45 @@ void runbbs_real(int socket, char *ip, int ssh) { dolog("Failed to setup sigterm handler."); exit(1); } - + if (sigaction(SIGPIPE, &st, NULL) == -1) { + dolog("Failed to setup sigpipe handler."); + exit(1); + } gSocket = socket; + + if (!ssh) { + gUser = NULL; + sshBBS = 0; + if (send(socket, iac_echo, 3, 0) != 3) { + dolog("Failed to send iac_echo"); + exit(0); + } + if (send(socket, iac_sga, 3, 0) != 3) { + dolog("Failed to send iac_sga"); + exit(0); + } + } else { + sshBBS = 1; + } + s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR); // find out which node we are for (i=1;i<=conf.nodes;i++) { sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i); + if (stat(buffer, &s) != 0) { mynode = i; - nodefile = fopen(buffer, "w"); - if (!nodefile) { + fno = open(buffer, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + if (fno == -1) { dolog("Error opening nodefile!"); - close(socket); - exit(1); + continue; } - fputs("UNKNOWN", nodefile); - fclose(nodefile); - + write(fno, "UNKNOWN", 7); + + close(fno); break; } } @@ -815,23 +949,9 @@ void runbbs_real(int socket, char *ip, int ssh) { dolog("Incoming %s connection on node %d", (ssh ? "SSH" : "Telnet"), mynode); - usertimeout = 10; - timeoutpaused = 0; - tries = 0; - - memset (&sa, 0, sizeof (sa)); - sa.sa_handler = &timer_handler; - sa.sa_flags = SA_RESTART; - sigaction (SIGALRM, &sa, 0); - - itime.it_interval.tv_sec = 60; - itime.it_interval.tv_usec = 0; - itime.it_value.tv_sec = 60; - itime.it_value.tv_usec = 0; - - setitimer (ITIMER_REAL, &itime, 0); - s_displayansi("issue"); + + tries = 0; if (!ssh) { tryagain: @@ -845,8 +965,8 @@ tryagain: if (strcasecmp(buffer, "new") == 0) { usernotfound = 1; } else if (check_user(buffer)) { - usernotfound = 1; s_printf(get_string(203)); + goto tryagain; } if (usernotfound) { @@ -871,7 +991,7 @@ tryagain: gUser = user; for (i=1;i<=conf.nodes;i++) { - sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i); + snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) == 0) { nodefile = fopen(buffer, "r"); if (!nodefile) { @@ -895,7 +1015,7 @@ tryagain: s_printf(get_string(24), gUser->loginname); s_getc(); for (i=1;i<=conf.nodes;i++) { - sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, i); + snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, i); if (stat(buffer, &s) == 0) { nodefile = fopen(buffer, "r"); if (!nodefile) { @@ -988,8 +1108,8 @@ tryagain: // bulletins display_bulletins(); - // external login cmd - + blog_display(); + // display info display_info(); @@ -1022,7 +1142,7 @@ tryagain: } void do_logout() { - char buffer[256]; + char buffer[PATH_MAX]; struct stat s; lua_State *L; int ret = 0; diff --git a/src/bbs.h b/src/bbs.h index 457462f..8f82707 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -12,7 +12,7 @@ #include "jamlib/jam.h" #define VERSION_MAJOR 0 -#define VERSION_MINOR 9 +#define VERSION_MINOR 10 #define VERSION_STR "alpha" #define NETWORK_FIDO 1 @@ -43,6 +43,7 @@ struct last10_callers { char name[17]; char location[33]; time_t time; + int calls; }__attribute__((packed)); struct text_file { @@ -93,6 +94,7 @@ struct file_directory { char *name; char *path; int sec_level; + int display_on_web; int file_sub_count; struct file_sub **file_subs; }; @@ -124,6 +126,8 @@ struct ip_address_guard { }; struct bbs_config { + uid_t uid; + gid_t gid; int codepage; int ipv6; char *bbs_name; @@ -239,11 +243,19 @@ struct msg_headers { int msg_count; }; +struct blog_entry_t { + char *subject; + char *author; + char *body; + time_t date; +}; + extern char *str_replace(const char *orig, const char *rep, const char *with); extern int copy_file(char *src, char *dest); extern int recursive_delete(const char *dir); -extern void automessage_write(struct user_record *user); +extern void automessage_write(); extern void automessage_display(); +extern void automessage(); extern void dolog(char *fmt, ...); extern void dolog_www(char *ipaddr, char *fmt, ...); extern void runbbs_ssh(char *ipaddress); @@ -258,6 +270,7 @@ extern void s_displayansi(char *file); extern char s_getchar(); extern void s_readpass(char *buffer, int max); extern void s_readstring(char *buffer, int max); +extern void s_readstring_inject(char *buffer, int max, char *inject); extern char s_getc(); extern void disconnect(char *calledby); extern void display_info(); @@ -282,7 +295,7 @@ extern void display_textfiles(); extern time_t utc_to_local(time_t utc); extern s_JamBase *open_jam_base(char *path); extern void free_message_headers(struct msg_headers *msghs); -extern struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user); +extern struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user, int personal); extern void mail_scan(struct user_record *user); extern char *editor(struct user_record *user, char *quote, int qlen, char *from, int email, int sig); extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email, int sig); @@ -302,6 +315,7 @@ extern void msg_conf_sub_bases(); extern void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno); extern void msgbase_reset_all_pointers(int readm); extern void full_mail_scan(struct user_record *user); +extern void full_mail_scan_personal(struct user_record *user); extern int read_new_msgs(struct user_record *user, struct msg_headers *msghs); extern int new_messages(struct user_record *user, int conference, int area); @@ -366,9 +380,19 @@ extern char *www_last10(); extern void www_expire_old_links(); extern char *www_create_link(int dir, int sub, int fid); extern char *www_decode_hash(char *hash); +extern char *www_sanitize(char *inp); +extern char *www_files_display_listing(int dir, int sub); +extern char *www_files_areas(); +extern char *www_files_get_from_area(int dir, int sub, char *file); +extern char *www_blog(); #endif extern int menu_system(char *menufile); extern char *nl_get_bbsname(struct fido_addr *addr, char *domain); extern void nl_browser(); + +extern void blog_display(); +extern void blog_write(); +extern int blog_load(struct blog_entry_t ***entries); + #endif diff --git a/src/bbs_list.c b/src/bbs_list.c index ac5f260..eb0627b 100644 --- a/src/bbs_list.c +++ b/src/bbs_list.c @@ -389,4 +389,4 @@ void bbs_list() { } } } -} \ No newline at end of file +} diff --git a/src/blog.c b/src/blog.c new file mode 100644 index 0000000..61b2c01 --- /dev/null +++ b/src/blog.c @@ -0,0 +1,256 @@ +#include +#include +#include +#include "bbs.h" + +extern struct bbs_config conf; +extern struct user_record *gUser; + +int blog_load(struct blog_entry_t ***entries) { + int blog_entry_count = 0; + struct blog_entry_t **blog_entries; + char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC"; + + char buffer[PATH_MAX]; + int rc; + sqlite3 *db; + sqlite3_stmt *res; + + snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); + + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + *entries = NULL; + return 0; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + + if (rc != SQLITE_OK) { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + *entries = NULL; + return 0; + } + while (sqlite3_step(res) == SQLITE_ROW) { + if (blog_entry_count == 0) { + blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *)); + } else { + blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1)); + } + blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t)); + + blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0)); + blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1)); + blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2)); + blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3); + blog_entry_count++; + } + + sqlite3_finalize(res); + sqlite3_close(db); + + *entries = blog_entries; + return blog_entry_count; +} + +void blog_display() { + + struct blog_entry_t **blog_entries; + int blog_entry_count = 0; + + int i; + struct tm thetime; + char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; + char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; + char c; + int hour; + int j; + int lines = 2; + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(280)); + s_printf(get_string(281)); + + blog_entry_count = blog_load(&blog_entries); + if (blog_entry_count == 0) { + s_printf(get_string(282)); + s_printf(get_string(6)); + s_getchar(); + return; + } + + c = 'y'; + + for (i=0;idate, &thetime); + + s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + if (thetime.tm_hour >= 12) { + hour = thetime.tm_hour - 12; + } else { + hour = thetime.tm_hour; + } + s_printf(get_string(284), (hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900); + + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + + s_printf("\r\n\e[0m"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + for (j=0; jbody); j++) { + if (blog_entries[i]->body[j] == '\r') { + s_printf("\r\n"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + } else { + s_printf("%c", blog_entries[i]->body[j]); + } + } + + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n"); + lines++; + if (lines == 22 && tolower(c) != 'c') { + s_printf("\r\n"); + s_printf(get_string(223)); + c = s_getchar(); + if (tolower(c) == 'n') { + break; + } + s_printf("\r\n\r\n"); + lines = 0; + } + } + for (i=0;isubject); + free(blog_entries[i]->author); + free(blog_entries[i]->body); + free(blog_entries[i]); + } + + free(blog_entries); + + s_printf(get_string(6)); + s_getchar(); + +} + +void blog_write() { + char *csql = "CREATE TABLE IF NOT EXISTS blog (" + "id INTEGER PRIMARY KEY," + "author TEXT COLLATE NOCASE," + "title TEXT," + "body TEXT," + "date INTEGER);"; + + char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)"; + int rc; + sqlite3 *db; + sqlite3_stmt *res; + char *blog_entry; + char buffer[PATH_MAX]; + char *blog_subject; + char *err_msg = 0; + + s_printf(get_string(285)); + s_readstring(buffer, 64); + s_printf("\r\n"); + + if (strlen(buffer) == 0) { + s_printf(get_string(39)); + return; + } + + blog_subject = strdup(buffer); + + blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1); + + if (blog_entry != NULL) { + snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path); + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + free(blog_entry); + free(blog_subject); + return; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_exec(db, csql, 0, 0, &err_msg); + if (rc != SQLITE_OK ) { + dolog("SQL error: %s", err_msg); + sqlite3_free(err_msg); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + + rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); + + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, gUser->loginname, -1, 0); + sqlite3_bind_text(res, 2, blog_subject, -1, 0); + sqlite3_bind_text(res, 3, blog_entry, -1, 0); + sqlite3_bind_int(res, 4, time(NULL)); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + sqlite3_finalize(res); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + free(blog_entry); + free(blog_subject); + return; + } + free(blog_subject); +} \ No newline at end of file diff --git a/src/bluewave.c b/src/bluewave.c index 0e2274a..1f8001e 100644 --- a/src/bluewave.c +++ b/src/bluewave.c @@ -134,7 +134,7 @@ int bwave_scan_email(int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FI } int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file, FILE *mix_file, FILE *dat_file, int *last_ptr) { - struct msg_headers *msghs = read_message_headers(confr, area, gUser); + struct msg_headers *msghs = read_message_headers(confr, area, gUser, 0); int all_unread = 1; s_JamBase *jb; s_JamLastRead jlr; @@ -282,6 +282,7 @@ int bwave_scan_area(int confr, int area, int areano, int totmsgs, FILE *fti_file fwrite(&mix, sizeof(MIX_REC), 1, mix_file); //} JAM_CloseMB(jb); + free(jb); free_message_headers(msghs); return totmsgs; } @@ -313,7 +314,8 @@ void bwave_create_packet() { FILE *inf_file; int tot_areas = 0; int totmsgs = 0; - + int ret; + for (i=0;imail_area_count;j++) { if (msgbase_is_subscribed(i, j)) { @@ -528,7 +530,8 @@ void bwave_create_packet() { dup2(bbs_stderr, STDERR_FILENO); dup2(bbs_stdin, STDIN_FILENO); } - system(buffer); + + ret = system(buffer); if (sshBBS) { @@ -541,8 +544,11 @@ void bwave_create_packet() { close(sterr); } - - do_download(gUser, archive); + if (ret != -1 && ret >> 8 != 127) { + do_download(gUser, archive); + } else { + s_printf(get_string(274)); + } snprintf(buffer, 1024, "%s/node%d/bwave", conf.bbs_path, mynode); recursive_delete(buffer); @@ -706,7 +712,8 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char sleep(1); } else { dolog("Failed to lock msg base!"); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); return 1; } } @@ -716,12 +723,14 @@ int bwave_add_message(int confr, int area, unsigned int dwritten, char *to, char JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return -1; } else { JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } return 0; } diff --git a/src/chat_system.c b/src/chat_system.c index 87e7506..9b27b0d 100644 --- a/src/chat_system.c +++ b/src/chat_system.c @@ -420,7 +420,7 @@ void chat_system(struct user_record *user) { } memset(inputbuffer, 0, 256); inputbuffer_at = 0; - } else if (c != '\n') { + } else if (c != '\n' && c != '\0') { if (c == '\b' || c == 127) { if (inputbuffer_at > 0) { inputbuffer_at--; @@ -446,7 +446,7 @@ void chat_system(struct user_record *user) { strncat(partmessage, readbuffer, len); strcpy(readbuffer, partmessage); - + y = 0; for (z = 0;z < strlen(readbuffer); z++) { if (readbuffer[z] != '\n') { @@ -454,6 +454,7 @@ void chat_system(struct user_record *user) { message[y+1] = '\0'; y++; } else { + y = 0; // json parse jsmn_init(&parser); diff --git a/src/files.c b/src/files.c index 2c313b8..f110028 100644 --- a/src/files.c +++ b/src/files.c @@ -846,11 +846,11 @@ void download_zmodem(struct user_record *user, char *filename) { break ; case ZmErrCantOpen: - dolog("cannot open file \"%s\": %s\n", filename, strerror(errno)) ; + dolog("cannot open file \"%s\": %s", filename, strerror(errno)) ; return; case ZmFileTooLong: - dolog("filename \"%s\" too long, skipping...\n", filename) ; + dolog("filename \"%s\" too long, skipping...", filename) ; return; case ZmDone: diff --git a/src/lua_glue.c b/src/lua_glue.c index 86102c4..8ead90b 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -21,6 +21,12 @@ int l_bbsWString(lua_State *L) { return 0; } +int l_displayBlog(lua_State *L) { + blog_display(); + + return 0; +} + int l_bbsRString(lua_State *L) { char buffer[256]; int len = lua_tonumber(L, -1); @@ -87,7 +93,7 @@ int l_bbsReadLast10(lua_State *L) { struct last10_callers l10; FILE *fptr; - fptr = fopen("last10.dat", "rb"); + fptr = fopen("last10v2.dat", "rb"); if (!fptr) { return 0; } @@ -100,8 +106,8 @@ int l_bbsReadLast10(lua_State *L) { lua_pushstring(L, l10.name); lua_pushstring(L, l10.location); lua_pushnumber(L, l10.time); - - return 3; + lua_pushnumber(L, l10.calls); + return 4; } int l_bbsGetEmailCount(lua_State *L) { @@ -115,6 +121,11 @@ int l_bbsFullMailScan(lua_State *L) { return 0; } +int l_bbsPersonalMailScan(lua_State *L) { + full_mail_scan_personal(gUser); + return 0; +} + int l_bbsMailScan(lua_State *L) { mail_scan(gUser); return 0; @@ -203,21 +214,22 @@ int l_messageFound(lua_State *L) { z = JAM_ReadMsgHeader(jb, id, &jmh, &jsp); if (z != 0) { - dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); lua_pushnumber(L, 0); return 1; } if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); lua_pushnumber(L, 0); return 1; } JAM_DelSubPacket(jsp); JAM_CloseMB(jb); - + free(jb); lua_pushnumber(L, 1); return 1; } @@ -247,9 +259,11 @@ int l_readMessageHdr(lua_State *L) { if (z != 0) { dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); } else if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } else { for (z=0;zNumFields;z++) { if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { @@ -270,7 +284,8 @@ int l_readMessageHdr(lua_State *L) { } JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); } if (subject == NULL) { subject = strdup("(No Subject)"); @@ -318,9 +333,11 @@ int l_readMessage(lua_State *L) { if (z != 0) { dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb)); JAM_CloseMB(jb); + free(jb); body = strdup("No Message"); } else if (jmh.Attribute & JAM_MSG_DELETED) { JAM_CloseMB(jb); + free(jb); body = strdup("No Message"); } else { body = (char *)malloc(jmh.TxtLen + 1); @@ -328,6 +345,7 @@ int l_readMessage(lua_State *L) { body[jmh.TxtLen] = '\0'; JAM_CloseMB(jb); + free(jb); } lua_pushstring(L, body); @@ -468,6 +486,7 @@ int l_postMessage(lua_State *L) { } else if (conf.mail_conferences[confr]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } @@ -479,7 +498,8 @@ int l_postMessage(lua_State *L) { sleep(1); } else { dolog("Failed to lock msg base!"); - JAM_CloseMB(jb); + JAM_CloseMB(jb); + free(jb); return 0; } } @@ -533,6 +553,7 @@ int l_postMessage(lua_State *L) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); } free(msg); @@ -599,6 +620,10 @@ void lua_push_cfunctions(lua_State *L) { lua_setglobal(L, "bbs_data_path"); lua_pushcfunction(L, l_userSecurity); lua_setglobal(L, "bbs_user_security"); + lua_pushcfunction(L, l_bbsPersonalMailScan); + lua_setglobal(L, "bbs_personal_mail_scan"); + lua_pushcfunction(L, l_displayBlog); + lua_setglobal(L, "bbs_display_blog"); } void do_lua_script(char *script) { diff --git a/src/mail_menu.c b/src/mail_menu.c index c2236bd..382ea55 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -128,6 +128,7 @@ void free_message_headers(struct msg_headers *msghs) { if (msghs->msgs[i]->replyid != NULL) { free(msghs->msgs[i]->replyid); } + free(msghs->msgs[i]); } if (msghs->msg_count > 0) { free(msghs->msgs); @@ -145,7 +146,7 @@ int msg_is_to(struct user_record *user, char *addressed_to, char *address, int t } else { myname = strdup(user->loginname); } - if (type == NETWORK_FIDO) { + if (type == NETWORK_FIDO && address != NULL) { if (strcasecmp(myname, addressed_to) == 0) { dest = parse_fido_addr(address); if (conf.mail_conferences[msgconf]->fidoaddr->zone == dest->zone && @@ -205,7 +206,7 @@ int msg_is_from(struct user_record *user, char *addressed_from, char *address, i } } -struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user) { +struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user, int personal) { s_JamBase *jb; s_JamBaseHeader jbh; s_JamMsgHeader jmh; @@ -339,6 +340,36 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r k++; continue; } + } else if (personal) { + if (!msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, conf.mail_conferences[msgconf]->realnames, msgconf) && + !msg_is_to(user, jamm->to, jamm->daddress, conf.mail_conferences[msgconf]->nettype, !conf.mail_conferences[msgconf]->realnames, msgconf)) { + + if (jamm->subject != NULL) { + free(jamm->subject); + } + if (jamm->from != NULL) { + free(jamm->from); + } + if (jamm->to != NULL) { + free(jamm->to); + } + if (jamm->oaddress != NULL) { + free(jamm->oaddress); + } + if (jamm->daddress != NULL) { + free(jamm->daddress); + } + if (jamm->msgid != NULL) { + free(jamm->msgid); + } + if (jamm->replyid != NULL) { + free(jamm->replyid); + } + free(jamm->msg_h); + free(jamm); + k++; + continue; + } } if (msghs->msg_count == 0) { @@ -354,9 +385,11 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r } else { JAM_CloseMB(jb); + free(jb); return NULL; } JAM_CloseMB(jb); + free(jb); return msghs; } @@ -588,9 +621,9 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in s_printf(get_string(87)); while(!doquit) { - s_printf(get_string(88), lines, next_line_buffer); + s_printf(get_string(88), lines, ""); strcpy(linebuffer, next_line_buffer); - s_readstring(&linebuffer[strlen(next_line_buffer)], 70 - strlen(next_line_buffer)); + s_readstring_inject(linebuffer, 70, next_line_buffer); memset(next_line_buffer, 0, 70); if (strlen(linebuffer) == 70 && linebuffer[69] != ' ') { @@ -1652,6 +1685,8 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno if (tolower(c) == 'r') { JAM_CloseMB(jb); + free(jb); + jb = NULL; if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { s_printf(get_string(113)); } else { @@ -1665,23 +1700,14 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno subject = (char *)malloc(strlen(buffer) + 1); strcpy(subject, buffer); - s_printf(get_string(114), subject); + s_printf(get_string(114)); + s_readstring_inject(buffer, 32, msghs->msgs[mailno]->from); + to = strdup(buffer); s_printf(get_string(115)); + s_readstring_inject(buffer, 64, subject); + free(subject); + subject = strdup(buffer); - c = s_getc(); - - if (tolower(c) == 'y') { - s_printf(get_string(116)); - s_readstring(buffer, 25); - - if (strlen(buffer) == 0) { - s_printf(get_string(117)); - } else { - free(subject); - subject = (char *)malloc(strlen(buffer) + 1); - strcpy(subject, buffer); - } - } s_printf("\r\n"); if (msghs->msgs[mailno]->from != NULL) { @@ -1695,11 +1721,9 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno sprintf(from, "%s %s", user->firstname, user->lastname); } if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NEWSGROUP_AREA) { + free(to); to = (char *)malloc(4); strcpy(to, "ALL"); - } else { - to = (char *)malloc(strlen(buffer) + 1); - strcpy(to, buffer); } replybody = external_editor(user, to, from, body, z2, msghs->msgs[mailno]->from, subject, 0, 0); if (replybody != NULL) { @@ -1942,6 +1966,11 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno msg_line_count = 0; } + if (jb != NULL) { + JAM_CloseMB(jb); + free(jb); + } + if (doquit == 2) { return 1; } @@ -1970,18 +1999,25 @@ int read_new_msgs(struct user_record *user, struct msg_headers *msghs) { jlr.LastReadMsg = 0; jlr.HighReadMsg = 0; all_unread = 1; - } else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { + } + if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); if (all_unread == 0) { k = jlr.HighReadMsg; for (i=0;imsg_count;i++) { if (msghs->msgs[i]->msg_h->MsgNum == k) { + i+=2; break; } + if (msghs->msgs[i]->msg_h->MsgNum > k) { + i++; + break; + } } - i += 2; + } else { i = 1; } @@ -2007,7 +2043,7 @@ void read_mail(struct user_record *user) { s_printf("\r\n"); // list mail in message base - msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); + msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); if (msghs != NULL && msghs->msg_count > 0) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { @@ -2023,6 +2059,7 @@ void read_mail(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); s_printf(get_string(120), msghs->msg_count); s_readstring(buffer, 6); @@ -2080,7 +2117,7 @@ void post_message(struct user_record *user) { sprintf(buffer, "ALL"); } else { s_printf(get_string(54)); - s_readstring(buffer, 16); + s_readstring(buffer, 32); } if (strlen(buffer) == 0) { strcpy(buffer, "ALL"); @@ -2287,6 +2324,7 @@ void post_message(struct user_record *user) { } if (z != 0) { JAM_CloseMB(jb); + free(jb); return; } @@ -2311,6 +2349,7 @@ void post_message(struct user_record *user) { JAM_DelSubPacket(jsp); free(msg); JAM_CloseMB(jb); + free(jb); } free(to); free(subject); @@ -2333,7 +2372,7 @@ void list_messages(struct user_record *user) { s_printf("\r\n"); // list mail in message base - msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); + msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); if (msghs != NULL && msghs->msg_count > 0) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { @@ -2349,6 +2388,7 @@ void list_messages(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); s_printf(get_string(125), msghs->msg_count); s_readstring(buffer, 6); @@ -2561,7 +2601,7 @@ void list_messages(struct user_record *user) { redraw = 1; read_message(user, msghs, i - 1, 0); free_message_headers(msghs); - msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); + msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user, 0); jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); if (!jb) { dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); @@ -2577,6 +2617,7 @@ void list_messages(struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); + free(jb); } } } @@ -2949,7 +2990,7 @@ void prev_mail_area(struct user_record *user) { -void do_mail_scan(struct user_record *user, int oldscan) { +void do_mail_scan(struct user_record *user, int oldscan, int personal) { s_JamBase *jb; s_JamBaseHeader jbh; s_JamLastRead jlr; @@ -2961,7 +3002,15 @@ void do_mail_scan(struct user_record *user, int oldscan) { int orig_conf; int orig_area; int res = 0; - s_printf(get_string(139)); + char ch; + int unread_count; + int k; + + if (personal) { + s_printf(get_string(276)); + } else { + s_printf(get_string(139)); + } c = s_getc(); if (tolower(c) == 'y' || tolower(c) == 's') { @@ -2969,12 +3018,15 @@ void do_mail_scan(struct user_record *user, int oldscan) { if (conf.mail_conferences[i]->sec_level > user->sec_level) { continue; } - s_printf(get_string(140), i, conf.mail_conferences[i]->name); - lines+=2; - if (lines == 22) { - s_printf(get_string(6)); - s_getc(); - lines = 0; + if (oldscan) { + s_printf(get_string(140), i, conf.mail_conferences[i]->name); + + lines+=2; + if (lines == 22) { + s_printf(get_string(6)); + s_getc(); + lines = 0; + } } for (j=0;jmail_area_count;j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { @@ -2993,16 +3045,18 @@ void do_mail_scan(struct user_record *user, int oldscan) { if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); continue; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (jbh.ActiveMsgs == 0) { JAM_CloseMB(jb); + free(jb); continue; } if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { - msghs = read_message_headers(i, j, user); + msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { if (msghs->msg_count > 0) { if (oldscan) { @@ -3014,16 +3068,25 @@ void do_mail_scan(struct user_record *user, int oldscan) { lines = 0; } } else { - orig_conf = user->cur_mail_conf; - orig_area = user->cur_mail_area; - - user->cur_mail_conf = i; - user->cur_mail_area = j; - - res = read_new_msgs(user, msghs); - - user->cur_mail_conf = orig_conf; - user->cur_mail_area = orig_area; + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(277), i, conf.mail_conferences[i]->name); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(279)); + + ch = s_getchar(); + s_printf("\r\n"); + if (tolower(ch) == 'y') { + orig_conf = user->cur_mail_conf; + orig_area = user->cur_mail_area; + + user->cur_mail_conf = i; + user->cur_mail_area = j; + + res = read_new_msgs(user, msghs); + + user->cur_mail_conf = orig_conf; + user->cur_mail_area = orig_area; + } } } free_message_headers(msghs); @@ -3038,19 +3101,29 @@ void do_mail_scan(struct user_record *user, int oldscan) { lines = 0; } } else { - msghs = read_message_headers(i, j, user); + msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { - if (msghs->msg_count > 0) { - orig_conf = user->cur_mail_conf; - orig_area = user->cur_mail_area; - - user->cur_mail_conf = i; - user->cur_mail_area = j; - - res = read_new_msgs(user, msghs); - - user->cur_mail_conf = orig_conf; - user->cur_mail_area = orig_area; + + if (msghs->msg_count > 0) { + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(277), i, conf.mail_conferences[i]->name); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + s_printf(get_string(279)); + + ch = s_getchar(); + s_printf("\r\n"); + if (tolower(ch) == 'y') { + orig_conf = user->cur_mail_conf; + orig_area = user->cur_mail_area; + + user->cur_mail_conf = i; + user->cur_mail_area = j; + + res = read_new_msgs(user, msghs); + + user->cur_mail_conf = orig_conf; + user->cur_mail_area = orig_area; + } } free_message_headers(msghs); } @@ -3058,13 +3131,24 @@ void do_mail_scan(struct user_record *user, int oldscan) { } } else { if (jlr.HighReadMsg < jbh.ActiveMsgs) { + + + if (conf.mail_conferences[i]->mail_areas[j]->type == TYPE_NETMAIL_AREA) { - msghs = read_message_headers(i, j, user); + msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { if (msghs->msg_count > 0) { - if (msghs->msgs[msghs->msg_count-1]->msg_no > jlr.HighReadMsg) { + unread_count = 0; + + for (k=msghs->msg_count-1;k>=0;k--) { + if (msghs->msgs[k]->msg_no < jlr.HighReadMsg) { + break; + } + unread_count++; + } + if (unread_count > 0) { if (oldscan) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msgs[msghs->msg_count-1]->msg_h->MsgNum - jlr.HighReadMsg); + s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); lines++; if (lines == 22) { s_printf(get_string(6)); @@ -3072,16 +3156,25 @@ void do_mail_scan(struct user_record *user, int oldscan) { lines = 0; } } else { - orig_conf = user->cur_mail_conf; - orig_area = user->cur_mail_area; - - user->cur_mail_conf = i; - user->cur_mail_area = j; - - res = read_new_msgs(user, msghs); - - user->cur_mail_conf = orig_conf; - user->cur_mail_area = orig_area; + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(277), i, conf.mail_conferences[i]->name); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(279)); + + ch = s_getchar(); + s_printf("\r\n"); + if (tolower(ch) == 'y') { + orig_conf = user->cur_mail_conf; + orig_area = user->cur_mail_area; + + user->cur_mail_conf = i; + user->cur_mail_area = j; + + res = read_new_msgs(user, msghs); + + user->cur_mail_conf = orig_conf; + user->cur_mail_area = orig_area; + } } } } @@ -3097,19 +3190,38 @@ void do_mail_scan(struct user_record *user, int oldscan) { lines = 0; } } else { - msghs = read_message_headers(i, j, user); + msghs = read_message_headers(i, j, user, personal); if (msghs != NULL) { - if (msghs->msg_count > 0) { - orig_conf = user->cur_mail_conf; - orig_area = user->cur_mail_area; + if (msghs->msg_count > 0) { + unread_count = 0; + + for (k=msghs->msg_count-1;k>=0;k--) { + if (msghs->msgs[k]->msg_no < jlr.HighReadMsg) { + break; + } + unread_count++; + } + if (unread_count > 0) { + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(277), i, conf.mail_conferences[i]->name); + s_printf(get_string(278), j, conf.mail_conferences[i]->mail_areas[j]->name, unread_count); + s_printf(get_string(279)); - user->cur_mail_conf = i; - user->cur_mail_area = j; - - res = read_new_msgs(user, msghs); - - user->cur_mail_conf = orig_conf; - user->cur_mail_area = orig_area; + ch = s_getchar(); + s_printf("\r\n"); + if (tolower(ch) == 'y') { + orig_conf = user->cur_mail_conf; + orig_area = user->cur_mail_area; + + user->cur_mail_conf = i; + user->cur_mail_area = j; + + res = read_new_msgs(user, msghs); + + user->cur_mail_conf = orig_conf; + user->cur_mail_area = orig_area; + } + } } free_message_headers(msghs); } @@ -3117,10 +3229,12 @@ void do_mail_scan(struct user_record *user, int oldscan) { } } else { JAM_CloseMB(jb); + free(jb); continue; } } JAM_CloseMB(jb); + free(jb); if (res) { break; } @@ -3135,12 +3249,16 @@ void do_mail_scan(struct user_record *user, int oldscan) { } } +void full_mail_scan_personal(struct user_record *user) { + do_mail_scan(user, 0, 1); +} + void full_mail_scan(struct user_record *user) { - do_mail_scan(user, 0); + do_mail_scan(user, 0, 0); } void mail_scan(struct user_record *user) { - do_mail_scan(user, 1); + do_mail_scan(user, 1, 0); } @@ -3257,6 +3375,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); return; } @@ -3301,6 +3420,7 @@ void msgbase_reset_pointers(int conference, int msgarea, int readm, int msgno) { JAM_WriteLastRead(jb, gUser->id, &jlr); } JAM_CloseMB(jb); + free(jb); } void msgbase_reset_all_pointers(int readm) { @@ -3326,15 +3446,17 @@ int new_messages(struct user_record *user, int conference, int area) { } if (JAM_ReadMBHeader(jb, &jbh) != 0) { JAM_CloseMB(jb); + free(jb); return 0; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { if (jbh.ActiveMsgs == 0) { JAM_CloseMB(jb); + free(jb); return 0; } if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { - msghs = read_message_headers(conference, area, user); + msghs = read_message_headers(conference, area, user, 0); if (msghs != NULL) { if (msghs->msg_count > 0) { count = msghs->msg_count; @@ -3347,7 +3469,7 @@ int new_messages(struct user_record *user, int conference, int area) { } else { if (jlr.HighReadMsg < jbh.ActiveMsgs) { if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_NETMAIL_AREA) { - msghs = read_message_headers(conference, area, user); + msghs = read_message_headers(conference, area, user, 0); if (msghs != NULL) { if (msghs->msg_count > 0) { if (msghs->msgs[msghs->msg_count-1]->msg_h->MsgNum > jlr.HighReadMsg) { @@ -3362,5 +3484,6 @@ int new_messages(struct user_record *user, int conference, int area) { } } JAM_CloseMB(jb); + free(jb); return count; } diff --git a/src/main.c b/src/main.c index 4f28d71..3b0be5b 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ extern struct user_record *gUser; int ssh_pid = -1; int bbs_pid = 0; int server_socket = -1; +int ipv6_pid = -1; int bbs_stdin; int bbs_stdout; @@ -62,6 +64,9 @@ void sigterm_handler(int s) MHD_stop_daemon(www_daemon); } #endif + if (ipv6_pid != -1) { + kill(ipv6_pid, SIGTERM); + } remove(conf.pid_file); exit(0); } @@ -255,6 +260,12 @@ static int file_sub_handler(void* user, const char* section, const char* name, if (strcasecmp(section, "main") == 0) { if (strcasecmp(name, "visible sec level") == 0) { fd->sec_level = atoi(value); + } else if (strcasecmp(name, "visible on web") == 0) { + if (strcasecmp(value, "true") == 0) { + fd->display_on_web = 1; + } else { + fd->display_on_web = 0; + } } } else { // check if it's partially filled in @@ -401,6 +412,7 @@ static int handler(void* user, const char* section, const char* name, const char* value) { struct bbs_config *conf = (struct bbs_config *)user; + struct passwd *pwd; if (strcasecmp(section, "main") == 0) { if (strcasecmp(name, "bbs name") == 0) { @@ -515,6 +527,12 @@ static int handler(void* user, const char* section, const char* name, } else { conf->date_style = 0; } + } else if (strcasecmp(name, "run as user") == 0) { + pwd = getpwnam(value); + if (pwd != NULL) { + conf->uid = pwd->pw_uid; + conf->gid = pwd->pw_gid; + } } } else if (strcasecmp(section, "paths") == 0){ if (strcasecmp(name, "ansi path") == 0) { @@ -566,6 +584,7 @@ static int handler(void* user, const char* section, const char* name, conf->file_directories[conf->file_directory_count]->name = strdup(name); conf->file_directories[conf->file_directory_count]->path = strdup(value); conf->file_directories[conf->file_directory_count]->file_sub_count = 0; + conf->file_directories[conf->file_directory_count]->display_on_web = 0; conf->file_directory_count++; } else if (strcasecmp(section, "text files") == 0) { if (conf->text_file_count == 0) { @@ -787,6 +806,14 @@ void serverssh(int port, int ipv6) { } c = sizeof(struct sockaddr_in); } + + if (conf.uid != getuid()) { + if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { + perror("SetUID Failed: "); + remove(conf.pid_file); + exit(1); + } + } listen(ssh_sock, 3); @@ -1063,6 +1090,7 @@ void server(int port, int ipv6) { ssh_pid = fork(); if (ssh_pid == 0) { + ipv6_pid = -1; ssh_pid = -1; serverssh(conf.ssh_port, ipv6); exit(0); @@ -1072,20 +1100,6 @@ void server(int port, int ipv6) { } } -#if defined(ENABLE_WWW) - if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) { - if (!conf.fork) { - printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4)); - } - www_init(); - if (ipv6) { - www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); - } else { - www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); - } - } -#endif - if (ipv6) { server_socket = socket(AF_INET6, SOCK_STREAM, 0); } else { @@ -1145,6 +1159,28 @@ void server(int port, int ipv6) { client_p = &client4; } + if (conf.uid != getuid()) { + if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { + perror("SetUID Failed: "); + remove(conf.pid_file); + exit(1); + } + } + +#if defined(ENABLE_WWW) + if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) { + if (!conf.fork) { + printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4)); + } + www_init(); + if (ipv6) { + www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION|MHD_USE_IPv6, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); + } else { + www_daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_NOTIFY_COMPLETED, &www_request_completed, NULL, MHD_OPTION_URI_LOG_CALLBACK, &www_logger, NULL, MHD_OPTION_END); + } + } +#endif + listen(server_socket, 3); @@ -1222,7 +1258,7 @@ void server(int port, int ipv6) { int main(int argc, char **argv) { int i; - int main_pid, ipv6_pid; + int main_pid; FILE *fptr; struct stat s; char buffer[1024]; @@ -1262,7 +1298,8 @@ int main(int argc, char **argv) { conf.codepage = 0; conf.date_style = 0; conf.ipv6 = 0; - + conf.uid = getuid(); + conf.gid = getgid(); // Load BBS data if (ini_parse(argv[1], handler, &conf) <0) { fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); @@ -1329,6 +1366,12 @@ int main(int argc, char **argv) { exit(-1); } else if (main_pid > 0) { + if (conf.uid != getuid()) { + if (setgid(conf.gid) != 0 || setuid(conf.uid) != 0) { + perror("Setuid Error: "); + exit(1); + } + } fptr = fopen(conf.pid_file, "w"); if (!fptr) { fprintf(stderr, "Unable to open pid file for writing.\n"); @@ -1351,6 +1394,7 @@ int main(int argc, char **argv) { } else if (ipv6_pid > 0) { server(conf.telnet_port, 0); } else { + ipv6_pid = -1; server(conf.telnet_port, 1); } } else { @@ -1375,6 +1419,7 @@ int main(int argc, char **argv) { } else if (ipv6_pid > 0) { server(conf.telnet_port, 0); } else { + ipv6_pid = -1; server(conf.telnet_port, 1); } } else { diff --git a/src/menus.c b/src/menus.c index 68dc8c6..98bf801 100644 --- a/src/menus.c +++ b/src/menus.c @@ -11,7 +11,7 @@ #define MENU_SUBMENU 1 #define MENU_LOGOFF 2 #define MENU_PREVMENU 3 -#define MENU_AUTOMESSAGEWRITE 4 +#define MENU_AUTOMESSAGE 4 #define MENU_TEXTFILES 5 #define MENU_CHATSYSTEM 6 #define MENU_BBSLIST 7 @@ -57,6 +57,8 @@ #define MENU_GENWWWURLS 47 #define MENU_NLBROWSER 48 #define MENU_SENDFEEDBACK 49 +#define MENU_BLOGDISPLAY 50 +#define MENU_BLOGWRITE 51 extern struct bbs_config conf; extern struct user_record *gUser; @@ -64,8 +66,9 @@ extern int mynode; struct menu_item { char hotkey; - int command; - char *data; + int *command; + char **data; + int command_count; int seclevel; }; @@ -80,6 +83,7 @@ int menu_system(char *menufile) { int i; int j; int k; + int m; struct stat s; char *lRet; lua_State *L; @@ -123,113 +127,131 @@ int menu_system(char *menufile) { } menu[menu_items-1] = (struct menu_item *)malloc(sizeof(struct menu_item)); menu[menu_items-1]->hotkey = buffer[7]; - menu[menu_items-1]->command = 0; + menu[menu_items-1]->command = NULL; menu[menu_items-1]->data = NULL; + menu[menu_items-1]->command_count = 0; menu[menu_items-1]->seclevel = 0; } else if (strncasecmp(buffer, "COMMAND", 7) == 0 && menu_items > 0) { + if (menu[menu_items-1]->command_count == 0) { + menu[menu_items-1]->command = (int *)malloc(sizeof(int)); + menu[menu_items-1]->data = (char **)malloc(sizeof(char *)); + } else { + menu[menu_items-1]->command = (int *)realloc(menu[menu_items-1]->command, sizeof(int) * (menu[menu_items-1]->command_count + 1)); + menu[menu_items-1]->data = (char **)realloc(menu[menu_items-1]->data, sizeof(char *) * (menu[menu_items-1]->command_count + 1)); + } + menu[menu_items-1]->command_count++; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = 0; + menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = NULL; if (strncasecmp(&buffer[8], "SUBMENU", 7) == 0) { - menu[menu_items-1]->command = MENU_SUBMENU; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBMENU; } else if (strncasecmp(&buffer[8], "LOGOFF", 6) == 0) { - menu[menu_items-1]->command = MENU_LOGOFF; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LOGOFF; } else if (strncasecmp(&buffer[8], "PREVMENU", 8) == 0) { - menu[menu_items-1]->command = MENU_PREVMENU; - } else if (strncasecmp(&buffer[8], "AUTOMESSAGE_WRITE", 17) == 0) { - menu[menu_items-1]->command = MENU_AUTOMESSAGEWRITE; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMENU; + } else if (strncasecmp(&buffer[8], "AUTOMESSAGE", 11) == 0) { + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_AUTOMESSAGE; } else if (strncasecmp(&buffer[8], "TEXTFILES", 9) == 0) { - menu[menu_items-1]->command = MENU_TEXTFILES; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_TEXTFILES; } else if (strncasecmp(&buffer[8], "CHATSYSTEM", 10) == 0) { - menu[menu_items-1]->command = MENU_CHATSYSTEM; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHATSYSTEM; } else if (strncasecmp(&buffer[8], "BBSLIST", 7) == 0) { - menu[menu_items-1]->command = MENU_BBSLIST; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BBSLIST; } else if (strncasecmp(&buffer[8], "LISTUSERS", 9) == 0) { - menu[menu_items-1]->command = MENU_LISTUSERS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTUSERS; } else if (strncasecmp(&buffer[8], "BULLETINS", 9) == 0) { - menu[menu_items-1]->command = MENU_BULLETINS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BULLETINS; } else if (strncasecmp(&buffer[8], "LAST10CALLERS", 13) == 0) { - menu[menu_items-1]->command = MENU_LAST10; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LAST10; } else if (strncasecmp(&buffer[8], "SETTINGS", 8) == 0) { - menu[menu_items-1]->command = MENU_SETTINGS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SETTINGS; } else if (strncasecmp(&buffer[8], "RUNDOOR", 7) == 0) { - menu[menu_items-1]->command = MENU_DOOR; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOOR; } else if (strncasecmp(&buffer[8], "MAILSCAN", 8) == 0) { - menu[menu_items-1]->command = MENU_MAILSCAN; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_MAILSCAN; } else if (strncasecmp(&buffer[8], "READMAIL", 8) == 0) { - menu[menu_items-1]->command = MENU_READMAIL; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_READMAIL; } else if (strncasecmp(&buffer[8], "POSTMESSAGE", 11) == 0) { - menu[menu_items-1]->command = MENU_POSTMESSAGE; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_POSTMESSAGE; } else if (strncasecmp(&buffer[8], "CHOOSEMAILCONF", 14) == 0) { - menu[menu_items-1]->command = MENU_CHOOSEMAILCONF; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILCONF; } else if (strncasecmp(&buffer[8], "CHOOSEMAILAREA", 14) == 0) { - menu[menu_items-1]->command = MENU_CHOOSEMAILAREA; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEMAILAREA; } else if (strncasecmp(&buffer[8], "SENDEMAIL", 9) == 0) { - menu[menu_items-1]->command = MENU_SENDEMAIL; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDEMAIL; } else if (strncasecmp(&buffer[8], "LISTEMAIL", 9) == 0) { - menu[menu_items-1]->command = MENU_LISTEMAIL; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTEMAIL; } else if (strncasecmp(&buffer[8], "NEXTMAILCONF", 12) == 0) { - menu[menu_items-1]->command = MENU_NEXTMAILCONF; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILCONF; } else if (strncasecmp(&buffer[8], "PREVMAILCONF", 12) == 0) { - menu[menu_items-1]->command = MENU_PREVMAILCONF; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILCONF; } else if (strncasecmp(&buffer[8], "NEXTMAILAREA", 12) == 0) { - menu[menu_items-1]->command = MENU_NEXTMAILAREA; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTMAILAREA; } else if (strncasecmp(&buffer[8], "PREVMAILAREA", 12) == 0) { - menu[menu_items-1]->command = MENU_PREVMAILAREA; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVMAILAREA; } else if (strncasecmp(&buffer[8], "BLUEWAVEDOWNLOAD", 16) == 0) { - menu[menu_items-1]->command = MENU_BLUEWAVEDOWN; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEDOWN; } else if (strncasecmp(&buffer[8], "BLUEWAVEUPLOAD", 14) == 0) { - menu[menu_items-1]->command = MENU_BLUEWAVEUP; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLUEWAVEUP; } else if (strncasecmp(&buffer[8], "CHOOSEFILEDIR", 13) == 0) { - menu[menu_items-1]->command = MENU_CHOOSEFILEDIR; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILEDIR; } else if (strncasecmp(&buffer[8], "CHOOSEFILESUB", 13) == 0) { - menu[menu_items-1]->command = MENU_CHOOSEFILESUB; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CHOOSEFILESUB; } else if (strncasecmp(&buffer[8], "LISTFILES", 9) == 0) { - menu[menu_items-1]->command = MENU_LISTFILES; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTFILES; } else if (strncasecmp(&buffer[8], "UPLOAD", 6) == 0) { - menu[menu_items-1]->command = MENU_UPLOAD; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_UPLOAD; } else if (strncasecmp(&buffer[8], "DOWNLOAD", 8) == 0) { - menu[menu_items-1]->command = MENU_DOWNLOAD; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOWNLOAD; } else if (strncasecmp(&buffer[8], "CLEARTAGGED", 11) == 0) { - menu[menu_items-1]->command = MENU_CLEARTAGGEDFILES; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_CLEARTAGGEDFILES; } else if (strncasecmp(&buffer[8], "NEXTFILEDIR", 11) == 0) { - menu[menu_items-1]->command = MENU_NEXTFILEDIR; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILEDIR; } else if (strncasecmp(&buffer[8], "PREVFILEDIR", 11) == 0) { - menu[menu_items-1]->command = MENU_PREVFILEDIR; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILEDIR; } else if (strncasecmp(&buffer[8], "NEXTFILESUB", 11) == 0) { - menu[menu_items-1]->command = MENU_NEXTFILESUB; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NEXTFILESUB; } else if (strncasecmp(&buffer[8], "PREVFILESUB", 11) == 0) { - menu[menu_items-1]->command = MENU_PREVFILESUB; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_PREVFILESUB; } else if (strncasecmp(&buffer[8], "LISTMESSAGES", 12) == 0) { - menu[menu_items-1]->command = MENU_LISTMESSAGES; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_LISTMESSAGES; } else if (strncasecmp(&buffer[8], "DOSCRIPT", 8) == 0) { - menu[menu_items-1]->command = MENU_DOSCRIPT; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DOSCRIPT; } else if (strncasecmp(&buffer[8], "SENDNODEMSG", 11) == 0) { - menu[menu_items-1]->command = MENU_SENDNODEMSG; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDNODEMSG; } else if (strncasecmp(&buffer[8], "SUBUNSUBCONF", 12) == 0) { - menu[menu_items-1]->command = MENU_SUBUNSUBCONF; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SUBUNSUBCONF; } else if (strncasecmp(&buffer[8], "RESETMSGPTRS", 12) == 0) { - menu[menu_items-1]->command = MENU_RESETPOINTERS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETPOINTERS; } else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) { - menu[menu_items-1]->command = MENU_RESETALLPOINTERS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_RESETALLPOINTERS; } else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) { - menu[menu_items-1]->command = MENU_FILESCAN; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESCAN; } else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) { - menu[menu_items-1]->command = MENU_FULLMAILSCAN; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FULLMAILSCAN; } else if (strncasecmp(&buffer[8], "FILESEARCH", 10) == 0) { - menu[menu_items-1]->command = MENU_FILESEARCH; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_FILESEARCH; } else if (strncasecmp(&buffer[8], "DISPLAYTXTFILE", 14) == 0) { - menu[menu_items-1]->command = MENU_DISPTXTFILE; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILE; } else if (strncasecmp(&buffer[8], "DISPLAYTXTPAUSE", 15) == 0) { - menu[menu_items-1]->command = MENU_DISPTXTFILEPAUSE; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_DISPTXTFILEPAUSE; } else if (strncasecmp(&buffer[8], "GENWWWURLS", 10) == 0) { - menu[menu_items-1]->command = MENU_GENWWWURLS; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_GENWWWURLS; } else if (strncasecmp(&buffer[8], "NLBROWSER", 9) == 0) { - menu[menu_items-1]->command = MENU_NLBROWSER; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_NLBROWSER; } else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) { - menu[menu_items-1]->command = MENU_SENDFEEDBACK; + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_SENDFEEDBACK; + } else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) { + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGDISPLAY; + } else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) { + menu[menu_items-1]->command[menu[menu_items -1]->command_count - 1] = MENU_BLOGWRITE; } } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { menu[menu_items-1]->seclevel = atoi(&buffer[9]); } else if (strncasecmp(buffer, "DATA", 4) == 0) { - menu[menu_items-1]->data = strdup(&buffer[5]); + if (menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] != NULL) { + free(menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1]); + } + menu[menu_items-1]->data[menu[menu_items -1]->command_count - 1] = strdup(&buffer[5]); } else if (strncasecmp(buffer, "LUASCRIPT", 9) == 0) { if (lua_script != NULL) { free(lua_script); @@ -328,14 +350,39 @@ int menu_system(char *menufile) { for (i=0;ihotkey) == tolower(c)) { if (menu[i]->seclevel <= gUser->sec_level) { - switch(menu[i]->command) { - case MENU_SUBMENU: - doquit = menu_system(menu[i]->data); - if (doquit == 1) { - // free menus + for (j=0; jcommand_count;j++) { + switch(menu[i]->command[j]) { + case MENU_SUBMENU: + doquit = menu_system(menu[i]->data[j]); + if (doquit == 1) { + // free menus + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); + } + if (ansi_file != NULL) { + free(ansi_file); + } + for (i=0;icommand_count;j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } + } + free(menu[i]->data); + free(menu[i]->command); + free(menu[i]); + } + free(menu); + return doquit; + } + break; + case MENU_LOGOFF: if (do_lua_menu) { lua_close(L); - } + } if (lua_script != NULL) { free(lua_script); } @@ -343,243 +390,246 @@ int menu_system(char *menufile) { free(ansi_file); } for (i=0;idata != NULL) { - free(menu[i]->data); + for (j=0;jcommand_count;j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } } + free(menu[i]->data); + free(menu[i]->command); free(menu[i]); } - free(menu); - return doquit; - } - break; - case MENU_LOGOFF: - if (do_lua_menu) { - lua_close(L); - } - if (lua_script != NULL) { - free(lua_script); - } - if (ansi_file != NULL) { - free(ansi_file); - } - for (i=0;idata != NULL) { - free(menu[i]->data); + free(menu); + return 1; + case MENU_PREVMENU: + if (do_lua_menu) { + lua_close(L); + } + if (lua_script != NULL) { + free(lua_script); } - free(menu[i]); - } - free(menu); - return 1; - case MENU_PREVMENU: - if (do_lua_menu) { - lua_close(L); - } - if (lua_script != NULL) { - free(lua_script); - } - if (ansi_file != NULL) { - free(ansi_file); - } - for (i=0;idata != NULL) { - free(menu[i]->data); + if (ansi_file != NULL) { + free(ansi_file); } - free(menu[i]); - } - free(menu); - return 0; - case MENU_AUTOMESSAGEWRITE: - automessage_write(gUser); - break; - case MENU_TEXTFILES: - display_textfiles(); - break; - case MENU_CHATSYSTEM: - chat_system(gUser); - break; - case MENU_BBSLIST: - bbs_list(gUser); - break; - case MENU_LISTUSERS: - list_users(gUser); - break; - case MENU_BULLETINS: - display_bulletins(); - break; - case MENU_LAST10: - display_last10_callers(gUser); - break; - case MENU_SETTINGS: - settings_menu(gUser); - break; - case MENU_DOOR: - { - for (j=0;jdata, conf.doors[j]->name) == 0) { - dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[j]->name, mynode); - rundoor(gUser, conf.doors[j]->command, conf.doors[j]->stdio, conf.doors[j]->codepage); - dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[j]->name, mynode); - break; + for (i=0;icommand_count;j++) { + if (menu[i]->data[j] != NULL) { + free(menu[i]->data[j]); + } + } + free(menu[i]->data); + free(menu[i]->command); + free(menu[i]); + } + free(menu); + return 0; + case MENU_AUTOMESSAGE: + automessage(); + break; + case MENU_TEXTFILES: + display_textfiles(); + break; + case MENU_CHATSYSTEM: + chat_system(gUser); + break; + case MENU_BBSLIST: + bbs_list(gUser); + break; + case MENU_LISTUSERS: + list_users(gUser); + break; + case MENU_BULLETINS: + display_bulletins(); + break; + case MENU_LAST10: + display_last10_callers(gUser); + break; + case MENU_SETTINGS: + settings_menu(gUser); + break; + case MENU_DOOR: + { + for (m=0;mdata[j], conf.doors[m]->name) == 0) { + dolog("%s launched door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); + rundoor(gUser, conf.doors[m]->command, conf.doors[m]->stdio, conf.doors[m]->codepage); + dolog("%s returned from door %s, on node %d", gUser->loginname, conf.doors[m]->name, mynode); + break; + } } } - } - break; - case MENU_MAILSCAN: - mail_scan(gUser); - break; - case MENU_READMAIL: - read_mail(gUser); - break; - case MENU_POSTMESSAGE: - post_message(gUser); - break; - case MENU_CHOOSEMAILCONF: - choose_conference(); - break; - case MENU_CHOOSEMAILAREA: - choose_area(); - break; - case MENU_SENDEMAIL: - send_email(gUser); - break; - case MENU_LISTEMAIL: - list_emails(gUser); - break; - case MENU_NEXTMAILCONF: - next_mail_conf(gUser); - break; - case MENU_PREVMAILCONF: - prev_mail_conf(gUser); - break; - case MENU_NEXTMAILAREA: - next_mail_area(gUser); - break; - case MENU_PREVMAILAREA: - prev_mail_area(gUser); - break; - case MENU_BLUEWAVEDOWN: - bwave_create_packet(); - break; - case MENU_BLUEWAVEUP: - bwave_upload_reply(); - break; - case MENU_CHOOSEFILEDIR: - choose_directory(); - break; - case MENU_CHOOSEFILESUB: - choose_subdir(); - break; - case MENU_LISTFILES: - list_files(gUser); - break; - case MENU_UPLOAD: - if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { - upload(gUser); - } else { - s_printf(get_string(84)); - } - break; - case MENU_DOWNLOAD: - download(gUser); - break; - case MENU_CLEARTAGGEDFILES: - clear_tagged_files(); - break; - case MENU_NEXTFILEDIR: - next_file_dir(gUser); - break; - case MENU_PREVFILEDIR: - prev_file_dir(gUser); - break; - case MENU_NEXTFILESUB: - next_file_sub(gUser); - break; - case MENU_PREVFILESUB: - prev_file_sub(gUser); - break; - case MENU_LISTMESSAGES: - list_messages(gUser); - break; - case MENU_DOSCRIPT: - do_lua_script(menu[i]->data); - break; - case MENU_SENDNODEMSG: - send_node_msg(); - break; - case MENU_SUBUNSUBCONF: - msg_conf_sub_bases(); - break; - case MENU_RESETPOINTERS: - s_printf(get_string(229)); - s_readstring(buffer, 10); - if (tolower(buffer[0]) == 'r') { - k = -1; - j = 1; - } else if (tolower(buffer[0]) == 'u') { - k = -1; - j = 0; - } else if (buffer[0] < '0' || buffer[0] > '9') { - s_printf(get_string(39)); break; - } else { - k = atoi(buffer) - 1; - } + case MENU_MAILSCAN: + mail_scan(gUser); + break; + case MENU_READMAIL: + read_mail(gUser); + break; + case MENU_POSTMESSAGE: + post_message(gUser); + break; + case MENU_CHOOSEMAILCONF: + choose_conference(); + break; + case MENU_CHOOSEMAILAREA: + choose_area(); + break; + case MENU_SENDEMAIL: + send_email(gUser); + break; + case MENU_LISTEMAIL: + list_emails(gUser); + break; + case MENU_NEXTMAILCONF: + next_mail_conf(gUser); + break; + case MENU_PREVMAILCONF: + prev_mail_conf(gUser); + break; + case MENU_NEXTMAILAREA: + next_mail_area(gUser); + break; + case MENU_PREVMAILAREA: + prev_mail_area(gUser); + break; + case MENU_BLUEWAVEDOWN: + bwave_create_packet(); + break; + case MENU_BLUEWAVEUP: + bwave_upload_reply(); + break; + case MENU_CHOOSEFILEDIR: + choose_directory(); + break; + case MENU_CHOOSEFILESUB: + choose_subdir(); + break; + case MENU_LISTFILES: + list_files(gUser); + break; + case MENU_UPLOAD: + if (gUser->sec_level >= conf.file_directories[gUser->cur_file_dir]->file_subs[gUser->cur_file_sub]->upload_sec_level) { + upload(gUser); + } else { + s_printf(get_string(84)); + } + break; + case MENU_DOWNLOAD: + download(gUser); + break; + case MENU_CLEARTAGGEDFILES: + clear_tagged_files(); + break; + case MENU_NEXTFILEDIR: + next_file_dir(gUser); + break; + case MENU_PREVFILEDIR: + prev_file_dir(gUser); + break; + case MENU_NEXTFILESUB: + next_file_sub(gUser); + break; + case MENU_PREVFILESUB: + prev_file_sub(gUser); + break; + case MENU_LISTMESSAGES: + list_messages(gUser); + break; + case MENU_DOSCRIPT: + do_lua_script(menu[i]->data[j]); + break; + case MENU_SENDNODEMSG: + send_node_msg(); + break; + case MENU_SUBUNSUBCONF: + msg_conf_sub_bases(); + break; + case MENU_RESETPOINTERS: + s_printf(get_string(229)); + s_readstring(buffer, 10); + if (tolower(buffer[0]) == 'r') { + k = -1; + m = 1; + } else if (tolower(buffer[0]) == 'u') { + k = -1; + m = 0; + } else if (buffer[0] < '0' || buffer[0] > '9') { + s_printf(get_string(39)); + break; + } else { + k = atoi(buffer) - 1; + } - msgbase_reset_pointers(gUser->cur_mail_conf, gUser->cur_mail_area, j, k); + msgbase_reset_pointers(gUser->cur_mail_conf, gUser->cur_mail_area, m, k); - break; - case MENU_RESETALLPOINTERS: - s_printf(get_string(230)); - confirm = s_getc(); - if (confirm == 'r' || confirm == 'R') { - j = 1; - } else if (confirm == 'u' || confirm == 'U') { - j = 0; - } else { - s_printf(get_string(39)); break; - } - msgbase_reset_all_pointers(j); - break; - case MENU_FILESCAN: - file_scan(); - break; - case MENU_FULLMAILSCAN: - full_mail_scan(gUser); - break; - case MENU_FILESEARCH: - file_search(); - break; - case MENU_DISPTXTFILE: - if (menu[i]->data != NULL) { - s_displayansi_pause(menu[i]->data, 0); - } - break; - case MENU_DISPTXTFILEPAUSE: - if (menu[i]->data != NULL) { - s_displayansi_pause(menu[i]->data, 1); - } - s_printf(get_string(6)); - s_getc(); - break; - case MENU_GENWWWURLS: - genurls(); - break; - case MENU_NLBROWSER: - nl_browser(); - break; - case MENU_SENDFEEDBACK: - if (check_user(conf.sysop_name)) { + case MENU_RESETALLPOINTERS: + s_printf(get_string(230)); + confirm = s_getc(); + if (confirm == 'r' || confirm == 'R') { + m = 1; + } else if (confirm == 'u' || confirm == 'U') { + m = 0; + } else { + s_printf(get_string(39)); + break; + } + msgbase_reset_all_pointers(m); break; - } - msg = external_editor(gUser, conf.sysop_name, gUser->loginname, NULL, 0, NULL, "Feedback", 1, 0); - if (msg != NULL) { - commit_email(conf.sysop_name, "Feedback", msg); - free(msg); - } - break; - default: - break; + case MENU_FILESCAN: + file_scan(); + break; + case MENU_FULLMAILSCAN: + if (menu[i]->data[j] != NULL) { + if (strcasecmp(menu[i]->data[j], "PERSONAL") == 0) { + full_mail_scan_personal(gUser); + } else { + full_mail_scan(gUser); + } + } else { + full_mail_scan(gUser); + } + break; + case MENU_FILESEARCH: + file_search(); + break; + case MENU_DISPTXTFILE: + if (menu[i]->data[j] != NULL) { + s_displayansi_pause(menu[i]->data[j], 0); + } + break; + case MENU_DISPTXTFILEPAUSE: + if (menu[i]->data[j] != NULL) { + s_displayansi_pause(menu[i]->data[j], 1); + } + s_printf(get_string(6)); + s_getc(); + break; + case MENU_GENWWWURLS: + genurls(); + break; + case MENU_NLBROWSER: + nl_browser(); + break; + case MENU_SENDFEEDBACK: + if (check_user(conf.sysop_name)) { + break; + } + msg = external_editor(gUser, conf.sysop_name, gUser->loginname, NULL, 0, NULL, "Feedback", 1, 0); + if (msg != NULL) { + commit_email(conf.sysop_name, "Feedback", msg); + free(msg); + } + break; + case MENU_BLOGDISPLAY: + blog_display(); + break; + case MENU_BLOGWRITE: + blog_write(); + break; + default: + break; + } } break; } diff --git a/src/strings.c b/src/strings.c index f08ef2c..ece3ee1 100644 --- a/src/strings.c +++ b/src/strings.c @@ -10,7 +10,7 @@ char **strings; int string_count; void chomp(char *string) { - while ((string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n') && strlen(string)) { + while (strlen(string) && (string[strlen(string)-1] == '\r' || string[strlen(string)-1] == '\n')) { string[strlen(string)-1] = '\0'; } } diff --git a/src/users.c b/src/users.c index 1026d08..a1e0d7a 100644 --- a/src/users.c +++ b/src/users.c @@ -76,7 +76,7 @@ static int secLevel(void* user, const char* section, const char* name, } int save_user(struct user_record *user) { - char buffer[256]; + char buffer[PATH_MAX]; sqlite3 *db; sqlite3_stmt *res; int rc; @@ -84,7 +84,7 @@ int save_user(struct user_record *user) { char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=?,signature=?,autosig=? where loginname LIKE ?"; - sprintf(buffer, "%s/users.sq3", conf.bbs_path); + snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); @@ -99,7 +99,7 @@ int save_user(struct user_record *user) { if (rc == SQLITE_OK) { sqlite3_bind_text(res, 1, user->password, -1, 0); - sqlite3_bind_text(res, 2, user->salt, -1, 0); + sqlite3_bind_text(res, 2, user->salt, -1, 0); sqlite3_bind_text(res, 3, user->firstname, -1, 0); sqlite3_bind_text(res, 4, user->lastname, -1, 0); sqlite3_bind_text(res, 5, user->email, -1, 0); @@ -128,13 +128,13 @@ int save_user(struct user_record *user) { rc = sqlite3_step(res); - if (rc != SQLITE_DONE) { - + sqlite3_finalize(res); dolog("execution failed: %s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } + sqlite3_finalize(res); sqlite3_close(db); return 1; @@ -583,7 +583,7 @@ int check_user(char *loginname) { } struct user_record *new_user() { - char buffer[256]; + char buffer[PATH_MAX]; struct user_record *user; int done = 0; char c; @@ -603,7 +603,7 @@ struct user_record *new_user() { s_printf(get_string(166)); s_readstring(buffer, 16); s_printf("\r\n"); - if (strlen(buffer) < 3) { + if (strlen(buffer) < 2) { s_printf(get_string(167)); continue; } @@ -753,7 +753,7 @@ struct user_record *new_user() { user->sec_level = conf.newuserlvl; user->bwavepktno = 0; user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t)); - sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); + snprintf(buffer, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level); if (ini_parse(buffer, secLevel, user->sec_info) <0) { dolog("Unable to load sec Level ini (%s)!", buffer); diff --git a/src/www.c b/src/www.c index 25ed557..4cbe0a2 100644 --- a/src/www.c +++ b/src/www.c @@ -420,6 +420,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url char *filename; int email; char *endptr; + int file_dir; + int file_sub; + char *filen; // char *static_buffer; page = NULL; @@ -573,6 +576,16 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); sprintf(whole_page, "%s%s%s", header, page, footer); + } else if (strcasecmp(url, "/blog") == 0 || strcasecmp(url, "/blog/") == 0) { + page = www_blog(); + if (page == NULL) { + free(header); + free(footer); + return MHD_NO; + } + whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); + + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) { con_inf->user = www_auth_ok(connection, url_); @@ -853,7 +866,115 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url free(footer); return MHD_YES; } + } else if (strcasecmp(url, "/files/areas/") == 0 || strcasecmp(url, "/files/areas") == 0) { + page = www_files_areas(); + whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); + sprintf(whole_page, "%s%s%s", header, page, footer); + } else if (strncasecmp(url, "/files/areas/", 13) == 0) { + file_dir = -1; + file_sub = -1; + filen = NULL; + url_copy = strdup(&url[13]); + + aptr = strtok(url_copy, "/"); + if (aptr != NULL) { + file_dir = strtol(aptr, &endptr, 10); + if (endptr == aptr) { + file_dir = -1; + } + aptr = strtok(NULL, "/"); + if (aptr != NULL) { + file_sub = strtol(aptr, &endptr, 10); + if (endptr == aptr) { + file_sub = -1; + } + aptr = strtok(NULL, "/"); + if (aptr != NULL) { + filen = strdup(aptr); + } + } + } + free(url_copy); + + if (file_dir != -1 && file_sub != -1 && filen == NULL) { + if (file_dir >= 0 && file_dir < conf.file_directory_count && file_sub >= 0 && file_sub < conf.file_directories[file_dir]->file_sub_count) { + if (conf.file_directories[file_dir]->display_on_web) { + page = www_files_display_listing(file_dir, file_sub); + } + } + } else if (file_dir != -1 && file_sub != -1 && filen != NULL) { + if (file_dir >= 0 && file_dir < conf.file_directory_count && file_sub >= 0 && file_sub < conf.file_directories[file_dir]->file_sub_count) { + if (conf.file_directories[file_dir]->display_on_web) { + // send file + filename = www_files_get_from_area(file_dir, file_sub, filen); + free(filen); + if (filename != NULL) { + mime = NULL; + // get mimetype + for (i=strlen(filename);i>0;--i) { + if (filename[i] == '.') { + mime = www_get_mime_type(&filename[i+1]); + break; + } + if (filename[i] == '/') { + mime = www_get_mime_type(NULL); + break; + } + } + + if (mime = NULL) { + mime = www_get_mime_type(NULL); + } + if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) { + fno = open(filename, O_RDONLY); + if (fno != -1) { + + + response = MHD_create_response_from_fd(s.st_size, fno); + MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime); + sprintf(buffer, "%ld", s.st_size); + MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_LENGTH, buffer); + + snprintf(buffer, PATH_MAX, "attachment; filename=\"%s\"", basename(filename)); + MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_DISPOSITION, buffer); + ret = MHD_queue_response (connection, MHD_HTTP_OK, response); + MHD_destroy_response (response); + free(header); + free(footer); + free(filename); + return ret; + } + } + free(filename); + } + if (www_404(header, footer, connection) != 0) { + free(header); + free(footer); + return MHD_NO; + } + free(header); + free(footer); + return MHD_YES; + } else { + free(filen); + } + } else { + free(filen); + } + } + if (page == NULL) { + if (www_403(header, footer, connection) != 0) { + free(header); + free(footer); + return MHD_NO; + } + free(header); + free(footer); + return MHD_YES; + } + whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1); + sprintf(whole_page, "%s%s%s", header, page, footer); } else if (strncasecmp(url, "/files/", 7) == 0) { filename = www_decode_hash(&url[7]); if (filename != NULL) { diff --git a/src/www_blog.c b/src/www_blog.c new file mode 100644 index 0000000..43b2ac1 --- /dev/null +++ b/src/www_blog.c @@ -0,0 +1,121 @@ +#if defined(ENABLE_WWW) + +#include +#include +#include +#include "bbs.h" + + +extern struct bbs_config conf; + +char *www_blog() { + char *page; + int max_len; + int len; + char buffer[4096]; + + struct blog_entry_t **blog_entries; + int blog_entry_count = 0; + int i, j; + struct tm thetime; + int hour; + + char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"}; + char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"}; + + page = (char *)malloc(4096); + max_len = 4096; + len = 0; + memset(page, 0, 4096); + + sprintf(buffer, "

System Blog

\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + blog_entry_count = blog_load(&blog_entries); + + if (blog_entry_count == 0) { + sprintf(buffer, "

No Entries

\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } else { + for (i=0;idate, &thetime); + if (thetime.tm_hour >= 12) { + hour = thetime.tm_hour - 12; + } else { + hour = thetime.tm_hour; + } + sprintf(buffer, "

%s

%d:%02d%s %s, %s %d %d
by %s
", blog_entries[i]->subject,(hour == 0 ? 12 : hour), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + for (j=0;jbody);j++) { + if (blog_entries[i]->body[j] == '\r') { + if (blog_entries[i]->body[j+1] == '\r') { + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } else { + if (len + 1 > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + page[len++] = ' '; + page[len] = '\0'; + } + } else { + if (len + 1 > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + page[len++] = blog_entries[i]->body[j]; + page[len] = '\0'; + } + } + sprintf(buffer, "

"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } + + for (i=0;isubject); + free(blog_entries[i]->author); + free(blog_entries[i]->body); + free(blog_entries[i]); + } + free(blog_entries); + } + + return page; +} + +#endif \ No newline at end of file diff --git a/src/www_files.c b/src/www_files.c index cfad512..a32e331 100644 --- a/src/www_files.c +++ b/src/www_files.c @@ -9,13 +9,65 @@ extern struct bbs_config conf; extern struct user_record *gUser; +extern char * aha(char *input); + +static char *www_decode(char *clean_url) { + char *url = (char *)malloc(strlen(clean_url) + 1); + int i; + int j = 0; + unsigned char c; + if (clean_url == NULL) { + free(url); + return NULL; + } + + for (i=0;isec_level < ) -#endif // get filename from database snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); return NULL; } sqlite3_busy_timeout(db, 5000); @@ -233,5 +279,270 @@ char *www_create_link(int dir, int sub, int fid) { return ret; } +char *www_files_display_listing(int dir, int sub) { + char *page; + int max_len; + int len; + char buffer[4096]; + char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; + char *filename; + char c; + int size; + char *aha_out; + char *description; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + int i; + char *clean_url; + + page = (char *)malloc(4096); + max_len = 4096; + len = 0; + memset(page, 0, 4096); + + snprintf(buffer, 4096, "

Files: %s - %s

\n", conf.file_directories[dir]->name, conf.file_directories[dir]->file_subs[sub]->name); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + snprintf(buffer, 4096, "%s/%s.sq3", conf.bbs_path, conf.file_directories[dir]->file_subs[sub]->database); + + rc = sqlite3_open(buffer, &db); + if (rc != SQLITE_OK) { + free(page); + return NULL; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + free(page); + return NULL; + } + snprintf(buffer, 4096, "\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + while (sqlite3_step(res) == SQLITE_ROW) { + filename = strdup(sqlite3_column_text(res, 1)); + clean_url = www_encode(basename(filename)); + snprintf(buffer, 4096, "", conf.www_url, dir, sub, basename(clean_url), basename(filename)); + free(clean_url); + free(filename); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + size = sqlite3_column_int(res, 3); + + if (size > 1024 * 1024 * 1024) { + size = size / 1024 / 1024 / 1024; + c = 'G'; + } else if (size > 1024 * 1024) { + size = size / 1024 / 1024; + c = 'M'; + } else if (size > 1024) { + size = size / 1024; + c = 'K'; + } else { + c = 'b'; + } + + snprintf(buffer, 4096, "", size, c); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + description = strdup((char *)sqlite3_column_text(res, 2)); + + for (i=0;i"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + aha_out = aha(description); + + while (len + strlen(aha_out) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, aha_out); + len += strlen(aha_out); + + free(aha_out); + free(description); + + snprintf(buffer, 4096, "\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + } + + snprintf(buffer, 4096, "
FilenameSizeDescription
%s%d%c
\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + sqlite3_finalize(res); + sqlite3_close(db); + + return page; +} + +char *www_files_areas() { + char *page; + int max_len; + int len; + char buffer[4096]; + int i; + int j; + + page = (char *)malloc(4096); + max_len = 4096; + len = 0; + memset(page, 0, 4096); + + sprintf(buffer, "

File Directories

\n"); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + + for (i=0;idisplay_on_web) { + sprintf(buffer, "
%s
\n", conf.file_directories[i]->name); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + for (j=0;jfile_sub_count;j++) { + sprintf(buffer, "\n", conf.www_url, i, j, conf.file_directories[i]->file_subs[j]->name); + if (len + strlen(buffer) > max_len - 1) { + max_len += 4096; + page = (char *)realloc(page, max_len); + } + strcat(page, buffer); + len += strlen(buffer); + } + } + } + + return page; +} + +char *www_files_get_from_area(int dir, int sub, char *clean_file) { + char *sql = "SELECT filename FROM files WHERE approved=1 AND filename LIKE ? ESCAPE \"^\""; + char *filenamelike; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + char buffer[PATH_MAX]; + char *ret = NULL; + int i; + int extra = 0; + int j; + char *file; + + file = www_decode(clean_file); + + for (i=0;ifile_subs[sub]->database); + + rc = sqlite3_open(buffer, &db); + if (rc != SQLITE_OK) { + return NULL; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return NULL; + } + sqlite3_bind_text(res, 1, filenamelike, -1, 0); + + rc = sqlite3_step(res); + if (rc == SQLITE_ROW) { + ret = strdup(sqlite3_column_text(res, 0)); + + } + + free(filenamelike); + sqlite3_finalize(res); + sqlite3_close(db); + return ret; +} #endif diff --git a/src/www_last10.c b/src/www_last10.c index f387a1d..62bac31 100644 --- a/src/www_last10.c +++ b/src/www_last10.c @@ -17,7 +17,7 @@ char *www_last10() { int i,z; struct tm l10_time; - FILE *fptr = fopen("last10.dat", "rb"); + FILE *fptr = fopen("last10v2.dat", "rb"); if (fptr != NULL) { @@ -56,9 +56,17 @@ char *www_last10() { for (z=0;z
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mon + 1, l10_time.tm_mday, l10_time.tm_year - 100); + if (callers[z].calls == 1) { + sprintf(buffer, "
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mon + 1, l10_time.tm_mday, l10_time.tm_year - 100, conf.www_url); + } else { + sprintf(buffer, "
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mon + 1, l10_time.tm_mday, l10_time.tm_year - 100); + } } else { - sprintf(buffer, "
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100); + if (callers[z].calls == 1) { + sprintf(buffer, "
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100, conf.www_url); + } else { + sprintf(buffer, "
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100); + } } if (len + strlen(buffer) > max_len - 1) { max_len += 4096; diff --git a/src/www_msgs.c b/src/www_msgs.c index 96ed912..e0f26ca 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -15,7 +15,7 @@ extern struct bbs_config conf; static char *www_wordwrap(char *content, int cutoff); -static char *www_sanitize(char *inp) { +char *www_sanitize(char *inp) { int i; char *result; int len = 0; @@ -150,7 +150,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i strcat(page, buffer); len += strlen(buffer); } - mhrs = read_message_headers(conference, area, user); + mhrs = read_message_headers(conference, area, user, 0); if (mhrs == NULL) { sprintf(buffer, "

No Messages

\n"); @@ -174,6 +174,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { free(page); + free_message_headers(mhrs); return NULL; } if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { @@ -181,7 +182,7 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i jlr.HighReadMsg = 0; } JAM_CloseMB(jb); - + free(jb); skip_f = mhrs->msg_count - skip; skip_t = mhrs->msg_count - skip - 50; if (skip_t < 0) { @@ -271,6 +272,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char *replyid = NULL; char *body = NULL; char *body2 = NULL; + char *replybody = NULL; int z; struct tm msg_date; time_t date; @@ -283,7 +285,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i char *from_s; char *subject_s; char *to_s; - + int l1, l2; char *aha_text; char *aha_out; @@ -303,11 +305,13 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); if (z != 0) { JAM_CloseMB(jb); + free(jb); return NULL; } if (jmh.Attribute & JAM_MSG_DELETED) { JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return NULL; } @@ -390,6 +394,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i free(replyid); } JAM_CloseMB(jb); + free(jb); return NULL; } } @@ -411,6 +416,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i JAM_WriteLastRead(jb, user->id, &jlr); JAM_CloseMB(jb); + free(jb); page = (char *)malloc(4096); max_len = 4096; @@ -605,13 +611,27 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i strcat(page, buffer); len += strlen(buffer); + replybody = (char *)malloc(strlen(body) + 1); + + l2 = 0; + for (l1=0;l1' && line_count < 4) { + quote_line = 1; } + + if (content[i] == '\r' && content[i+1] != '\r') { + if (content[i+1] == ' ' && quote_line != 1) { + content[at++] = '\r'; + line_count = 0; + quote_line = 0; + } else if (quote_line != 1) { + if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ') { + content[at++] = ' '; + line_count++; + } + } else if (quote_line == 1) { + content[at++] = '\r'; + line_count = 0; + quote_line = 0; + } + } else if (content[i] == '\r' && content[i+1] == '\r') { + content[at++] = '\r'; + content[at++] = '\r'; + line_count = 0; + quote_line = 0; + i++; + } else { + content[at++] = content[i]; + line_count++; + } + } + content[at++] = content[i]; + content[at] = '\0'; + + + at = 0; + + len = strlen(content); + ret = (char *)malloc(len + 1); + if (ret == NULL) { + return NULL; + } + + line_count = 0; + quote_line = 0; + + for (i=0;i' && line_count < 4) { + quote_line = 1; + } } else { ret[at++] = content[i]; } @@ -725,12 +799,21 @@ static char *www_wordwrap(char *content, int cutoff) { if (content[i] == '\r') { line_count = 0; last_space = NULL; + quote_line = 0; } else if (line_count == cutoff) { // wrap - if (last_space != NULL) { + if (quote_line == 1) { + while (i < len - 1 && content[i + 1] != '\r') { + i++; + } + last_space = NULL; + line_count = 0; + quote_line = 0; + } else if (last_space != NULL) { *last_space = '\r'; line_count = strlen(&last_space[1]); last_space = NULL; + quote_line = 0; } else { extra++; ret = (char *)realloc(ret, strlen(content) + extra + 1); @@ -741,6 +824,7 @@ static char *www_wordwrap(char *content, int cutoff) { ret[at] = '\0'; last_space = NULL; line_count = 0; + quote_line = 0; } } else { line_count++; @@ -868,11 +952,13 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, sleep(1); } else { JAM_CloseMB(jb); + free(jb); return 0; } } if (z != 0) { JAM_CloseMB(jb); + free(jb); return 0; } @@ -903,6 +989,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } body3 = (char *)malloc(strlen(body2) + 2 + strlen(buffer)); @@ -911,6 +998,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } @@ -924,6 +1012,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_UnlockMB(jb); JAM_DelSubPacket(jsp); JAM_CloseMB(jb); + free(jb); return 0; } else { if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) { @@ -941,7 +1030,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, JAM_DelSubPacket(jsp); JAM_CloseMB(jb); - + free(jb); return 1; } return 0; diff --git a/utils/dosbox_shim/Makefile b/utils/dosbox_shim/Makefile new file mode 100644 index 0000000..cdab50f --- /dev/null +++ b/utils/dosbox_shim/Makefile @@ -0,0 +1,51 @@ +OS := $(shell uname -s) + +ifeq ($(OS), FreeBSD) + CC=cc + CFLAGS=-I/usr/local/include + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), DragonFly) + CC=cc + CFLAGS=-I/usr/local/include -I/usr/local/include/ncurses + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), NetBSD) + CC=cc + CFLAGS=-I/usr/pkg/include + LDFLAGS=-R/usr/pkg/lib -L/usr/pkg/lib +endif +ifeq ($(OS), OpenBSD) + CC=cc + CFLAGS=-I/usr/local/include + LDFLAGS=-L/usr/local/lib +endif +ifeq ($(OS), Linux) + CC=gcc + CFLAGS= + LDFLAGS= +endif +ifeq ($(OS), Darwin) + CC=cc + CFLAGS= + LDFLAGS= +endif +ifeq ($(OS), SunOS) + CC=gcc + CFLAGS= + LDFLAGS= +endif + +DEPS = main.c + +OBJ = main.o +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +shim: $(OBJ) + $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) + +.PHONY: clean + +clean: + rm -f $(OBJ) shim diff --git a/utils/dosbox_shim/main.c b/utils/dosbox_shim/main.c new file mode 100644 index 0000000..26b7529 --- /dev/null +++ b/utils/dosbox_shim/main.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(__OpenBSD__) +# include +#endif + +int main(int argc, char **argv) { + int port; + int node; + char *script; + pid_t pid; + int server_socket; + int on = 1; + struct sockaddr_in server, client; + int client_fd; + int c; + fd_set master, read_fds; + int len; + char inbuf[256]; + int i; + char *arguments[4]; + + if (argc < 4) { + fprintf(stderr, "Usage ./dosbox_shim [port] [node] [script]\n"); + exit(-1); + } + + port = atoi(argv[1]); + node = atoi(argv[2]); + script = strdup(argv[3]); + + + pid = fork(); + + if (pid < 0) { + fprintf(stderr, "Error forking!\n"); + exit(-1); + } else if (pid == 0) { + arguments[0] = strdup(script); + sprintf(inbuf, "%d", port); + arguments[1] = strdup(inbuf); + sprintf(inbuf, "%d", node); + arguments[2] = strdup(inbuf); + arguments[3] = NULL; + + + execvp(script, arguments); + } else { + server_socket = socket(AF_INET, SOCK_STREAM, 0); + if (server_socket == -1) { + fprintf(stderr, "Couldn't create socket.\n"); + exit(-1); + } + if (setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { + fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); + exit(1); + } + server.sin_family = AF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = htons(port); + + c = sizeof(struct sockaddr_in); + + if (bind(server_socket, (struct sockaddr *)&server, sizeof(server)) < 0) { + perror("Bind Failed, Error\n"); + exit(-1); + } + + listen(server_socket, 1); + + client_fd = accept(server_socket, (struct sockaddr *)&client, (socklen_t *)&c); + + if (client_fd == -1) { + perror("accept"); + exit(-1); + } + + FD_ZERO(&master); + + FD_SET(STDIN_FILENO, &master); + FD_SET(client_fd, &master); + + while(1) { + read_fds = master; + + if (select(client_fd + 1, &read_fds, NULL, NULL, NULL) == -1) { + perror("select"); + exit(-1); + } + + if (FD_ISSET(STDIN_FILENO, &read_fds)) { + len = read(STDIN_FILENO, inbuf, 256); + for (i=0;i +#include +#include +#include +#include +#include +#include +#include +#include "../../src/inih/ini.h" +#include "filecenter.h" + +struct files { + char *name; + char *description; + int approved; + int dlcount; + time_t uploadtime; +}; + +struct file_directory **file_directories; +int file_directory_count = 0; +CDKSCREEN *cdkscreen = 0; +//CDKMENTRY *desc_entry = 0; +WINDOW *desc_win = 0; +WINDOW *instruction_win = 0; + +char instructions[] = "t - toggle approval\na - approve all\nu - unapprove all\nd - delete file\nm - move file\ns - scan for files\ne - edit description"; +char *bbspath; +char *configpath; + +int current_dir; +int current_sub; + +struct files **f; +int fcount = 0; +char **filenames; + +struct archiver **archivers; +int archiver_count = 0; + +static int archiver_config_handler(void* user, const char* section, const char* name, + const char* value) +{ + int i; + + for (i=0;iname, section) == 0) { + // found it + if (strcasecmp(name, "extension") == 0) { + archivers[i]->extension = strdup(value); + } else if (strcasecmp(name, "unpack") == 0) { + archivers[i]->unpack = strdup(value); + } else if (strcasecmp(name, "pack") == 0) { + archivers[i]->pack = strdup(value); + } + return 1; + } + } + + if (archiver_count == 0) { + archivers = (struct archiver **)malloc(sizeof(struct archiver *)); + } else { + archivers = (struct archiver **)realloc(archivers, sizeof(struct archiver *) * (archiver_count + 1)); + } + + archivers[archiver_count] = (struct archiver *)malloc(sizeof(struct archiver)); + + archivers[archiver_count]->name = strdup(section); + + if (strcasecmp(name, "extension") == 0) { + archivers[archiver_count]->extension = strdup(value); + } else if (strcasecmp(name, "unpack") == 0) { + archivers[archiver_count]->unpack = strdup(value); + } else if (strcasecmp(name, "pack") == 0) { + archivers[archiver_count]->pack = strdup(value); + } + archiver_count++; + + return 1; +} + +static int bbs_cfg_handler(void *user, const char* section, const char* name, const char *value) +{ + if (strcasecmp(section, "paths") == 0) { + if (strcasecmp(name, "bbs path") == 0) { + bbspath = strdup(value); + } + if (strcasecmp(name, "config path") == 0) { + configpath = strdup(value); + } + } + if (strcasecmp(section, "file directories") == 0) { + if (file_directory_count == 0) { + file_directories = (struct file_directory **)malloc(sizeof(struct file_directory *)); + } else { + file_directories = (struct file_directory **)realloc(file_directories, sizeof(struct file_directory *) * (file_directory_count + 1)); + } + + file_directories[file_directory_count] = (struct file_directory *)malloc(sizeof(struct file_directory)); + file_directories[file_directory_count]->name = strdup(name); + file_directories[file_directory_count]->path = strdup(value); + file_directories[file_directory_count]->file_sub_count = 0; + file_directories[file_directory_count]->display_on_web = 0; + file_directory_count++; + } + return 1; +} + +static int file_sub_handler(void* user, const char* section, const char* name, + const char* value) +{ + struct file_directory *fd = (struct file_directory *)user; + int i; + + if (strcasecmp(section, "main") == 0) { + if (strcasecmp(name, "visible sec level") == 0) { + fd->sec_level = atoi(value); + } else if (strcasecmp(name, "visible on web") == 0) { + if (strcasecmp(value, "true") == 0) { + fd->display_on_web = 1; + } else { + fd->display_on_web = 0; + } + } + } else { + // check if it's partially filled in + for (i=0;ifile_sub_count;i++) { + if (strcasecmp(fd->file_subs[i]->name, section) == 0) { + if (strcasecmp(name, "upload sec level") == 0) { + fd->file_subs[i]->upload_sec_level = atoi(value); + } else if (strcasecmp(name, "download sec level") == 0) { + fd->file_subs[i]->download_sec_level = atoi(value); + } else if (strcasecmp(name, "database") == 0) { + fd->file_subs[i]->database = strdup(value); + } else if (strcasecmp(name, "upload path") == 0) { + fd->file_subs[i]->upload_path = strdup(value); + } + return 1; + } + } + if (fd->file_sub_count == 0) { + fd->file_subs = (struct file_sub **)malloc(sizeof(struct file_sub *)); + } else { + fd->file_subs = (struct file_sub **)realloc(fd->file_subs, sizeof(struct file_sub *) * (fd->file_sub_count + 1)); + } + + fd->file_subs[fd->file_sub_count] = (struct file_sub *)malloc(sizeof(struct file_sub)); + + fd->file_subs[fd->file_sub_count]->name = strdup(section); + if (strcasecmp(name, "upload sec level") == 0) { + fd->file_subs[fd->file_sub_count]->upload_sec_level = atoi(value); + } else if (strcasecmp(name, "download sec level") == 0) { + fd->file_subs[fd->file_sub_count]->download_sec_level = atoi(value); + } else if (strcasecmp(name, "database") == 0) { + fd->file_subs[fd->file_sub_count]->database = strdup(value); + } else if (strcasecmp(name, "upload path") == 0) { + fd->file_subs[fd->file_sub_count]->upload_path = strdup(value); + } + fd->file_sub_count++; + } + return 1; +} + +static void doApprove(int index) { + char sql_approve[] = "UPDATE files SET approved=1 WHERE filename LIKE ?"; + sqlite3_stmt *res; + int rc; + struct stat st; + sqlite3 *db; + char database[PATH_MAX]; + + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + + // populate scroll list + rc = sqlite3_open(database, &db); + + if (rc != SQLITE_OK) { + return; + } + sqlite3_busy_timeout(db, 5000); + + + if (stat(f[index]->name, &st) == 0) { + f[index]->approved = 1; + sprintf(filenames[index], "%s (approved)", basename(f[index]->name)); + rc = sqlite3_prepare_v2(db, sql_approve, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return; + } + sqlite3_bind_text(res, 1, f[index]->name, -1, 0); + + sqlite3_step(res); + + sqlite3_finalize(res); + } + sqlite3_close(db); +} + +static void doDisapprove(int index) { + char sql_approve[] = "UPDATE files SET approved=0 WHERE filename LIKE ?"; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + struct stat s; + char database[PATH_MAX]; + + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + + // populate scroll list + rc = sqlite3_open(database, &db); + + if (rc != SQLITE_OK) { + return; + } + sqlite3_busy_timeout(db, 5000); + + f[index]->approved = 0; + if (stat(f[index]->name, &s) != 0) { + sprintf(filenames[index], "%s (missing)", basename(f[index]->name)); + } else { + sprintf(filenames[index], "%s (unapproved)", basename(f[index]->name)); + } + rc = sqlite3_prepare_v2(db, sql_approve, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return; + } + sqlite3_bind_text(res, 1, f[index]->name, -1, 0); + + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); +} + +static int deleteFile(EObjectType cdktype, void *object, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)object; + + int index = getCDKScrollCurrent(s); + sqlite3 *db; + sqlite3_stmt *res; + int rc; + struct stat st; + char database[PATH_MAX]; + int i; + + char sql_delete[] = "DELETE FROM files WHERE filename LIKE ?"; + + if (index >= fcount) { + return FALSE; + } + + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + + rc = sqlite3_open(database, &db); + + if (rc != SQLITE_OK) { + return FALSE; + } + sqlite3_busy_timeout(db, 5000); + + rc = sqlite3_prepare_v2(db, sql_delete, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return FALSE; + } + sqlite3_bind_text(res, 1, f[index]->name, -1, 0); + + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + + + if (stat(f[index]->name, &st) == 0) { + remove(f[index]->name); + } + + free(f[index]->name); + free(f[index]->description); + free(f[index]); + free(filenames[index]); + + + for (i=index; i < fcount - 1; i++) { + filenames[i] = filenames[i+1]; + f[i] = f[i+1]; + } + + fcount--; + + if (fcount == 0) { + free(filenames); + free(f); + filenames = NULL; + setCDKScrollItems(s, filenames, fcount, FALSE); + eraseCDKScroll(s); + drawCDKScroll(s, TRUE); +// refreshCDKScreen(cdkscreen); + return FALSE; + } + + filenames = (char **)realloc(filenames, sizeof(char *) * (fcount)); + f = (struct files **)realloc(f, sizeof(struct files *) * (fcount)); + + + setCDKScrollItems(s, filenames, fcount, FALSE); + eraseCDKScroll(s); + drawCDKScroll(s, TRUE); +// refreshCDKScreen(cdkscreen); + return FALSE; +} + +static int approveFile(EObjectType cdktype, void *object, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)object; + + + int index = getCDKScrollCurrent(s); + if (index >= fcount) { + return FALSE; + } + if (f[index]->approved == 1) { + doDisapprove(index); + } else { + doApprove(index); + } + setCDKScrollItems(s, filenames, fcount, FALSE); +// refreshCDKScreen(cdkscreen); + return FALSE; +} + +static int approveAll(EObjectType cdktype, void *object, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)object; + int i; + + for (i=0;iapproved == 0) { + doApprove(i); + } + } + setCDKScrollItems(s, filenames, fcount, FALSE); +// refreshCDKScreen(cdkscreen); + return FALSE; + +} + +static int disapproveAll(EObjectType cdktype, void *object, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)object; + int i; + + for (i=0;iapproved == 1) { + doDisapprove(i); + } + } + setCDKScrollItems(s, filenames, fcount, FALSE); +// refreshCDKScreen(cdkscreen); + return FALSE; + +} + +int copy_file(char *src, char *dest) { + FILE *src_file; + FILE *dest_file; + + char c; + + src_file = fopen(src, "rb"); + if (!src_file) { + return -1; + } + dest_file = fopen(dest, "wb"); + if (!dest_file) { + fclose(src_file); + return -1; + } + + while(1) { + c = fgetc(src_file); + if (!feof(src_file)) { + fputc(c, dest_file); + } else { + break; + } + } + + fclose(src_file); + fclose(dest_file); + return 0; +} + +int recursive_delete(const char *dir) { + int ret = 0; + FTS *ftsp = NULL; + FTSENT *curr; + + char *files[] = { (char *) dir, NULL }; + + ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL); + if (!ftsp) { + ret = -1; + goto finish; + } + + while ((curr = fts_read(ftsp))) { + switch (curr->fts_info) { + case FTS_NS: + case FTS_DNR: + case FTS_ERR: + break; + + case FTS_DC: + case FTS_DOT: + case FTS_NSOK: + break; + + case FTS_D: + break; + + case FTS_DP: + case FTS_F: + case FTS_SL: + case FTS_SLNONE: + case FTS_DEFAULT: + if (remove(curr->fts_accpath) < 0) { + ret = -1; + } + break; + } + } + +finish: + if (ftsp) { + fts_close(ftsp); + } + + return ret; +} + +static int moveFile(EObjectType cdktype, void *object, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)object; + CDKSCROLL *dirScrollList; + CDKSCROLL *subScrollList; + + int dir_sel; + int sub_sel; + + char **filedirs; + char **filesubs; + + char dest_file[PATH_MAX]; + + int index = getCDKScrollCurrent(s); + + char title[42]; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + struct stat st; + char database[PATH_MAX]; + int i; + char create_sql[] = "CREATE TABLE IF NOT EXISTS files (" + "Id INTEGER PRIMARY KEY," + "filename TEXT," + "description TEXT," + "size INTEGER," + "dlcount INTEGER," + "uploaddate INTEGER," + "approved INTEGER);"; + + char sql_delete[] = "DELETE FROM files WHERE filename LIKE ?"; + char sql_insert[] = "INSERT INTO files (filename, description, size, dlcount, uploaddate, approved) VALUES(?, ?, ?, ?, ?, ?)"; + + char *err_msg = 0; + + if (index >= fcount) { + return FALSE; + } + + dirScrollList = newCDKScroll(cdkscreen, 9, 1, 1, 12, 36, "File Directories", NULL, 0, FALSE, A_REVERSE, TRUE, TRUE); + + filedirs = (char **)malloc(sizeof(char *) * file_directory_count); + + for (i=0;iname); + } + + setCDKScrollItems(dirScrollList, filedirs, file_directory_count, FALSE); + + while(1) { + dir_sel = activateCDKScroll(dirScrollList, 0); + if (dirScrollList->exitType == vESCAPE_HIT) { + break; + } else if (dirScrollList->exitType == vNORMAL) { + snprintf(title, 42, "%s", file_directories[dir_sel]->name); + + subScrollList = newCDKScroll(cdkscreen, 12, 1, 1, 12, 36, title, NULL, 0, FALSE, A_REVERSE, TRUE, TRUE); + + filesubs = (char **)malloc(sizeof(char *) * file_directory_count); + + for (i=0;ifile_sub_count;i++) { + filesubs[i] = strdup(file_directories[dir_sel]->file_subs[i]->name); + } + + setCDKScrollItems(subScrollList, filesubs, file_directories[dir_sel]->file_sub_count, FALSE); + + while (1) { + sub_sel = activateCDKScroll(subScrollList, 0); + if (subScrollList->exitType == vESCAPE_HIT) { + for (i=0;ifile_sub_count;i++) { + free(filesubs[i]); + } + free(filesubs); + destroyCDKScroll(subScrollList); + break; + } else if (subScrollList->exitType == vNORMAL) { + snprintf(dest_file, PATH_MAX, "%s/%s", file_directories[dir_sel]->file_subs[sub_sel]->upload_path, basename(f[index]->name)); + + if (stat(dest_file, &st) != 0) { + // move file + if (copy_file(f[index]->name, dest_file) == 0) { + // success + unlink(f[index]->name); + // remove from database + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + rc = sqlite3_open(database, &db); + + if (rc != SQLITE_OK) { + break; + } + sqlite3_busy_timeout(db, 5000); + + rc = sqlite3_prepare_v2(db, sql_delete, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + break; + } + sqlite3_bind_text(res, 1, f[index]->name, -1, 0); + + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + + // add to dest database + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[dir_sel]->file_subs[sub_sel]->database); + rc = sqlite3_open(database, &db); + + if (rc != SQLITE_OK) { + break; + } + sqlite3_busy_timeout(db, 5000); + + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK ) { + sqlite3_free(err_msg); + sqlite3_close(db); + return FALSE; + } + + rc = sqlite3_prepare_v2(db, sql_insert, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + return FALSE; + } + + stat(dest_file, &st); + sqlite3_bind_text(res, 1, dest_file, -1, 0); + sqlite3_bind_text(res, 2, f[index]->description, -1, 0); + sqlite3_bind_int(res, 3, st.st_size); + sqlite3_bind_int(res, 4, f[index]->dlcount); + sqlite3_bind_int(res, 5, f[index]->uploadtime); + sqlite3_bind_int(res, 6, f[index]->approved); + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + // remove from current memory + + free(filenames[index]); + free(f[index]->name); + free(f[index]->description); + free(f[index]); + + for (i=index;ifile_sub_count;i++) { + free(filesubs[i]); + } + free(filesubs); + eraseCDKScroll(subScrollList); + destroyCDKScroll(subScrollList); + } + for (i=0;idescription, fptr); + + fclose(fptr); + + snprintf(buffer, PATH_MAX, "./editor.sh"); + if (stat(buffer, &st) != 0) { + snprintf(buffer, PATH_MAX, "/usr/bin/nano"); + if (stat(buffer, &st) != 0) { + snprintf(buffer, PATH_MAX, "/usr/bin/vi"); + if (stat(buffer, &st) != 0) { + return FALSE; + } + } + } + strncat(buffer, " /tmp/filecenter_id.txt", PATH_MAX); + def_prog_mode(); + savetty(); + system(buffer); + resetty(); + reset_prog_mode(); + snprintf(buffer, PATH_MAX, "/tmp/filecenter_id.txt"); + + if (stat(buffer, &st) != 0) { + return FALSE; + } + fptr = fopen(buffer, "r"); + if (!fptr) { + return FALSE; + } + free(f[index]->description); + + f[index]->description = (char *)malloc(sizeof(char) * (st.st_size + 1)); + memset(f[index]->description, 0, st.st_size + 1); + + + fread(f[index]->description, 1, st.st_size, fptr); + + fclose(fptr); + unlink(buffer); + + // update file descripiton + snprintf(buffer, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + + rc = sqlite3_open(buffer, &db); + + if (rc != SQLITE_OK) { + return FALSE; + } + sqlite3_busy_timeout(db, 5000); + + rc = sqlite3_prepare_v2(db, sql_update, -1, &res, 0); + + sqlite3_bind_text(res, 1, f[index]->description, -1, 0); + sqlite3_bind_text(res, 2, f[index]->name, -1, 0); + + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + + // update display + refreshCDKScreen(cdkscreen); + werase(desc_win); + waddstr(desc_win, f[index]->description); + wrefresh(desc_win); + werase(instruction_win); + waddstr(instruction_win, instructions); + wrefresh(instruction_win); +} + +static int scanFiles(EObjectType cdktype, void *object, void *clientData, chtype input) { + DIR *ind = opendir(file_directories[current_dir]->file_subs[current_sub]->upload_path); + FILE *fptr; + struct dirent *dent; + int i; + int j; + int bpos; + int gotdesc = 0; + char buffer[PATH_MAX]; + int found; + char *description; + char addfilesql[] = "INSERT INTO files (filename, description, size, dlcount, uploaddate, approved) VALUES(?, ?, ?, 0, ?, 0)"; + char database[PATH_MAX]; + sqlite3 *db; + int rc; + sqlite3_stmt *res; + struct stat st; + int fdate; + int len; + CDKSCROLL *s = (CDKSCROLL *)object; + + if (!ind) { + return FALSE; + } + + while ((dent = readdir(ind)) != NULL) { + if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) { + continue; + } + + sprintf(buffer, "%s/%s", file_directories[current_dir]->file_subs[current_sub]->upload_path, dent->d_name); + + stat(buffer, &st); + + if (!S_ISREG(st.st_mode)) { + continue; + } + + found = 0; + for (j=0;jname), dent->d_name) == 0) { + found = 1; + break; + } + } + + if (found == 1) { + continue; + } + + gotdesc = 0; + description = NULL; + + for (i=0;id_name) >= strlen(archivers[i]->extension) + 1) { + if (strcasecmp(&dent->d_name[strlen(dent->d_name) - strlen(archivers[i]->extension)], archivers[i]->extension) == 0) { + // match + bpos = 0; + for (j=0;junpack);j++) { + if (archivers[i]->unpack[j] == '*') { + j++; + if (archivers[i]->unpack[j] == 'a') { + sprintf(&buffer[bpos], "%s/%s", file_directories[current_dir]->file_subs[current_sub]->upload_path, dent->d_name); + bpos = strlen(buffer); + } else if (archivers[i]->unpack[j] == 'd') { + sprintf(&buffer[bpos], "/tmp/filecenter_temp"); + bpos = strlen(buffer); + } else if (archivers[i]->unpack[j] == '*') { + buffer[bpos++] = '*'; + buffer[bpos] = '\0'; + } + } else { + buffer[bpos++] = archivers[i]->unpack[j]; + buffer[bpos] = '\0'; + } + } + + system(buffer); + + snprintf(buffer, PATH_MAX, "/tmp/filecenter_temp/FILE_ID.DIZ"); + if (stat(buffer, &st) != 0) { + snprintf(buffer, PATH_MAX, "/tmp/filecenter_temp/file_id.diz"); + if (stat(buffer, &st) != 0) { + gotdesc = 0; + snprintf(buffer, PATH_MAX, "/tmp/filecenter_temp"); + recursive_delete(buffer); + break; + } + } + + description = (char *)malloc(st.st_size + 1); + + fptr = fopen(buffer, "rb"); + + fread(description, 1, st.st_size, fptr); + description[st.st_size] = '\0'; + fclose(fptr); + + bpos = 0; + len = strlen(description); + for (j=0;jd_name) + 30); + sprintf(filenames[fcount], "%s (unapproved)", dent->d_name); + + if (fcount == 0) { + f = (struct files **)malloc(sizeof(struct files *)); + } else { + f = (struct files **)realloc(f, sizeof(struct files *) * (fcount + 1)); + } + f[fcount] = (struct files *)malloc(sizeof(struct files)); + f[fcount]->name = (char *)malloc(strlen(file_directories[current_dir]->file_subs[current_sub]->upload_path) + strlen(dent->d_name) + 2); + sprintf(f[fcount]->name, "%s/%s", file_directories[current_dir]->file_subs[current_sub]->upload_path, dent->d_name); + f[fcount]->description = description; + f[fcount]->approved = 0; + + // add to database + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[current_dir]->file_subs[current_sub]->database); + + rc = sqlite3_open(database, &db); + if (rc != SQLITE_OK) { + free(f[fcount]->name); + free(f[fcount]->description); + free(filenames[fcount]); + free(f[fcount]); + if (fcount == 0) { + free(f); + free(filenames); + } else { + f = (struct files **)realloc(f, sizeof(struct files *) * fcount); + filenames = (char **)realloc(filenames, sizeof(char *) * fcount); + } + setCDKScrollItems(s, filenames, fcount, FALSE); + eraseCDKScroll(s); + drawCDKScroll(s, TRUE); +// refreshCDKScreen(cdkscreen); + closedir(ind); + return FALSE; + } + + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, addfilesql, -1, &res, 0); + if (rc != SQLITE_OK) { + sqlite3_close(db); + free(f[fcount]->name); + free(f[fcount]->description); + free(filenames[fcount]); + free(f[fcount]); + if (fcount == 0) { + free(f); + free(filenames); + } else { + f = (struct files **)realloc(f, sizeof(struct files *) * fcount); + filenames = (char **)realloc(filenames, sizeof(char *) * fcount); + } + + setCDKScrollItems(s, filenames, fcount, FALSE); + eraseCDKScroll(s); + drawCDKScroll(s, TRUE); +// refreshCDKScreen(cdkscreen); + closedir(ind); + return FALSE; + } + stat(f[fcount]->name, &st); + + sqlite3_bind_text(res, 1, f[fcount]->name, -1, 0); + sqlite3_bind_text(res, 2, f[fcount]->description, -1, 0); + sqlite3_bind_int(res, 3, st.st_size); + fdate = time(NULL); + sqlite3_bind_int(res, 4, fdate); + + sqlite3_step(res); + + sqlite3_finalize(res); + sqlite3_close(db); + fcount++; + + } + setCDKScrollItems(s, filenames, fcount, FALSE); + eraseCDKScroll(s); + drawCDKScroll(s, TRUE); +// refreshCDKScreen(cdkscreen); + closedir(ind); + return FALSE; +} + +int desc_function(EObjectType objtype, void *obj, void *clientData, chtype input) { + CDKSCROLL *s = (CDKSCROLL *)obj; + + if (fcount == 0) return FALSE; + int index = getCDKScrollCurrent(s); + + werase(desc_win); + waddstr(desc_win, f[index]->description); + wrefresh(desc_win); +// setCDKMentryValue(desc_entry, f[index]->description); + return FALSE; +} + +void list_files(int dir, int sub) { + CDKSCROLL *scrollList = 0; + int selection; + int i; + char title[42]; + sqlite3 *db; + sqlite3_stmt *res; + int rc; + struct stat s; + char sql_read[] = "SELECT filename, description, approved, dlcount, uploaddate FROM files"; + char create_sql[] = "CREATE TABLE IF NOT EXISTS files (" + "Id INTEGER PRIMARY KEY," + "filename TEXT," + "description TEXT," + "size INTEGER," + "dlcount INTEGER," + "uploaddate INTEGER," + "approved INTEGER);"; + char database[PATH_MAX]; + char *err_msg; + + + current_dir = dir; + current_sub = sub; + + + snprintf(title, 42, "%s", file_directories[dir]->file_subs[sub]->name); + snprintf(database, PATH_MAX, "%s/%s.sq3", bbspath, file_directories[dir]->file_subs[sub]->database); + + // populate scroll list + rc = sqlite3_open(database, &db); + + + if (rc != SQLITE_OK) { + return; + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg); + if (rc != SQLITE_OK ) { + sqlite3_free(err_msg); + sqlite3_close(db); + return; + } + rc = sqlite3_prepare_v2(db, sql_read, -1, &res, 0); + + f = NULL; + filenames = NULL; + + while(sqlite3_step(res) == SQLITE_ROW) { + if (fcount == 0) { + f = (struct files **)malloc(sizeof(struct files *)); + filenames = (char **)malloc(sizeof(char *)); + } else { + f = (struct files **)realloc(f, sizeof(struct files *) * (fcount + 1)); + filenames = (char **)realloc(filenames, sizeof(char *) * (fcount + 1)); + } + + f[fcount] = (struct files *)malloc(sizeof(struct files)); + f[fcount]->name = strdup((char *)sqlite3_column_text(res, 0)); + f[fcount]->description = strdup((char *)sqlite3_column_text(res, 1)); + f[fcount]->approved = sqlite3_column_int(res, 2); + f[fcount]->dlcount = sqlite3_column_int(res, 3); + f[fcount]->uploadtime = sqlite3_column_int(res, 4); + filenames[fcount] = (char *)malloc(strlen(basename(f[fcount]->name)) + 30); + if (stat(f[fcount]->name, &s) != 0) { + sprintf(filenames[fcount], "%s (missing)", basename(f[fcount]->name)); + if (f[fcount]->approved == 1) { + // unapprove missing file + doDisapprove(fcount); + } + } else if (f[fcount]->approved) { + sprintf(filenames[fcount], "%s (approved)", basename(f[fcount]->name)); + } else { + sprintf(filenames[fcount], "%s (unapproved)", basename(f[fcount]->name)); + } + fcount++; + } + + sqlite3_finalize(res); + sqlite3_close(db); + + scrollList = newCDKScroll(cdkscreen, 6, 1, 1, 12, 36, title, NULL, 0, FALSE, A_REVERSE, TRUE, TRUE); + if (!scrollList) { + for (i=0;iname); + free(f[i]->description); + free(f[i]); + free(filenames[i]); + } + + free(f); + free(filenames); + fcount = 0; + return; + } + if (fcount > 0) { + werase(desc_win); + waddstr(desc_win, f[0]->description); +// setCDKMentryValue(desc_entry, f[0]->description); + } else { +// setCDKMentryValue(desc_entry, ""); + werase(desc_win); + } + wrefresh(desc_win); + setCDKScrollPostProcess(scrollList, desc_function, NULL); + setCDKScrollItems(scrollList, filenames, fcount, FALSE); + + bindCDKObject (vSCROLL, scrollList, 'm', moveFile, NULL); + bindCDKObject (vSCROLL, scrollList, 'u', disapproveAll, NULL); + bindCDKObject (vSCROLL, scrollList, 'a', approveAll, NULL); + bindCDKObject (vSCROLL, scrollList, 't', approveFile, NULL); + bindCDKObject (vSCROLL, scrollList, 'd', deleteFile, NULL); + bindCDKObject (vSCROLL, scrollList, 's', scanFiles, NULL); + bindCDKObject (vSCROLL, scrollList, 'e', editFileID, NULL); + + while(1) { + selection = activateCDKScroll(scrollList, 0); + if (scrollList->exitType == vESCAPE_HIT) { + break; + } + } + for (i=0;iname); + free(f[i]->description); + free(f[i]); + free(filenames[i]); + } + if (fcount != 0) { + free(f); + free(filenames); + } + fcount = 0; + destroyCDKScroll(scrollList); +} + +void list_subdirs(int selected) { + CDKSCROLL *scrollList = 0; + int selection; + int i; + char title[42]; + + char **filesubs = (char **)malloc(sizeof(char *) * file_directories[selected]->file_sub_count); + + snprintf(title, 42, "%s", file_directories[selected]->name); + + for (i=0;ifile_sub_count;i++) { + filesubs[i] = strdup(file_directories[selected]->file_subs[i]->name); + } + + scrollList = newCDKScroll(cdkscreen, 4, 1, 1, 12, 36, title, NULL, 0, FALSE, A_REVERSE, TRUE, TRUE); + if (!scrollList) { + fprintf(stderr, "Unable to make scrolllist!"); + destroyCDKScreen(cdkscreen); + endCDK(); + exit(-1); + } + setCDKScrollItems(scrollList, filesubs, file_directories[selected]->file_sub_count, FALSE); + while(1) { + selection = activateCDKScroll(scrollList, 0); + if (scrollList->exitType == vESCAPE_HIT) { + break; + } else if (scrollList->exitType == vNORMAL) { + list_files(selected, selection); + } + } + + destroyCDKScroll(scrollList); + for (i=0;ifile_sub_count;i++) { + free(filesubs[i]); + } + + free(filesubs); +} + +int main(int argc, char **argv) { + int i; + CDK_PARAMS params; + WINDOW *cursesWin = 0; + CDKSCROLL *scrollList = 0; + int selection; + char **filedirs; + char buffer[PATH_MAX]; + + CDKparseParams(argc, argv, ¶ms, "c:" CDK_CLI_PARAMS); + + if (ini_parse(CDKparamString (¶ms, 'c'), bbs_cfg_handler, NULL) <0) { + fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); + exit(-1); + } + + snprintf(buffer, 1024, "%s/archivers.ini", configpath); + if (ini_parse(buffer, archiver_config_handler, NULL) <0) { + fprintf(stderr, "Unable to load configuration ini %s\n", buffer); + exit(-1); + } + + for (i=0;ipath); + if (ini_parse(buffer, file_sub_handler, file_directories[i])) { + fprintf(stderr, "Unable to load %s\n", buffer); + exit(-1); + } + } + cursesWin = initscr(); + cdkscreen = initCDKScreen(cursesWin); + + desc_win = newwin(10, 46, 14, 1); + instruction_win = newwin(10, 32, 14, 47); + + waddstr(instruction_win, instructions); + + wrefresh(instruction_win); + + scrollList = newCDKScroll(cdkscreen, 2, 1, 1, 12, 36, "File Directories", NULL, 0, FALSE, A_REVERSE, TRUE, TRUE); + if (!scrollList) { + fprintf(stderr, "Unable to make scrolllist!"); + destroyCDKScreen(cdkscreen); + endCDK(); + exit(-1); + } + + filedirs = (char **)malloc(sizeof(char *) * file_directory_count); + + for (i=0;iname); + } + + setCDKScrollItems(scrollList, filedirs, file_directory_count, FALSE); + + while(1) { + selection = activateCDKScroll(scrollList, 0); + if (scrollList->exitType == vESCAPE_HIT) { + break; + } else if (scrollList->exitType == vNORMAL) { + list_subdirs(selection); + } + } + + destroyCDKScroll(scrollList); + destroyCDKScreen(cdkscreen); + endCDK(); +} \ No newline at end of file diff --git a/utils/magimail/src/magimail/misc.c b/utils/magimail/src/magimail/misc.c index 2f0b041..430116a 100644 --- a/utils/magimail/src/magimail/misc.c +++ b/utils/magimail/src/magimail/misc.c @@ -184,8 +184,10 @@ bool IsArc(char *file) if(strlen(file)!=12) return(FALSE); if(file[8]!='.') return(FALSE); - for(c=0;c<8;c++) + for(c=0;c<8;c++) { + if (c == 4 && tolower(file[c]) == 'p') continue; if((file[c]<'0' || file[c]>'9') && ((tolower(file[c]) < 'a') || (tolower(file[c]) > 'f'))) return(FALSE); + } strncpy(ext,&file[9],2); ext[2]=0;