]> git.mxchange.org Git - friendica.git/commitdiff
Disable setting fields in case we use environment variables
authorPhilipp <admin@philipp.info>
Sat, 25 Mar 2023 18:02:47 +0000 (19:02 +0100)
committerPhilipp <admin@philipp.info>
Mon, 27 Mar 2023 17:36:13 +0000 (19:36 +0200)
src/Core/Config/Capability/IManageConfigValues.php
src/Core/Config/Model/DatabaseConfig.php
src/Core/Config/Model/ReadOnlyFileConfig.php
src/Core/Config/ValueObject/Cache.php
src/Module/Admin/Logs/Settings.php
src/Module/Admin/Site.php
src/Module/Admin/Storage.php
view/templates/admin/storage.tpl
view/templates/field_select.tpl
view/theme/frio/templates/admin/storage.tpl
view/theme/frio/templates/field_select.tpl

index 4f785d0077e8ba00ca1574f3f07f3d48f8a684c4..93e0143b0a7da7ef99977ef8e4db18efa8eb26b7 100644 (file)
@@ -58,6 +58,16 @@ interface IManageConfigValues
         */
        public function get(string $cat, string $key = null, $default_value = null);
 
+       /**
+        * Returns true, if the current config cannot be changed
+        *
+        * @param string $cat The category of the configuration value
+        * @param string $key The configuration key to query
+        *
+        * @return bool true, if set is disabled
+        */
+       public function isSetDisabled(string $cat, string $key): bool;
+
        /**
         * Sets a configuration value for system config
         *
index 7167ccbf8e686bee2bddcef327b83ad8543462ea..058c90359944c313cda98f73b8c2577ef98e3d68 100644 (file)
@@ -80,6 +80,12 @@ class DatabaseConfig implements IManageConfigValues
                return $this->cache->get($cat, $key) ?? $default_value;
        }
 
+       /** {@inheritDoc} */
+       public function isSetDisabled(string $cat, string $key): bool
+       {
+               return $this->cache->getSource($cat, $key) >= Cache::SOURCE_ENV;
+       }
+
        /** {@inheritDoc} */
        public function set(string $cat, string $key, $value): bool
        {
index 4b32720f02c720c72d32c85175b81d36321cd943..f0a25fcf401361650cd14a514842acdc3c965e30 100644 (file)
@@ -68,6 +68,12 @@ class ReadOnlyFileConfig implements IManageConfigValues
                return $this->configCache->get($cat, $key) ?? $default_value;
        }
 
+       /** {@inheritDoc} */
+       public function isSetDisabled(string $cat, string $key): bool
+       {
+               return $this->configCache->getSource($cat, $key) >= Cache::SOURCE_ENV;
+       }
+
        /** {@inheritDoc} */
        public function set(string $cat, string $key, $value): bool
        {
index acfac3ab9a99138f36a8210c948145a224d6ba9d..f80be180494f2d5bac74592f6970baefb40b189e 100644 (file)
@@ -31,6 +31,15 @@ use ParagonIE\HiddenString\HiddenString;
  */
 class Cache
 {
+       /** @var int[] A list of valid config source  */
+       const VALID_SOURCES = [
+               self::SOURCE_STATIC,
+               self::SOURCE_FILE,
+               self::SOURCE_DATA,
+               self::SOURCE_ENV,
+               self::SOURCE_FIX,
+       ];
+
        /** @var int Indicates that the cache entry is a default value - Lowest Priority */
        const SOURCE_STATIC = 0;
        /** @var int Indicates that the cache entry is set by file - Low Priority */
index 91b29387109ece7cf4613e84f1f405c98b711adc..1fbd4ce8433bcc5013c8b4548b436b761e71fff1 100644 (file)
@@ -48,9 +48,15 @@ class Settings extends BaseAdmin
                        return;
                }
 
-               DI::config()->set('system', 'logfile', $logfile);
-               DI::config()->set('system', 'debugging', $debugging);
-               DI::config()->set('system', 'loglevel', $loglevel);
+               if (!DI::config()->isSetDisabled('system', 'logfile')) {
+                       DI::config()->set('system', 'logfile', $logfile);
+               }
+               if (!DI::config()->isSetDisabled('system', 'debugging')) {
+                       DI::config()->set('system', 'debugging', $debugging);
+               }
+               if (!DI::config()->isSetDisabled('system', 'loglevel')) {
+                       DI::config()->set('system', 'loglevel', $loglevel);
+               }
 
                DI::baseUrl()->redirect('admin/logs');
        }
@@ -82,9 +88,9 @@ class Settings extends BaseAdmin
                        '$clear' => DI::l10n()->t('Clear'),
                        '$logname' => DI::config()->get('system', 'logfile'),
                        // see /help/smarty3-templates#1_1 on any Friendica node
