Exemplo n.º 1
0
	void OnReload(Configuration::Conf *conf) override
	{
		Configuration::Block *block = conf->GetModule(this);
		std::vector<Anope::string> new_services;

		for (int i = 0; i < block->CountBlock("redis"); ++i)
		{
			Configuration::Block *redis = block->GetBlock("redis", i);

			const Anope::string &n = redis->Get<Anope::string>("name"),
						&ip = redis->Get<Anope::string>("ip");
			int port = redis->Get<int>("port");
			unsigned db = redis->Get<unsigned>("db");

			delete services[n];
			services[n] = new MyRedisService(this, n, ip, port, db);
			new_services.push_back(n);
		}

		for (std::map<Anope::string, MyRedisService *>::iterator it = services.begin(); it != services.end();)
		{
			Provider *p = it->second;
			++it;

			if (std::find(new_services.begin(), new_services.end(), p->name) == new_services.end())
				delete it->second;
		}
	}
Exemplo n.º 2
0
	void OnReload(Configuration::Conf *conf) override
	{
		Configuration::Block *config = conf->GetModule(this);

		for (std::map<Anope::string, SQLiteService *>::iterator it = this->SQLiteServices.begin(); it != this->SQLiteServices.end();)
		{
			const Anope::string &cname = it->first;
			SQLiteService *s = it->second;
			int i, num;
			++it;

			for (i = 0, num = config->CountBlock("sqlite"); i < num; ++i)
				if (config->GetBlock("sqlite", i)->Get<Anope::string>("name", "sqlite/main") == cname)
					break;

			if (i == num)
			{
				Log(LOG_NORMAL, "sqlite") << "SQLite: Removing server connection " << cname;

				delete s;
				this->SQLiteServices.erase(cname);
			}
		}

		for (int i = 0; i < config->CountBlock("sqlite"); ++i)
		{
			Configuration::Block *block = config->GetBlock("sqlite", i);
			Anope::string connname = block->Get<Anope::string>("name", "sqlite/main");

			if (this->SQLiteServices.find(connname) == this->SQLiteServices.end())
			{
				Anope::string database = Anope::DataDir + "/" + block->Get<Anope::string>("database", "anope");

				try
				{
					SQLiteService *ss = new SQLiteService(this, connname, database);
					this->SQLiteServices[connname] = ss;

					Log(LOG_NORMAL, "sqlite") << "SQLite: Successfully added database " << database;
				}
				catch (const SQL::Exception &ex)
				{
					Log(LOG_NORMAL, "sqlite") << "SQLite: " << ex.GetReason();
				}
			}
		}
	}
Exemplo n.º 3
0
Arquivo: log.cpp Projeto: Robby-/anope
	void OnReload(Configuration::Conf *conf) override
	{
		Configuration::Block *block = conf->GetModule(this);
		defaults.clear();

		for (int i = 0; i < block->CountBlock("default"); ++i)
		{
			Configuration::Block *def = block->GetBlock("default", i);

			LogDefault ld;

			ld.service = def->Get<Anope::string>("service");
			ld.command = def->Get<Anope::string>("command");
			ld.method = def->Get<Anope::string>("method");

			defaults.push_back(ld);
		}
	}
Exemplo n.º 4
0
	void OnReload(Configuration::Conf *config) override
	{
		Configuration::Block *conf = config->GetModule(this);

		for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end();)
		{
			const Anope::string &cname = it->first;
			LDAPService *s = it->second;
			int i;

			++it;

			for (i = 0; i < conf->CountBlock("ldap"); ++i)
				if (conf->GetBlock("ldap", i)->Get<Anope::string>("name", "ldap/main") == cname)
					break;

			if (i == conf->CountBlock("ldap"))
			{
				logger.Log("Removing server connection {0}", cname);

				s->SetExitState();
				s->Wakeup();
				s->Join();
				delete s;
				this->LDAPServices.erase(cname);
			}
		}

		for (int i = 0; i < conf->CountBlock("ldap"); ++i)
		{
			Configuration::Block *ldap = conf->GetBlock("ldap", i);

			const Anope::string &connname = ldap->Get<Anope::string>("name", "ldap/main");

			if (this->LDAPServices.find(connname) == this->LDAPServices.end())
			{
				const Anope::string &server = ldap->Get<Anope::string>("server", "127.0.0.1");
				const Anope::string &admin_binddn = ldap->Get<Anope::string>("admin_binddn");
				const Anope::string &admin_password = ldap->Get<Anope::string>("admin_password");

				try
				{
					LDAPService *ss = new LDAPService(this, connname, server, admin_binddn, admin_password);
					ss->Start();
					this->LDAPServices.insert(std::make_pair(connname, ss));

					logger.Log("Successfully initialized server {0} ({1})", connname, server);
				}
				catch (const LDAPException &ex)
				{
					logger.Log(ex.GetReason());
				}
			}
		}
	}
