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 nContexts = num_sessions;
72 nptr = malloc(sizeof(struct CitContext) * nContexts);
75 /* Couldn't malloc so we have to bail but stick to the protocol */
76 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
80 begin_critical_section(S_SESSION_TABLE);
81 for (cptr = ContextList, i=0; cptr != NULL && i < nContexts; cptr = cptr->next, i++)
83 memcpy(&nptr[i], cptr, sizeof (struct CitContext));
85 end_critical_section (S_SESSION_TABLE);
87 aide = CC->user.axlevel >= 6;
88 cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
90 for (i=0; i<nContexts; i++)
98 if (nptr[i].cs_flags & CS_POSTING)
103 if (nptr[i].fake_username[0])
105 strcpy(un, nptr[i].fake_username);
110 strcpy(un, nptr[i].curr_user);
112 if (nptr[i].fake_hostname[0])
114 strcpy(host, nptr[i].fake_hostname);
119 strcpy(host, nptr[i].cs_host);
121 GenerateRoomDisplay(real_room, &nptr[i], CC);
123 if (nptr[i].fake_roomname[0]) {
124 strcpy(room, nptr[i].fake_roomname);
129 strcpy(room, real_room);
132 if ((aide) && (spoofed)) {
136 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
140 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide))
142 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
143 nptr[i].cs_pid, un, room,
144 host, nptr[i].cs_clientname,
145 (long)(nptr[i].lastidle),
146 nptr[i].lastcmdname, flags
149 if ((user_spoofed) && (aide)) {
150 cprintf("%s|", nptr[i].curr_user);
156 if ((room_spoofed) && (aide)) {
157 cprintf("%s|", real_room);
163 if ((host_spoofed) && (aide)) {
164 cprintf("%s|", nptr[i].cs_host);
170 cprintf("%d\n", nptr[i].logged_in);
174 /* release out copy of the context list */
177 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
178 * so that external paging modules such as serv_icq can add more
179 * content to the Wholist.
181 PerformSessionHooks(EVT_RWHO);
187 * Masquerade roomname
189 void cmd_rchg(char *argbuf)
191 char newroomname[ROOMNAMELEN];
193 extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
194 newroomname[ROOMNAMELEN-1] = 0;
195 if (!IsEmptyStr(newroomname)) {
196 safestrncpy(CC->fake_roomname, newroomname,
197 sizeof(CC->fake_roomname) );
200 safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
202 cprintf("%d OK\n", CIT_OK);
206 * Masquerade hostname
208 void cmd_hchg(char *argbuf)
210 char newhostname[64];
212 extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
213 if (!IsEmptyStr(newhostname)) {
214 safestrncpy(CC->fake_hostname, newhostname,
215 sizeof(CC->fake_hostname) );
218 safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
220 cprintf("%d OK\n", CIT_OK);
225 * Masquerade username (aides only)
227 void cmd_uchg(char *argbuf)
230 char newusername[USERNAME_SIZE];
232 extract_token(newusername, argbuf, 0, '|', sizeof newusername);
234 if (CtdlAccessCheck(ac_aide)) return;
236 if (!IsEmptyStr(newusername)) {
237 CC->cs_flags &= ~CS_STEALTH;
238 memset(CC->fake_username, 0, 32);
239 if (strncasecmp(newusername, CC->curr_user,
240 strlen(CC->curr_user)))
241 safestrncpy(CC->fake_username, newusername,
242 sizeof(CC->fake_username));
245 CC->fake_username[0] = '\0';
246 CC->cs_flags |= CS_STEALTH;
248 cprintf("%d\n",CIT_OK);
255 * enter or exit "stealth mode"
257 void cmd_stel(char *cmdbuf)
261 requested_mode = extract_int(cmdbuf,0);
263 if (CtdlAccessCheck(ac_logged_in)) return;
265 if (requested_mode == 1) {
266 CC->cs_flags = CC->cs_flags | CS_STEALTH;
267 PerformSessionHooks(EVT_STEALTH);
269 if (requested_mode == 0) {
270 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
271 PerformSessionHooks(EVT_UNSTEALTH);
274 cprintf("%d %d\n", CIT_OK,
275 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
279 CTDL_MODULE_INIT(rwho)
283 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
284 CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
285 CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
286 CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
287 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
290 /* return our Subversion id for the Log */