feat: enhance pass-through statistics to include source and destination addresses

This commit is contained in:
SunBK201 2025-11-06 13:50:54 +08:00
parent 85d81c1f78
commit a392e6272a
5 changed files with 32 additions and 18 deletions

View File

@ -15,9 +15,9 @@ local pass_stats = {}
local pass_stats_file = io.open("/var/log/ua3f/pass_stats", "r")
if pass_stats_file then
for line in pass_stats_file:lines() do
local host, count, ua = line:match("^(%S+)%s(%d+)%s(.+)$")
local srcAddr, destAddr, count, ua = line:match("^(%S+)%s(%S+)%s(%d+)%s(.+)$")
if ua and count then
table.insert(pass_stats, {ua = ua, count = count, host = host})
table.insert(pass_stats, {ua = ua, count = count, srcAddr = srcAddr, destAddr = destAddr})
end
end
pass_stats_file:close()
@ -54,14 +54,16 @@ end
<tr class="tr table-titles">
<th class="th"><%:User-Agent%></th>
<th class="th"><%:Pass-Through Count%></th>
<th class="th"><%:Last Host%></th>
<th class="th"><%:Last Source Address%></th>
<th class="th"><%:Last Destination Address%></th>
</tr>
<% for i, item in ipairs(pass_stats) do %>
<tr class="tr <%= rowstyle(i) %>">
<td class="td" data-title="<%:User-Agent%>"><span><%= item.ua %></span></td>
<td class="td" data-title="<%:Pass-Through Count%>"><%= item.count %></td>
<td class="td" data-title="<%:Last Host%>"><span><%= item.host %></span></td>
<td class="td" data-title="<%:Last Source Address%>"><span><%= item.srcAddr %></span></td>
<td class="td" data-title="<%:Last Destination Address%>"><span><%= item.destAddr %></span></td>
</tr>
<% end %>
</table>
@ -120,12 +122,12 @@ end
#pass-stats-table th:nth-child(1),
#pass-stats-table td:nth-child(1) {
width: 50%;
width: 30%;
}
#pass-stats-table th:nth-child(2),
#pass-stats-table td:nth-child(2) {
width: 20%;
width: 10%;
text-align: center;
}
@ -133,4 +135,9 @@ end
#pass-stats-table td:nth-child(3) {
width: 30%;
}
#pass-stats-table th:nth-child(4),
#pass-stats-table td:nth-child(4) {
width: 30%;
}
</style>

View File

@ -83,8 +83,11 @@ msgstr "User-Agent 放行次数实时统计"
msgid "Pass-Through Count"
msgstr "放行次数"
msgid "Last Host"
msgstr "最后访问地址"
msgid "Last Source Address"
msgstr "最近访问源地址"
msgid "Last Destination Address"
msgstr "最近访问目标地址"
msgid "Display Lines"
msgstr "显示行数"

View File

@ -113,7 +113,8 @@ func (r *Rewriter) ShouldRewrite(req *http.Request, srcAddr, destAddr string) bo
hit := !isWhitelist && matches
if !hit {
statistics.AddPassThroughRecord(&statistics.PassThroughRecord{
Host: destAddr,
SrcAddr: srcAddr,
DestAddr: destAddr,
UA: originalUA,
})
}

View File

@ -11,7 +11,8 @@ import (
const passthroughStatsFile = "/var/log/ua3f/pass_stats"
type PassThroughRecord struct {
Host string
SrcAddr string
DestAddr string
UA string
Count int
}
@ -42,7 +43,7 @@ func dumpPassThroughRecords() {
})
for _, record := range statList {
line := fmt.Sprintf("%s %d %s\n", record.Host, record.Count, record.UA)
line := fmt.Sprintf("%s %s %d %s\n", record.SrcAddr, record.DestAddr, record.Count, record.UA)
f.WriteString(line)
}
}

View File

@ -35,10 +35,12 @@ func StartRecorder() {
}
if r, exists := passThroughRecords[record.UA]; exists {
r.Count++
r.Host = record.Host
r.DestAddr = record.DestAddr
r.SrcAddr = record.SrcAddr
} else {
passThroughRecords[record.UA] = &PassThroughRecord{
Host: record.Host,
SrcAddr: record.SrcAddr,
DestAddr: record.DestAddr,
UA: record.UA,
Count: 1,
}