mirror of
https://github.com/znc/znc.git
synced 2026-08-12 11:52:57 +02:00
Merge pull request #1020 from jpnurmi/traffic
Calculate per-network traffic (#963)
This commit is contained in:
@@ -33,6 +33,23 @@
|
||||
<th>Total IRC Connections</th>
|
||||
<td><? VAR TotalIRCConnections ?></td>
|
||||
</tr>
|
||||
<? ELSE ?>
|
||||
<tr class="evenrow">
|
||||
<th>Networks</th>
|
||||
<td><? VAR TotalNetworks ?></td>
|
||||
</tr>
|
||||
<tr class="oddrow">
|
||||
<th>Attached Networks</th>
|
||||
<td><? VAR AttachedNetworks ?></td>
|
||||
</tr>
|
||||
<tr class="evenrow">
|
||||
<th>Client Connections</th>
|
||||
<td><? VAR TotalCConnections ?></td>
|
||||
</tr>
|
||||
<tr class="oddrow">
|
||||
<th>IRC Connections</th>
|
||||
<td><? VAR TotalIRCConnections ?></td>
|
||||
</tr>
|
||||
<? ENDIF ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -40,51 +57,74 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<? IF IsAdmin && TrafficLoop ?>
|
||||
<? IF IsAdmin ?>
|
||||
<div class="section">
|
||||
<h3>Traffic</h3>
|
||||
<h3>Total</h3>
|
||||
<div class="sectionbg">
|
||||
<div class="sectionbody">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Username</td>
|
||||
<td></td>
|
||||
<td>In</td>
|
||||
<td>Out</td>
|
||||
<td>Total</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<? LOOP TrafficLoop SORTASC=Username ?>
|
||||
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
|
||||
<td><? VAR Username ?></td>
|
||||
<td><? VAR In ?></td>
|
||||
<td><? VAR Out ?></td>
|
||||
<td><? VAR Total ?></td>
|
||||
</tr>
|
||||
<? REM ?>Add the totals separately so that if sort is ever used they stay at the bottom
|
||||
By keeping them inside the loop we can figure out even/odd classes though.
|
||||
<? ENDREM ?>
|
||||
<? IF __LAST__ ?>
|
||||
<tr class="<? IF __EVEN__ ?>oddrow<? ELSE ?>evenrow<? ENDIF ?>">
|
||||
<td>User Total</td>
|
||||
<tr class="evenrow">
|
||||
<td>Users</td>
|
||||
<td><? VAR UserIn TOP ?></td>
|
||||
<td><? VAR UserOut TOP ?></td>
|
||||
<td><? VAR UserTotal TOP ?></td>
|
||||
</tr>
|
||||
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
|
||||
<td>ZNC Total</td>
|
||||
<tr class="oddrow">
|
||||
<td>ZNC</td>
|
||||
<td><? VAR ZNCIn TOP ?></td>
|
||||
<td><? VAR ZNCOut TOP ?></td>
|
||||
<td><? VAR ZNCTotal TOP ?></td>
|
||||
</tr>
|
||||
<tr class="<? IF __EVEN__ ?>oddrow<? ELSE ?>evenrow<? ENDIF ?>">
|
||||
<td>Grand Total</td>
|
||||
<tr class="evenrow">
|
||||
<td>Total</td>
|
||||
<td><? VAR AllIn TOP ?></td>
|
||||
<td><? VAR AllOut TOP ?></td>
|
||||
<td><? VAR AllTotal TOP ?></td>
|
||||
</tr>
|
||||
<? ENDIF ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? ENDIF ?>
|
||||
|
||||
<? IF TrafficLoop ?>
|
||||
<div class="section">
|
||||
<? IF IsAdmin ?>
|
||||
<h3>Users</h3>
|
||||
<? ELSE ?>
|
||||
<h3>Traffic</h3>
|
||||
<? ENDIF ?>
|
||||
<div class="sectionbg">
|
||||
<div class="sectionbody">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Username</td>
|
||||
<td>Network</td>
|
||||
<td>In</td>
|
||||
<td>Out</td>
|
||||
<td>Total</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<? LOOP TrafficLoop ?>
|
||||
<tr class="<? IF __EVEN__ ?>evenrow<? ELSE ?>oddrow<? ENDIF ?>">
|
||||
<td><? VAR Username ?></td>
|
||||
<td><? VAR Network ?></td>
|
||||
<td><? VAR In ?></td>
|
||||
<td><? VAR Out ?></td>
|
||||
<td><? VAR Total ?></td>
|
||||
</tr>
|
||||
<? ENDLOOP ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
+23
-2
@@ -78,7 +78,7 @@ public:
|
||||
vParams.push_back(make_pair("user", ""));
|
||||
AddSubPage(std::make_shared<CWebSubPage>("settings", "Global Settings", CWebSubPage::F_ADMIN));
|
||||
AddSubPage(std::make_shared<CWebSubPage>("edituser", "Your Settings", vParams));
|
||||
AddSubPage(std::make_shared<CWebSubPage>("traffic", "Traffic Info", CWebSubPage::F_ADMIN));
|
||||
AddSubPage(std::make_shared<CWebSubPage>("traffic", "Traffic Info", vParams));
|
||||
AddSubPage(std::make_shared<CWebSubPage>("listusers", "Manage Users", CWebSubPage::F_ADMIN));
|
||||
}
|
||||
|
||||
@@ -573,7 +573,7 @@ public:
|
||||
return true;
|
||||
} else if (sPageName == "listusers" && spSession->IsAdmin()) {
|
||||
return ListUsersPage(WebSock, Tmpl);
|
||||
} else if (sPageName == "traffic" && spSession->IsAdmin()) {
|
||||
} else if (sPageName == "traffic") {
|
||||
return TrafficPage(WebSock, Tmpl);
|
||||
} else if (sPageName == "index") {
|
||||
return true;
|
||||
@@ -1431,6 +1431,7 @@ public:
|
||||
}
|
||||
|
||||
bool TrafficPage(CWebSock& WebSock, CTemplate& Tmpl) {
|
||||
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
|
||||
Tmpl["Title"] = "Traffic Info";
|
||||
Tmpl["Uptime"] = CZNC::Get().GetUptime();
|
||||
|
||||
@@ -1441,6 +1442,11 @@ public:
|
||||
|
||||
for (const auto& it : msUsers) {
|
||||
CUser* pUser = it.second;
|
||||
|
||||
if (!spSession->IsAdmin() && spSession->GetUser() != it.second) {
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<CIRCNetwork*> vNetworks = pUser->GetNetworks();
|
||||
|
||||
for (const CIRCNetwork* pNetwork : vNetworks) {
|
||||
@@ -1469,12 +1475,27 @@ public:
|
||||
CZNC::TrafficStatsMap traffic = CZNC::Get().GetTrafficStats(Users, ZNC, Total);
|
||||
|
||||
for (const auto& it : traffic) {
|
||||
if (!spSession->IsAdmin() && !spSession->GetUser()->GetUserName().Equals(it.first)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CTemplate& l = Tmpl.AddRow("TrafficLoop");
|
||||
|
||||
l["Username"] = it.first;
|
||||
l["In"] = CString::ToByteStr(it.second.first);
|
||||
l["Out"] = CString::ToByteStr(it.second.second);
|
||||
l["Total"] = CString::ToByteStr(it.second.first + it.second.second);
|
||||
|
||||
CZNC::TrafficStatsPair NetworkTotal;
|
||||
CZNC::TrafficStatsMap NetworkTraffic = CZNC::Get().GetNetworkTrafficStats(it.first, NetworkTotal);
|
||||
for (const auto& it2 : NetworkTraffic) {
|
||||
CTemplate& l2 = Tmpl.AddRow("TrafficLoop");
|
||||
|
||||
l2["Network"] = it2.first;
|
||||
l2["In"] = CString::ToByteStr(it2.second.first);
|
||||
l2["Out"] = CString::ToByteStr(it2.second.second);
|
||||
l2["Total"] = CString::ToByteStr(it2.second.first + it2.second.second);
|
||||
}
|
||||
}
|
||||
|
||||
Tmpl["UserIn"] = CString::ToByteStr(Users.first);
|
||||
|
||||
Reference in New Issue
Block a user