コード例 #1
0
ファイル: m_cgiirc.cpp プロジェクト: H7-25/inspircd
		CmdResult Handle(const std::vector<std::string> &parameters, User *user)
		{
			if(user->registered == REG_ALL)
				return CMD_FAILURE;

			for(CGIHostlist::iterator iter = Hosts.begin(); iter != Hosts.end(); iter++)
			{
				if(InspIRCd::Match(user->host, iter->hostmask, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(user->GetIPString(), iter->hostmask, ascii_case_insensitive_map))
				{
					if(iter->type == WEBIRC && parameters[0] == iter->password)
					{
						realhost.set(user, user->host);
						realip.set(user, user->GetIPString());

						bool host_ok = (parameters[2].length() < 64);
						const std::string& newhost = (host_ok ? parameters[2] : parameters[3]);

						if (notify)
							ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s from %s", user->nick.c_str(), user->host.c_str(), newhost.c_str(), user->host.c_str());

						// Check if we're happy with the provided hostname. If it's problematic then make sure we won't set a host later, just the IP
						if (host_ok)
							webirc_hostname.set(user, parameters[2]);
						else
							webirc_hostname.unset(user);

						webirc_ip.set(user, parameters[3]);
						return CMD_SUCCESS;
					}
				}
			}

			ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s tried to use WEBIRC, but didn't match any configured webirc blocks.", user->GetFullRealHost().c_str());
			return CMD_FAILURE;
		}
コード例 #2
0
ファイル: m_identmeta.cpp プロジェクト: Adam-/inspircd-extras
	void OnChangeIdent(User* user, const std::string& ident)
	{
		if (IS_LOCAL(user) && ext.get(user) == NULL)
		{
			ServerInstance->Logs->Log("m_identmeta", DEBUG, "Setting ident metadata of %s to %s.",
				user->nick.c_str(), ident.c_str());
			ext.set(user, ident);
		}
	}
コード例 #3
0
	static bool ReadCGIIRCExt(const char* extname, User* user, std::string& out)
	{
		ExtensionItem* wiext = ServerInstance->Extensions.GetItem(extname);
		if (!wiext)
			return false;

		if (wiext->creator->ModuleSourceFile != "m_cgiirc.so")
			return false;

		StringExtItem* stringext = static_cast<StringExtItem*>(wiext);
		std::string* addr = stringext->get(user);
		if (!addr)
			return false;
		out = *addr;
		return true;
	}
コード例 #4
0
ファイル: m_customtitle.cpp プロジェクト: krsnapc/inspircd
	CmdResult Handle(const std::vector<std::string> &parameters, User* user)
	{
		const std::string userHost = user->ident + "@" + user->host;
		const std::string userIP = user->ident + "@" + user->GetIPString();

		ConfigTagList tags = ServerInstance->Config->ConfTags("title");
		for (ConfigIter i = tags.first; i != tags.second; ++i)
		{
			std::string Name = i->second->getString("name");
			std::string pass = i->second->getString("password");
			std::string hash = i->second->getString("hash");
			std::string host = i->second->getString("host", "*@*");
			std::string title = i->second->getString("title");
			std::string vhost = i->second->getString("vhost");

			if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
				InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
			{
				ctitle.set(user, title);

				ServerInstance->PI->SendMetaData(user, "ctitle", title);

				if (!vhost.empty())
					user->ChangeDisplayedHost(vhost.c_str());

				user->WriteNotice("Custom title set to '" + title + "'");

				return CMD_SUCCESS;
			}
		}

		user->WriteNotice("Invalid title credentials");
		return CMD_SUCCESS;
	}
コード例 #5
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	ModResult OnStats(Stats::Context& stats) override
	{
		if (stats.GetSymbol() != 'G')
			return MOD_RES_PASSTHRU;

		unsigned int unknown = 0;
		std::map<std::string, unsigned int> results;

		const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
		for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
		{
			std::string* cc = ext.get(*i);
			if (cc)
				results[*cc]++;
			else
				unknown++;
		}

		for (std::map<std::string, unsigned int>::const_iterator i = results.begin(); i != results.end(); ++i)
		{
			stats.AddRow(801, "GeoIPSTATS " + i->first + " " + ConvToStr(i->second));
		}

		if (unknown)
			stats.AddRow(801, "GeoIPSTATS Unknown " + ConvToStr(unknown));

		return MOD_RES_DENY;
	}
コード例 #6
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	std::string* SetExt(User* user)
	{
		const char* code = NULL;
		switch (user->client_sa.family())
		{
			case AF_INET:
				code = GeoIP_country_code_by_addr(ipv4db, user->GetIPString().c_str());
				break;

			case AF_INET6:
				code = GeoIP_country_code_by_addr_v6(ipv6db, user->GetIPString().c_str());
				break;
		}

		ext.set(user, code ? code : "UNK");
		return ext.get(user);
	}
コード例 #7
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	void OnWhois(Whois::Context& whois) override
	{
		// If the extban is disabled we don't expose users location.
		if (!extban)
			return;

		std::string* cc = ext.get(whois.GetTarget());
		if (!cc)
			cc = SetExt(whois.GetTarget());

		whois.SendLine(RPL_WHOISCOUNTRY, *cc, "is located in this country");
	}
コード例 #8
0
ファイル: m_swhois.cpp プロジェクト: Canternet/inspircd
	CmdResult Handle(const std::vector<std::string> &parameters, User* user)
	{
		User* dest = ServerInstance->FindNick(parameters[0]);

		if ((!dest) || (IS_SERVER(dest))) // allow setting swhois using SWHOIS before reg
		{
			user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
			return CMD_FAILURE;
		}

		std::string* text = swhois.get(dest);
		if (text)
		{
			// We already had it set...
			if (!user->server->IsULine())
				// Ulines set SWHOISes silently
				ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick.c_str(), dest->nick.c_str(), text->c_str(), parameters[1].c_str());
		}
		else if (!user->server->IsULine())
		{
			// Ulines set SWHOISes silently
			ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois to '%s'", user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str());
		}

		if (parameters[1].empty())
			swhois.unset(dest);
		else
			swhois.set(dest, parameters[1]);

		/* Bug #376 - feature request -
		 * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
		 * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
		 * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
		 * -- Brain
		 */
		ServerInstance->PI->SendMetaData(dest, "swhois", parameters[1]);

		return CMD_SUCCESS;
	}
