diff --git a/src/di.php b/src/di.php index e0ba38cdf..36c8e4e37 100644 --- a/src/di.php +++ b/src/di.php @@ -487,7 +487,7 @@ $di['set_return_uri'] = function () use ($di): void { /* * Creates a new API object based on the specified role and returns it. * - * @param string $role The role to create the API object for. Can be 'guest', 'client', 'admin', or 'system'. + * @param string $role The role to create the API object for. Can be 'guest', 'client', or 'admin'. * * @return \Api_Handler The new API object that was just created. * @@ -498,7 +498,6 @@ $di['api'] = $di->protect(function ($role) use ($di) { 'guest' => new Model_Guest(), 'client' => $di['loggedin_client'], 'admin' => $di['loggedin_admin'], - 'system' => $di['mod_service']('staff')->getCronAdmin(), default => throw new Exception('Unrecognized Handler type: ' . $role), }; @@ -553,9 +552,15 @@ $di['api_admin'] = fn () => $di['api']('admin'); * * @param void * - * @return \Api_Handler + * @return \Api_Handler Internal-only system API handler used for cron/background processing. */ -$di['api_system'] = fn () => $di['api']('system'); +$di['api_system'] = function () use ($di) { + $identity = $di['mod_service']('staff')->getCronAdmin(); + $api = new Api_Handler($identity); + $api->setDi($di); + + return $api; +}; $di['tools'] = function () use ($di) { $service = new FOSSBilling\Tools(); diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index 5e1cfd1c6..aaa332cf3 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -310,7 +310,7 @@ LOCK TABLES `setting` WRITE; INSERT INTO `setting` (`id`, `param`, `value`, `public`, `category`, `hash`, `created_at`, `updated_at`) VALUES - (1,'last_patch','52',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), + (1,'last_patch','53',0,NULL,NULL,'2024-12-30 12:00:00','2024-12-30 12:00:00'), (2,'company_name','Company Name',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (3,'company_email','support@yourcompany.com',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), (4,'company_signature','FOSSBilling.org - Client Management, Invoicing and Support Software',0,NULL,NULL,'2022-12-01 12:00:00','2022-12-01 12:00:00'), diff --git a/src/library/Box/TwigExtensions.php b/src/library/Box/TwigExtensions.php index 87e9aeba8..383485578 100644 --- a/src/library/Box/TwigExtensions.php +++ b/src/library/Box/TwigExtensions.php @@ -136,6 +136,7 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte return [ new TwigFunction('render_widgets', $this->twig_render_widgets(...), ['needs_environment' => true, 'is_safe' => ['html']]), new TwigFunction('svg_sprite', $this->twig_svg_sprite(...), ['needs_environment' => true, 'is_safe' => ['html']]), + new TwigFunction('has_permission', $this->has_permission(...)), // FOSSBilling API functions new TwigFunction('fb_api', $this->fb_api(...), ['is_safe' => ['html']]), @@ -193,6 +194,19 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte return $output; } + public function has_permission(string $module, ?string $permission = null): bool + { + if (!$this->di['auth']->isAdminLoggedIn()) { + return false; + } + + try { + return $this->di['mod_service']('Staff')->hasPermission($this->di['loggedin_admin'], $module, $permission); + } catch (Throwable) { + return false; + } + } + public function twig_ipcountryname_filter($value) { if (empty($value)) { diff --git a/src/library/FOSSBilling/UpdatePatcher.php b/src/library/FOSSBilling/UpdatePatcher.php index edf2651d1..607ba09f9 100644 --- a/src/library/FOSSBilling/UpdatePatcher.php +++ b/src/library/FOSSBilling/UpdatePatcher.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace FOSSBilling; +use Doctrine\DBAL\ParameterType; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; @@ -294,6 +295,7 @@ class UpdatePatcher implements InjectionAwareInterface 50 => 'patch50', 51 => 'patch51', 52 => 'patch52', + 53 => 'patch53', ]; ksort($patches, SORT_NATURAL); @@ -824,6 +826,79 @@ class UpdatePatcher implements InjectionAwareInterface } } + private function patch53(): void + { + $dbal = $this->di['dbal']; + $tools = $this->di['tools']; + $now = date('Y-m-d H:i:s'); + + $dbal->beginTransaction(); + + try { + $batchSize = 1000; + $adminUpdateStmt = $dbal->prepare('UPDATE admin SET api_token = :api_token, updated_at = :updated_at WHERE id = :id'); + $clientUpdateStmt = $dbal->prepare('UPDATE client SET api_token = :api_token, updated_at = :updated_at WHERE id = :id'); + + $lastAdminId = 0; + do { + $adminIds = $dbal->createQueryBuilder() + ->select('id') + ->from('admin') + ->where('id > :lastId') + ->orderBy('id', 'ASC') + ->setMaxResults($batchSize) + ->setParameter('lastId', $lastAdminId) + ->executeQuery() + ->fetchFirstColumn(); + + foreach ($adminIds as $adminId) { + $adminUpdateStmt->bindValue('api_token', $tools->generatePassword(32)); + $adminUpdateStmt->bindValue('updated_at', $now); + $adminUpdateStmt->bindValue('id', (int) $adminId, ParameterType::INTEGER); + $adminUpdateStmt->executeStatement(); + } + + if (!empty($adminIds)) { + $lastAdminId = (int) end($adminIds); + } + } while (!empty($adminIds)); + + $lastClientId = 0; + do { + $clientIds = $dbal->createQueryBuilder() + ->select('id') + ->from('client') + ->where('id > :lastId') + ->orderBy('id', 'ASC') + ->setMaxResults($batchSize) + ->setParameter('lastId', $lastClientId) + ->executeQuery() + ->fetchFirstColumn(); + + foreach ($clientIds as $clientId) { + $clientUpdateStmt->bindValue('api_token', $tools->generatePassword(32)); + $clientUpdateStmt->bindValue('updated_at', $now); + $clientUpdateStmt->bindValue('id', (int) $clientId, ParameterType::INTEGER); + $clientUpdateStmt->executeStatement(); + } + + if (!empty($clientIds)) { + $lastClientId = (int) end($clientIds); + } + } while (!empty($clientIds)); + + $dbal->createQueryBuilder() + ->delete('session') + ->executeStatement(); + + $dbal->commit(); + } catch (\Throwable $e) { + $dbal->rollBack(); + + throw $e; + } + } + /** * If we end up needing a newly introduced package during the update process, composer's autoloader won't have it until the next load. * As a workaround, we can register AntLoader and point it at the Vendor folder which will then act as fallback to find the needed classes. diff --git a/src/modules/Api/Controller/Client.php b/src/modules/Api/Controller/Client.php index 4f89f6e18..1bb23be66 100644 --- a/src/modules/Api/Controller/Client.php +++ b/src/modules/Api/Controller/Client.php @@ -45,8 +45,9 @@ class Client implements InjectionAwareInterface public function register(\Box_App &$app): void { - $app->post('/api/:role/:class/:method', 'post_method', ['role', 'class', 'method'], static::class); - $app->get('/api/:role/:class/:method', 'get_method', ['role', 'class', 'method'], static::class); + $allowedRouteRoles = $this->registerAllowedRouteRoles(); + $app->post('/api/:role/:class/:method', 'post_method', $allowedRouteRoles, static::class); + $app->get('/api/:role/:class/:method', 'get_method', $allowedRouteRoles, static::class); // all other requests are error requests $app->get('/api/:page', 'show_error', ['page' => '(.?)+'], static::class); @@ -187,24 +188,12 @@ class Client implements InjectionAwareInterface $this->checkHttpReferer(); $this->isRoleAllowed($role); - $hasTokenAuthCredentials = in_array($role, ['client', 'admin'], true) && $this->hasTokenAuthCredentials(); - $hasValidSession = false; - - try { - $this->isRoleLoggedIn($role); - $hasValidSession = true; - } catch (\Exception) { - } - - if ($hasTokenAuthCredentials) { - // Token auth via the Authorization header is not vulnerable to CSRF (browsers cannot send - // Authorization headers cross-origin automatically), so skip CSRF and perform token login. - $this->_tryTokenLogin(); - } elseif (!$hasValidSession) { - $this->_tryTokenLogin(); - } elseif ($role == 'client' || $role == 'admin') { - // Authenticated browser session for privileged roles must pass CSRF checks. - $this->_checkCSRFToken(); + if ($role !== 'guest') { + if ($this->shouldUseTokenLogin($role)) { + $this->_tryTokenLogin($role); + } else { + $this->requireSessionAuth($role); + } } $api = $this->di['api']($role); @@ -236,11 +225,14 @@ class Client implements InjectionAwareInterface private function getAuth(): array { - if (isset($_SERVER['HTTP_AUTHORIZATION'])) { - $auth_params = explode(':', base64_decode(substr((string) $_SERVER['HTTP_AUTHORIZATION'], 6))); - $_SERVER['PHP_AUTH_USER'] = $auth_params[0]; - unset($auth_params[0]); - $_SERVER['PHP_AUTH_PW'] = implode('', $auth_params); + if (!isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['HTTP_AUTHORIZATION'])) { + $parsedAuth = $this->tryParseBasicAuthHeader(); + if ($parsedAuth === null) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 201); + } + + $_SERVER['PHP_AUTH_USER'] = $parsedAuth['username']; + $_SERVER['PHP_AUTH_PW'] = $parsedAuth['password']; } if (!isset($_SERVER['PHP_AUTH_USER'])) { @@ -258,11 +250,14 @@ class Client implements InjectionAwareInterface return [$_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']]; } - protected function _tryTokenLogin(): void + protected function _tryTokenLogin(string $routeRole): void { [$username, $password] = $this->getAuth(); + if ($username !== $routeRole) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); + } - switch ($username) { + switch ($routeRole) { case 'client': $model = $this->di['db']->findOne('Client', 'api_token = ?', [$password]); if (!$model instanceof \Model_Client) { @@ -277,6 +272,12 @@ class Client implements InjectionAwareInterface if (!$model instanceof \Model_Admin) { throw new \FOSSBilling\InformationException('Authentication Failed', null, 205); } + + $cronAdmin = $this->di['mod_service']('staff')->getCronAdmin(); + if ($cronAdmin instanceof \Model_Admin && (int) $model->id === (int) $cronAdmin->id) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 205); + } + $sessionAdminArray = [ 'id' => $model->id, 'email' => $model->email, @@ -287,21 +288,96 @@ class Client implements InjectionAwareInterface break; - case 'guest': // do not allow at the moment default: throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); } } - protected function hasTokenAuthCredentials(): bool + private function registerAllowedRouteRoles(): array { - try { - [$username, $password] = $this->getAuth(); - } catch (\Exception) { + return [ + 'role' => 'guest|client|admin', + 'class' => '[a-zA-Z0-9_]+', + 'method' => '[a-zA-Z0-9_]+', + ]; + } + + protected function shouldUseTokenLogin(string $routeRole): bool + { + if (!in_array($routeRole, ['client', 'admin'], true)) { return false; } - return in_array($username, ['client', 'admin'], true) && $password !== ''; + $username = $this->getProvidedBasicAuthUsername(); + if ($username === null) { + return false; + } + + if ($username !== $routeRole) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 203); + } + + return true; + } + + private function getProvidedBasicAuthUsername(): ?string + { + if (isset($_SERVER['PHP_AUTH_USER']) && in_array($_SERVER['PHP_AUTH_USER'], ['client', 'admin'], true)) { + return (string) $_SERVER['PHP_AUTH_USER']; + } + + $parsedAuth = $this->tryParseBasicAuthHeader(); + if ($parsedAuth === null) { + return null; + } + + $username = $parsedAuth['username']; + if (!in_array($username, ['client', 'admin'], true)) { + return null; + } + + return $username; + } + + /** + * @return array{username: string, password: string}|null + */ + private function tryParseBasicAuthHeader(): ?array + { + if (!isset($_SERVER['HTTP_AUTHORIZATION'])) { + return null; + } + + $authorization = trim((string) $_SERVER['HTTP_AUTHORIZATION']); + if (stripos($authorization, 'Basic ') !== 0) { + return null; + } + + $decoded = base64_decode(substr($authorization, 6), true); + if ($decoded === false || !str_contains($decoded, ':')) { + return null; + } + + [$username, $password] = explode(':', $decoded, 2); + + return [ + 'username' => $username, + 'password' => $password, + ]; + } + + private function requireSessionAuth(string $role): void + { + try { + $this->isRoleLoggedIn($role); + if ($role === 'client' || $role === 'admin') { + $this->_checkCSRFToken(); + } + } catch (\FOSSBilling\InformationException $exception) { + throw $exception; + } catch (\Exception) { + throw new \FOSSBilling\InformationException('Authentication Failed', null, 201); + } } /** @@ -312,8 +388,8 @@ class Client implements InjectionAwareInterface private function isRoleAllowed($role): bool { $allowed = ['guest', 'client', 'admin']; - if (!in_array($role, $allowed)) { - new \FOSSBilling\Exception('Unknown API call :call', [':call' => ''], 701); + if (!in_array($role, $allowed, true)) { + throw new \FOSSBilling\Exception('Unknown API call :call', [':call' => (string) $role], 701); } return true; @@ -341,10 +417,12 @@ class Client implements InjectionAwareInterface error_log("{$e->getMessage()} {$e->getCode()}."); $code = $e->getCode() ?: 9999; $result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]]; - $authFailed = [201, 202, 206, 204, 205, 203, 403, 1004, 1002]; + $authFailed = [201, 202, 206, 204, 205, 203, 1004, 1002]; if (in_array($code, $authFailed)) { header('HTTP/1.1 401 Unauthorized'); + } elseif ($code == 403) { + header('HTTP/1.1 403 Forbidden'); } elseif ($code == 701 || $code == 879) { header('HTTP/1.1 400 Bad Request'); } diff --git a/src/modules/Client/Api/Admin.php b/src/modules/Client/Api/Admin.php index 40eceb04d..d04e1b455 100644 --- a/src/modules/Client/Api/Admin.php +++ b/src/modules/Client/Api/Admin.php @@ -31,6 +31,8 @@ class Admin extends \Api_Abstract */ public function get_list($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $per_page = $data['per_page'] ?? $this->di['pager']->getDefaultPerPage(); [$sql, $params] = $this->getService()->getSearchQuery($data); $pager = $this->di['pager']->getPaginatedResultSet($sql, $params, $per_page); @@ -52,6 +54,8 @@ class Admin extends \Api_Abstract */ public function get_pairs($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $service = $this->di['mod_service']('client'); return $service->getPairs($data); @@ -66,10 +70,13 @@ class Admin extends \Api_Abstract */ public function get($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view'); + $service = $this->getService(); $client = $service->get($data); + $includeSensitive = $this->di['mod_service']('Staff')->hasPermission(null, 'client', 'manage_api_keys'); - return $service->toApiArray($client, true, $this->getIdentity()); + return $service->toApiArray($client, true, $this->getIdentity(), $includeSensitive); } /** @@ -80,6 +87,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'ID required'])] public function login($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'impersonate_login'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -138,6 +147,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['email' => 'Email required', 'first_name' => 'First name is required'])] public function create($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'create'); + $validator = $this->di['validator']; $data['email'] = $this->di['tools']->validateAndSanitizeEmail($data['email']); @@ -161,6 +172,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID is missing'])] public function delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'delete'); + $model = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $this->di['events_manager']->fire(['event' => 'onBeforeAdminClientDelete', 'params' => ['id' => $model->id]]); @@ -215,6 +228,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID was not passed'])] public function update($data = []): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'edit_profile'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -279,6 +294,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'ID required', 'password' => 'Password required', 'password_confirm' => 'Password confirmation required'])] public function change_password($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'change_password'); + $this->di['validator']->passwordsMatch($data); $this->di['validator']->isPasswordStrong($data['password']); @@ -332,6 +349,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID was not passed'])] public function balance_delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_balance'); + $model = $this->di['db']->getExistingModelById('ClientBalance', $data['id'], 'Balance line not found'); $id = $model->id; @@ -354,6 +373,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID required', 'amount' => 'Amount is required', 'description' => 'Description is required'])] public function balance_add_funds($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_balance'); + $client = $this->di['db']->getExistingModelById('Client', $data['id'], 'Client not found'); $service = $this->di['mod_service']('client'); @@ -387,6 +408,8 @@ class Admin extends \Api_Abstract */ public function login_history_get_list($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'view_login_history'); + [$q, $params] = $this->getService()->getHistorySearchQuery($data); $per_page = $data['per_page'] ?? $this->di['pager']->getDefaultPerPage(); $pager = $this->di['pager']->getPaginatedResultSet($q, $params, $per_page); @@ -440,6 +463,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['title' => 'Group title is missing'])] public function group_create($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + return $this->getService()->createGroup($data); } @@ -451,6 +476,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Group ID is missing'])] public function group_update($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + $model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found'); $model->title = $data['title'] ?? $model->title; @@ -468,6 +495,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Group ID is missing'])] public function group_delete($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_groups'); + $model = $this->di['db']->getExistingModelById('ClientGroup', $data['id'], 'Group not found'); $clients = $this->di['db']->find('Client', 'client_group_id = :group_id', [':group_id' => $data['id']]); @@ -498,6 +527,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['ids' => 'IDs were not passed'])] public function batch_delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'bulk_delete'); + foreach ($data['ids'] as $id) { $this->delete(['id' => $id]); } @@ -507,6 +538,8 @@ class Admin extends \Api_Abstract public function export_csv($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'export'); + $data['headers'] ??= []; return $this->getService()->exportCSV($data['headers']); diff --git a/src/modules/Client/Service.php b/src/modules/Client/Service.php index 31b25f1c0..6d076871c 100644 --- a/src/modules/Client/Service.php +++ b/src/modules/Client/Service.php @@ -20,6 +20,73 @@ class Service implements InjectionAwareInterface { protected ?\Pimple\Container $di = null; + public function getModulePermissions(): array + { + return [ + 'view' => [ + 'type' => 'bool', + 'display_name' => __trans('View client details'), + 'description' => __trans('Allows the staff member to view client account details and listings.'), + ], + 'create' => [ + 'type' => 'bool', + 'display_name' => __trans('Create clients'), + 'description' => __trans('Allows the staff member to create new client accounts.'), + ], + 'edit_profile' => [ + 'type' => 'bool', + 'display_name' => __trans('Edit client profiles'), + 'description' => __trans('Allows the staff member to update client profile details and account settings.'), + ], + 'impersonate_login' => [ + 'type' => 'bool', + 'display_name' => __trans('Login as client'), + 'description' => __trans('Allows the staff member to authenticate as any client account.'), + ], + 'manage_api_keys' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client API keys'), + 'description' => __trans('Allows the staff member to view and generate API keys for client accounts.'), + ], + 'change_password' => [ + 'type' => 'bool', + 'display_name' => __trans('Change client passwords'), + 'description' => __trans('Allows the staff member to set new passwords for client accounts.'), + ], + 'manage_balance' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client balance'), + 'description' => __trans('Allows the staff member to add or remove balance entries for client accounts.'), + ], + 'view_login_history' => [ + 'type' => 'bool', + 'display_name' => __trans('View client login history'), + 'description' => __trans('Allows the staff member to view client login history and IP addresses.'), + ], + 'manage_groups' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage client groups'), + 'description' => __trans('Allows the staff member to create, update, and delete client groups.'), + ], + 'delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Delete clients'), + 'description' => __trans('Allows the staff member to permanently remove client accounts.'), + ], + 'bulk_delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Bulk delete clients'), + 'description' => __trans('Allows the staff member to permanently remove multiple client accounts in a single action.'), + ], + 'export' => [ + 'type' => 'bool', + 'display_name' => __trans('Export clients'), + 'description' => __trans('Allows the staff member to export client account data.'), + ], + 'manage_settings' => [], + ]; + } + public function setDi(\Pimple\Container $di): void { $this->di = $di; @@ -339,7 +406,7 @@ class Service implements InjectionAwareInterface return $this->di['db']->findOne('Client', 'email = ? and pass = ? and status = ?', [$email, $password, \Model_Client::ACTIVE]); } - public function toApiArray(\Model_Client $model, $deep = false, $identity = null): array + public function toApiArray(\Model_Client $model, $deep = false, $identity = null, bool $includeSensitive = false): array { $details = [ 'id' => $model->id, @@ -385,13 +452,16 @@ class Service implements InjectionAwareInterface if ($identity instanceof \Model_Admin) { $details['auth_type'] = $model->auth_type; - $details['api_token'] = $model->api_token; $details['ip'] = $model->ip; $details['status'] = $model->status; $details['tax_exempt'] = $model->tax_exempt; $details['group'] = ($clientGroup) ? $clientGroup->title : null; $details['updated_at'] = $model->updated_at; $details['email_approved'] = $model->email_approved; + + if ($includeSensitive) { + $details['api_token'] = $model->api_token; + } } return $details; diff --git a/src/modules/Client/templates/admin/mod_client_group.html.twig b/src/modules/Client/templates/admin/mod_client_group.html.twig index 53f375a67..c4e545ff4 100644 --- a/src/modules/Client/templates/admin/mod_client_group.html.twig +++ b/src/modules/Client/templates/admin/mod_client_group.html.twig @@ -1,6 +1,7 @@ {% extends 'layout_default.html.twig' %} {% set active_menu = 'client' %} +{% set can_manage_groups = has_permission('client', 'manage_groups') %} {% block meta_title %}{{ group.title}}{% endblock %} @@ -25,6 +26,7 @@

{{ 'Edit client group'|trans }} - {{ group.title }}

+ {% if can_manage_groups %}
@@ -53,5 +55,10 @@
+ {% else %} +
+

{{ 'You do not have permission to manage client groups.'|trans }}

+
+ {% endif %}
{% endblock %} diff --git a/src/modules/Client/templates/admin/mod_client_index.html.twig b/src/modules/Client/templates/admin/mod_client_index.html.twig index d9262c5f3..3aa5bf8fb 100644 --- a/src/modules/Client/templates/admin/mod_client_index.html.twig +++ b/src/modules/Client/templates/admin/mod_client_index.html.twig @@ -3,6 +3,11 @@ {% import 'macro_functions.html.twig' as mf %} {% set active_menu = 'client' %} +{% set can_create_client = has_permission('client', 'create') %} +{% set can_manage_groups = has_permission('client', 'manage_groups') %} +{% set can_delete_client = has_permission('client', 'delete') %} +{% set can_bulk_delete_clients = has_permission('client', 'bulk_delete') and can_delete_client %} +{% set can_export_clients = has_permission('client', 'export') %} {% block meta_title %}{{ 'Clients'|trans }}{% endblock %} @@ -172,6 +177,7 @@ + {% if can_create_client %} + {% endif %} + {% if can_manage_groups %} @@ -191,6 +199,7 @@ {{ 'New Group'|trans }} + {% endif %}
@@ -201,9 +210,11 @@ + {% if can_bulk_delete_clients %} + {% endif %} @@ -216,9 +227,11 @@ {% set clients = admin.client_get_list({ 'per_page': 30, 'page': request.page }|merge(request)) %} {% for client in clients.list %} + {% if can_bulk_delete_clients %} + {% endif %} {% else %} - + {% endfor %} @@ -276,24 +291,31 @@ + {% if can_create_client %}
{{ include('mod_client_new_form.html.twig') }}
+ {% endif %} + {% if can_manage_groups %}
{{ 'Name'|trans }} {{ 'Company'|trans }} {{ 'Status'|trans }}
@@ -257,17 +270,19 @@ + {% if can_delete_client %} + {% endif %}
{{ 'The list is empty'|trans }}{{ 'The list is empty'|trans }}
@@ -344,6 +366,7 @@ + {% endif %} {% endblock %} diff --git a/src/modules/Client/templates/admin/mod_client_login_history.html.twig b/src/modules/Client/templates/admin/mod_client_login_history.html.twig index 21ea1f2b7..d706ae820 100644 --- a/src/modules/Client/templates/admin/mod_client_login_history.html.twig +++ b/src/modules/Client/templates/admin/mod_client_login_history.html.twig @@ -1,6 +1,7 @@ {% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %} {% import 'macro_functions.html.twig' as mf %} +{% set can_view_client_login_history = has_permission('client', 'view_login_history') %} {% block meta_title %}{{ 'Clients Login History'|trans }}{% endblock %} @@ -12,6 +13,7 @@
{{ 'Client login history'|trans }}
+ {% if can_view_client_login_history %} {{ include('partial_search.html.twig') }}
@@ -53,5 +55,10 @@ + {% else %} +
+

{{ 'You do not have permission to view client login history.'|trans }}

+
+ {% endif %} {% endblock %} diff --git a/src/modules/Client/templates/admin/mod_client_manage.html.twig b/src/modules/Client/templates/admin/mod_client_manage.html.twig index 161ee2505..afe75d4ce 100644 --- a/src/modules/Client/templates/admin/mod_client_manage.html.twig +++ b/src/modules/Client/templates/admin/mod_client_manage.html.twig @@ -3,6 +3,14 @@ {% import 'macro_functions.html.twig' as mf %} {% set active_menu = 'client' %} +{% set can_impersonate_client = has_permission('client', 'impersonate_login') %} +{% set can_delete_client = has_permission('client', 'delete') %} +{% set can_edit_profile = has_permission('client', 'edit_profile') %} +{% set can_change_password = has_permission('client', 'change_password') %} +{% set can_manage_balance = has_permission('client', 'manage_balance') %} +{% set can_manage_api_keys = has_permission('client', 'manage_api_keys') %} +{% set can_view_client_login_history = has_permission('client', 'view_login_history') %} +{% set has_profile_edit_actions = can_edit_profile or can_change_password %} {% block meta_title %}{{ client.first_name }} {{ client.last_name }}{% endblock %} @@ -25,9 +33,11 @@ + {% if has_profile_edit_actions %} + {% endif %} @@ -37,12 +47,16 @@ + {% if can_manage_balance %} + {% endif %} + {% if can_view_client_login_history %} + {% endif %} @@ -109,7 +123,11 @@ - {{ client.notes }} + {% if has_profile_edit_actions %} + {{ client.notes }} + {% else %} + {{ client.notes }} + {% endif %} {% endif %} @@ -117,10 +135,12 @@ + {% if can_manage_api_keys %} + {% endif %}
IP: {%if client.ip %}{{ client.ip|iplookup }}{% else %}{{ 'Unknown'|trans }}{% endif %}
{{ 'API Key'|trans }}: {{ client.api_token|default('-') }}
{{ 'Address'|trans }}: @@ -137,12 +157,15 @@ + {% if has_profile_edit_actions %}
+ {% if can_edit_profile %}
{{ 'Client profile details'|trans }}
@@ -394,7 +420,9 @@
+ {% endif %} + {% if can_change_password %}
{{ 'Change password'|trans }}
@@ -414,9 +442,12 @@ -
- -
{{ 'Custom fields'|trans }}
+ {% endif %} + {% if can_edit_profile %} + {% if can_change_password %} +
+ {% endif %} +
{{ 'Custom Fields'|trans }}

{{ 'Use these fields to define custom client details'|trans }}

{% for i in 1..10 %} @@ -432,8 +463,10 @@
+ {% endif %}
+ {% endif %}
@@ -637,6 +670,7 @@
+ {% if can_manage_balance %}
{{ 'Client payments history'|trans }}
@@ -709,7 +743,9 @@
+ {% endif %} + {% if can_view_client_login_history %}
{{ 'Login history'|trans }}
@@ -742,6 +778,7 @@
+ {% endif %}
diff --git a/src/modules/Client/templates/admin/mod_client_new_form.html.twig b/src/modules/Client/templates/admin/mod_client_new_form.html.twig index b2a72e75a..1ff3196f0 100644 --- a/src/modules/Client/templates/admin/mod_client_new_form.html.twig +++ b/src/modules/Client/templates/admin/mod_client_new_form.html.twig @@ -1,4 +1,5 @@ {% import 'macro_functions.html.twig' as mf %} +{% if has_permission('client', 'create') %}
@@ -153,3 +154,4 @@
+{% endif %} diff --git a/src/modules/Currency/Api/Admin.php b/src/modules/Currency/Api/Admin.php index 1906d67a7..be6bd6d5b 100644 --- a/src/modules/Currency/Api/Admin.php +++ b/src/modules/Currency/Api/Admin.php @@ -95,6 +95,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['code' => 'Currency code is missing', 'format' => 'Currency format is missing'])] public function create($data = []): string { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('currency', 'create'); + $service = $this->getService(); /** @var \Box\Mod\Currency\Repository\CurrencyRepository $repo */ @@ -126,6 +128,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['code' => 'Currency code is missing'])] public function update($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('currency', 'edit'); + $format = $data['format'] ?? null; $title = $data['title'] ?? null; $priceFormat = $data['price_format'] ?? null; @@ -147,6 +151,8 @@ class Admin extends \Api_Abstract */ public function update_rates(array $data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('currency', 'update_rates'); + return $this->service->updateCurrencyRates(); } @@ -158,6 +164,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['code' => 'Currency code is missing'])] public function delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('currency', 'delete'); + return $this->getService()->deleteCurrencyByCode($data['code']); } @@ -170,6 +178,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['code' => 'Currency code is missing'])] public function set_default($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('currency', 'set_default'); + $service = $this->getService(); /** @var \Box\Mod\Currency\Repository\CurrencyRepository $repo */ diff --git a/src/modules/Currency/Service.php b/src/modules/Currency/Service.php index 87fbd7d7e..92c3a3ed1 100644 --- a/src/modules/Currency/Service.php +++ b/src/modules/Currency/Service.php @@ -53,6 +53,31 @@ class Service implements InjectionAwareInterface { return [ 'can_always_access' => true, + 'create' => [ + 'type' => 'bool', + 'display_name' => __trans('Create currencies'), + 'description' => __trans('Allows the staff member to add new currencies to the system.'), + ], + 'edit' => [ + 'type' => 'bool', + 'display_name' => __trans('Edit currencies'), + 'description' => __trans('Allows the staff member to update currency titles, formats, and conversion rates.'), + ], + 'delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Delete currencies'), + 'description' => __trans('Allows the staff member to remove currencies from the system.'), + ], + 'set_default' => [ + 'type' => 'bool', + 'display_name' => __trans('Set default currency'), + 'description' => __trans('Allows the staff member to change the system default currency.'), + ], + 'update_rates' => [ + 'type' => 'bool', + 'display_name' => __trans('Update currency rates'), + 'description' => __trans('Allows the staff member to refresh all currency conversion rates.'), + ], 'manage_settings' => [], ]; } diff --git a/src/modules/Currency/templates/admin/mod_currency_manage.html.twig b/src/modules/Currency/templates/admin/mod_currency_manage.html.twig index 64a52088f..850caacc4 100644 --- a/src/modules/Currency/templates/admin/mod_currency_manage.html.twig +++ b/src/modules/Currency/templates/admin/mod_currency_manage.html.twig @@ -3,6 +3,7 @@ {% import 'macro_functions.html.twig' as mf %} {% set active_menu = 'system' %} +{% set can_edit_currency = has_permission('currency', 'edit') %} {% block meta_title %}{{ 'Currency Management'|trans }}{% endblock %} @@ -27,6 +28,7 @@ {% block content %}
+ {% if can_edit_currency %}

