diff options
| author | 2024-10-22 21:40:31 +0100 | |
|---|---|---|
| committer | 2024-10-22 21:52:21 +0100 | |
| commit | f4a9f3ce222dc1251a5c4caf88ca898fc46eabde (patch) | |
| tree | 870eb83409159f161385a42616d05fc7a0943a5a /src/modules/m_sslinfo.cpp | |
| parent | Merge branch 'insp3' into insp4. (diff) | |
Add a stats character to sslinfo for viewing ciphersuite info.
Diffstat (limited to 'src/modules/m_sslinfo.cpp')
| -rw-r--r-- | src/modules/m_sslinfo.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index f8b609dd0..5a4a08ae4 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -28,6 +28,7 @@ #include "inspircd.h" #include "extension.h" #include "modules/ssl.h" +#include "modules/stats.h" #include "modules/webirc.h" #include "modules/who.h" #include "modules/whois.h" @@ -305,9 +306,10 @@ public: class ModuleSSLInfo final : public Module + , public Stats::EventListener , public WebIRC::EventListener - , public Whois::EventListener , public Who::EventListener + , public Whois::EventListener { private: CommandSSLInfo cmd; @@ -333,9 +335,10 @@ private: public: ModuleSSLInfo() : Module(VF_VENDOR, "Adds user facing TLS information, various TLS configuration options, and the /SSLINFO command to look up TLS certificate information for other users.") + , Stats::EventListener(this) , WebIRC::EventListener(this) - , Whois::EventListener(this) , Who::EventListener(this) + , Whois::EventListener(this) , cmd(this) { } @@ -486,6 +489,43 @@ public: return MOD_RES_PASSTHRU; } + ModResult OnStats(Stats::Context& stats) override + { + if (stats.GetSymbol() != 't') + return MOD_RES_PASSTHRU; + + // Counter for the number of users using each ciphersuite. + std::map<std::string, size_t> counts; + auto& plaintext = counts["Plain text"]; + auto& unknown = counts["Unknown"]; + for (auto* user : ServerInstance->Users.GetLocalUsers()) + { + const auto* ssliohook = SSLIOHook::IsSSL(&user->eh); + if (!ssliohook) + { + plaintext++; + continue; + } + + std::string ciphersuite; + ssliohook->GetCiphersuite(ciphersuite); + if (ciphersuite.empty()) + unknown++; + else + counts[ciphersuite]++; + } + + for (const auto& [ciphersuite, count] : counts) + { + stats.AddGenericRow(INSP_FORMAT("{}: {}", ciphersuite, count)) + .AddTags(stats, { + { "ciphersuite", ciphersuite }, + { "count", ConvToStr(count) }, + }); + } + return MOD_RES_DENY; + } + void OnWebIRCAuth(LocalUser* user, const WebIRC::FlagMap* flags) override { // We are only interested in connection flags. If none have been |