コード例 #9
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	ModResult OnCheckBan(User* user, Channel*, const std::string& mask) override
	{
		if (extban && (mask.length() > 2) && (mask[0] == 'G') && (mask[1] == ':'))
		{
			std::string* cc = ext.get(user);
			if (!cc)
				cc = SetExt(user);

			if (InspIRCd::Match(*cc, mask.substr(2)))
				return MOD_RES_DENY;
		}
		return MOD_RES_PASSTHRU;
	}
コード例 #10
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) override
	{
		std::string* cc = ext.get(user);
		if (!cc)
			cc = SetExt(user);

		std::string geoip = myclass->config->getString("geoip");
		if (geoip.empty())
			return MOD_RES_PASSTHRU;
		irc::commasepstream list(geoip);
		std::string country;
		while (list.GetToken(country))
			if (country == *cc)
				return MOD_RES_PASSTHRU;
		return MOD_RES_DENY;
	}
コード例 #11
0
ファイル: m_geoip.cpp プロジェクト: Adam-/inspircd
	void init() override
	{
		ipv4db = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD);
		if (!ipv4db)
			throw ModuleException("Unable to load the IPv4 GeoIP database. Are you missing GeoIP.dat?");

		ipv6db = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
		if (!ipv6db)
			throw ModuleException("Unable to load the IPv6 GeoIP database. Are you missing GeoIPv6.dat?");

		const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
		for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
		{
			LocalUser* user = *i;
			if ((user->registered == REG_ALL) && (!ext.get(user)))
			{
				SetExt(user);
			}
		}
	}
