ns_saset.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 class CommandNSSASet : public Command
00017 {
00018  public:
00019         CommandNSSASet(Module *creator) : Command(creator, "nickserv/saset", 2, 4)
00020         {
00021                 this->SetDesc(_("Set SET-options on another nickname"));
00022                 this->SetSyntax(_("\037option\037 \037nickname\037 \037parameters\037"));
00023         }
00024 
00025         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00026         {
00027                 this->OnSyntaxError(source, "");
00028                 return;
00029         }
00030 
00031         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00032         {
00033                 this->SendSyntax(source);
00034                 source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
00035                 Anope::string this_name = source.command;
00036                 for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it)
00037                 {
00038                         const Anope::string &c_name = it->first;
00039                         const CommandInfo &info = it->second;
00040 
00041                         if (c_name.find_ci(this_name + " ") == 0)
00042                         {
00043                                 ServiceReference<Command> command("Command", info.name);
00044                                 if (command)
00045                                 {
00046                                         source.command = c_name;
00047                                         command->OnServHelp(source);
00048                                 }
00049                         }
00050                 }
00051                 source.Reply(_("Type \002%s%s HELP SASET \037option\037\002 for more information\n"
00052                                 "on a specific option. The options will be set on the given\n"
00053                                 "\037nickname\037."), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
00054                 return true;
00055         }
00056 };
00057 
00058 class CommandNSSASetPassword : public Command
00059 {
00060  public:
00061         CommandNSSASetPassword(Module *creator) : Command(creator, "nickserv/saset/password", 2, 2)
00062         {
00063                 this->SetDesc(_("Set the nickname password"));
00064                 this->SetSyntax(_("\037nickname\037 \037new-password\037"));
00065         }
00066 
00067         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00068         {
00069                 const NickAlias *setter_na = NickAlias::Find(params[0]);
00070                 if (setter_na == NULL)
00071                 {
00072                         source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str());
00073                         return;
00074                 }
00075                 NickCore *nc = setter_na->nc;
00076 
00077                 size_t len = params[1].length();
00078 
00079                 if (Config->NSSecureAdmins && source.nc != nc && nc->IsServicesOper())
00080                 {
00081                         source.Reply(_("You may not change the password of other services operators."));
00082                         return;
00083                 }
00084                 else if (nc->display.equals_ci(params[1]) || (Config->StrictPasswords && len < 5))
00085                 {
00086                         source.Reply(MORE_OBSCURE_PASSWORD);
00087                         return;
00088                 }
00089                 else if (len > Config->PassLen)
00090                 {
00091                         source.Reply(PASSWORD_TOO_LONG);
00092                         return;
00093                 }
00094 
00095                 Anope::Encrypt(params[1], nc->pass);
00096                 Anope::string tmp_pass;
00097                 if (Anope::Decrypt(nc->pass, tmp_pass) == 1)
00098                         source.Reply(_("Password for \002%s\002 changed to \002%s\002."), nc->display.c_str(), tmp_pass.c_str());
00099                 else
00100                         source.Reply(_("Password for \002%s\002 changed."), nc->display.c_str());
00101 
00102                 return;
00103         }
00104 
00105         bool OnHelp(CommandSource &source, const Anope::string &) anope_override
00106         {
00107                 this->SendSyntax(source);
00108                 source.Reply(" ");
00109                 source.Reply(_("Changes the password used to identify as the nick's owner."));
00110                 return true;
00111         }
00112 };
00113 
00114 class NSSASet : public Module
00115 {
00116         CommandNSSASet commandnssaset;
00117         CommandNSSASetPassword commandnssasetpassword;
00118 
00119  public:
00120         NSSASet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00121                 commandnssaset(this), commandnssasetpassword(this)
00122         {
00123                 this->SetAuthor("Anope");
00124 
00125         }
00126 };
00127 
00128 MODULE_INIT(NSSASet)