diff --git a/api/ApplicationContext.php b/api/ApplicationContext.php index 1de7ca80..9e6cacda 100644 --- a/api/ApplicationContext.php +++ b/api/ApplicationContext.php @@ -13,6 +13,7 @@ use BusinessLogic\Security\BanRetriever; use BusinessLogic\Security\UserContextBuilder; use BusinessLogic\Security\UserToTicketChecker; use BusinessLogic\Settings\ApiChecker; +use BusinessLogic\Settings\SettingsRetriever; use BusinessLogic\Statuses\StatusRetriever; use BusinessLogic\Tickets\Autoassigner; use BusinessLogic\Tickets\TicketDeleter; @@ -124,5 +125,8 @@ class ApplicationContext { // Statuses $this->get[StatusRetriever::class] = new StatusRetriever($this->get[StatusGateway::class]); + + // Settings + $this->get[SettingsRetriever::class] = new SettingsRetriever($this->get[ModsForHeskSettingsGateway::class]); } } \ No newline at end of file diff --git a/api/BusinessLogic/Settings/SettingsRetriever.php b/api/BusinessLogic/Settings/SettingsRetriever.php index 9e81aa4a..e8db0e48 100644 --- a/api/BusinessLogic/Settings/SettingsRetriever.php +++ b/api/BusinessLogic/Settings/SettingsRetriever.php @@ -3,20 +3,84 @@ namespace BusinessLogic\Settings; // TODO Test! +use DataAccess\Settings\ModsForHeskSettingsGateway; + class SettingsRetriever { + /* @var $modsForHeskSettingsGateway ModsForHeskSettingsGateway */ + private $modsForHeskSettingsGateway; + + function __construct($modsForHeskSettingsGateway) { + $this->modsForHeskSettingsGateway = $modsForHeskSettingsGateway; + } private static $settingsToNotReturn = array( 'webmaster_email', 'noreply_email', 'noreply_name', 'db_.*', + 'admin_dir', + 'attach_dir', + 'cache_dir', + 'autoclose', + 'autologin', + 'autoassign', + 'secimg_.*', + 'recaptcha_.*', + 'question_.*', + 'attempt_.*', + 'reset_pass', + 'x_frame_opt', + 'force_ssl', + 'imap.*', + 'smtp.*', + 'email_piping', + 'pop3.*', + 'loop.*', + 'email_providers', + 'notify_.*', + 'alink', + 'submit_notice', + 'online', + 'online_min', + 'modsForHeskVersion', + 'use_mailgun', + 'mailgun.*', + 'kb_attach_dir', + 'public_api', + 'custom_fields', + 'hesk_version', + 'hesk_license', ); /** * @param $heskSettings array - * @param $modsForHeskSettings array + * @return array */ - function getAllSettings($heskSettings, $modsForHeskSettings) { + function getAllSettings($heskSettings) { + $modsForHeskSettings = $this->modsForHeskSettingsGateway->getAllSettings($heskSettings); + $settingsToReturn = array(); + + foreach ($heskSettings as $key => $value) { + if ($this->isPermittedKey($key)) { + $settingsToReturn[$key] = $value; + } + } + foreach ($modsForHeskSettings as $key => $value) { + if ($this->isPermittedKey($key)) { + $settingsToReturn[$key] = $value; + } + } + + return $settingsToReturn; + } + + private function isPermittedKey($key) { + foreach (self::$settingsToNotReturn as $setting) { + if (preg_match("/{$setting}/", $key)) { + return false; + } + } + return true; } } \ No newline at end of file diff --git a/api/Controllers/Settings/SettingsController.php b/api/Controllers/Settings/SettingsController.php new file mode 100644 index 00000000..c8e53941 --- /dev/null +++ b/api/Controllers/Settings/SettingsController.php @@ -0,0 +1,17 @@ +get[SettingsRetriever::class]; + + output($settingsRetriever->getAllSettings($hesk_settings, $modsForHesk_settings)); + } +} \ No newline at end of file diff --git a/api/index.php b/api/index.php index a4d69986..991160c5 100644 --- a/api/index.php +++ b/api/index.php @@ -159,6 +159,8 @@ Link::all(array( '/v1/staff/tickets/{i}/attachments/{i}' => \Controllers\Attachments\StaffTicketAttachmentsController::class, // Statuses '/v1/statuses' => \Controllers\Statuses\StatusController::class, + // Settings + '/v1/settings' => \Controllers\Settings\SettingsController::class, // Any URL that doesn't match goes to the 404 handler '404' => 'handle404'