diff --git a/phpmyfaq/assets/templates/setup/index.twig b/phpmyfaq/assets/templates/setup/index.twig index 8e1c2d9280..2eb7dfb0e2 100644 --- a/phpmyfaq/assets/templates/setup/index.twig +++ b/phpmyfaq/assets/templates/setup/index.twig @@ -27,307 +27,316 @@ {% for hint in nonCriticalSettings %} - {{ hint | raw }} + {{ hint | raw }} {% endfor %} + {% if filePermissions != null %} + + {% endif %} + {% if checkBasicError %} {% else %} -
+
-

Step 1/4: Database setup

+

Step 1/4: Database setup

-
- -
- - Please select your preferred database type. -
-
- -
- +
- - - Please enter the host or path to the socket of your database server. - + + Please select your preferred database type.
-
- -
- - Please enter the port your database server. + +
+
+ +
+ + + Please enter the host or path to the socket of your database server. + +
-
-
- -
- - Please enter your database user. +
+ +
+ + Please enter the port your database server. +
-
-
- -
-
- - +
+ +
+ + Please enter your database user. +
+
+
+ +
+
+ + +
+ Please enter your database password. +
+
+
+ +
+ + Please enter your existing database name.
- Please enter your database password.
-
- -
- - Please enter your existing database name. + +
+
+ +
+ + + Please enter the full path to your SQLite datafile which should be outside your document root. + +
-
-
- +
- + - Please enter the full path to your SQLite datafile which should be outside your document root. + Please enter a table prefix here if you want to install more phpMyFAQ installations in one + database.
-
- -
- - - Please enter a table prefix here if you want to install more phpMyFAQ installations in one - database. - -
-
-
- -
-

Step 2/4: LDAP setup

- {% if isLdapEnabled %} -
-
- - -
-
-
- -
- - Please enter the host of your LDAP server. -
-
-
- -
- - Please enter the port of your LDAP server. -
-
-
- -
- - Please enter your specified RDN username. -
-
-
- -
- - Please enter your LDAP password. -
-
-
- -
- - - Please enter your distinguished name, e.g. 'cn=John Doe,ou=Accounts,o=My Company,c=US'. - -
+
+

Step 2/4: LDAP setup

+ {% if isLdapEnabled %} +
+
+ + +
+
+
+ +
+ + Please enter the host of your LDAP server. +
+
+
+ +
+ + Please enter the port of your LDAP server. +
+
+
+ +
+ + Please enter your specified RDN username. +
+
+
+ +
+ + Please enter your LDAP password. +
+
+
+ +
+ + + Please enter your distinguished name, e.g. 'cn=John Doe,ou=Accounts,o=My Company,c=US'. + +
+
+

+ + You can add additional LDAP configurations later in the admin configuration panel. +

+ {% else %} +

+ + LDAP support is not enabled in your PHP installation. +

+ {% endif %}
-

- - You can add additional LDAP configurations later in the admin configuration panel. -

- {% else %} -

- - LDAP support is not enabled in your PHP installation. -

- {% endif %} -
-
-

Step 3/4: Elasticsearch setup

- {% if isElasticsearchEnabled %} -
-
- - -
-
-
- -
-
- - +
+

Step 3/4: Elasticsearch setup

+ {% if isElasticsearchEnabled %} +
+
+ + +
+
+
+ +
+
+ + Add another Elasticsearch Host +
+ + Please enter the host (domain or IP) with port number of your Elasticsearch server. + +
- - Please enter the host (domain or IP) with port number of your Elasticsearch server. - -
-
-
- -
- - Please enter your Elasticsearch index name. -
+
+ +
+ + Please enter your Elasticsearch index name. +
+
+ {% else %} +

+ + cURL and OpenSSL support are not enabled in your PHP installation. +

+ {% endif %}
- {% else %} -

- - cURL and OpenSSL support are not enabled in your PHP installation. -

- {% endif %} -
-
-

Step 4/4: Admin user setup

+
+

Step 4/4: Admin user setup

-
- -
- - Please select your default language. +
+ +
+ + Please select your default language. +
-
-
- -
- - - Complexity of rights and permissions. - +
+ +
+ + + Complexity of rights and permissions. + +
-
-
- -
- - Please enter your real name. +
+ +
+ + Please enter your real name. +
-
-
- -
- - Please enter your email address. +
+ +
+ + Please enter your email address. +
-
-
- -
- - Please enter your login name. +
+ +
+ + Please enter your login name. +
-
-
- -
-
- - +
+ +
+
+ + +
+ Please enter your password with at least 8 characters.
- Please enter your password with at least 8 characters.
-
-
- -
-
- - +
+ +
+
+ + +
+ Please retype your password.
- Please retype your password.
-
-
-
-

- - After clicking the "Submit" button, all necessary tables will be created and filled with your data. - Depending on your system, this may take some time. Stay tuned. -

+
+
+

+ + After clicking the "Submit" button, all necessary tables will be created and filled with your data. + Depending on your system, this may take some time. Stay tuned. +

