From 6eb6cc94c7926fd3bc0b4dfac4616961e33a9505 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:07:31 -0500 Subject: [PATCH 1/7] Move config/dbstructure.php to config/dbstructure.config.php --- config/{dbstructure.php => dbstructure.config.php} | 0 src/Database/DBStructure.php | 12 ++++++------ tests/Util/VFSTrait.php | 2 +- update.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) rename config/{dbstructure.php => dbstructure.config.php} (100%) diff --git a/config/dbstructure.php b/config/dbstructure.config.php similarity index 100% rename from config/dbstructure.php rename to config/dbstructure.config.php diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index d4a1ee937..b5e444020 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -28,7 +28,7 @@ class DBStructure const UPDATE_FAILED = 2; // Database check failed /** - * Database structure definition loaded from config/dbstructure.php + * Database structure definition loaded from config/dbstructure.config.php * * @var array */ @@ -783,10 +783,10 @@ class DBStructure } /** - * Loads the database structure definition from the config/dbstructure.php file. + * Loads the database structure definition from the config/dbstructure.config.php file. * On first pass, defines DB_UPDATE_VERSION constant. * - * @see config/dbstructure.php + * @see config/dbstructure.config.php * @param boolean $with_addons_structure Whether to tack on addons additional tables * @return array * @throws Exception @@ -796,16 +796,16 @@ class DBStructure if (!self::$definition) { $a = \Friendica\BaseObject::getApp(); - $filename = $a->getBasePath() . '/config/dbstructure.php'; + $filename = $a->getBasePath() . '/config/dbstructure.config.php'; if (!is_readable($filename)) { - throw new Exception('Missing database structure config file config/dbstructure.php'); + throw new Exception('Missing database structure config file config/dbstructure.config.php'); } $definition = require $filename; if (!$definition) { - throw new Exception('Corrupted database structure config file config/dbstructure.php'); + throw new Exception('Corrupted database structure config file config/dbstructure.config.php'); } self::$definition = $definition; diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 972119134..1edc25d42 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -30,7 +30,7 @@ trait VFSTrait $this->setConfigFile('config.ini.php'); $this->setConfigFile('settings.ini.php'); $this->setConfigFile('local.ini.php'); - $this->setConfigFile('dbstructure.php'); + $this->setConfigFile('dbstructure.config.php'); } /** diff --git a/update.php b/update.php index 115f817d7..41b6fa96f 100644 --- a/update.php +++ b/update.php @@ -21,7 +21,7 @@ require_once 'include/dba.php'; * This function is responsible for doing post update changes to the data * (not the structure) in the database. * - * Database structure changes are done in config/dbstructure.php + * Database structure changes are done in config/dbstructure.config.php * * If there is a need for a post process to a structure change, update this file * by adding a new function at the end with the number of the new DB_UPDATE_VERSION. @@ -33,7 +33,7 @@ require_once 'include/dba.php'; * * 1. Create a function "update_4712()" here in the update.php * 2. Apply the needed structural changes in config/dbStructure.php - * 3. Set DB_UPDATE_VERSION in config/dbstructure.php to 4712. + * 3. Set DB_UPDATE_VERSION in config/dbstructure.config.php to 4712. * * If you need to run a script before the database update, name the function "pre_update_4712()" */ From d6eb1135e5b46ec2f7443b19c26c877f93f6b7c2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:42:05 -0500 Subject: [PATCH 2/7] Add support for PHP array config files - Add new base config files - Remove useless DIRECTORY_SEPARATOR instances --- .gitignore | 2 + config/addon-sample.config.php | 12 + config/defaults.config.php | 424 +++++++++++++++++++++++++++++++++ config/local-sample.config.php | 44 ++++ config/settings.config.php | 113 +++++++++ src/App.php | 124 ++++++---- 6 files changed, 676 insertions(+), 43 deletions(-) create mode 100644 config/addon-sample.config.php create mode 100644 config/defaults.config.php create mode 100644 config/local-sample.config.php create mode 100644 config/settings.config.php diff --git a/.gitignore b/.gitignore index db1c3c130..87ce354c1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ home.html robots.txt #ignore local config +/config/local.config.php +/config/addon.config.php /config/local.ini.php /config/addon.ini.php diff --git a/config/addon-sample.config.php b/config/addon-sample.config.php new file mode 100644 index 000000000..2c88073c7 --- /dev/null +++ b/config/addon-sample.config.php @@ -0,0 +1,12 @@ + [ + 'consumerkey' => 'localhost', + 'consumersecret' => 'mysqlusername', + ], +]; diff --git a/config/defaults.config.php b/config/defaults.config.php new file mode 100644 index 000000000..ec855abf6 --- /dev/null +++ b/config/defaults.config.php @@ -0,0 +1,424 @@ + [ + // host (String) + // Hostname or IP address of the database server. + // Can contain the port number with the syntax "hostname:port". + 'hostname' => '', + + // user (String) + // Database user name. Please don't use "root". + 'username' => '', + + // pass (String) + // Database user password. Please don't use empty passwords. + 'password' => '', + + // base (String) + // Database name. + 'database' => '', + + // charset (String) + // Database connexion charset. Changing this value will likely corrupt special characters. + 'charset' => 'utf8mb4', + ], + 'config' => [ + // admin_email (Comma-separated list) + // In order to perform system administration via the admin panel, + // this must precisely match the email address of the person logged in. + 'admin_email' => '', + + // admin_nickname (String) + // Nickname of the main admin user, used if there are more than one admin user defined in config => admin_email. + 'admin_nickname' => '', + + // max_import_size (Integer) + // Maximum body size of DFRN and Mail messages in characters. 0 is unlimited. + 'max_import_size' => 200000, + + // php_path (String) + // Location of PHP command line processor. + 'php_path' => 'php', + ], + 'system' => [ + // allowed_link_protocols (Array) + // Allowed protocols in links URLs, add at your own risk. http is always allowed. + 'allowed_link_protocols' => ['ftp', 'ftps', 'mailto', 'cid', 'gopher'], + + // always_show_preview (Boolean) + // Only show small preview pictures. + 'always_show_preview' => false, + + // archival_days (Integer) + // Number of days that we try to deliver content before we archive a contact. + 'archival_days' => 32, + + // auth_cookie_lifetime (Integer) + // Number of days that should pass without any activity before a user who + // chose "Remember me" when logging in is considered logged out. + 'auth_cookie_lifetime' => 7, + + // block_local_dir (Boolean) + // Deny public access to the local user directory. + 'block_local_dir' => false, + + // cache_driver (database|memcache|memcached|redis) + // Whether to use Memcache or Memcached or Redis to store temporary cache. + 'cache_driver' => 'database', + + // config_adapter (jit|preload) + // Allow to switch the configuration adapter to improve performances at the cost of memory consumption. + 'config_adapter' => 'jit', + + // curl_range_bytes (Integer) + // Maximum number of bytes that should be fetched. Default is 0, which mean "no limit". + 'curl_range_bytes' => 0, + + // crawl_permit_period (Integer) + // Period in seconds between allowed searches when the number of free searches is reached and "permit_crawling" is activated. + 'crawl_permit_period' => 60, + + // db_log (Path) + // Name of a logfile to log slow database queries. + 'db_log' => '', + + // db_log_index (Path) + // Name of a logfile to log queries with bad indexes. + 'db_log_index' => '', + + // db_log_index_watch (Comma-separated list) + // Watchlist of indexes to watch. + 'db_log_index_watch' => '', + + // db_log_index_blacklist (Comma-separated list) + // Blacklist of indexes that shouldn't be watched. + 'db_log_index_blacklist' => '', + + // db_loglimit (Integer) + // If a database call lasts longer than this value in seconds it is logged. + // Inactive if system => db_log is empty. + 'db_loglimit' => 10, + + // db_loglimit_index (Integer) + // Number of index rows needed to be logged for indexes on the watchlist. 0 to disable. + 'db_loglimit_index' => 0, + + // db_loglimit_index_high (Integer) + // Number of index rows to be logged anyway (for any index). 0 to disable. + 'db_loglimit_index_high' => 0, + + // dbclean_expire_conversation (Integer) + // When DBClean is enabled, any entry in the conversation table will be deleted after this many days. + // This data is used for ActivityPub, so it shouldn't be lower than the average duration of a discussion. + 'dbclean_expire_conversation' => 90, + + // dbclean-expire-limit (Integer) + // This defines the number of items that are to be deleted in a single call. + // Reduce this value when you are getting memory issues. + 'dbclean-expire-limit' => 1000, + + // diaspora_test (Boolean) + // For development only. Disables the message transfer. + 'diaspora_test' => false, + + // disable_email_validation (Boolean) + // Disables the check if a mail address is in a valid format and can be resolved via DNS. + 'disable_email_validation' => false, + + // disable_url_validation (Boolean) + // Disables the DNS lookup of an URL. + 'disable_url_validation' => false, + + // disable_password_exposed (Boolean) + // Disable the exposition check against the remote haveibeenpwned API on password change. + 'disable_password_exposed' => false, + + // disable_polling (Boolean) + // Disable the polling of DFRN and OStatus contacts through onepoll.php. + 'disable_polling' => false, + + // dlogfile (Path) + // location of the developer log file. + 'dlogfile' => '', + + // dlogip (String) + // restricts develop log writes to requests originating from this IP address. + 'dlogip' => '', + + // free_crawls (Integer) + // Number of "free" searches when system => permit_crawling is enabled. + 'free_crawls' => 10, + + // frontend_worker_timeout (Integer) + // Value in minutes after we think that a frontend task was killed by the webserver. + 'frontend_worker_timeout' => 10, + + // groupedit_image_limit (Integer) + // Number of contacts at which the group editor should switch from display the profile pictures of the contacts to only display the names. + // This can alternatively be set on a per account basis in the pconfig table. + 'groupedit_image_limit' => 400, + + // hsts (Boolean) + // Enables the sending of HTTP Strict Transport Security headers. + 'hsts' => false, + + // ignore_cache (Boolean) + // For development only. Disables the item cache. + 'ignore_cache' => false, + + // instances_social_key (String) + // Key to the API of https://instances.social which retrieves data about mastodon servers. + // See https://instances.social/api/token to get an API key. + 'instances_social_key' => '', + + // ipv4_resolve (Boolean) + // Resolve IPV4 addresses only. Don't resolve to IPV6. + 'ipv4_resolve' => false, + + // invitation_only (Boolean) + // If set true registration is only possible after a current member of the node has send an invitation. + 'invitation_only' => false, + + // like_no_comment (Boolean) + // Don't update the "commented" value of an item when it is liked. + 'like_no_comment' => false, + + // local_block (Boolean) + // Used in conjunction with "block_public". + 'local_block' => false, + + // local_search (Boolean) + // Blocks search for users who are not logged in to prevent crawlers from blocking your system. + 'local_search' => false, + + // local_tags (Boolean) + // If activated, all hashtags will point to the local server. + 'local_tags' => false, + + // max_batch_queue (Integer) + // Maximum number of batched queue items for a single contact before subsequent messages are discarded. + 'max_batch_queue' => 1000, + + // max_connections (Integer) + // The maximum number of database connections which can be in use before the worker process is deferred to its next interval. + // When the system can't detect the maximum numbers of connection then this value can be used. Use 0 for auto-detection. + 'max_connections' => 0, + + // max_connections_level (Integer 0-100) + // The maximum percentage of connections that are allowed to let the worker start. + 'max_connections_level' => 75, + + // max_contact_queue (Integer) + // Maximum number of queue items for a single contact before subsequent messages are discarded. + 'max_contact_queue' => 500, + + // max_image_length (Integer) + // An alternate way of limiting picture upload sizes. + // Specify the maximum pixel length that pictures are allowed to be (for non-square pictures, it will apply to the longest side). + // Pictures longer than this length will be resized to be this length (on the longest side, the other side will be scaled appropriately). + // If you don't want to set a maximum length, set to -1. + 'max_image_length' => -1, + + // max_processes_backend (Integer) + // Maximum number of concurrent database processes for background tasks. + 'max_processes_backend' => 5, + + // max_processes_frontend (Integer) + // Maximum number of concurrent database processes for foreground tasks. + 'max_processes_frontend' => 20, + + // maximagesize (Integer) + // Maximum size in bytes of an uploaded photo. + 'maximagesize' => 800000, + + // memcache_host (String) + // Host name of the memcache daemon. + 'memcache_host' => '127.0.0.1', + + // memcache_port (Integer) + // Port number of the memcache daemon. + 'memcache_port' => 11211, + + // memcached_hosts (Array) + // Array of Memcached servers info [host, port(, weight)], see Memcached::addServers. + 'memcached_hosts' => [ + ['127.0.0.1', '11211'], + ], + + // min_poll_interval (Integer) + // minimal distance in minutes between two polls for a contact. Reasonable values are between 1 and 59. + 'min_poll_interval' => 1, + + // no_count (Boolean) + // Don't do count calculations (currently only when showing photo albums). + 'no_count' => false, + + // no_oembed (Boolean) + // Don't use OEmbed to fetch more information about a link. + 'no_oembed' => false, + + // no_smilies (Boolean) + // Don't show smilies. + 'no_smilies' => false, + + // no_view_full_size (Boolean) + // Don't add the link "View full size" under a resized image. + 'no_view_full_size' => false, + + // optimize_items (Boolean) + // Triggers an SQL command to optimize the item table before expiring items. + 'optimize_items' => false, + + // paranoia (Boolean) + // Log out users if their IP address changed. + 'paranoia' => false, + + // permit_crawling (Boolean) + // Restricts the search for not logged in users to one search per minute. + 'permit_crawling' => false, + + // pidfile (Path) + // Daemon pid file path. For example: pidfile = /path/to/daemon.pid + 'pidfile' => '', + + // png_quality (Integer) + // Sets the ImageMagick compression level for PNG images. Values ranges from 0 (uncompressed) to 9 (most compressed). + 'png_quality' => 8, + + // profiler (Boolean) + // Enable internal timings to help optimize code. Needed for "rendertime" addon. + 'profiler' => false, + + // proxy_cache_time (Integer) + // Period in seconds after which the cache is cleared. + 'proxy_cache_time' => 86400, + + // pushpoll_frequency (Integer) + // Frequency of contact poll for subhub contact using the DFRM or OStatus network. + // Available values: + // - 5 = every month + // - 4 = every week + // - 3 = every day + // - 2 = twice a day + // - 1 = every hour + // - 0 = every minute + 'pushpoll_frequency' => 3, + + // queue_no_dead_check (Boolean) + // Ignore if the target contact or server seems to be dead during queue delivery. + 'queue_no_dead_check' => false, + + // redis_host (String) + // Host name of the redis daemon. + 'redis_host' => '127.0.0.1', + + // redis_port (String) + // Port number of the redis daemon. + 'redis_port' => 6379, + + // session_handler (database|cache|native) + // Whether to use Cache to store session data or to use PHP native session storage. + 'session_handler' => 'database', + + // remove_multiplicated_lines (Boolean) + // If enabled, multiple linefeeds in items are stripped to a single one. + 'remove_multiplicated_lines' => false, + + // sendmail_params (Boolean) + // Normal sendmail command parameters will be added when the PHP mail() function is called for sending e-mails. + // This ensures the Sender Email address setting is applied to the message envelope rather than the host's default address. + // Set to false if your non-sendmail agent is incompatible, or to restore old behavior of using the host address. + 'sendmail_params' => true, + + // show_global_community_hint (Boolean) + // When the global community page is enabled, use this option to display a hint above the stream, that this is a collection of all public top-level postings that arrive on your node. + 'show_global_community_hint' => false, + + // show_unsupported_addons (Boolean) + // Show all addons including the unsupported ones. + 'show_unsupported_addons' => false, + + // show_unsupported_themes (Boolean) + // Show all themes including the unsupported ones. + 'show_unsupported_themes' => false, + + // throttle_limit_day (Integer) + // Maximum number of posts that a user can send per day with the API. 0 to disable daily throttling. + 'throttle_limit_day' => 0, + + // throttle_limit_week (Integer) + // Maximum number of posts that a user can send per week with the API. 0 to disable weekly throttling. + 'throttle_limit_week' => 0, + + // throttle_limit_month (Integer) + // Maximum number of posts that a user can send per month with the API. 0 to disable monthly throttling. + 'throttle_limit_month' => 0, + + // urlpath (String) + // If you are using a subdirectory of your domain you will need to put the relative path (from the root of your domain) here. + // For instance if your URL is 'http://example.com/directory/subdirectory', set urlpath to 'directory/subdirectory'. + 'urlpath' => '', + + // username_min_length (Integer) + // The minimum character length a username can be. + // This length is check once the username has been trimmed and multiple spaces have been collapsed into one. + // Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars. + 'username_min_length' => 3, + + // username_max_length (Integer) + // The maximum character length a username can be. + // This length is check once the username has been trimmed and multiple spaces have been collapsed into one. + // Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars. + 'username_max_length' => 48, + + // worker_cooldown (Integer) + // Cooldown period in seconds after each worker function call. + 'worker_cooldown' => 0, + + // worker_debug (Boolean) + // If enabled, it prints out the number of running processes split by priority. + 'worker_debug' => false, + + // worker_fetch_limit (Integer) + // Number of worker tasks that are fetched in a single query. + 'worker_fetch_limit' => 1, + + // worker_load_exponent (Integer) + // Default 3, which allows only 25% of the maximum worker queues when server load reaches around 37% of maximum load. + // For a linear response where 25% of worker queues are allowed at 75% of maximum load, set this to 1. + // Setting 0 would allow maximum worker queues at all times, which is not recommended. + 'worker_load_exponent' => 3, + + // xrd_timeout (Integer) + // Timeout in seconds for fetching the XRD links. + 'xrd_timeout' => 20, + ], + 'experimental' => [ + // exp_themes (Boolean) + // Show experimental themes in user settings. + 'exp_themes' => false, + ], + 'theme' => [ + // hide_eventlist (Boolean) + // Don't show the birthdays and events on the profile and network page. + 'hide_eventlist' => false, + ], + 'jabber' => [ + // debug (Boolean) + // Enable debug level for the jabber account synchronisation. + 'debug' => false, + // lockpath (Path) + // Must be writable by the ejabberd process. if set then it will prevent the running of multiple processes. + 'lockpath' => '', + ], +]; diff --git a/config/local-sample.config.php b/config/local-sample.config.php new file mode 100644 index 000000000..c9ca85aee --- /dev/null +++ b/config/local-sample.config.php @@ -0,0 +1,44 @@ + [ + 'hostname' => 'localhost', + 'username' => 'mysqlusername', + 'password' => 'mysqlpassword', + 'database' => 'mysqldatabasename', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'admin_email' => '', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; diff --git a/config/settings.config.php b/config/settings.config.php new file mode 100644 index 000000000..b818f66bf --- /dev/null +++ b/config/settings.config.php @@ -0,0 +1,113 @@ + [ + // info (String) + // Plaintext description of this node, used in the /friendica module. + 'info' => '', + + // register_policy (Constant) + // Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED. + // Be certain to create your own personal account before setting REGISTER_CLOSED. + // REGISTER_APPROVE requires you set system.admin_email to the email address of an already registered person who can authorize and/or approve/deny the request. + 'register_policy' => 'REGISTER_CLOSED', + + // register_text (String) + // Will be displayed prominently on the registration page. + 'register_text' => '', + + // sitename (String) + // Displayed server name. + 'sitename' => 'Friendica Social Network', + ], + 'system' => [ + // account_abandon_days (Integer) + // Will not waste system resources polling external sites for abandonded accounts. + // Enter 0 for no time limit. + 'account_abandon_days' => 0, + + // addon (Comma-separated list) + // Manual list of addons which are enabled on this system. + 'addon' => '', + + // allowed_themes (Comma-separated list) + // Themes users can change to in their settings. + 'allowed_themes' => 'quattro,vier,duepuntozero,smoothly', + + // default_timezone (String) + // Choose a default timezone. See https://secure.php.net/manual/en/timezones.php + // It only applies to timestamps for anonymous viewers. + 'default_timezone' => 'UTC', + + // directory (String) + // URL of the global directory. + 'directory' => 'https://dir.friendica.social', + + // forbidden_nicknames (Comma-separated list) + // Prevents users from registering the specified nicknames on this node. + // Default value comprises classic role names from RFC 2142. + 'forbidden_nicknames' => 'info, marketing, sales, support, abuse, noc, security, postmaster, hostmaster, usenet, news, webmaster, www, uucp, ftp, root, sysop', + + // jpeg_quality (Integer) + // Sets the ImageMagick quality level for JPEG images. Values ranges from 50 (awful) to 100 (near perfect). + 'jpeg_quality' => 100, + + // language (String) + // System default languague, inluding admin-created user default language. + // Two-letters ISO 639-1 code. + 'language' => 'en', + + // max_image_length (Integer) + // An alternate way of limiting picture upload sizes. + // Specify the maximum pixel length that pictures are allowed to be (for non-square pictures, it will apply to the longest side). + // Pictures longer than this length will be resized to be this length (on the longest side, the other side will be scaled appropriately). + // If you don't want to set a maximum length, set to -1. + 'max_image_length' => -1, + + // maximagesize (Integer) + // Maximum size in bytes of an uploaded photo. + 'maximagesize' => 800000, + + // no_regfullname (Boolean) + // Allow pseudonyms (true) or enforce a space between first name and last name in Full name, as an anti spam measure (false). + 'no_regfullname' => true, + + // optimize_max_tablesize (Integer) + // Maximum table size (in MB) for the automatic optimization. + // -1 to disable automatic optimization. + // 0 to use internal default (100MB) + 'optimize_max_tablesize' => -1, + + // rino_encrypt (Integer) + // Server-to-server private message encryption (RINO). + // Encryption will only be provided if this setting is set to a non zero value on both servers. + // Set to 0 to disable, 2 to enable, 1 is deprecated but won't need mcrypt. + 'rino_encrypt' => 2, + + // temppath (String) + // Custom temporary file directory + 'temppath' => '', + + // theme (String) + // System theme name. + 'theme' => 'vier', + + // url (String) + // The fully-qualified URL of this Friendica node. + // Used by the worker in a non-HTTP execution environment. + 'url' => '', + ], + + // Used in the admin settings to lock certain features + 'featurelock' => [ + ], +]; diff --git a/src/App.php b/src/App.php index 67625228b..845560a4d 100644 --- a/src/App.php +++ b/src/App.php @@ -214,7 +214,7 @@ class App set_include_path( get_include_path() . PATH_SEPARATOR . $this->getBasePath() . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR - . $this->getBasePath(). DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR + . $this->getBasePath() . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR . $this->getBasePath()); if (!empty($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'pagename=') === 0) { @@ -329,24 +329,24 @@ class App * Load the configuration files * * First loads the default value for all the configuration keys, then the legacy configuration files, then the - * expected local.ini.php + * expected local.config.php */ private function loadConfigFiles() { - $this->loadConfigFile($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php'); - $this->loadConfigFile($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php'); + $this->loadConfigFile($this->getBasePath() . '/config/defaults.config.php'); + $this->loadConfigFile($this->getBasePath() . '/config/settings.config.php'); // Legacy .htconfig.php support - if (file_exists($this->getBasePath() . DIRECTORY_SEPARATOR . '.htpreconfig.php')) { + if (file_exists($this->getBasePath() . '/.htpreconfig.php')) { $a = $this; - include $this->getBasePath() . DIRECTORY_SEPARATOR . '.htpreconfig.php'; + include $this->getBasePath() . '/.htpreconfig.php'; } // Legacy .htconfig.php support - if (file_exists($this->getBasePath() . DIRECTORY_SEPARATOR . '.htconfig.php')) { + if (file_exists($this->getBasePath() . '/.htconfig.php')) { $a = $this; - include $this->getBasePath() . DIRECTORY_SEPARATOR . '.htconfig.php'; + include $this->getBasePath() . '/.htconfig.php'; $this->setConfigValue('database', 'hostname', $db_host); $this->setConfigValue('database', 'username', $db_user); @@ -374,24 +374,50 @@ class App } } - if (file_exists($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { - $this->loadConfigFile($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php', true); + if (file_exists($this->getBasePath() . '/config/local.config.php')) { + $this->loadConfigFile($this->getBasePath() . '/config/local.config.php', true); + } elseif (file_exists($this->getBasePath() . '/config/local.ini.php')) { + $this->loadINIConfigFile($this->getBasePath() . '/config/local.ini.php', true); } } + /** + * Tries to load the specified legacy configuration file into the App->config array. + * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config. + * + * @deprecated since version 2018.12 + * @param string $filepath + * @param bool $overwrite Force value overwrite if the config key already exists + * @throws Exception + */ + public function loadINIConfigFile($filepath, $overwrite = false) + { + if (!file_exists($filepath)) { + throw new Exception('Error parsing non-existent INI config file ' . $filepath); + } + + $contents = include($filepath); + + $config = parse_ini_string($contents, true, INI_SCANNER_TYPED); + + if ($config === false) { + throw new Exception('Error parsing INI config file ' . $filepath); + } + + $this->loadConfigArray($config, $overwrite); + } + /** * Tries to load the specified configuration file into the App->config array. * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config. * - * The config format is INI and the template for configuration files is the following: + * The config format is PHP array and the template for configuration files is the following: * - * [ + * 'key' => 'value', + * ], + * ]; * * @param string $filepath * @param bool $overwrite Force value overwrite if the config key already exists @@ -400,17 +426,46 @@ class App public function loadConfigFile($filepath, $overwrite = false) { if (!file_exists($filepath)) { - throw new Exception('Error parsing non-existent config file ' . $filepath); + throw new Exception('Error loading non-existent config file ' . $filepath); } - $contents = include($filepath); + $config = include($filepath); - $config = parse_ini_string($contents, true, INI_SCANNER_TYPED); - - if ($config === false) { - throw new Exception('Error parsing config file ' . $filepath); + if (!is_array($config)) { + throw new Exception('Error loading config file ' . $filepath); } + $this->loadConfigArray($config, $overwrite); + } + + /** + * Loads addons configuration files + * + * First loads all activated addons default configuration through the load_config hook, then load the local.config.php + * again to overwrite potential local addon configuration. + */ + private function loadAddonConfig() + { + // Loads addons default config + Core\Hook::callAll('load_config'); + + // Load the local addon config file to overwritten default addon config values + if (file_exists($this->getBasePath() . '/config/addon.config.php')) { + $this->loadConfigFile($this->getBasePath() . '/config/addon.config.php', true); + } elseif (file_exists($this->getBasePath() . '/config/addon.ini.php')) { + $this->loadINIConfigFile($this->getBasePath() . '/config/addon.ini.php', true); + } + } + + /** + * Tries to load the specified configuration array into the App->config array. + * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config. + * + * @param array $config + * @param bool $overwrite Force value overwrite if the config key already exists + */ + private function loadConfigArray(array $config, $overwrite = false) + { foreach ($config as $category => $values) { foreach ($values as $key => $value) { if ($overwrite) { @@ -422,23 +477,6 @@ class App } } - /** - * Loads addons configuration files - * - * First loads all activated addons default configuration throught the load_config hook, then load the local.ini.php - * again to overwrite potential local addon configuration. - */ - private function loadAddonConfig() - { - // Loads addons default config - Core\Addon::callHooks('load_config'); - - // Load the local addon config file to overwritten default addon config values - if (file_exists($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php')) { - $this->loadConfigFile($this->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php', true); - } - } - /** * Loads the default timezone * @@ -661,8 +699,8 @@ class App $this->urlPath = trim($parsed['path'], '\\/'); } - if (file_exists($this->getBasePath() . DIRECTORY_SEPARATOR . '.htpreconfig.php')) { - include $this->getBasePath() . DIRECTORY_SEPARATOR . '.htpreconfig.php'; + if (file_exists($this->getBasePath() . '/.htpreconfig.php')) { + include $this->getBasePath() . '/.htpreconfig.php'; } if (Core\Config::get('config', 'hostname') != '') { From 98d90e131ded624c552102dd450a21e6a67aecf1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:44:09 -0500 Subject: [PATCH 3/7] Update install to generate config/local.config.php --- .travis.yml | 2 +- INSTALL.txt | 29 +++---- bin/dev/vagrant_provision.sh | 3 +- src/App/Mode.php | 5 +- src/Core/Console/AutomaticInstallation.php | 18 ++-- src/Core/Installer.php | 22 ++--- tests/Util/VFSTrait.php | 6 +- tests/src/App/ModeTest.php | 6 +- .../AutomaticInstallationConsoleTest.php | 84 ++++++++++--------- tests/src/Core/InstallerTest.php | 6 +- util/local.config.vagrant.php | 41 +++++++++ view/templates/local.config.tpl | 35 ++++++++ 12 files changed, 168 insertions(+), 89 deletions(-) create mode 100644 util/local.config.vagrant.php create mode 100644 view/templates/local.config.tpl diff --git a/.travis.yml b/.travis.yml index bb8b11311..f9f9acff1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: install: - composer install before_script: - - cp config/local-sample.ini.php config/local.ini.php + - cp config/local-sample.config.php config/local.config.php - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' - mysql -utravis test < database.sql - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini diff --git a/INSTALL.txt b/INSTALL.txt index 2f0613fb7..9d10e8aee 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -114,7 +114,7 @@ password, database name). 4. If you know in advance that it will be impossible for the web server to write or create files in the config/ subfolder, create an empty file called -local.ini.php and make it writable by the web server. +local.config.php and make it writable by the web server. 5. Visit your website with a web browser and follow the instructions. Please note any error messages and correct these before continuing. @@ -128,9 +128,9 @@ so in the host name setting for the database. 6. *If* the automated installation fails for any reason, check the following: - - "config/local.ini.php" exists - If not, edit local-sample.ini.php and change system settings. Rename -to local.ini.php + - "config/local.config.php" exists + If not, edit local-sample.config.php and change system settings. Rename +to local.config.php - Database is populated. If not, import the contents of "database.sql" with phpmyadmin or mysql command line @@ -139,7 +139,7 @@ or mysql command line Registration errors should all be recoverable automatically. If you get any *critical* failure at this point, it generally indicates the database was not installed correctly. You might wish to move/rename -local.ini.php to another name and empty (called 'dropping') the database +local.config.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. **************************************************************************** @@ -184,7 +184,7 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yoursef a backup plan. -The most important file is the `config/local.ini.php` file in the base directory. +The most important file is the `config/local.config.php` file in the base directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. @@ -281,21 +281,21 @@ Windows). ##################################################################### -- If you are unable to write the file config/local.ini.php during installation +- If you are unable to write the file config/local.config.php during installation due to permissions issues: ##################################################################### create an empty file with that name and give it world-write permission. For Linux: -% touch config/local.ini.php -% chmod 664 config/local.ini.php +% touch config/local.config.php +% chmod 664 config/local.config.php Retry the installation. As soon as the database has been created, ******* this is important ********* -% chmod 644 config/local.ini.php +% chmod 644 config/local.config.php ##################################################################### - Some configurations with "suhosin" security are configured without @@ -334,11 +334,12 @@ After a while I noticed, that bin/worker.php calls further php script via proc_open. These scripts themselves also use proc_open and fail, because they are NOT called with -d suhosin.executor.func.blacklist=none. -So the simple solution is to put the correct parameters into config/local.ini.php: +So the simple solution is to put the correct parameters into config/local.config.php: -[config] -; Location of PHP command line processor -php_path = "/usr/bin/php -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none" + 'config' => [ + //Location of PHP command line processor + 'php_path' => '/usr/bin/php -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none', + ], This is obvious as soon as you notice that the friendica-cron uses proc_open to execute php-scripts that also use proc_open, but it took me quite some time to diff --git a/bin/dev/vagrant_provision.sh b/bin/dev/vagrant_provision.sh index ac093e789..440a7b590 100755 --- a/bin/dev/vagrant_provision.sh +++ b/bin/dev/vagrant_provision.sh @@ -86,8 +86,7 @@ cd /var/www php bin/composer.phar install # initial config file for friendica in vagrant -#cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php -cp /vagrant/util/local.ini.vagrant.php /vagrant/config/local.ini.php +cp /vagrant/util/local.config.vagrant.php /vagrant/config/local.config.php # copy the .htaccess-dist file to .htaccess so that rewrite rules work cp /vagrant/.htaccess-dist /vagrant/.htaccess diff --git a/src/App/Mode.php b/src/App/Mode.php index d9f5cdbd4..fdfb2ce6e 100644 --- a/src/App/Mode.php +++ b/src/App/Mode.php @@ -52,8 +52,9 @@ class Mode $this->mode = 0; - if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') - && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { + if (!file_exists($this->basepath . '/config/local.config.php') + && !file_exists($this->basepath . '/config/local.ini.php') + && !file_exists($this->basepath . '/.htconfig.php')) { return; } diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 294009ada..150b7e52a 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -23,7 +23,7 @@ Synopsis bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f] Description - Installs Friendica with data based on the local.ini.php file or environment variables + Installs Friendica with data based on the local.config.php file or environment variables Notes Not checking .htaccess/URL-Rewrite during CLI installation. @@ -32,7 +32,7 @@ Options -h|--help|-? Show help information -v Show more debug information. -a All setup checks are required (except .htaccess) - -f|--file prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables) + -f|--file prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables) -s|--savedb Save the DB credentials to the file (if environment variables is used) -H|--dbhost The host of the mysql/mariadb database (env MYSQL_HOST) -p|--dbport The port of the mysql/mariadb database (env MYSQL_PORT) @@ -58,11 +58,11 @@ Environment variables FRIENDICA_LANG The langauge of Friendica Examples - bin/console autoinstall -f 'input.ini.php - Installs Friendica with the prepared 'input.ini.php' file + bin/console autoinstall -f 'input.config.php + Installs Friendica with the prepared 'input.config.php' file bin/console autoinstall --savedb - Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file + Installs Friendica with environment variables and saves them to the 'config/local.config.php' file bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica Installs Friendica with a local mysql database with credentials @@ -96,11 +96,11 @@ HELP; $config_file = $this->getOption(['f', 'file']); if (!empty($config_file)) { - if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') { + if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') { // Copy config file $this->out("Copying config file...\n"); - if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { - throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.ini.php' manually.\n"); + if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) { + throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n"); } } @@ -175,7 +175,7 @@ HELP; Theme::install(Config::get('system', 'theme')); $this->out(" Complete\n\n"); } else { - $this->out(" Theme setting is empty. Please check the file 'config/local.ini.php'\n\n"); + $this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n"); } $this->out("\nInstallation is finished\n"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index f7190b2f8..b84bcd916 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -123,7 +123,7 @@ class Installer /** * Executes the installation of Friendica in the given environment. - * - Creates `config/local.ini.php` + * - Creates `config/local.config.php` * - Installs Database Structure * * @param string $phppath Path to the PHP-Binary (optional, if not set e.g. 'php' or '/usr/bin/php') @@ -141,7 +141,7 @@ class Installer */ public function createConfig($phppath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $basepath) { - $tpl = Renderer::getMarkupTemplate('local.ini.tpl'); + $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$phpath' => $phppath, '$dbhost' => $dbhost, @@ -154,10 +154,10 @@ class Installer '$adminmail' => $adminmail, ]); - $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php', $txt); + $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); if (!$result) { - $this->addCheck(L10n::t('The database configuration file "config/local.ini.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'), false, false, htmlentities($txt, ENT_COMPAT, 'UTF-8')); + $this->addCheck(L10n::t('The database configuration file "config/local.config.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'), false, false, htmlentities($txt, ENT_COMPAT, 'UTF-8')); } return $result; @@ -444,9 +444,9 @@ class Installer } /** - * "config/local.ini.php" - Check + * "config/local.config.php" - Check * - * Checks if it's possible to create the "config/local.ini.php" + * Checks if it's possible to create the "config/local.config.php" * * @return bool false if something required failed */ @@ -454,17 +454,17 @@ class Installer { $status = true; $help = ""; - if ((file_exists('config/local.ini.php') && !is_writable('config/local.ini.php')) || - (!file_exists('config/local.ini.php') && !is_writable('.'))) { + if ((file_exists('config/local.config.php') && !is_writable('config/local.config.php')) || + (!file_exists('config/local.config.php') && !is_writable('.'))) { $status = false; - $help = L10n::t('The web installer needs to be able to create a file called "local.ini.php" in the "config" folder of your web server and it is unable to do so.') . EOL; + $help = L10n::t('The web installer needs to be able to create a file called "local.config.php" in the "config" folder of your web server and it is unable to do so.') . EOL; $help .= L10n::t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.') . EOL; - $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named local.ini.php in your Friendica "config" folder.') . EOL; + $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named local.config.php in your Friendica "config" folder.') . EOL; $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.') . EOL; } - $this->addCheck(L10n::t('config/local.ini.php is writable'), $status, false, $help); + $this->addCheck(L10n::t('config/local.config.php is writable'), $status, false, $help); // Local INI File is not required return true; diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 1edc25d42..50999b984 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -27,9 +27,9 @@ trait VFSTrait // create a virtual directory and copy all needed files and folders to it $this->root = vfsStream::setup('friendica', null, $structure); - $this->setConfigFile('config.ini.php'); - $this->setConfigFile('settings.ini.php'); - $this->setConfigFile('local.ini.php'); + $this->setConfigFile('defaults.config.php'); + $this->setConfigFile('settings.config.php'); + $this->setConfigFile('local.config.php'); $this->setConfigFile('dbstructure.config.php'); } diff --git a/tests/src/App/ModeTest.php b/tests/src/App/ModeTest.php index cab953bda..d534e24ed 100644 --- a/tests/src/App/ModeTest.php +++ b/tests/src/App/ModeTest.php @@ -36,11 +36,11 @@ class ModeTest extends MockedTest { $mode = new Mode($this->root->url()); - $this->assertTrue($this->root->hasChild('config/local.ini.php')); + $this->assertTrue($this->root->hasChild('config/local.config.php')); - $this->delConfigFile('local.ini.php'); + $this->delConfigFile('local.config.php'); - $this->assertFalse($this->root->hasChild('config/local.ini.php')); + $this->assertFalse($this->root->hasChild('config/local.config.php')); $mode->determine(); diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 957517f03..b70447a54 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -41,9 +41,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest { parent::setUp(); - if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { + if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) { $this->root->getChild('config') - ->removeChild('local.ini.php'); + ->removeChild('local.config.php'); } $this->db_host = getenv('MYSQL_HOST'); @@ -58,7 +58,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest } /** - * Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.ini.php + * Creates the arguments which is asserted to be passed to 'replaceMacros()' for creating the local.config.php * * @param bool $withDb if true, DB will get saved too * @@ -184,51 +184,53 @@ FIN; $this->mockUpdate([false, true, true], null, 1); $config = << [ + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'charset' => 'utf8mb4', + ], -[config] -admin_email = - -sitename = Friendica Social Network - -register_policy = REGISTER_OPEN -register_text = - -[system] -default_timezone = UTC - -language = en -INI; -// Keep this line + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + 'config' => [ + 'admin_email' => '', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; CONF; - vfsStream::newFile('prepared.ini.php') + vfsStream::newFile('prepared.config.php') ->at($this->root) ->setContent($config); $console = new AutomaticInstallation($this->consoleArgv); - $console->setOption('f', 'prepared.ini.php'); + $console->setOption('f', 'prepared.config.php'); $txt = $this->dumpExecute($console); $this->assertFinished($txt, false, true); - $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); + $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); } /** @@ -241,7 +243,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -267,7 +269,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -292,7 +294,7 @@ CONF; $this->mockExistsTable('user', false, 1); $this->mockUpdate([false, true, true], null, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(true), '', 1); $console = new AutomaticInstallation($this->consoleArgv); @@ -326,7 +328,7 @@ CONF; { $this->mockConnect(false, 1); - $this->mockGetMarkupTemplate('local.ini.tpl', 'testTemplate', 1); + $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', $this->createArgumentsForMacro(false), '', 1); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); @@ -350,7 +352,7 @@ Synopsis bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f] Description - Installs Friendica with data based on the local.ini.php file or environment variables + Installs Friendica with data based on the local.config.php file or environment variables Notes Not checking .htaccess/URL-Rewrite during CLI installation. @@ -359,7 +361,7 @@ Options -h|--help|-? Show help information -v Show more debug information. -a All setup checks are required (except .htaccess) - -f|--file prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables) + -f|--file prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables) -s|--savedb Save the DB credentials to the file (if environment variables is used) -H|--dbhost The host of the mysql/mariadb database (env MYSQL_HOST) -p|--dbport The port of the mysql/mariadb database (env MYSQL_PORT) @@ -385,11 +387,11 @@ Environment variables FRIENDICA_LANG The langauge of Friendica Examples - bin/console autoinstall -f 'input.ini.php - Installs Friendica with the prepared 'input.ini.php' file + bin/console autoinstall -f 'input.config.php + Installs Friendica with the prepared 'input.config.php' file bin/console autoinstall --savedb - Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file + Installs Friendica with environment variables and saves them to the 'config/local.config.php' file bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica Installs Friendica with a local mysql database with credentials diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index ebbf5037d..32a80a77e 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -195,14 +195,14 @@ class InstallerTest extends MockedTest */ public function testCheckLocalIni() { - $this->assertTrue($this->root->hasChild('config/local.ini.php')); + $this->assertTrue($this->root->hasChild('config/local.config.php')); $install = new Installer(); $this->assertTrue($install->checkLocalIni()); - $this->delConfigFile('local.ini.php'); + $this->delConfigFile('local.config.php'); - $this->assertFalse($this->root->hasChild('config/local.ini.php')); + $this->assertFalse($this->root->hasChild('config/local.config.php')); $install = new Installer(); $this->assertTrue($install->checkLocalIni()); diff --git a/util/local.config.vagrant.php b/util/local.config.vagrant.php new file mode 100644 index 000000000..fcac663c4 --- /dev/null +++ b/util/local.config.vagrant.php @@ -0,0 +1,41 @@ + [ + 'hostname' => 'localhost', + 'username' => 'mysqlusername', + 'password' => 'mysqlpassword', + 'database' => 'mysqldatabasename', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'admin_email' => 'admin@friendica.local', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + ], +]; diff --git a/view/templates/local.config.tpl b/view/templates/local.config.tpl new file mode 100644 index 000000000..5839e8c34 --- /dev/null +++ b/view/templates/local.config.tpl @@ -0,0 +1,35 @@ + [ + 'hostname' => '{{$dbhost}}', + 'username' => '{{$dbuser}}', + 'password' => '{{$dbpass}}', + 'database' => '{{$dbdata}}', + 'charset' => 'utf8mb4', + ], + + // **************************************************************** + // The configuration below will be overruled by the admin panel. + // Changes made below will only have an effect if the database does + // not contain any configuration for the friendica system. + // **************************************************************** + + 'config' => [ + 'php_path' => '{{$phpath}}', + 'admin_email' => '{{$adminmail}}', + 'sitename' => 'Friendica Social Network', + 'register_policy' => 'REGISTER_OPEN', + 'max_import_size' => 200000, + ], + 'system' => [ + 'urlpath' => '{{$urlpath}}', + 'default_timezone' => '{{$timezone}}', + 'language' => '{{$language}}', + ], +]; From c964e193b9b476debc16e42279801372137bc3bc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:44:51 -0500 Subject: [PATCH 4/7] Replace *.ini.php by *.config.php in comments --- bin/daemon.php | 11 ++++++++--- boot.php | 12 +++++++----- mod/admin.php | 2 +- src/Core/Config/JITConfigAdapter.php | 4 ++-- src/Core/Console/Config.php | 2 +- tests/src/Core/Console/ConfigConsoleTest.php | 2 +- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index f628031c3..9df8b8957 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -42,9 +42,14 @@ if ($a->getMode()->isInstall()) { Config::load(); if (empty(Config::get('system', 'pidfile'))) { - die('Please set system.pidfile in config/local.ini.php. For example:'."\n". - '[system]'."\n". - 'pidfile = /path/to/daemon.pid'."\n"); + die(<< [ + 'pidfile' => '/path/to/daemon.pid', + ], +TXT + ); } $pidfile = Config::get('system', 'pidfile'); diff --git a/boot.php b/boot.php index 6373b2c64..f3d1f6f64 100644 --- a/boot.php +++ b/boot.php @@ -56,13 +56,13 @@ define('EOL', "
\r\n"); * @brief Image storage quality. * * Lower numbers save space at cost of image detail. - * For ease of upgrade, please do not change here. Set [system] jpegquality = n in config/local.ini.php, + * For ease of upgrade, please do not change here. Set system.jpegquality = n in config/local.config.php, * where n is between 1 and 100, and with very poor results below about 50 */ define('JPEG_QUALITY', 100); /** - * [system] png_quality = n where is between 0 (uncompressed) to 9 + * system.png_quality = n where is between 0 (uncompressed) to 9 */ define('PNG_QUALITY', 8); @@ -73,10 +73,12 @@ define('PNG_QUALITY', 8); * this length (on the longest side, the other side will be scaled appropriately). * Modify this value using * - * [system] - * max_image_length = n; + * 'system' => [ + * 'max_image_length' => 'n', + * ... + * ], * - * in config/local.ini.php + * in config/local.config.php * * If you don't want to set a maximum length, set to -1. The default value is * defined by 'MAX_IMAGE_LENGTH' below. diff --git a/mod/admin.php b/mod/admin.php index 5bf55423e..ab5c37ec0 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -914,7 +914,7 @@ function admin_page_summary(App $a) // Legacy config file warning if (file_exists('.htconfig.php')) { $showwarning = true; - $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php. See the Config help page for help with the transition.', $a->getBaseURL() . '/help/Config'); + $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from .htconfig.php. See the Config help page for help with the transition.', $a->getBaseURL() . '/help/Config'); } // Check server vitality diff --git a/src/Core/Config/JITConfigAdapter.php b/src/Core/Config/JITConfigAdapter.php index b985d91c2..2018f583d 100644 --- a/src/Core/Config/JITConfigAdapter.php +++ b/src/Core/Config/JITConfigAdapter.php @@ -65,13 +65,13 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter $this->in_db[$cat][$k] = true; return $value; } elseif (isset($a->config[$cat][$k])) { - // Assign the value (mostly) from config/local.ini.php file to the cache + // Assign the value (mostly) from config/local.config.php file to the cache $this->cache[$cat][$k] = $a->config[$cat][$k]; $this->in_db[$cat][$k] = false; return $a->config[$cat][$k]; } elseif (isset($a->config[$k])) { - // Assign the value (mostly) from config/local.ini.php file to the cache + // Assign the value (mostly) from config/local.config.php file to the cache $this->cache[$k] = $a->config[$k]; $this->in_db[$k] = false; diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index 3b92d5a78..ce367fffb 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -59,7 +59,7 @@ Description Sets the value of the provided key in the category Notes: - Setting config entries which are manually set in config/local.ini.php may result in + Setting config entries which are manually set in config/local.config.php may result in conflict between database settings and the manual startup settings. Options diff --git a/tests/src/Core/Console/ConfigConsoleTest.php b/tests/src/Core/Console/ConfigConsoleTest.php index 8f845ae7b..3ba2bd60d 100644 --- a/tests/src/Core/Console/ConfigConsoleTest.php +++ b/tests/src/Core/Console/ConfigConsoleTest.php @@ -139,7 +139,7 @@ Description Sets the value of the provided key in the category Notes: - Setting config entries which are manually set in config/local.ini.php may result in + Setting config entries which are manually set in config/local.config.php may result in conflict between database settings and the manual startup settings. Options From 1b30c684f31e370fe2bf7a1f59f980e0399747ab Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 25 Nov 2018 01:56:02 -0500 Subject: [PATCH 5/7] Update documentation with new config style/name - Fix typos --- doc/Config.md | 204 +++++++++++++++++++++----------- doc/FAQ.md | 10 +- doc/Home.md | 4 +- doc/Install.md | 30 ++--- doc/Installing-Connectors.md | 4 +- doc/Settings.md | 84 +++++++------ doc/Update.md | 2 +- doc/Vagrant.md | 4 +- doc/de/FAQ.md | 6 +- doc/de/Home.md | 2 +- doc/de/Install.md | 22 ++-- doc/de/Installing-Connectors.md | 4 +- doc/de/Settings.md | 34 +++--- 13 files changed, 244 insertions(+), 166 deletions(-) diff --git a/doc/Config.md b/doc/Config.md index 788c1cd0b..f85ceb498 100644 --- a/doc/Config.md +++ b/doc/Config.md @@ -1,55 +1,54 @@ -Config values that can only be set in config/local.ini.php +Config values that can only be set in config/local.config.php ========================================================== * [Home](help) -Friendica's configuration is done in two places: in INI configuration files and in the `config` database table. +Friendica's configuration is done in two places: in PHP array configuration files and in the `config` database table. Database config values overwrite the same file config values. ## File configuration -WARNING: some characters `?{}|&~![()^"` should not be used in the keys or values. If one of those character is required put the value between double quotes (eg. password = "let&me&in") -The configuration format for file configuration is an INI string returned from a PHP file. -This prevents your webserver from displaying your private configuration it interprets the configuration files and displays nothing. +The configuration format for file configuration is an array returned from a PHP file. +This prevents your webserver from displaying your private configuration. It interprets the configuration files and displays nothing. A typical configuration file looks like this: ```php - [ + // Comment line + 'key' => 'value', + ], + 'section2' => [ + 'array' => ['value0', 'value1', 'value2'], + ], +]; ``` ### Configuration location The `config` directory holds key configuration files: -- `config.ini.php` holds the default values for all the configuration keys that can only be set in `local.ini.php`. -- `settings.ini.php` holds the default values for some configuration keys that are set through the admin settings page. -- `local.ini.php` holds the current node custom configuration. -- `addon.ini.php` is optional and holds the custom configuration for specific addons. +- `defaults.config.php` holds the default values for all the configuration keys that can only be set in `local.config.php`. +- `settings.config.php` holds the default values for some configuration keys that are set through the admin settings page. +- `local.config.php` holds the current node custom configuration. +- `addon.config.php` is optional and holds the custom configuration for specific addons. -Addons can define their own default configuration values in `addon/[addon]/config/[addon].ini.php` which is loaded when the addon is activated. +Addons can define their own default configuration values in `addon/[addon]/config/[addon].config.php` which is loaded when the addon is activated. -#### Migrating from .htconfig.php to config/local.ini.php +#### Migrating from .htconfig.php to config/local.config.php The legacy `.htconfig.php` configuration file is still supported, but is deprecated and will be removed in a subsequent Friendica release. The migration is pretty straightforward: -If you had any addon-specific configuration in your `.htconfig.php`, just copy `config/addon-sample.ini.php` to `config/addon.ini.php` and move your configuration values. -Afterwards, copy `config/local-sample.ini.php` to `config/local.ini.php`, move the remaining configuration values to it according to the following conversion chart, then rename your `.htconfig.php` to check your node is working as expected before deleting it. +If you had any addon-specific configuration in your `.htconfig.php`, just copy `config/addon-sample.config.php` to `config/addon.config.php` and move your configuration values. +Afterwards, copy `config/local-sample.config.php` to `config/local.config.php`, move the remaining configuration values to it according to the following conversion chart, then rename your `.htconfig.php` to check your node is working as expected before deleting it.