mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-03 06:07:20 +02:00
parent
53657e8716
commit
3993ac954c
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -545,3 +546,39 @@ func handleWhitelistEnable(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.SendOK(w)
|
utils.SendOK(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List all quick ban ip address
|
||||||
|
func handleListQuickBan(w http.ResponseWriter, r *http.Request) {
|
||||||
|
currentSummary := statisticCollector.GetCurrentDailySummary()
|
||||||
|
type quickBanEntry struct {
|
||||||
|
IpAddr string
|
||||||
|
Count int
|
||||||
|
CountryCode string
|
||||||
|
}
|
||||||
|
result := []quickBanEntry{}
|
||||||
|
currentSummary.RequestClientIp.Range(func(key, value interface{}) bool {
|
||||||
|
ip := key.(string)
|
||||||
|
count := value.(int)
|
||||||
|
thisEntry := quickBanEntry{
|
||||||
|
IpAddr: ip,
|
||||||
|
Count: count,
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the country code
|
||||||
|
geoinfo, err := geodbStore.ResolveCountryCodeFromIP(ip)
|
||||||
|
if err == nil {
|
||||||
|
thisEntry.CountryCode = geoinfo.CountryIsoCode
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, thisEntry)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
//Sort result based on count
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
return result[i].Count > result[j].Count
|
||||||
|
})
|
||||||
|
|
||||||
|
js, _ := json.Marshal(result)
|
||||||
|
utils.SendJSONResponse(w, string(js))
|
||||||
|
}
|
||||||
|
@ -114,6 +114,9 @@ func RegisterAccessRuleAPIs(authRouter *auth.RouterDef) {
|
|||||||
authRouter.HandleFunc("/api/whitelist/ip/add", handleIpWhitelistAdd)
|
authRouter.HandleFunc("/api/whitelist/ip/add", handleIpWhitelistAdd)
|
||||||
authRouter.HandleFunc("/api/whitelist/ip/remove", handleIpWhitelistRemove)
|
authRouter.HandleFunc("/api/whitelist/ip/remove", handleIpWhitelistRemove)
|
||||||
authRouter.HandleFunc("/api/whitelist/enable", handleWhitelistEnable)
|
authRouter.HandleFunc("/api/whitelist/enable", handleWhitelistEnable)
|
||||||
|
|
||||||
|
/* Quick Ban List */
|
||||||
|
authRouter.HandleFunc("/api/quickban/list", handleListQuickBan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the APIs for path blocking rules management functions, WIP
|
// Register the APIs for path blocking rules management functions, WIP
|
||||||
|
@ -694,6 +694,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>IP</th>
|
<th>IP</th>
|
||||||
<th>Access Count</th>
|
<th>Access Count</th>
|
||||||
|
<th>Country of Origin</th>
|
||||||
<th>Blacklist</th>
|
<th>Blacklist</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -1489,15 +1490,30 @@
|
|||||||
|
|
||||||
//Load the summary to ip access table
|
//Load the summary to ip access table
|
||||||
function initBlacklistQuickBanTable(){
|
function initBlacklistQuickBanTable(){
|
||||||
$.get("/api/stats/summary", function(data){
|
$.get("/api/quickban/list", function(data){
|
||||||
initIpAccessTable(data.RequestClientIp);
|
//Convert the data to a dictionary
|
||||||
|
var ipAccessCounts = {};
|
||||||
|
access_ip_country_map = {};
|
||||||
|
data.forEach(function(entry){
|
||||||
|
ipAccessCounts[entry.IpAddr] = entry.Count
|
||||||
|
access_ip_country_map[entry.IpAddr] = entry.CountryCode;
|
||||||
|
});
|
||||||
|
initIpAccessTable(ipAccessCounts);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
initBlacklistQuickBanTable();
|
initBlacklistQuickBanTable();
|
||||||
|
|
||||||
|
function getCountryISOFromQuickBan(ip){
|
||||||
|
if (access_ip_country_map[ip] === "") {
|
||||||
|
return "LAN / Reserved";
|
||||||
|
}
|
||||||
|
return access_ip_country_map[ip];
|
||||||
|
}
|
||||||
|
|
||||||
var blacklist_entriesPerPage = 30;
|
var blacklist_entriesPerPage = 30;
|
||||||
var blacklist_currentPage = 1;
|
var blacklist_currentPage = 1;
|
||||||
var blacklist_totalPages = 0;
|
var blacklist_totalPages = 0;
|
||||||
|
var access_ip_country_map = {};
|
||||||
|
|
||||||
function initIpAccessTable(ipAccessCounts){
|
function initIpAccessTable(ipAccessCounts){
|
||||||
blacklist_totalPages = Math.ceil(Object.keys(ipAccessCounts).length / blacklist_entriesPerPage);
|
blacklist_totalPages = Math.ceil(Object.keys(ipAccessCounts).length / blacklist_entriesPerPage);
|
||||||
@ -1533,6 +1549,7 @@
|
|||||||
var row = $("<tr>").appendTo(tableBody);
|
var row = $("<tr>").appendTo(tableBody);
|
||||||
$("<td>").text(ip).appendTo(row);
|
$("<td>").text(ip).appendTo(row);
|
||||||
$("<td>").text(accessCount).appendTo(row);
|
$("<td>").text(accessCount).appendTo(row);
|
||||||
|
$("<td>").text(getCountryISOFromQuickBan(ip)).appendTo(row);
|
||||||
if (ipInBlacklist(ip)){
|
if (ipInBlacklist(ip)){
|
||||||
$("<td>").html(`<button class="ui basic green tiny icon button" title"Unban IP" onclick="handleUnban('${ip}');"><i class="green check icon"></i></button>`).appendTo(row);
|
$("<td>").html(`<button class="ui basic green tiny icon button" title"Unban IP" onclick="handleUnban('${ip}');"><i class="green check icon"></i></button>`).appendTo(row);
|
||||||
}else{
|
}else{
|
||||||
@ -1542,7 +1559,7 @@
|
|||||||
|
|
||||||
if (slicedEntries.length == 0){
|
if (slicedEntries.length == 0){
|
||||||
var row = $("<tr>").appendTo(tableBody);
|
var row = $("<tr>").appendTo(tableBody);
|
||||||
$("<td colspan='3'>").html(`
|
$("<td colspan='4'>").html(`
|
||||||
<i class="ui green circle check icon"></i> There are no HTTP requests recorded today
|
<i class="ui green circle check icon"></i> There are no HTTP requests recorded today
|
||||||
`).appendTo(row);
|
`).appendTo(row);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user