1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #include "inspircd_config.h"
19 #include "configreader.h"
21 #include <sys/errno.h>
22 #include <sys/ioctl.h>
23 #include <sys/utsname.h>
29 #include <sys/types.h>
31 #include <sys/resource.h>
34 #define RUSAGE_CHILDREN -1
45 #include "inspstring.h"
46 #include "helperfuncs.h"
48 #include "socketengine.h"
50 #include "command_parse.h"
52 extern InspIRCd* ServerInstance;
54 const long duration_m = 60;
55 const long duration_h = duration_m * 60;
56 const long duration_d = duration_h * 24;
57 const long duration_w = duration_d * 7;
58 const long duration_y = duration_w * 52;
60 /* XXX - these really belong in helperfuncs perhaps -- w00t */
61 bool is_uline(const char* server)
68 return (find(ServerInstance->Config->ulines.begin(),ServerInstance->Config->ulines.end(),server) != ServerInstance->Config->ulines.end());
71 int operstrcmp(const char* data,const char* input)
74 FOREACH_RESULT(I_OnOperCompare,OnOperCompare(data,input))
75 ServerInstance->Log(DEBUG,"operstrcmp: %d",MOD_RESULT);
80 ServerInstance->Log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
81 return strcmp(data,input);
84 long duration(const char* str)
90 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
94 return duration(n.c_str());
97 for (char* i = (char*)str; *i; i++)
99 // if we have digits, build up a string for the value in n_field,
100 // up to 10 digits in size.
101 if ((*i >= '0') && (*i <= '9'))
103 strlcat(n_field,i,10);
107 // we dont have a digit, check for numeric tokens
111 total += atoi(n_field);
115 total += (atoi(n_field)*duration_m);
119 total += (atoi(n_field)*duration_h);
123 total += (atoi(n_field)*duration_d);
127 total += (atoi(n_field)*duration_w);
131 total += (atoi(n_field)*duration_y);
137 // add trailing seconds
138 total += atoi(n_field);
143 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
145 bool host_matches_everyone(const std::string &mask, userrec* user)
148 char itrigger[MAXBUF];
151 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
152 strlcpy(itrigger,"95.5",MAXBUF);
154 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","hostmasks", 0))
157 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
159 strlcpy(buffer,u->second->ident,MAXBUF);
160 charlcat(buffer,'@',MAXBUF);
161 strlcat(buffer,u->second->host,MAXBUF);
162 if (match(buffer,mask.c_str()))
165 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
166 if (percent > (float)atof(itrigger))
168 ServerInstance->WriteOpers("*** \2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick,mask.c_str(),percent);
174 bool ip_matches_everyone(const std::string &ip, userrec* user)
176 char itrigger[MAXBUF];
179 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
180 strlcpy(itrigger,"95.5",MAXBUF);
182 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","ipmasks",0))
185 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
187 if (match(u->second->GetIPString(),ip.c_str(),true))
191 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
192 if (percent > (float)atof(itrigger))
194 ServerInstance->WriteOpers("*** \2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick,ip.c_str(),percent);
200 bool nick_matches_everyone(const std::string &nick, userrec* user)
202 char itrigger[MAXBUF];
205 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
206 strlcpy(itrigger,"95.5",MAXBUF);
208 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","nickmasks",0))
211 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
213 if (match(u->second->nick,nick.c_str()))
217 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
218 if (percent > (float)atof(itrigger))
220 ServerInstance->WriteOpers("*** \2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick,nick.c_str(),percent);