4 * This module implements server commands related to the display and
5 * manipulation of the "Who's online" list.
7 * Copyright (c) 1987-2009 by the citadel.org team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/types.h>
34 #if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
39 # include <sys/time.h>
48 #include <libcitadel.h>
51 #include "citserver.h"
61 #include "ctdl_module.h"
65 * display who's online
67 void cmd_rwho(char *argbuf) {
68 struct CitContext *nptr;
76 char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
77 char host[64], flags[5];
79 /* So that we don't keep the context list locked for a long time
80 * we create a copy of it first
84 nptr = CtdlGetContextArray(&nContexts) ;
87 /* Couldn't malloc so we have to bail but stick to the protocol */
88 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
93 aide = CC->user.axlevel >= AxAideU;
94 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
96 for (i=0; i<nContexts; i++)
104 if (nptr[i].cs_flags & CS_POSTING)
109 if (nptr[i].fake_username[0])
111 strcpy(un, nptr[i].fake_username);
116 strcpy(un, nptr[i].curr_user);
118 if (nptr[i].fake_hostname[0])
120 strcpy(host, nptr[i].fake_hostname);
125 strcpy(host, nptr[i].cs_host);
127 GenerateRoomDisplay(real_room, &nptr[i], CC);
129 if (nptr[i].fake_roomname[0]) {
130 strcpy(room, nptr[i].fake_roomname);
135 strcpy(room, real_room);
138 if ((aide) && (spoofed)) {
142 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
146 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
148 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
149 nptr[i].cs_pid, un, room,
150 host, nptr[i].cs_clientname,
151 (long)(nptr[i].lastidle),
152 nptr[i].lastcmdname, flags
155 if ((user_spoofed) && (aide)) {
156 cprintf("%s|", nptr[i].curr_user);
162 if ((room_spoofed) && (aide)) {
163 cprintf("%s|", real_room);
169 if ((host_spoofed) && (aide)) {
170 cprintf("%s|", nptr[i].cs_host);
176 cprintf("%d\n", nptr[i].logged_in);
180 /* release out copy of the context list */
183 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
184 * so that external paging modules such as serv_icq can add more
185 * content to the Wholist.
187 PerformSessionHooks(EVT_RWHO);
193 * Masquerade roomname
195 void cmd_rchg(char *argbuf)
197 char newroomname[ROOMNAMELEN];
199 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
200 newroomname[ROOMNAMELEN-1] = 0;
201 if (!IsEmptyStr(newroomname)) {
202 safestrncpy(CC->fake_roomname, newroomname,
203 sizeof(CC->fake_roomname) );
206 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
208 cprintf("%d OK\n", CIT_OK);
212 * Masquerade hostname
214 void cmd_hchg(char *argbuf)
216 char newhostname[64];
218 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
219 if (!IsEmptyStr(newhostname)) {
220 safestrncpy(CC->fake_hostname, newhostname,
221 sizeof(CC->fake_hostname) );
224 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
226 cprintf("%d OK\n", CIT_OK);
231 * Masquerade username (aides only)
233 void cmd_uchg(char *argbuf)
236 char newusername[USERNAME_SIZE];
238 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
240 if (CtdlAccessCheck(ac_aide)) return;
242 if (!IsEmptyStr(newusername)) {
243 CC->cs_flags &= ~CS_STEALTH;
244 memset(CC->fake_username, 0, 32);
245 if (strncasecmp(newusername, CC->curr_user,
246 strlen(CC->curr_user)))
247 safestrncpy(CC->fake_username, newusername,
248 sizeof(CC->fake_username));
251 CC->fake_username[0] = '\0';
252 CC->cs_flags |= CS_STEALTH;
254 cprintf("%d\n",CIT_OK);
261 * enter or exit "stealth mode"
263 void cmd_stel(char *cmdbuf)
267 requested_mode = extract_int(cmdbuf,0);
269 if (CtdlAccessCheck(ac_logged_in)) return;
271 if (requested_mode == 1) {
272 CC->cs_flags = CC->cs_flags | CS_STEALTH;
273 PerformSessionHooks(EVT_STEALTH);
275 if (requested_mode == 0) {
276 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
277 PerformSessionHooks(EVT_UNSTEALTH);
280 cprintf("%d %d\n", CIT_OK,
281 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
285 CTDL_MODULE_INIT(rwho)
289 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
290 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
291 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
292 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
293 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
296 /* return our Subversion id for the Log */