Anope IRC Services  Version 2.0
os_config.cpp
Go to the documentation of this file.
1 /* OperServ core functions
2  *
3  * (C) 2003-2014 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]);
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  {
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);
94 
95  if (!items || items->size() <= 1)
96  continue;
97 
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 {
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 
static Anope::map< ExtensibleItem< CSMiscData > * > items
Definition: cs_set_misc.cpp:18
#define ACCESS_DENIED
Definition: language.h:73
void AddEntry(const ListEntry &entry)
Definition: misc.cpp:134
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: os_config.cpp:23
std::map< Anope::string, Anope::string > ListEntry
Definition: lists.h:68
Definition: Config.cs:26
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: os_config.cpp:123
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
CommandOSConfig(Module *creator)
Definition: os_config.cpp:17
#define MODULE_INIT(x)
Definition: modules.h:45
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
bool Set(const Anope::string &tag, const Anope::string &value)
Definition: config.cpp:56
OSConfig(const Anope::string &modname, const Anope::string &creator)
Definition: os_config.cpp:143
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
T Get(const Anope::string &tag)
Definition: config.h:44
const Anope::string & GetName() const
Definition: config.cpp:30
const item_map * GetItems() const
Definition: config.cpp:65
#define _(x)
Definition: services.h:50
ListFormatter & AddColumn(const Anope::string &name)
Definition: misc.cpp:128
CommandOSConfig commandosconfig
Definition: os_config.cpp:140