Integrated the DKIM signer into serv_smtpclient, but disabled it
[citadel.git] / webcit / paging.c
1 // This module handles instant message related functions.
2 //
3 // Copyright (c) 1996-2023 by the citadel.org team
4 //
5 // This program is open source software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License, version 3.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12
13 #include "webcit.h"
14
15 // display the form for paging (x-messaging) another user
16 void display_page(void) {
17         char recp[SIZ];
18
19         strcpy(recp, bstr("recp"));
20
21         output_headers(1, 1, 1, 0, 0, 0);
22         wc_printf("<div id=\"room_banner_override\">\n");
23         wc_printf("<h1>");
24         wc_printf(_("Send instant message"));
25         wc_printf("</h1>");
26         wc_printf("</div>\n");
27
28         wc_printf("<div id=\"content\" class=\"service\">\n");
29
30         wc_printf("<table class=\"paging_background\"><tr><td>\n");
31
32         wc_printf(_("Send an instant message to: "));
33         escputs(recp);
34         wc_printf("<br>\n");
35
36         wc_printf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
37         wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
38         wc_printf("<input type=\"hidden\" name=\"template\" value=\"who\">\n");
39
40         wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
41
42         wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
43         escputs(recp);
44         wc_printf("\">\n");
45
46         wc_printf(_("Enter message text:"));
47         wc_printf("<br>");
48
49         wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
50                 "WIDTH=40></TEXTAREA>\n");
51
52         wc_printf("</TD></TR></TABLE><br>\n");
53
54         wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
55         wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
56
57         wc_printf("</FORM></CENTER>\n");
58         wc_printf("</td></tr></table>\n");
59         wDumpContent(1);
60 }
61
62
63 // page another user
64 void page_user(void) {
65         char recp[256];
66         StrBuf *Line;
67
68         safestrncpy(recp, bstr("recp"), sizeof recp);
69
70         if (!havebstr("send_button")) {
71                 AppendImportantMessage(_("Message was not sent."), -1);
72         }
73         else {
74                 Line = NewStrBuf();
75                 serv_printf("SEXP %s|-", recp);
76                 StrBuf_ServGetln(Line);
77                 if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
78                         char buf[256];
79                         text_to_server(bstr("msgtext"));
80                         serv_puts("000");
81                         stresc(buf, 256, recp, 0, 0);
82                         AppendImportantMessage(buf, -1);
83                         AppendImportantMessage(_("Message has been sent to "), -1);
84                 }
85         }
86
87         url_do_template();
88 }
89
90
91 // display page popup
92 // If there are instant messages waiting, and we notice that we haven't checked them in
93 // a while, it probably means that we need to open the instant messenger window.
94 int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP) {
95         int len;
96         char buf[SIZ];
97
98         // JavaScript function to alert the user that popups are probably blocked
99         // First, do the check as part of our page load.
100         serv_puts("NOOP");
101         len = serv_getln(buf, sizeof buf);
102         if ((len >= 3) && (buf[3] == '*')) {
103                 if ((time(NULL) - WC->last_pager_check) > 60) {
104                         return 1;
105                 }
106         }
107         return 0;
108         // Then schedule it to happen again a minute from now if the user is idle.
109 }
110
111
112 void ajax_send_instant_message(void) {
113         char recp[256];
114         char buf[256];
115
116         safestrncpy(recp, bstr("recp"), sizeof recp);
117
118         serv_printf("SEXP %s|-", recp);
119         serv_getln(buf, sizeof buf);
120
121         if (buf[0] == '4') {
122                 text_to_server(bstr("msg"));
123                 serv_puts("000");
124         }
125
126         escputs(buf);   // doesn't really matter what we return - the client ignores it
127 }
128
129
130 void 
131 InitModule_PAGING
132 (void)
133 {
134         WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
135         WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
136         WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
137         RegisterConditional("COND:PAGE:WAITING", 0, Conditional_PAGE_WAITING, CTX_NONE);
138 }
139
140
141 void 
142 SessionDestroyModule_PAGING
143 (wcsession *sess)
144 {
145         /* nothing here anymore */
146 }