InspIRCd  3.0
xline.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2019 Matt Schatz <[email protected]>
5  * Copyright (C) 2012-2013, 2017-2018, 2020 Sadie Powell <[email protected]>
6  * Copyright (C) 2012, 2019 Robby <[email protected]>
7  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
8  * Copyright (C) 2007 Dennis Friis <[email protected]>
9  * Copyright (C) 2006-2008 Robin Burchell <[email protected]>
10  * Copyright (C) 2004, 2006-2008, 2010 Craig Edwards <[email protected]>
11  *
12  * This file is part of InspIRCd. InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #pragma once
27 
35 class CoreExport XLine : public classbase
36 {
37  protected:
38 
44  void DefaultApply(User* u, const std::string &line, bool bancache);
45 
46  public:
47 
55  XLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& t)
56  : set_time(s_time)
57  , duration(d)
58  , source(src)
59  , reason(re)
60  , type(t)
61  , from_config(false)
62  {
63  expiry = set_time + duration;
64  }
65 
68  virtual ~XLine()
69  {
70  }
71 
75  virtual void SetCreateTime(time_t created)
76  {
77  set_time = created;
78  expiry = created + duration;
79  }
80 
86  virtual bool Matches(User *u) = 0;
87 
94  virtual bool Matches(const std::string &str) = 0;
95 
100  virtual void Apply(User* u);
101 
105  virtual void Unset() { }
106 
111  virtual void DisplayExpiry();
112 
120  virtual const std::string& Displayable() = 0;
121 
124  virtual void OnAdd() { }
125 
128  time_t set_time;
129 
132  unsigned long duration;
133 
136  std::string source;
137 
140  std::string reason;
141 
144  time_t expiry;
145 
149  const std::string type;
150 
151  // Whether this XLine was loaded from the server config.
152  bool from_config;
153 
154  virtual bool IsBurstable();
155 };
156 
159 class CoreExport KLine : public XLine
160 {
161  public:
162 
171  KLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
172  : XLine(s_time, d, src, re, "K"), identmask(ident), hostmask(host)
173  {
174  matchtext = this->identmask;
175  matchtext.append("@").append(this->hostmask);
176  }
177 
181  {
182  }
183 
184  bool Matches(User* u) CXX11_OVERRIDE;
185 
186  bool Matches(const std::string& str) CXX11_OVERRIDE;
187 
188  void Apply(User* u) CXX11_OVERRIDE;
189 
190  const std::string& Displayable() CXX11_OVERRIDE;
191 
192  bool IsBurstable() CXX11_OVERRIDE;
193 
196  std::string identmask;
199  std::string hostmask;
200 
201  std::string matchtext;
202 };
203 
206 class CoreExport GLine : public XLine
207 {
208  public:
217  GLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
218  : XLine(s_time, d, src, re, "G"), identmask(ident), hostmask(host)
219  {
220  matchtext = this->identmask;
221  matchtext.append("@").append(this->hostmask);
222  }
223 
227  {
228  }
229 
230  bool Matches(User* u) CXX11_OVERRIDE;
231 
232  bool Matches(const std::string& str) CXX11_OVERRIDE;
233 
234  void Apply(User* u) CXX11_OVERRIDE;
235 
236  const std::string& Displayable() CXX11_OVERRIDE;
237 
240  std::string identmask;
243  std::string hostmask;
244 
245  std::string matchtext;
246 };
247 
250 class CoreExport ELine : public XLine
251 {
252  public:
261  ELine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
262  : XLine(s_time, d, src, re, "E"), identmask(ident), hostmask(host)
263  {
264  matchtext = this->identmask;
265  matchtext.append("@").append(this->hostmask);
266  }
267 
268  ~ELine()
269  {
270  }
271 
272  bool Matches(User* u) CXX11_OVERRIDE;
273 
274  bool Matches(const std::string& str) CXX11_OVERRIDE;
275 
276  void Unset() CXX11_OVERRIDE;
277 
278  void OnAdd() CXX11_OVERRIDE;
279 
280  const std::string& Displayable() CXX11_OVERRIDE;
281 
284  std::string identmask;
287  std::string hostmask;
288 
289  std::string matchtext;
290 };
291 
294 class CoreExport ZLine : public XLine
295 {
296  public:
304  ZLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ip)
305  : XLine(s_time, d, src, re, "Z"), ipaddr(ip)
306  {
307  }
308 
312  {
313  }
314 
315  bool Matches(User* u) CXX11_OVERRIDE;
316 
317  bool Matches(const std::string& str) CXX11_OVERRIDE;
318 
319  void Apply(User* u) CXX11_OVERRIDE;
320 
321  const std::string& Displayable() CXX11_OVERRIDE;
322 
325  std::string ipaddr;
326 };
327 
330 class CoreExport QLine : public XLine
331 {
332  public:
340  QLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& nickname)
341  : XLine(s_time, d, src, re, "Q"), nick(nickname)
342  {
343  }
344 
348  {
349  }
350  bool Matches(User* u) CXX11_OVERRIDE;
351 
352  bool Matches(const std::string& str) CXX11_OVERRIDE;
353 
354  void Apply(User* u) CXX11_OVERRIDE;
355 
356  const std::string& Displayable() CXX11_OVERRIDE;
357 
360  std::string nick;
361 };
362 
370 class CoreExport XLineFactory
371 {
372  protected:
373 
374  std::string type;
375 
376  public:
377 
381  XLineFactory(const std::string &t) : type(t) { }
382 
386  virtual const std::string& GetType() { return type; }
387 
396  virtual XLine* Generate(time_t set_time, unsigned long duration, const std::string& source, const std::string& reason, const std::string& xline_specific_mask) = 0;
397 
398  virtual bool AutoApplyToUserList(XLine* x) { return true; }
399 
402  virtual ~XLineFactory() { }
403 };
404 
409 class CoreExport XLineManager
410 {
411  protected:
414  std::vector<XLine *> pending_lines;
415 
418  XLineFactMap line_factory;
419 
425  XLineContainer lookup_lines;
426 
427  public:
428 
431  XLineManager();
432 
435  ~XLineManager();
436 
440  IdentHostPair IdentSplit(const std::string &ident_and_host);
441 
444  void CheckELines();
445 
452  XLineLookup* GetAll(const std::string &type);
453 
456  void DelAll(const std::string &type);
457 
461  std::vector<std::string> GetAllTypes();
462 
468  bool AddLine(XLine* line, User* user);
469 
478  bool DelLine(const char* hostmask, const std::string& type, std::string& reason, User* user, bool simulate = false);
479 
490  bool RegisterFactory(XLineFactory* xlf);
491 
496  bool UnregisterFactory(XLineFactory* xlf);
497 
502  XLineFactory* GetFactory(const std::string &type);
503 
509  XLine* MatchesLine(const std::string &type, User* user);
510 
516  XLine* MatchesLine(const std::string &type, const std::string &pattern);
517 
523  void ExpireLine(ContainerIter container, LookupIter item, bool silent = false);
524 
529  void ApplyLines();
530 
532  DEPRECATED_METHOD(void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats));
533 
539  bool InvokeStats(const std::string& type, Stats::Context& context);
540 
542  void ExpireRemovedConfigLines(const std::string& type, const insp::flat_set<std::string>& configlines);
543 };
Definition: xline.h:251
ELine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:261
Definition: xline.h:207
GLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:217
~GLine()
Definition: xline.h:226
Definition: xline.h:160
~KLine()
Definition: xline.h:180
KLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:171
Definition: xline.h:331
QLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &nickname)
Definition: xline.h:340
~QLine()
Definition: xline.h:347
Definition: users.h:247
Definition: xline.h:371
virtual ~XLineFactory()
Definition: xline.h:402
virtual XLine * Generate(time_t set_time, unsigned long duration, const std::string &source, const std::string &reason, const std::string &xline_specific_mask)=0
XLineFactory(const std::string &t)
Definition: xline.h:381
virtual const std::string & GetType()
Definition: xline.h:386
Definition: xline.h:36
std::string reason
Definition: xline.h:140
virtual ~XLine()
Definition: xline.h:68
virtual void Unset()
Definition: xline.h:105
virtual void SetCreateTime(time_t created)
Definition: xline.h:75
time_t set_time
Definition: xline.h:128
virtual void OnAdd()
Definition: xline.h:124
unsigned long duration
Definition: xline.h:132
const std::string type
Definition: xline.h:149
time_t expiry
Definition: xline.h:144
virtual bool Matches(const std::string &str)=0
XLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &t)
Definition: xline.h:55
std::string source
Definition: xline.h:136
virtual const std::string & Displayable()=0
Definition: xline.h:410
XLineContainer lookup_lines
Definition: xline.h:425
XLineFactMap line_factory
Definition: xline.h:418
DEPRECATED_METHOD(void InvokeStats(const std::string &type, unsigned int numeric, Stats::Context &stats))
std::vector< XLine * > pending_lines
Definition: xline.h:414
Definition: xline.h:295
~ZLine()
Definition: xline.h:311
ZLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ip)
Definition: xline.h:304
Definition: base.h:46
Definition: flat_map.h:210