new: Decoupled Cerebrate settings from application settings
And included an example of setting providerpull/70/head
parent
fcde68be3f
commit
14c70a092f
|
@ -89,9 +89,4 @@ return [
|
||||||
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
|
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Cerebrate' => [
|
|
||||||
'open' => [],
|
|
||||||
'dark' => 0,
|
|
||||||
'baseurl' => ''
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -87,6 +87,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'Cerebrate' => [
|
||||||
|
'open' => [],
|
||||||
|
'app.baseurl' => 'http://localhost:8000/',
|
||||||
|
'app.uuid' => 'cc9b9358-7c4b-4464-9a2c-f0cb089ff974',
|
||||||
|
'ui.dark' => 0,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
|
@ -124,7 +124,7 @@ class AppController extends Controller
|
||||||
$this->set('menu', $this->ACL->getMenu());
|
$this->set('menu', $this->ACL->getMenu());
|
||||||
$this->set('ajax', $this->request->is('ajax'));
|
$this->set('ajax', $this->request->is('ajax'));
|
||||||
$this->request->getParam('prefix');
|
$this->request->getParam('prefix');
|
||||||
$this->set('darkMode', !empty(Configure::read('Cerebrate.dark')));
|
$this->set('darkMode', !empty(Configure::read('Cerebrate')['ui.dark']));
|
||||||
$this->set('baseurl', Configure::read('App.fullBaseUrl'));
|
$this->set('baseurl', Configure::read('App.fullBaseUrl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,23 @@ class SettingsProviderTable extends AppTable
|
||||||
* Supports up to 3 levels:
|
* Supports up to 3 levels:
|
||||||
* Application -> Network -> Proxy -> Proxy.URL
|
* Application -> Network -> Proxy -> Proxy.URL
|
||||||
* page -> [group] -> [panel] -> setting
|
* page -> [group] -> [panel] -> setting
|
||||||
*
|
* Keys of setting configuration are the actual setting name.
|
||||||
* - Leave errorMessage empty to let the validator generate the error message
|
* Accepted setting configuration:
|
||||||
* - Default severity level is `info` if a `default` value is provided otherwise it becomes `critical`
|
* name [required]: The human readable name of the setting.
|
||||||
|
* type [required]: The type of the setting.
|
||||||
|
* description [required]: A description of the setting.
|
||||||
|
* Default severity level is `info` if a `default` value is provided otherwise it becomes `critical`
|
||||||
|
* default [optional]: The default value of the setting if not specified in the configuration.
|
||||||
|
* options [optional]: Used to populate the select with options. Keys are values to be saved, values are human readable version of the value.
|
||||||
|
* Required paramter if `type` == `select`.
|
||||||
|
* severity [optional]: Severity level of the setting if the configuration is incorrect.
|
||||||
|
* dependsOn [optional]: If the validation of this setting depends on the validation of the provided setting name
|
||||||
|
* test [optional]: Could be either a string or an anonymous function to be called in order to warn user if setting is invalid.
|
||||||
|
* Could be either: `string`, `boolean`, `integer`, `select`
|
||||||
|
* beforeSave [optional]: Could be either a string or an anonymous function to be called in order to block a setting to be saved.
|
||||||
|
* afterSave [optional]: Could be either a string or an anonymous function to be called allowing to execute a function after the setting is saved.
|
||||||
|
* redacted [optional]: Should the setting value be redacted. FIXME: To implement
|
||||||
|
* cli_only [optional]: Should this setting be modified only via the CLI.
|
||||||
*/
|
*/
|
||||||
private function generateSettingsConfiguration()
|
private function generateSettingsConfiguration()
|
||||||
{
|
{
|
||||||
|
@ -38,41 +52,23 @@ class SettingsProviderTable extends AppTable
|
||||||
'General' => [
|
'General' => [
|
||||||
'Essentials' => [
|
'Essentials' => [
|
||||||
'app.baseurl' => [
|
'app.baseurl' => [
|
||||||
'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.'),
|
|
||||||
'severity' => 'critical',
|
|
||||||
'default' => '',
|
|
||||||
'name' => __('Base URL'),
|
'name' => __('Base URL'),
|
||||||
'test' => 'testBaseURL',
|
|
||||||
'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.'),
|
||||||
|
'default' => '',
|
||||||
|
'severity' => 'critical',
|
||||||
|
'test' => 'testBaseURL',
|
||||||
],
|
],
|
||||||
'app.uuid' => [
|
'app.uuid' => [
|
||||||
|
'name' => 'UUID',
|
||||||
|
'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.'),
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'name' => 'UUID',
|
|
||||||
'severity' => 'critical',
|
'severity' => 'critical',
|
||||||
'test' => 'testUuid',
|
'test' => 'testUuid',
|
||||||
'type' => 'string'
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Miscellaneous' => [
|
'Miscellaneous' => [
|
||||||
'to-del' => [
|
|
||||||
'description' => 'to del',
|
|
||||||
'errorMessage' => 'to del',
|
|
||||||
'default' => 'A-default-value',
|
|
||||||
'name' => 'To DEL',
|
|
||||||
'test' => function($value) {
|
|
||||||
return empty($value) ? __('Oh not! it\'s not valid!') : true;
|
|
||||||
},
|
|
||||||
'beforeSave' => function($value, $setting) {
|
|
||||||
if ($value != 'foo') {
|
|
||||||
return 'value must be `foo`!';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
'afterSave' => function($value, $setting) {
|
|
||||||
},
|
|
||||||
'type' => 'string'
|
|
||||||
],
|
|
||||||
'sc2.hero' => [
|
'sc2.hero' => [
|
||||||
'description' => 'The true hero',
|
'description' => 'The true hero',
|
||||||
'default' => 'Sarah Kerrigan',
|
'default' => 'Sarah Kerrigan',
|
||||||
|
@ -85,10 +81,10 @@ class SettingsProviderTable extends AppTable
|
||||||
],
|
],
|
||||||
'type' => 'select'
|
'type' => 'select'
|
||||||
],
|
],
|
||||||
'sc2.antagonist' => [
|
'sc2.antagonists' => [
|
||||||
'description' => 'The real bad guy',
|
'description' => 'The bad guys',
|
||||||
'default' => 'Amon',
|
'default' => 'Amon',
|
||||||
'name' => 'Antagonist',
|
'name' => 'Antagonists',
|
||||||
'options' => function($settingsProviders) {
|
'options' => function($settingsProviders) {
|
||||||
return [
|
return [
|
||||||
'Amon' => 'Amon',
|
'Amon' => 'Amon',
|
||||||
|
@ -97,7 +93,7 @@ class SettingsProviderTable extends AppTable
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
'severity' => 'warning',
|
'severity' => 'warning',
|
||||||
'type' => 'select'
|
'type' => 'multi-select'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'floating-setting' => [
|
'floating-setting' => [
|
||||||
|
@ -113,43 +109,43 @@ class SettingsProviderTable extends AppTable
|
||||||
'Network' => [
|
'Network' => [
|
||||||
'Proxy' => [
|
'Proxy' => [
|
||||||
'proxy.host' => [
|
'proxy.host' => [
|
||||||
'description' => __('The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.'),
|
|
||||||
'name' => __('Host'),
|
'name' => __('Host'),
|
||||||
'test' => 'testHostname',
|
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
|
'description' => __('The hostname of an HTTP proxy for outgoing sync requests. Leave empty to not use a proxy.'),
|
||||||
|
'test' => 'testHostname',
|
||||||
],
|
],
|
||||||
'proxy.port' => [
|
'proxy.port' => [
|
||||||
'description' => __('The TCP port for the HTTP proxy.'),
|
|
||||||
'name' => __('Port'),
|
'name' => __('Port'),
|
||||||
'test' => 'testForRangeXY',
|
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
|
'description' => __('The TCP port for the HTTP proxy.'),
|
||||||
|
'test' => 'testForRangeXY',
|
||||||
],
|
],
|
||||||
'proxy.user' => [
|
'proxy.user' => [
|
||||||
|
'name' => __('User'),
|
||||||
|
'type' => 'string',
|
||||||
'description' => __('The authentication username for the HTTP proxy.'),
|
'description' => __('The authentication username for the HTTP proxy.'),
|
||||||
'default' => 'admin',
|
'default' => 'admin',
|
||||||
'name' => __('User'),
|
|
||||||
'dependsOn' => 'proxy.host',
|
'dependsOn' => 'proxy.host',
|
||||||
'type' => 'string',
|
|
||||||
],
|
],
|
||||||
'proxy.password' => [
|
'proxy.password' => [
|
||||||
|
'name' => __('Password'),
|
||||||
|
'type' => 'string',
|
||||||
'description' => __('The authentication password for the HTTP proxy.'),
|
'description' => __('The authentication password for the HTTP proxy.'),
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'name' => __('Password'),
|
|
||||||
'dependsOn' => 'proxy.host',
|
'dependsOn' => 'proxy.host',
|
||||||
'type' => 'string',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'UI' => [
|
'UI' => [
|
||||||
'General' => [
|
'General' => [
|
||||||
'app.ui.dark' => [
|
'ui.dark' => [
|
||||||
|
'name' => __('Dark theme'),
|
||||||
|
'type' => 'boolean',
|
||||||
'description' => __('Enable the dark theme of the application'),
|
'description' => __('Enable the dark theme of the application'),
|
||||||
'default' => false,
|
'default' => false,
|
||||||
'name' => __('Dark theme'),
|
|
||||||
'test' => function() {
|
'test' => function() {
|
||||||
return 'Fake error';
|
return 'Fake error';
|
||||||
},
|
},
|
||||||
'type' => 'boolean',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -157,20 +153,20 @@ class SettingsProviderTable extends AppTable
|
||||||
'Security' => [
|
'Security' => [
|
||||||
'Development' => [
|
'Development' => [
|
||||||
'Debugging' => [
|
'Debugging' => [
|
||||||
'app.security.debug' => [
|
'security.debug' => [
|
||||||
|
'name' => __('Debug Level'),
|
||||||
|
'type' => 'select',
|
||||||
'description' => __('The debug level of the instance'),
|
'description' => __('The debug level of the instance'),
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
'name' => __('Debug Level'),
|
|
||||||
'test' => function($value, $setting, $validator) {
|
|
||||||
$validator->range('value', [0, 3]);
|
|
||||||
return testValidator($value, $validator);
|
|
||||||
},
|
|
||||||
'type' => 'select',
|
|
||||||
'options' => [
|
'options' => [
|
||||||
0 => __('Debug Off'),
|
0 => __('Debug Off'),
|
||||||
1 => __('Debug On'),
|
1 => __('Debug On'),
|
||||||
2 => __('Debug On + SQL Dump'),
|
2 => __('Debug On + SQL Dump'),
|
||||||
]
|
],
|
||||||
|
'test' => function($value, $setting, $validator) {
|
||||||
|
$validator->range('value', [0, 3]);
|
||||||
|
return testValidator($value, $validator);
|
||||||
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue