summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-03-11 00:47:28 -0500
committerAdam <Adam@anope.org>2011-03-11 00:47:28 -0500
commit1ee3d3d81034c2e2d8c1bf55db8963a50e35f363 (patch)
treed8952ff4d27e144eedd63a056971dfc2b1af5411 /modules
parent97c2e0957d32c87e1055041e43eb13a4a26d0765 (diff)
Added os_config and support for including additional configuration files.
Diffstat (limited to 'modules')
-rw-r--r--modules/core/ns_identify.cpp2
-rw-r--r--modules/core/ns_recover.cpp6
-rw-r--r--modules/core/ns_register.cpp2
-rw-r--r--modules/core/ns_release.cpp3
-rw-r--r--modules/core/os_akill.cpp2
-rw-r--r--modules/core/os_config.cpp231
-rw-r--r--modules/core/os_reload.cpp3
-rw-r--r--modules/core/os_snline.cpp2
-rw-r--r--modules/core/os_sqline.cpp2
-rw-r--r--modules/core/os_stats.cpp40
-rw-r--r--modules/core/os_szline.cpp2
11 files changed, 244 insertions, 51 deletions
diff --git a/modules/core/ns_identify.cpp b/modules/core/ns_identify.cpp
index 074adbb76..db7ad563b 100644
--- a/modules/core/ns_identify.cpp
+++ b/modules/core/ns_identify.cpp
@@ -95,7 +95,7 @@ class CommandNSIdentify : public Command
source.Reply(_("Your email address is not confirmed. To confirm it, follow the instructions that were emailed to you when you registered."));
time_t time_registered = Anope::CurTime - na->time_registered;
if (Config->NSUnconfirmedExpire > time_registered)
- source.Reply(_("Your account will expire, if not confirmed, in %s"), duration(u->Account(), Config->NSUnconfirmedExpire - time_registered).c_str());
+ source.Reply(_("Your account will expire, if not confirmed, in %s"), duration(Config->NSUnconfirmedExpire - time_registered).c_str());
}
check_memos(u);
diff --git a/modules/core/ns_recover.cpp b/modules/core/ns_recover.cpp
index af50ed573..5e7e8c175 100644
--- a/modules/core/ns_recover.cpp
+++ b/modules/core/ns_recover.cpp
@@ -51,7 +51,7 @@ class CommandNSRecover : public Command
u2->Collide(na);
/* Convert Config->NSReleaseTimeout seconds to string format */
- Anope::string relstr = duration(na->nc, Config->NSReleaseTimeout);
+ Anope::string relstr = duration(Config->NSReleaseTimeout);
source.Reply(_(NICK_RECOVERED), Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str());
}
@@ -74,7 +74,7 @@ class CommandNSRecover : public Command
u2->Collide(na);
/* Convert Config->NSReleaseTimeout seconds to string format */
- Anope::string relstr = duration(na->nc, Config->NSReleaseTimeout);
+ Anope::string relstr = duration(Config->NSReleaseTimeout);
source.Reply(_(NICK_RECOVERED), Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str());
}
@@ -87,7 +87,7 @@ class CommandNSRecover : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
{
/* Convert Config->NSReleaseTimeout seconds to string format */
- Anope::string relstr = duration(source.u->Account(), Config->NSReleaseTimeout);
+ Anope::string relstr = duration(Config->NSReleaseTimeout);
source.Reply(_("Syntax: \002RECOVER \037nickname\037 [\037password\037]\002\n"
" \n"
diff --git a/modules/core/ns_register.cpp b/modules/core/ns_register.cpp
index d336f1f4d..c71bcea9c 100644
--- a/modules/core/ns_register.cpp
+++ b/modules/core/ns_register.cpp
@@ -200,7 +200,7 @@ class CommandNSRegister : public Command
if (SendRegmail(u, na))
{
source.Reply(_("A passcode has been sent to %s, please type %R%s confirm <passcode> to confirm your email address."), email.c_str(), NickServ->nick.c_str());
- source.Reply(_("If you do not confirm your email address within %s your account will expire."), duration(na->nc, Config->NSUnconfirmedExpire).c_str());
+ source.Reply(_("If you do not confirm your email address within %s your account will expire."), duration(Config->NSUnconfirmedExpire).c_str());
}
}
diff --git a/modules/core/ns_release.cpp b/modules/core/ns_release.cpp
index 1a0319b78..d77bd113b 100644
--- a/modules/core/ns_release.cpp
+++ b/modules/core/ns_release.cpp
@@ -72,8 +72,7 @@ class CommandNSRelease : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
{
/* Convert Config->NSReleaseTimeout seconds to string format */
- User *u = source.u;
- Anope::string relstr = duration(u->Account(), Config->NSReleaseTimeout);
+ Anope::string relstr = duration(Config->NSReleaseTimeout);
source.Reply(_("Syntax: \002RELEASE \037nickname\037 [\037password\037]\002\n"
" \n"
diff --git a/modules/core/os_akill.cpp b/modules/core/os_akill.cpp
index dd07e2abc..f9083e2c6 100644
--- a/modules/core/os_akill.cpp
+++ b/modules/core/os_akill.cpp
@@ -195,7 +195,7 @@ class CommandOSAKill : public Command
source.Reply(_("\002%s\002 added to the AKILL list."), mask.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(NULL, expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
if (readonly)
source.Reply(_(READ_ONLY_MODE));
diff --git a/modules/core/os_config.cpp b/modules/core/os_config.cpp
new file mode 100644
index 000000000..b7335527c
--- /dev/null
+++ b/modules/core/os_config.cpp
@@ -0,0 +1,231 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2011 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+
+class CommandOSConfig : public Command
+{
+ void ChangeHash(ConfigDataHash &hash, const Anope::string &block, const Anope::string &iname, const Anope::string &value)
+ {
+ ConfigDataHash::iterator it = hash.find(block);
+
+ KeyValList &list = it->second;
+ for (unsigned i = 0; i < list.size(); ++i)
+ {
+ const Anope::string &item = list[i].first;
+ if (item == iname)
+ {
+ list[i] = std::make_pair(item, value);
+ break;
+ }
+ }
+ }
+
+ public:
+ CommandOSConfig() : Command("CONFIG", 1, 4, "operserv/config")
+ {
+ this->SetDesc("View and change configuration file settings");
+ }
+
+ CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &what = params[0];
+
+ if (what.equals_ci("MODIFY") && params.size() > 3)
+ {
+ ConfigItems configitems(Config);
+
+ for (unsigned i = 0; !configitems.Values[i].tag.empty(); ++i)
+ {
+ ConfigItems::Item *v = &configitems.Values[i];
+ if (v->tag.equals_cs(params[1]) && v->value.equals_cs(params[2]))
+ {
+ try
+ {
+ ValueItem vi(params[3]);
+ if (!v->validation_function(Config, v->tag, v->value, vi))
+ throw ConfigException("Parameter failed to validate.");
+
+ int dt = v->datatype;
+
+ if (dt & DT_NORELOAD)
+ throw ConfigException("This item can not be changed while Anope is running.");
+ bool allow_wild = dt & DT_ALLOW_WILD;
+ dt &= ~(DT_ALLOW_NEWLINE | DT_ALLOW_WILD);
+
+ /* Yay for *massive* copypaste from config.cpp */
+ switch (dt)
+ {
+ case DT_NOSPACES:
+ {
+ ValueContainerString *vcs = debug_cast<ValueContainerString *>(v->val);
+ Config->ValidateNoSpaces(vi.GetValue(), v->tag, v->value);
+ vcs->Set(vi.GetValue());
+ break;
+ }
+ case DT_HOSTNAME:
+ {
+ ValueContainerString *vcs = debug_cast<ValueContainerString *>(v->val);
+ Config->ValidateHostname(vi.GetValue(), v->tag, v->value);
+ vcs->Set(vi.GetValue());
+ break;
+ }
+ case DT_IPADDRESS:
+ {
+ ValueContainerString *vcs = debug_cast<ValueContainerString *>(v->val);
+ Config->ValidateIP(vi.GetValue(), v->tag, v->value, allow_wild);
+ vcs->Set(vi.GetValue());
+ break;
+ }
+ case DT_CHARPTR:
+ {
+ ValueContainerChar *vcc = debug_cast<ValueContainerChar *>(v->val);
+ // Make sure we also copy the null terminator
+ vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
+ break;
+ }
+ case DT_STRING:
+ {
+ ValueContainerString *vcs = debug_cast<ValueContainerString *>(v->val);
+ vcs->Set(vi.GetValue());
+ break;
+ }
+ case DT_INTEGER:
+ {
+ int val = vi.GetInteger();
+ ValueContainerInt *vci = debug_cast<ValueContainerInt *>(v->val);
+ vci->Set(&val, sizeof(int));
+ break;
+ }
+ case DT_UINTEGER:
+ {
+ unsigned val = vi.GetInteger();
+ ValueContainerUInt *vci = debug_cast<ValueContainerUInt *>(v->val);
+ vci->Set(&val, sizeof(unsigned));
+ break;
+ }
+ case DT_LUINTEGER:
+ {
+ unsigned long val = vi.GetInteger();
+ ValueContainerLUInt *vci = debug_cast<ValueContainerLUInt *>(v->val);
+ vci->Set(&val, sizeof(unsigned long));
+ break;
+ }
+ case DT_TIME:
+ {
+ time_t time = dotime(vi.GetValue());
+ ValueContainerTime *vci = debug_cast<ValueContainerTime *>(v->val);
+ vci->Set(&time, sizeof(time_t));
+ break;
+ }
+ case DT_BOOLEAN:
+ {
+ bool val = vi.GetBool();
+ ValueContainerBool *vcb = debug_cast<ValueContainerBool *>(v->val);
+ vcb->Set(&val, sizeof(bool));
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ catch (const ConfigException &ex)
+ {
+ source.Reply(_("Error changing configuration value: ") + ex.GetReason());
+ return MOD_CONT;
+ }
+
+ ChangeHash(Config->config_data, params[1], params[2], params[3]);
+
+ Log(LOG_ADMIN, source.u, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3];
+ source.Reply(_("Value of %s:%s changed to %s"), params[1].c_str(), params[2].c_str(), params[3].c_str());
+ return MOD_CONT;
+ }
+ }
+
+ source.Reply("There is no configuration value named %s:%s", params[1].c_str(), params[2].c_str());
+ }
+ else if (what.equals_ci("VIEW"))
+ {
+ /* Blocks we should show */
+ const Anope::string show_blocks[] = { "botserv", "chanserv", "defcon", "global", "memoserv", "nickserv", "networkinfo", "operserv", "options", "" };
+
+ Log(LOG_ADMIN, source.u, this);
+
+ for (ConfigDataHash::const_iterator it = Config->config_data.begin(), it_end = Config->config_data.end(); it != it_end; ++it)
+ {
+ const Anope::string &bname = it->first;
+ const KeyValList &list = it->second;
+
+ bool ok = false;
+ for (unsigned i = 0; !show_blocks[i].empty(); ++i)
+ if (bname == show_blocks[i])
+ ok = true;
+ if (ok == false)
+ continue;
+
+ source.Reply(_("%s settings:"), bname.c_str());
+ for (unsigned i = 0; i < list.size(); ++i)
+ {
+ const Anope::string &first = list[i].first, second = list[i].second;
+
+ if (first == "modules")
+ continue; // Modules list isn't important
+
+ source.Reply(_(" Name: %-15s Value: %s"), first.c_str(), second.c_str());
+ }
+ }
+
+ source.Reply(_("End of configuration."));
+ }
+ else
+ this->OnSyntaxError(source, what);
+
+ return MOD_CONT;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand)
+ {
+ source.Reply(_("Syntax: \002CONFIG {\037MODIFY\037|\037VIEW\037} [\037block name\037 \037item name\037 \037item value\037]\002\n"
+ "\n"
+ "\002CONFIG\002 allows you to change and view configuration settings.\n"
+ "Settings changed by this command are temporary and will not be reflected\n"
+ "back into the configuration file, and will be lost if Anope is shut down,\n"
+ "restarted, or the RELOAD command is used.\n"
+ " \n"
+ "Example:\n"
+ " \002CONFIG MODIFY nickserv forcemail no\002"));
+ return true;
+ }
+
+ void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
+ {
+ SyntaxError(source, "CONFIG", _("CONFIG {\037MODIFY\037|\037VIEW\037} [\037block name\037 \037item name\037 \037item value\037]"));
+ }
+};
+
+class OSConfig : public Module
+{
+ CommandOSConfig commandosconfig;
+
+ public:
+ OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
+ {
+ this->SetAuthor("Anope");
+ this->SetType(CORE);
+
+ this->AddCommand(OperServ, &commandosconfig);
+ }
+};
+
+MODULE_INIT(OSConfig)
diff --git a/modules/core/os_reload.cpp b/modules/core/os_reload.cpp
index 0a3e26ccc..46e3686a2 100644
--- a/modules/core/os_reload.cpp
+++ b/modules/core/os_reload.cpp
@@ -29,13 +29,14 @@ class CommandOSReload : public Command
delete Config;
Config = newconfig;
FOREACH_MOD(I_OnReload, OnReload(false));
+ source.Reply(_("Services' configuration file has been reloaded."));
}
catch (const ConfigException &ex)
{
Log() << "Error reloading configuration file: " << ex.GetReason();
+ source.Reply(_("Error reloading confguration file: ") + ex.GetReason());
}
- source.Reply(_("Services' configuration file has been reloaded."));
return MOD_CONT;
}
diff --git a/modules/core/os_snline.cpp b/modules/core/os_snline.cpp
index f9697a98f..6758b98b6 100644
--- a/modules/core/os_snline.cpp
+++ b/modules/core/os_snline.cpp
@@ -208,7 +208,7 @@ class CommandOSSNLine : public Command
return MOD_CONT;
source.Reply(_("\002%s\002 added to the SNLINE list."), mask.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(NULL, expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
if (readonly)
source.Reply(_(READ_ONLY_MODE));
diff --git a/modules/core/os_sqline.cpp b/modules/core/os_sqline.cpp
index 56a1aed9d..c9599f0e0 100644
--- a/modules/core/os_sqline.cpp
+++ b/modules/core/os_sqline.cpp
@@ -188,7 +188,7 @@ class CommandOSSQLine : public Command
return MOD_CONT;
source.Reply(_("\002%s\002 added to the SQLINE list."), mask.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(NULL, expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
if (readonly)
source.Reply(_(READ_ONLY_MODE));
diff --git a/modules/core/os_stats.cpp b/modules/core/os_stats.cpp
index a3898949f..8dedee571 100644
--- a/modules/core/os_stats.cpp
+++ b/modules/core/os_stats.cpp
@@ -130,47 +130,9 @@ class CommandOSStats : public Command
CommandReturn DoStatsUptime(CommandSource &source)
{
time_t uptime = Anope::CurTime - start_time;
- int days = uptime / 86400, hours = (uptime / 3600) % 24, mins = (uptime / 60) % 60, secs = uptime % 60;
source.Reply(_("Current users: \002%d\002 (\002%d\002 ops)"), usercnt, opcnt);
source.Reply(_("Maximum users: \002%d\002 (%s)"), maxusercnt, do_strftime(maxusertime).c_str());
- if (days > 1)
- source.Reply(_("Services up \002%d\002 days, \002%02d:%02d\002"), days, hours, mins, secs);
- else if (days == 1)
- source.Reply(_("Services up OPER_STATS_UPTIME_1\002%dOPER_STATS_UPTIME_1\002 day, OPER_STATS_UPTIME_1\002%02d:%02dOPER_STATS_UPTIME_1\002"), days, hours, mins, secs);
- else
- {
- if (hours > 1)
- {
- if (mins != 1)
- source.Reply(_("Services up \002%d\002 hours, \002%d\002 minutes"), hours, mins);
- else
- source.Reply(_("Services up OPER_STATS_UPTIME_H1\002%dOPER_STATS_UPTIME_H1\002 hours, OPER_STATS_UPTIME_H1\002%dOPER_STATS_UPTIME_H1\002 minute"), hours, mins, secs);
- }
- else if (hours == 1)
- {
- if (mins != 1)
- source.Reply(_("Services up OPER_STATS_UPTIME_1\002%dOPER_STATS_UPTIME_1\002 hour, OPER_STATS_UPTIME_1\002%dOPER_STATS_UPTIME_1\002 minutes"), hours, mins, secs);
- else
- source.Reply(_("Services up OPER_STATS_UPTIME_1H1\002%dOPER_STATS_UPTIME_1H1\002 hour, OPER_STATS_UPTIME_1H1\002%dOPER_STATS_UPTIME_1H1\002 minute"), hours, mins, secs);
- }
- else
- {
- if (mins != 1)
- {
- if (secs != 1)
- source.Reply(_("Services up \002%d\002 minutes, \002%d\002 seconds"), mins, secs);
- else
- source.Reply(_("Services up OPER_STATS_UPTIME_M1\002%dOPER_STATS_UPTIME_M1\002 minutes, OPER_STATS_UPTIME_M1\002%dOPER_STATS_UPTIME_M1\002 second"), mins, secs);
- }
- else
- {
- if (secs != 1)
- source.Reply(_("Services up OPER_STATS_UPTIME_1\002%dOPER_STATS_UPTIME_1\002 minute, OPER_STATS_UPTIME_1\002%dOPER_STATS_UPTIME_1\002 seconds"), mins, secs);
- else
- source.Reply(_("Services up OPER_STATS_UPTIME_1M1\002%dOPER_STATS_UPTIME_1M1\002 minute, OPER_STATS_UPTIME_1M1\002%dOPER_STATS_UPTIME_1M1\002 second"), mins, secs);
- }
- }
- }
+ source.Reply(_("Services up %s"), duration(uptime).c_str());
return MOD_CONT;
}
diff --git a/modules/core/os_szline.cpp b/modules/core/os_szline.cpp
index 3225aab39..30a339263 100644
--- a/modules/core/os_szline.cpp
+++ b/modules/core/os_szline.cpp
@@ -192,7 +192,7 @@ class CommandOSSZLine : public Command
return MOD_CONT;
source.Reply(_("\002%s\002 added to the SZLINE list."), mask.c_str());
- Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(NULL, expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
+ Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << duration(expires - Anope::CurTime) << " [affects " << affected << " user(s) (" << percent << "%)]";
if (readonly)
source.Reply(_(READ_ONLY_MODE));