+
-
- - - + + + {% endif %} diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php index 67aacaf51f..65fad84e55 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php @@ -61,6 +61,7 @@ public function index(): Response 'documentationUrl' => System::getDocumentationUrl(), 'checkBasicError' => $checkBasicError, 'nonCriticalSettings' => $installer->checkNoncriticalSettings(), + 'filePermissions' => $installer->checkFilesystemPermissions(), 'supportedDatabases' => $system->getSupportedSafeDatabases(), 'currentPath' => dirname(__DIR__, 4), 'isLdapEnabled' => $installer->hasLdapSupport(), diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php index dd3396b496..da7c56bdc2 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php @@ -429,6 +429,10 @@ class Installer extends Setup 'layout.customCss' => '', ]; + /** + * Array with form inputs + * @var array + */ public array $formInputs = [ // Ask Question inputs [ @@ -574,7 +578,7 @@ class Installer extends Setup * * @throws \Exception */ - public function __construct(protected System $system) + public function __construct(private System $system) { parent::__construct(); @@ -592,8 +596,6 @@ public function __construct(protected System $system) /** * Removes the database.php and the ldap.php if an installation failed. - * - * @todo have to be moved to the Installer class */ public static function cleanFailedInstallationFiles(): void { @@ -609,27 +611,21 @@ public static function cleanFailedInstallationFiles(): void } /** - * Check absolutely necessary stuff and die. + * Check the necessary stuff and throw an exception if something is wrong. * @throws Exception */ public function checkBasicStuff(): void { if (!$this->checkMinimumPhpVersion()) { - throw new Exception( - sprintf('Sorry, but you need PHP %s or later!', System::VERSION_MINIMUM_PHP) - ); + throw new Exception(sprintf('Sorry, but you need PHP %s or later!', System::VERSION_MINIMUM_PHP)); } if (!function_exists('date_default_timezone_set')) { - throw new Exception( - 'Sorry, but setting a default timezone does not work in your environment!' - ); + throw new Exception('Sorry, but setting a default timezone does not work in your environment!'); } if (!$this->system->checkDatabase()) { - throw new Exception( - 'No supported database detected!' - ); + throw new Exception('No supported database detected!'); } if (!$this->system->checkRequiredExtensions()) { @@ -642,55 +638,14 @@ public function checkBasicStuff(): void } if (!$this->system->checkInstallation()) { - throw new Exception( - 'phpMyFAQ is already installed! Please use the update.' - ); - } - } - - /** - * Checks for the minimum PHP requirement and if the database credentials file is readable. - * - * @throws Exception - * @todo this method should be in the the Update class - */ - public function checkPreUpgrade(string $databaseType): void - { - $database = null; - if (!$this->checkMinimumPhpVersion()) { - throw new Exception(sprintf('Sorry, but you need PHP %s or later!', System::VERSION_MINIMUM_PHP)); - } - - if (!is_readable(PMF_ROOT_DIR . '/content/core/config/database.php')) { - throw new Exception( - 'It seems you never run a version of phpMyFAQ. Please use the installation script' - ); - } - - if ('' !== $databaseType) { - $databaseFound = false; - foreach (array_keys($this->system->getSupportedDatabases()) as $database) { - if ($database === $databaseType) { - $databaseFound = true; - break; - } - } - - if (!$databaseFound) { - throw new Exception( - sprintf( - 'It seems you are using an unsupported database version. We found %s', - ucfirst((string) $database) - ) - ); - } + throw new Exception('phpMyFAQ is already installed! Please use the update.'); } } /** * Checks if the file permissions are okay. */ - public function checkFilesystemPermissions(): void + public function checkFilesystemPermissions(): string|null { $instanceSetup = new Setup(); $instanceSetup->setRootDir(PMF_ROOT_DIR); @@ -705,22 +660,27 @@ public function checkFilesystemPermissions(): void $failedDirs = $instanceSetup->checkDirs($dirs); $numDirs = count($failedDirs); + $hints = ''; if (1 <= $numDirs) { - printf( + $hints .= sprintf( '

The following %s could not be created or %s not writable:

    ', (1 < $numDirs) ? 'directories' : 'directory', (1 < $numDirs) ? 'are' : 'is' ); foreach ($failedDirs as $failedDir) { - echo "
  • {$failedDir}
  • \n"; + $hints .= "
  • {$failedDir}
  • \n"; } - printf( + $hints .= sprintf( '

Please create %s manually and/or change access to chmod 775 (or ' . 'greater if necessary).

', (1 < $numDirs) ? 'them' : 'it' ); + + return $hints; } + + return null; } /** @@ -872,8 +832,6 @@ public function startInstall(array|null $setup = null): void // $ldapEnabled = Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_SPECIAL_CHARS); if (extension_loaded('ldap') && !is_null($ldapEnabled)) { - $ldapSetup = []; - // check LDAP entries $ldapSetup['ldapServer'] = Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_SPECIAL_CHARS); if (is_null($ldapSetup['ldapServer'])) { @@ -965,7 +923,7 @@ public function startInstall(array|null $setup = null): void $esSetup = []; } - // check login name + // check the login name if (!isset($setup['loginname'])) { $loginName = Filter::filterInput(INPUT_POST, 'loginname', FILTER_SANITIZE_SPECIAL_CHARS); } else {