mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 20:29:22 -05:00
SYN-48: Track User-Agents as well as IPs for client devices.
This commit is contained in:
parent
0fdf308874
commit
f7d80930f2
@ -223,8 +223,17 @@ class Auth(object):
|
|||||||
user = yield self.get_user_by_token(access_token)
|
user = yield self.get_user_by_token(access_token)
|
||||||
|
|
||||||
ip_addr = self.hs.get_ip_from_request(request)
|
ip_addr = self.hs.get_ip_from_request(request)
|
||||||
|
user_agent = request.requestHeaders.getRawHeaders(
|
||||||
|
"User-Agent",
|
||||||
|
default=[""]
|
||||||
|
)[0]
|
||||||
if user and access_token and ip_addr:
|
if user and access_token and ip_addr:
|
||||||
self.store.insert_client_ip(user, access_token, ip_addr)
|
self.store.insert_client_ip(
|
||||||
|
user,
|
||||||
|
access_token,
|
||||||
|
ip_addr,
|
||||||
|
user_agent
|
||||||
|
)
|
||||||
|
|
||||||
defer.returnValue(user)
|
defer.returnValue(user)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -294,13 +294,15 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
|
|
||||||
defer.returnValue(self.min_token)
|
defer.returnValue(self.min_token)
|
||||||
|
|
||||||
def insert_client_ip(self, user, access_token, ip):
|
def insert_client_ip(self, user, access_token, ip, user_agent):
|
||||||
return self._simple_insert(
|
return self._simple_insert(
|
||||||
"user_ips",
|
"user_ips",
|
||||||
{
|
{
|
||||||
"user": user.to_string(),
|
"user": user.to_string(),
|
||||||
"access_token": access_token,
|
"access_token": access_token,
|
||||||
"ip": ip
|
"ip": ip,
|
||||||
|
"user_agent": user_agent,
|
||||||
|
"last_used": int(self._clock.time()),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ CREATE TABLE IF NOT EXISTS user_ips (
|
|||||||
user TEXT NOT NULL,
|
user TEXT NOT NULL,
|
||||||
access_token TEXT NOT NULL,
|
access_token TEXT NOT NULL,
|
||||||
ip TEXT NOT NULL,
|
ip TEXT NOT NULL,
|
||||||
CONSTRAINT user_ip UNIQUE (user, access_token, ip) ON CONFLICT IGNORE
|
user_agent TEXT NOT NULL,
|
||||||
|
last_used INTEGER NOT NULL,
|
||||||
|
CONSTRAINT user_ip UNIQUE (user, access_token, ip, user_agent) ON CONFLICT REPLACE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
||||||
|
@ -35,7 +35,9 @@ CREATE TABLE IF NOT EXISTS user_ips (
|
|||||||
user TEXT NOT NULL,
|
user TEXT NOT NULL,
|
||||||
access_token TEXT NOT NULL,
|
access_token TEXT NOT NULL,
|
||||||
ip TEXT NOT NULL,
|
ip TEXT NOT NULL,
|
||||||
CONSTRAINT user_ip UNIQUE (user, access_token, ip) ON CONFLICT IGNORE
|
user_agent TEXT NOT NULL,
|
||||||
|
last_used INTEGER NOT NULL,
|
||||||
|
CONSTRAINT user_ip UNIQUE (user, access_token, ip, user_agent) ON CONFLICT REPLACE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
CREATE INDEX IF NOT EXISTS user_ips_user ON user_ips(user);
|
||||||
|
Loading…
Reference in New Issue
Block a user