Merge remote-tracking branch 'origin/develop' into develop

pull/79/head
Sami Mokaddem 2021-10-21 11:13:05 +02:00
commit cf2500286a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 72 additions and 20 deletions

View File

@ -87,7 +87,12 @@ try {
*/ */
if (file_exists(CONFIG . 'app_local.php')) { if (file_exists(CONFIG . 'app_local.php')) {
Configure::load('app_local', 'default'); Configure::load('app_local', 'default');
Configure::load('cerebrate', 'default', true); //Configure::load('cerebrate', 'default', true);
$settings = file_get_contents(CONFIG . 'config.json');
$settings = json_decode($settings, true);
foreach ($settings as $path => $setting) {
Configure::write($path, $setting);
}
} }
/* /*

View File

@ -132,11 +132,10 @@ class AppController extends Controller
$this->set('ajax', $this->request->is('ajax')); $this->set('ajax', $this->request->is('ajax'));
$this->request->getParam('prefix'); $this->request->getParam('prefix');
$this->set('baseurl', Configure::read('App.fullBaseUrl')); $this->set('baseurl', Configure::read('App.fullBaseUrl'));
if (!empty($user) && !empty($user->user_settings_by_name['ui.bsTheme']['value'])) {
if (!empty($user) && !empty($user->user_settings_by_name_with_fallback['ui.bsTheme']['value'])) { $this->set('bsTheme', $user->user_settings_by_name['ui.bsTheme']['value']);
$this->set('bsTheme', $user->user_settings_by_name_with_fallback['ui.bsTheme']['value']);
} else { } else {
$this->set('bsTheme', Configure::read('Cerebrate')['ui.bsTheme']); $this->set('bsTheme', Configure::read('ui.bsTheme'));
} }
if ($this->modelClass == 'Tags.Tags') { if ($this->modelClass == 'Tags.Tags') {

View File

@ -18,6 +18,24 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
parent::__construct(); parent::__construct();
} }
public function retrieveSettingPathsBasedOnBlueprint(): array
{
$blueprint = $this->generateSettingsConfiguration();
$paths = [];
foreach ($blueprint as $l1) {
foreach ($l1 as $l2) {
foreach ($l2 as $l3) {
foreach ($l3 as $k => $v) {
if ($k[0] !== '_') {
$paths[] = $k;
}
}
}
}
}
return $paths;
}
protected function generateSettingsConfiguration() protected function generateSettingsConfiguration()
{ {
return [ return [
@ -26,7 +44,7 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
'Essentials' => [ 'Essentials' => [
'_description' => __('Ensentials settings required for the application to run normally.'), '_description' => __('Ensentials settings required for the application to run normally.'),
'_icon' => 'user-cog', '_icon' => 'user-cog',
'app.baseurl' => [ 'App.baseurl' => [
'name' => __('Base URL'), 'name' => __('Base URL'),
'type' => 'string', 'type' => 'string',
'description' => __('The base url of the application (in the format https://www.mymispinstance.com or https://myserver.com/misp). Several features depend on this setting being correctly set to function.'), 'description' => __('The base url of the application (in the format https://www.mymispinstance.com or https://myserver.com/misp). Several features depend on this setting being correctly set to function.'),
@ -34,7 +52,7 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
'severity' => 'critical', 'severity' => 'critical',
'test' => 'testBaseURL', 'test' => 'testBaseURL',
], ],
'app.uuid' => [ 'App.uuid' => [
'name' => 'UUID', 'name' => 'UUID',
'type' => 'string', 'type' => 'string',
'description' => __('The Cerebrate instance UUID. This UUID is used to identify this instance.'), 'description' => __('The Cerebrate instance UUID. This UUID is used to identify this instance.'),
@ -85,26 +103,26 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
], ],
'Network' => [ 'Network' => [
'Proxy' => [ 'Proxy' => [
'proxy.host' => [ 'Proxy.host' => [
'name' => __('Host'), 'name' => __('Host'),
'type' => 'string', 'type' => 'string',
'description' => __('The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.'), 'description' => __('The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.'),
'test' => 'testHostname', 'test' => 'testHostname',
], ],
'proxy.port' => [ 'Proxy.port' => [
'name' => __('Port'), 'name' => __('Port'),
'type' => 'integer', 'type' => 'integer',
'description' => __('The TCP port for the HTTP proxy.'), 'description' => __('The TCP port for the HTTP proxy.'),
'test' => 'testForRangeXY', 'test' => 'testForRangeXY',
], ],
'proxy.user' => [ 'Proxy.user' => [
'name' => __('User'), 'name' => __('User'),
'type' => 'string', 'type' => 'string',
'description' => __('The authentication username for the HTTP proxy.'), 'description' => __('The authentication username for the HTTP proxy.'),
'default' => 'admin', 'default' => 'admin',
'dependsOn' => 'proxy.host', 'dependsOn' => 'proxy.host',
], ],
'proxy.password' => [ 'Proxy.password' => [
'name' => __('Password'), 'name' => __('Password'),
'type' => 'string', 'type' => 'string',
'description' => __('The authentication password for the HTTP proxy.'), 'description' => __('The authentication password for the HTTP proxy.'),
@ -181,11 +199,16 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
'dependsOn' => 'keycloak.enabled' 'dependsOn' => 'keycloak.enabled'
], ],
'keycloak.default_role_name' => [ 'keycloak.default_role_name' => [
'name' => 'Authoritative', 'name' => 'Default role',
'type' => 'boolean', 'type' => 'select',
'severity' => 'info', 'severity' => 'info',
'description' => __('Override local role and organisation settings based on the settings in KeyCloak'), 'description' => __('Select the default role name to be used when creating users'),
'default' => false, 'options' => function ($settingsProviders) {
$roleTable = TableRegistry::getTableLocator()->get('Roles');
$allRoleNames = $roleTable->find()->toArray();
$allRoleNames = array_column($allRoleNames, 'name');
return array_combine($allRoleNames, $allRoleNames);
},
'dependsOn' => 'keycloak.enabled' 'dependsOn' => 'keycloak.enabled'
], ],
'keycloak.mapping.org_uuid' => [ 'keycloak.mapping.org_uuid' => [
@ -252,7 +275,7 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
], ],
'Development' => [ 'Development' => [
'Debugging' => [ 'Debugging' => [
'security.debug' => [ 'debug' => [
'name' => __('Debug Level'), 'name' => __('Debug Level'),
'type' => 'select', 'type' => 'select',
'description' => __('The debug level of the instance'), 'description' => __('The debug level of the instance'),

View File

@ -4,6 +4,7 @@ namespace App\Model\Table;
use App\Model\Table\AppTable; use App\Model\Table\AppTable;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Error\Debugger;
require_once(APP . 'Model' . DS . 'Table' . DS . 'SettingProviders' . DS . 'CerebrateSettingsProvider.php'); require_once(APP . 'Model' . DS . 'Table' . DS . 'SettingProviders' . DS . 'CerebrateSettingsProvider.php');
use App\Settings\SettingsProvider\CerebrateSettingsProvider; use App\Settings\SettingsProvider\CerebrateSettingsProvider;
@ -12,7 +13,14 @@ class SettingsTable extends AppTable
{ {
private static $FILENAME = 'cerebrate'; private static $FILENAME = 'cerebrate';
private static $CONFIG_KEY = 'Cerebrate'; private static $CONFIG_KEY = 'Cerebrate';
private static $DUMPABLE = [
'Cerebrate',
'proxy',
'ui',
'keycloak',
'app'
];
public function initialize(array $config): void public function initialize(array $config): void
{ {
parent::initialize($config); parent::initialize($config);
@ -96,15 +104,32 @@ class SettingsTable extends AppTable
private function readSettings() private function readSettings()
{ {
return Configure::read()[$this::$CONFIG_KEY]; $settingPaths = $this->SettingsProvider->retrieveSettingPathsBasedOnBlueprint();
$settings = [];
foreach ($settingPaths as $path) {
if (Configure::check($path)) {
$settings[$path] = Configure::read($path);
}
}
return $settings;
}
private function loadSettings(): void
{
$settings = file_get_contents(CONFIG . 'config.json');
$settings = json_decode($settings, true);
foreach ($settings as $path => $setting) {
Configure::write($path, $setting);
}
} }
private function saveSettingOnDisk($name, $value) private function saveSettingOnDisk($name, $value)
{ {
$settings = $this->readSettings(); $settings = $this->readSettings();
$settings[$name] = $value; $settings[$name] = $value;
Configure::write($this::$CONFIG_KEY, $settings); $settings = json_encode($settings, JSON_PRETTY_PRINT);
Configure::dump($this::$FILENAME, 'default', [$this::$CONFIG_KEY]); file_put_contents(CONFIG . 'config.json', $settings);
$this->loadSettings();
return true; return true;
} }
} }