void OnLookupComplete(const Query *record) override { if (!user || user->Quitting()) return; const ResourceRecord &ans_record = record->answers[0]; // Replies should be in 127.0.0.0/8 if (ans_record.rdata.find("127.") != 0) return; sockaddrs sresult; sresult.pton(AF_INET, ans_record.rdata); int result = sresult.sa4.sin_addr.s_addr >> 24; Blacklist::Reply *reply = blacklist.Find(result); if (!blacklist.replies.empty() && !reply) return; if (reply && reply->allow_account && user->Account()) return; Anope::string reason = this->blacklist.reason, addr = user->ip.addr(); reason = reason.replace_all_cs("%n", user->nick); reason = reason.replace_all_cs("%u", user->GetIdent()); reason = reason.replace_all_cs("%g", user->realname); reason = reason.replace_all_cs("%h", user->host); reason = reason.replace_all_cs("%i", addr); reason = reason.replace_all_cs("%r", reply ? reply->reason : ""); reason = reason.replace_all_cs("%N", Config->GetBlock("networkinfo")->Get<Anope::string>("networkname")); ServiceBot *OperServ = Config->GetClient("OperServ"); creator->logger.Category("dnsbl").Bot(OperServ).Log(_("{0} ({1}) appears in {2}"), user->GetMask(), addr, this->blacklist.name); XLine *x = Serialize::New<XLine *>(); x->SetMask("*@" + addr); x->SetBy(OperServ ? OperServ->nick : "m_dnsbl"); x->SetCreated(Anope::CurTime); x->SetExpires(Anope::CurTime + this->blacklist.bantime); x->SetReason(reason); x->SetID(XLineManager::GenerateUID()); if (this->add_to_akill && akills) { akills->AddXLine(x); akills->Send(NULL, x); } else { IRCD->Send<messages::Akill>(nullptr, x); delete x; } }
void SendAkill(User *u, XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) { if (!u) { /* * No user (this akill was just added), and contains nick and/or realname. * Find users that match and ban them. */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } XLine *old = x; if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ XLine *xl = Serialize::New<XLine *>(); xl->SetMask("*@" + u->host); xl->SetBy(old->GetBy()); xl->SetExpires(old->GetExpires()); xl->SetReason(old->GetReason()); xl->SetID(old->GetID()); old->GetManager()->AddXLine(xl); x = xl; Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); } /* Calculate the time left before this would expire, capping it at 2 days */ time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; Uplink::Send(Config->GetClient("OperServ"), "KLINE", timeleft, x->GetUser(), x->GetHost(), x->GetReason()); }