2 * This module implements server commands related to the display and
3 * manipulation of the "Who's online" list.
5 * Copyright (c) 1987-2012 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
30 #include <sys/types.h>
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
37 # include <sys/time.h>
46 #include <libcitadel.h>
49 #include "citserver.h"
58 #include "ctdl_module.h"
62 * display who's online
64 void cmd_rwho(char *argbuf) {
65 struct CitContext *nptr;
73 char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
74 char host[64], flags[5];
76 /* So that we don't keep the context list locked for a long time
77 * we create a copy of it first
81 nptr = CtdlGetContextArray(&nContexts) ;
84 /* Couldn't malloc so we have to bail but stick to the protocol */
85 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
90 aide = CtdlAccessCheck(ac_aide);
91 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
93 for (i=0; i<nContexts; i++)
101 if (!aide && nptr[i].state == CON_SYS)
104 if (!aide && nptr[i].kill_me != 0)
107 if (nptr[i].cs_flags & CS_POSTING)
112 if (nptr[i].fake_username[0])
114 strcpy(un, nptr[i].fake_username);
119 strcpy(un, nptr[i].curr_user);
121 if (nptr[i].fake_hostname[0])
123 strcpy(host, nptr[i].fake_hostname);
128 strcpy(host, nptr[i].cs_host);
130 GenerateRoomDisplay(real_room, &nptr[i], CC);
132 if (nptr[i].fake_roomname[0]) {
133 strcpy(room, nptr[i].fake_roomname);
138 strcpy(room, real_room);
141 if ((aide) && (spoofed)) {
145 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
149 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
151 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
152 nptr[i].cs_pid, un, room,
153 host, nptr[i].cs_clientname,
154 (long)(nptr[i].lastidle),
155 nptr[i].lastcmdname, flags
158 if ((user_spoofed) && (aide)) {
159 cprintf("%s|", nptr[i].curr_user);
165 if ((room_spoofed) && (aide)) {
166 cprintf("%s|", real_room);
172 if ((host_spoofed) && (aide)) {
173 cprintf("%s|", nptr[i].cs_host);
179 cprintf("%d\n", nptr[i].logged_in);
183 /* release out copy of the context list */
186 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
187 * so that external paging modules such as serv_icq can add more
188 * content to the Wholist.
190 PerformSessionHooks(EVT_RWHO);
196 * Masquerade roomname
198 void cmd_rchg(char *argbuf)
200 char newroomname[ROOMNAMELEN];
202 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
203 newroomname[ROOMNAMELEN-1] = 0;
204 if (!IsEmptyStr(newroomname)) {
205 safestrncpy(CC->fake_roomname, newroomname,
206 sizeof(CC->fake_roomname) );
209 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
211 cprintf("%d OK\n", CIT_OK);
215 * Masquerade hostname
217 void cmd_hchg(char *argbuf)
219 char newhostname[64];
221 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
222 if (!IsEmptyStr(newhostname)) {
223 safestrncpy(CC->fake_hostname, newhostname,
224 sizeof(CC->fake_hostname) );
227 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
229 cprintf("%d OK\n", CIT_OK);
234 * Masquerade username (aides only)
236 void cmd_uchg(char *argbuf)
239 char newusername[USERNAME_SIZE];
241 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
243 if (CtdlAccessCheck(ac_aide)) return;
245 if (!IsEmptyStr(newusername)) {
246 CC->cs_flags &= ~CS_STEALTH;
247 memset(CC->fake_username, 0, 32);
248 if (strncasecmp(newusername, CC->curr_user,
249 strlen(CC->curr_user)))
250 safestrncpy(CC->fake_username, newusername,
251 sizeof(CC->fake_username));
254 CC->fake_username[0] = '\0';
255 CC->cs_flags |= CS_STEALTH;
257 cprintf("%d\n",CIT_OK);
264 * enter or exit "stealth mode"
266 void cmd_stel(char *cmdbuf)
270 requested_mode = extract_int(cmdbuf,0);
272 if (CtdlAccessCheck(ac_logged_in)) return;
274 if (requested_mode == 1) {
275 CC->cs_flags = CC->cs_flags | CS_STEALTH;
276 PerformSessionHooks(EVT_STEALTH);
278 if (requested_mode == 0) {
279 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
280 PerformSessionHooks(EVT_UNSTEALTH);
283 cprintf("%d %d\n", CIT_OK,
284 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
288 CTDL_MODULE_INIT(rwho)
292 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
293 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
294 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
295 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
296 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
299 /* return our module name for the log */