mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-16 16:57:08 +00:00
feat: enhance pass-through statistics to include source and destination addresses
This commit is contained in:
parent
85d81c1f78
commit
a392e6272a
@ -15,9 +15,9 @@ local pass_stats = {}
|
|||||||
local pass_stats_file = io.open("/var/log/ua3f/pass_stats", "r")
|
local pass_stats_file = io.open("/var/log/ua3f/pass_stats", "r")
|
||||||
if pass_stats_file then
|
if pass_stats_file then
|
||||||
for line in pass_stats_file:lines() do
|
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
|
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
|
||||||
end
|
end
|
||||||
pass_stats_file:close()
|
pass_stats_file:close()
|
||||||
@ -54,14 +54,16 @@ end
|
|||||||
<tr class="tr table-titles">
|
<tr class="tr table-titles">
|
||||||
<th class="th"><%:User-Agent%></th>
|
<th class="th"><%:User-Agent%></th>
|
||||||
<th class="th"><%:Pass-Through Count%></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>
|
</tr>
|
||||||
|
|
||||||
<% for i, item in ipairs(pass_stats) do %>
|
<% for i, item in ipairs(pass_stats) do %>
|
||||||
<tr class="tr <%= rowstyle(i) %>">
|
<tr class="tr <%= rowstyle(i) %>">
|
||||||
<td class="td" data-title="<%:User-Agent%>"><span><%= item.ua %></span></td>
|
<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="<%: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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
@ -120,12 +122,12 @@ end
|
|||||||
|
|
||||||
#pass-stats-table th:nth-child(1),
|
#pass-stats-table th:nth-child(1),
|
||||||
#pass-stats-table td:nth-child(1) {
|
#pass-stats-table td:nth-child(1) {
|
||||||
width: 50%;
|
width: 30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pass-stats-table th:nth-child(2),
|
#pass-stats-table th:nth-child(2),
|
||||||
#pass-stats-table td:nth-child(2) {
|
#pass-stats-table td:nth-child(2) {
|
||||||
width: 20%;
|
width: 10%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,4 +135,9 @@ end
|
|||||||
#pass-stats-table td:nth-child(3) {
|
#pass-stats-table td:nth-child(3) {
|
||||||
width: 30%;
|
width: 30%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pass-stats-table th:nth-child(4),
|
||||||
|
#pass-stats-table td:nth-child(4) {
|
||||||
|
width: 30%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -83,8 +83,11 @@ msgstr "User-Agent 放行次数实时统计"
|
|||||||
msgid "Pass-Through Count"
|
msgid "Pass-Through Count"
|
||||||
msgstr "放行次数"
|
msgstr "放行次数"
|
||||||
|
|
||||||
msgid "Last Host"
|
msgid "Last Source Address"
|
||||||
msgstr "最后访问地址"
|
msgstr "最近访问源地址"
|
||||||
|
|
||||||
|
msgid "Last Destination Address"
|
||||||
|
msgstr "最近访问目标地址"
|
||||||
|
|
||||||
msgid "Display Lines"
|
msgid "Display Lines"
|
||||||
msgstr "显示行数"
|
msgstr "显示行数"
|
||||||
|
|||||||
@ -113,8 +113,9 @@ func (r *Rewriter) ShouldRewrite(req *http.Request, srcAddr, destAddr string) bo
|
|||||||
hit := !isWhitelist && matches
|
hit := !isWhitelist && matches
|
||||||
if !hit {
|
if !hit {
|
||||||
statistics.AddPassThroughRecord(&statistics.PassThroughRecord{
|
statistics.AddPassThroughRecord(&statistics.PassThroughRecord{
|
||||||
Host: destAddr,
|
SrcAddr: srcAddr,
|
||||||
UA: originalUA,
|
DestAddr: destAddr,
|
||||||
|
UA: originalUA,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return hit
|
return hit
|
||||||
|
|||||||
@ -11,9 +11,10 @@ import (
|
|||||||
const passthroughStatsFile = "/var/log/ua3f/pass_stats"
|
const passthroughStatsFile = "/var/log/ua3f/pass_stats"
|
||||||
|
|
||||||
type PassThroughRecord struct {
|
type PassThroughRecord struct {
|
||||||
Host string
|
SrcAddr string
|
||||||
UA string
|
DestAddr string
|
||||||
Count int
|
UA string
|
||||||
|
Count int
|
||||||
}
|
}
|
||||||
|
|
||||||
var passThroughRecords = make(map[string]*PassThroughRecord)
|
var passThroughRecords = make(map[string]*PassThroughRecord)
|
||||||
@ -42,7 +43,7 @@ func dumpPassThroughRecords() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for _, record := range statList {
|
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)
|
f.WriteString(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,12 +35,14 @@ func StartRecorder() {
|
|||||||
}
|
}
|
||||||
if r, exists := passThroughRecords[record.UA]; exists {
|
if r, exists := passThroughRecords[record.UA]; exists {
|
||||||
r.Count++
|
r.Count++
|
||||||
r.Host = record.Host
|
r.DestAddr = record.DestAddr
|
||||||
|
r.SrcAddr = record.SrcAddr
|
||||||
} else {
|
} else {
|
||||||
passThroughRecords[record.UA] = &PassThroughRecord{
|
passThroughRecords[record.UA] = &PassThroughRecord{
|
||||||
Host: record.Host,
|
SrcAddr: record.SrcAddr,
|
||||||
UA: record.UA,
|
DestAddr: record.DestAddr,
|
||||||
Count: 1,
|
UA: record.UA,
|
||||||
|
Count: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user