1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 /* $ModDesc: RLINE: Regexp user banning. */
19 /* $CompileFlags: exec("pcre-config --cflags") */
20 /* $LinkerFlags: exec("pcre-config --libs") rpath("pcre-config --libs") -lpcre */
23 #pragma comment(lib, "pcre.lib")
26 class CoreExport RLine : public XLine
31 * @param s_time The set time
32 * @param d The duration of the xline
33 * @param src The sender of the xline
34 * @param re The reason of the xline
35 * @param regex Pattern to match with
38 RLine(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char* regexs) : XLine(Instance, s_time, d, src, re, "K")
45 regex = pcre_compile(regexs, 0, &error, &erroffset, NULL);
49 ServerInstance->SNO->WriteToSnoMask('x',"Error in regular expression: %s at offset %d: %s\n", regexs, erroffset, error);
50 throw CoreException("Bad regex pattern.");
61 virtual bool Matches(User *u)
63 std::string compare = compare.assign(u->nick) + "!" + u->ident + "@" + u->host + " " + u->fullname;
65 ServerInstance->Log(DEBUG, "Matching " + matchtext + " against string " + compare);
67 if (pcre_exec(regex, NULL, compare.c_str(), compare.length(), 0, 0, NULL, 0) > -1)
76 virtual bool Matches(const std::string&); // Ignored for us
78 virtual void Apply(User* u)
80 DefaultApply(u, "R", true);
83 virtual void DisplayExpiry()
85 ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed R-Line %s (set by %s %d seconds ago)", this->matchtext.c_str(), this->source, this->duration);
88 virtual const char* Displayable()
90 return matchtext.c_str();
93 std::string matchtext;
99 /** An XLineFactory specialized to generate RLine* pointers
101 class CoreExport RLineFactory : public XLineFactory
104 RLineFactory(InspIRCd* Instance) : XLineFactory(Instance, "R") { }
108 XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
110 return new RLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
118 User* find = ServerInstance->FindNick(parameters[0]);
122 ih.second = find->GetIPString();
125 ih = ServerInstance->XLines->IdentSplit(parameters[0]);
127 if (ServerInstance->HostMatchesEveryone(ih.first+"@"+ih.second,user))
130 if (!strchr(parameters[0],'@'))
132 user->WriteServ("NOTICE %s :*** G-Line must contain a username, e.g. *@%s",user->nick,parameters[0]);
135 else if (strchr(parameters[0],'!'))
137 user->WriteServ("NOTICE %s :*** G-Line cannot contain a nickname!",user->nick);
141 long duration = ServerInstance->Duration(parameters[1]);
142 GLine* gl = new GLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], ih.first.c_str(), ih.second.c_str());
143 if (ServerInstance->XLines->AddLine(gl, user))
147 ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent G-line for %s.",user->nick,parameters[0]);
151 time_t c_requires_crap = duration + ServerInstance->Time();
152 ServerInstance->SNO->WriteToSnoMask('x',"%s added timed G-line for %s, expires on %s",user->nick,parameters[0],
153 ServerInstance->TimeString(c_requires_crap).c_str());
156 ServerInstance->XLines->ApplyLines();
161 user->WriteServ("NOTICE %s :*** G-Line for %s already exists",user->nick,parameters[0]);
167 if (ServerInstance->XLines->DelLine(parameters[0],"G",user))
169 ServerInstance->SNO->WriteToSnoMask('x',"%s Removed G-line on %s.",user->nick,parameters[0]);
173 user->WriteServ("NOTICE %s :*** G-line %s not found in list, try /stats g.",user->nick,parameters[0]);
178 class ModuleRLine : public Module
181 ModuleRLine(InspIRCd* Me) : Module(Me)
185 virtual ~ModuleRLine()
190 MODULE_INIT(ModuleRLine)