webcit_before_automake is now the trunk
[citadel.git] / webcit / who.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup DislpayWho Display a list of all users currently logged on to the Citadel server.
6  * \ingroup WebcitDisplayItems
7  */
8 /*@{*/
9 #include "webcit.h"
10
11
12
13 /**
14  * \brief Display inner div of Wholist
15  */
16 void who_inner_div(void) {
17         char buf[SIZ], user[SIZ], room[SIZ], host[SIZ],
18                 realroom[SIZ], realhost[SIZ];
19         int sess;
20         time_t last_activity;
21         time_t now;
22         int bg = 0;
23
24         wprintf("<table border=\"0\" cellspacing=\"0\" width=\"100%%\" bgcolor=\"#FFFFFF\">"
25                 "<tr>\n");
26         wprintf("<th colspan=\"3\"> </th>\n");
27         wprintf("<th>%s</th>\n", _("User name"));
28         wprintf("<th>%s</th>", _("Room"));
29         wprintf("<th>%s</th>\n</tr>\n", _("From host"));
30
31         serv_puts("TIME");
32         serv_getln(buf, sizeof buf);
33         if (buf[0] == '2') {
34                 now = extract_long(&buf[4], 0);
35         }
36         else {
37                 now = time(NULL);
38         }
39
40         serv_puts("RWHO");
41         serv_getln(buf, sizeof buf);
42         if (buf[0] == '1') {
43                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
44                         sess = extract_int(buf, 0);
45                         extract_token(user, buf, 1, '|', sizeof user);
46                         extract_token(room, buf, 2, '|', sizeof room);
47                         extract_token(host, buf, 3, '|', sizeof host);
48                         extract_token(realroom, buf, 9, '|', sizeof realroom);
49                         extract_token(realhost, buf, 10, '|', sizeof realhost);
50                         last_activity = extract_long(buf, 5);
51
52                         bg = 1 - bg;
53                         wprintf("<tr bgcolor=\"#%s\">",
54                                 (bg ? "DDDDDD" : "FFFFFF")
55                         );
56
57
58                         wprintf("<td>");
59                         if ((WC->is_aide) &&
60                             (sess != WC->ctdl_pid)) {
61                                 wprintf(" <a href=\"terminate_session?which_session=%d", sess);
62                                 wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
63                         }
64                         if (sess == WC->ctdl_pid) {
65                                 wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
66                         }
67                         wprintf("</td>");
68
69                         /** (link to page this user) */
70                         wprintf("<td><a href=\"display_page?recp=");
71                         urlescputs(user);
72                         wprintf("\">"
73                                 "<img align=\"middle\" "
74                                 "src=\"static/citadelchat_24x.gif\" "
75                                 "alt=\"(p)\""
76                                 " border=\"0\" /></a> ");
77                         wprintf("</td>");
78
79                         /** (idle flag) */
80                         wprintf("<td>");
81                         if ((now - last_activity) > 900L) {
82                                 wprintf(" "
83                                         "<img align=\"middle\" "
84                                         "src=\"static/inactiveuser_24x.gif\" "
85                                         "alt=\"(idle)\" border=\"0\" />");
86                         }
87                         else {
88                                 wprintf(" "
89                                         "<img align=\"middle\" "
90                                         "src=\"static/activeuser_24x.gif\" "
91                                         "alt=\"(active)\" border=\"0\" />");
92                         }
93                         wprintf("</td>\n<td>");
94
95
96
97                         /** username (link to user bio/photo page) */
98                         wprintf("<a href=\"showuser?who=");
99                         urlescputs(user);
100                         wprintf("\">");
101                         escputs(user);
102                         wprintf("</a>");
103
104                         /** room */
105                         wprintf("</td>\n\t<td>");
106                         escputs(room);
107                         if (strlen(realroom) > 0) {
108                                 wprintf("<br /><i>");
109                                 escputs(realroom);
110                                 wprintf("</i>");
111                         }
112                         wprintf("</td>\n\t<td>");
113
114                         /** hostname */
115                         escputs(host);
116                         if (strlen(realhost) > 0) {
117                                 wprintf("<br /><i>");
118                                 escputs(realhost);
119                                 wprintf("</i>");
120                         }
121                         wprintf("</td>\n</tr>");
122                 }
123         }
124         wprintf("</table>");
125 }
126
127
128 /**
129  * \brief who is on?
130  */
131 void who(void)
132 {
133         char title[256];
134
135         output_headers(1, 1, 2, 0, 0, 0);
136
137         wprintf("<script type=\"text/javascript\">\n"
138                 "function ConfirmKill() { \n"
139                 "return confirm('%s');\n"
140                 "}\n"
141                 "</script>\n", _("Do you really want to kill this session?")
142         );
143
144         wprintf("<div id=\"banner\">\n");
145         wprintf("<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
146         wprintf("<img src=\"static/usermanag_48x.gif\" alt=\" \" "
147                 "align=middle "
148                 ">");
149         wprintf("<span class=\"titlebar\"> ");
150
151         snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
152         escputs(title);
153
154         wprintf("</span></td><td align=right>");
155         offer_start_page();
156         wprintf("</td></tr></table>\n");
157         wprintf("</div>\n");
158
159         wprintf("<div id=\"content\">\n");
160
161         wprintf("<div style=\"display:inline\" id=\"fix_scrollbar_bug\">");
162         who_inner_div();
163         wprintf("</div>\n");
164
165         wprintf("<div id=\"instructions\" align=center>");
166         wprintf(_("Click on a name to read user info.  Click on %s "
167                 "to send an instant message to that user."),
168                 "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
169         );
170         wprintf("</div>\n");
171
172         /**
173          * JavaScript to make the ajax refresh happen:
174          * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
175          * It wants: 1. The div being updated
176          *           2. The URL of the update source
177          *           3. Other flags (such as the HTTP method and the refresh frequency)
178          */
179         wprintf(
180                 "<script type=\"text/javascript\">                                      "
181                 " new Ajax.PeriodicalUpdater('fix_scrollbar_bug', 'who_inner_html',     "
182                 "                            { method: 'get', frequency: 30 }  );       "
183                 "</script>                                                              \n"
184         );
185         wDumpContent(1);
186 }
187
188 /**
189  * \brief end session \todo what??? does this belong here? 
190  */
191 void terminate_session(void)
192 {
193         char buf[SIZ];
194
195         serv_printf("TERM %s", bstr("which_session"));
196         serv_getln(buf, sizeof buf);
197         who();
198 }
199
200
201 /**
202  * \brief Change your session info (fake roomname and hostname)
203  */
204 void edit_me(void)
205 {
206         char buf[SIZ];
207
208         if (strlen(bstr("change_room_name_button")) > 0) {
209                 serv_printf("RCHG %s", bstr("fake_roomname"));
210                 serv_getln(buf, sizeof buf);
211                 http_redirect("who");
212         } else if (strlen(bstr("change_host_name_button")) > 0) {
213                 serv_printf("HCHG %s", bstr("fake_hostname"));
214                 serv_getln(buf, sizeof buf);
215                 http_redirect("who");
216         } else if (strlen(bstr("change_user_name_button")) > 0) {
217                 serv_printf("UCHG %s", bstr("fake_username"));
218                 serv_getln(buf, sizeof buf);
219                 http_redirect("who");
220         } else if (strlen(bstr("cancel_button")) > 0) {
221                 http_redirect("who");
222         } else {
223                 output_headers(1, 1, 0, 0, 0, 0);
224
225                 wprintf("<div id=\"banner\">\n");
226                 wprintf("<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>");
227                 wprintf("<span class=\"titlebar\">");
228                 wprintf(_("Edit your session display"));
229                 wprintf("</span></td></tr></table>\n");
230                 wprintf("</div>\n<div id=\"content\">\n");
231
232                 wprintf(_("This screen allows you to change the way your "
233                         "session appears in the 'Who is online' listing. "
234                         "To turn off any 'fake' name you've previously "
235                         "set, simply click the appropriate 'change' button "
236                         "without typing anything in the corresponding box. "));
237                 wprintf("<br />\n");
238
239                 wprintf("<form method=\"POST\" action=\"edit_me\">\n");
240
241                 wprintf("<table border=0 width=100%%>\n");
242
243                 wprintf("<tr><td><b>");
244                 wprintf(_("Room name:"));
245                 wprintf("</b></td>\n<td>");
246                 wprintf("<input type=\"text\" name=\"fake_roomname\" maxlength=\"64\">\n");
247                 wprintf("</td>\n<td align=center>");
248                 wprintf("<input type=\"submit\" name=\"change_room_name_button\" value=\"%s\">",
249                         _("Change room name"));
250                 wprintf("</td>\n</tr>\n");
251
252                 wprintf("<tr><td><b>");
253                 wprintf(_("Host name:"));
254                 wprintf("</b></td><td>");
255                 wprintf("<input type=\"text\" name=\"fake_hostname\" maxlength=\"64\">\n");
256                 wprintf("</td>\n<td align=center>");
257                 wprintf("<input type=\"submit\" name=\"change_host_name_button\" value=\"%s\">",
258                         _("Change host name"));
259                 wprintf("</td>\n</tr>\n");
260
261                 if (WC->is_aide) {
262                         wprintf("<tr><td><b>");
263                         wprintf(_("User name:"));
264                         wprintf("</b></td><td>");
265                         wprintf("<input type=\"text\" name=\"fake_username\" maxlength=\"64\">\n");
266                         wprintf("</td>\n<td align=center>");
267                         wprintf("<input type=\"submit\" name \"change_user_name_button\" value=\"%s\">",
268                                 _("Change user name"));
269                         wprintf("</td>\n</tr>\n");
270                 }
271                 wprintf("<tr><td> </td><td> </td><td align=center>");
272                 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">",
273                         _("Cancel"));
274                 wprintf("</td></tr></table>\n");
275                 wprintf("</form></center>\n");
276                 wDumpContent(1);
277         }
278 }
279
280
281 /*@}*/