mirror of
				https://github.com/slawkens/myaac.git
				synced 2025-10-31 07:56:23 +01:00 
			
		
		
		
	Compare commits
	
		
			30 Commits
		
	
	
		
			feature/re
			...
			feature/tw
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 11a2275115 | ||
|   | 50f73ba56c | ||
|   | 7dcdc4f743 | ||
|   | 8697809bbe | ||
|   | 2f0758e351 | ||
|   | 6667c8c364 | ||
|   | c13a540878 | ||
|   | 869ec035d9 | ||
|   | 9d696d31d8 | ||
|   | 8cc4caf587 | ||
|   | e1d1c7d5db | ||
|   | 320733c2c1 | ||
|   | c1809a98d1 | ||
|   | 46ed541015 | ||
|   | 29207361b7 | ||
|   | 25013ae91b | ||
|   | 5d630ba9dd | ||
|   | feadf1314d | ||
|   | 08b8a716d4 | ||
|   | cc26b5c744 | ||
|   | cb6e9a6a88 | ||
|   | 4adb0758c5 | ||
|   | 9af676a59e | ||
|   | 7312383f73 | ||
|   | 3c1210fefa | ||
|   | 3aaf71b9b5 | ||
|   | 28d61ee12f | ||
|   | 592bfaea70 | ||
|   | b471b1567a | ||
|   | 44fe03c6ea | 
| @@ -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> | ||||
|   | ||||
| @@ -26,8 +26,8 @@ | ||||
| if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is required.'); | ||||
|  | ||||
| const MYAAC = true; | ||||
| const MYAAC_VERSION = '1.4.1-dev'; | ||||
| const DATABASE_VERSION = 43; | ||||
| const MYAAC_VERSION = '2.0-dev'; | ||||
| 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 NOT NULL AUTO_INCREMENT, | ||||
| 	`account_id` int NOT NULL, | ||||
| 	`ip` int unsigned NOT NULL DEFAULT 0, | ||||
| 	`ipv6` binary(16) NOT NULL DEFAULT 0, | ||||
| 	`ip` varchar(45) NOT NULL DEFAULT '', | ||||
| 	`date` int 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` | ||||
|   | ||||
| @@ -545,33 +545,39 @@ function template_header($is_admin = false): string | ||||
|  */ | ||||
| function template_footer(): string | ||||
| { | ||||
| 	global $views_counter; | ||||
| 	$ret = ''; | ||||
| 	$footer = []; | ||||
|  | ||||
| 	if(admin()) { | ||||
| 		$ret .= generateLink(ADMIN_URL, 'Admin Panel', true); | ||||
| 		$footer[] = generateLink(ADMIN_URL, 'Admin Panel', true); | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.visitors_counter')) { | ||||
| 		global $visitors; | ||||
| 		$amount = $visitors->getAmountVisitors(); | ||||
| 		$ret .= '<br/>Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; | ||||
| 		$footer[] = 'Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.views_counter')) { | ||||
| 		$ret .= '<br/>Page has been viewed ' . $views_counter . ' times.'; | ||||
| 		global $views_counter; | ||||
| 		$footer[] = 'Page has been viewed ' . $views_counter . ' times.'; | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.footer_load_time')) { | ||||
| 		$ret .= '<br/>Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; | ||||
| 		$footer[] = 'Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; | ||||
| 	} | ||||
|  | ||||
| 	$settingFooter = setting('core.footer'); | ||||
| 	if(isset($settingFooter[0])) { | ||||
| 		$ret .= '<br/>' . $settingFooter; | ||||
| 		$footer[] = '' . $settingFooter; | ||||
| 	} | ||||
|  | ||||
| 	// please respect my work and help spreading the word, thanks! | ||||
| 	return $ret . '<br/>' . base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); | ||||
| 	$footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); | ||||
|  | ||||
| 	global $hooks; | ||||
| 	$hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer); | ||||
|  | ||||
| 	return implode('<br/>', $footer); | ||||
| } | ||||
|  | ||||
| function template_ga_code() | ||||
|   | ||||
| @@ -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'); | ||||
|   | ||||
| @@ -37,6 +37,11 @@ class Hook | ||||
| 		return !isset($ret) || $ret == 1 || $ret; | ||||
| 	} | ||||
|  | ||||
| 	public function executeFilter(&$args) { | ||||
| 		return include BASE . $this->_file; | ||||
| 	} | ||||
|  | ||||
| 	public function name() {return $this->_name;} | ||||
| 	public function type() {return $this->_type;} | ||||
| 	public function file() {return $this->_file;} | ||||
| } | ||||
|   | ||||
| @@ -4,22 +4,23 @@ namespace MyAAC; | ||||
|  | ||||
| class Hooks | ||||
| { | ||||
| 	private static $_hooks = array(); | ||||
| 	private static array $_hooks = []; | ||||
|  | ||||
| 	public function register($hook, $type = '', $file = null) { | ||||
| 	public function register($hook, $type = '', $file = null): void | ||||
| 	{ | ||||
| 		if(!($hook instanceof Hook)) | ||||
| 			$hook = new Hook($hook, $type, $file); | ||||
|  | ||||
| 		self::$_hooks[$hook->type()][] = $hook; | ||||
| 	} | ||||
|  | ||||
| 	public function trigger($type, $params = array()) | ||||
| 	public function trigger($type, $params = []): bool | ||||
| 	{ | ||||
| 		$ret = true; | ||||
| 		if(isset(self::$_hooks[$type])) | ||||
| 		{ | ||||
|  | ||||
| 		if(isset(self::$_hooks[$type])) { | ||||
| 			foreach(self::$_hooks[$type] as $name => $hook) { | ||||
| 				/** @var $hook Hook */ | ||||
| 				/** @var Hook $hook */ | ||||
| 				if (!$hook->execute($params)) { | ||||
| 					$ret = false; | ||||
| 				} | ||||
| @@ -29,11 +30,21 @@ class Hooks | ||||
| 		return $ret; | ||||
| 	} | ||||
|  | ||||
| 	public function exist($type) { | ||||
| 	public function triggerFilter($type, &$args): void | ||||
| 	{ | ||||
| 		if(isset(self::$_hooks[$type])) { | ||||
| 			foreach(self::$_hooks[$type] as $hook) { | ||||
| 				/** @var Hook $hook */ | ||||
| 				$hook->executeFilter($args); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public function exist($type): bool { | ||||
| 		return isset(self::$_hooks[$type]); | ||||
| 	} | ||||
|  | ||||
| 	public function load() | ||||
| 	public function load(): void | ||||
| 	{ | ||||
| 		foreach(Plugins::getHooks() as $hook) { | ||||
| 			$this->register($hook['name'], $hook['type'], $hook['file']); | ||||
|   | ||||
| @@ -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']; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -198,6 +198,9 @@ class Plugins { | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		global $hooks; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_ROUTES, $routes); | ||||
|  | ||||
| 		usort($routes, function ($a, $b) | ||||
| 		{ | ||||
| 			// key 3 is priority | ||||
|   | ||||
							
								
								
									
										28
									
								
								system/src/Twig/EnvironmentBridge.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								system/src/Twig/EnvironmentBridge.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| namespace MyAAC\Twig; | ||||
|  | ||||
| use Twig\Environment; | ||||
|  | ||||
| class EnvironmentBridge extends Environment | ||||
| { | ||||
| 	public function display($name, array $context = []): void | ||||
| 	{ | ||||
| 		global $hooks; | ||||
|  | ||||
| 		$context['viewName'] = $name; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context); | ||||
|  | ||||
| 		parent::display($name, $context); | ||||
| 	} | ||||
|  | ||||
| 	public function render($name, array $context = []): string | ||||
| 	{ | ||||
| 		global $hooks; | ||||
|  | ||||
| 		$context['viewName'] = $name; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context); | ||||
|  | ||||
| 		return parent::render($name, $context); | ||||
| 	} | ||||
| } | ||||
| @@ -97,6 +97,12 @@ define('HOOK_CACHE_CLEAR', ++$i); | ||||
| define('HOOK_INSTALL_FINISH', ++$i); | ||||
| define('HOOK_INSTALL_FINISH_END', ++$i); | ||||
|  | ||||
| // hook filters | ||||
| define('HOOK_FILTER_ROUTES', ++$i); | ||||
| define('HOOK_FILTER_TWIG_DISPLAY', ++$i); | ||||
| define('HOOK_FILTER_TWIG_RENDER', ++$i); | ||||
| define('HOOK_FILTER_THEME_FOOTER', ++$i); | ||||
|  | ||||
| const HOOK_FIRST = HOOK_INIT; | ||||
| define('HOOK_LAST', $i); | ||||
|  | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
|  */ | ||||
| defined('MYAAC') or die('Direct access not allowed!'); | ||||
|  | ||||
| use MyAAC\CsrfToken; | ||||
| use Twig\Environment as Twig_Environment; | ||||
| use MyAAC\Twig\EnvironmentBridge as MyAAC_Twig_EnvironmentBridge; | ||||
| use Twig\Extension\DebugExtension as Twig_DebugExtension; | ||||
| use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader; | ||||
| use Twig\TwigFilter; | ||||
| @@ -20,7 +19,7 @@ global $twig, $twig_loader; | ||||
|  | ||||
| $dev_mode = (config('env') === 'dev'); | ||||
| $twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates'); | ||||
| $twig = new Twig_Environment($twig_loader, array( | ||||
| $twig = new MyAAC_Twig_EnvironmentBridge($twig_loader, array( | ||||
| 	'cache' => CACHE . 'twig/', | ||||
| 	'auto_reload' => $dev_mode, | ||||
| 	'debug' => $dev_mode | ||||
|   | ||||
		Reference in New Issue
	
	Block a user