11 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <netinet/in.h>
30 * Look for URL's embedded in a buffer and make them linkable. We use a
31 * target window in order to keep the BBS session in its own window.
47 for (pos = 0; pos < strlen(buf); ++pos) {
48 if (!strncasecmp(&buf[pos], "http://", 7))
50 if (!strncasecmp(&buf[pos], "ftp://", 6))
57 if ((start > 0) && (buf[start - 1] == '<'))
59 if ((start > 0) && (buf[start - 1] == '['))
61 if ((start > 0) && (buf[start - 1] == '('))
63 if ((start > 0) && (buf[start - 1] == '{'))
66 for (pos = strlen(buf); pos > start; --pos) {
67 if ((buf[pos] == ' ') || (buf[pos] == ench))
71 strncpy(urlbuf, &buf[start], end - start);
72 urlbuf[end - start] = 0;
75 strncpy(outbuf, buf, start);
76 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
77 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
78 strcat(outbuf, &buf[end]);
79 if ( strlen(outbuf) < 250 )
84 void read_message(msgnum, oper)
102 strcpy(reply_to, "");
104 sprintf(buf, "MSG0 %ld", msgnum);
108 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
111 wprintf("<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=000077><TR><TD>\n");
112 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFF00\"> ");
113 strcpy(m_subject, "");
115 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
116 if (!strncasecmp(buf, "nhdr=yes", 8))
120 if (!strncasecmp(buf, "type=", 5))
121 format_type = atoi(&buf[5]);
122 if (!strncasecmp(buf, "from=", 5)) {
123 strcpy(from, &buf[5]);
128 if (!strncasecmp(buf, "subj=", 5))
129 strcpy(m_subject, &buf[5]);
130 if ((!strncasecmp(buf, "hnod=", 5))
131 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
132 wprintf("(%s) ", &buf[5]);
133 if ((!strncasecmp(buf, "room=", 5))
134 && (strcasecmp(&buf[5], WC->wc_roomname)))
135 wprintf("in %s> ", &buf[5]);
136 if (!strncasecmp(buf, "rfca=", 5)) {
137 strcpy(rfca, &buf[5]);
143 if (!strncasecmp(buf, "node=", 5)) {
144 if ( ((WC->room_flags & QR_NETWORK)
145 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
146 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
149 wprintf("@%s ", &buf[5]);
152 if (!strncasecmp(buf, "rcpt=", 5))
153 wprintf("to %s ", &buf[5]);
154 if (!strncasecmp(buf, "time=", 5)) {
155 fmt_date(now, atol(&buf[5]));
161 /* Generate a reply-to address */
162 if (strlen(rfca) > 0) {
163 strcpy(reply_to, rfca);
166 if (strlen(node) > 0) {
167 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
171 snprintf(reply_to, sizeof(reply_to), "%s", from);
177 wprintf("</FONT></TD>");
179 /* begin right-hand toolbar */
180 wprintf("<TD ALIGN=RIGHT>\n"
181 "<TABLE BORDER=0><TR>\n");
183 wprintf("<TD BGCOLOR=\"AAAADD\">"
184 "<A HREF=\"/display_enter?recp=");
185 urlescputs(reply_to);
186 wprintf("\">Reply</A>"
189 if (WC->is_room_aide) {
190 wprintf("<TD BGCOLOR=\"AAAADD\">"
191 "<A HREF=\"/confirm_move_msg"
196 wprintf("<TD BGCOLOR=\"AAAADD\">"
197 "<A HREF=\"/confirm_delete_msg"
204 wprintf("</TR></TABLE>\n"
207 /* end right-hand toolbar */
210 if (strlen(m_subject) > 0) {
211 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
213 "</TD><TD> </TD></TR>\n", m_subject);
216 wprintf("</TR></TABLE>\n");
218 if (format_type == 0) {
221 while (serv_gets(buf), strcmp(buf, "000")) {
222 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
223 buf[strlen(buf) - 1] = 0;
225 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
226 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"000044\"><I>");
228 } else if ((bq == 1) &&
229 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
230 wprintf("</FONT></I>");
236 wprintf("</TT><BR>\n");
245 * load message pointers from the server
247 int load_msg_ptrs(servcmd)
257 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
260 while (serv_gets(buf), strcmp(buf, "000")) {
261 WC->msgarr[nummsgs] = atol(buf);
269 * command loop for reading messages
271 void readloop(char *oper)
279 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ",
281 if (!strcmp(oper, "readnew")) {
282 strcpy(cmd, "MSGS NEW");
283 wprintf("new messages");
284 } else if (!strcmp(oper, "readold")) {
285 strcpy(cmd, "MSGS OLD");
286 wprintf("old messages");
288 strcpy(cmd, "MSGS ALL");
289 wprintf("all messages");
291 wprintf("</B></CENTER><BR>\n");
293 nummsgs = load_msg_ptrs(cmd);
295 if (!strcmp(oper, "readnew")) {
296 wprintf("<EM>No new messages in this room.</EM>\n");
297 } else if (!strcmp(oper, "readold")) {
298 wprintf("<EM>No old messages in this room.</EM>\n");
300 wprintf("<EM>This room is empty.</EM>\n");
304 for (a = 0; a < nummsgs; ++a) {
305 read_message(WC->msgarr[a], oper);
308 DONE: wDumpContent(1);
315 * Post message (or don't post message)
317 * Note regarding the "dont_post" variable:
318 * A random value (actually, it's just a timestamp) is inserted as a hidden
319 * field called "postseq" when the display_enter page is generated. This
320 * value is checked when posting, using the static variable dont_post. If a
321 * user attempts to post twice using the same dont_post value, the message is
322 * discarded. This prevents the accidental double-saving of the same message
323 * if the user happens to click the browser "back" button.
325 void post_message(void)
328 static long dont_post = (-1L);
332 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
333 strcpy(buf, bstr("sc"));
334 if (strcasecmp(buf, "Save message")) {
335 wprintf("Cancelled. Message was not posted.<BR>\n");
336 } else if (atol(bstr("postseq")) == dont_post) {
337 wprintf("Automatically cancelled because you have already "
338 "saved this message.<BR>\n");
340 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
344 text_to_server(bstr("msgtext"));
346 wprintf("Message has been posted.<BR>\n");
347 dont_post = atol(bstr("postseq"));
349 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
364 * prompt for a recipient (to be called from display_enter() only)
366 void prompt_for_recipient()
369 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
370 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
371 wprintf("<B>Send private e-mail</B>\n");
372 wprintf("</FONT></TD></TR></TABLE>\n");
375 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
376 wprintf("Enter recipient: ");
377 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
378 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
379 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
380 wprintf("</FORM></CENTER>\n");
386 * display the message entry screen
388 void display_enter(void)
396 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
398 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
402 if (!strncmp(buf, "570", 3)) {
403 if (strlen(bstr("recp")) > 0) {
404 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
406 prompt_for_recipient();
410 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
413 wprintf("<CENTER>Enter message below. Messages are formatted to\n");
414 wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
415 wprintf("formatting, indent a line at least one space. \n");
419 tm = (struct tm *) localtime(&now);
420 strcpy(buf, (char *) asctime(tm));
421 buf[strlen(buf) - 1] = 0;
422 strcpy(&buf[16], &buf[19]);
423 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
424 wprintf("from %s ", WC->wc_username);
425 if (strlen(bstr("recp")) > 0)
426 wprintf("to %s ", bstr("recp"));
427 wprintf("in %s> ", WC->wc_roomname);
428 wprintf("</B></FONT><BR><CENTER>\n");
430 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
431 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
433 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
435 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
436 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
438 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
439 "WIDTH=80></TEXTAREA><P>\n");
441 wprintf("</FORM></CENTER>\n");
442 DONE: wDumpContent(1);
453 * Confirm deletion of a message
455 void confirm_delete_msg(void)
459 msgid = atol(bstr("msgid"));
463 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
464 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
465 wprintf("<B>Confirm deletion of message</B>\n");
466 wprintf("</FONT></TD></TR></TABLE>\n");
470 wprintf("Are you sure you want to delete this message? <BR>\n");
472 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
473 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
475 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
476 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
477 wprintf("</FORM></CENTER>\n");
479 wprintf("</CENTER>\n");
485 void delete_msg(void)
490 msgid = atol(bstr("msgid"));
494 if (!strcasecmp(bstr("yesno"), "Yes")) {
495 sprintf(buf, "DELE %ld", msgid);
498 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
500 wprintf("<EM>Message not deleted.</EM><BR>\n");
510 * Confirm move of a message
512 void confirm_move_msg(void)
518 msgid = atol(bstr("msgid"));
522 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
523 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
524 wprintf("<B>Confirm move of message</B>\n");
525 wprintf("</FONT></TD></TR></TABLE>\n");
529 wprintf("Please select the room to which you would like this message moved:<BR>\n");
531 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
532 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
536 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
540 while (serv_gets(buf), strcmp(buf, "000")) {
541 extract(targ, buf, 0);
547 wprintf("</SELECT>\n");
550 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
551 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
552 wprintf("</FORM></CENTER>\n");
554 wprintf("</CENTER>\n");
565 msgid = atol(bstr("msgid"));
569 if (!strcasecmp(bstr("yesno"), "Move")) {
570 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
573 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
575 wprintf("<EM>Message not deleted.</EM><BR>\n");