ns_sendpass.cpp

Go to the documentation of this file.
00001 /* NickServ core functions
00002  *
00003  * (C) 2003-2012 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  */
00011 
00012 /*************************************************************************/
00013 
00014 #include "module.h"
00015 
00016 static bool SendPassMail(User *u, const NickAlias *na, const BotInfo *bi, const Anope::string &pass);
00017 
00018 class CommandNSSendPass : public Command
00019 {
00020  public:
00021         CommandNSSendPass(Module *creator) : Command(creator, "nickserv/sendpass", 1, 1)
00022         {
00023                 this->SetFlag(CFLAG_ALLOW_UNREGISTERED);
00024                 this->SetDesc(_("Forgot your password? Try this"));
00025                 this->SetSyntax(_("\037nickname\037"));
00026         }
00027 
00028         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00029         {
00030                 const Anope::string &nick = params[0];
00031                 const NickAlias *na;
00032 
00033                 if (Config->RestrictMail && !source.HasCommand("nickserv/sendpass"))
00034                         source.Reply(ACCESS_DENIED);
00035                 else if (!(na = NickAlias::Find(nick)))
00036                         source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
00037                 else
00038                 {
00039                         Anope::string tmp_pass;
00040                         if (Anope::Decrypt(na->nc->pass, tmp_pass) == 1)
00041                         {
00042                                 if (SendPassMail(source.GetUser(), na, source.service, tmp_pass))
00043                                 {
00044                                         Log(Config->RestrictMail ? LOG_ADMIN : LOG_COMMAND, source, this) << "for " << na->nick;
00045                                         source.Reply(_("Password of \002%s\002 has been sent."), nick.c_str());
00046                                 }
00047                         }
00048                         else
00049                                 source.Reply(_("%s command unavailable because encryption is in use."), source.command.c_str());
00050                 }
00051 
00052                 return;
00053         }
00054 
00055         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00056         {
00057                 this->SendSyntax(source);
00058                 source.Reply(" ");
00059                 source.Reply(_("Send the password of the given nickname to the e-mail address\n"
00060                                 "set in the nickname record. This command is really useful\n"
00061                                 "to deal with lost passwords.\n"
00062                                 " \n"
00063                                 "May be limited to \002IRC operators\002 on certain networks."));
00064                 return true;
00065         }
00066 };
00067 
00068 class NSSendPass : public Module
00069 {
00070         CommandNSSendPass commandnssendpass;
00071 
00072  public:
00073         NSSendPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00074                 commandnssendpass(this)
00075         {
00076                 this->SetAuthor("Anope");
00077 
00078                 if (!Config->UseMail)
00079                         throw ModuleException("Not using mail.");
00080 
00081                 Anope::string tmp_pass = "plain:tmp";
00082                 if (Anope::Decrypt(tmp_pass, tmp_pass) == -1)
00083                         throw ModuleException("Incompatible with the encryption module being used");
00084 
00085         }
00086 };
00087 
00088 static bool SendPassMail(User *u, const NickAlias *na, const BotInfo *bi, const Anope::string &pass)
00089 {
00090         Anope::string subject = Language::Translate(na->nc, Config->MailSendpassSubject.c_str());
00091         Anope::string message = Language::Translate(na->nc, Config->MailSendpassMessage.c_str());
00092 
00093         subject = subject.replace_all_cs("%n", na->nick);
00094         subject = subject.replace_all_cs("%N", Config->NetworkName);
00095         subject = subject.replace_all_cs("%p", pass);
00096 
00097         message = message.replace_all_cs("%n", na->nick);
00098         message = message.replace_all_cs("%N", Config->NetworkName);
00099         message = message.replace_all_cs("%p", pass);
00100 
00101         return Mail::Send(u, na->nc, bi, subject, message);
00102 }
00103 
00104 MODULE_INIT(NSSendPass)