-                       '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
-                       '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory.")],
-                       '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
+                       '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), "", DI::config()->isSetDisabled('system', 'debugging') ? 'disabled' : ''],
+                       '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory."), "", DI::config()->isSetDisabled('system', 'logfile') ? 'disabled' : ''],
+                       '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices, DI::config()->isSetDisabled('system', 'loglevel') ? 'disabled' : ''],
                        '$form_security_token' => self::getFormSecurityToken("admin_logs"),
                        '$phpheader' => DI::l10n()->t("PHP logging"),
                        '$phphint' => DI::l10n()->t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
index c867c04c976417ac723029bbc346c0069aa0c099..98e5070580bcd66c79c873f6f9b906f23f91bcd6 100644 (file)
@@ -165,7 +165,9 @@ class Site extends BaseAdmin
                $transactionConfig->set('system', 'poco_discovery'        , $poco_discovery);
                $transactionConfig->set('system', 'poco_local_search'     , $poco_local_search);
                $transactionConfig->set('system', 'nodeinfo'              , $nodeinfo);
-               $transactionConfig->set('config', 'sitename'              , $sitename);
+               if (!DI::config()->isSetDisabled('config', 'sitename')) {
+                       $transactionConfig->set('config', 'sitename'          , $sitename);
+               }
                $transactionConfig->set('config', 'sender_email'          , $sender_email);
                $transactionConfig->set('system', 'suppress_tags'         , $suppress_tags);
                $transactionConfig->set('system', 'shortcut_icon'         , $shortcut_icon);
@@ -188,7 +190,9 @@ class Site extends BaseAdmin
                } else {
                        $transactionConfig->set('config', 'info', $additional_info);
                }
-               $transactionConfig->set('system', 'language', $language);
+               if (!DI::config()->isSetDisabled('system', 'language')) {
+                       $transactionConfig->set('system', 'language', $language);
+               }
                $transactionConfig->set('system', 'theme', $theme);
                Theme::install($theme);
 
@@ -413,7 +417,7 @@ class Site extends BaseAdmin
                        '$relocate_cmd'      => DI::l10n()->t('(Friendica directory)# bin/console relocate https://newdomain.com'),
 
                        // name, label, value, help string, extra data...
-                       '$sitename'         => ['sitename', DI::l10n()->t('Site name'), DI::config()->get('config', 'sitename'), ''],
+                       '$sitename'         => ['sitename', DI::l10n()->t('Site name'), DI::config()->get('config', 'sitename'), '', '', DI::config()->isSetDisabled('config', 'sitename') ? 'disabled' : ''],
                        '$sender_email'     => ['sender_email', DI::l10n()->t('Sender Email'), DI::config()->get('config', 'sender_email'), DI::l10n()->t('The email address your server shall use to send notification emails from.'), '', '', 'email'],
                        '$system_actor_name' => ['system_actor_name', DI::l10n()->t('Name of the system actor'), User::getActorName(), DI::l10n()->t("Name of the internal system account that is used to perform ActivityPub requests. This must be an unused username. If set, this can't be changed again.")],
                        '$banner'           => ['banner', DI::l10n()->t('Banner/Logo'), $banner, ''],
@@ -421,7 +425,7 @@ class Site extends BaseAdmin
                        '$shortcut_icon'    => ['shortcut_icon', DI::l10n()->t('Shortcut icon'), DI::config()->get('system', 'shortcut_icon'), DI::l10n()->t('Link to an icon that will be used for browsers.')],
                        '$touch_icon'       => ['touch_icon', DI::l10n()->t('Touch icon'), DI::config()->get('system', 'touch_icon'), DI::l10n()->t('Link to an icon that will be used for tablets and mobiles.')],
                        '$additional_info'  => ['additional_info', DI::l10n()->t('Additional Info'), $additional_info, DI::l10n()->t('For public servers: you can add additional information here that will be listed at %s/servers.', Search::getGlobalDirectory())],
-                       '$language'         => ['language', DI::l10n()->t('System language'), DI::config()->get('system', 'language'), '', $lang_choices],
+                       '$language'         => ['language', DI::l10n()->t('System language'), DI::config()->get('system', 'language'), '', $lang_choices, DI::config()->isSetDisabled('system', 'language') ? 'disabled' : ''],
                        '$theme'            => ['theme', DI::l10n()->t('System theme'), DI::config()->get('system', 'theme'), DI::l10n()->t('Default system theme - may be over-ridden by user profiles - <a href="%s" id="cnftheme">Change default theme settings</a>', DI::baseUrl() . '/admin/themes'), $theme_choices],
                        '$theme_mobile'     => ['theme_mobile', DI::l10n()->t('Mobile system theme'), DI::config()->get('system', 'mobile-theme', '---'), DI::l10n()->t('Theme for mobile devices'), $theme_choices_mobile],
                        '$force_ssl'        => ['force_ssl', DI::l10n()->t('Force SSL'), DI::config()->get('system', 'force_ssl'), DI::l10n()->t('Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.')],
