]> code.citadel.org Git - citadel.git/blob - citadel/serv_rwho.c
* More conflict checking stuff
[citadel.git] / citadel / serv_rwho.c
1 /*
2  * $Id$
3  *
4  * This module implementsserver commands related to the display and
5  * manipulation of the "Who's online" list.
6  *
7  */
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <sys/wait.h>
31 #include <string.h>
32 #include <limits.h>
33 #include "citadel.h"
34 #include "server.h"
35 #include "sysdep_decls.h"
36 #include "citserver.h"
37 #include "support.h"
38 #include "config.h"
39 #include "control.h"
40 #include "dynloader.h"
41 #include "room_ops.h"
42 #include "user_ops.h"
43 #include "policy.h"
44 #include "database.h"
45 #include "msgbase.h"
46 #include "tools.h"
47
48
49
50 /*
51  * display who's online
52  */
53 void cmd_rwho(char *argbuf) {
54         struct CitContext *cptr;
55         int spoofed = 0;
56         int user_spoofed = 0;
57         int room_spoofed = 0;
58         int host_spoofed = 0;
59         int aide;
60         char un[40];
61         char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
62         char host[64], flags[5];
63         
64         aide = CC->usersupp.axlevel >= 6;
65         cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
66         
67         for (cptr = ContextList; cptr != NULL; cptr = cptr->next) 
68         {
69                 flags[0] = '\0';
70                 spoofed = 0;
71                 user_spoofed = 0;
72                 room_spoofed = 0;
73                 host_spoofed = 0;
74                 
75                 if (cptr->cs_flags & CS_POSTING)
76                    strcat(flags, "*");
77                 else
78                    strcat(flags, ".");
79                    
80                 if (cptr->fake_username[0])
81                 {
82                    strcpy(un, cptr->fake_username);
83                    spoofed = 1;
84                    user_spoofed = 1;
85                 }
86                 else
87                    strcpy(un, cptr->curr_user);
88                    
89                 if (cptr->fake_hostname[0])
90                 {
91                    strcpy(host, cptr->fake_hostname);
92                    spoofed = 1;
93                    host_spoofed = 1;
94                 }
95                 else
96                    strcpy(host, cptr->cs_host);
97
98                 GenerateRoomDisplay(real_room, cptr, CC);
99
100                 if (cptr->fake_roomname[0]) {
101                         strcpy(room, cptr->fake_roomname);
102                         spoofed = 1;
103                         room_spoofed = 1;
104                 }
105                 else {
106                         strcpy(room, real_room);
107                 }
108                 
109                 if ((aide) && (spoofed)) {
110                         strcat(flags, "+");
111                 }
112                 
113                 if ((cptr->cs_flags & CS_STEALTH) && (aide)) {
114                         strcat(flags, "-");
115                 }
116                 
117                 if (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
118                 {
119                         cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|%d|",
120                                 cptr->cs_pid, un, room,
121                                 host, cptr->cs_clientname,
122                                 (long)(cptr->lastidle),
123                                 cptr->lastcmdname, flags,
124                                 cptr->logged_in
125                         );
126
127                         if ((user_spoofed) && (aide)) {
128                                 cprintf("%s|", cptr->curr_user);
129                         }
130                         else {
131                                 cprintf("|");
132                         }
133         
134                         if ((room_spoofed) && (aide)) {
135                                 cprintf("%s|", real_room);
136                         }
137                         else {
138                                 cprintf("|");
139                         }
140         
141                         if ((host_spoofed) && (aide)) {
142                                 cprintf("%s|", cptr->cs_host);
143                         }
144                         else {
145                                 cprintf("|");
146                         }
147         
148                         cprintf("\n");
149                 }
150         }
151
152         /* Now it's magic time.  Before we finish, call any EVT_RWHO hooks
153          * so that external paging modules such as serv_icq can add more
154          * content to the Wholist.
155          */
156         PerformSessionHooks(EVT_RWHO);
157         cprintf("000\n");
158         }
159
160
161 /*
162  * Masquerade roomname
163  */
164 void cmd_rchg(char *argbuf)
165 {
166         char newroomname[SIZ];
167
168         extract(newroomname, argbuf, 0);
169         newroomname[ROOMNAMELEN-1] = 0;
170         if (strlen(newroomname) > 0) {
171                 safestrncpy(CC->fake_roomname, newroomname,
172                         sizeof(CC->fake_roomname) );
173                 }
174         else {
175                 strcpy(CC->fake_roomname, "");
176                 }
177         cprintf("%d OK\n", CIT_OK);
178 }
179
180 /*
181  * Masquerade hostname 
182  */
183 void cmd_hchg(char *argbuf)
184 {
185         char newhostname[SIZ];
186
187         extract(newhostname, argbuf, 0);
188         if (strlen(newhostname) > 0) {
189                 safestrncpy(CC->fake_hostname, newhostname,
190                         sizeof(CC->fake_hostname) );
191                 }
192         else {
193                 strcpy(CC->fake_hostname, "");
194                 }
195         cprintf("%d OK\n", CIT_OK);
196 }
197
198
199 /*
200  * Masquerade username (aides only)
201  */
202 void cmd_uchg(char *argbuf)
203 {
204
205         char newusername[SIZ];
206
207         extract(newusername, argbuf, 0);
208
209         if (CtdlAccessCheck(ac_aide)) return;
210
211         if (strlen(newusername) > 0) {
212                 CC->cs_flags &= ~CS_STEALTH;
213                 memset(CC->fake_username, 0, 32);
214                 if (strncasecmp(newusername, CC->curr_user,
215                                 strlen(CC->curr_user)))
216                         safestrncpy(CC->fake_username, newusername,
217                                 sizeof(CC->fake_username));
218         }
219         else {
220                 CC->fake_username[0] = '\0';
221                 CC->cs_flags |= CS_STEALTH;
222         }
223         cprintf("%d\n",CIT_OK);
224 }
225
226
227
228
229 /*
230  * enter or exit "stealth mode"
231  */
232 void cmd_stel(char *cmdbuf)
233 {
234         int requested_mode;
235
236         requested_mode = extract_int(cmdbuf,0);
237
238         if (CtdlAccessCheck(ac_logged_in)) return;
239
240         if (requested_mode == 1) {
241                 CC->cs_flags = CC->cs_flags | CS_STEALTH;
242         }
243         if (requested_mode == 0) {
244                 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
245         }
246
247         cprintf("%d %d\n", CIT_OK,
248                 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
249 }
250
251
252
253
254
255
256
257 char *Dynamic_Module_Init(void)
258 {
259         CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
260         CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
261         CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
262         CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
263         CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
264         return "$Id$";
265 }