コード例 #12
0
ファイル: m_mlock.cpp プロジェクト: Adam-/inspircd
	ModResult OnRawMode(User* source, Channel* channel, ModeHandler* mh, const std::string& parameter, bool adding) override
	{
		if (!channel)
			return MOD_RES_PASSTHRU;

		if (!IS_LOCAL(source))
			return MOD_RES_PASSTHRU;

		std::string *mlock_str = mlock.get(channel);
		if (!mlock_str)
			return MOD_RES_PASSTHRU;

		const char mode = mh->GetModeChar();
		std::string::size_type p = mlock_str->find(mode);
		if (p != std::string::npos)
		{
			source->WriteNumeric(ERR_MLOCKRESTRICTED, channel->name, mode, *mlock_str, "MODE cannot be set due to channel having an active MLOCK restriction policy");
			return MOD_RES_DENY;
		}

		return MOD_RES_PASSTHRU;
	}
コード例 #13
0
ファイル: m_cgiirc.cpp プロジェクト: aszrul/inspircd
	CmdResult HandleLocal(LocalUser* user, const Params& parameters) override
	{
		if (user->registered == REG_ALL || realhost.get(user))
			return CMD_FAILURE;

		for (std::vector<WebIRCHost>::const_iterator iter = hosts.begin(); iter != hosts.end(); ++iter)
		{
			// If we don't match the host then skip to the next host.
			if (!iter->Matches(user, parameters[0], sslapi))
				continue;

			irc::sockets::sockaddrs ipaddr;
			if (!irc::sockets::aptosa(parameters[3], user->client_sa.port(), ipaddr))
			{
				WriteLog("Connecting user %s (%s) tried to use WEBIRC but gave an invalid IP address.",
					user->uuid.c_str(), user->GetIPString().c_str());
				ServerInstance->Users.QuitUser(user, "WEBIRC: IP address is invalid: " + parameters[3]);
				return CMD_FAILURE;
			}

			// The user matched a WebIRC block!
			gateway.set(user, parameters[1]);
			realhost.set(user, user->GetRealHost());
			realip.set(user, user->GetIPString());

			WriteLog("Connecting user %s is using a WebIRC gateway; changing their IP from %s to %s.",
				user->uuid.c_str(), user->GetIPString().c_str(), parameters[3].c_str());

			// If we have custom flags then deal with them.
			WebIRC::FlagMap flags;
			const bool hasflags = (parameters.size() > 4);
			if (hasflags)
			{
				// Parse the flags.
				irc::spacesepstream flagstream(parameters[4]);
				for (std::string flag; flagstream.GetToken(flag); )
				{
					// Does this flag have a value?
					const size_t separator = flag.find('=');
					if (separator == std::string::npos)
					{
						flags[flag];
						continue;
					}

					// The flag has a value!
					const std::string key = flag.substr(0, separator);
					const std::string value = flag.substr(separator + 1);
					flags[key] = value;
				}
			}

			// Inform modules about the WebIRC attempt.
			FOREACH_MOD_CUSTOM(webircevprov, WebIRC::EventListener, OnWebIRCAuth, (user, (hasflags ? &flags : NULL)));

			// Set the IP address sent via WEBIRC. We ignore the hostname and lookup
			// instead do our own DNS lookups because of unreliable gateways.
			user->SetClientIP(ipaddr);
			return CMD_SUCCESS;
		}

		WriteLog("Connecting user %s (%s) tried to use WEBIRC but didn't match any configured WebIRC hosts.",
			user->uuid.c_str(), user->GetIPString().c_str());
		ServerInstance->Users.QuitUser(user, "WEBIRC: you don't match any configured WebIRC hosts.");
		return CMD_FAILURE;
	}