11 #include <sys/types.h>
13 #include <sys/socket.h>
16 #include <netinet/in.h>
34 * Look for URL's embedded in a buffer and make them linkable. We use a
35 * target window in order to keep the BBS session in its own window.
51 for (pos = 0; pos < strlen(buf); ++pos) {
52 if (!strncasecmp(&buf[pos], "http://", 7))
54 if (!strncasecmp(&buf[pos], "ftp://", 6))
61 if ((start > 0) && (buf[start - 1] == '<'))
63 if ((start > 0) && (buf[start - 1] == '['))
65 if ((start > 0) && (buf[start - 1] == '('))
67 if ((start > 0) && (buf[start - 1] == '{'))
70 for (pos = strlen(buf); pos > start; --pos) {
71 if ((buf[pos] == ' ') || (buf[pos] == ench))
75 strncpy(urlbuf, &buf[start], end - start);
76 urlbuf[end - start] = 0;
79 strncpy(outbuf, buf, start);
80 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
81 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
82 strcat(outbuf, &buf[end]);
83 if ( strlen(outbuf) < 250 )
88 void read_message(msgnum, oper)
101 sprintf(buf, "MSG0 %ld", msgnum);
105 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
108 wprintf("<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=000077><TR><TD>\n");
109 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFF00\"> ");
110 strcpy(m_subject, "");
112 strcpy(reply_to, "nobody...xxxxx");
113 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
114 if (!strncasecmp(buf, "nhdr=yes", 8))
118 if (!strncasecmp(buf, "type=", 5))
119 format_type = atoi(&buf[5]);
120 if (!strncasecmp(buf, "from=", 5)) {
121 wprintf("from %s ", &buf[5]);
122 strcpy(from, &buf[5]);
124 if (!strncasecmp(buf, "path=", 5))
125 strcpy(reply_to, &buf[5]);
126 if (!strncasecmp(buf, "subj=", 5))
127 strcpy(m_subject, &buf[5]);
128 if ((!strncasecmp(buf, "hnod=", 5))
129 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
130 wprintf("(%s) ", &buf[5]);
131 if ((!strncasecmp(buf, "room=", 5))
132 && (strcasecmp(&buf[5], WC->wc_roomname)))
133 wprintf("in %s> ", &buf[5]);
135 if (!strncasecmp(buf, "node=", 5)) {
136 if ((WC->room_flags & QR_NETWORK)
137 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
138 && (strcasecmp(&buf[5], serv_info.serv_fqdn))))) {
139 wprintf("@%s ", &buf[5]);
141 if ((!strcasecmp(&buf[5], serv_info.serv_nodename))
142 || (!strcasecmp(&buf[5], serv_info.serv_fqdn))) {
143 strcpy(reply_to, from);
144 } else if (haschar(&buf[5], '.') == 0) {
145 sprintf(reply_to, "%s @ %s", from, &buf[5]);
148 if (!strncasecmp(buf, "rcpt=", 5))
149 wprintf("to %s ", &buf[5]);
150 if (!strncasecmp(buf, "time=", 5)) {
152 tm = (struct tm *) localtime(&now);
153 strcpy(buf, (char *) asctime(tm));
154 buf[strlen(buf) - 1] = 0;
155 strcpy(&buf[16], &buf[19]);
156 wprintf("%s ", &buf[4]);
162 wprintf("</FONT></TD>");
164 if (WC->is_room_aide) {
165 wprintf("<TD ALIGN=RIGHT NOWRAP><FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"FFFF00\"><B>");
167 wprintf("<A HREF=\"/confirm_move_msg");
168 wprintf("&msgid=%ld", msgnum);
169 wprintf("\">Move</A>");
171 wprintf(" ");
173 wprintf("<A HREF=\"/confirm_delete_msg");
174 wprintf("&msgid=%ld", msgnum);
175 wprintf("\">Del</A>");
177 wprintf("</B></FONT></TD>");
179 wprintf("</TR></TABLE>\n");
181 if (strlen(m_subject) > 0) {
182 wprintf("Subject: %s<BR>\n", m_subject);
184 if (format_type == 0) {
187 while (serv_gets(buf), strcmp(buf, "000")) {
188 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
189 buf[strlen(buf) - 1] = 0;
191 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
192 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"000044\"><I>");
194 } else if ((bq == 1) &&
195 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
196 wprintf("</FONT></I>");
202 wprintf("</TT><BR>\n");
211 * load message pointers from the server
213 int load_msg_ptrs(servcmd)
223 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
226 while (serv_gets(buf), strcmp(buf, "000")) {
227 msgarr[nummsgs] = atol(buf);
235 * command loop for reading messages
237 void readloop(char *oper)
245 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ", WC->wc_roomname);
246 if (!strcmp(oper, "readnew")) {
247 strcpy(cmd, "MSGS NEW");
248 wprintf("new messages");
249 } else if (!strcmp(oper, "readold")) {
250 strcpy(cmd, "MSGS OLD");
251 wprintf("old messages");
253 strcpy(cmd, "MSGS ALL");
254 wprintf("all messages");
256 wprintf("</B></CENTER><BR>\n");
258 nummsgs = load_msg_ptrs(cmd);
260 if (!strcmp(oper, "readnew")) {
261 wprintf("<EM>No new messages in this room.</EM>\n");
262 } else if (!strcmp(oper, "readold")) {
263 wprintf("<EM>No old messages in this room.</EM>\n");
265 wprintf("<EM>This room is empty.</EM>\n");
269 for (a = 0; a < nummsgs; ++a) {
270 read_message(msgarr[a], oper);
273 DONE:wDumpContent(1);
280 * Post message (or don't post message)
282 * Note regarding the "dont_post" variable:
283 * A random value (actually, it's just a timestamp) is inserted as a hidden
284 * field called "postseq" when the display_enter page is generated. This
285 * value is checked when posting, using the static variable dont_post. If a
286 * user attempts to post twice using the same dont_post value, the message is
287 * discarded. This prevents the accidental double-saving of the same message
288 * if the user happens to click the browser "back" button.
290 void post_message(void)
293 static long dont_post = (-1L);
297 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
298 strcpy(buf, bstr("sc"));
299 if (strcasecmp(buf, "Save message")) {
300 wprintf("Cancelled. Message was not posted.<BR>\n");
301 } else if (atol(bstr("postseq")) == dont_post) {
302 wprintf("Automatically cancelled because you have already "
303 "saved this message.<BR>\n");
305 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
309 text_to_server(bstr("msgtext"));
311 wprintf("Message has been posted.<BR>\n");
312 dont_post = atol(bstr("postseq"));
314 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
329 * prompt for a recipient (to be called from display_enter() only)
331 void prompt_for_recipient()
334 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
335 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
336 wprintf("<B>Send private e-mail</B>\n");
337 wprintf("</FONT></TD></TR></TABLE>\n");
340 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
341 wprintf("Enter recipient: ");
342 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
343 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
344 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
345 wprintf("</FORM></CENTER>\n");
351 * display the message entry screen
353 void display_enter(void)
361 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
363 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
367 if (!strncmp(buf, "570", 3)) {
368 if (strlen(bstr("recp")) > 0) {
369 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
371 prompt_for_recipient();
375 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
378 wprintf("<CENTER>Enter message below. Messages are formatted to\n");
379 wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
380 wprintf("formatting, indent a line at least one space. \n");
384 tm = (struct tm *) localtime(&now);
385 strcpy(buf, (char *) asctime(tm));
386 buf[strlen(buf) - 1] = 0;
387 strcpy(&buf[16], &buf[19]);
388 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
389 wprintf("from %s ", WC->wc_username);
390 if (strlen(bstr("recp")) > 0)
391 wprintf("to %s ", bstr("recp"));
392 wprintf("in %s> ", WC->wc_roomname);
393 wprintf("</B></FONT><BR><CENTER>\n");
395 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
396 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
398 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
400 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
401 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
403 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
404 "WIDTH=80></TEXTAREA><P>\n");
406 wprintf("</FORM></CENTER>\n");
407 DONE: wDumpContent(1);
419 * Confirm deletion of a message
421 void confirm_delete_msg(void)
425 msgid = atol(bstr("msgid"));
429 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
430 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
431 wprintf("<B>Confirm deletion of message</B>\n");
432 wprintf("</FONT></TD></TR></TABLE>\n");
436 wprintf("Are you sure you want to delete this message? <BR>\n");
438 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
439 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
441 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
442 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
443 wprintf("</FORM></CENTER>\n");
445 wprintf("</CENTER>\n");
451 void delete_msg(void)
456 msgid = atol(bstr("msgid"));
460 if (!strcasecmp(bstr("yesno"), "Yes")) {
461 sprintf(buf, "DELE %ld", msgid);
464 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
466 wprintf("<EM>Message not deleted.</EM><BR>\n");
476 * Confirm move of a message
478 void confirm_move_msg(void)
484 msgid = atol(bstr("msgid"));
488 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
489 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
490 wprintf("<B>Confirm move of message</B>\n");
491 wprintf("</FONT></TD></TR></TABLE>\n");
495 wprintf("Please select the room to which you would like this message moved:<BR>\n");
497 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
498 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
502 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
506 while (serv_gets(buf), strcmp(buf, "000")) {
507 extract(targ, buf, 0);
513 wprintf("</SELECT>\n");
516 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
517 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
518 wprintf("</FORM></CENTER>\n");
520 wprintf("</CENTER>\n");
531 msgid = atol(bstr("msgid"));
535 if (!strcasecmp(bstr("yesno"), "Move")) {
536 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
539 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
541 wprintf("<EM>Message not deleted.</EM><BR>\n");