mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Add realm ID for actions based ip logging (#24453)
* Update SQL queries to insert realm id
* Insert the realm id when logging actions based on IP
* Adding the SQL update file
* Update 9999_99_99_99_auth.sql
* Update auth structure
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
(cherry picked from commit 56f20d69a6)
This commit is contained in:
@@ -688,6 +688,7 @@ CREATE TABLE `logs_ip_actions` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Identifier',
|
||||
`account_id` int(10) unsigned NOT NULL COMMENT 'Account ID',
|
||||
`character_guid` bigint(20) unsigned NOT NULL COMMENT 'Character Guid',
|
||||
`realm_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Realm ID',
|
||||
`type` tinyint(3) unsigned NOT NULL,
|
||||
`ip` varchar(15) NOT NULL DEFAULT '127.0.0.1',
|
||||
`systemnote` text COMMENT 'Notes inserted by system',
|
||||
@@ -2466,6 +2467,7 @@ INSERT INTO `updates` VALUES
|
||||
('2020_03_31_00_auth.sql','BA82A58E95730A397922B6723DA027986E6CD535','ARCHIVED','2020-03-31 17:00:16',0),
|
||||
('2020_04_04_00_auth.sql','5F118989A9F8AFA3B2065AB9C2C0BB7D9A0EB97A','ARCHIVED','2020-04-04 13:23:53',0),
|
||||
('2020_04_07_00_auth.sql','6D73A4E1EC5382F10C39F20E2E6E764510A8A5E6','ARCHIVED','2020-04-07 22:23:35',0),
|
||||
('2020_04_18_00_auth.sql','BD962B50760771B60F2785027D6957EEF2009240','ARCHIVED','2020-04-18 14:09:28',0),
|
||||
('2020_04_30_00_auth.sql','2FD304B8EF82D529D69287BF22EF061A267F827E','ARCHIVED','2020-04-30 00:39:29',0),
|
||||
('2020_05_19_00_auth.sql','12D9F26538F63546B74793499E8A71BD885E8E5F','ARCHIVED','2020-05-19 12:00:00',0),
|
||||
('2020_06_04_00_auth.sql','BA797B558196B1A07F8FF66E5288AD04659CF6AC','ARCHIVED','2020-06-04 09:57:07',0),
|
||||
|
||||
2
sql/updates/auth/master/2020_04_18_00_auth.sql
Normal file
2
sql/updates/auth/master/2020_04_18_00_auth.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
--
|
||||
ALTER TABLE `logs_ip_actions` ADD COLUMN `realm_id` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Realm ID' AFTER `character_guid`;
|
||||
@@ -95,14 +95,14 @@ void LoginDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(LOGIN_DEL_ACCOUNT, "DELETE FROM account WHERE id = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(LOGIN_SEL_AUTOBROADCAST, "SELECT id, weight, text FROM autobroadcast WHERE realmid = ? OR realmid = -1", CONNECTION_SYNCH);
|
||||
PrepareStatement(LOGIN_GET_EMAIL_BY_ID, "SELECT email FROM account WHERE id = ?", CONNECTION_SYNCH);
|
||||
// 0: uint32, 1: uint32, 2: uint8, 3: uint32, 4: string // Complete name: "Login_Insert_AccountLoginDeLete_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_ALDL_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id,character_guid,type,ip,systemnote,unixtime,time) VALUES (?, ?, ?, (SELECT last_ip FROM account WHERE id = ?), ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint8, 3: uint32, 4: string // Complete name: "Login_Insert_FailedAccountLogin_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_FACL_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id,character_guid,type,ip,systemnote,unixtime,time) VALUES (?, ?, ?, (SELECT last_attempt_ip FROM account WHERE id = ?), ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint8, 3: string, 4: string // Complete name: "Login_Insert_CharacterDelete_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_CHAR_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id,character_guid,type,ip,systemnote,unixtime,time) VALUES (?, ?, ?, ?, ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: string, 2: string // Complete name: "Login_Insert_Failed_Account_Login_due_password_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_FALP_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id,character_guid,type,ip,systemnote,unixtime,time) VALUES (?, 0, 1, ?, ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint32, 3: uint8, 4: uint32, 5: string // Complete name: "Login_Insert_AccountLoginDeLete_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_ALDL_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id, character_guid, realm_id, type, ip, systemnote, unixtime, time) VALUES (?, ?, ?, ?, (SELECT last_ip FROM account WHERE id = ?), ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint32, 3: uint8, 4: uint32, 5: string // Complete name: "Login_Insert_FailedAccountLogin_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_FACL_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id, character_guid, realm_id, type, ip, systemnote, unixtime, time) VALUES (?, ?, ?, ?, (SELECT last_attempt_ip FROM account WHERE id = ?), ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: uint32, 3: uint8, 4: string, 5: string // Complete name: "Login_Insert_CharacterDelete_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_CHAR_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id, character_guid, realm_id, type, ip, systemnote, unixtime, time) VALUES (?, ?, ?, ?, ?, ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
// 0: uint32, 1: uint32, 2: string, 3: string // Complete name: "Login_Insert_Failed_Account_Login_due_password_IP_Logging"
|
||||
PrepareStatement(LOGIN_INS_FALP_IP_LOGGING, "INSERT INTO logs_ip_actions (account_id, character_guid, realm_id, type, ip, systemnote, unixtime, time) VALUES (?, 0, ?, 1, ?, ?, unix_timestamp(NOW()), NOW())", CONNECTION_ASYNC);
|
||||
PrepareStatement(LOGIN_SEL_ACCOUNT_ACCESS_BY_ID, "SELECT SecurityLevel, RealmID FROM account_access WHERE AccountID = ? and (RealmID = ? OR RealmID = -1) ORDER BY SecurityLevel desc", CONNECTION_SYNCH);
|
||||
|
||||
PrepareStatement(LOGIN_SEL_RBAC_ACCOUNT_PERMISSIONS, "SELECT permissionId, granted FROM rbac_account_permissions WHERE accountId = ? AND (realmId = ? OR realmId = -1) ORDER BY permissionId, realmId", CONNECTION_BOTH);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include "ScriptMgr.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Player.h"
|
||||
#include "Realm.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
enum IPLoggingTypes
|
||||
@@ -95,6 +97,7 @@ class AccountActionIpLogger : public AccountScript
|
||||
|
||||
// We declare all the required variables
|
||||
uint32 playerGuid = accountId;
|
||||
uint32 realmId = realm.Id.Realm;
|
||||
std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
|
||||
|
||||
// With this switch, we change systemNote so that we have a more accurate phrasing of what type it is.
|
||||
@@ -139,10 +142,11 @@ class AccountActionIpLogger : public AccountScript
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ALDL_IP_LOGGING);
|
||||
|
||||
stmt->setUInt32(0, playerGuid);
|
||||
stmt->setUInt32(1, 0);
|
||||
stmt->setUInt8(2, aType);
|
||||
stmt->setUInt32(3, playerGuid);
|
||||
stmt->setString(4, systemNote);
|
||||
stmt->setUInt64(1, 0);
|
||||
stmt->setUInt32(2, realmId);
|
||||
stmt->setUInt8(3, aType);
|
||||
stmt->setUInt32(4, playerGuid);
|
||||
stmt->setString(5, systemNote);
|
||||
LoginDatabase.Execute(stmt);
|
||||
}
|
||||
else // ... but for failed login, we query last_attempt_ip from account table. Which we do with an unique query
|
||||
@@ -150,10 +154,11 @@ class AccountActionIpLogger : public AccountScript
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_FACL_IP_LOGGING);
|
||||
|
||||
stmt->setUInt32(0, playerGuid);
|
||||
stmt->setUInt32(1, 0);
|
||||
stmt->setUInt8(2, aType);
|
||||
stmt->setUInt32(3, playerGuid);
|
||||
stmt->setString(4, systemNote);
|
||||
stmt->setUInt64(1, 0);
|
||||
stmt->setUInt32(2, realmId);
|
||||
stmt->setUInt8(3, aType);
|
||||
stmt->setUInt32(4, playerGuid);
|
||||
stmt->setString(5, systemNote);
|
||||
LoginDatabase.Execute(stmt);
|
||||
}
|
||||
return;
|
||||
@@ -199,6 +204,7 @@ class CharacterActionIpLogger : public PlayerScript
|
||||
|
||||
// We declare all the required variables
|
||||
uint32 playerGuid = player->GetSession()->GetAccountId();
|
||||
uint32 realmId = realm.Id.Realm;
|
||||
const std::string currentIp = player->GetSession()->GetRemoteAddress();
|
||||
std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it...
|
||||
|
||||
@@ -232,9 +238,10 @@ class CharacterActionIpLogger : public PlayerScript
|
||||
|
||||
stmt->setUInt32(0, playerGuid);
|
||||
stmt->setUInt64(1, player->GetGUID().GetCounter());
|
||||
stmt->setUInt8(2, aType);
|
||||
stmt->setString(3, currentIp); // We query the ip here.
|
||||
stmt->setString(4, systemNote);
|
||||
stmt->setUInt32(2, realmId);
|
||||
stmt->setUInt8(3, aType);
|
||||
stmt->setString(4, currentIp); // We query the ip here.
|
||||
stmt->setString(5, systemNote);
|
||||
// Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
|
||||
// Rather, we let it be added with the SQL query.
|
||||
|
||||
@@ -265,6 +272,7 @@ public:
|
||||
// Action IP Logger is only intialized if config is set up
|
||||
// Else, this script isn't loaded in the first place: We require no config check.
|
||||
|
||||
uint32 realmId = realm.Id.Realm;
|
||||
// Query playerGuid/accountId, as we only have characterGuid
|
||||
std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
|
||||
|
||||
@@ -286,17 +294,19 @@ public:
|
||||
}
|
||||
|
||||
// Once we have done everything, we can insert the new log.
|
||||
LoginDatabasePreparedStatement* stmt2 = LoginDatabase.GetPreparedStatement(LOGIN_INS_ALDL_IP_LOGGING);
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ALDL_IP_LOGGING);
|
||||
|
||||
stmt->setUInt32(0, playerGuid);
|
||||
stmt->setUInt64(1, guid.GetCounter());
|
||||
stmt->setUInt32(2, realmId);
|
||||
stmt->setUInt8(3, aType);
|
||||
stmt->setUInt32(4, playerGuid);
|
||||
stmt->setString(5, systemNote);
|
||||
|
||||
stmt2->setUInt32(0, playerGuid);
|
||||
stmt2->setUInt64(1, guid.GetCounter());
|
||||
stmt2->setUInt8(2, aType);
|
||||
stmt2->setUInt32(3, playerGuid);
|
||||
stmt2->setString(4, systemNote);
|
||||
// Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
|
||||
// Rather, we let it be added with the SQL query.
|
||||
|
||||
LoginDatabase.Execute(stmt2);
|
||||
LoginDatabase.Execute(stmt);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user