mirror of
				https://github.com/slawkens/myaac.git
				synced 2025-10-29 23:16:23 +01:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			develop
			...
			feature/ac
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 9d976256c3 | ||
|   | 45af46b3c1 | ||
|   | 58feff50c6 | 
| @@ -9,6 +9,7 @@ | ||||
|  */ | ||||
|  | ||||
| use MyAAC\Models\Account as AccountModel; | ||||
| use MyAAC\Models\AccountAction; | ||||
| use MyAAC\Models\Player; | ||||
|  | ||||
| defined('MYAAC') or die('Direct access not allowed!'); | ||||
| @@ -466,9 +467,8 @@ else if (isset($_REQUEST['search'])) { | ||||
| 									</thead> | ||||
| 									<tbody> | ||||
| 										<?php | ||||
| 											$accountActions = \MyAAC\Models\AccountAction::where('account_id', $account->getId())->orderByDesc('date')->get(); | ||||
| 											$accountActions = AccountAction::where('account_id', $account->getId())->orderByDesc('date')->get(); | ||||
| 											foreach ($accountActions as $i => $log): | ||||
| 												$log->ip = ($log->ip != 0 ? long2ip($log->ip) : inet_ntop($log->ipv6)); | ||||
| 												?> | ||||
| 											<tr> | ||||
| 												<td><?php echo $i + 1; ?></td> | ||||
|   | ||||
| @@ -27,7 +27,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is | ||||
|  | ||||
| const MYAAC = true; | ||||
| const MYAAC_VERSION = '1.2'; | ||||
| const DATABASE_VERSION = 43; | ||||
| const DATABASE_VERSION = 44; | ||||
| const TABLE_PREFIX = 'myaac_'; | ||||
| define('START_TIME', microtime(true)); | ||||
| define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); | ||||
|   | ||||
| @@ -2,12 +2,12 @@ SET @myaac_database_version = 43; | ||||
|  | ||||
| CREATE TABLE `myaac_account_actions` | ||||
| ( | ||||
| 	`id` INT(11) NOT NULL AUTO_INCREMENT, | ||||
| 	`account_id` INT(11) NOT NULL, | ||||
| 	`ip` INT(10) UNSIGNED NOT NULL DEFAULT 0, | ||||
| 	`ipv6` BINARY(16) NOT NULL DEFAULT 0, | ||||
| 	`ip` VARCHAR(45) NOT NULL DEFAULT '', | ||||
| 	`date` INT(11) NOT NULL DEFAULT 0, | ||||
| 	`action` VARCHAR(255) NOT NULL DEFAULT '', | ||||
| 	KEY (`account_id`) | ||||
| 	PRIMARY KEY (`id`) | ||||
| ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4; | ||||
|  | ||||
| CREATE TABLE `myaac_admin_menu` | ||||
|   | ||||
| @@ -12,6 +12,8 @@ | ||||
|  * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3 | ||||
|  */ | ||||
|  | ||||
| use MyAAC\Models\AccountAction; | ||||
|  | ||||
| /** | ||||
|  * OTServ account abstraction. | ||||
|  * | ||||
| @@ -1010,26 +1012,16 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable | ||||
|  | ||||
| 	public function logAction($action) | ||||
| 	{ | ||||
| 		$ip = get_browser_real_ip(); | ||||
| 		if(!str_contains($ip, ":")) { | ||||
| 			$ipv6 = '0'; | ||||
| 		} | ||||
| 		else { | ||||
| 			$ipv6 = $ip; | ||||
| 			$ip = ''; | ||||
| 		} | ||||
|  | ||||
| 		return $this->db->exec('INSERT INTO `' . TABLE_PREFIX . 'account_actions` (`account_id`, `ip`, `ipv6`, `date`, `action`) VALUES (' . $this->db->quote($this->getId()).', ' . ($ip == '' ? '0' : $this->db->quote(ip2long($ip))) . ', (' . ($ipv6 == '0' ? $this->db->quote('') : $this->db->quote(inet_pton($ipv6))) . '), UNIX_TIMESTAMP(NOW()), ' . $this->db->quote($action).')'); | ||||
| 		AccountAction::create([ | ||||
| 			'account_id' => $this->getId(), | ||||
| 			'ip' => get_browser_real_ip(), | ||||
| 			'date' => time(), | ||||
| 			'action' => $action, | ||||
| 		]); | ||||
| 	} | ||||
|  | ||||
| 	public function getActionsLog($limit1, $limit2) | ||||
| 	{ | ||||
| 		$actions = array(); | ||||
|  | ||||
| 		foreach($this->db->query('SELECT `ip`, `ipv6`, `date`, `action` FROM `' . TABLE_PREFIX . 'account_actions` WHERE `account_id` = ' . $this->data['id'] . ' ORDER by `date` DESC LIMIT ' . $limit1 . ', ' . $limit2 . '')->fetchAll() as $a) | ||||
| 			$actions[] = array('ip' => $a['ip'], 'ipv6' => $a['ipv6'], 'date' => $a['date'], 'action' => $a['action']); | ||||
|  | ||||
| 		return $actions; | ||||
| 	public function getActionsLog($limit) { | ||||
| 		return AccountAction::where('account_id', $this->data['id'])->orderByDesc('date')->limit($limit)->get()->toArray(); | ||||
| 	} | ||||
| /** | ||||
|  * Returns players iterator. | ||||
|   | ||||
							
								
								
									
										27
									
								
								system/migrations/44.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								system/migrations/44.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @var OTS_DB_MySQL $db | ||||
|  */ | ||||
|  | ||||
| // 2025-02-27 | ||||
| // remove ipv6, change to ip (for both ipv4 + ipv6) as VARCHAR(45) | ||||
| $up = function () use ($db) { | ||||
| 	$db->query("ALTER TABLE `myaac_account_actions` DROP KEY `account_id`;"); | ||||
| 	$db->query("ALTER TABLE  `myaac_account_actions` ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);"); | ||||
|  | ||||
| 	$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "VARCHAR(45) NOT NULL DEFAULT ''"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_NTOA(`ip`) WHERE `ip` != '0';"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET6_NTOA(`ipv6`) WHERE `ip` = '0';"); | ||||
| 	$db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6'); | ||||
| }; | ||||
|  | ||||
| $down = function () use ($db) { | ||||
| 	$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` DROP `id`;"); | ||||
| 	$db->query("ALTER TABLE  `" . TABLE_PREFIX . "account_actions` ADD KEY (`account_id`);"); | ||||
|  | ||||
| 	$db->addColumn(TABLE_PREFIX . 'account_actions', 'ipv6', "BINARY(16) NOT NULL DEFAULT 0x00000000000000000000000000000000 AFTER ip"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ipv6` = INET6_ATON(ip) WHERE NOT IS_IPV4(`ip`);"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_ATON(`ip`) WHERE IS_IPV4(`ip`);"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = 0 WHERE `ipv6` != 0x00000000000000000000000000000000;"); | ||||
| 	$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "INT(11) UNSIGNED NOT NULL DEFAULT 0;"); | ||||
| }; | ||||
| @@ -85,12 +85,8 @@ if($email_new_time > 1) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| $actions = array(); | ||||
| foreach($account_logged->getActionsLog(0, 1000) as $action) { | ||||
| 	$actions[] = array('action' => $action['action'], 'date' => $action['date'], 'ip' => $action['ip'] != 0 ? long2ip($action['ip']) : inet_ntop($action['ipv6'])); | ||||
| } | ||||
| $actions = $account_logged->getActionsLog(1000); | ||||
|  | ||||
| $players = array(); | ||||
| /** @var OTS_Players_List $account_players */ | ||||
| $account_players = $account_logged->getPlayersList(); | ||||
| $account_players->orderBy('id'); | ||||
|   | ||||
| @@ -9,6 +9,6 @@ class AccountAction extends Model { | ||||
|  | ||||
| 	public $timestamps = false; | ||||
|  | ||||
| 	protected $fillable = ['account_id', 'ip', 'ipv6', 'date', 'action']; | ||||
| 	protected $fillable = ['account_id', 'ip', 'date', 'action']; | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user