a836e8d19f5b2518671673d576db78442c3de08e
[citadel.git] / citadel / serv_rwho.c
1 /*
2  * $Id$
3  *
4  * This module implements the RWHO (Read WHO's online) server command.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/wait.h>
19 #include <string.h>
20 #include <limits.h>
21 #include "citadel.h"
22 #include "server.h"
23 #include <time.h>
24 #include "sysdep_decls.h"
25 #include "citserver.h"
26 #include "support.h"
27 #include "config.h"
28 #include "control.h"
29 #include "dynloader.h"
30 #include "room_ops.h"
31 #include "user_ops.h"
32 #include "policy.h"
33 #include "database.h"
34 #include "msgbase.h"
35 #include "tools.h"
36
37
38
39
40 /*
41  * 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 char *Dynamic_Module_Init(void)
127 {
128         CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
129         return "$Id$";
130 }