{{ 'Edit Currency Information'|trans }} {{ currency.code }}

@@ -79,5 +81,10 @@
+ {% else %} +
+

{{ 'You do not have permission to edit currencies.'|trans }}

+
+ {% endif %}
{% endblock %} diff --git a/src/modules/Currency/templates/admin/mod_currency_settings.html.twig b/src/modules/Currency/templates/admin/mod_currency_settings.html.twig index 6d6fee878..e6109b365 100644 --- a/src/modules/Currency/templates/admin/mod_currency_settings.html.twig +++ b/src/modules/Currency/templates/admin/mod_currency_settings.html.twig @@ -4,6 +4,11 @@ {% set active_menu = 'system' %} {% set params = admin.extension_config_get({ 'ext': 'mod_currency' }) %} +{% set can_create_currency = has_permission('currency', 'create') %} +{% set can_edit_currency = has_permission('currency', 'edit') %} +{% set can_delete_currency = has_permission('currency', 'delete') %} +{% set can_set_default_currency = has_permission('currency', 'set_default') %} +{% set can_update_currency_rates = has_permission('currency', 'update_rates') %} {% block meta_title %}{{ 'Currency Settings'|trans }}{% endblock %} @@ -29,6 +34,7 @@ + {% if can_create_currency %} + {% endif %} @@ -81,12 +88,15 @@ {{ currency.conversion_rate }} {{ mf.currency_format(1) }} = {{ mf.currency(1, currency.code) }} + {% if can_edit_currency %} + {% endif %} + {% if can_delete_currency %} @@ -94,7 +104,8 @@ - {% if not currency.default %} + {% endif %} + {% if can_set_default_currency and not currency.default %} @@ -115,18 +126,21 @@
+ {% if can_create_currency %}
@@ -161,6 +175,7 @@
+ {% endif %}
diff --git a/src/modules/Extension/templates/admin/mod_extension_index.html.twig b/src/modules/Extension/templates/admin/mod_extension_index.html.twig index ff7456073..5f564b6df 100644 --- a/src/modules/Extension/templates/admin/mod_extension_index.html.twig +++ b/src/modules/Extension/templates/admin/mod_extension_index.html.twig @@ -1,6 +1,7 @@ {% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %} {% import 'macro_functions.html.twig' as mf %} +{% set can_manage_hooks = has_permission('hook', 'manage_hooks') %} {% block meta_title %}{{ 'Extensions'|trans }}{% endblock %} @@ -18,9 +19,11 @@ + {% if can_manage_hooks %} + {% endif %}
@@ -166,6 +169,7 @@
+ {% if can_manage_hooks %}
@@ -190,6 +194,7 @@
+ {% endif %} diff --git a/src/modules/Hook/Api/Admin.php b/src/modules/Hook/Api/Admin.php index 024edba03..5393d5a05 100644 --- a/src/modules/Hook/Api/Admin.php +++ b/src/modules/Hook/Api/Admin.php @@ -25,6 +25,8 @@ class Admin extends \Api_Abstract */ public function get_list($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('hook', 'manage_hooks'); + $service = $this->getService(); [$sql, $params] = $service->getSearchQuery($data); $per_page = $data['per_page'] ?? $this->di['pager']->getDefaultPerPage(); @@ -41,6 +43,8 @@ class Admin extends \Api_Abstract */ public function call($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('hook', 'trigger_hooks'); + if (!isset($data['event']) || empty($data['event'])) { error_log('Invoked event call without providing event name'); @@ -70,6 +74,8 @@ class Admin extends \Api_Abstract */ public function batch_connect($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('hook', 'manage_hooks'); + $mod = $data['mod'] ?? null; $service = $this->getService(); diff --git a/src/modules/Hook/Service.php b/src/modules/Hook/Service.php index 1eb973f82..a5f4d9a13 100644 --- a/src/modules/Hook/Service.php +++ b/src/modules/Hook/Service.php @@ -31,7 +31,16 @@ class Service implements InjectionAwareInterface public function getModulePermissions(): array { return [ - 'hide_permissions' => true, + 'manage_hooks' => [ + 'type' => 'bool', + 'display_name' => __trans('Manage hooks'), + 'description' => __trans('Allows the staff member to view and reconnect registered event hooks.'), + ], + 'trigger_hooks' => [ + 'type' => 'bool', + 'display_name' => __trans('Trigger hooks'), + 'description' => __trans('Allows the staff member to invoke hooks manually with custom event payloads.'), + ], ]; } diff --git a/src/modules/Profile/Api/Admin.php b/src/modules/Profile/Api/Admin.php index 47e64e7ca..ca9aeebb8 100644 --- a/src/modules/Profile/Api/Admin.php +++ b/src/modules/Profile/Api/Admin.php @@ -145,6 +145,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Client ID was not passed'])] public function api_key_reset($data): string { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('client', 'manage_api_keys'); + $client = $this->di['db']->getExistingModelById('Client', $data['id']); return $this->getService()->resetApiKey($client); diff --git a/src/modules/Redirect/Api/Admin.php b/src/modules/Redirect/Api/Admin.php index 59356cba4..0e0c13500 100644 --- a/src/modules/Redirect/Api/Admin.php +++ b/src/modules/Redirect/Api/Admin.php @@ -46,6 +46,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['path' => 'Redirect path was not passed', 'target' => 'Redirect target was not passed'])] public function create($data): int { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('redirect', 'create_and_edit'); + $id = $this->getService()->create( trim(htmlspecialchars((string) $data['path'], ENT_QUOTES | ENT_HTML5, 'UTF-8'), '/'), trim(htmlspecialchars((string) $data['target'], ENT_QUOTES | ENT_HTML5, 'UTF-8'), '/') @@ -67,6 +69,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Redirect ID was not passed'])] public function update($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('redirect', 'create_and_edit'); + $this->getService()->update($this->getService()->get((int) $data['id']), $data); $this->di['logger']->info('Updated redirect #%s', $data['id']); @@ -82,6 +86,8 @@ class Admin extends \Api_Abstract #[RequiredParams(['id' => 'Redirect ID was not passed'])] public function delete($data): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('redirect', 'delete'); + $this->getService()->delete($this->getService()->get((int) $data['id'])); $this->di['logger']->info('Removed redirect #%s', $data['id']); diff --git a/src/modules/Redirect/Service.php b/src/modules/Redirect/Service.php index 4659a0d78..2a1028690 100644 --- a/src/modules/Redirect/Service.php +++ b/src/modules/Redirect/Service.php @@ -33,6 +33,23 @@ class Service implements \FOSSBilling\InjectionAwareInterface return $this->di; } + public function getModulePermissions(): array + { + return [ + 'create_and_edit' => [ + 'type' => 'bool', + 'display_name' => __trans('Create and edit redirects'), + 'description' => __trans('Allows the staff member to create and edit redirects.'), + ], + 'delete' => [ + 'type' => 'bool', + 'display_name' => __trans('Delete redirects'), + 'description' => __trans('Allows the staff member to delete redirects.'), + ], + 'manage_settings' => [], + ]; + } + public function getExtensionMetaRepository(): ExtensionMetaRepository { if ($this->extensionMetaRepository === null) { diff --git a/src/modules/Redirect/templates/admin/mod_redirect_settings.html.twig b/src/modules/Redirect/templates/admin/mod_redirect_settings.html.twig index 1fb106c40..3b83372ac 100644 --- a/src/modules/Redirect/templates/admin/mod_redirect_settings.html.twig +++ b/src/modules/Redirect/templates/admin/mod_redirect_settings.html.twig @@ -95,7 +95,7 @@ diff --git a/src/modules/Staff/Service.php b/src/modules/Staff/Service.php index 232f6dd0c..b5cb65abf 100644 --- a/src/modules/Staff/Service.php +++ b/src/modules/Staff/Service.php @@ -16,6 +16,8 @@ use FOSSBilling\InjectionAwareInterface; class Service implements InjectionAwareInterface { + private array $permissionCache = []; + protected ?\Pimple\Container $di = null; public function setDi(\Pimple\Container $di): void @@ -28,6 +30,17 @@ class Service implements InjectionAwareInterface return $this->di; } + private function getPermissionsFromCache(int|string $memberId): ?array + { + $cacheKey = (string) $memberId; + + if (!array_key_exists($cacheKey, $this->permissionCache)) { + return null; + } + + return is_array($this->permissionCache[$cacheKey]) ? $this->permissionCache[$cacheKey] : []; + } + public function getModulePermissions(): array { return [ @@ -144,11 +157,19 @@ class Service implements InjectionAwareInterface ->setParameter('id', $member_id) ->executeStatement(); + $this->permissionCache[(string) $member_id] = $array; + return true; } public function getPermissions($member_id) { + $cachedPermissions = $this->getPermissionsFromCache($member_id); + + if (!is_null($cachedPermissions)) { + return $cachedPermissions; + } + $query = $this->di['dbal']->createQueryBuilder(); $query ->select('permissions') @@ -158,10 +179,12 @@ class Service implements InjectionAwareInterface $result = $query->executeQuery()->fetchOne() ?? ''; $permissions = json_decode($result, true); - if (!$permissions) { - return []; + if (!is_array($permissions)) { + $permissions = []; } + $this->permissionCache[(string) $member_id] = $permissions; + return $permissions; } @@ -189,11 +212,7 @@ class Service implements InjectionAwareInterface $modulePermissions = $extensionService->getSpecificModulePermissions($module); $permissions = $this->getPermissions($member->id); - if ($modulePermissions['hide_permissions'] ?? false) { - $canAlwaysAccess = true; - } else { - $canAlwaysAccess = $modulePermissions['can_always_access'] ?? false; - } + $canAlwaysAccess = $modulePermissions['can_always_access'] ?? false; if (!$canAlwaysAccess) { // They have no permissions or don't have any access to that module @@ -203,16 +222,17 @@ class Service implements InjectionAwareInterface } if (!is_null($key)) { - // If this passes, the permission key isn't assigned to them and they therefore don't have permission - if (!is_array($permissions[$module]) || !array_key_exists($key, $permissions[$module])) { + $modulePermissions = $permissions[$module] ?? []; + + if (!is_array($modulePermissions) || !array_key_exists($key, $modulePermissions)) { return false; } if (!is_null($constraint)) { - return $permissions[$module][$key] === $constraint; + return $modulePermissions[$key] === $constraint; } - return (bool) $permissions[$module][$key]; + return (bool) $modulePermissions[$key]; } return true; @@ -228,7 +248,9 @@ class Service implements InjectionAwareInterface public function checkPermissionsAndThrowException(string $module, ?string $key = null, mixed $constraint = null): void { if (!$this->hasPermission(null, $module, $key, $constraint)) { - throw new \FOSSBilling\InformationException('You do not have permission to perform this action', [], 403); + $requiredPermission = is_null($key) ? $module : "{$module}.{$key}"; + + throw new \FOSSBilling\InformationException("You need the \"{$requiredPermission}\" permission to perform this action", [], 403); } } diff --git a/src/modules/System/Api/Admin.php b/src/modules/System/Api/Admin.php index ecdedf4f1..252301597 100644 --- a/src/modules/System/Api/Admin.php +++ b/src/modules/System/Api/Admin.php @@ -40,6 +40,8 @@ class Admin extends \Api_Abstract */ public function update_params($data) { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('system', 'update_params'); + return $this->getService()->updateParams($data); } @@ -170,6 +172,8 @@ class Admin extends \Api_Abstract */ public function recheck_update(): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('system', 'recheck_update'); + $updater = $this->di['updater']; $updater->getLatestVersionInfo(null, true); @@ -249,6 +253,8 @@ class Admin extends \Api_Abstract */ public function toggle_error_reporting(): bool { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('system', 'toggle_error_reporting'); + $current = Config::getProperty('debug_and_monitoring.report_errors', false); Config::setProperty('debug_and_monitoring.report_errors', !$current); @@ -265,6 +271,8 @@ class Admin extends \Api_Abstract public function get_interface_ips(): array { + $this->di['mod_service']('Staff')->checkPermissionsAndThrowException('system', 'manage_network_interface'); + return \FOSSBilling\Tools::listHttpInterfaces(); } diff --git a/src/modules/System/Service.php b/src/modules/System/Service.php index 670df563d..f9ae24845 100644 --- a/src/modules/System/Service.php +++ b/src/modules/System/Service.php @@ -56,6 +56,11 @@ class Service 'display_name' => __trans('Manage company legal'), 'description' => __trans('Allows the staff member to update company legal as set under the system module.'), ], + 'update_params' => [ + 'type' => 'bool', + 'display_name' => __trans('Update system parameters'), + 'description' => __trans('Allows the staff member to update system parameters through the system API endpoint.'), + ], 'invalidate_cache' => [ 'type' => 'bool', 'display_name' => __trans('Invalidate cache'), @@ -66,6 +71,16 @@ class Service 'display_name' => __trans('Update FOSSBilling'), 'description' => __trans('Allows the staff member to update FOSSBilling.'), ], + 'recheck_update' => [ + 'type' => 'bool', + 'display_name' => __trans('Recheck for updates'), + 'description' => __trans('Allows the staff member to clear cached update information and fetch the latest update metadata.'), + ], + 'toggle_error_reporting' => [ + 'type' => 'bool', + 'display_name' => __trans('Toggle error reporting'), + 'description' => __trans('Allows the staff member to enable or disable error reporting for this FOSSBilling instance.'), + ], 'manage_network_interface' => [ 'type' => 'bool', 'display_name' => __trans('Manage the network interface'), diff --git a/src/modules/System/templates/admin/mod_system_settings.html.twig b/src/modules/System/templates/admin/mod_system_settings.html.twig index 088f842b9..d6f9cafb5 100644 --- a/src/modules/System/templates/admin/mod_system_settings.html.twig +++ b/src/modules/System/templates/admin/mod_system_settings.html.twig @@ -25,6 +25,10 @@ {% block content %} {% set new_params = admin.extension_config_get({ 'ext': 'mod_system' }) %} {% set params = admin.system_get_params %} + {% set can_update_params = has_permission('system', 'update_params') %} + {% set can_invalidate_cache = has_permission('system', 'invalidate_cache') %} + {% set can_toggle_error_reporting = has_permission('system', 'toggle_error_reporting') %} + {% set can_manage_network_interface = has_permission('system', 'manage_network_interface') %}
@@ -227,7 +231,7 @@ @@ -521,7 +525,7 @@ ZW=Zimbabwe

{{ 'Cache Control'|trans }}

- +
@@ -610,9 +614,13 @@ ZW=Zimbabwe
{{ 'This FOSSBilling instance is automatically sending error reports which helps us improve the software and keep it stable. Thanks!'|trans }}
-
- {{ 'Disable error reporting'|trans }} - + {% if can_toggle_error_reporting %} + + {{ 'Disable error reporting'|trans }} + + {% else %} + + {% endif %} {% else %} - - {{ 'Enable error reporting'|trans }} - + {% if can_toggle_error_reporting %} + + {{ 'Enable error reporting'|trans }} + + {% else %} + + {% endif %} {% endif %}

{{ "FOSSBilling optionally includes automated error reporting to help aid the project's development and stability. To find the most up-to-date information about it, you should review the links and information below."|trans }}

@@ -652,30 +664,35 @@ ZW=Zimbabwe + {% if can_manage_network_interface %} +
+

{{ 'If your server has multiple network interfaces, you may select the default one for FOSSBilling to use when making requests here.'|trans }}

- -

{{ 'If your server has multiple network interfaces, you may select the default one for FOSSBilling to use when making requests here.'|trans }}

- -
- - +
+ + +
+ +
+ +
+ + +
+ + {{ "If the dropdown menu doesn't have the appropriate network interface, please enter the IP address or name (e.g., eth0) of the correct one above."|trans }} + +
+ + + + {% else %} + - -
- -
- - -
- - {{ "If the dropdown menu doesn't have the appropriate network interface, please enter the IP address or name (e.g., eth0) of the correct one above."|trans }} - -
- - - + {% endif %}
@@ -686,6 +703,7 @@ ZW=Zimbabwe {% block js %}