fix: remove UA - IP mapping from redis

pull/199/head
Raphaël Vinot 2021-04-18 17:58:16 +02:00
parent be1ca8d088
commit 9952e4de32
2 changed files with 11 additions and 0 deletions

View File

@ -123,6 +123,9 @@ class Lookyloo():
with self_generated_ua_file.open('w') as f:
json.dump(to_store, f, indent=2)
# Remove the UA / IP mapping.
self.redis.delete(f'user_agents|{yesterday.isoformat()}')
def _cache_capture(self, capture_uuid: str) -> CrawledTree:
'''Generate the pickle, set the cache, add capture in the indexes'''
capture_dir = self._get_capture_dir(capture_uuid)

View File

@ -191,6 +191,14 @@ app.jinja_env.globals.update(month_name=month_name)
@app.after_request
def after_request(response):
# We keep a list user agents in order to build a list to use in the capture
# interface: this is the easiest way to have something up to date.
# The reason we also get the IP address of the client is because we
# count the frequency of each user agents and use it to sort them on the
# capture page, and we want to avoid counting the same user (same IP)
# multiple times in a day.
# The cache of IPs is deleted after the UA file is generated (see lookyloo.build_ua_file),
# once a day.
ua = request.headers.get('User-Agent')
real_ip = request.headers.get('X-Real-IP')
if ua: