pull/139/head
midoks 3 years ago
parent dd6659f0a1
commit 070f3924d0
  1. 21
      plugins/webstats/index.py
  2. 2
      plugins/webstats/js/stats.js

@ -965,6 +965,17 @@ def getIpStatList():
total_req = 0 total_req = 0
total_flow = 0 total_flow = 0
gepip_mmdb = getServerDir() + '/GeoLite2-City.mmdb'
geoip_exists = False
if os.path.exists(gepip_mmdb):
import geoip2.database
reader = geoip2.database.Reader(gepip_mmdb)
geoip_exists = True
# response = reader.city("172.70.206.144")
# print(response.country.names["zh-CN"])
# print(response.subdivisions.most_specific.names["zh-CN"])
# print(response.city.names["zh-CN"])
for x in clist: for x in clist:
total_req += x['day'] total_req += x['day']
total_flow += x['flow'] total_flow += x['flow']
@ -972,6 +983,16 @@ def getIpStatList():
for i in range(len(clist)): for i in range(len(clist)):
clist[i]['day_rate'] = round((clist[i]['day'] / total_req) * 100, 2) clist[i]['day_rate'] = round((clist[i]['day'] / total_req) * 100, 2)
clist[i]['flow_rate'] = round((clist[i]['flow'] / total_flow) * 100, 2) clist[i]['flow_rate'] = round((clist[i]['flow'] / total_flow) * 100, 2)
ip = clist[i]['ip']
if ip == "127.0.0.1":
clist[i]['area'] = "本地"
elif geoip_exists:
response = reader.city(clist[i]['ip'])
country = response.country.names["zh-CN"]
subdivisions = response.subdivisions.most_specific.names["zh-CN"]
city = response.city.names["zh-CN"]
clist[i]['area'] = country + "," + subdivisions + "," + city
return mw.returnJson(True, 'ok', clist) return mw.returnJson(True, 'ok', clist)

@ -1750,7 +1750,7 @@ function wsIpStatLogRequest(page){
list += '<tr>'; list += '<tr>';
list += '<td>' + (parseInt(i)+1)+'</td>'; list += '<td>' + (parseInt(i)+1)+'</td>';
list += '<td><span style="width:100px;">' + data[i]['ip']+'</span></td>'; list += '<td><span style="width:100px;">' + data[i]['ip']+'</span></td>';
list += '<td>' + "0" +'</td>'; list += '<td>' + data[i]['area'] +'</td>';
list += '<td>' + data[i]['day'] +'('+data[i]['day_rate']+'%)</td>'; list += '<td>' + data[i]['day'] +'('+data[i]['day_rate']+'%)</td>';
list += '<td>' + toSize(data[i]['flow']) +'('+data[i]['flow_rate']+'%)</td>'; list += '<td>' + toSize(data[i]['flow']) +'('+data[i]['flow_rate']+'%)</td>';
list += '<td><span><div class="share_num" style="width:'+data[i]['flow_rate']+'%"></div></span>' +'</td>'; list += '<td><span><div class="share_num" style="width:'+data[i]['flow_rate']+'%"></div></span>' +'</td>';

Loading…
Cancel
Save