Log telemetry connections in DB (#63435)

About The Pull Request

Logs tgui telemetry connections into the database. Useful since they are normally capped to 5.

Does not change the fact that the "banned account in connection history" part is still based on your history at that time. I figured it could potentially be very slow to go through your entire database history.
This commit is contained in:
Mothblocks
2021-12-21 19:52:17 -08:00
committed by GitHub
parent 360d2659af
commit f0c78c9667
5 changed files with 97 additions and 6 deletions

View File

@@ -1,13 +1,33 @@
Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255. Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255.
The latest database version is 5.20; The query to update the schema revision table is: Make sure to also update `DB_MAJOR_VERSION` and `DB_MINOR_VERSION`, which can be found in `code/__DEFINES/subsystem.dm`.
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 20); The latest database version is 5.21; The query to update the schema revision table is:
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 21);
or or
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 20); INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 21);
In any query remember to add a prefix to the table names if you use one. In any query remember to add a prefix to the table names if you use one.
Version 5.21, 15 December 2021, by Mothblocks
Adds `telemetry_connections` table for tracking tgui telemetry.
```
CREATE TABLE `telemetry_connections` (
`id` INT NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(32) NOT NULL,
`telemetry_ckey` VARCHAR(32) NOT NULL,
`address` INT(10) NOT NULL,
`computer_id` VARCHAR(32) NOT NULL,
`first_round_id` INT(11) UNSIGNED NULL,
`latest_round_id` INT(11) UNSIGNED NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`)
);
```
-----------------------------------------------------
Version 5.20, 11 November 2021, by Mothblocks Version 5.20, 11 November 2021, by Mothblocks
Adds `admin_ckey` field to the `known_alts` table to track who added what. Adds `admin_ckey` field to the `known_alts` table to track who added what.

View File

@@ -677,6 +677,22 @@ CREATE TABLE `known_alts` (
UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`) UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`)
); );
--
-- Table structure for table `telemetry_connections`
--
DROP TABLE IF EXISTS `telemetry_connections`;
CREATE TABLE `telemetry_connections` (
`id` INT NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(32) NOT NULL,
`telemetry_ckey` VARCHAR(32) NOT NULL,
`address` INT(10) NOT NULL,
`computer_id` VARCHAR(32) NOT NULL,
`first_round_id` INT(11) UNSIGNED NULL,
`latest_round_id` INT(11) UNSIGNED NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`)
);
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

View File

@@ -677,6 +677,22 @@ CREATE TABLE `SS13_known_alts` (
UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`) UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`)
); );
--
-- Table structure for table `telemetry_connections`
--
DROP TABLE IF EXISTS `SS13_telemetry_connections`;
CREATE TABLE `SS13_telemetry_connections` (
`id` INT NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(32) NOT NULL,
`telemetry_ckey` VARCHAR(32) NOT NULL,
`address` INT(10) NOT NULL,
`computer_id` VARCHAR(32) NOT NULL,
`first_round_id` INT(11) UNSIGNED NULL,
`latest_round_id` INT(11) UNSIGNED NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`)
);
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

View File

@@ -20,7 +20,7 @@
* *
* make sure you add an update to the schema_version stable in the db changelog * make sure you add an update to the schema_version stable in the db changelog
*/ */
#define DB_MINOR_VERSION 20 #define DB_MINOR_VERSION 21
//! ## Timing subsystem //! ## Timing subsystem

View File

@@ -61,16 +61,23 @@
qdel(client) qdel(client)
return return
var/ckey = client?.ckey
if (!ckey)
return
var/list/all_known_alts = GLOB.known_alts.load_known_alts() var/list/all_known_alts = GLOB.known_alts.load_known_alts()
var/list/our_known_alts = list() var/list/our_known_alts = list()
for (var/known_alt in all_known_alts) for (var/known_alt in all_known_alts)
if (known_alt[1] == client?.ckey) if (known_alt[1] == ckey)
our_known_alts += known_alt[2] our_known_alts += known_alt[2]
else if (known_alt[2] == client?.ckey) else if (known_alt[2] == ckey)
our_known_alts += known_alt[1] our_known_alts += known_alt[1]
var/list/found var/list/found
var/list/insert_queries = list()
for(var/i in 1 to len) for(var/i in 1 to len)
if(QDELETED(client)) if(QDELETED(client))
// He got cleaned up before we were done // He got cleaned up before we were done
@@ -81,6 +88,31 @@
if (!row || row.len < 3 || (!row["ckey"] || !row["address"] || !row["computer_id"])) if (!row || row.len < 3 || (!row["ckey"] || !row["address"] || !row["computer_id"]))
return return
if (!isnull(GLOB.round_id))
insert_queries += SSdbcore.NewQuery({"
INSERT INTO [format_table_name("telemetry_connections")] (
ckey,
telemetry_ckey,
address,
computer_id,
first_round_id,
latest_round_id
) VALUES(
:ckey,
:telemetry_ckey,
INET_ATON(:address),
:computer_id,
:round_id,
:round_id
) ON DUPLICATE KEY UPDATE latest_round_id = :round_id
"}, list(
"ckey" = ckey,
"telemetry_ckey" = row["ckey"],
"address" = row["address"],
"computer_id" = row["computer_id"],
"round_id" = GLOB.round_id,
))
if (row["ckey"] in our_known_alts) if (row["ckey"] in our_known_alts)
continue continue
@@ -89,9 +121,16 @@
break break
CHECK_TICK CHECK_TICK
// This fucker has a history of playing on a banned account. // This fucker has a history of playing on a banned account.
if(found) if(found)
var/msg = "[key_name(client)] has a banned account in connection history! (Matched: [found["ckey"]], [found["address"]], [found["computer_id"]])" var/msg = "[key_name(client)] has a banned account in connection history! (Matched: [found["ckey"]], [found["address"]], [found["computer_id"]])"
message_admins(msg) message_admins(msg)
log_admin_private(msg) log_admin_private(msg)
log_suspicious_login(msg, access_log_mirror = FALSE) log_suspicious_login(msg, access_log_mirror = FALSE)
// Only log them all at the end, since it's not as important as reporting an evader
for (var/datum/db_query/insert_query as anything in insert_queries)
insert_query.Execute()
QDEL_LIST(insert_queries)