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
This commit is contained in:
psychon
2010-12-24 21:56:35 +00:00
parent f6935557ce
commit 144cdf256b
2 changed files with 63 additions and 0 deletions
+35
View File
@@ -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<CSocketSorter> 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);
+28
View File
@@ -0,0 +1,28 @@
<? INC Header.tmpl ?>
<table class="data">
<thead>
<tr>
<td>Name</td>
<td>Created</td>
<td>State</td>
<td>SSL</td>
<td>Local</td>
<td>Remote</td>
</tr>
</thead>
<tbody>
<? LOOP SocketsLoop ?>
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
<td><? VAR Name ?></td>
<td><? VAR Created ?></td>
<td><? VAR State ?></td>
<td><? VAR SSL ?></td>
<td><? VAR Local ?></td>
<td><? VAR Remote ?></td>
</tr>
<? ENDLOOP ?>
</tbody>
</table>
<? INC Footer.tmpl ?>