anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

os_set.cpp (7868B)

      1 /* OperServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandOSSet : public Command
     15 {
     16  private:
     17 	void DoList(CommandSource &source)
     18 	{
     19 		Log(LOG_ADMIN, source, this) << "LIST";
     20 
     21 		Anope::string index;
     22 
     23 		index = Anope::ReadOnly ? _("%s is enabled") : _("%s is disabled");
     24 		source.Reply(index.c_str(), "READONLY");
     25 		index = Anope::Debug ? _("%s is enabled") : _("%s is disabled");
     26 		source.Reply(index.c_str(), "DEBUG");
     27 		index = Anope::NoExpire ? _("%s is enabled") : _("%s is disabled");
     28 		source.Reply(index.c_str(), "NOEXPIRE");
     29 
     30 		return;
     31 	}
     32 
     33 	void DoSetReadOnly(CommandSource &source, const std::vector<Anope::string> &params)
     34 	{
     35 		const Anope::string &setting = params.size() > 1 ? params[1] : "";
     36 
     37 		if (setting.empty())
     38 		{
     39 			this->OnSyntaxError(source, "READONLY");
     40 			return;
     41 		}
     42 
     43 		if (setting.equals_ci("ON"))
     44 		{
     45 			Anope::ReadOnly = true;
     46 			Log(LOG_ADMIN, source, this) << "READONLY ON";
     47 			source.Reply(_("Services are now in \002read-only\002 mode."));
     48 		}
     49 		else if (setting.equals_ci("OFF"))
     50 		{
     51 			Anope::ReadOnly = false;
     52 			Log(LOG_ADMIN, source, this) << "READONLY OFF";
     53 			source.Reply(_("Services are now in \002read-write\002 mode."));
     54 		}
     55 		else
     56 			source.Reply(_("Setting for READONLY must be \002ON\002 or \002OFF\002."));
     57 
     58 		return;
     59 	}
     60 
     61 	void DoSetSuperAdmin(CommandSource &source, const std::vector<Anope::string> &params)
     62 	{
     63 		const Anope::string &setting = params.size() > 1 ? params[1] : "";
     64 
     65 		if (!source.GetUser())
     66 			return;
     67 
     68 		if (setting.empty())
     69 		{
     70 			this->OnSyntaxError(source, "SUPERADMIN");
     71 			return;
     72 		}
     73 
     74 		/**
     75 		 * Allow the user to turn super admin on/off
     76 		 *
     77 		 * Rob
     78 		 **/
     79 		bool super_admin = Config->GetModule(this->owner)->Get<bool>("superadmin");
     80 		if (!super_admin)
     81 			source.Reply(_("Super admin can not be set because it is not enabled in the configuration."));
     82 		else if (setting.equals_ci("ON"))
     83 		{
     84 			source.GetUser()->super_admin = true;
     85 			source.Reply(_("You are now a super admin."));
     86 			Log(LOG_ADMIN, source, this) << "SUPERADMIN ON";
     87 		}
     88 		else if (setting.equals_ci("OFF"))
     89 		{
     90 			source.GetUser()->super_admin = false;
     91 			source.Reply(_("You are no longer a super admin."));
     92 			Log(LOG_ADMIN, source, this) << "SUPERADMIN OFF";
     93 		}
     94 		else
     95 			source.Reply(_("Setting for super admin must be \002ON\002 or \002OFF\002."));
     96 
     97 		return;
     98 	}
     99 
    100 	void DoSetDebug(CommandSource &source, const std::vector<Anope::string> &params)
    101 	{
    102 		const Anope::string &setting = params.size() > 1 ? params[1] : "";
    103 
    104 		if (setting.empty())
    105 		{
    106 			this->OnSyntaxError(source, "DEBUG");
    107 			return;
    108 		}
    109 
    110 		if (setting.equals_ci("ON"))
    111 		{
    112 			Anope::Debug = 1;
    113 			Log(LOG_ADMIN, source, this) << "DEBUG ON";
    114 			source.Reply(_("Services are now in \002debug\002 mode."));
    115 		}
    116 		else if (setting.equals_ci("OFF") || setting == "0")
    117 		{
    118 			Log(LOG_ADMIN, source, this) << "DEBUG OFF";
    119 			Anope::Debug = 0;
    120 			source.Reply(_("Services are now in \002non-debug\002 mode."));
    121 		}
    122 		else
    123 		{
    124 			try
    125 			{
    126 				Anope::Debug = convertTo<int>(setting);
    127 				Log(LOG_ADMIN, source, this) << "DEBUG " << Anope::Debug;
    128 				source.Reply(_("Services are now in \002debug\002 mode (level %d)."), Anope::Debug);
    129 				return;
    130 			}
    131 			catch (const ConvertException &) { }
    132 
    133 			source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number."));
    134 		}
    135 
    136 		return;
    137 	}
    138 
    139 	void DoSetNoExpire(CommandSource &source, const std::vector<Anope::string> &params)
    140 	{
    141 		const Anope::string &setting = params.size() > 1 ? params[1] : "";
    142 
    143 		if (setting.empty())
    144 		{
    145 			this->OnSyntaxError(source, "NOEXPIRE");
    146 			return;
    147 		}
    148 
    149 		if (setting.equals_ci("ON"))
    150 		{
    151 			Anope::NoExpire = true;
    152 			Log(LOG_ADMIN, source, this) << "NOEXPIRE ON";
    153 			source.Reply(_("Services are now in \002no expire\002 mode."));
    154 		}
    155 		else if (setting.equals_ci("OFF"))
    156 		{
    157 			Anope::NoExpire = false;
    158 			Log(LOG_ADMIN, source, this) << "NOEXPIRE OFF";
    159 			source.Reply(_("Services are now in \002expire\002 mode."));
    160 		}
    161 		else
    162 			source.Reply(_("Setting for NOEXPIRE must be \002ON\002 or \002OFF\002."));
    163 
    164 		return;
    165 	}
    166  public:
    167 	CommandOSSet(Module *creator) : Command(creator, "operserv/set", 1, 2)
    168 	{
    169 		this->SetDesc(_("Set various global Services options"));
    170 		this->SetSyntax(_("\037option\037 \037setting\037"));
    171 	}
    172 
    173 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
    174 	{
    175 		const Anope::string &option = params[0];
    176 
    177 		if (option.equals_ci("LIST"))
    178 			return this->DoList(source);
    179 		else if (option.equals_ci("READONLY"))
    180 			return this->DoSetReadOnly(source, params);
    181 		else if (option.equals_ci("DEBUG"))
    182 			return this->DoSetDebug(source, params);
    183 		else if (option.equals_ci("NOEXPIRE"))
    184 			return this->DoSetNoExpire(source, params);
    185 		else if (option.equals_ci("SUPERADMIN"))
    186 			return this->DoSetSuperAdmin(source, params);
    187 		else
    188 			this->OnSyntaxError(source, "");
    189 
    190 		return;
    191 	}
    192 
    193 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    194 	{
    195 		if (subcommand.empty())
    196 		{
    197 			this->SendSyntax(source);
    198 			source.Reply(" ");
    199 			source.Reply(_("Sets various global Services options.  Option names\n"
    200 					"currently defined are:\n"
    201 					"    READONLY   Set read-only or read-write mode\n"
    202 					"    DEBUG      Activate or deactivate debug mode\n"
    203 					"    NOEXPIRE   Activate or deactivate no expire mode\n"
    204 					"    SUPERADMIN Activate or deactivate super admin mode\n"
    205 					"    LIST       List the options"));
    206 		}
    207 		else if (subcommand.equals_ci("LIST"))
    208 			source.Reply(_("Syntax: \002LIST\002\n"
    209 					" \n"
    210 					"Display the various %s settings."), source.service->nick.c_str());
    211 		else if (subcommand.equals_ci("READONLY"))
    212 			source.Reply(_("Syntax: \002READONLY {ON | OFF}\002\n"
    213 					" \n"
    214 					"Sets read-only mode on or off.  In read-only mode, normal\n"
    215 					"users will not be allowed to modify any Services data,\n"
    216 					"including channel and nickname access lists, etc.  IRCops\n"
    217 					"with sufficient Services privileges will be able to modify\n"
    218 					"Services' AKILL, SQLINE, SNLINE and ignore lists, drop,\n"
    219 					"suspend or forbid nicknames and channels, and manage news,\n"
    220 					"oper info and DNS, but any such changes will not be saved\n"
    221 					"unless read-only mode is deactivated before Services are\n"
    222 					"terminated or restarted.\n"
    223 					" \n"
    224 					"This option is equivalent to the command-line option\n"
    225 					"\002--readonly\002."));
    226 		else if (subcommand.equals_ci("DEBUG"))
    227 			source.Reply(_("Syntax: \002DEBUG {ON | OFF}\002\n"
    228 					" \n"
    229 					"Sets debug mode on or off.\n"
    230 					" \n"
    231 					"This option is equivalent to the command-line option\n"
    232 					"\002--debug\002."));
    233 		else if (subcommand.equals_ci("NOEXPIRE"))
    234 			source.Reply(_("Syntax: \002NOEXPIRE {ON | OFF}\002\n"
    235 					" \n"
    236 					"Sets no expire mode on or off. In no expire mode, nicks,\n"
    237 					"channels, akills and exceptions won't expire until the\n"
    238 					"option is unset.\n"
    239 					" \n"
    240 					"This option is equivalent to the command-line option\n"
    241 					"\002--noexpire\002."));
    242 		else if (subcommand.equals_ci("SUPERADMIN"))
    243 			source.Reply(_("Syntax: \002SUPERADMIN {ON | OFF}\002\n"
    244 					" \n"
    245 					"Setting this will grant you extra privileges such as the\n"
    246 					"ability to be \"founder\" on all channel's etc...\n"
    247 					" \n"
    248 					"This option is \002not\002 persistent, and should only be used when\n"
    249 					"needed, and set back to OFF when no longer needed."));
    250 		else
    251 			return false;
    252 		return true;
    253 	}
    254 };
    255 
    256 class OSSet : public Module
    257 {
    258 	CommandOSSet commandosset;
    259 
    260  public:
    261 	OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    262 		commandosset(this)
    263 	{
    264 	}
    265 };
    266 
    267 MODULE_INIT(OSSet)