1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_links.c: Shows what servers are currently connected. |
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 "client.h" |
27 |
#include "irc_string.h" |
28 |
#include "ircd.h" |
29 |
#include "numeric.h" |
30 |
#include "s_serv.h" |
31 |
#include "send.h" |
32 |
#include "conf.h" |
33 |
#include "motd.h" |
34 |
#include "parse.h" |
35 |
#include "modules.h" |
36 |
|
37 |
|
38 |
static void |
39 |
do_links(struct Client *source_p, int parc, char *parv[]) |
40 |
{ |
41 |
sendto_realops_flags(UMODE_SPY, L_ALL, |
42 |
"LINKS requested by %s (%s@%s) [%s]", |
43 |
source_p->name, |
44 |
source_p->username, source_p->host, |
45 |
source_p->servptr->name); |
46 |
|
47 |
if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.flatten_links) |
48 |
{ |
49 |
const char *mask = (parc > 2 ? parv[2] : parv[1]); |
50 |
const char *me_name, *nick, *p; |
51 |
struct Client *target_p; |
52 |
dlink_node *ptr; |
53 |
|
54 |
me_name = ID_or_name(&me, source_p->from); |
55 |
nick = ID_or_name(source_p, source_p->from); |
56 |
|
57 |
DLINK_FOREACH(ptr, global_serv_list.head) |
58 |
{ |
59 |
target_p = ptr->data; |
60 |
|
61 |
/* skip hidden servers */ |
62 |
if (IsHidden(target_p)) |
63 |
if (!HasUMode(source_p, UMODE_OPER)) |
64 |
continue; |
65 |
|
66 |
if (!EmptyString(mask) && !match(mask, target_p->name)) |
67 |
continue; |
68 |
|
69 |
if (target_p->info[0]) |
70 |
{ |
71 |
if ((p = strchr(target_p->info, ']'))) |
72 |
p += 2; /* skip the nasty [IP] part */ |
73 |
else |
74 |
p = target_p->info; |
75 |
} |
76 |
else |
77 |
p = "(Unknown Location)"; |
78 |
|
79 |
/* We just send the reply, as if they are here there's either no SHIDE, |
80 |
* or they're an oper.. |
81 |
*/ |
82 |
sendto_one(source_p, form_str(RPL_LINKS), |
83 |
me_name, nick, |
84 |
target_p->name, target_p->servptr->name, |
85 |
target_p->hopcount, p); |
86 |
} |
87 |
|
88 |
sendto_one(source_p, form_str(RPL_ENDOFLINKS), |
89 |
me_name, nick, |
90 |
EmptyString(mask) ? "*" : mask); |
91 |
} |
92 |
else |
93 |
{ |
94 |
/* |
95 |
* Print our own info so at least it looks like a normal links |
96 |
* then print out the file (which may or may not be empty) |
97 |
*/ |
98 |
sendto_one(source_p, form_str(RPL_LINKS), |
99 |
ID_or_name(&me, source_p->from), |
100 |
ID_or_name(source_p, source_p->from), |
101 |
me.name, me.name, 0, me.info); |
102 |
send_message_file(source_p, &ConfigFileEntry.linksfile); |
103 |
sendto_one(source_p, form_str(RPL_ENDOFLINKS), |
104 |
ID_or_name(&me, source_p->from), |
105 |
ID_or_name(source_p, source_p->from), "*"); |
106 |
} |
107 |
} |
108 |
|
109 |
static void |
110 |
mo_links(struct Client *client_p, struct Client *source_p, |
111 |
int parc, char *parv[]) |
112 |
{ |
113 |
if (parc > 2) |
114 |
if (!ConfigFileEntry.disable_remote || HasUMode(source_p, UMODE_OPER)) |
115 |
if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, |
116 |
parc, parv) != HUNTED_ISME) |
117 |
return; |
118 |
|
119 |
do_links(source_p, parc, parv); |
120 |
} |
121 |
|
122 |
/* |
123 |
* m_links - LINKS message handler |
124 |
* parv[0] = sender prefix |
125 |
* parv[1] = servername mask |
126 |
* or |
127 |
* parv[0] = sender prefix |
128 |
* parv[1] = server to query |
129 |
* parv[2] = servername mask |
130 |
*/ |
131 |
static void |
132 |
m_links(struct Client *client_p, struct Client *source_p, |
133 |
int parc, char *parv[]) |
134 |
{ |
135 |
static time_t last_used = 0; |
136 |
|
137 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
138 |
{ |
139 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
140 |
me.name, source_p->name); |
141 |
return; |
142 |
} |
143 |
|
144 |
last_used = CurrentTime; |
145 |
|
146 |
if (!ConfigServerHide.flatten_links) |
147 |
{ |
148 |
mo_links(client_p, source_p, parc, parv); |
149 |
return; |
150 |
} |
151 |
|
152 |
do_links(source_p, parc, parv); |
153 |
} |
154 |
|
155 |
/* |
156 |
* ms_links - LINKS message handler |
157 |
* parv[0] = sender prefix |
158 |
* parv[1] = servername mask |
159 |
* or |
160 |
* parv[0] = sender prefix |
161 |
* parv[1] = server to query |
162 |
* parv[2] = servername mask |
163 |
*/ |
164 |
static void |
165 |
ms_links(struct Client *client_p, struct Client *source_p, |
166 |
int parc, char *parv[]) |
167 |
{ |
168 |
if (hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, |
169 |
parc, parv) != HUNTED_ISME) |
170 |
return; |
171 |
|
172 |
if (IsClient(source_p)) |
173 |
m_links(client_p, source_p, parc, parv); |
174 |
} |
175 |
|
176 |
static struct Message links_msgtab = { |
177 |
"LINKS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
178 |
{m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore} |
179 |
}; |
180 |
|
181 |
static void |
182 |
module_init(void) |
183 |
{ |
184 |
mod_add_cmd(&links_msgtab); |
185 |
} |
186 |
|
187 |
static void |
188 |
module_exit(void) |
189 |
{ |
190 |
mod_del_cmd(&links_msgtab); |
191 |
} |
192 |
|
193 |
struct module module_entry = { |
194 |
.node = { NULL, NULL, NULL }, |
195 |
.name = NULL, |
196 |
.version = "$Revision$", |
197 |
.handle = NULL, |
198 |
.modinit = module_init, |
199 |
.modexit = module_exit, |
200 |
.flags = 0 |
201 |
}; |