11 #include <sys/types.h>
13 #include <sys/socket.h>
16 #include <netinet/in.h>
31 * Look for URL's embedded in a buffer and make them linkable. We use a
32 * target window in order to keep the BBS session in its own window.
48 for (pos = 0; pos < strlen(buf); ++pos) {
49 if (!strncasecmp(&buf[pos], "http://", 7))
51 if (!strncasecmp(&buf[pos], "ftp://", 6))
58 if ((start > 0) && (buf[start - 1] == '<'))
60 if ((start > 0) && (buf[start - 1] == '['))
62 if ((start > 0) && (buf[start - 1] == '('))
64 if ((start > 0) && (buf[start - 1] == '{'))
67 for (pos = strlen(buf); pos > start; --pos) {
68 if ((buf[pos] == ' ') || (buf[pos] == ench))
72 strncpy(urlbuf, &buf[start], end - start);
73 urlbuf[end - start] = 0;
76 strncpy(outbuf, buf, start);
77 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
78 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
79 strcat(outbuf, &buf[end]);
80 if ( strlen(outbuf) < 250 )
85 void read_message(msgnum, oper)
98 sprintf(buf, "MSG0 %ld", msgnum);
102 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
105 wprintf("<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=000077><TR><TD>\n");
106 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFF00\"> ");
107 strcpy(m_subject, "");
109 strcpy(WC->reply_to, "nobody...xxxxx");
110 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
111 if (!strncasecmp(buf, "nhdr=yes", 8))
115 if (!strncasecmp(buf, "type=", 5))
116 format_type = atoi(&buf[5]);
117 if (!strncasecmp(buf, "from=", 5)) {
118 wprintf("from %s ", &buf[5]);
119 strcpy(from, &buf[5]);
121 if (!strncasecmp(buf, "path=", 5))
122 strcpy(WC->reply_to, &buf[5]);
123 if (!strncasecmp(buf, "subj=", 5))
124 strcpy(m_subject, &buf[5]);
125 if ((!strncasecmp(buf, "hnod=", 5))
126 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
127 wprintf("(%s) ", &buf[5]);
128 if ((!strncasecmp(buf, "room=", 5))
129 && (strcasecmp(&buf[5], WC->wc_roomname)))
130 wprintf("in %s> ", &buf[5]);
132 if (!strncasecmp(buf, "node=", 5)) {
133 if ((WC->room_flags & QR_NETWORK)
134 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
135 && (strcasecmp(&buf[5], serv_info.serv_fqdn))))) {
136 wprintf("@%s ", &buf[5]);
138 if ((!strcasecmp(&buf[5], serv_info.serv_nodename))
139 || (!strcasecmp(&buf[5], serv_info.serv_fqdn))) {
140 strcpy(WC->reply_to, from);
141 } else if (haschar(&buf[5], '.') == 0) {
142 sprintf(WC->reply_to, "%s @ %s", from, &buf[5]);
145 if (!strncasecmp(buf, "rcpt=", 5))
146 wprintf("to %s ", &buf[5]);
147 if (!strncasecmp(buf, "time=", 5)) {
149 tm = (struct tm *) localtime(&now);
150 strcpy(buf, (char *) asctime(tm));
151 buf[strlen(buf) - 1] = 0;
152 strcpy(&buf[16], &buf[19]);
153 wprintf("%s ", &buf[4]);
159 wprintf("</FONT></TD>");
161 if (WC->is_room_aide) {
162 wprintf("<TD ALIGN=RIGHT NOWRAP><FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"FFFF00\"><B>");
164 wprintf("<A HREF=\"/confirm_move_msg");
165 wprintf("&msgid=%ld", msgnum);
166 wprintf("\">Move</A>");
168 wprintf(" ");
170 wprintf("<A HREF=\"/confirm_delete_msg");
171 wprintf("&msgid=%ld", msgnum);
172 wprintf("\">Del</A>");
174 wprintf("</B></FONT></TD>");
176 wprintf("</TR></TABLE>\n");
178 if (strlen(m_subject) > 0) {
179 wprintf("Subject: %s<BR>\n", m_subject);
181 if (format_type == 0) {
184 while (serv_gets(buf), strcmp(buf, "000")) {
185 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
186 buf[strlen(buf) - 1] = 0;
188 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
189 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" COLOR=\"000044\"><I>");
191 } else if ((bq == 1) &&
192 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
193 wprintf("</FONT></I>");
199 wprintf("</TT><BR>\n");
208 * load message pointers from the server
210 int load_msg_ptrs(servcmd)
220 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
223 while (serv_gets(buf), strcmp(buf, "000")) {
224 WC->msgarr[nummsgs] = atol(buf);
232 * command loop for reading messages
234 void readloop(char *oper)
242 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\"><CENTER><B>%s - ",
244 if (!strcmp(oper, "readnew")) {
245 strcpy(cmd, "MSGS NEW");
246 wprintf("new messages");
247 } else if (!strcmp(oper, "readold")) {
248 strcpy(cmd, "MSGS OLD");
249 wprintf("old messages");
251 strcpy(cmd, "MSGS ALL");
252 wprintf("all messages");
254 wprintf("</B></CENTER><BR>\n");
256 nummsgs = load_msg_ptrs(cmd);
258 if (!strcmp(oper, "readnew")) {
259 wprintf("<EM>No new messages in this room.</EM>\n");
260 } else if (!strcmp(oper, "readold")) {
261 wprintf("<EM>No old messages in this room.</EM>\n");
263 wprintf("<EM>This room is empty.</EM>\n");
267 for (a = 0; a < nummsgs; ++a) {
268 read_message(WC->msgarr[a], oper);
271 DONE: wDumpContent(1);
278 * Post message (or don't post message)
280 * Note regarding the "dont_post" variable:
281 * A random value (actually, it's just a timestamp) is inserted as a hidden
282 * field called "postseq" when the display_enter page is generated. This
283 * value is checked when posting, using the static variable dont_post. If a
284 * user attempts to post twice using the same dont_post value, the message is
285 * discarded. This prevents the accidental double-saving of the same message
286 * if the user happens to click the browser "back" button.
288 void post_message(void)
291 static long dont_post = (-1L);
295 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
296 strcpy(buf, bstr("sc"));
297 if (strcasecmp(buf, "Save message")) {
298 wprintf("Cancelled. Message was not posted.<BR>\n");
299 } else if (atol(bstr("postseq")) == dont_post) {
300 wprintf("Automatically cancelled because you have already "
301 "saved this message.<BR>\n");
303 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
307 text_to_server(bstr("msgtext"));
309 wprintf("Message has been posted.<BR>\n");
310 dont_post = atol(bstr("postseq"));
312 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
327 * prompt for a recipient (to be called from display_enter() only)
329 void prompt_for_recipient()
332 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
333 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
334 wprintf("<B>Send private e-mail</B>\n");
335 wprintf("</FONT></TD></TR></TABLE>\n");
338 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
339 wprintf("Enter recipient: ");
340 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
341 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
342 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
343 wprintf("</FORM></CENTER>\n");
349 * display the message entry screen
351 void display_enter(void)
359 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
361 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
365 if (!strncmp(buf, "570", 3)) {
366 if (strlen(bstr("recp")) > 0) {
367 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
369 prompt_for_recipient();
373 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
376 wprintf("<CENTER>Enter message below. Messages are formatted to\n");
377 wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
378 wprintf("formatting, indent a line at least one space. \n");
382 tm = (struct tm *) localtime(&now);
383 strcpy(buf, (char *) asctime(tm));
384 buf[strlen(buf) - 1] = 0;
385 strcpy(&buf[16], &buf[19]);
386 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
387 wprintf("from %s ", WC->wc_username);
388 if (strlen(bstr("recp")) > 0)
389 wprintf("to %s ", bstr("recp"));
390 wprintf("in %s> ", WC->wc_roomname);
391 wprintf("</B></FONT><BR><CENTER>\n");
393 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
394 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
396 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
398 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
399 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
401 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
402 "WIDTH=80></TEXTAREA><P>\n");
404 wprintf("</FORM></CENTER>\n");
405 DONE: wDumpContent(1);
417 * Confirm deletion of a message
419 void confirm_delete_msg(void)
423 msgid = atol(bstr("msgid"));
427 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
428 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
429 wprintf("<B>Confirm deletion of message</B>\n");
430 wprintf("</FONT></TD></TR></TABLE>\n");
434 wprintf("Are you sure you want to delete this message? <BR>\n");
436 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
437 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
439 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
440 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
441 wprintf("</FORM></CENTER>\n");
443 wprintf("</CENTER>\n");
449 void delete_msg(void)
454 msgid = atol(bstr("msgid"));
458 if (!strcasecmp(bstr("yesno"), "Yes")) {
459 sprintf(buf, "DELE %ld", msgid);
462 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
464 wprintf("<EM>Message not deleted.</EM><BR>\n");
474 * Confirm move of a message
476 void confirm_move_msg(void)
482 msgid = atol(bstr("msgid"));
486 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
487 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
488 wprintf("<B>Confirm move of message</B>\n");
489 wprintf("</FONT></TD></TR></TABLE>\n");
493 wprintf("Please select the room to which you would like this message moved:<BR>\n");
495 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
496 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
500 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
504 while (serv_gets(buf), strcmp(buf, "000")) {
505 extract(targ, buf, 0);
511 wprintf("</SELECT>\n");
514 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
515 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
516 wprintf("</FORM></CENTER>\n");
518 wprintf("</CENTER>\n");
529 msgid = atol(bstr("msgid"));
533 if (!strcasecmp(bstr("yesno"), "Move")) {
534 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
537 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
539 wprintf("<EM>Message not deleted.</EM><BR>\n");