index e31d7db390c3f2831868b9bda676180ca92c8d5f..b3361b6c179b2499d3ad1dc4d5e59fe0c9d362a6 100644 (file)
@@ -76,7 +76,7 @@ class Storage extends BaseAdmin
                        }
                }
 
-               if (!empty($_POST['submit_save_set'])) {
+               if (!empty($_POST['submit_save_set']) && !DI::config()->isSetDisabled('storage', 'name') ) {
                        try {
                                $newstorage = DI::storageManager()->getWritableStorageByName($storagebackend);
 
@@ -129,6 +129,7 @@ class Storage extends BaseAdmin
                                'prefix' => $storage_form_prefix,
                                'form'   => $storage_form,
                                'active' => $current_storage_backend instanceof ICanWriteToStorage && $name === $current_storage_backend::getName(),
+                               'set_disabled' => DI::config()->isSetDisabled('storage', 'name'),
                        ];
                }
 
index b1918c5a8b11f7ff8c48decb955d8ed9290caabc..e4c33e1e285528a44de429deac0941307a97d430 100644 (file)
 
                {{if $storage.form}}
                <input type="submit" name="submit_save" value="{{$save}}"/>
-               {{if $storage.active}}
+        {{if ! $storage.set_disabled}}
+                               {{if $storage.active}}
                <input type="submit" name="submit_save_set" value="{{$save_reload}}"/>
-               {{else}}
+                               {{else}}
                <input type="submit" name="submit_save_set" value="{{$save_use}}"/>
+                               {{/if}}
                {{/if}}
-               {{else}}
+               {{elseif ! $storage.set_disabled}}
                <br /><input type="submit" name="submit_save_set" {{if $storage.active}}disabled="disabled"{{/if}} value="{{$use}}"/>
                {{/if}}
        </form>
index 16a796a444befe7ad668c93665c9071b4cf96a1f..9336ce3cc7e810c6d2b9252e203c9d98587a7c83 100644 (file)
@@ -1,7 +1,7 @@
 
        <div class="field select">
                <label for="id_{{$field.0}}">{{$field.1}}</label>
-               <select name="{{$field.0}}" id="id_{{$field.0}}" aria-describedby="{{$field.0}}_tip">
+               <select name="{{$field.0}}" id="id_{{$field.0}}" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
        {{foreach $field.4 as $opt=>$val}}
                        <option value="{{$opt}}" dir="auto"{{if $opt==$field.2}} selected="selected"{{/if}}>{{$val}}</option>
        {{/foreach}}
index 1a63d1817fdc64d24e8b74996d2bd8be20369934..e2d1bbf895bc883f81ac227e46618fdb0869f300 100644 (file)
                                <div class="panel-footer">
                                        {{if $storage.form}}
                                        <input type="submit" name="submit_save" class="btn btn-primary" value="{{$save}}"/>
-                                               {{if $storage.active}}
+                           {{if ! $storage.set_disabled}}
+                                                       {{if $storage.active}}
                                        <input type="submit" name="submit_save_set" class="btn btn-primary" value="{{$save_reload}}"/>
-                                               {{else}}
+                                                       {{else}}
                                        <input type="submit" name="submit_save_set" class="btn btn-primary" value="{{$save_use}}"/>
+                                                       {{/if}}
                                                {{/if}}
-                                       {{else}}
+                                       {{elseif ! $storage.set_disabled }}
                                        <input type="submit" name="submit_save_set" class="btn btn-primary" {{if $storage.active}}disabled="disabled"{{/if}} value="{{$use}}"/>
                                        {{/if}}
                                </div>
index 25cfd652cd22970aa223e35c2237586c001df919..d5bcfdad617c6c04b5cddc5288aa19389f583444 100644 (file)
@@ -1,7 +1,7 @@
 
        <div class="form-group field select">
                <label for="id_{{$field.0}}">{{$field.1}}</label>
-               <select name="{{$field.0}}" id="id_{{$field.0}}" class="form-control" aria-describedby="{{$field.0}}_tip">
+               <select name="{{$field.0}}" id="id_{{$field.0}}" class="form-control" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
        {{foreach $field.4 as $opt=>$val}}
                        <option value="{{$opt}}" {{if $opt==$field.2}}selected="selected"{{/if}}>{{$val}}</option>
        {{/foreach}}