#include "module.h" #define AUTHOR "DukePyrolator" #define VERSION "0.9 for anope 1.9.4 only" void DoAutoIdentify(User *u) { NickAlias *na = findnick(u->nick); if (!na) return; if (u->IsIdentified() && (u->Account() == na->nc)) return; if ((na->HasFlag(NS_FORBIDDEN)) || (na->nc->HasFlag(NI_SUSPENDED))) return; if (na->nc->access.empty()) // access list is empty return; if (u->fingerprint.empty()) // user is not using ssl return; for (unsigned i = 0; i < na->nc->access.size(); i++) { Anope::string access = na->nc->GetAccess(i); if (u->fingerprint.equals_cs(access)) { u->UpdateHost(); na->last_realname = u->realname; na->last_seen = time(NULL); u->Login(na->nc); ircdproto->SendAccountLogin(u, u->Account()); ircdproto->SetAutoIdentificationToken(u); Log() << NickServ->nick << ": " << u->GetMask() << "automatically identified for group " << u->Account()->display << " by SSL Fingerprint"; u->SendMessage(NickServ, "SSL Fingerprint accepted. You are now recognized."); if (ircd->vhost) do_on_id(u); if (Config->NSModeOnID) do_setmodes(u); FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); if (Config->NSForceEmail && u->IsIdentified() && u->Account()->email.empty()) { u->SendMessage(NickServ, _("You must now supply an e-mail for your nick.\n" "This e-mail will allow you to retrieve your password in\n" "case you forget it.")); u->SendMessage(NickServ, _("Type \002%R%S SET EMAIL \037e-mail\037\002 in order to set your e-mail.\n" "Your privacy is respected; this e-mail won't be given to\n" "any third-party person.")); } if (u->IsIdentified()) check_memos(u); } } } EventReturn DoOnAccess(User *u, const std::vector ¶ms) { Anope::string cmd = params[0]; Anope::string mask = params.size() > 1 ? params[1] : ""; if (!u->IsIdentified()) return EVENT_CONTINUE; // nick not identified if (mask.empty()) return EVENT_CONTINUE; // let it handle by ns_access if (mask.find('@') != Anope::string::npos) return EVENT_CONTINUE; // let it handle by ns_access if (cmd.equals_ci("ADD") && mask.equals_ci("fingerprint")) { if (!u->fingerprint.empty()) { if (u->Account()->access.size() >= Config->NSAccessMax) { u->SendMessage(NickServ, _("Sorry, you can only have %d access entries for a nickname."), Config->NSAccessMax); return EVENT_STOP; } if (u->Account()->FindAccess(u->fingerprint)) { u->SendMessage(NickServ, _("Mask \002%s\002 already present on your access list."), u->fingerprint.c_str()); return EVENT_STOP; } u->Account()->AddAccess(u->fingerprint); u->SendMessage(NickServ, _("\002%s\002 added to your access list."), u->fingerprint.c_str()); return EVENT_STOP; } else { u->SendMessage(NickServ, "You have no SSL Fingerprint to add"); return EVENT_STOP; } } if (cmd.equals_ci("DEL")) { if (mask.equals_ci("fingerprint")) { if (!u->fingerprint.empty()) { if (u->Account()->FindAccess(u->fingerprint)) { u->SendMessage(NickServ, _("\002%s\002 deleted from your access list."), u->fingerprint.c_str()); u->Account()->EraseAccess(u->fingerprint); } else { u->SendMessage(NickServ, _("\002%s\002 not found on your access list."), u->fingerprint.c_str()); } } else { u->SendMessage(NickServ, "You have no SSL Fingerprint to delete"); } return EVENT_STOP; } else if (u->Account()->FindAccess(mask)) { u->SendMessage(NickServ, _("\002%s\002 deleted from your access list."), mask.c_str()); u->Account()->EraseAccess(mask); return EVENT_STOP; } } return EVENT_CONTINUE; } class NSFingerprint : public Module { public: NSFingerprint(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { ModuleManager::Attach(I_OnUserNickChange, this); ModuleManager::Attach(I_OnPreCommand, this); ModuleManager::Attach(I_OnUserLogoff, this); ModuleManager::Attach(I_OnFingerprint, this); this->SetAuthor(AUTHOR); this->SetVersion(VERSION); this->SetType(THIRD); } ~NSFingerprint() { } void OnFingerprint(User *u) { DoAutoIdentify(u); } void OnUserNickChange(User *u, const Anope::string &oldnick) // called on event nickchange { DoAutoIdentify(u); } EventReturn OnPreCommand(CommandSource &source, Command *command, const std::vector ¶ms) { if ((source.service == NickServ) && (command->name.equals_ci("ACCESS"))) return DoOnAccess(source.u, params); return EVENT_CONTINUE; } }; MODULE_INIT(NSFingerprint)