4 * This module implements server commands related to the display and
5 * manipulation of the "Who's online" list.
17 #include <sys/types.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
33 #include <libcitadel.h>
36 #include "citserver.h"
47 #include "ctdl_module.h"
51 * display who's online
53 void cmd_rwho(char *argbuf
) {
54 struct CitContext
*nptr
;
62 char real_room
[ROOMNAMELEN
], room
[ROOMNAMELEN
];
63 char host
[64], flags
[5];
65 /* So that we don't keep the context list locked for a long time
66 * we create a copy of it first
70 nptr
= CtdlGetContextArray(&nContexts
) ;
73 /* Couldn't malloc so we have to bail but stick to the protocol */
74 cprintf("%d%c \n", LISTING_FOLLOWS
, CtdlCheckExpress() );
79 aide
= CC
->user
.axlevel
>= 6;
80 cprintf("%d%c \n", LISTING_FOLLOWS
, CtdlCheckExpress() );
82 for (i
=0; i
<nContexts
; i
++)
90 if (nptr
[i
].cs_flags
& CS_POSTING
)
95 if (nptr
[i
].fake_username
[0])
97 strcpy(un
, nptr
[i
].fake_username
);
102 strcpy(un
, nptr
[i
].curr_user
);
104 if (nptr
[i
].fake_hostname
[0])
106 strcpy(host
, nptr
[i
].fake_hostname
);
111 strcpy(host
, nptr
[i
].cs_host
);
113 GenerateRoomDisplay(real_room
, &nptr
[i
], CC
);
115 if (nptr
[i
].fake_roomname
[0]) {
116 strcpy(room
, nptr
[i
].fake_roomname
);
121 strcpy(room
, real_room
);
124 if ((aide
) && (spoofed
)) {
128 if ((nptr
[i
].cs_flags
& CS_STEALTH
) && (aide
)) {
132 if (((nptr
[i
].cs_flags
&CS_STEALTH
)==0) || (aide
))
134 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
135 nptr
[i
].cs_pid
, un
, room
,
136 host
, nptr
[i
].cs_clientname
,
137 (long)(nptr
[i
].lastidle
),
138 nptr
[i
].lastcmdname
, flags
141 if ((user_spoofed
) && (aide
)) {
142 cprintf("%s|", nptr
[i
].curr_user
);
148 if ((room_spoofed
) && (aide
)) {
149 cprintf("%s|", real_room
);
155 if ((host_spoofed
) && (aide
)) {
156 cprintf("%s|", nptr
[i
].cs_host
);
162 cprintf("%d\n", nptr
[i
].logged_in
);
166 /* release out copy of the context list */
169 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
170 * so that external paging modules such as serv_icq can add more
171 * content to the Wholist.
173 PerformSessionHooks(EVT_RWHO
);
179 * Masquerade roomname
181 void cmd_rchg(char *argbuf
)
183 char newroomname
[ROOMNAMELEN
];
185 extract_token(newroomname
, argbuf
, 0, '|', sizeof newroomname
);
186 newroomname
[ROOMNAMELEN
-1] = 0;
187 if (!IsEmptyStr(newroomname
)) {
188 safestrncpy(CC
->fake_roomname
, newroomname
,
189 sizeof(CC
->fake_roomname
) );
192 safestrncpy(CC
->fake_roomname
, "", sizeof CC
->fake_roomname
);
194 cprintf("%d OK\n", CIT_OK
);
198 * Masquerade hostname
200 void cmd_hchg(char *argbuf
)
202 char newhostname
[64];
204 extract_token(newhostname
, argbuf
, 0, '|', sizeof newhostname
);
205 if (!IsEmptyStr(newhostname
)) {
206 safestrncpy(CC
->fake_hostname
, newhostname
,
207 sizeof(CC
->fake_hostname
) );
210 safestrncpy(CC
->fake_hostname
, "", sizeof CC
->fake_hostname
);
212 cprintf("%d OK\n", CIT_OK
);
217 * Masquerade username (aides only)
219 void cmd_uchg(char *argbuf
)
222 char newusername
[USERNAME_SIZE
];
224 extract_token(newusername
, argbuf
, 0, '|', sizeof newusername
);
226 if (CtdlAccessCheck(ac_aide
)) return;
228 if (!IsEmptyStr(newusername
)) {
229 CC
->cs_flags
&= ~CS_STEALTH
;
230 memset(CC
->fake_username
, 0, 32);
231 if (strncasecmp(newusername
, CC
->curr_user
,
232 strlen(CC
->curr_user
)))
233 safestrncpy(CC
->fake_username
, newusername
,
234 sizeof(CC
->fake_username
));
237 CC
->fake_username
[0] = '\0';
238 CC
->cs_flags
|= CS_STEALTH
;
240 cprintf("%d\n",CIT_OK
);
247 * enter or exit "stealth mode"
249 void cmd_stel(char *cmdbuf
)
253 requested_mode
= extract_int(cmdbuf
,0);
255 if (CtdlAccessCheck(ac_logged_in
)) return;
257 if (requested_mode
== 1) {
258 CC
->cs_flags
= CC
->cs_flags
| CS_STEALTH
;
259 PerformSessionHooks(EVT_STEALTH
);
261 if (requested_mode
== 0) {
262 CC
->cs_flags
= CC
->cs_flags
& ~CS_STEALTH
;
263 PerformSessionHooks(EVT_UNSTEALTH
);
266 cprintf("%d %d\n", CIT_OK
,
267 ((CC
->cs_flags
& CS_STEALTH
) ? 1 : 0) );
271 CTDL_MODULE_INIT(rwho
)
275 CtdlRegisterProtoHook(cmd_rwho
, "RWHO", "Display who is online");
276 CtdlRegisterProtoHook(cmd_hchg
, "HCHG", "Masquerade hostname");
277 CtdlRegisterProtoHook(cmd_rchg
, "RCHG", "Masquerade roomname");
278 CtdlRegisterProtoHook(cmd_uchg
, "UCHG", "Masquerade username");
279 CtdlRegisterProtoHook(cmd_stel
, "STEL", "Enter/exit stealth mode");
282 /* return our Subversion id for the Log */