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