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 - ", WC->wc_roomname);
243 if (!strcmp(oper, "readnew")) {
244 strcpy(cmd, "MSGS NEW");
245 wprintf("new messages");
246 } else if (!strcmp(oper, "readold")) {
247 strcpy(cmd, "MSGS OLD");
248 wprintf("old messages");
250 strcpy(cmd, "MSGS ALL");
251 wprintf("all messages");
253 wprintf("</B></CENTER><BR>\n");
255 nummsgs = load_msg_ptrs(cmd);
257 if (!strcmp(oper, "readnew")) {
258 wprintf("<EM>No new messages in this room.</EM>\n");
259 } else if (!strcmp(oper, "readold")) {
260 wprintf("<EM>No old messages in this room.</EM>\n");
262 wprintf("<EM>This room is empty.</EM>\n");
266 for (a = 0; a < nummsgs; ++a) {
267 read_message(WC->msgarr[a], oper);
270 DONE:wDumpContent(1);
277 * Post message (or don't post message)
279 * Note regarding the "dont_post" variable:
280 * A random value (actually, it's just a timestamp) is inserted as a hidden
281 * field called "postseq" when the display_enter page is generated. This
282 * value is checked when posting, using the static variable dont_post. If a
283 * user attempts to post twice using the same dont_post value, the message is
284 * discarded. This prevents the accidental double-saving of the same message
285 * if the user happens to click the browser "back" button.
287 void post_message(void)
290 static long dont_post = (-1L);
294 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
295 strcpy(buf, bstr("sc"));
296 if (strcasecmp(buf, "Save message")) {
297 wprintf("Cancelled. Message was not posted.<BR>\n");
298 } else if (atol(bstr("postseq")) == dont_post) {
299 wprintf("Automatically cancelled because you have already "
300 "saved this message.<BR>\n");
302 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
306 text_to_server(bstr("msgtext"));
308 wprintf("Message has been posted.<BR>\n");
309 dont_post = atol(bstr("postseq"));
311 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
326 * prompt for a recipient (to be called from display_enter() only)
328 void prompt_for_recipient()
331 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
332 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
333 wprintf("<B>Send private e-mail</B>\n");
334 wprintf("</FONT></TD></TR></TABLE>\n");
337 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
338 wprintf("Enter recipient: ");
339 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
340 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
341 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
342 wprintf("</FORM></CENTER>\n");
348 * display the message entry screen
350 void display_enter(void)
358 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
360 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
364 if (!strncmp(buf, "570", 3)) {
365 if (strlen(bstr("recp")) > 0) {
366 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
368 prompt_for_recipient();
372 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
375 wprintf("<CENTER>Enter message below. Messages are formatted to\n");
376 wprintf("the <EM>reader's</EM> screen width. To defeat the\n");
377 wprintf("formatting, indent a line at least one space. \n");
381 tm = (struct tm *) localtime(&now);
382 strcpy(buf, (char *) asctime(tm));
383 buf[strlen(buf) - 1] = 0;
384 strcpy(&buf[16], &buf[19]);
385 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
386 wprintf("from %s ", WC->wc_username);
387 if (strlen(bstr("recp")) > 0)
388 wprintf("to %s ", bstr("recp"));
389 wprintf("in %s> ", WC->wc_roomname);
390 wprintf("</B></FONT><BR><CENTER>\n");
392 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
393 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
395 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
397 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
398 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
400 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
401 "WIDTH=80></TEXTAREA><P>\n");
403 wprintf("</FORM></CENTER>\n");
404 DONE: wDumpContent(1);
416 * Confirm deletion of a message
418 void confirm_delete_msg(void)
422 msgid = atol(bstr("msgid"));
426 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
427 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
428 wprintf("<B>Confirm deletion of message</B>\n");
429 wprintf("</FONT></TD></TR></TABLE>\n");
433 wprintf("Are you sure you want to delete this message? <BR>\n");
435 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
436 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
438 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
439 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
440 wprintf("</FORM></CENTER>\n");
442 wprintf("</CENTER>\n");
448 void delete_msg(void)
453 msgid = atol(bstr("msgid"));
457 if (!strcasecmp(bstr("yesno"), "Yes")) {
458 sprintf(buf, "DELE %ld", msgid);
461 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
463 wprintf("<EM>Message not deleted.</EM><BR>\n");
473 * Confirm move of a message
475 void confirm_move_msg(void)
481 msgid = atol(bstr("msgid"));
485 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
486 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
487 wprintf("<B>Confirm move of message</B>\n");
488 wprintf("</FONT></TD></TR></TABLE>\n");
492 wprintf("Please select the room to which you would like this message moved:<BR>\n");
494 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
495 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
499 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
503 while (serv_gets(buf), strcmp(buf, "000")) {
504 extract(targ, buf, 0);
510 wprintf("</SELECT>\n");
513 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
514 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
515 wprintf("</FORM></CENTER>\n");
517 wprintf("</CENTER>\n");
528 msgid = atol(bstr("msgid"));
532 if (!strcasecmp(bstr("yesno"), "Move")) {
533 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
536 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
538 wprintf("<EM>Message not deleted.</EM><BR>\n");