1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_admin.c: Sends administrative information to a user. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "handlers.h" |
27 |
#include "client.h" |
28 |
#include "ircd.h" |
29 |
#include "numeric.h" |
30 |
#include "s_conf.h" |
31 |
#include "s_serv.h" |
32 |
#include "send.h" |
33 |
#include "msg.h" |
34 |
#include "parse.h" |
35 |
#include "conf/modules.h" |
36 |
|
37 |
static void m_admin(struct Client *, struct Client *, int, char *[]); |
38 |
static void mr_admin(struct Client *, struct Client *, int, char *[]); |
39 |
static void ms_admin(struct Client *, struct Client *, int, char *[]); |
40 |
static void *do_admin(va_list); |
41 |
|
42 |
struct Message admin_msgtab = { |
43 |
"ADMIN", 0, 0, 0, 0, MFLG_SLOW | MFLG_UNREG, 0, |
44 |
{ mr_admin, m_admin, ms_admin, m_ignore, ms_admin, m_ignore } |
45 |
}; |
46 |
|
47 |
static struct Callback *admin_cb = NULL; |
48 |
|
49 |
INIT_MODULE(m_admin, "$Revision$") |
50 |
{ |
51 |
admin_cb = register_callback("doing_admin", do_admin); |
52 |
mod_add_cmd(&admin_msgtab); |
53 |
} |
54 |
|
55 |
CLEANUP_MODULE |
56 |
{ |
57 |
mod_del_cmd(&admin_msgtab); |
58 |
uninstall_hook(admin_cb, do_admin); |
59 |
} |
60 |
|
61 |
/*! \brief ADMIN command handler (called for unregistered clients only) |
62 |
* |
63 |
* \param client_p Pointer to allocated Client struct with physical connection |
64 |
* to this server, i.e. with an open socket connected. |
65 |
* \param source_p Pointer to allocated Client struct from which the message |
66 |
* originally comes from. This can be a local or remote client. |
67 |
* \param parc Integer holding the number of supplied arguments. |
68 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
69 |
* pointers. |
70 |
* \note Valid arguments for this command are: |
71 |
* - parv[0] = sender prefix |
72 |
* - parv[1] = name of target (rejected for unregistered clients) |
73 |
*/ |
74 |
static void |
75 |
mr_admin(struct Client *client_p, struct Client *source_p, |
76 |
int parc, char *parv[]) |
77 |
{ |
78 |
static time_t last_used = 0; |
79 |
|
80 |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
81 |
{ |
82 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
83 |
me.name, EmptyString(parv[0]) ? "*" : parv[0]); |
84 |
return; |
85 |
} |
86 |
|
87 |
last_used = CurrentTime; |
88 |
|
89 |
execute_callback(admin_cb, source_p, parc, parv); |
90 |
} |
91 |
|
92 |
/*! \brief ADMIN command handler (called for local clients only) |
93 |
* |
94 |
* \param client_p Pointer to allocated Client struct with physical connection |
95 |
* to this server, i.e. with an open socket connected. |
96 |
* \param source_p Pointer to allocated Client struct from which the message |
97 |
* originally comes from. This can be a local or remote client. |
98 |
* \param parc Integer holding the number of supplied arguments. |
99 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
100 |
* pointers. |
101 |
* \note Valid arguments for this command are: |
102 |
* - parv[0] = sender prefix |
103 |
* - parv[1] = name of target (optional; string can be a nick or server |
104 |
* and can also include wildcards) |
105 |
*/ |
106 |
static void |
107 |
m_admin(struct Client *client_p, struct Client *source_p, |
108 |
int parc, char *parv[]) |
109 |
{ |
110 |
static time_t last_used = 0; |
111 |
|
112 |
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) |
113 |
{ |
114 |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
115 |
me.name, source_p->name); |
116 |
return; |
117 |
} |
118 |
|
119 |
last_used = CurrentTime; |
120 |
|
121 |
if (!ConfigFileEntry.disable_remote) |
122 |
if (hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, |
123 |
parc, parv) != HUNTED_ISME) |
124 |
return; |
125 |
|
126 |
execute_callback(admin_cb, source_p, parc, parv); |
127 |
} |
128 |
|
129 |
/*! \brief ADMIN command handler (called for remote clients and servers) |
130 |
* |
131 |
* \param client_p Pointer to allocated Client struct with physical connection |
132 |
* to this server, i.e. with an open socket connected. |
133 |
* \param source_p Pointer to allocated Client struct from which the message |
134 |
* originally comes from. This can be a local or remote client. |
135 |
* \param parc Integer holding the number of supplied arguments. |
136 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
137 |
* pointers. |
138 |
* \note Valid arguments for this command are: |
139 |
* - parv[0] = sender prefix |
140 |
* - parv[1] = name of target (optional; string can be a nick or server |
141 |
* and can also include wildcards) |
142 |
*/ |
143 |
static void |
144 |
ms_admin(struct Client *client_p, struct Client *source_p, |
145 |
int parc, char *parv[]) |
146 |
{ |
147 |
if (hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, |
148 |
parc, parv) != HUNTED_ISME) |
149 |
return; |
150 |
|
151 |
if (IsClient(source_p)) |
152 |
execute_callback(admin_cb, source_p, parc, parv); |
153 |
} |
154 |
|
155 |
/* do_admin() |
156 |
* |
157 |
* inputs - pointer to client to report to |
158 |
* output - none |
159 |
* side effects - admin info is sent to client given |
160 |
*/ |
161 |
static void * |
162 |
do_admin(va_list args) |
163 |
{ |
164 |
struct Client *source_p = va_arg(args, struct Client *); |
165 |
const char *me_name; |
166 |
const char *nick; |
167 |
|
168 |
me_name = ID_or_name(&me, source_p->from); |
169 |
nick = ID_or_name(source_p, source_p->from); |
170 |
|
171 |
sendto_one(source_p, form_str(RPL_ADMINME), |
172 |
me_name, nick, me.name); |
173 |
if (AdminInfo.name != NULL) |
174 |
sendto_one(source_p, form_str(RPL_ADMINLOC1), |
175 |
me_name, nick, AdminInfo.name); |
176 |
if (AdminInfo.description != NULL) |
177 |
sendto_one(source_p, form_str(RPL_ADMINLOC2), |
178 |
me_name, nick, AdminInfo.description); |
179 |
if (AdminInfo.email != NULL) |
180 |
sendto_one(source_p, form_str(RPL_ADMINEMAIL), |
181 |
me_name, nick, AdminInfo.email); |
182 |
|
183 |
return NULL; |
184 |
} |