2 * This module implements server commands related to the display and
3 * manipulation of the "Who's online" list.
5 * Copyright (c) 1987-2009 by the citadel.org team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 = CC->user.axlevel >= AxAideU;
91 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
93 for (i=0; i<nContexts; i++)
101 if (nptr[i].cs_flags & CS_POSTING)
106 if (nptr[i].fake_username[0])
108 strcpy(un, nptr[i].fake_username);
113 strcpy(un, nptr[i].curr_user);
115 if (nptr[i].fake_hostname[0])
117 strcpy(host, nptr[i].fake_hostname);
122 strcpy(host, nptr[i].cs_host);
124 GenerateRoomDisplay(real_room, &nptr[i], CC);
126 if (nptr[i].fake_roomname[0]) {
127 strcpy(room, nptr[i].fake_roomname);
132 strcpy(room, real_room);
135 if ((aide) && (spoofed)) {
139 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
143 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
145 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
146 nptr[i].cs_pid, un, room,
147 host, nptr[i].cs_clientname,
148 (long)(nptr[i].lastidle),
149 nptr[i].lastcmdname, flags
152 if ((user_spoofed) && (aide)) {
153 cprintf("%s|", nptr[i].curr_user);
159 if ((room_spoofed) && (aide)) {
160 cprintf("%s|", real_room);
166 if ((host_spoofed) && (aide)) {
167 cprintf("%s|", nptr[i].cs_host);
173 cprintf("%d\n", nptr[i].logged_in);
177 /* release out copy of the context list */
180 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
181 * so that external paging modules such as serv_icq can add more
182 * content to the Wholist.
184 PerformSessionHooks(EVT_RWHO);
190 * Masquerade roomname
192 void cmd_rchg(char *argbuf)
194 char newroomname[ROOMNAMELEN];
196 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
197 newroomname[ROOMNAMELEN-1] = 0;
198 if (!IsEmptyStr(newroomname)) {
199 safestrncpy(CC->fake_roomname, newroomname,
200 sizeof(CC->fake_roomname) );
203 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
205 cprintf("%d OK\n", CIT_OK);
209 * Masquerade hostname
211 void cmd_hchg(char *argbuf)
213 char newhostname[64];
215 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
216 if (!IsEmptyStr(newhostname)) {
217 safestrncpy(CC->fake_hostname, newhostname,
218 sizeof(CC->fake_hostname) );
221 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
223 cprintf("%d OK\n", CIT_OK);
228 * Masquerade username (aides only)
230 void cmd_uchg(char *argbuf)
233 char newusername[USERNAME_SIZE];
235 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
237 if (CtdlAccessCheck(ac_aide)) return;
239 if (!IsEmptyStr(newusername)) {
240 CC->cs_flags &= ~CS_STEALTH;
241 memset(CC->fake_username, 0, 32);
242 if (strncasecmp(newusername, CC->curr_user,
243 strlen(CC->curr_user)))
244 safestrncpy(CC->fake_username, newusername,
245 sizeof(CC->fake_username));
248 CC->fake_username[0] = '\0';
249 CC->cs_flags |= CS_STEALTH;
251 cprintf("%d\n",CIT_OK);
258 * enter or exit "stealth mode"
260 void cmd_stel(char *cmdbuf)
264 requested_mode = extract_int(cmdbuf,0);
266 if (CtdlAccessCheck(ac_logged_in)) return;
268 if (requested_mode == 1) {
269 CC->cs_flags = CC->cs_flags | CS_STEALTH;
270 PerformSessionHooks(EVT_STEALTH);
272 if (requested_mode == 0) {
273 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
274 PerformSessionHooks(EVT_UNSTEALTH);
277 cprintf("%d %d\n", CIT_OK,
278 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
282 CTDL_MODULE_INIT(rwho)
286 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
287 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
288 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
289 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
290 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
293 /* return our module name for the log */