diff options
| author | 2017-10-15 14:00:29 +0100 | |
|---|---|---|
| committer | 2017-10-15 17:19:27 +0100 | |
| commit | 52727673077afcb7377cef7491d3bdf9ab1c372e (patch) | |
| tree | f6be56b775e48964ffcd4929109964c58bc2df82 /src/modules/m_cgiirc.cpp | |
| parent | Add support for hashed WebIRC passwords to m_cgiirc. (diff) | |
| download | inspircd++-52727673077afcb7377cef7491d3bdf9ab1c372e.tar.gz inspircd++-52727673077afcb7377cef7491d3bdf9ab1c372e.tar.bz2 inspircd++-52727673077afcb7377cef7491d3bdf9ab1c372e.zip | |
Clean up the WEBIRC command handler.
- Fix the extremely broken indentation.
- Simplify the HandleLocal code flow.
- Improve the notices sent to operators.
Diffstat (limited to 'src/modules/m_cgiirc.cpp')
| -rw-r--r-- | src/modules/m_cgiirc.cpp | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index f5584e264..87cd86000 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -91,58 +91,55 @@ class CommandWebIRC : public SplitCommand , gateway("cgiirc_gateway", ExtensionItem::EXT_USER, Creator) , realhost("cgiirc_realhost", ExtensionItem::EXT_USER, Creator) , realip("cgiirc_realip", ExtensionItem::EXT_USER, Creator) - { - allow_empty_last_param = false; - works_before_reg = true; - this->syntax = "password gateway hostname ip"; - } - CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) - { - if(user->registered == REG_ALL) - return CMD_FAILURE; - - irc::sockets::sockaddrs ipaddr; - if (!irc::sockets::aptosa(parameters[3], 0, ipaddr)) - { - user->CommandFloodPenalty += 5000; - ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s tried to use WEBIRC but gave an invalid IP address.", user->GetFullRealHost().c_str()); - return CMD_FAILURE; - } + { + allow_empty_last_param = false; + works_before_reg = true; + this->syntax = "password gateway hostname ip"; + } - 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])) - continue; + CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) CXX11_OVERRIDE + { + if (user->registered == REG_ALL) + return CMD_FAILURE; - { - { - gateway.set(user, parameters[1]); - realhost.set(user, user->host); - realip.set(user, user->GetIPString()); + irc::sockets::sockaddrs ipaddr; + if (!irc::sockets::aptosa(parameters[3], 0, ipaddr)) + { + user->CommandFloodPenalty += 5000; + ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s tried to use WEBIRC but gave an invalid IP address.", user->GetFullRealHost().c_str()); + return CMD_FAILURE; + } - // 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 - bool host_ok = (parameters[2].length() <= ServerInstance->Config->Limits.MaxHost) && (parameters[2].find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == std::string::npos); - const std::string& newhost = (host_ok ? parameters[2] : parameters[3]); + // If the hostname is malformed then we use the IP address instead. + bool host_ok = (parameters[2].length() <= ServerInstance->Config->Limits.MaxHost) && (parameters[2].find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-") == std::string::npos); + const std::string& newhost = (host_ok ? parameters[2] : parameters[3]); - if (notify) - ServerInstance->SNO->WriteGlobalSno('w', "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()); + 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])) + continue; - // Where the magic happens - change their IP - ChangeIP(user, parameters[3]); - // And follow this up by changing their host - user->host = user->dhost = newhost; - user->InvalidateCache(); + // The user matched a WebIRC block! + gateway.set(user, parameters[1]); + realhost.set(user, user->host); + realip.set(user, user->GetIPString()); - return CMD_SUCCESS; - } - } - } + if (notify) + ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s is using a WebIRC gateway; changing their IP/host from %s/%s to %s/%s.", + user->nick.c_str(), user->GetIPString().c_str(), user->host.c_str(), parameters[3].c_str(), newhost.c_str()); - user->CommandFloodPenalty += 5000; - ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s tried to use WEBIRC, but didn't match any configured webirc blocks.", user->GetFullRealHost().c_str()); - return CMD_FAILURE; + // Set the IP address and hostname sent via WEBIRC. + ChangeIP(user, parameters[3]); + user->host = user->dhost = newhost; + user->InvalidateCache(); + return CMD_SUCCESS; } + + user->CommandFloodPenalty += 5000; + ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s tried to use WEBIRC but didn't match any configured WebIRC hosts.", user->GetFullRealHost().c_str()); + return CMD_FAILURE; + } }; |
