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)
243 wprintf("HTTP/1.0 200 OK\n");
246 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ", WC->wc_roomname);
247 if (!strcmp(oper, "readnew")) {
248 strcpy(cmd, "MSGS NEW");
249 wprintf("new messages");
250 } else if (!strcmp(oper, "readold")) {
251 strcpy(cmd, "MSGS OLD");
252 wprintf("old messages");
254 strcpy(cmd, "MSGS ALL");
255 wprintf("all messages");
257 wprintf("</B></CENTER><BR>\n");
259 nummsgs = load_msg_ptrs(cmd);
261 if (!strcmp(oper, "readnew")) {
262 wprintf("<EM>No new messages in this room.</EM>\n");
263 } else if (!strcmp(oper, "readold")) {
264 wprintf("<EM>No old messages in this room.</EM>\n");
266 wprintf("<EM>This room is empty.</EM>\n");
270 for (a = 0; a < nummsgs; ++a) {
271 read_message(msgarr[a], oper);
274 DONE:wDumpContent(1);
281 * Post message (or don't post message)
283 * Note regarding the "dont_post" variable:
284 * A random value (actually, it's just a timestamp) is inserted as a hidden
285 * field called "postseq" when the display_enter page is generated. This
286 * value is checked when posting, using the static variable dont_post. If a
287 * user attempts to post twice using the same dont_post value, the message is
288 * discarded. This prevents the accidental double-saving of the same message
289 * if the user happens to click the browser "back" button.
291 void post_message(void)
294 static long dont_post = (-1L);
296 wprintf("HTTP/1.0 200 OK\n");
299 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
300 strcpy(buf, bstr("sc"));
301 if (strcasecmp(buf, "Save message")) {
302 wprintf("Cancelled. Message was not posted.<BR>\n");
303 } else if (atol(bstr("postseq")) == dont_post) {
304 wprintf("Automatically cancelled because you have already "
305 "saved this message.<BR>\n");
307 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
311 text_to_server(bstr("msgtext"));
313 wprintf("Message has been posted.<BR>\n");
314 dont_post = atol(bstr("postseq"));
316 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
331 * prompt for a recipient (to be called from display_enter() only)
333 void prompt_for_recipient()
336 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
337 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
338 wprintf("<B>Send private e-mail</B>\n");
339 wprintf("</FONT></TD></TR></TABLE>\n");
342 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
343 wprintf("Enter recipient: ");
344 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
345 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
346 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
347 wprintf("</FORM></CENTER>\n");
353 * display the message entry screen
355 void display_enter(void)
361 wprintf("HTTP/1.0 200 OK\n");
364 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
366 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
370 if (!strncmp(buf, "570", 3)) {
371 if (strlen(bstr("recp")) > 0) {
372 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
374 prompt_for_recipient();
378 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
381 wprintf("<CENTER>Enter message below. Messages are formatted to\n");
382 wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
383 wprintf("formatting, indent a line at least one space. \n");
387 tm = (struct tm *) localtime(&now);
388 strcpy(buf, (char *) asctime(tm));
389 buf[strlen(buf) - 1] = 0;
390 strcpy(&buf[16], &buf[19]);
391 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
392 wprintf("from %s ", WC->wc_username);
393 if (strlen(bstr("recp")) > 0)
394 wprintf("to %s ", bstr("recp"));
395 wprintf("in %s> ", WC->wc_roomname);
396 wprintf("</B></FONT><BR><CENTER>\n");
398 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
399 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
401 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
403 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
404 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
406 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
407 "WIDTH=80></TEXTAREA><P>\n");
409 wprintf("</FORM></CENTER>\n");
410 DONE: wDumpContent(1);
422 * Confirm deletion of a message
424 void confirm_delete_msg(void)
428 msgid = atol(bstr("msgid"));
430 wprintf("HTTP/1.0 200 OK\n");
433 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
434 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
435 wprintf("<B>Confirm deletion of message</B>\n");
436 wprintf("</FONT></TD></TR></TABLE>\n");
440 wprintf("Are you sure you want to delete this message? <BR>\n");
442 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
443 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
445 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
446 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
447 wprintf("</FORM></CENTER>\n");
449 wprintf("</CENTER>\n");
455 void delete_msg(void)
460 msgid = atol(bstr("msgid"));
462 wprintf("HTTP/1.0 200 OK\n");
465 if (!strcasecmp(bstr("yesno"), "Yes")) {
466 sprintf(buf, "DELE %ld", msgid);
469 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
471 wprintf("<EM>Message not deleted.</EM><BR>\n");
481 * Confirm move of a message
483 void confirm_move_msg(void)
489 msgid = atol(bstr("msgid"));
491 wprintf("HTTP/1.0 200 OK\n");
494 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
495 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
496 wprintf("<B>Confirm move of message</B>\n");
497 wprintf("</FONT></TD></TR></TABLE>\n");
501 wprintf("Please select the room to which you would like this message moved:<BR>\n");
503 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
504 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
508 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
512 while (serv_gets(buf), strcmp(buf, "000")) {
513 extract(targ, buf, 0);
519 wprintf("</SELECT>\n");
522 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
523 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
524 wprintf("</FORM></CENTER>\n");
526 wprintf("</CENTER>\n");
537 msgid = atol(bstr("msgid"));
539 wprintf("HTTP/1.0 200 OK\n");
542 if (!strcasecmp(bstr("yesno"), "Move")) {
543 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
546 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
548 wprintf("<EM>Message not deleted.</EM><BR>\n");