00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 class CommandOSSet : public Command
00017 {
00018 private:
00019 void DoList(CommandSource &source)
00020 {
00021 Log(LOG_ADMIN, source, this);
00022
00023 Anope::string index;
00024
00025 index = Anope::ReadOnly ? _("%s is enabled") : _("%s is disabled");
00026 source.Reply(index.c_str(), "READONLY");
00027 index = Anope::Debug ? _("%s is enabled") : _("%s is disabled");
00028 source.Reply(index.c_str(), "DEBUG");
00029 index = Anope::NoExpire ? _("%s is enabled") : _("%s is disabled");
00030 source.Reply(index.c_str(), "NOEXPIRE");
00031
00032 return;
00033 }
00034
00035 void DoSetReadOnly(CommandSource &source, const std::vector<Anope::string> ¶ms)
00036 {
00037 const Anope::string &setting = params.size() > 1 ? params[1] : "";
00038
00039 if (setting.empty())
00040 {
00041 this->OnSyntaxError(source, "READONLY");
00042 return;
00043 }
00044
00045 if (setting.equals_ci("ON"))
00046 {
00047 Anope::ReadOnly = true;
00048 Log(LOG_ADMIN, source, this) << "READONLY ON";
00049 source.Reply(_("Services are now in \002read-only\002 mode."));
00050 }
00051 else if (setting.equals_ci("OFF"))
00052 {
00053 Anope::ReadOnly = false;
00054 Log(LOG_ADMIN, source, this) << "READONLY OFF";
00055 source.Reply(_("Services are now in \002read-write\002 mode."));
00056 }
00057 else
00058 source.Reply(_("Setting for READONLY must be \002ON\002 or \002OFF\002."));
00059
00060 return;
00061 }
00062
00063 void DoSetSuperAdmin(CommandSource &source, const std::vector<Anope::string> ¶ms)
00064 {
00065 const Anope::string &setting = params.size() > 1 ? params[1] : "";
00066
00067 if (!source.GetUser())
00068 return;
00069
00070 if (setting.empty())
00071 {
00072 this->OnSyntaxError(source, "SUPERADMIN");
00073 return;
00074 }
00075
00081 if (!Config->SuperAdmin)
00082 source.Reply(_("SuperAdmin can not be set because it is not enabled in the configuration."));
00083 else if (setting.equals_ci("ON"))
00084 {
00085 source.GetUser()->super_admin = true;
00086 source.Reply(_("You are now a SuperAdmin."));
00087 Log(LOG_ADMIN, source, this) << "SUPERADMIN ON";
00088 }
00089 else if (setting.equals_ci("OFF"))
00090 {
00091 source.GetUser()->super_admin = false;
00092 source.Reply(_("You are no longer a SuperAdmin."));
00093 Log(LOG_ADMIN, source, this) << "SUPERADMIN OFF";
00094 }
00095 else
00096 source.Reply(_("Setting for SuperAdmin must be \002ON\002 or \002OFF\002."));
00097
00098 return;
00099 }
00100
00101 void DoSetDebug(CommandSource &source, const std::vector<Anope::string> ¶ms)
00102 {
00103 const Anope::string &setting = params.size() > 1 ? params[1] : "";
00104
00105 if (setting.empty())
00106 {
00107 this->OnSyntaxError(source, "DEBUG");
00108 return;
00109 }
00110
00111 if (setting.equals_ci("ON"))
00112 {
00113 Anope::Debug = 1;
00114 Log(LOG_ADMIN, source, this) << "DEBUG ON";
00115 source.Reply(_("Services are now in \002debug\002 mode."));
00116 }
00117 else if (setting.equals_ci("OFF") || setting == "0")
00118 {
00119 Log(LOG_ADMIN, source, this) << "DEBUG OFF";
00120 Anope::Debug = 0;
00121 source.Reply(_("Services are now in \002non-debug\002 mode."));
00122 }
00123 else
00124 {
00125 try
00126 {
00127 Anope::Debug = convertTo<int>(setting);
00128 Log(LOG_ADMIN, source, this) << "DEBUG " << Anope::Debug;
00129 source.Reply(_("Services are now in \002debug\002 mode (level %d)."), Anope::Debug);
00130 return;
00131 }
00132 catch (const ConvertException &) { }
00133
00134 source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number."));
00135 }
00136
00137 return;
00138 }
00139
00140 void DoSetNoExpire(CommandSource &source, const std::vector<Anope::string> ¶ms)
00141 {
00142 const Anope::string &setting = params.size() > 1 ? params[1] : "";
00143
00144 if (setting.empty())
00145 {
00146 this->OnSyntaxError(source, "NOEXPIRE");
00147 return;
00148 }
00149
00150 if (setting.equals_ci("ON"))
00151 {
00152 Anope::NoExpire = true;
00153 Log(LOG_ADMIN, source, this) << "NOEXPIRE ON";
00154 source.Reply(_("Services are now in \002no expire\002 mode."));
00155 }
00156 else if (setting.equals_ci("OFF"))
00157 {
00158 Anope::NoExpire = false;
00159 Log(LOG_ADMIN, source, this) << "NOEXPIRE OFF";
00160 source.Reply(_("Services are now in \002expire\002 mode."));
00161 }
00162 else
00163 source.Reply(_("Setting for NOEXPIRE must be \002ON\002 or \002OFF\002."));
00164
00165 return;
00166 }
00167 public:
00168 CommandOSSet(Module *creator) : Command(creator, "operserv/set", 1, 2)
00169 {
00170 this->SetDesc(_("Set various global Services options"));
00171 this->SetSyntax(_("\037option\037 \037setting\037"));
00172 }
00173
00174 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00175 {
00176 const Anope::string &option = params[0];
00177
00178 if (option.equals_ci("LIST"))
00179 return this->DoList(source);
00180 else if (option.equals_ci("READONLY"))
00181 return this->DoSetReadOnly(source, params);
00182 else if (option.equals_ci("SUPERADMIN"))
00183 return this->DoSetSuperAdmin(source, params);
00184 else if (option.equals_ci("DEBUG"))
00185 return this->DoSetDebug(source, params);
00186 else if (option.equals_ci("NOEXPIRE"))
00187 return this->DoSetNoExpire(source, params);
00188 else
00189 this->OnSyntaxError(source, "");
00190
00191 return;
00192 }
00193
00194 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00195 {
00196 if (subcommand.empty())
00197 {
00198 this->SendSyntax(source);
00199 source.Reply(" ");
00200 source.Reply(_("Sets various global Services options. Option names\n"
00201 "currently defined are:\n"
00202 " READONLY Set read-only or read-write mode\n"
00203 " DEBUG Activate or deactivate debug mode\n"
00204 " NOEXPIRE Activate or deactivate no expire mode\n"
00205 " SUPERADMIN Activate or deactivate SuperAdmin mode\n"
00206 " LIST List the options"));
00207 }
00208 else if (subcommand.equals_ci("LIST"))
00209 source.Reply(_("Syntax: \002LIST\n"
00210 "Display the various %s settings"), Config->OperServ.c_str());
00211 else if (subcommand.equals_ci("READONLY"))
00212 source.Reply(_("Syntax: \002READONLY {ON | OFF}\002\n"
00213 " \n"
00214 "Sets read-only mode on or off. In read-only mode, normal\n"
00215 "users will not be allowed to modify any Services data,\n"
00216 "including channel and nickname access lists, etc. IRCops\n"
00217 "with sufficient Services privileges will be able to modify\n"
00218 "Services' AKILL list and drop or forbid nicknames and\n"
00219 "channels, but any such changes will not be saved unless\n"
00220 "read-only mode is deactivated before Services is terminated\n"
00221 "or restarted.\n"
00222 " \n"
00223 "This option is equivalent to the command-line option\n"
00224 "\002-readonly\002."));
00225 else if (subcommand.equals_ci("NOEXPIRE"))
00226 source.Reply(_("Syntax: \002NOEXPIRE {ON | OFF}\002\n"
00227 "Sets no expire mode on or off. In no expire mode, nicks,\n"
00228 "channels, akills and exceptions won't expire until the\n"
00229 "option is unset.\n"
00230 "This option is equivalent to the command-line option\n"
00231 "\002-noexpire\002."));
00232 else if (subcommand.equals_ci("SUPERADMIN"))
00233 source.Reply(_("Syntax: \002SUPERADMIN {ON | OFF}\002\n"
00234 "Setting this will grant you extra privileges such as the\n"
00235 "ability to be \"founder\" on all channel's etc...\n"
00236 "This option is \002not\002 persistent, and should only be used when\n"
00237 "needed, and set back to OFF when no longer needed."));
00238 else
00239 return false;
00240 return true;
00241 }
00242 };
00243
00244 class OSSet : public Module
00245 {
00246 CommandOSSet commandosset;
00247
00248 public:
00249 OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00250 commandosset(this)
00251 {
00252 this->SetAuthor("Anope");
00253
00254 }
00255 };
00256
00257 MODULE_INIT(OSSet)