citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

serv_rwho.c
Go to the documentation of this file.
1/*
2 * This module implements server commands related to the display and
3 * manipulation of the "Who's online" list.
4 *
5 * Copyright (c) 1987-2019 by the citadel.org team
6 *
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include "sysdep.h"
18#include <stdlib.h>
19#include <unistd.h>
20#include <stdio.h>
21#include <fcntl.h>
22#include <signal.h>
23#include <pwd.h>
24#include <errno.h>
25#include <sys/types.h>
26#include <time.h>
27#include <sys/wait.h>
28#include <string.h>
29#include <limits.h>
30#include <libcitadel.h>
31#include "citadel.h"
32#include "server.h"
33#include "citserver.h"
34#include "support.h"
35#include "config.h"
36#include "control.h"
37#include "user_ops.h"
38#include "database.h"
39#include "msgbase.h"
40#include "ctdl_module.h"
41
42/* Don't show the names of private rooms unless the viewing
43 * user also knows the rooms.
44 */
45void GenerateRoomDisplay(char *real_room,
46 CitContext *viewed,
47 CitContext *viewer) {
48
49 int ra;
50
51 strcpy(real_room, viewed->room.QRname);
52 if (viewed->room.QRflags & QR_MAILBOX) {
53 strcpy(real_room, &real_room[11]);
54 }
55 if (viewed->room.QRflags & QR_PRIVATE) {
56 CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
57 if ( (ra & UA_KNOWN) == 0) {
58 strcpy(real_room, " ");
59 }
60 }
61
62 if (viewed->cs_flags & CS_CHAT) {
63 while (strlen(real_room) < 14) {
64 strcat(real_room, " ");
65 }
66 strcpy(&real_room[14], "<chat>");
67 }
68
69}
70
71
72
73/*
74 * display who's online
75 */
76void cmd_rwho(char *argbuf) {
77 struct CitContext *nptr;
78 int nContexts, i;
79 int spoofed = 0;
80 int aide;
81 char room[ROOMNAMELEN];
82 char flags[5];
83
84 /* So that we don't keep the context list locked for a long time
85 * we create a copy of it first
86 */
87 nptr = CtdlGetContextArray(&nContexts) ;
88 if (!nptr)
89 {
90 /* Couldn't malloc so we have to bail but stick to the protocol */
92 cprintf("000\n");
93 return;
94 }
95
96 aide = ( (CC->user.axlevel >= AxAideU) || (CC->internal_pgm) ) ;
98
99 for (i=0; i<nContexts; i++) {
100 flags[0] = '\0';
101 spoofed = 0;
102
103 if (!aide && nptr[i].state == CON_SYS)
104 continue;
105
106 if (!aide && nptr[i].kill_me != 0)
107 continue;
108
109 if (nptr[i].cs_flags & CS_POSTING) {
110 strcat(flags, "*");
111 }
112 else {
113 strcat(flags, ".");
114 }
115
116 GenerateRoomDisplay(room, &nptr[i], CC);
117
118 if ((aide) && (spoofed)) {
119 strcat(flags, "+");
120 }
121
122 if ((nptr[i].cs_flags & CS_STEALTH) && (aide)) {
123 strcat(flags, "-");
124 }
125
126 if (((nptr[i].cs_flags&CS_STEALTH)==0) || (aide)) {
127
128 cprintf("%d|%s|%s|%s|%s|%ld|%s|%s|",
129 nptr[i].cs_pid, nptr[i].curr_user, room,
130 nptr[i].cs_host, nptr[i].cs_clientname,
131 (long)(nptr[i].lastidle),
132 nptr[i].lastcmdname, flags
133 );
134
135 cprintf("|"); // no spoofed user names anymore
136 cprintf("|"); // no spoofed room names anymore
137 cprintf("|"); // no spoofed host names anymore
138
139 cprintf("%d\n", nptr[i].logged_in);
140 }
141 }
142
143 /* release our copy of the context list */
144 free(nptr);
145
146 /* Now it's magic time. Before we finish, call any EVT_RWHO hooks
147 * so that external paging modules such as serv_icq can add more
148 * content to the Wholist.
149 */
151 cprintf("000\n");
152}
153
154
155/*
156 * enter or exit "stealth mode"
157 */
158void cmd_stel(char *cmdbuf)
159{
160 int requested_mode;
161
162 requested_mode = extract_int(cmdbuf,0);
163
164 if (CtdlAccessCheck(ac_logged_in)) return;
165
166 if (requested_mode == 1) {
167 CC->cs_flags = CC->cs_flags | CS_STEALTH;
169 }
170 if (requested_mode == 0) {
171 CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
173 }
174
175 cprintf("%d %d\n", CIT_OK,
176 ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
177}
178
179
181{
182 if(!threading)
183 {
184 CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
185 CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
186 //CtdlRegisterSessionHook(dead_io_check, EVT_TIMER, PRIO_QUEUE + 50);
187
188 }
189
190 /* return our module name for the log */
191 return "rwho";
192}
#define ROOMNAMELEN
Definition: citadel.h:56
char CtdlCheckExpress(void)
Definition: citserver.c:168
CitContext * CtdlGetContextArray(int *count)
Definition: context.c:445
#define CC
Definition: context.h:140
@ CON_SYS
Definition: context.h:28
int CtdlAccessCheck(int)
Definition: user_ops.c:387
void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view)
Definition: room_ops.c:121
@ ac_logged_in
Definition: ctdl_module.h:244
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define CTDL_MODULE_INIT(module_name)
Definition: ctdl_module.h:50
#define CIT_OK
Definition: ipcdef.h:6
#define LISTING_FOLLOWS
Definition: ipcdef.h:5
#define QR_PRIVATE
Definition: ipcdef.h:41
#define QR_MAILBOX
Definition: ipcdef.h:53
#define UA_KNOWN
Definition: ipcdef.h:79
void free(void *)
void PerformSessionHooks(int EventType)
void cmd_stel(char *cmdbuf)
Definition: serv_rwho.c:158
void cmd_rwho(char *argbuf)
Definition: serv_rwho.c:76
void GenerateRoomDisplay(char *real_room, CitContext *viewed, CitContext *viewer)
Definition: serv_rwho.c:45
#define EVT_STEALTH
Definition: server.h:221
#define CS_POSTING
Definition: server.h:112
#define CS_STEALTH
Definition: server.h:110
#define EVT_RWHO
Definition: server.h:219
#define EVT_UNSTEALTH
Definition: server.h:222
#define CS_CHAT
Definition: server.h:111
int cs_pid
Definition: context.h:44
int logged_in
Definition: context.h:70
char lastcmdname[5]
Definition: context.h:76
char cs_clientname[32]
Definition: context.h:89
struct ctdluser user
Definition: context.h:109
time_t lastidle
Definition: context.h:48
unsigned cs_flags
Definition: context.h:77
char curr_user[64]
Definition: context.h:69
int kill_me
Definition: context.h:50
CCState state
Definition: context.h:49
char cs_host[64]
Definition: context.h:90
struct ctdlroom room
Definition: context.h:110
char QRname[128]
Definition: citadel.h:108
unsigned QRflags
Definition: citadel.h:113
void cprintf(const char *format,...)
Definition: sysdep.c:381