Exemplo n.º 5
0
	void OnReload(Configuration::Conf *conf) override
	{
		Configuration::Block *config = conf->GetModule(this);

		for (std::map<Anope::string, MySQLService *>::iterator it = this->MySQLServices.begin(); it != this->MySQLServices.end();)
		{
			const Anope::string &cname = it->first;
			MySQLService *s = it->second;
			int i;

			++it;

			for (i = 0; i < config->CountBlock("mysql"); ++i)
				if (config->GetBlock("mysql", i)->Get<Anope::string>("name", "mysql/main") == cname)
					break;

			if (i == config->CountBlock("mysql"))
			{
				Log(LOG_NORMAL, "mysql") << "MySQL: Removing server connection " << cname;

				delete s;
				this->MySQLServices.erase(cname);
			}
		}

		for (int i = 0; i < config->CountBlock("mysql"); ++i)
		{
			Configuration::Block *block = config->GetBlock("mysql", i);
			const Anope::string &connname = block->Get<Anope::string>("name", "mysql/main");

			if (this->MySQLServices.find(connname) == this->MySQLServices.end())
			{
				const Anope::string &database = block->Get<Anope::string>("database", "anope");
				const Anope::string &server = block->Get<Anope::string>("server", "127.0.0.1");
				const Anope::string &user = block->Get<Anope::string>("username", "anope");
				const Anope::string &password = block->Get<Anope::string>("password");
				int port = block->Get<int>("port", "3306");

				try
				{
					MySQLService *ss = new MySQLService(this, connname, database, server, user, password, port);
					this->MySQLServices.insert(std::make_pair(connname, ss));

					Log(LOG_NORMAL, "mysql") << "MySQL: Successfully connected to server " << connname << " (" << server << ")";
				}
				catch (const SQL::Exception &ex)
				{
					Log(LOG_NORMAL, "mysql") << "MySQL: " << ex.GetReason();
				}
			}
		}
	}
Exemplo n.º 6
0
	void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
	{
		const Anope::string &what = params[0];

		if (what.equals_ci("MODIFY") && params.size() > 3)
		{
			if (!source.HasPriv("operserv/config"))
			{
				source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/config");
				return;
			}

			Configuration::Block *block = Config->GetBlock(params[1]);
			if (!block)
				block = Config->GetModule(params[1]);

			if (!block)
			{
				source.Reply(_("There is no such configuration block \002{0}\002."), params[1]);
				return;
			}

			block->Set(params[2], params[3]);

			Log(LOG_ADMIN, source, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3];
			source.Reply(_("Value of \002{0}:{1}\002 changed to \002{2}\002."), params[1], params[2], params[3]);
		}
		else if (what.equals_ci("VIEW"))
		{
			/* Blocks we should show */
			const Anope::string show_blocks[] = { "serverinfo", "networkinfo", "options", "" };

			Log(LOG_ADMIN, source, this) << "VIEW";

			for (unsigned i = 0; !show_blocks[i].empty(); ++i)
			{
				Configuration::Block *block = Config->GetBlock(show_blocks[i]);
				const Configuration::Block::item_map *items = block->GetItems();

				if (!items)
					continue;

				ListFormatter lflist(source.GetAccount());
				lflist.AddColumn(_("Name")).AddColumn(_("Value"));

				for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
				{
					ListFormatter::ListEntry entry;
					entry["Name"] = it->first;
					entry["Value"] = it->second;
					lflist.AddEntry(entry);
				}

				std::vector<Anope::string> replies;
				lflist.Process(replies);

				source.Reply(_("%s settings:"), block->GetName());

				for (unsigned j = 0; j < replies.size(); ++j)
					source.Reply(replies[j]);

				source.Reply(" ");
			}

			ListFormatter lflist(source.GetAccount());
			lflist.AddColumn(_("Module Name")).AddColumn(_("Name")).AddColumn(_("Value"));

			for (int i = 0; i < Config->CountBlock("module"); ++i)
			{
				Configuration::Block *block = Config->GetBlock("module", i);
				const Configuration::Block::item_map *items = block->GetItems();

				if (!items || items->size() <= 1)
					continue;

				ListFormatter::ListEntry entry;
				entry["Module Name"] = block->Get<Anope::string>("name");

				for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
				{
					entry["Name"] = it->first;
					entry["Value"] = it->second;
					lflist.AddEntry(entry);
				}
			}

			std::vector<Anope::string> replies;
			lflist.Process(replies);

			source.Reply(_("Module settings:"));

			for (unsigned j = 0; j < replies.size(); ++j)
				source.Reply(replies[j]);

			source.Reply(_("End of configuration."));
		}
		else
			this->OnSyntaxError(source, what);
	}