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