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.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
25 #include <sys/types.h>
27 #if TIME_WITH_SYS_TIME
28 # include <sys/time.h>
32 # include <sys/time.h>
41 #include <libcitadel.h>
44 #include "citserver.h"
53 #include "ctdl_module.h"
57 * display who's online
59 void cmd_rwho(char *argbuf) {
60 struct CitContext *nptr;
68 char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
69 char host[64], flags[5];
71 /* So that we don't keep the context list locked for a long time
72 * we create a copy of it first
74 nptr = CtdlGetContextArray(&nContexts) ;
77 /* Couldn't malloc so we have to bail but stick to the protocol */
78 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
83 aide = ( (CC->user.axlevel >= AxAideU) || (CC->internal_pgm) ) ;
84 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
86 for (i=0; i<nContexts; i++)
94 if (!aide && nptr[i].state == CON_SYS)
97 if (!aide && nptr[i].kill_me != 0)
100 if (nptr[i].cs_flags & CS_POSTING)
105 if (nptr[i].fake_username[0])
107 strcpy(un, nptr[i].fake_username);
112 strcpy(un, nptr[i].curr_user);
114 if (nptr[i].fake_hostname[0])
116 strcpy(host, nptr[i].fake_hostname);
121 strcpy(host, nptr[i].cs_host);
123 GenerateRoomDisplay(real_room, &nptr[i], CC);
125 if (nptr[i].fake_roomname[0]) {
126 strcpy(room, nptr[i].fake_roomname);
131 strcpy(room, real_room);
134 if ((aide) && (spoofed)) {
138 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
142 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
144 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
145 nptr[i].cs_pid, un, room,
146 host, nptr[i].cs_clientname,
147 (long)(nptr[i].lastidle),
148 nptr[i].lastcmdname, flags
151 if ((user_spoofed) && (aide)) {
152 cprintf("%s|", nptr[i].curr_user);
158 if ((room_spoofed) && (aide)) {
159 cprintf("%s|", real_room);
165 if ((host_spoofed) && (aide)) {
166 cprintf("%s|", nptr[i].cs_host);
172 cprintf("%d\n", nptr[i].logged_in);
176 /* release out copy of the context list */
179 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
180 * so that external paging modules such as serv_icq can add more
181 * content to the Wholist.
183 PerformSessionHooks(EVT_RWHO);
189 * Masquerade roomname
191 void cmd_rchg(char *argbuf)
193 char newroomname[ROOMNAMELEN];
195 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
196 newroomname[ROOMNAMELEN-1] = 0;
197 if (!IsEmptyStr(newroomname)) {
198 safestrncpy(CC->fake_roomname, newroomname,
199 sizeof(CC->fake_roomname) );
202 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
204 cprintf("%d OK\n", CIT_OK);
208 * Masquerade hostname
210 void cmd_hchg(char *argbuf)
212 char newhostname[64];
214 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
215 if (!IsEmptyStr(newhostname)) {
216 safestrncpy(CC->fake_hostname, newhostname,
217 sizeof(CC->fake_hostname) );
220 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
222 cprintf("%d OK\n", CIT_OK);
227 * Masquerade username (aides only)
229 void cmd_uchg(char *argbuf)
232 char newusername[USERNAME_SIZE];
234 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
236 if (CtdlAccessCheck(ac_aide)) return;
238 if (!IsEmptyStr(newusername)) {
239 CC->cs_flags &= ~CS_STEALTH;
240 memset(CC->fake_username, 0, 32);
241 if (strncasecmp(newusername, CC->curr_user,
242 strlen(CC->curr_user)))
243 safestrncpy(CC->fake_username, newusername,
244 sizeof(CC->fake_username));
247 CC->fake_username[0] = '\0';
248 CC->cs_flags |= CS_STEALTH;
250 cprintf("%d\n",CIT_OK);
257 * enter or exit "stealth mode"
259 void cmd_stel(char *cmdbuf)
263 requested_mode = extract_int(cmdbuf,0);
265 if (CtdlAccessCheck(ac_logged_in)) return;
267 if (requested_mode == 1) {
268 CC->cs_flags = CC->cs_flags | CS_STEALTH;
269 PerformSessionHooks(EVT_STEALTH);
271 if (requested_mode == 0) {
272 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
273 PerformSessionHooks(EVT_UNSTEALTH);
276 cprintf("%d %d\n", CIT_OK,
277 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
281 CTDL_MODULE_INIT(rwho)
285 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
286 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
287 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
288 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
289 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
292 /* return our module name for the log */