diff --git a/logview/views.py b/logview/views.py index 2d4a279..63543a3 100644 --- a/logview/views.py +++ b/logview/views.py @@ -24,14 +24,17 @@ from django.db.models import Q def get_city_by_ip(ip): - try: - doc = requests.get('https://whois.pconline.com.cn/ip.jsp?ip=%s' % ip, - headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' - '(KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'}).text.strip() - city = doc.split(' ')[0] - except Exception as e: - city = '' - return city + for _ in range(3): + try: + doc = requests.get('https://whois.pconline.com.cn/ip.jsp?ip=%s' % ip, + headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'}).text.strip() + city = doc.split(' ')[0] + if city == '503': + continue + except Exception as e: + city = '' + return city @csrf_exempt @@ -56,7 +59,7 @@ def index(request): user_domain = items[-2] user = User.objects.filter(user_domain=user_domain) if user: - city = get_city_by_ip(remote_addr) + city = '' # get_city_by_ip(remote_addr) request_headers = '' for key in request.META: if key.startswith('REQUEST_') or key.startswith('HTTP_') or key.startswith('CONTENT_'): diff --git a/templates/views.html b/templates/views.html index 34af9bf..3d19d6d 100644 --- a/templates/views.html +++ b/templates/views.html @@ -69,7 +69,10 @@ {% translate '域名' %} Type IP - {% translate '位置' %} + {% translate '位置' %} +
+
+ {% translate '时间' %} {% translate '操作' %} @@ -113,7 +116,10 @@ ID URL IP - {% translate '位置' %} + {% translate '位置' %} +
+
+ {% translate '时间' %} {% translate '操作' %} @@ -121,7 +127,7 @@ {% for log in logs %} - {{log.id}} + {{log.id}} {{ log.path }} {% if log.remote_addr %} {{ log.remote_addr }} {% else %}   {% endif %} {% if log.city %} {{ log.city }} {% else %}   {% endif %} @@ -492,25 +498,36 @@ $('[data-toggle="popover"]').popover(); }) $(document).ready(function() { + var loc = $(location).attr('pathname'); + if (loc.endsWith('/web/')){ + col_index = 2 + } + if (loc.endsWith('/dns/')){ + col_index = 3 + } var allIPs = new Set([]); $('.table tr').each(function(index) { - if (index !== 0){ - allIPs.add($(this).children('td')[3].innerText); + if (index !== 0 && $(this).children('td')[col_index]){ + allIPs.add($(this).children('td')[col_index].innerText); } }); if (allIPs.size !== 0 ){ $.post("/ip2location", {"ips": Array.from(allIPs).join(',')}, function(result){ var data = $.parseJSON(result); $('.table tr').each(function(index) { - if (index !== 0){ - let ip = $(this).children('td')[3].innerText; + if (index !== 0 && $(this).children('td')[col_index]){ + let ip = $(this).children('td')[col_index].innerText; if (ip in data){ - $(this).children('td')[4].innerText = data[ip]; + $(this).children('td')[col_index+1].innerText = data[ip]; } } }); + $('#spinner_location').hide() }); + } else { + $('#spinner_location').hide() } + });