anope

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

os_config.cpp (4229B)

      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 CommandOSConfig : public Command
     15 {
     16  public:
     17 	CommandOSConfig(Module *creator) : Command(creator, "operserv/config", 1, 4)
     18 	{
     19 		this->SetDesc(_("View and change configuration file settings"));
     20 		this->SetSyntax(_("{\037MODIFY\037|\037VIEW\037} [\037block name\037 \037item name\037 \037item value\037]"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &what = params[0];
     26 
     27 		if (what.equals_ci("MODIFY") && params.size() > 3)
     28 		{
     29 			if (!source.HasPriv("operserv/config"))
     30 			{
     31 				source.Reply(ACCESS_DENIED);
     32 				return;
     33 			}
     34 
     35 			Configuration::Block *block = Config->GetBlock(params[1]);
     36 			if (!block)
     37 				block = Config->GetModule(params[1]);
     38 
     39 			if (!block)
     40 			{
     41 				source.Reply(_("There is no such configuration block %s."), params[1].c_str());
     42 				return;
     43 			}
     44 
     45 			block->Set(params[2], params[3]);
     46 
     47 			Log(LOG_ADMIN, source, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3];
     48 			source.Reply(_("Value of %s:%s changed to %s"), params[1].c_str(), params[2].c_str(), params[3].c_str());
     49 		}
     50 		else if (what.equals_ci("VIEW"))
     51 		{
     52 			/* Blocks we should show */
     53 			const Anope::string show_blocks[] = { "serverinfo", "networkinfo", "options", "" };
     54 
     55 			Log(LOG_ADMIN, source, this) << "VIEW";
     56 
     57 			for (unsigned i = 0; !show_blocks[i].empty(); ++i)
     58 			{
     59 				Configuration::Block *block = Config->GetBlock(show_blocks[i]);
     60 				const Configuration::Block::item_map *items = block->GetItems();
     61 
     62 				if (!items)
     63 					continue;
     64 
     65 				ListFormatter lflist(source.GetAccount());
     66 				lflist.AddColumn(_("Name")).AddColumn(_("Value"));
     67 
     68 				for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
     69 				{
     70 					ListFormatter::ListEntry entry;
     71 					entry["Name"] = it->first;
     72 					entry["Value"] = it->second;
     73 					lflist.AddEntry(entry);
     74 				}
     75 
     76 				std::vector<Anope::string> replies;
     77 				lflist.Process(replies);
     78 
     79 				source.Reply(_("%s settings:"), block->GetName().c_str());
     80 
     81 				for (unsigned j = 0; j < replies.size(); ++j)
     82 					source.Reply(replies[j]);
     83 
     84 				source.Reply(" ");
     85 			}
     86 
     87 			ListFormatter lflist(source.GetAccount());
     88 			lflist.AddColumn(_("Module Name")).AddColumn(_("Name")).AddColumn(_("Value"));
     89 
     90 			for (int i = 0; i < Config->CountBlock("module"); ++i)
     91 			{
     92 				Configuration::Block *block = Config->GetBlock("module", i);
     93 				const Configuration::Block::item_map *items = block->GetItems();
     94 
     95 				if (!items || items->size() <= 1)
     96 					continue;
     97 
     98 				ListFormatter::ListEntry entry;
     99 				entry["Module Name"] = block->Get<Anope::string>("name");
    100 
    101 				for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
    102 				{
    103 					entry["Name"] = it->first;
    104 					entry["Value"] = it->second;
    105 					lflist.AddEntry(entry);
    106 				}
    107 			}
    108 
    109 			std::vector<Anope::string> replies;
    110 			lflist.Process(replies);
    111 
    112 			source.Reply(_("Module settings:"));
    113 
    114 			for (unsigned j = 0; j < replies.size(); ++j)
    115 				source.Reply(replies[j]);
    116 
    117 			source.Reply(_("End of configuration."));
    118 		}
    119 		else
    120 			this->OnSyntaxError(source, what);
    121 	}
    122 
    123 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    124 	{
    125 		this->SendSyntax(source);
    126 		source.Reply(" ");
    127 		source.Reply(_("Allows you to change and view configuration settings.\n"
    128 				"Settings changed by this command are temporary and will not be reflected\n"
    129 				"back into the configuration file, and will be lost if Anope is shut down,\n"
    130 				"restarted, or the configuration is reloaded.\n"
    131 				" \n"
    132 				"Example:\n"
    133 				"     \002MODIFY nickserv forcemail no\002"));
    134 		return true;
    135 	}
    136 };
    137 
    138 class OSConfig : public Module
    139 {
    140 	CommandOSConfig commandosconfig;
    141 
    142  public:
    143 	OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    144 		commandosconfig(this)
    145 	{
    146 
    147 	}
    148 };
    149 
    150 MODULE_INIT(OSConfig)