os_login.cpp

Go to the documentation of this file.
00001 /* OperServ core functions
00002  *
00003  * (C) 2003-2013 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 
00015 #include "module.h"
00016 
00017 class CommandOSLogin : public Command
00018 {
00019  public:
00020         CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1)
00021         {
00022                 this->SetDesc(Anope::printf(_("Login to %s"), Config->OperServ.c_str()));
00023                 this->SetSyntax(_("\037password\037"));
00024                 this->RequireUser(true);
00025         }
00026 
00027         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00028         {
00029                 const Anope::string &password = params[0];
00030 
00031                 User *u = source.GetUser();
00032                 Oper *o = source.nc->o;
00033                 if (o == NULL)
00034                         source.Reply(_("No oper block for your nick."));
00035                 else if (o->password.empty())
00036                         source.Reply(_("Your oper block doesn't require logging in."));
00037                 else if (u->HasExt("os_login_password_correct"))
00038                         source.Reply(_("You are already identified."));
00039                 else if (o->password != password)
00040                 {
00041                         source.Reply(PASSWORD_INCORRECT);
00042                         u->BadPassword();
00043                 }
00044                 else
00045                 {
00046                         Log(LOG_ADMIN, source, this) << "and successfully identified to " << source.service->nick;
00047                         u->Extend("os_login_password_correct");
00048                         source.Reply(_("Password accepted."));
00049                 }
00050 
00051                 return;
00052         }
00053 
00054         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00055         {
00056                 this->SendSyntax(source);
00057                 source.Reply(" ");
00058                 source.Reply(_("Logs you in to %s so you gain Services Operator privileges.\n"
00059                                 "This command may be unnecessary if your oper block is\n"
00060                                 "configured without a password."), source.service->nick.c_str());
00061                 return true;
00062         }
00063 };
00064 
00065 class CommandOSLogout : public Command
00066 {
00067  public:
00068         CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0)
00069         {
00070                 this->SetDesc(Anope::printf(_("Logout from %s"), Config->OperServ.c_str()));
00071                 this->SetSyntax("");
00072                 this->RequireUser(true);
00073         }
00074 
00075         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00076         {
00077                 User *u = source.GetUser();
00078                 Oper *o = source.nc->o;
00079                 if (o == NULL)
00080                         source.Reply(_("No oper block for your nick."));
00081                 else if (o->password.empty())
00082                         source.Reply(_("Your oper block doesn't require logging in."));
00083                 else if (!u->HasExt("os_login_password_correct"))
00084                         source.Reply(_("You are not identified."));
00085                 else
00086                 {
00087                         Log(LOG_ADMIN, source, this);
00088                         u->Shrink("os_login_password_correct");
00089                         source.Reply(_("You have been logged out."));
00090                 }
00091         }
00092 
00093         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00094         {
00095                 this->SendSyntax(source);
00096                 source.Reply(" ");
00097                 source.Reply(_("Logs you out from %s so you lose Services Operator privileges.\n"
00098                                 "This command is only useful if your oper block is configured\n"
00099                                 "with a password."), source.service->nick.c_str());
00100                 return true;
00101         }
00102 };
00103 
00104 class OSLogin : public Module
00105 {
00106         CommandOSLogin commandoslogin;
00107         CommandOSLogout commandoslogout;
00108 
00109  public:
00110         OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00111                 commandoslogin(this), commandoslogout(this)
00112         {
00113                 this->SetAuthor("Anope");
00114 
00115                 ModuleManager::Attach(I_IsServicesOper, this);
00116         }
00117 
00118         ~OSLogin()
00119         {
00120                 for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
00121                         it->second->Shrink("os_login_password_correct");
00122         }
00123 
00124         EventReturn IsServicesOper(User *u) anope_override
00125         {
00126                 if (!u->Account()->o->password.empty())
00127                 {
00128                         if (u->HasExt("os_login_password_correct"))
00129                                 return EVENT_ALLOW;
00130                         return EVENT_STOP;
00131                 }
00132 
00133                 return EVENT_CONTINUE;
00134         }
00135 };
00136 
00137 MODULE_INIT(OSLogin)