From 90a38a00d8d642cb7473523539b64aa7c836a8c5 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Tue, 26 Mar 2019 22:04:31 +0100 Subject: [PATCH 01/12] Adding basepath, urlpath, hostname and ssl_policy to installation --- bin/daemon.php | 4 +- src/BaseObject.php | 3 + src/Core/Console/AutomaticInstallation.php | 71 +++++--- src/Core/Installer.php | 37 +++-- src/Database/DBA.php | 11 +- src/Factory/DBFactory.php | 9 +- src/Factory/DependencyFactory.php | 4 +- src/Module/Install.php | 103 ++++++++++-- tests/DatabaseTest.php | 1 - tests/Util/AppMockTrait.php | 9 +- tests/include/ApiTest.php | 2 +- .../AutomaticInstallationConsoleTest.php | 151 +++++++++++++----- tests/src/Core/InstallerTest.php | 16 ++ tests/src/Database/DBATest.php | 2 +- tests/src/Database/DBStructureTest.php | 2 +- tests/src/Util/BasePathTest.php | 29 ++++ view/templates/install_base.tpl | 34 ++++ view/templates/install_db.tpl | 6 +- view/templates/install_settings.tpl | 10 +- view/templates/local.config.tpl | 3 + 20 files changed, 380 insertions(+), 127 deletions(-) create mode 100644 tests/src/Util/BasePathTest.php create mode 100644 view/templates/install_base.tpl diff --git a/bin/daemon.php b/bin/daemon.php index 298cfa2534..047bf71be7 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -144,9 +144,7 @@ if (!$foreground) { file_put_contents($pidfile, $pid); // We lose the database connection upon forking - /// @todo refactoring during https://github.com/friendica/friendica/issues/6720 - $basePath = \Friendica\Util\BasePath::create(dirname(__DIR__), $_SERVER); - Factory\DBFactory::init($basePath, $a->getConfigCache(), $a->getProfiler(), $_SERVER); + Factory\DBFactory::init($a->getConfigCache(), $a->getProfiler(), $_SERVER); } Config::set('system', 'worker_daemon_mode', true); diff --git a/src/BaseObject.php b/src/BaseObject.php index 7e90478a9d..9a2d064750 100644 --- a/src/BaseObject.php +++ b/src/BaseObject.php @@ -15,6 +15,9 @@ use Friendica\Network\HTTPException\InternalServerErrorException; */ class BaseObject { + /** + * @var App + */ private static $app = null; /** diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 911c1c00a8..34a933e12e 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -30,17 +30,19 @@ Options -v Show more debug information. -a All setup checks are required (except .htaccess) -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) - -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) - -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) - -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -u|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) - -b|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -A|--admin The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL) - -T|--tz The timezone of Friendica (env FRIENDICA_TZ) - -L|--lang The language of Friendica (env FRIENDICA_LANG) + -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) + -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) + -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) + -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) + -U|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) + -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) + -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -S|--sslpolicy The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) + -n|--hostname The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) + -t|--tz The timezone of Friendica (env FRIENDICA_TZ) + -L|--lang The language of Friendica (env FRIENDICA_LANG) Environment variables MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) @@ -48,9 +50,12 @@ Environment variables MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database - FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - FRIENDICA_PHP_PATH The path of the PHP binary + FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection + FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection + FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) + FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL) + FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica @@ -76,6 +81,7 @@ HELP; $installer = new Installer(); $configCache = $a->getConfigCache(); + $installer->setUpCache($configCache, dirname(__DIR__, 3), $_SERVER); $this->out(" Complete!\n\n"); @@ -99,7 +105,7 @@ HELP; // 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.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"); + 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"); } } @@ -129,7 +135,10 @@ HELP; $php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null); if (!empty($php_path)) { $configCache->set('config', 'php_path', $php_path); + } else { + $configCache->set('config', 'php_path', $installer->getPHPPath()); } + $configCache->set('config', 'admin_email', $this->getOption(['A', 'admin'], !empty(getenv('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : '')); @@ -140,16 +149,29 @@ HELP; $this->getOption(['L', 'lang'], !empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG)); + $configCache->set('system', 'urlpath', $this->getOption(['u', 'urlpath'], !empty(getenv('FRIENDICA_URL_PATH')) ? getenv('FRIENDICA_URL_PATH') : '')); + $basepath = $this->getOption(['b', 'basepath'], !empty(getenv('FRIENDICA_BASE_PATH')) ? getenv('FRIENDICA_BASE_PATH') : null); + if (!empty($basepath)) { + $configCache->set('system', 'basepath', $basepath); + } + $php_path = $this->getOption(['B', 'phppath'], !empty(getenv('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : null); + if (!empty($php_path)) { + $configCache->set('config', 'php_path', $php_path); + } + $ssl_policy = $this->getOption(['S', 'sslpolicy'], !empty(getenv('FRIENDICA_SSL_POLICY')) ? getenv('FRIENDICA_SSL_POLICY') : null); + if (!empty($ssl_policy)) { + $configCache->set('system', 'ssl_policy', $ssl_policy); + } + $configCache->set('config', 'hostname', $this->getOption(['n', 'hostname'], !empty(getenv('FRIENDICA_HOSTNAME')) ? getenv('FRIENDICA_HOSTNAME') : '')); - if (empty($php_path)) { - $configCache->set('config', 'php_path', $installer->getPHPPath()); + $configCache->set('system', 'url', $installer->determineBaseUrl($configCache)); + + if (empty($configCache->get('config', 'hostname'))) { + $this->out('The Friendica hostname has to be set during CLI installation.'); + return 1; } - $installer->createConfig( - $a, - $configCache, - $a->getBasePath() - ); + $installer->createConfig($configCache); } $this->out(" Complete!\n\n"); @@ -159,7 +181,7 @@ HELP; $installer->resetChecks(); - if (!$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) { + if (!$installer->checkDB($configCache, $a->getProfiler())) { $errorMessage = $this->extractErrors($installer->getChecks()); throw new RuntimeException($errorMessage); } @@ -220,10 +242,7 @@ HELP; $checked = false; } - $php_path = null; - if ($configCache->has('config', 'php_path')) { - $php_path = $configCache->get('config', 'php_path'); - } + $php_path = $configCache->get('config', 'php_path'); if (!$installer->checkPHP($php_path, true)) { $checked = false; diff --git a/src/Core/Installer.php b/src/Core/Installer.php index b9f096eb5b..52a51498e8 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -6,12 +6,12 @@ namespace Friendica\Core; use DOMDocument; use Exception; -use Friendica\App; use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Object\Image; use Friendica\Util\Logger\VoidLogger; +use Friendica\Util\BasePath; use Friendica\Util\Network; use Friendica\Util\Profiler; use Friendica\Util\Strings; @@ -131,15 +131,15 @@ class Installer * - Creates `config/local.config.php` * - Installs Database Structure * - * @param App $app The Friendica App * @param IConfigCache $configCache The config cache with all config relevant information - * @param string $basepath The basepath of Friendica * * @return bool true if the config was created, otherwise false * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function createConfig(App $app, IConfigCache $configCache, $basepath) + public function createConfig(IConfigCache $configCache) { + $basepath = $configCache->get('system', 'basepath'); + $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$dbhost' => $configCache->get('database', 'hostname'), @@ -147,12 +147,16 @@ class Installer '$dbpass' => $configCache->get('database', 'password'), '$dbdata' => $configCache->get('database', 'database'), - '$phpath' => $this->getPHPPath(), + '$phpath' => $configCache->get('config', 'php_path'), '$adminmail' => $configCache->get('config', 'admin_email'), + '$hostname' => $configCache->get('config', 'hostname'), + '$urlpath' => $configCache->get('system', 'urlpath'), + '$baseurl' => $configCache->get('system', 'url'), + '$sslpolicy' => $configCache->get('system', 'ssl_policy'), + '$basepath' => $basepath, '$timezone' => $configCache->get('system', 'default_timezone'), '$language' => $configCache->get('system', 'language'), - '$urlpath' => $app->getURLPath(), ]); $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); @@ -244,7 +248,7 @@ class Installer $help .= EOL . EOL; $tpl = Renderer::getMarkupTemplate('field_input.tpl'); $help .= Renderer::replaceMacros($tpl, [ - '$field' => ['phpath', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], + '$field' => ['config.php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], ]); $phppath = ""; } @@ -588,21 +592,20 @@ class Installer /** * Checking the Database connection and if it is available for the current installation * - * @param string $basePath The basepath of this call * @param IConfigCache $configCache The configuration cache * @param Profiler $profiler The profiler of this app * * @return bool true if the check was successful, otherwise false * @throws Exception */ - public function checkDB($basePath, IConfigCache $configCache, Profiler $profiler) + public function checkDB(IConfigCache $configCache, Profiler $profiler) { $dbhost = $configCache->get('database', 'hostname'); $dbuser = $configCache->get('database', 'username'); $dbpass = $configCache->get('database', 'password'); $dbdata = $configCache->get('database', 'database'); - if (!DBA::connect($basePath, $configCache, $profiler, new VoidLogger(), $dbhost, $dbuser, $dbpass, $dbdata)) { + if (!DBA::connect($configCache, $profiler, new VoidLogger(), $dbhost, $dbuser, $dbpass, $dbdata)) { $this->addCheck(L10n::t('Could not connect to database.'), false, true, ''); return false; @@ -618,4 +621,18 @@ class Installer return true; } + + /** + * Setup the default cache for a new installation + * + * @param IConfigCache $configCache The configuration cache + * @param string $basePath The determined basepath + * + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function setUpCache(IConfigCache $configCache, $basePath) + { + $configCache->set('config', 'php_path' , $this->getPHPPath()); + $configCache->set('system', 'basepath' , $basePath); + } } diff --git a/src/Database/DBA.php b/src/Database/DBA.php index c5ba523810..bbf134e8ad 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -44,10 +44,6 @@ class DBA * @var LoggerInterface */ private static $logger; - /** - * @var string - */ - private static $basePath; private static $server_info = ''; private static $connection; private static $driver; @@ -63,14 +59,13 @@ class DBA private static $db_name = ''; private static $db_charset = ''; - public static function connect($basePath, IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger, $serveraddr, $user, $pass, $db, $charset = null) + public static function connect(IConfigCache $configCache, Profiler $profiler, LoggerInterface $logger, $serveraddr, $user, $pass, $db, $charset = null) { if (!is_null(self::$connection) && self::connected()) { return true; } // We are storing these values for being able to perform a reconnect - self::$basePath = $basePath; self::$configCache = $configCache; self::$profiler = $profiler; self::$logger = $logger; @@ -189,7 +184,7 @@ class DBA public static function reconnect() { self::disconnect(); - $ret = self::connect(self::$basePath, self::$configCache, self::$profiler, self::$logger, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset); + $ret = self::connect(self::$configCache, self::$profiler, self::$logger, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset); return $ret; } @@ -1079,7 +1074,7 @@ class DBA * This process must only be started once, since the value is cached. */ private static function buildRelationData() { - $definition = DBStructure::definition(self::$basePath); + $definition = DBStructure::definition(self::$configCache->get('system', 'basepath')); foreach ($definition AS $table => $structure) { foreach ($structure['fields'] AS $field => $field_struct) { diff --git a/src/Factory/DBFactory.php b/src/Factory/DBFactory.php index eeab555667..1c01f73319 100644 --- a/src/Factory/DBFactory.php +++ b/src/Factory/DBFactory.php @@ -12,16 +12,13 @@ class DBFactory /** * Initialize the DBA connection * - * @param string $basePath The basepath of the application * @param Cache\IConfigCache $configCache The configuration cache * @param Profiler $profiler The profiler * @param array $server The $_SERVER variables * * @throws \Exception if connection went bad - * - * @todo refactor basedir during https://github.com/friendica/friendica/issues/6720 */ - public static function init($basePath, Cache\IConfigCache $configCache, Profiler $profiler, array $server) + public static function init(Cache\IConfigCache $configCache, Profiler $profiler, array $server) { if (Database\DBA::connected()) { return; @@ -52,9 +49,9 @@ class DBFactory $db_data = $server['MYSQL_DATABASE']; } - if (Database\DBA::connect($basePath, $configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset)) { + if (Database\DBA::connect($configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset)) { // Loads DB_UPDATE_VERSION constant - Database\DBStructure::definition($basePath, false); + Database\DBStructure::definition($configCache->get('system', 'basepath'), false); } unset($db_host, $db_user, $db_pass, $db_data, $charset); diff --git a/src/Factory/DependencyFactory.php b/src/Factory/DependencyFactory.php index 9512d8d948..d089c32666 100644 --- a/src/Factory/DependencyFactory.php +++ b/src/Factory/DependencyFactory.php @@ -3,7 +3,6 @@ namespace Friendica\Factory; use Friendica\App; -use Friendica\Database\DBA; use Friendica\Factory; use Friendica\Util\BasePath; use Friendica\Util\BaseURL; @@ -30,12 +29,11 @@ class DependencyFactory $configLoader = new Config\ConfigFileLoader($basePath, $mode); $configCache = Factory\ConfigFactory::createCache($configLoader); $profiler = Factory\ProfilerFactory::create($configCache); - Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER); + Factory\DBFactory::init($configCache, $profiler, $_SERVER); $config = Factory\ConfigFactory::createConfig($configCache); // needed to call PConfig::init() Factory\ConfigFactory::createPConfig($configCache); $logger = Factory\LoggerFactory::create($channel, $config, $profiler); - DBA::setLogger($logger); Factory\LoggerFactory::createDev($channel, $config, $profiler); $baseURL = new BaseURL($config, $_SERVER); diff --git a/src/Module/Install.php b/src/Module/Install.php index 8e93c0a26c..67677940f3 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -8,6 +8,8 @@ use Friendica\Core; use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\Util\BasePath; +use Friendica\Util\BaseURL; use Friendica\Util\Strings; use Friendica\Util\Temporal; @@ -18,17 +20,21 @@ class Install extends BaseModule */ const SYSTEM_CHECK = 1; /** - * Step two - Database configuration + * Step two - Base information */ - const DATABASE_CONFIG = 2; + const BASE_CONFIG = 2; /** - * Step three - Adapat site settings + * Step three - Database configuration */ - const SITE_SETTINGS = 3; + const DATABASE_CONFIG = 3; /** - * Step four - All steps finished + * Step four - Adapat site settings */ - const FINISHED = 4; + const SITE_SETTINGS = 4; + /** + * Step five - All steps finished + */ + const FINISHED = 5; /** * @var int The current step of the wizard @@ -44,10 +50,6 @@ class Install extends BaseModule { $a = self::getApp(); - if (!$a->getMode()->isInstall()) { - Core\System::httpExit(403); - } - // route: install/testrwrite // $baseurl/install/testrwrite to test if rewrite in .htaccess is working if ($a->getArgumentValue(1, '') == 'testrewrite') { @@ -55,11 +57,16 @@ class Install extends BaseModule Core\System::httpExit(204); } + self::$installer = new Core\Installer(); + + // get basic installation information and save them to the config cache + $configCache = $a->getConfigCache(); + self::$installer->setUpCache($configCache, BasePath::create($a->getBasePath(), $_SERVER)); + // We overwrite current theme css, because during install we may not have a working mod_rewrite // so we may not have a css at all. Here we set a static css file for the install procedure pages Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css'; - self::$installer = new Core\Installer(); self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK); } @@ -70,20 +77,34 @@ class Install extends BaseModule switch (self::$currentWizardStep) { case self::SYSTEM_CHECK: + case self::BASE_CONFIG: + self::checkSetting($configCache, $_POST, 'config', 'php_path'); + break; + case self::DATABASE_CONFIG: self::checkSetting($configCache, $_POST, 'config', 'php_path'); + + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); break; case self::SITE_SETTINGS: self::checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); + self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); self::checkSetting($configCache, $_POST, 'database', 'username', ''); self::checkSetting($configCache, $_POST, 'database', 'password', ''); self::checkSetting($configCache, $_POST, 'database', 'database', ''); // If we cannot connect to the database, return to the previous step - if (!self::$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) { + if (!self::$installer->checkDB($configCache, $a->getProfiler())) { self::$currentWizardStep = self::DATABASE_CONFIG; } @@ -92,6 +113,11 @@ class Install extends BaseModule case self::FINISHED: self::checkSetting($configCache, $_POST, 'config', 'php_path'); + self::checkSetting($configCache, $_POST, 'config', 'hostname'); + self::checkSetting($configCache, $_POST, 'system', 'ssl_policy'); + self::checkSetting($configCache, $_POST, 'system', 'basepath'); + self::checkSetting($configCache, $_POST, 'system', 'urlpath'); + self::checkSetting($configCache, $_POST, 'database', 'hostname', Core\Installer::DEFAULT_HOST); self::checkSetting($configCache, $_POST, 'database', 'username', ''); self::checkSetting($configCache, $_POST, 'database', 'password', ''); @@ -102,16 +128,16 @@ class Install extends BaseModule self::checkSetting($configCache, $_POST, 'config', 'admin_email', ''); // If we cannot connect to the database, return to the Database config wizard - if (!self::$installer->checkDB($a->getBasePath(), $configCache, $a->getProfiler())) { + if (!self::$installer->checkDB($configCache, $a->getProfiler())) { self::$currentWizardStep = self::DATABASE_CONFIG; return; } - if (!self::$installer->createConfig($a, $configCache, $a->getBasePath())) { + if (!self::$installer->createConfig($configCache)) { return; } - self::$installer->installDatabase($a->getBasePath()); + self::$installer->installDatabase($configCache->get('system', 'basepath')); break; } @@ -146,6 +172,43 @@ class Install extends BaseModule ]); break; + case self::BASE_CONFIG: + $ssl_choices = [ + BaseUrl::SSL_POLICY_NONE => L10n::t("No SSL policy, links will track page SSL state"), + BaseUrl::SSL_POLICY_FULL => L10n::t("Force all links to use SSL"), + BaseUrl::SSL_POLICY_SELFSIGN => L10n::t("Self-signed certificate, use SSL for local links only \x28discouraged\x29") + ]; + + $tpl = Renderer::getMarkupTemplate('install_base.tpl'); + $output .= Renderer::replaceMacros($tpl, [ + '$title' => $install_title, + '$pass' => L10n::t('Base settings'), + '$ssl_policy' => ['system-ssl_policy', + L10n::t("SSL link policy"), + $configCache->get('system', 'ssl_policy'), + L10n::t("Determines whether generated links should be forced to use SSL"), + $ssl_choices], + '$hostname' => ['config-hostname', + L10n::t('Host name'), + $configCache->get('config', 'hostname'), + L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), + 'required'], + '$basepath' => ['system-basepath', + L10n::t("Base path to installation"), + $configCache->get('system', 'basepath'), + L10n::t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), + 'required'], + '$urlpath' => ['system-urlpath', + L10n::t('Sub path of the URL'), + $configCache->get('system', 'urlpath'), + L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), + ''], + '$baseurl' => $a->getBaseURL(), + '$php_path' => $configCache->get('config', 'php_path'), + '$submit' => L10n::t('Submit'), + ]); + break; + case self::DATABASE_CONFIG: $tpl = Renderer::getMarkupTemplate('install_db.tpl'); $output .= Renderer::replaceMacros($tpl, [ @@ -155,6 +218,10 @@ class Install extends BaseModule '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'), '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'), 'checks' => self::$installer->getChecks(), + '$hostname' => $configCache->get('config', 'hostname'), + '$ssl_policy' => $configCache->get('system', 'ssl_policy'), + '$basepath' => $configCache->get('system', 'basepath'), + '$urlpath' => $configCache->get('system', 'urlpath'), '$dbhost' => ['database-hostname', L10n::t('Database Server Name'), $configCache->get('database', 'hostname'), @@ -192,11 +259,14 @@ class Install extends BaseModule '$title' => $install_title, '$checks' => self::$installer->getChecks(), '$pass' => L10n::t('Site settings'), + '$hostname' => $configCache->get('config', 'hostname'), + '$ssl_policy' => $configCache->get('system', 'ssl_policy'), + '$basepath' => $configCache->get('system', 'basepath'), + '$urlpath' => $configCache->get('system', 'urlpath'), '$dbhost' => $configCache->get('database', 'hostname'), '$dbuser' => $configCache->get('database', 'username'), '$dbpass' => $configCache->get('database', 'password'), '$dbdata' => $configCache->get('database', 'database'), - '$phpath' => $configCache->get('config', 'php_path'), '$adminmail' => ['config-admin_email', L10n::t('Site administrator email address'), $configCache->get('config', 'admin_email'), @@ -212,6 +282,7 @@ class Install extends BaseModule L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices], '$baseurl' => $a->getBaseURL(), + '$php_path' => $configCache->get('config', 'php_path'), '$submit' => L10n::t('Submit') ]); break; diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 0c2350e2de..b3418c20f4 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -50,7 +50,6 @@ abstract class DatabaseTest extends MockedTest $profiler = \Mockery::mock(Profiler::class); DBA::connect( - $basePath, $config, $profiler, new VoidLogger(), diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index 23920ff6f4..0bbacaf48d 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -39,10 +39,9 @@ trait AppMockTrait * Mock the App * * @param vfsStreamDirectory $root The root directory - * @param Config\Cache\ConfigCache $configCache * @param bool $raw If true, no config mocking will be done */ - public function mockApp(vfsStreamDirectory $root, $configCache = null, $raw = false) + public function mockApp(vfsStreamDirectory $root, $raw = false) { $this->configMock = \Mockery::mock(Config\Cache\IConfigCache::class); $this->mode = \Mockery::mock(App\Mode::class); @@ -50,7 +49,7 @@ trait AppMockTrait // Disable the adapter $configAdapterMock->shouldReceive('isConnected')->andReturn(false); - $config = new Config\Configuration((isset($configCache) ? $configCache : $this->configMock), $configAdapterMock); + $config = new Config\Configuration($this->configMock, $configAdapterMock); // Initialize empty Config Config::init($config); @@ -69,7 +68,7 @@ trait AppMockTrait $this->app ->shouldReceive('getConfigCache') - ->andReturn((isset($configCache) ? $configCache : $this->configMock)); + ->andReturn($this->configMock); $this->app ->shouldReceive('getTemplateEngine') ->andReturn(new FriendicaSmartyEngine()); @@ -82,7 +81,7 @@ trait AppMockTrait $this->app ->shouldReceive('getBaseUrl') ->andReturnUsing(function () { - return $this->app->getConfigCache()->get('system', 'url'); + return $this->configMock->get('system', 'url'); }); BaseObject::setApp($this->app); diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 933b9a45ae..8dc3304f2b 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -55,7 +55,7 @@ class ApiTest extends DatabaseTest $configLoader = new ConfigFileLoader($basePath, $mode); $configCache = Factory\ConfigFactory::createCache($configLoader); $profiler = Factory\ProfilerFactory::create($configCache); - Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER); + Factory\DBFactory::init($configCache, $profiler, $_SERVER); $config = Factory\ConfigFactory::createConfig($configCache); Factory\ConfigFactory::createPConfig($configCache); $logger = Factory\LoggerFactory::create('test', $config, $profiler); diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index f24f56cdb5..30c8b4b850 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -56,7 +56,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest $this->configCache->set('config', 'php_path', trim(shell_exec('which php'))); $this->configCache->set('system', 'theme', 'smarty3'); - $this->mockApp($this->root, null, true); + $this->mockApp($this->root, true); $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) { if ($key !== 'basepath') { @@ -97,10 +97,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest ], 'config' => [ 'php_path' => '', + 'hostname' => 'friendica.local', 'admin_email' => '', ], 'system' => [ + 'basepath' => '', 'urlpath' => '', + 'url' => 'http://friendica.local', + 'ssl_policy' => '', 'default_timezone' => '', 'language' => '', ], @@ -117,10 +121,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest ], 'config' => [ 'php_path' => '', + 'hostname' => 'friendica.local', 'admin_email' => 'admin@philipp.info', ], 'system' => [ 'urlpath' => 'test/it', + 'url' => 'http://friendica.local/test/it', + 'basepath' => '', + 'ssl_policy' => '2', 'default_timezone' => 'en', 'language' => 'Europe/Berlin', ], @@ -137,10 +145,14 @@ class AutomaticInstallationConsoleTest extends ConsoleTest ], 'config' => [ 'php_path' => '', + 'hostname' => 'friendica.local', 'admin_email' => 'admin@philipp.info', ], 'system' => [ 'urlpath' => 'test/it', + 'url' => 'https://friendica.local/test/it', + 'basepath' => '', + 'ssl_policy' => '1', 'default_timezone' => 'en', 'language' => 'Europe/Berlin', ], @@ -236,6 +248,30 @@ Checking database... Could not connect to database.: +FIN; + + $this->assertEquals($finished, $txt); + } + + private function assertStuckHostnam($txt) + { + $finished = <<assertEquals($finished, $txt); @@ -269,8 +305,9 @@ FIN; * @param boolean $saveDb True, if the db credentials should get saved to the file * @param boolean $default True, if we use the default values * @param boolean $defaultDb True, if we use the default value for the DB + * @param boolean $realBasepath True, if we use the real basepath of the installation, not the mocked one */ - public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true) + public function assertConfig($assertion = null, $saveDb = false, $default = true, $defaultDb = true, $realBasepath = false) { if (!empty($assertion['database']['hostname'])) { $assertion['database']['hostname'] .= (!empty($assertion['database']['port']) ? ':' . $assertion['database']['port'] : ''); @@ -283,18 +320,35 @@ FIN; $this->assertConfigEntry('config', 'admin_email', $assertion); $this->assertConfigEntry('config', 'php_path', trim(shell_exec('which php'))); + $this->assertConfigEntry('config', 'hostname', $assertion); $this->assertConfigEntry('system', 'default_timezone', $assertion, ($default) ? Installer::DEFAULT_TZ : null); $this->assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null); + $this->assertConfigEntry('system', 'url', $assertion); + $this->assertConfigEntry('system', 'urlpath', $assertion); + $this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? SSL_POLICY_NONE : null); + $this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion); } /** * Test the automatic installation without any parameter/setting + * Should stuck because of missing hostname */ public function testEmpty() { - $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once(); + $console = new AutomaticInstallation($this->consoleArgv); + $txt = $this->dumpExecute($console); + + $this->assertStuckHostnam($txt); + } + + /** + * Test the automatic installation without any parameter/setting + * except hostname + */ + public function testEmptyWithHostname() + { $this->mockConnect(true, 1); $this->mockConnected(true, 1); $this->mockExistsTable('user', false, 1); @@ -304,13 +358,14 @@ FIN; $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); $console = new AutomaticInstallation($this->consoleArgv); + $console->setOption('n', 'friendica.local'); $txt = $this->dumpExecute($console); $this->assertFinished($txt, true, false); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); - $this->assertConfig(); + $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local']], false, true, true, true); } /** @@ -356,12 +411,16 @@ return [ 'config' => [ 'admin_email' => '{$conf('config', 'admin_email')}', + 'hostname' => '{$conf('config', 'hostname')}', 'sitename' => 'Friendica Social Network', 'register_policy' => \Friendica\Module\Register::OPEN, 'register_text' => '', ], 'system' => [ + 'basepath' => '{$conf('system', 'basepath')}', 'urlpath' => '{$conf('system', 'urlpath')}', + 'url' => '{$conf('system', 'url')}', + 'ssl_policy' => '{$conf('system', 'ssl_policy')}', 'default_timezone' => '{$conf('system', 'default_timezone')}', 'language' => '{$conf('system', 'language')}', ], @@ -392,8 +451,6 @@ CONF; */ public function testWithEnvironmentAndSave(array $data) { - $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once(); - $this->mockConnect(true, 1); $this->mockConnected(true, 1); $this->mockExistsTable('user', false, 1); @@ -408,11 +465,14 @@ CONF; $this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username'])); $this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password'])); + $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname'])); + $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath'])); $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath'])); $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path'])); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email'])); $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone'])); $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language'])); + $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy'])); $console = new AutomaticInstallation($this->consoleArgv); $console->setOption('savedb', true); @@ -420,7 +480,7 @@ CONF; $txt = $this->dumpExecute($console); $this->assertFinished($txt, true); - $this->assertConfig($data, true, true, false); + $this->assertConfig($data, true, true, false, true); } /** @@ -430,8 +490,6 @@ CONF; */ public function testWithEnvironmentWithoutSave(array $data) { - $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once(); - $this->mockConnect(true, 1); $this->mockConnected(true, 1); $this->mockExistsTable('user', false, 1); @@ -446,18 +504,21 @@ CONF; $this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username'])); $this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password'])); - $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath'])); - $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path'])); + $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname'])); + $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath'])); + $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath'])); + $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path'])); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email'])); - $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone'])); - $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language'])); + $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone'])); + $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language'])); + $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy'])); $console = new AutomaticInstallation($this->consoleArgv); $txt = $this->dumpExecute($console); $this->assertFinished($txt, true); - $this->assertConfig($data, false, true); + $this->assertConfig($data, false, true, false, true); } /** @@ -466,8 +527,6 @@ CONF; */ public function testWithArguments(array $data) { - $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once(); - $this->mockConnect(true, 1); $this->mockConnected(true, 1); $this->mockExistsTable('user', false, 1); @@ -483,21 +542,24 @@ CONF; $console->setOption($var, $data[$cat][$key]); } }; - $option('dbhost' , 'database', 'hostname'); - $option('dbport' , 'database', 'port'); - $option('dbuser' , 'database', 'username'); - $option('dbpass' , 'database', 'password'); - $option('dbdata' , 'database', 'database'); - $option('urlpath' , 'system' , 'urlpath'); - $option('phppath' , 'config' , 'php_path'); - $option('admin' , 'config' , 'admin_email'); - $option('tz' , 'system' , 'default_timezone'); - $option('lang' , 'system' , 'language'); + $option('dbhost' , 'database', 'hostname'); + $option('dbport' , 'database', 'port'); + $option('dbuser' , 'database', 'username'); + $option('dbpass' , 'database', 'password'); + $option('dbdata' , 'database', 'database'); + $option('urlpath' , 'system' , 'urlpath'); + $option('phppath' , 'config' , 'php_path'); + $option('admin' , 'config' , 'admin_email'); + $option('tz' , 'system' , 'default_timezone'); + $option('lang' , 'system' , 'language'); + $option('hostname' , 'config' , 'hostname'); + $option('basepath' , 'system' , 'basepath'); + $option('sslpolicy' , 'system' , 'ssl_policy'); $txt = $this->dumpExecute($console); $this->assertFinished($txt, true); - $this->assertConfig($data, true, true, true); + $this->assertConfig($data, true, true, true, true); } /** @@ -505,20 +567,20 @@ CONF; */ public function testNoDatabaseConnection() { - $this->app->shouldReceive('getURLPath')->andReturn('')->atLeast()->once(); $this->mockConnect(false, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); $console = new AutomaticInstallation($this->consoleArgv); + $console->setOption('n', 'friendica.local'); $txt = $this->dumpExecute($console); $this->assertStuckDB($txt); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); - $this->assertConfig(null, false, true, false); + $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local']], false, true, false, true); } public function testGetHelp() @@ -540,17 +602,19 @@ Options -v Show more debug information. -a All setup checks are required (except .htaccess) -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) - -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) - -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) - -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -u|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) - -b|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -A|--admin The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL) - -T|--tz The timezone of Friendica (env FRIENDICA_TZ) - -L|--lang The language of Friendica (env FRIENDICA_LANG) + -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) + -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) + -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) + -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) + -U|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) + -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) + -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -S|--sslpolicy The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) + -n|--hostname The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) + -t|--tz The timezone of Friendica (env FRIENDICA_TZ) + -L|--lang The language of Friendica (env FRIENDICA_LANG) Environment variables MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) @@ -558,9 +622,12 @@ Environment variables MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database - FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - FRIENDICA_PHP_PATH The path of the PHP binary + FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection + FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection + FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) + FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL) + FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index e56596c6c0..a238bf8e7d 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -3,6 +3,7 @@ // this is in the same namespace as Install for mocking 'function_exists' namespace Friendica\Core; +use Friendica\Core\Config\Cache\IConfigCache; use Friendica\Network\CurlResult; use Friendica\Object\Image; use Friendica\Test\MockedTest; @@ -392,6 +393,21 @@ class InstallerTest extends MockedTest false, $install->getChecks()); } + + /** + * Test the setup of the config cache for installation + */ + public function testSetUpCache() + { + $this->mockL10nT(); + + $install = new Installer(); + $configCache = \Mockery::mock(IConfigCache::class); + $configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once(); + $configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once(); + + $install->setUpCache($configCache, '/test/'); + } } /** diff --git a/tests/src/Database/DBATest.php b/tests/src/Database/DBATest.php index 21ccd1df1f..36bba1e65b 100644 --- a/tests/src/Database/DBATest.php +++ b/tests/src/Database/DBATest.php @@ -20,7 +20,7 @@ class DBATest extends DatabaseTest $configLoader = new ConfigFileLoader($basePath, $mode); $configCache = Factory\ConfigFactory::createCache($configLoader); $profiler = Factory\ProfilerFactory::create($configCache); - Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER); + Factory\DBFactory::init($configCache, $profiler, $_SERVER); $config = Factory\ConfigFactory::createConfig($configCache); Factory\ConfigFactory::createPConfig($configCache); $logger = Factory\LoggerFactory::create('test', $config, $profiler); diff --git a/tests/src/Database/DBStructureTest.php b/tests/src/Database/DBStructureTest.php index 4bf4ed51c4..6050b7073a 100644 --- a/tests/src/Database/DBStructureTest.php +++ b/tests/src/Database/DBStructureTest.php @@ -20,7 +20,7 @@ class DBStructureTest extends DatabaseTest $configLoader = new ConfigFileLoader($basePath, $mode); $configCache = Factory\ConfigFactory::createCache($configLoader); $profiler = Factory\ProfilerFactory::create($configCache); - Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER); + Factory\DBFactory::init($configCache, $profiler, $_SERVER); $config = Factory\ConfigFactory::createConfig($configCache); Factory\ConfigFactory::createPConfig($configCache); $logger = Factory\LoggerFactory::create('test', $config, $profiler); diff --git a/tests/src/Util/BasePathTest.php b/tests/src/Util/BasePathTest.php new file mode 100644 index 0000000000..bb23cb650d --- /dev/null +++ b/tests/src/Util/BasePathTest.php @@ -0,0 +1,29 @@ + '/invalid', 'PWD' => '/invalid2']; + $this->assertEquals('/valid', BasePath::create('/valid', $serverArr)); + } + + /** + * Test the basepath determination with DOCUMENT_ROOT and PWD + */ + public function testDetermineBasePathWithServer() + { + $serverArr = ['DOCUMENT_ROOT' => '/valid']; + $this->assertEquals('/valid', BasePath::create('', $serverArr)); + + $serverArr = ['PWD' => '/valid_too']; + $this->assertEquals('/valid_too', BasePath::create('', $serverArr)); + } +} diff --git a/view/templates/install_base.tpl b/view/templates/install_base.tpl new file mode 100644 index 0000000000..712488fb7e --- /dev/null +++ b/view/templates/install_base.tpl @@ -0,0 +1,34 @@ +

{{$title}}

+

{{$pass}}

+ +

+ {{$info_01}}
+ {{$info_02}}
+ {{$info_03}} +

+ + + {{foreach $checks as $check}} +
{{$check.title}} + {{if ! $check.status}} + Requirement not satisfied + {{/if}} + {{/foreach}} +
+ +
+ + + + + {{include file="field_select.tpl" field=$ssl_policy}} +
+ {{include file="field_input.tpl" field=$hostname}} +
+ {{include file="field_input.tpl" field=$basepath}} +
+ {{include file="field_input.tpl" field=$urlpath}} + + + +
diff --git a/view/templates/install_db.tpl b/view/templates/install_db.tpl index 5c28f0e5f7..1a5778cc83 100644 --- a/view/templates/install_db.tpl +++ b/view/templates/install_db.tpl @@ -19,7 +19,11 @@
- + + + + + {{include file="field_input.tpl" field=$dbhost}} {{include file="field_input.tpl" field=$dbuser}} diff --git a/view/templates/install_settings.tpl b/view/templates/install_settings.tpl index 2f28a25c6f..e17ef2456b 100644 --- a/view/templates/install_settings.tpl +++ b/view/templates/install_settings.tpl @@ -7,14 +7,18 @@ + + + + - + -{{include file="field_input.tpl" field=$adminmail}} -{{$timezone nofilter}} +{{include file="field_input.tpl" field=$adminmail}}
+{{$timezone nofilter}}
{{include file="field_select.tpl" field=$language}} diff --git a/view/templates/local.config.tpl b/view/templates/local.config.tpl index 3201a99854..05c87056c6 100644 --- a/view/templates/local.config.tpl +++ b/view/templates/local.config.tpl @@ -24,11 +24,14 @@ return [ 'php_path' => '{{$phpath}}', 'admin_email' => '{{$adminmail}}', 'sitename' => 'Friendica Social Network', + 'hostname' => '{{$hostname}}', 'register_policy' => \Friendica\Module\Register::OPEN, 'max_import_size' => 200000, ], 'system' => [ 'urlpath' => '{{$urlpath}}', + 'url' => '{{$baseurl}}', + 'ssl_policy' => {{$sslpolicy}}, 'basepath' => '{{$basepath}}', 'default_timezone' => '{{$timezone}}', 'language' => '{{$language}}', From 677cb205f50bf27757a6d7c5a810835b5690b63d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 21:46:06 +0200 Subject: [PATCH 02/12] fix auto install --- src/App.php | 10 ++++++ src/Core/Console/AutomaticInstallation.php | 30 +++++++--------- src/Core/Installer.php | 8 +++-- src/Core/Renderer.php | 11 +++--- test.config.php | 42 ++++++++++++++++++++++ 5 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 test.config.php diff --git a/src/App.php b/src/App.php index 1123f67b06..c0cc1617d0 100644 --- a/src/App.php +++ b/src/App.php @@ -138,6 +138,16 @@ class App return $this->config->getCache(); } + /** + * Returns the current config of this nodde + * + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + /** * The basepath of this app * diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 34a933e12e..50da333625 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -7,6 +7,8 @@ use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Installer; use Friendica\Core\Theme; +use Friendica\Util\BasePath; +use Friendica\Util\BaseURL; use Friendica\Util\Config\ConfigFileLoader; use RuntimeException; @@ -36,11 +38,9 @@ Options -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -U|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) + -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) - -S|--sslpolicy The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) - -n|--hostname The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) -t|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) @@ -50,12 +50,10 @@ Environment variables MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database - FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection + FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub' FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) - FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL) - FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica @@ -81,7 +79,7 @@ HELP; $installer = new Installer(); $configCache = $a->getConfigCache(); - $installer->setUpCache($configCache, dirname(__DIR__, 3), $_SERVER); + $installer->setUpCache($configCache, BasePath::create($a->getBasePath(), $_SERVER)); $this->out(" Complete!\n\n"); @@ -119,7 +117,6 @@ HELP; $save_db = $this->getOption(['s', 'savedb'], false); - //$db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST') ? getenv('MYSQL_HOST') : Installer::DEFAULT_HOST) : ''); $db_host = $this->getOption(['H', 'dbhost'], ($save_db) ? (getenv('MYSQL_HOST')) : Installer::DEFAULT_HOST); $db_port = $this->getOption(['p', 'dbport'], ($save_db) ? getenv('MYSQL_PORT') : null); $configCache->set('database', 'hostname', $db_host . (!empty($db_port) ? ':' . $db_port : '')); @@ -149,7 +146,6 @@ HELP; $this->getOption(['L', 'lang'], !empty(getenv('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : Installer::DEFAULT_LANG)); - $configCache->set('system', 'urlpath', $this->getOption(['u', 'urlpath'], !empty(getenv('FRIENDICA_URL_PATH')) ? getenv('FRIENDICA_URL_PATH') : '')); $basepath = $this->getOption(['b', 'basepath'], !empty(getenv('FRIENDICA_BASE_PATH')) ? getenv('FRIENDICA_BASE_PATH') : null); if (!empty($basepath)) { $configCache->set('system', 'basepath', $basepath); @@ -158,20 +154,20 @@ HELP; if (!empty($php_path)) { $configCache->set('config', 'php_path', $php_path); } - $ssl_policy = $this->getOption(['S', 'sslpolicy'], !empty(getenv('FRIENDICA_SSL_POLICY')) ? getenv('FRIENDICA_SSL_POLICY') : null); - if (!empty($ssl_policy)) { - $configCache->set('system', 'ssl_policy', $ssl_policy); - } - $configCache->set('config', 'hostname', $this->getOption(['n', 'hostname'], !empty(getenv('FRIENDICA_HOSTNAME')) ? getenv('FRIENDICA_HOSTNAME') : '')); - $configCache->set('system', 'url', $installer->determineBaseUrl($configCache)); + $url = $this->getOption(['U', 'url'], !empty(getenv('FRIENDICA_URL')) ? getenv('FRIENDICA_URL') : null); - if (empty($configCache->get('config', 'hostname'))) { - $this->out('The Friendica hostname has to be set during CLI installation.'); + if (empty($url)) { + $this->out('The Friendica URL has to be set during CLI installation.'); return 1; + } else { + $baseUrl = new BaseURL($a->getConfig(), []); + $baseUrl->saveByURL($url); } $installer->createConfig($configCache); + + return 1; } $this->out(" Complete!\n\n"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 52a51498e8..be725056d1 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -140,6 +140,10 @@ class Installer { $basepath = $configCache->get('system', 'basepath'); + $url = $configCache->get('system', 'url'); + + print_r("URL - " . $url . PHP_EOL); + $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$dbhost' => $configCache->get('database', 'hostname'), @@ -152,12 +156,12 @@ class Installer '$hostname' => $configCache->get('config', 'hostname'), '$urlpath' => $configCache->get('system', 'urlpath'), - '$baseurl' => $configCache->get('system', 'url'), + '$baseurl' => $url, '$sslpolicy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $basepath, '$timezone' => $configCache->get('system', 'default_timezone'), '$language' => $configCache->get('system', 'language'), - ]); + ], false); $result = file_put_contents($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php', $txt); diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 8844f26881..ef3665d748 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -52,19 +52,22 @@ class Renderer extends BaseObject /** * @brief This is our template processor * - * @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty - * @param array $vars key value pairs (search => replace) + * @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty + * @param array $vars key value pairs (search => replace) + * @param bool $overwriteURL Overwrite the base url with the system wide set base url * * @return string substituted string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function replaceMacros($s, $vars) + public static function replaceMacros($s, $vars, $overwriteURL = true) { $stamp1 = microtime(true); $a = self::getApp(); // pass $baseurl to all templates - $vars['$baseurl'] = System::baseUrl(); + if ($overwriteURL) { + $vars['$baseurl'] = System::baseUrl(); + } $t = self::getTemplateEngine(); try { diff --git a/test.config.php b/test.config.php new file mode 100644 index 0000000000..df2073ae77 --- /dev/null +++ b/test.config.php @@ -0,0 +1,42 @@ + [ + 'hostname' => 'localhost', + 'username' => 'friendica', + 'password' => 'friendica', + 'database' => 'friendica', + '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' => '/usr/bin/php', + 'admin_email' => '', + 'sitename' => 'Friendica Social Network', + 'hostname' => 'friendica.local', + 'register_policy' => \Friendica\Module\Register::OPEN, + 'max_import_size' => 200000, + ], + 'system' => [ + 'urlpath' => 'test', + 'url' => 'https://friendica.local/test', + 'ssl_policy' => 1, + 'basepath' => '/vagrant', + 'default_timezone' => 'America/Los_Angeles', + 'language' => 'en', + 'debugging' => true, + 'logfile' => 'friendica.log', + 'loglevel' => 'info', + ], +]; From 3a0664d827ba8aa2ba7c2c2aa8472fa0ff4007cf Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 21:59:05 +0200 Subject: [PATCH 03/12] fixing auto install tests --- src/Core/Console/AutomaticInstallation.php | 2 - src/Core/Installer.php | 2 - tests/Util/AppMockTrait.php | 3 ++ tests/Util/RendererMockTrait.php | 35 +++++++----- .../AutomaticInstallationConsoleTest.php | 53 ++++++++----------- 5 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 50da333625..ed890f3c05 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -166,8 +166,6 @@ HELP; } $installer->createConfig($configCache); - - return 1; } $this->out(" Complete!\n\n"); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index be725056d1..a8f45e0b7c 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -142,8 +142,6 @@ class Installer $url = $configCache->get('system', 'url'); - print_r("URL - " . $url . PHP_EOL); - $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$dbhost' => $configCache->get('database', 'hostname'), diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index 0bbacaf48d..03e8085479 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -69,6 +69,9 @@ trait AppMockTrait $this->app ->shouldReceive('getConfigCache') ->andReturn($this->configMock); + $this->app + ->shouldReceive('getConfig') + ->andReturn($config); $this->app ->shouldReceive('getTemplateEngine') ->andReturn(new FriendicaSmartyEngine()); diff --git a/tests/Util/RendererMockTrait.php b/tests/Util/RendererMockTrait.php index b0fa8132c9..403f25f14d 100644 --- a/tests/Util/RendererMockTrait.php +++ b/tests/Util/RendererMockTrait.php @@ -15,9 +15,9 @@ trait RendererMockTrait /** * Mocking the method 'Renderer::getMarkupTemplate()' * - * @param string $templateName The name of the template which should get - * @param string $return the return value of the mock (should be defined to have it later for followUp use) - * @param null|int $times How often the method will get used + * @param string $templateName The name of the template which should get + * @param string $return the return value of the mock (should be defined to have it later for followUp use) + * @param null|int $times How often the method will get used */ public function mockGetMarkupTemplate($templateName, $return = '', $times = null) { @@ -35,12 +35,13 @@ trait RendererMockTrait /** * Mocking the method 'Renderer::replaceMacros()' * - * @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()' - * @param array|\Closure|null $args The arguments to pass to the macro - * @param string $return the return value of the mock - * @param null|int $times How often the method will get used + * @param string $template The template to use (normally, it is the mock result of 'mockGetMarkupTemplate()' + * @param array|\Closure|null $args The arguments to pass to the macro + * @param bool $overwriteURL if the URL should get overwritten + * @param string $return the return value of the mock + * @param null|int $times How often the method will get used */ - public function mockReplaceMacros($template, $args = null, $return = '', $times = null) + public function mockReplaceMacros($template, $args = null, $overwriteURL = true, $return = '', $times = null) { if (!isset($this->rendererMock)) { $this->rendererMock = \Mockery::mock('alias:' . Renderer::class); @@ -50,10 +51,18 @@ trait RendererMockTrait $args = []; } - $this->rendererMock - ->shouldReceive('replaceMacros') - ->with($template, $args) - ->times($times) - ->andReturn($return); + if ($overwriteURL) { + $this->rendererMock + ->shouldReceive('replaceMacros') + ->with($template, $args) + ->times($times) + ->andReturn($return); + } else { + $this->rendererMock + ->shouldReceive('replaceMacros') + ->with($template, $args, false) + ->times($times) + ->andReturn($return); + } } } diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 30c8b4b850..aaca4b8b05 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -10,13 +10,12 @@ use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\L10nMockTrait; use Friendica\Test\Util\RendererMockTrait; +use Friendica\Util\BaseURL; use Friendica\Util\Logger\VoidLogger; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamFile; /** - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled * @requires PHP 7.0 */ class AutomaticInstallationConsoleTest extends ConsoleTest @@ -104,7 +103,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest 'basepath' => '', 'urlpath' => '', 'url' => 'http://friendica.local', - 'ssl_policy' => '', + 'ssl_policy' => 0, 'default_timezone' => '', 'language' => '', ], @@ -253,7 +252,7 @@ FIN; $this->assertEquals($finished, $txt); } - private function assertStuckHostnam($txt) + private function assertStuckURL($txt) { $finished = <<assertConfigEntry('system', 'language', $assertion, ($default) ? Installer::DEFAULT_LANG : null); $this->assertConfigEntry('system', 'url', $assertion); $this->assertConfigEntry('system', 'urlpath', $assertion); - $this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? SSL_POLICY_NONE : null); + $this->assertConfigEntry('system', 'ssl_policy', $assertion, ($default) ? BaseURL::DEFAULT_SSL_SCHEME : null); $this->assertConfigEntry('system', 'basepath', ($realBasepath) ? $this->root->url() : $assertion); } @@ -340,14 +339,14 @@ FIN; $txt = $this->dumpExecute($console); - $this->assertStuckHostnam($txt); + $this->assertStuckURL($txt); } /** * Test the automatic installation without any parameter/setting - * except hostname + * except URL */ - public function testEmptyWithHostname() + public function testEmptyWithURL() { $this->mockConnect(true, 1); $this->mockConnected(true, 1); @@ -355,17 +354,17 @@ FIN; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1); $console = new AutomaticInstallation($this->consoleArgv); - $console->setOption('n', 'friendica.local'); + $console->setOption('url', 'http://friendica.local'); $txt = $this->dumpExecute($console); $this->assertFinished($txt, true, false); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); - $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local']], false, true, true, true); + $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlPath' => '']], false, true, true, true); } /** @@ -457,7 +456,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1); $this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname'])); $this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port'])); @@ -467,12 +466,11 @@ CONF; $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname'])); $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath'])); - $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath'])); + $this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url'])); $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path'])); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email'])); $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone'])); $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language'])); - $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy'])); $console = new AutomaticInstallation($this->consoleArgv); $console->setOption('savedb', true); @@ -496,7 +494,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1); $this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname'])); $this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port'])); @@ -506,12 +504,11 @@ CONF; $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname'])); $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath'])); - $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath'])); + $this->assertTrue(putenv('FRIENDICA_URL=' . $data['system']['url'])); $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path'])); $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email'])); $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone'])); $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language'])); - $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy'])); $console = new AutomaticInstallation($this->consoleArgv); @@ -533,7 +530,7 @@ CONF; $this->mockUpdate([$this->root->url(), false, true, true], null, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1); $console = new AutomaticInstallation($this->consoleArgv); @@ -547,14 +544,12 @@ CONF; $option('dbuser' , 'database', 'username'); $option('dbpass' , 'database', 'password'); $option('dbdata' , 'database', 'database'); - $option('urlpath' , 'system' , 'urlpath'); + $option('url' , 'system' , 'url'); $option('phppath' , 'config' , 'php_path'); $option('admin' , 'config' , 'admin_email'); $option('tz' , 'system' , 'default_timezone'); $option('lang' , 'system' , 'language'); - $option('hostname' , 'config' , 'hostname'); $option('basepath' , 'system' , 'basepath'); - $option('sslpolicy' , 'system' , 'ssl_policy'); $txt = $this->dumpExecute($console); @@ -570,17 +565,17 @@ CONF; $this->mockConnect(false, 1); $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1); - $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1); + $this->mockReplaceMacros('testTemplate', \Mockery::any(), false, '', 1); $console = new AutomaticInstallation($this->consoleArgv); - $console->setOption('n', 'friendica.local'); + $console->setOption('url', 'http://friendica.local'); $txt = $this->dumpExecute($console); $this->assertStuckDB($txt); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')); - $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local']], false, true, false, true); + $this->assertConfig(['config' => ['hostname' => 'friendica.local'], 'system' => ['url' => 'http://friendica.local', 'ssl_policy' => 0, 'urlpath' => '']], false, true, false, true); } public function testGetHelp() @@ -608,11 +603,9 @@ Options -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -U|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) + -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) - -S|--sslpolicy The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) - -n|--hostname The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME) -t|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) @@ -622,12 +615,10 @@ Environment variables MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database - FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection + FRIENDICA_URL The full base URL of Friendica - f.e. 'https://friendica.local/sub' FRIENDICA_PHP_PATH The path of the PHP binary - leave empty for auto detection FRIENDICA_BASE_PATH The basepath of Friendica - leave empty for auto detection FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) - FRIENDICA_SSL_POLICY The SSL policy of Friendica (default is NO SSL) - FRIENDICA_HOSTNAME The hostname of Friendica - leave empty for auto detection FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica From f2b2451bcceeb963c6185eb8efa5e7d9beac62f6 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 21:59:52 +0200 Subject: [PATCH 04/12] adding annotation --- tests/src/Core/Console/AutomaticInstallationConsoleTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index aaca4b8b05..048a99e81a 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -16,6 +16,8 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamFile; /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled * @requires PHP 7.0 */ class AutomaticInstallationConsoleTest extends ConsoleTest From 8fe606660df0fb32ebdc1693ea2a1de813850647 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 22:06:05 +0200 Subject: [PATCH 05/12] trim whitespaces --- src/Core/Console/AutomaticInstallation.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index ed890f3c05..2aacc11094 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -32,17 +32,17 @@ Options -v Show more debug information. -a All setup checks are required (except .htaccess) -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) - -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) - -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) - -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) - -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) - -t|--tz The timezone of Friendica (env FRIENDICA_TZ) - -L|--lang The language of Friendica (env FRIENDICA_LANG) + -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) + -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) + -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) + -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) + -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) + -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) + -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -t|--tz The timezone of Friendica (env FRIENDICA_TZ) + -L|--lang The language of Friendica (env FRIENDICA_LANG) Environment variables MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) From 288af6c896445727148ac19db079738c68bd5ea9 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 22:14:10 +0200 Subject: [PATCH 06/12] remove test config --- test.config.php | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 test.config.php diff --git a/test.config.php b/test.config.php deleted file mode 100644 index df2073ae77..0000000000 --- a/test.config.php +++ /dev/null @@ -1,42 +0,0 @@ - [ - 'hostname' => 'localhost', - 'username' => 'friendica', - 'password' => 'friendica', - 'database' => 'friendica', - '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' => '/usr/bin/php', - 'admin_email' => '', - 'sitename' => 'Friendica Social Network', - 'hostname' => 'friendica.local', - 'register_policy' => \Friendica\Module\Register::OPEN, - 'max_import_size' => 200000, - ], - 'system' => [ - 'urlpath' => 'test', - 'url' => 'https://friendica.local/test', - 'ssl_policy' => 1, - 'basepath' => '/vagrant', - 'default_timezone' => 'America/Los_Angeles', - 'language' => 'en', - 'debugging' => true, - 'logfile' => 'friendica.log', - 'loglevel' => 'info', - ], -]; From 5c57f2b09a4b7e051aa0e4602ae47e26e22baaa9 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 22:47:47 +0200 Subject: [PATCH 07/12] adapt help for tests --- .../AutomaticInstallationConsoleTest.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 048a99e81a..dcf052b304 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -599,17 +599,17 @@ Options -v Show more debug information. -a All setup checks are required (except .htaccess) -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) - -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) - -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) - -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) - -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) - -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) - -t|--tz The timezone of Friendica (env FRIENDICA_TZ) - -L|--lang The language of Friendica (env FRIENDICA_LANG) + -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) + -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) + -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) + -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) + -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) + -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) + -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -t|--tz The timezone of Friendica (env FRIENDICA_TZ) + -L|--lang The language of Friendica (env FRIENDICA_LANG) Environment variables MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) From d90eb6a811cfb57dfbe1de295f494de3bfee0e09 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 13 Apr 2019 22:51:45 +0200 Subject: [PATCH 08/12] Remove php_path duplicate in auto-install --- src/Core/Console/AutomaticInstallation.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 2aacc11094..561b05a1d2 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -129,6 +129,7 @@ HELP; $configCache->set('database', 'password', $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : '')); + $php_path = $this->getOption(['b', 'phppath'], !empty('FRIENDICA_PHP_PATH') ? getenv('FRIENDICA_PHP_PATH') : null); if (!empty($php_path)) { $configCache->set('config', 'php_path', $php_path); @@ -150,10 +151,6 @@ HELP; if (!empty($basepath)) { $configCache->set('system', 'basepath', $basepath); } - $php_path = $this->getOption(['B', 'phppath'], !empty(getenv('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : null); - if (!empty($php_path)) { - $configCache->set('config', 'php_path', $php_path); - } $url = $this->getOption(['U', 'url'], !empty(getenv('FRIENDICA_URL')) ? getenv('FRIENDICA_URL') : null); From d579d9e1d0d82a011e2513b34f1b6e0330fe7937 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Apr 2019 13:54:36 +0200 Subject: [PATCH 09/12] Add basepath to vagrant config file --- mods/local.config.vagrant.php | 83 ++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/mods/local.config.vagrant.php b/mods/local.config.vagrant.php index a9b95d02d7..c35b1a33d1 100644 --- a/mods/local.config.vagrant.php +++ b/mods/local.config.vagrant.php @@ -1,41 +1,42 @@ - [ - 'hostname' => 'localhost', - 'username' => 'friendica', - 'password' => 'friendica', - 'database' => 'friendica', - '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' => \Friendica\Module\Register::OPEN, - 'register_text' => '', - ], - 'system' => [ - 'default_timezone' => 'UTC', - 'language' => 'en', - ], -]; + [ + 'hostname' => 'localhost', + 'username' => 'friendica', + 'password' => 'friendica', + 'database' => 'friendica', + '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' => \Friendica\Module\Register::OPEN, + 'register_text' => '', + ], + 'system' => [ + 'default_timezone' => 'UTC', + 'language' => 'en', + 'basepath' => '/vagrant', + ], +]; From 58c9566c3d086583a1a55901c8c1c865d5f94891 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Apr 2019 14:05:48 +0200 Subject: [PATCH 10/12] code style & install-403 fix --- src/App.php | 2 +- src/Core/Console/AutomaticInstallation.php | 2 +- src/Core/Installer.php | 3 +- src/Core/Renderer.php | 88 ++++----- src/Module/Install.php | 174 +++++++++--------- .../AutomaticInstallationConsoleTest.php | 2 +- 6 files changed, 138 insertions(+), 133 deletions(-) diff --git a/src/App.php b/src/App.php index c0cc1617d0..fddfb0a6da 100644 --- a/src/App.php +++ b/src/App.php @@ -139,7 +139,7 @@ class App } /** - * Returns the current config of this nodde + * Returns the current config of this node * * @return Configuration */ diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index 561b05a1d2..e2857d6517 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -40,7 +40,7 @@ Options -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -b|--basepath The basepath of Friendica (env FRIENDICA_BASE_PATH) -t|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) diff --git a/src/Core/Installer.php b/src/Core/Installer.php index a8f45e0b7c..2df398fb0d 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -249,8 +249,9 @@ class Installer $help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; $help .= EOL . EOL; $tpl = Renderer::getMarkupTemplate('field_input.tpl'); + /// @todo Separate backend Installer class and presentation layer/view $help .= Renderer::replaceMacros($tpl, [ - '$field' => ['config.php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], + '$field' => ['config-php_path', L10n::t('PHP executable path'), $phppath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], ]); $phppath = ""; } diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index ef3665d748..72073086ab 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -15,17 +15,17 @@ use Friendica\Render\ITemplateEngine; */ class Renderer extends BaseObject { - /** + /** * @brief An array of registered template engines ('name'=>'class name') */ - public static $template_engines = []; + public static $template_engines = []; - /** + /** * @brief An array of instanced template engines ('name'=>'instance') */ public static $template_engine_instance = []; - /** + /** * @brief An array for all theme-controllable parameters * * Mostly unimplemented yet. Only options 'template_engine' and @@ -39,15 +39,15 @@ class Renderer extends BaseObject 'stylesheet' => '', 'template_engine' => 'smarty3', ]; - - private static $ldelim = [ + + private static $ldelim = [ 'internal' => '', 'smarty3' => '{{' ]; private static $rdelim = [ 'internal' => '', 'smarty3' => '}}' - ]; + ]; /** * @brief This is our template processor @@ -59,28 +59,28 @@ class Renderer extends BaseObject * @return string substituted string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function replaceMacros($s, $vars, $overwriteURL = true) - { - $stamp1 = microtime(true); - $a = self::getApp(); + public static function replaceMacros($s, $vars, $overwriteURL = true) + { + $stamp1 = microtime(true); + $a = self::getApp(); - // pass $baseurl to all templates + // pass $baseurl to all templates if ($overwriteURL) { $vars['$baseurl'] = System::baseUrl(); } - $t = self::getTemplateEngine(); + $t = self::getTemplateEngine(); - try { - $output = $t->replaceMacros($s, $vars); - } catch (Exception $e) { - echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; - exit(); - } + try { + $output = $t->replaceMacros($s, $vars); + } catch (Exception $e) { + echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; + exit(); + } $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack()); - return $output; - } + return $output; + } /** * @brief Load a given template $s @@ -91,35 +91,35 @@ class Renderer extends BaseObject * @return string template. * @throws Exception */ - public static function getMarkupTemplate($s, $root = '') - { - $stamp1 = microtime(true); - $a = self::getApp(); - $t = self::getTemplateEngine(); + public static function getMarkupTemplate($s, $root = '') + { + $stamp1 = microtime(true); + $a = self::getApp(); + $t = self::getTemplateEngine(); - try { - $template = $t->getTemplateFile($s, $root); - } catch (Exception $e) { - echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; - exit(); - } + try { + $template = $t->getTemplateFile($s, $root); + } catch (Exception $e) { + echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; + exit(); + } - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); - return $template; - } + return $template; + } - /** + /** * @brief Register template engine class * * @param string $class */ public static function registerTemplateEngine($class) { - $v = get_class_vars($class); - - if (!empty($v['name'])) - { + $v = get_class_vars($class); + + if (!empty($v['name'])) + { $name = $v['name']; self::$template_engines[$name] = $class; } else { @@ -153,9 +153,9 @@ class Renderer extends BaseObject echo "template engine $template_engine is not registered!\n"; exit(); - } - - /** + } + + /** * @brief Returns the active template engine. * * @return string the active template engine @@ -175,7 +175,7 @@ class Renderer extends BaseObject self::$theme['template_engine'] = $engine; } - /** + /** * Gets the right delimiter for a template engine * * Currently: diff --git a/src/Module/Install.php b/src/Module/Install.php index 67677940f3..1402c58cd2 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -28,7 +28,7 @@ class Install extends BaseModule */ const DATABASE_CONFIG = 3; /** - * Step four - Adapat site settings + * Step four - Adapt site settings */ const SITE_SETTINGS = 4; /** @@ -50,6 +50,10 @@ class Install extends BaseModule { $a = self::getApp(); + if (!$a->getMode()->isInstall()) { + Core\System::httpExit(403); + } + // route: install/testrwrite // $baseurl/install/testrwrite to test if rewrite in .htaccess is working if ($a->getArgumentValue(1, '') == 'testrewrite') { @@ -160,15 +164,15 @@ class Install extends BaseModule $tpl = Renderer::getMarkupTemplate('install_checks.tpl'); $output .= Renderer::replaceMacros($tpl, [ - '$title' => $install_title, - '$pass' => L10n::t('System check'), - '$checks' => self::$installer->getChecks(), - '$passed' => $status, - '$see_install' => L10n::t('Please see the file "INSTALL.txt".'), - '$next' => L10n::t('Next'), - '$reload' => L10n::t('Check again'), - '$php_path' => $php_path, - '$baseurl' => $a->getBaseURL() + '$title' => $install_title, + '$pass' => L10n::t('System check'), + '$checks' => self::$installer->getChecks(), + '$passed' => $status, + '$see_install' => L10n::t('Please see the file "INSTALL.txt".'), + '$next' => L10n::t('Next'), + '$reload' => L10n::t('Check again'), + '$php_path' => $php_path, + '$baseurl' => $a->getBaseURL() ]); break; @@ -184,25 +188,25 @@ class Install extends BaseModule '$title' => $install_title, '$pass' => L10n::t('Base settings'), '$ssl_policy' => ['system-ssl_policy', - L10n::t("SSL link policy"), - $configCache->get('system', 'ssl_policy'), - L10n::t("Determines whether generated links should be forced to use SSL"), - $ssl_choices], + L10n::t("SSL link policy"), + $configCache->get('system', 'ssl_policy'), + L10n::t("Determines whether generated links should be forced to use SSL"), + $ssl_choices], '$hostname' => ['config-hostname', - L10n::t('Host name'), - $configCache->get('config', 'hostname'), - L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), - 'required'], + L10n::t('Host name'), + $configCache->get('config', 'hostname'), + L10n::t('Overwrite this field in case the determinated hostname isn\'t right, otherweise leave it as is.'), + 'required'], '$basepath' => ['system-basepath', - L10n::t("Base path to installation"), - $configCache->get('system', 'basepath'), - L10n::t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), - 'required'], + L10n::t("Base path to installation"), + $configCache->get('system', 'basepath'), + L10n::t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), + 'required'], '$urlpath' => ['system-urlpath', - L10n::t('Sub path of the URL'), - $configCache->get('system', 'urlpath'), - L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), - ''], + L10n::t('Sub path of the URL'), + $configCache->get('system', 'urlpath'), + L10n::t('Overwrite this field in case the sub path determination isn\'t right, otherwise leave it as is. Leaving this field blank means the installation is at the base URL without sub path.'), + ''], '$baseurl' => $a->getBaseURL(), '$php_path' => $configCache->get('config', 'php_path'), '$submit' => L10n::t('Submit'), @@ -212,41 +216,41 @@ class Install extends BaseModule case self::DATABASE_CONFIG: $tpl = Renderer::getMarkupTemplate('install_db.tpl'); $output .= Renderer::replaceMacros($tpl, [ - '$title' => $install_title, - '$pass' => L10n::t('Database connection'), - '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'), - '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'), - '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'), - 'checks' => self::$installer->getChecks(), + '$title' => $install_title, + '$pass' => L10n::t('Database connection'), + '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'), + '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'), + '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'), + 'checks' => self::$installer->getChecks(), '$hostname' => $configCache->get('config', 'hostname'), '$ssl_policy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $configCache->get('system', 'basepath'), '$urlpath' => $configCache->get('system', 'urlpath'), - '$dbhost' => ['database-hostname', - L10n::t('Database Server Name'), - $configCache->get('database', 'hostname'), - '', - 'required'], - '$dbuser' => ['database-username', - L10n::t('Database Login Name'), - $configCache->get('database', 'username'), - '', - 'required', - 'autofocus'], - '$dbpass' => ['database-password', - L10n::t('Database Login Password'), - $configCache->get('database', 'password'), - L10n::t("For security reasons the password must not be empty"), - 'required'], - '$dbdata' => ['database-database', - L10n::t('Database Name'), - $configCache->get('database', 'database'), - '', - 'required'], - '$lbl_10' => L10n::t('Please select a default timezone for your website'), - '$baseurl' => $a->getBaseURL(), - '$php_path' => $configCache->get('config', 'php_path'), - '$submit' => L10n::t('Submit') + '$dbhost' => ['database-hostname', + L10n::t('Database Server Name'), + $configCache->get('database', 'hostname'), + '', + 'required'], + '$dbuser ' => ['database-username', + L10n::t('Database Login Name'), + $configCache->get('database', 'username'), + '', + 'required', + 'autofocus'], + '$dbpass' => ['database-password', + L10n::t('Database Login Password'), + $configCache->get('database', 'password'), + L10n::t("For security reasons the password must not be empty"), + 'required'], + '$dbdata' => ['database-database', + L10n::t('Database Name'), + $configCache->get('database', 'database'), + '', + 'required'], + '$lbl_10' => L10n::t('Please select a default timezone for your website'), + '$baseurl' => $a->getBaseURL(), + '$php_path' => $configCache->get('config', 'php_path'), + '$submit' => L10n::t('Submit') ]); break; @@ -256,34 +260,34 @@ class Install extends BaseModule $tpl = Renderer::getMarkupTemplate('install_settings.tpl'); $output .= Renderer::replaceMacros($tpl, [ - '$title' => $install_title, - '$checks' => self::$installer->getChecks(), - '$pass' => L10n::t('Site settings'), - '$hostname' => $configCache->get('config', 'hostname'), - '$ssl_policy' => $configCache->get('system', 'ssl_policy'), - '$basepath' => $configCache->get('system', 'basepath'), - '$urlpath' => $configCache->get('system', 'urlpath'), - '$dbhost' => $configCache->get('database', 'hostname'), - '$dbuser' => $configCache->get('database', 'username'), - '$dbpass' => $configCache->get('database', 'password'), - '$dbdata' => $configCache->get('database', 'database'), - '$adminmail' => ['config-admin_email', - L10n::t('Site administrator email address'), - $configCache->get('config', 'admin_email'), - L10n::t('Your account email address must match this in order to use the web admin panel.'), - 'required', 'autofocus', 'email'], - '$timezone' => Temporal::getTimezoneField('system-default_timezone', - L10n::t('Please select a default timezone for your website'), - $configCache->get('system', 'default_timezone'), - ''), - '$language' => ['system-language', - L10n::t('System Language:'), - $configCache->get('system', 'language'), - L10n::t('Set the default language for your Friendica installation interface and to send emails.'), - $lang_choices], - '$baseurl' => $a->getBaseURL(), - '$php_path' => $configCache->get('config', 'php_path'), - '$submit' => L10n::t('Submit') + '$title' => $install_title, + '$checks' => self::$installer->getChecks(), + '$pass' => L10n::t('Site settings'), + '$hostname' => $configCache->get('config', 'hostname'), + '$ssl_policy' => $configCache->get('system', 'ssl_policy'), + '$basepath' => $configCache->get('system', 'basepath'), + '$urlpath' => $configCache->get('system', 'urlpath'), + '$dbhost' => $configCache->get('database', 'hostname'), + '$dbuser' => $configCache->get('database', 'username'), + '$dbpass' => $configCache->get('database', 'password'), + '$dbdata' => $configCache->get('database', 'database'), + '$adminmail' => ['config-admin_email', + L10n::t('Site administrator email address'), + $configCache->get('config', 'admin_email'), + L10n::t('Your account email address must match this in order to use the web admin panel.'), + 'required', 'autofocus', 'email'], + '$timezone' => Temporal::getTimezoneField('system-default_timezone', + L10n::t('Please select a default timezone for your website'), + $configCache->get('system', 'default_timezone'), + ''), + '$language' => ['system-language', + L10n::t('System Language:'), + $configCache->get('system', 'language'), + L10n::t('Set the default language for your Friendica installation interface and to send emails.'), + $lang_choices], + '$baseurl' => $a->getBaseURL(), + '$php_path' => $configCache->get('config', 'php_path'), + '$submit' => L10n::t('Submit') ]); break; diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index dcf052b304..9ed3d404f2 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -607,7 +607,7 @@ Options -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -U|--url The full base URL of Friendica - f.e. 'https://friendica.local/sub' (env FRIENDICA_URL) -B|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) - -b|--basepath The basepath of Friendica(env FRIENDICA_BASE_PATH) + -b|--basepath The basepath of Friendica (env FRIENDICA_BASE_PATH) -t|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) From 03e149270b65141e189096e64f1f0538867c1de5 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Apr 2019 14:40:26 +0200 Subject: [PATCH 11/12] bugfix --- src/Core/Installer.php | 5 +---- src/Module/Install.php | 2 +- src/Util/BaseURL.php | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 2df398fb0d..782a139e14 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -11,7 +11,6 @@ use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Object\Image; use Friendica\Util\Logger\VoidLogger; -use Friendica\Util\BasePath; use Friendica\Util\Network; use Friendica\Util\Profiler; use Friendica\Util\Strings; @@ -140,8 +139,6 @@ class Installer { $basepath = $configCache->get('system', 'basepath'); - $url = $configCache->get('system', 'url'); - $tpl = Renderer::getMarkupTemplate('local.config.tpl'); $txt = Renderer::replaceMacros($tpl, [ '$dbhost' => $configCache->get('database', 'hostname'), @@ -154,7 +151,7 @@ class Installer '$hostname' => $configCache->get('config', 'hostname'), '$urlpath' => $configCache->get('system', 'urlpath'), - '$baseurl' => $url, + '$baseurl' => $configCache->get('system', 'url'), '$sslpolicy' => $configCache->get('system', 'ssl_policy'), '$basepath' => $basepath, '$timezone' => $configCache->get('system', 'default_timezone'), diff --git a/src/Module/Install.php b/src/Module/Install.php index 1402c58cd2..65a30e894b 100644 --- a/src/Module/Install.php +++ b/src/Module/Install.php @@ -231,7 +231,7 @@ class Install extends BaseModule $configCache->get('database', 'hostname'), '', 'required'], - '$dbuser ' => ['database-username', + '$dbuser' => ['database-username', L10n::t('Database Login Name'), $configCache->get('database', 'username'), '', diff --git a/src/Util/BaseURL.php b/src/Util/BaseURL.php index cd703a9177..be34de30ec 100644 --- a/src/Util/BaseURL.php +++ b/src/Util/BaseURL.php @@ -285,7 +285,7 @@ class BaseURL if (empty($this->url)) { $this->determineBaseUrl(); - if (!empty($url)) { + if (!empty($this->url)) { $this->config->set('system', 'url', $this->url); } } From 462973b0028ae62d4c817b8ef80298dc3319da77 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 14 Apr 2019 14:53:57 +0200 Subject: [PATCH 12/12] Bugfix BaseURL --- tests/src/Util/BaseURLTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/src/Util/BaseURLTest.php b/tests/src/Util/BaseURLTest.php index ee88bd9804..1e74af39fe 100644 --- a/tests/src/Util/BaseURLTest.php +++ b/tests/src/Util/BaseURLTest.php @@ -179,18 +179,26 @@ class BaseURLTest extends MockedTest $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']); $configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']); + // If we don't have an urlPath as an input, we assert it, we will save it to the DB for the next time if (!isset($input['urlPath']) && isset($assert['urlPath'])) { $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once(); } + // If we don't have the ssl_policy as an input, we assert it, we will save it to the DB for the next time if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) { $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once(); } - if (!isset($input['hostname']) && !empty($assert['hostname'])) { + // If we don't have the hostname as an input, we assert it, we will save it to the DB for the next time + if (empty($input['hostname']) && !empty($assert['hostname'])) { $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once(); } + // If we don't have an URL at first, but we assert it, we will save it to the DB for the next time + if (empty($input['url']) && !empty($assert['url'])) { + $configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once(); + } + $baseUrl = new BaseURL($configMock, $server); $this->assertEquals($assert['hostname'], $baseUrl->getHostname());