From 144cdf256bd964112abcfd14ea5f01a1777aa019 Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 24 Dec 2010 21:56:35 +0000 Subject: [PATCH] Add a web interface to listsockets Thanks to kylef for the patch and again sorry for svn. ;) git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2212 726aef4b-f618-498e-8847-2d620e286838 --- modules/extra/listsockets.cpp | 35 +++++++++++++++++++++++ modules/extra/listsockets/tmpl/index.tmpl | 28 ++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 modules/extra/listsockets/tmpl/index.tmpl diff --git a/modules/extra/listsockets.cpp b/modules/extra/listsockets.cpp index cce36c40..e7c534d6 100644 --- a/modules/extra/listsockets.cpp +++ b/modules/extra/listsockets.cpp @@ -72,6 +72,41 @@ public: return true; } + virtual bool WebRequiresAdmin() { return true; } + virtual CString GetWebMenuTitle() { return "List sockets"; } + + virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { + if (sPageName.empty() || sPageName == "index") { + CSockManager& m = CZNC::Get().GetManager(); + if (!m.size()) { + return false; + } + + std::priority_queue socks; + + for (unsigned int a = 0; a < m.size(); a++) { + socks.push(m[a]); + } + + while (!socks.empty()) { + Csock* pSocket = socks.top().GetSock(); + socks.pop(); + + CTemplate& Row = Tmpl.AddRow("SocketsLoop"); + Row["Name"] = pSocket->GetSockName(); + Row["Created"] = GetCreatedTime(pSocket); + Row["State"] = GetSocketState(pSocket); + Row["SSL"] = pSocket->GetSSL() ? "Yes" : "No"; + Row["Local"] = GetLocalHost(pSocket, true); + Row["Remote"] = GetRemoteHost(pSocket, true); + } + + return true; + } + + return false; + } + virtual void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0); CString sArg = sLine.Token(1, true); diff --git a/modules/extra/listsockets/tmpl/index.tmpl b/modules/extra/listsockets/tmpl/index.tmpl new file mode 100644 index 00000000..01c90822 --- /dev/null +++ b/modules/extra/listsockets/tmpl/index.tmpl @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCreatedStateSSLLocalRemote
+ +