diff --git a/classes/Accounting/Auth.class.php b/classes/Accounting/Auth.class.php index 8d376ea..a62a3dc 100644 --- a/classes/Accounting/Auth.class.php +++ b/classes/Accounting/Auth.class.php @@ -1,61 +1,64 @@ -isLoggedIn(); - } - - public static function TwoFactorLogin(string $username, #[\SensitiveParameter] string $password) : bool { - return AuthFactory::getInstance()->TwoFactorLogin($username, $password); - } - - public static function login(string $username, #[\SensitiveParameter] string $password) : bool { - return AuthFactory::getInstance()->login($username, $password); - } - - public static function logout() : bool { - return AuthFactory::getInstance()->logout(); - } - - public static function getID() : ?int { - return AuthFactory::getInstance()->getID(); - } - - public static function getUsername() : ?string { - return AuthFactory::getInstance()->getUsername(); - } - - public static function getMail() : ?string { - return AuthFactory::getInstance()->getMail(); - } - - public static function getGravatar() : string { - return AuthFactory::getInstance()->getGravatar(); - } - - public static function setSettings(string $name, int | string | null $user_id = null, mixed $value = null) : void { - AuthFactory::getInstance()->setSettings($name, $user_id, $value); - } - - public static function getSettings(string $name, int | string | null $user_id = null, mixed $default = null) : mixed { - return AuthFactory::getInstance()->getSettings($name, $user_id, $default); - } - - public static function removeSettings(string $name, int | string | null $user_id = null) : void { - AuthFactory::getInstance()->removeSettings($name, $user_id); - } - - public static function hasPermission(string $name) : bool { - return AuthFactory::getInstance()->hasPermission($name); - } - } -?> \ No newline at end of file +isLoggedIn(); + } + + public static function TwoFactorLogin(string $username, #[\SensitiveParameter] string $password) : bool { + return AuthFactory::getInstance()->TwoFactorLogin($username, $password); + } + + public static function login(string $username, #[\SensitiveParameter] string $password) : bool { + return AuthFactory::getInstance()->login($username, $password); + } + + public static function logout() : bool { + return AuthFactory::getInstance()->logout(); + } + + public static function getID() : ?int { + return AuthFactory::getInstance()->getID(); + } + + public static function getUsername() : ?string { + return AuthFactory::getInstance()->getUsername(); + } + + public static function getMail() : ?string { + return AuthFactory::getInstance()->getMail(); + } + + public static function getGravatar() : string { + return AuthFactory::getInstance()->getGravatar(); + } + + public static function setSettings(string $name, int | string | null $user_id = null, mixed $value = null) : void { + AuthFactory::getInstance()->setSettings($name, $user_id, $value); + } + + public static function getSettings(string $name, int | string | null $user_id = null, mixed $default = null) : mixed { + return AuthFactory::getInstance()->getSettings($name, $user_id, $default); + } + + public static function removeSettings(string $name, int | string | null $user_id = null) : void { + AuthFactory::getInstance()->removeSettings($name, $user_id); + } + + public static function hasPermission(string $name) : bool { + return AuthFactory::getInstance()->hasPermission($name); + } + + public static function getPermissions() : array { + return AuthFactory::getInstance()->getPermissions(); + } + } + + ?> \ No newline at end of file diff --git a/classes/Accounting/AuthFactory.class.php b/classes/Accounting/AuthFactory.class.php index d215cfc..7236082 100644 --- a/classes/Accounting/AuthFactory.class.php +++ b/classes/Accounting/AuthFactory.class.php @@ -1,23 +1,69 @@ user = new User(); + if(self::isLoggedIn()) { + $this->user->fetch(self::getID()); + foreach(Database::fetch('SELECT * FROM `'.DATABASE_PREFIX.'users_permissions` WHERE `user_id`=:user_id', [ 'user_id' => self::getID() ]) as $entry) { + $this->permissions[] = $entry->permission; + } + if(defined('DEBUG') && DEBUG) { + Response::addHeader('USER', json_encode([ + 'ID' => $this->user->getID(), + 'Username' => $this->user->getUsername(), + 'IsLoggedIn' => $this->isLoggedIn() + ])); + Response::addHeader('PERMISSIONS', json_encode($this->permissions)); + } + } + } + + public function isLoggedIn() : bool { + $user_id = Session::get('user_id'); + + return (!empty($user_id) && $user_id > 0); + } + + /* + Check if user is logged in. + + @return bool + */ + public function getID() : ?int { + return Session::get('user_id'); + } + + /* + Get user id of the current user. + + @return int | null + */ + public function getUsername() : ?string { + return Session::get('user_name'); + } + + /* + Get username of the current user. + + @return string | null + */ public static function getInstance() : AuthFactory { if(self::$instance === null) { self::$instance = new self(); @@ -26,59 +72,6 @@ return self::$instance; } - protected function __construct() { - $this->user = new User(); - - if(self::isLoggedIn()) { - $this->user->fetch(self::getID()); - - foreach(Database::fetch('SELECT * FROM `' . DATABASE_PREFIX . 'users_permissions` WHERE `user_id`=:user_id', [ - 'user_id' => self::getID() - ]) AS $entry) { - $this->permissions[] = $entry->permission; - } - - if(defined('DEBUG') && DEBUG) { - Response::addHeader('USER', json_encode([ - 'ID' => $this->user->getID(), - 'Username' => $this->user->getUsername(), - 'IsLoggedIn' => $this->isLoggedIn() - ])); - - Response::addHeader('PERMISSIONS', json_encode($this->permissions)); - } - } - } - - /* - Check if user is logged in. - - @return bool - */ - public function isLoggedIn() : bool { - $user_id = Session::get('user_id'); - - return (!empty($user_id) && $user_id > 0); - } - - /* - Get user id of the current user. - - @return int | null - */ - public function getID() : ?int { - return Session::get('user_id'); - } - - /* - Get username of the current user. - - @return string | null - */ - public function getUsername() : ?string { - return Session::get('user_name'); - } - /* Log out the current user. @@ -90,7 +83,7 @@ return true; } - + /* Get E-Mail address of the current user. @@ -99,7 +92,7 @@ public function getMail() : ?string { return $this->user->getMail(); } - + /* Log in a specific user by `$username` and `$password`. @@ -108,32 +101,29 @@ @return bool @throw Exception */ - public function login(string $username, #[\SensitiveParameter] string $password) : bool { - $result = Database::single('SELECT `id`, `username`, `password`, UPPER(SHA2(CONCAT(`id`, :salt, :password), 512)) as `crypted` FROM `' . DATABASE_PREFIX . 'users` WHERE `username`=:username LIMIT 1', [ - 'username' => $username, - 'password' => $password, - 'salt' => MYSQL_PASSWORTD_SALT + public function login(string $username, #[\SensitiveParameter] string $password) : bool { + $result = Database::single('SELECT `id`, `username`, `password`, UPPER(SHA2(CONCAT(`id`, :salt, :password), 512)) as `crypted` FROM `'.DATABASE_PREFIX.'users` WHERE `username`=:username LIMIT 1', [ + 'username' => $username, + 'password' => $password, + 'salt' => MYSQL_PASSWORTD_SALT ]); - if(!$result) { throw new \Exception(I18N::get('Unknown User')); } - if($result->password !== $result->crypted) { throw new \Exception(I18N::get('Password mismatched.')); } - if($result->id > 0) { $this->user->fetch((int) $result->id); - Session::set('user_name', $result->username); - Session::set('user_id', (int) $result->id); + Session::set('user_name', $result->username); + Session::set('user_id', (int) $result->id); } else { throw new \Exception(I18N::get('Unknown User')); } return true; } - + /* Check a specific user by `$username` and `$password` for Two-Factor-Authentication. @@ -142,32 +132,28 @@ @return bool @throw Exception */ - public function TwoFactorLogin(string $username, #[\SensitiveParameter] string $password) : bool { - $result = Database::single('SELECT `id`, `username`, `email`, `password`, UPPER(SHA2(CONCAT(`id`, :salt, :password), 512)) as `crypted` FROM `' . DATABASE_PREFIX . 'users` WHERE `username`=:username LIMIT 1', [ - 'username' => $username, - 'password' => $password, - 'salt' => MYSQL_PASSWORTD_SALT + public function TwoFactorLogin(string $username, #[\SensitiveParameter] string $password) : bool { + $result = Database::single('SELECT `id`, `username`, `email`, `password`, UPPER(SHA2(CONCAT(`id`, :salt, :password), 512)) as `crypted` FROM `'.DATABASE_PREFIX.'users` WHERE `username`=:username LIMIT 1', [ + 'username' => $username, + 'password' => $password, + 'salt' => MYSQL_PASSWORTD_SALT ]); - if(!$result) { throw new \Exception(I18N::get('Unknown User')); } - if($result->password !== $result->crypted) { throw new \Exception(I18N::get('Password mismatched.')); } - if(!filter_var($result->email, FILTER_VALIDATE_EMAIL)) { return false; } - if($result->id <= 0) { throw new \Exception(I18N::get('Unknown User')); } return true; } - + /* Get Settings from (given) user account. @@ -179,7 +165,7 @@ public function getSettings(string $name, int | string | null $user_id = null, mixed $default = null) : mixed { return $this->user->getSettings($name, $user_id, $default); } - + /* Remove Settings from (given) user account. @@ -189,7 +175,7 @@ public function removeSettings(string $name, int | string | null $user_id = null) : void { $this->user->removeSettings($name, $user_id); } - + /* Set Settings from (given) user account. @@ -200,7 +186,7 @@ public function setSettings(string $name, int | string | null $user_id = null, mixed $value = null) : void { $this->user->setSettings($name, $user_id, $value); } - + /* Get Gravatar-URL from actual user. @@ -209,27 +195,46 @@ public function getGravatar() : string { return $this->user->getGravatar(); } - + /* Check given Permission from actual user. @param string $name @return bool */ - public function hasPermission(string $name) : bool { + public function hasPermission(string $name) : bool { if(count($this->permissions) > 0) { if($name === '*') { return count($this->permissions) >= 1; } + if(in_array('*', $this->permissions)) { + return true; + } + if(stristr($name, '::*') !== false) { + $count = 0; + $split = explode('::*', $name); + foreach($this->permissions as $permission) { + if(str_starts_with($permission, $split[0])) { + ++$count; + } + } + if($count > 0) { + return true; + } + } return in_array($name, $this->permissions); } - if($name === '*') { return (count($this->permissions) >= 1); } return in_array($name, $this->permissions); } + + public function getPermissions() : array { + return $this->permissions; + } } -?> \ No newline at end of file + + ?> \ No newline at end of file diff --git a/classes/Accounting/User.class.php b/classes/Accounting/User.class.php index f1bd356..4051b0e 100644 --- a/classes/Accounting/User.class.php +++ b/classes/Accounting/User.class.php @@ -1,60 +1,52 @@ $id, - 'salt' => RESET_PASSWORD_SALT + public function fetch(int $id) : void { + $result = Database::single('SELECT *, "[*** PROTECTED ***]" as `password`, UPPER(SHA2(CONCAT(`id`, :salt, `email`), 512)) AS `crypted_mail` FROM `'.DATABASE_PREFIX.'users` WHERE `id`=:id LIMIT 1', [ + 'id' => $id, + 'salt' => RESET_PASSWORD_SALT ]); - - $this->id = $result->id; - $this->username = $result->username; - $this->email = $result->email; - $this->crypted_mail = $result->crypted_mail; - - $this->data = Database::single('SELECT * FROM `' . DATABASE_PREFIX . 'users_data` WHERE `user_id`=:user_id LIMIT 1', [ - 'user_id' => $this->id - ]); - + $this->id = $result->id; + $this->username = $result->username; + $this->email = $result->email; + $this->crypted_mail = $result->crypted_mail; + $this->data = Database::single('SELECT * FROM `'.DATABASE_PREFIX.'users_data` WHERE `user_id`=:user_id LIMIT 1', [ 'user_id' => $this->id ]); + foreach(Database::fetch('SELECT * FROM `'.DATABASE_PREFIX.'users_permissions` WHERE `user_id`=:user_id', [ 'user_id' => $this->id ]) as $permission) { + $this->permissions[] = $permission->permission; + } if($this->data !== false) { - foreach($this->data AS $index => $entry) { - if(in_array($index, [ 'id', 'user_id' ])) { + foreach($this->data as $index => $entry) { + if(in_array($index, [ + 'id', + 'user_id' + ])) { continue; } - $this->data->{$index} = Encryption::decrypt($entry, ENCRYPTION_SALT); } } } - public function getID() : ?int { - /*if($this->id == null && Auth::getID() != null) { - return Auth::getID(); - }*/ - - return $this->id; - } - public function getFirstName() : ?string { if(!$this->data) { return null; @@ -64,7 +56,7 @@ } public function getLastName() : ?string { - if(!$this->data) { + if(!$this->data) { return null; } @@ -72,7 +64,7 @@ } public function getPhoneNumber() : ?string { - if(!$this->data) { + if(!$this->data) { return null; } @@ -80,7 +72,7 @@ } public function getAddress() : ?string { - if(!$this->data) { + if(!$this->data) { return null; } @@ -88,10 +80,9 @@ } public function getFullName() : ?string { - if(!$this->data) { + if(!$this->data) { return ''; } - if(empty($this->data->name_first)) { return ''; } @@ -113,20 +104,15 @@ public function getSettings(string $name, int | string | null $user_id = null, mixed $default = null) : mixed { if(!empty($user_id) && is_string($user_id)) { - $result = Database::single('SELECT `id` FROM `' . DATABASE_PREFIX . 'users` WHERE `username`=:username LIMIT 1', [ - 'username' => $user_id - ]); - + $result = Database::single('SELECT `id` FROM `'.DATABASE_PREFIX.'users` WHERE `username`=:username LIMIT 1', [ 'username' => $user_id ]); if(!empty($result)) { $user_id = $result->id; } } - - $result = Database::single('SELECT * FROM `' . DATABASE_PREFIX . 'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name + $result = Database::single('SELECT * FROM `'.DATABASE_PREFIX.'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name ]); - if(!empty($result)) { if(!empty($result->value)) { return $result->value; @@ -136,34 +122,51 @@ return $default; } + public function getID() : ?int { + /*if($this->id == null && Auth::getID() != null) { + return Auth::getID(); + }*/ + return $this->id; + } + public function removeSettings(string $name, int | string | null $user_id = null) : void { - if(Database::exists('SELECT `id` FROM `' . DATABASE_PREFIX . 'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name + if(Database::exists('SELECT `id` FROM `'.DATABASE_PREFIX.'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name ])) { - Database::delete(DATABASE_PREFIX . 'users_settings', [ - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name + Database::delete(DATABASE_PREFIX.'users_settings', [ + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name ]); } } + public function delete() : void { + Database::update(DATABASE_PREFIX.'users', [ 'id' ], [ + 'id' => (empty($user_id) ? $this->getID() : $user_id), + 'deleted' => 'Yes' + ]); + } + public function setSettings(string $name, int | string | null $user_id = null, mixed $value = null) : void { - if(Database::exists('SELECT `id` FROM `' . DATABASE_PREFIX . 'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name + if(Database::exists('SELECT `id` FROM `'.DATABASE_PREFIX.'users_settings` WHERE `user_id`=:user_id AND `key`=:key LIMIT 1', [ + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name ])) { - Database::update(DATABASE_PREFIX . 'users_settings', [ 'user_id', 'key' ], [ - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name, - 'value' => $value + Database::update(DATABASE_PREFIX.'users_settings', [ + 'user_id', + 'key' + ], [ + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name, + 'value' => $value ]); } else { - Database::insert(DATABASE_PREFIX . 'users_settings', [ - 'id' => NULL, - 'user_id' => (empty($user_id) ? $this->getID() : $user_id), - 'key' => $name, - 'value' => $value + Database::insert(DATABASE_PREFIX.'users_settings', [ + 'id' => null, + 'user_id' => (empty($user_id) ? $this->getID() : $user_id), + 'key' => $name, + 'value' => $value ]); } } @@ -172,11 +175,39 @@ return sprintf('https://www.gravatar.com/avatar/%s?s=%d&d=%s&r=%s', md5(strtolower(trim($this->email))), 22, 'mp', 'g'); } - public function delete() : void { - Database::update(DATABASE_PREFIX . 'users', [ 'id' ], [ - 'id' => (empty($user_id) ? $this->getID() : $user_id), - 'deleted' => 'Yes' - ]); + public function hasPermission(string $name) : bool { + if(count($this->permissions) > 0) { + if($name === '*') { + return count($this->permissions) >= 1; + } + if(in_array('*', $this->permissions)) { + return true; + } + if(stristr($name, '::*') !== false) { + $count = 0; + $split = explode('::*', $name); + foreach($this->permissions as $permission) { + if(str_starts_with($permission, $split[0])) { + ++$count; + } + } + if($count > 0) { + return true; + } + } + + return in_array($name, $this->permissions); + } + if($name === '*') { + return (count($this->permissions) >= 1); + } + + return in_array($name, $this->permissions); + } + + public function getPermissions() : array { + return $this->permissions; } } -?> \ No newline at end of file + + ?> \ No newline at end of file diff --git a/classes/Templating/TemplateNavigationCategory.class.php b/classes/Templating/TemplateNavigationCategory.class.php index 8fcbf98..1048a62 100644 --- a/classes/Templating/TemplateNavigationCategory.class.php +++ b/classes/Templating/TemplateNavigationCategory.class.php @@ -1,207 +1,202 @@ -navigation = $navigation; - $this->id = $id; - $this->label = $label; - } - - public function getID() : ?string { - return $this->id; - } - - public function getLabel() : ?string { - return $this->label; - } - - public function isEmpty() : bool { - return (count($this->getEntries()) === 0); - } - - public function getEntries() : array { - $hardcoded = []; - - switch($this->id) { - case 'account': - $hardcoded = [ - (object) [ - 'name' => I18N::get('Account'), - 'icon' => Icon::render('account'), - 'order' => 1, - 'url' => '/account', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/account') - ], - (object) [ - 'name' => I18N::get('Settings'), - 'icon' => Icon::render('settings'), - 'order' => 2, - 'url' => '/settings', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/settings') - ], - (object) [ - 'name' => I18N::get('Logout'), - 'icon' => Icon::render('logout'), - 'order' => 99999, - 'url' => '/logout', - 'active' => $this->navigation->getCore()->getRouter()->is('/logout') - ] - ]; - break; - case 'admin': - if(Auth::hasPermission('*')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Overview'), - 'icon' => Icon::render('overview'), - 'order' => 1, - 'url' => '/admin', - 'active' => $this->navigation->getCore()->getRouter()->is('/admin') - ]; - } - - if(Auth::hasPermission('USERS::VIEW')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Users'), - 'icon' => Icon::render('users'), - 'order' => 1, - 'url' => '/admin/users', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/users') - ]; - } - - if(Auth::hasPermission('THEMES::VIEW')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Themes'), - 'icon' => Icon::render('themes'), - 'order' => 2, - 'url' => '/admin/themes', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/themes') - ]; - } - - if(Auth::hasPermission('MODULES::VIEW')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Modules'), - 'icon' => Icon::render('modules'), - 'order' => 3, - 'url' => '/admin/modules', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/modules') - ]; - } - break; - case 'server': - if(Auth::hasPermission('SERVER::VIEW')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Server'), - 'icon' => Icon::render('server'), - 'order' => 1, - 'url' => '/server/server', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/server') - ]; - } - - if(Auth::hasPermission('LOGFILES::VIEW')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Logfiles'), - 'icon' => Icon::render('logfiles'), - 'order' => 2, - 'url' => '/server/logs', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/logs') - ]; - } - - if(Auth::hasPermission('SERVER::MANAGE')) { - $hardcoded[] = (object) [ - 'name' => I18N::get('Settings'), - 'icon' => Icon::render('options'), - 'order' => 1, - 'url' => '/server/settings', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/settings') - ]; - - $hardcoded[] = (object) [ - 'name' => I18N::get('Console'), - 'icon' => Icon::render('console'), - 'order' => 2, - 'url' => '/server/console', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/console') - ]; - - $hardcoded[] = (object) [ - 'name' => I18N::get('Packages'), - 'icon' => Icon::render('packages'), - 'order' => 3, - 'url' => '/server/packages', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/packages') - ]; - - $hardcoded[] = (object) [ - 'name' => I18N::get('Services'), - 'icon' => Icon::render('services'), - 'order' => 4, - 'url' => '/server/services', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/services') - ]; - - $hardcoded[] = (object) [ - 'name' => I18N::get('Network'), - 'icon' => Icon::render('network'), - 'order' => 5, - 'url' => '/server/network', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/network') - ]; - - $hardcoded[] = (object) [ - 'name' => I18N::get('Reboot'), - 'icon' => Icon::render('reboot'), - 'order' => 6, - 'url' => '/server/reboot', - 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/reboot') - ]; - } - break; - } - - $results = $this->navigation->getCore()->getHooks()->applyFilter(strtoupper(sprintf('%s_MANAGEMENT', $this->id)), $hardcoded); - - usort($results, function ($a, $b) { - if($a->{'order'} === $b->{'order'}) { - return 0; - } - - return ($a->{'order'} < $b->{'order'}) ? -1 : 1; - }); - - usort($results, function($a, $b) { - if(empty($a->order)) { - $a->order = 0; - } - - if(empty($b->order)) { - $b->order = 999; - } - - return $a->order > $b->order ? 1 : -1; - }); - - return $results; - } - } -?> \ No newline at end of file +navigation = $navigation; + $this->id = $id; + $this->label = $label; + } + + public function getID() : ?string { + return $this->id; + } + + public function getLabel() : ?string { + return $this->label; + } + + public function isEmpty() : bool { + return (count($this->getEntries()) === 0); + } + + public function getEntries() : array { + $hardcoded = []; + switch($this->id) { + case 'account': + $hardcoded = [ + (object) [ + 'name' => I18N::get('Account'), + 'icon' => Icon::render('account'), + 'order' => 1, + 'url' => '/account', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/account') + ], + (object) [ + 'name' => I18N::get('Settings'), + 'icon' => Icon::render('settings'), + 'order' => 2, + 'url' => '/settings', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/settings') + ], + (object) [ + 'name' => I18N::get('Logout'), + 'icon' => Icon::render('logout'), + 'order' => 99999, + 'url' => '/logout', + 'active' => $this->navigation->getCore()->getRouter()->is('/logout') + ] + ]; + break; + case 'admin': + if(Auth::hasPermission('THEMES::*') || Auth::hasPermission('MODULES::*') || Auth::hasPermission('USERS::*')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Overview'), + 'icon' => Icon::render('overview'), + 'order' => 1, + 'url' => '/admin', + 'active' => $this->navigation->getCore()->getRouter()->is('/admin') + ]; + } + if(Auth::hasPermission('USERS::*')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Users'), + 'icon' => Icon::render('users'), + 'order' => 1, + 'url' => '/admin/users', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/users') + ]; + } + if(Auth::hasPermission('THEMES::*')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Themes'), + 'icon' => Icon::render('themes'), + 'order' => 2, + 'url' => '/admin/themes', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/themes') + ]; + } + if(Auth::hasPermission('MODULES::*')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Modules'), + 'icon' => Icon::render('modules'), + 'order' => 3, + 'url' => '/admin/modules', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/admin/modules') + ]; + } + break; + case 'server': + if(Auth::hasPermission('SERVER::SERVER')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Server'), + 'icon' => Icon::render('server'), + 'order' => 1, + 'url' => '/server/server', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/server') + ]; + } + if(Auth::hasPermission('SERVER::LOGFILES')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Logfiles'), + 'icon' => Icon::render('logfiles'), + 'order' => 2, + 'url' => '/server/logs', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/logs') + ]; + } + if(Auth::hasPermission('SERVER::SETTINGS')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Settings'), + 'icon' => Icon::render('options'), + 'order' => 1, + 'url' => '/server/settings', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/settings') + ]; + } + if(Auth::hasPermission('SERVER::CONSOLE')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Console'), + 'icon' => Icon::render('console'), + 'order' => 2, + 'url' => '/server/console', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/console') + ]; + } + if(Auth::hasPermission('SERVER::PACKAGES')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Packages'), + 'icon' => Icon::render('packages'), + 'order' => 3, + 'url' => '/server/packages', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/packages') + ]; + } + if(Auth::hasPermission('SERVER::SERVICES')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Services'), + 'icon' => Icon::render('services'), + 'order' => 4, + 'url' => '/server/services', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/services') + ]; + } + if(Auth::hasPermission('SERVER::NETWORK')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Network'), + 'icon' => Icon::render('network'), + 'order' => 5, + 'url' => '/server/network', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/network') + ]; + } + if(Auth::hasPermission('SERVER::REBOOT')) { + $hardcoded[] = (object) [ + 'name' => I18N::get('Reboot'), + 'icon' => Icon::render('reboot'), + 'order' => 6, + 'url' => '/server/reboot', + 'active' => $this->navigation->getCore()->getRouter()->startsWith('/server/reboot') + ]; + } + break; + } + $results = $this->navigation->getCore()->getHooks()->applyFilter(strtoupper(sprintf('%s_MANAGEMENT', $this->id)), $hardcoded); + usort($results, function($a, $b) { + if($a->{'order'} === $b->{'order'}) { + return 0; + } + + return ($a->{'order'} < $b->{'order'}) ? -1 : 1; + }); + usort($results, function($a, $b) { + if(empty($a->order)) { + $a->order = 0; + } + if(empty($b->order)) { + $b->order = 999; + } + + return $a->order > $b->order ? 1 : -1; + }); + + return $results; + } + } + + ?> \ No newline at end of file diff --git a/default/admin/modules.php b/default/admin/modules.php index c017ef4..cc4ba5b 100644 --- a/default/admin/modules.php +++ b/default/admin/modules.php @@ -4,7 +4,7 @@ use fruithost\Localization\I18N; $template->header(); - if(!Auth::hasPermission('MODULES::VIEW')) { + if(!Auth::hasPermission('MODULES::*')) { ?>