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 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 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)
278 int num_displayed = 0;
280 startmsg = atol(bstr("startmsg"));
281 maxmsgs = atoi(bstr("maxmsgs"));
282 if (maxmsgs == 0) maxmsgs = 20;
286 /* wprintf("<CENTER><B>%s - ",
288 if (!strcmp(oper, "readnew")) {
289 strcpy(cmd, "MSGS NEW");
290 /* wprintf("new messages"); */
291 } else if (!strcmp(oper, "readold")) {
292 strcpy(cmd, "MSGS OLD");
293 /* wprintf("old messages"); */
295 strcpy(cmd, "MSGS ALL");
296 /* wprintf("all messages"); */
298 /* wprintf("</B></CENTER><BR>\n"); */
300 nummsgs = load_msg_ptrs(cmd);
302 if (!strcmp(oper, "readnew")) {
303 wprintf("<EM>No new messages in this room.</EM>\n");
304 } else if (!strcmp(oper, "readold")) {
305 wprintf("<EM>No old messages in this room.</EM>\n");
307 wprintf("<EM>This room is empty.</EM>\n");
312 for (a = 0; a < nummsgs; ++a) {
313 if (WC->msgarr[a] >= startmsg) {
314 read_message(WC->msgarr[a], oper);
316 if ( (num_displayed >= maxmsgs) && (a < nummsgs) ) {
317 wprintf("<CENTER><FONT SIZE=+1>"
318 "There are %d more messages here."
319 " </FONT>",
320 nummsgs - num_displayed);
321 wprintf("<A HREF=\"/readfwd?startmsg=%ld"
324 "</A> ",
326 wprintf("<A HREF=\"/readfwd?startmsg=%ld"
330 WC->msgarr[a+1], maxmsgs, maxmsgs);
331 wprintf("</CENTER><HR>\n");
337 DONE: wDumpContent(1);
344 * Post message (or don't post message)
346 * Note regarding the "dont_post" variable:
347 * A random value (actually, it's just a timestamp) is inserted as a hidden
348 * field called "postseq" when the display_enter page is generated. This
349 * value is checked when posting, using the static variable dont_post. If a
350 * user attempts to post twice using the same dont_post value, the message is
351 * discarded. This prevents the accidental double-saving of the same message
352 * if the user happens to click the browser "back" button.
354 void post_message(void)
357 static long dont_post = (-1L);
361 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
362 strcpy(buf, bstr("sc"));
363 if (strcasecmp(buf, "Save message")) {
364 wprintf("Cancelled. Message was not posted.<BR>\n");
365 } else if (atol(bstr("postseq")) == dont_post) {
366 wprintf("Automatically cancelled because you have already "
367 "saved this message.<BR>\n");
369 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
373 text_to_server(bstr("msgtext"));
375 wprintf("Message has been posted.<BR>\n");
376 dont_post = atol(bstr("postseq"));
378 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
393 * prompt for a recipient (to be called from display_enter() only)
395 void prompt_for_recipient()
398 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
399 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
400 wprintf("<B>Send private e-mail</B>\n");
401 wprintf("</FONT></TD></TR></TABLE>\n");
404 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
405 wprintf("Enter recipient: ");
406 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
407 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
408 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
409 wprintf("</FORM></CENTER>\n");
415 * display the message entry screen
417 void display_enter(void)
425 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
427 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
431 if (!strncmp(buf, "570", 3)) {
432 if (strlen(bstr("recp")) > 0) {
433 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
435 prompt_for_recipient();
439 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
444 tm = (struct tm *) localtime(&now);
445 strcpy(buf, (char *) asctime(tm));
446 buf[strlen(buf) - 1] = 0;
447 strcpy(&buf[16], &buf[19]);
448 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
449 wprintf("from %s ", WC->wc_username);
450 if (strlen(bstr("recp")) > 0)
451 wprintf("to %s ", bstr("recp"));
452 wprintf("in %s> ", WC->wc_roomname);
453 wprintf("</B></FONT><BR><CENTER>\n");
455 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
456 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
458 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
460 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
461 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
463 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
464 "WIDTH=80></TEXTAREA><P>\n");
466 wprintf("</FORM></CENTER>\n");
467 DONE: wDumpContent(1);
478 * Confirm deletion of a message
480 void confirm_delete_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 deletion of message</B>\n");
491 wprintf("</FONT></TD></TR></TABLE>\n");
495 wprintf("Are you sure you want to delete this message? <BR>\n");
497 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
498 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
500 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
501 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
502 wprintf("</FORM></CENTER>\n");
504 wprintf("</CENTER>\n");
510 void delete_msg(void)
515 msgid = atol(bstr("msgid"));
519 if (!strcasecmp(bstr("yesno"), "Yes")) {
520 sprintf(buf, "DELE %ld", msgid);
523 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
525 wprintf("<EM>Message not deleted.</EM><BR>\n");
535 * Confirm move of a message
537 void confirm_move_msg(void)
543 msgid = atol(bstr("msgid"));
547 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
548 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
549 wprintf("<B>Confirm move of message</B>\n");
550 wprintf("</FONT></TD></TR></TABLE>\n");
554 wprintf("Please select the room to which you would like this message moved:<BR>\n");
556 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
557 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
561 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
565 while (serv_gets(buf), strcmp(buf, "000")) {
566 extract(targ, buf, 0);
572 wprintf("</SELECT>\n");
575 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
576 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
577 wprintf("</FORM></CENTER>\n");
579 wprintf("</CENTER>\n");
590 msgid = atol(bstr("msgid"));
594 if (!strcasecmp(bstr("yesno"), "Move")) {
595 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
598 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
600 wprintf("<EM>Message not deleted.</EM><BR>\n");