aboutsummaryrefslogtreecommitdiffstats
path: root/modules/sslinfo.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-11-01 14:35:23 +0000
committerGravatar Sadie Powell2024-11-01 15:53:04 +0000
commit8a3aba4044ee10df332631c4c66ed60299566e58 (patch)
treeafb185a313dff83d61c26e3b95f47b62d3ab5694 /modules/sslinfo.cpp
parentDefault <options:extbanformat> to name. (diff)
parentUse fmtlib instead of iostream in ConvToStr where available. (diff)
Merge branch 'insp4' into master.
Diffstat (limited to 'modules/sslinfo.cpp')
-rw-r--r--modules/sslinfo.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/modules/sslinfo.cpp b/modules/sslinfo.cpp
index b88506e4f..d3b21296d 100644
--- a/modules/sslinfo.cpp
+++ b/modules/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,46 @@ 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)
+ {
+ if (!count)
+ continue;
+
+ stats.AddGenericRow(FMT::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