aboutsummaryrefslogtreecommitdiff
path: root/userapi
diff options
context:
space:
mode:
authorDavid Spenler <15622190+DavidSpenler@users.noreply.github.com>2020-11-17 05:07:03 -0500
committerGitHub <noreply@github.com>2020-11-17 10:07:03 +0000
commit35ea55e70bf9d4e9db8fe0e0c741f685dcedf0ec (patch)
tree9f6bdc6d1c7a1c9d2f43ce0e6a51cb37ac452357 /userapi
parentd3b3371856b4593cded8b5c77a6edd02746804ed (diff)
Implemented whois endpoint (#1573)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'userapi')
-rw-r--r--userapi/storage/devices/postgres/devices_table.go17
-rw-r--r--userapi/storage/devices/sqlite3/devices_table.go17
2 files changed, 28 insertions, 6 deletions
diff --git a/userapi/storage/devices/postgres/devices_table.go b/userapi/storage/devices/postgres/devices_table.go
index 379fed79..cc554fe7 100644
--- a/userapi/storage/devices/postgres/devices_table.go
+++ b/userapi/storage/devices/postgres/devices_table.go
@@ -77,7 +77,7 @@ const selectDeviceByIDSQL = "" +
"SELECT display_name FROM device_devices WHERE localpart = $1 and device_id = $2"
const selectDevicesByLocalpartSQL = "" +
- "SELECT device_id, display_name FROM device_devices WHERE localpart = $1 AND device_id != $2"
+ "SELECT device_id, display_name, last_seen_ts, ip, user_agent FROM device_devices WHERE localpart = $1 AND device_id != $2"
const updateDeviceNameSQL = "" +
"UPDATE device_devices SET display_name = $1 WHERE localpart = $2 AND device_id = $3"
@@ -281,8 +281,9 @@ func (s *devicesStatements) selectDevicesByLocalpart(
for rows.Next() {
var dev api.Device
- var id, displayname sql.NullString
- err = rows.Scan(&id, &displayname)
+ var lastseents sql.NullInt64
+ var id, displayname, ip, useragent sql.NullString
+ err = rows.Scan(&id, &displayname, &lastseents, &ip, &useragent)
if err != nil {
return devices, err
}
@@ -292,6 +293,16 @@ func (s *devicesStatements) selectDevicesByLocalpart(
if displayname.Valid {
dev.DisplayName = displayname.String
}
+ if lastseents.Valid {
+ dev.LastSeenTS = lastseents.Int64
+ }
+ if ip.Valid {
+ dev.LastSeenIP = ip.String
+ }
+ if useragent.Valid {
+ dev.UserAgent = useragent.String
+ }
+
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
devices = append(devices, dev)
}
diff --git a/userapi/storage/devices/sqlite3/devices_table.go b/userapi/storage/devices/sqlite3/devices_table.go
index 26c03222..cdfe2bb9 100644
--- a/userapi/storage/devices/sqlite3/devices_table.go
+++ b/userapi/storage/devices/sqlite3/devices_table.go
@@ -62,7 +62,7 @@ const selectDeviceByIDSQL = "" +
"SELECT display_name FROM device_devices WHERE localpart = $1 and device_id = $2"
const selectDevicesByLocalpartSQL = "" +
- "SELECT device_id, display_name FROM device_devices WHERE localpart = $1 AND device_id != $2"
+ "SELECT device_id, display_name, last_seen_ts, ip, user_agent FROM device_devices WHERE localpart = $1 AND device_id != $2"
const updateDeviceNameSQL = "" +
"UPDATE device_devices SET display_name = $1 WHERE localpart = $2 AND device_id = $3"
@@ -256,8 +256,9 @@ func (s *devicesStatements) selectDevicesByLocalpart(
for rows.Next() {
var dev api.Device
- var id, displayname sql.NullString
- err = rows.Scan(&id, &displayname)
+ var lastseents sql.NullInt64
+ var id, displayname, ip, useragent sql.NullString
+ err = rows.Scan(&id, &displayname, &lastseents, &ip, &useragent)
if err != nil {
return devices, err
}
@@ -267,6 +268,16 @@ func (s *devicesStatements) selectDevicesByLocalpart(
if displayname.Valid {
dev.DisplayName = displayname.String
}
+ if lastseents.Valid {
+ dev.LastSeenTS = lastseents.Int64
+ }
+ if ip.Valid {
+ dev.LastSeenIP = ip.String
+ }
+ if useragent.Valid {
+ dev.UserAgent = useragent.String
+ }
+
dev.UserID = userutil.MakeUserID(localpart, s.serverName)
devices = append(devices, dev)
}