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 *cptr;
55 struct CitContext *nptr;
63 char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
64 char host[64], flags[5];
66 /* So that we don't keep the context list locked for a long time
67 * we create a copy of it first
71 nptr = CtdlGetContextArray(&nContexts) ;
74 /* Couldn't malloc so we have to bail but stick to the protocol */
75 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
80 aide = CC->user.axlevel >= 6;
81 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
83 for (i=0; i<nContexts; i++)
91 if (nptr[i].cs_flags & CS_POSTING)
96 if (nptr[i].fake_username[0])
98 strcpy(un, nptr[i].fake_username);
103 strcpy(un, nptr[i].curr_user);
105 if (nptr[i].fake_hostname[0])
107 strcpy(host, nptr[i].fake_hostname);
112 strcpy(host, nptr[i].cs_host);
114 GenerateRoomDisplay(real_room, &nptr[i], CC);
116 if (nptr[i].fake_roomname[0]) {
117 strcpy(room, nptr[i].fake_roomname);
122 strcpy(room, real_room);
125 if ((aide) && (spoofed)) {
129 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
133 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
135 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
136 nptr[i].cs_pid, un, room,
137 host, nptr[i].cs_clientname,
138 (long)(nptr[i].lastidle),
139 nptr[i].lastcmdname, flags
142 if ((user_spoofed) && (aide)) {
143 cprintf("%s|", nptr[i].curr_user);
149 if ((room_spoofed) && (aide)) {
150 cprintf("%s|", real_room);
156 if ((host_spoofed) && (aide)) {
157 cprintf("%s|", nptr[i].cs_host);
163 cprintf("%d\n", nptr[i].logged_in);
167 /* release out copy of the context list */
170 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
171 * so that external paging modules such as serv_icq can add more
172 * content to the Wholist.
174 PerformSessionHooks(EVT_RWHO);
180 * Masquerade roomname
182 void cmd_rchg(char *argbuf)
184 char newroomname[ROOMNAMELEN];
186 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
187 newroomname[ROOMNAMELEN-1] = 0;
188 if (!IsEmptyStr(newroomname)) {
189 safestrncpy(CC->fake_roomname, newroomname,
190 sizeof(CC->fake_roomname) );
193 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
195 cprintf("%d OK\n", CIT_OK);
199 * Masquerade hostname
201 void cmd_hchg(char *argbuf)
203 char newhostname[64];
205 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
206 if (!IsEmptyStr(newhostname)) {
207 safestrncpy(CC->fake_hostname, newhostname,
208 sizeof(CC->fake_hostname) );
211 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
213 cprintf("%d OK\n", CIT_OK);
218 * Masquerade username (aides only)
220 void cmd_uchg(char *argbuf)
223 char newusername[USERNAME_SIZE];
225 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
227 if (CtdlAccessCheck(ac_aide)) return;
229 if (!IsEmptyStr(newusername)) {
230 CC->cs_flags &= ~CS_STEALTH;
231 memset(CC->fake_username, 0, 32);
232 if (strncasecmp(newusername, CC->curr_user,
233 strlen(CC->curr_user)))
234 safestrncpy(CC->fake_username, newusername,
235 sizeof(CC->fake_username));
238 CC->fake_username[0] = '\0';
239 CC->cs_flags |= CS_STEALTH;
241 cprintf("%d\n",CIT_OK);
248 * enter or exit "stealth mode"
250 void cmd_stel(char *cmdbuf)
254 requested_mode = extract_int(cmdbuf,0);
256 if (CtdlAccessCheck(ac_logged_in)) return;
258 if (requested_mode == 1) {
259 CC->cs_flags = CC->cs_flags | CS_STEALTH;
260 PerformSessionHooks(EVT_STEALTH);
262 if (requested_mode == 0) {
263 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
264 PerformSessionHooks(EVT_UNSTEALTH);
267 cprintf("%d %d\n", CIT_OK,
268 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
272 CTDL_MODULE_INIT(rwho)
276 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
277 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
278 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
279 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
280 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
283 /* return our Subversion id for the Log */