diff --git a/plugins/webstats/index.py b/plugins/webstats/index.py index 35fec34b1..49e97f5a8 100755 --- a/plugins/webstats/index.py +++ b/plugins/webstats/index.py @@ -965,6 +965,17 @@ def getIpStatList(): total_req = 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: total_req += x['day'] total_flow += x['flow'] @@ -972,6 +983,16 @@ def getIpStatList(): for i in range(len(clist)): clist[i]['day_rate'] = round((clist[i]['day'] / total_req) * 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) diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 0869746e7..3576641d2 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -1750,7 +1750,7 @@ function wsIpStatLogRequest(page){ list += ''; list += '' + (parseInt(i)+1)+''; list += '' + data[i]['ip']+''; - list += '' + "0" +''; + list += '' + data[i]['area'] +''; list += '' + data[i]['day'] +'('+data[i]['day_rate']+'%)'; list += '' + toSize(data[i]['flow']) +'('+data[i]['flow_rate']+'%)'; list += '
' +'';