00001
00002
00003
00009 #include "webcit.h"
00010
00014 void display_page(void)
00015 {
00016 char recp[SIZ];
00017
00018 strcpy(recp, bstr("recp"));
00019
00020 output_headers(1, 1, 2, 0, 0, 0);
00021 wprintf("<div id=\"banner\">\n"
00022 "<TABLE class=\"paging_banner\"><TR><TD>"
00023 "<SPAN CLASS=\"titlebar\">");
00024 wprintf(_("Send instant message"));
00025 wprintf("</SPAN>"
00026 "</TD></TR></TABLE>\n"
00027 "</div>\n<div id=\"content\">\n"
00028 );
00029
00030 wprintf("<div class=\"fix_scrollbar_bug\">"
00031 "<table class=\"paging_background\"><tr><td>\n");
00032
00033 wprintf(_("Send an instant message to: "));
00034 escputs(recp);
00035 wprintf("<br>\n");
00036
00037 wprintf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
00038
00039 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
00040
00041 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
00042 escputs(recp);
00043 wprintf("\">\n");
00044
00045 wprintf(_("Enter message text:"));
00046 wprintf("<br />");
00047
00048 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
00049 "WIDTH=40></TEXTAREA>\n");
00050
00051 wprintf("</TD></TR></TABLE><br />\n");
00052
00053 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
00054 wprintf("<br /><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
00055
00056 wprintf("</FORM></CENTER>\n");
00057 wprintf("</td></tr></table></div>\n");
00058 wDumpContent(1);
00059 }
00060
00064 void page_user(void)
00065 {
00066 char recp[256];
00067 char buf[256];
00068
00069 safestrncpy(recp, bstr("recp"), sizeof recp);
00070
00071 if (strlen(bstr("send_button")) == 0) {
00072 safestrncpy(WC->ImportantMessage,
00073 _("Message was not sent."),
00074 sizeof WC->ImportantMessage
00075 );
00076 } else {
00077 serv_printf("SEXP %s|-", recp);
00078 serv_getln(buf, sizeof buf);
00079
00080 if (buf[0] == '4') {
00081 text_to_server(bstr("msgtext"));
00082 serv_puts("000");
00083 stresc(buf, recp, 0, 0);
00084 snprintf(WC->ImportantMessage,
00085 sizeof WC->ImportantMessage,
00086 "%s%s.",
00087 _("Message has been sent to "),
00088 buf
00089 );
00090 }
00091 else {
00092 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
00093 }
00094 }
00095
00096 who();
00097 }
00098
00099
00100
00104 void do_chat(void)
00105 {
00106 char buf[SIZ];
00107
00109 serv_printf("GOTO %s", WC->wc_roomname);
00110 serv_getln(buf, sizeof buf);
00111 if (buf[0] != '2') {
00112 smart_goto("_BASEROOM_");
00113 return;
00114 }
00115
00120 if (WC->chat_sock < 0) {
00121 close(WC->chat_sock);
00122 WC->chat_sock = (-1);
00123 }
00124
00130 begin_ajax_response();
00131 do_template("chatframeset");
00132 end_ajax_response();
00133 return;
00134 }
00135
00136
00142 void page_popup(void)
00143 {
00144 char buf[SIZ];
00145
00147 wprintf("<script type=\"text/javascript\"> "
00148 "function PopUpFailed() { "
00149 " alert(\"%s\"); "
00150 "} "
00151 "</script>\n",
00152 _("You have one or more instant messages waiting, but the Citadel Instant Messenger "
00153 "window failed to open. This is probably because you have a popup blocker "
00154 "installed. Please configure your popup blocker to allow popups from this site "
00155 "if you wish to receive instant messages.")
00156 );
00157
00159 serv_puts("NOOP");
00160 serv_getln(buf, sizeof buf);
00161 if (buf[3] == '*') {
00162 if ((time(NULL) - WC->last_pager_check) > 60) {
00163 wprintf("<script type=\"text/javascript\">"
00164 " var oWin = window.open('static/instant_messenger.html', "
00165 " 'CTDL_MESSENGER', 'width=700,height=400'); "
00166 " if (oWin==null || typeof(oWin)==\"undefined\") { "
00167 " PopUpFailed(); "
00168 " } "
00169 "</script>"
00170 );
00171 }
00172 }
00173
00175 wprintf("<script type=\"text/javascript\"> "
00176 " function HandleSslp(sslg_xmlresponse) { "
00177 " sslg_response = sslg_xmlresponse.responseText.substr(0, 1); "
00178 " if (sslg_response == 'Y') { "
00179 " var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
00180 " 'width=700,height=400'); "
00181 " if (oWin==null || typeof(oWin)==\"undefined\") { "
00182 " PopUpFailed(); "
00183 " } "
00184 " } "
00185 " } "
00186 " function CheckPager() { "
00187 " new Ajax.Request('sslg', { method: 'get', parameters: CtdlRandomString(), "
00188 " onSuccess: HandleSslp } ); "
00189 " } "
00190 " new PeriodicalExecuter(CheckPager, 30); "
00191 "</script> "
00192 );
00193 }
00194
00195
00196
00202 int setup_chat_socket(void) {
00203 char buf[SIZ];
00204 int i;
00205 int good_chatmode = 0;
00206
00207 if (WC->chat_sock < 0) {
00208
00209 if (!strcasecmp(ctdlhost, "uds")) {
00211 sprintf(buf, "%s/citadel.socket", ctdlport);
00212 WC->chat_sock = uds_connectsock(buf);
00213 }
00214 else {
00216 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
00217 }
00218
00219 if (WC->chat_sock < 0) {
00220 return(errno);
00221 }
00222
00224 i = WC->serv_sock;
00225 WC->serv_sock = WC->chat_sock;
00226 WC->chat_sock = i;
00227
00228 serv_getln(buf, sizeof buf);
00229 if (buf[0] == '2') {
00230 serv_printf("USER %s", WC->wc_username);
00231 serv_getln(buf, sizeof buf);
00232 if (buf[0] == '3') {
00233 serv_printf("PASS %s", WC->wc_password);
00234 serv_getln(buf, sizeof buf);
00235 if (buf[0] == '2') {
00236 serv_printf("GOTO %s", WC->wc_roomname);
00237 serv_getln(buf, sizeof buf);
00238 if (buf[0] == '2') {
00239 serv_puts("CHAT");
00240 serv_getln(buf, sizeof buf);
00241 if (buf[0] == '8') {
00242 good_chatmode = 1;
00243 }
00244 }
00245 }
00246 }
00247 }
00248
00250 i = WC->serv_sock;
00251 WC->serv_sock = WC->chat_sock;
00252 WC->chat_sock = i;
00253
00254 if (!good_chatmode) close(WC->serv_sock);
00255
00256 }
00257 return(0);
00258 }
00259
00260
00261
00268 void chat_recv(void) {
00269 int i;
00270 struct pollfd pf;
00271 int got_data = 0;
00272 int end_chat_now = 0;
00273 char buf[SIZ];
00274 char cl_user[SIZ];
00275 char cl_text[SIZ];
00276 char *output_data = NULL;
00277
00278 output_headers(0, 0, 0, 0, 0, 0);
00279
00280 wprintf("Content-type: text/html; charset=utf-8\n");
00281 wprintf("\n");
00282 wprintf("<html>\n"
00283 "<head>\n"
00284 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
00285 "</head>\n"
00286
00287 "<body bgcolor=\"#FFFFFF\">\n"
00288 );
00289
00290 if (setup_chat_socket() != 0) {
00291 wprintf(_("An error occurred while setting up the chat socket."));
00292 wprintf("</BODY></HTML>\n");
00293 wDumpContent(0);
00294 return;
00295 }
00296
00300 output_data = strdup("");
00301 do {
00302 got_data = 0;
00303 pf.fd = WC->chat_sock;
00304 pf.events = POLLIN;
00305 pf.revents = 0;
00306 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
00307 ++got_data;
00308
00310 i = WC->serv_sock;
00311 WC->serv_sock = WC->chat_sock;
00312 WC->chat_sock = i;
00313
00314 serv_getln(buf, sizeof buf);
00315
00316 if (!strcmp(buf, "000")) {
00317 strcpy(buf, ":|");
00318 strcat(buf, _("Now exiting chat mode."));
00319 end_chat_now = 1;
00320 }
00321
00323 i = WC->serv_sock;
00324 WC->serv_sock = WC->chat_sock;
00325 WC->chat_sock = i;
00326
00328 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
00329 strcat(output_data, buf);
00330 strcat(output_data, "\n");
00331 }
00332
00333 } while ( (got_data) && (!end_chat_now) );
00334
00335 if (end_chat_now) {
00336 close(WC->chat_sock);
00337 WC->chat_sock = (-1);
00338 wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
00339 }
00340
00341 if (strlen(output_data) > 0) {
00342
00343 if (output_data[strlen(output_data)-1] == '\n') {
00344 output_data[strlen(output_data)-1] = 0;
00345 }
00346
00348 wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
00349 "onLoad=\" \n"
00350 );
00351
00352 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
00353 extract_token(buf, output_data, i, '\n', sizeof buf);
00354 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
00355 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
00356
00357 if (strcasecmp(cl_text, "NOOP")) {
00358
00359 wprintf("parent.chat_transcript.document.write('");
00360
00361 if (strcasecmp(cl_user, WC->last_chat_user)) {
00362 wprintf("<TABLE border=0 WIDTH=100%% "
00363 "CELLSPACING=1 CELLPADDING=0 "
00364 "BGCOLOR="#FFFFFF">"
00365 "<TR><TD></TR></TD></TABLE>"
00366 );
00367
00368 }
00369
00370 wprintf("<TABLE border=0 WIDTH=100%% "
00371 "CELLSPACING=0 CELLPADDING=0 "
00372 "BGCOLOR="#EEEEEE">");
00373
00374 wprintf("<TR><TD>");
00375
00376 if (!strcasecmp(cl_user, ":")) {
00377 wprintf("<I>");
00378 }
00379
00380 if (strcasecmp(cl_user, WC->last_chat_user)) {
00381 wprintf("<B>");
00382
00383 if (!strcasecmp(cl_user, WC->wc_fullname)) {
00384 wprintf("<FONT COLOR="#FF0000">");
00385 }
00386 else {
00387 wprintf("<FONT COLOR="#0000FF">");
00388 }
00389 jsescputs(cl_user);
00390
00391 wprintf("</FONT>: </B>");
00392 }
00393 else {
00394 wprintf(" ");
00395 }
00396 jsescputs(cl_text);
00397 if (!strcasecmp(cl_user, ":")) {
00398 wprintf("</I>");
00399 }
00400
00401 wprintf("</TD></TR></TABLE>");
00402 wprintf("'); \n");
00403
00404 strcpy(WC->last_chat_user, cl_user);
00405 }
00406 }
00407
00408 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
00409 }
00410
00411 free(output_data);
00412
00413 wprintf("</BODY></HTML>\n");
00414 wDumpContent(0);
00415 }
00416
00417
00421 void chat_send(void) {
00422 int i;
00423 char send_this[SIZ];
00424 char buf[SIZ];
00425
00426 output_headers(0, 0, 0, 0, 0, 0);
00427 wprintf("Content-type: text/html; charset=utf-8\n");
00428 wprintf("\n");
00429 wprintf("<HTML>"
00430 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
00431 );
00432
00433 if (bstr("send_this") != NULL) {
00434 strcpy(send_this, bstr("send_this"));
00435 }
00436 else {
00437 strcpy(send_this, "");
00438 }
00439
00440 if (strlen(bstr("help_button")) > 0) {
00441 strcpy(send_this, "/help");
00442 }
00443
00444 if (strlen(bstr("list_button")) > 0) {
00445 strcpy(send_this, "/who");
00446 }
00447
00448 if (strlen(bstr("exit_button")) > 0) {
00449 strcpy(send_this, "/quit");
00450 }
00451
00452 if (setup_chat_socket() != 0) {
00453 wprintf(_("An error occurred while setting up the chat socket."));
00454 wprintf("</BODY></HTML>\n");
00455 wDumpContent(0);
00456 return;
00457 }
00458
00460 i = WC->serv_sock;
00461 WC->serv_sock = WC->chat_sock;
00462 WC->chat_sock = i;
00463
00464 while (strlen(send_this) > 0) {
00465 if (strlen(send_this) < 67) {
00466 serv_puts(send_this);
00467 strcpy(send_this, "");
00468 }
00469 else {
00470 for (i=55; i<67; ++i) {
00471 if (send_this[i] == ' ') break;
00472 }
00473 strncpy(buf, send_this, i);
00474 buf[i] = 0;
00475 strcpy(send_this, &send_this[i]);
00476 serv_puts(buf);
00477 }
00478 }
00479
00481 i = WC->serv_sock;
00482 WC->serv_sock = WC->chat_sock;
00483 WC->chat_sock = i;
00484
00485 wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
00486 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
00487 "NAME=\"send_this\">\n", SIZ-10);
00488 wprintf("<br />");
00489 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
00490 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
00491 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
00492 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
00493 wprintf("</FORM>\n");
00494
00495 wprintf("</BODY></HTML>\n");
00496 wDumpContent(0);
00497 }
00498