diff --git a/phpmyfaq/.htaccess b/phpmyfaq/.htaccess index 1d0d7cd5d9..69908b7098 100644 --- a/phpmyfaq/.htaccess +++ b/phpmyfaq/.htaccess @@ -96,6 +96,9 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization" # User pages RewriteRule ^user/(ucp|bookmarks|request-removal|logout|register) index.php?action=$1 [L,QSA] + # Setup and update pages + RewriteRule ^setup/(.*) setup/index.php [L,QSA] + # Administration API RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA] diff --git a/phpmyfaq/assets/templates/setup/base.twig b/phpmyfaq/assets/templates/setup/base.twig new file mode 100644 index 0000000000..97d0c08daf --- /dev/null +++ b/phpmyfaq/assets/templates/setup/base.twig @@ -0,0 +1,49 @@ + + + + + phpMyFAQ {{ newVersion }} {{ setupType }} + + + + + + + + + + + +{% block content %}{% endblock %} + + + + + + diff --git a/phpmyfaq/assets/templates/setup/index.twig b/phpmyfaq/assets/templates/setup/index.twig index e69de29bb2..28b92becfa 100644 --- a/phpmyfaq/assets/templates/setup/index.twig +++ b/phpmyfaq/assets/templates/setup/index.twig @@ -0,0 +1,335 @@ +{% extends 'setup/base.twig' %} + +{% block content %} +
+
+ +
+
+ +
+

phpMyFAQ {{ newVersion }}

+
+

+ Did you already read our + documentation + carefully before starting the phpMyFAQ setup? +

+
+
+ +
+ Database Setup + LDAP Setup + Elasticsearch Setup + Admin user account +
+ + {% for hint in nonCriticalSettings %} + + {% endfor %} + + {% if checkBasicError %} + + {% else %} + +
+ +

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 enter the port your database server. +
+
+
+ +
+ + Please enter your database user. +
+
+
+ +
+
+ + + + +
+ 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 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'. + +
+
+

+ + 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 %} +
+
+ + +
+
+
+ +
+
+ + + Add another Elasticsearch Host + +
+ + Please enter the host (domain or IP) with port number of your Elasticsearch server. + +
+
+
+ +
+ + Please enter your Elasticsearch index name. +
+
+ {% else %} +

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

+ {% endif %} +
+ +
+

Step 4/4: Admin user setup

+ +
+ +
+ + Please select your default language. +
+
+ +
+ +
+ + + Complexity of rights and permissions. + +
+
+
+ +
+ + Please enter your real name. +
+
+
+ +
+ + Please enter your email address. +
+
+
+ +
+ + Please enter your login name. +
+
+
+ +
+
+ + + + +
+ Please enter your password with at least 8 characters. +
+
+
+ +
+
+ + + + +
+ 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. +

+
+
+
+ + + + + + {% endif %} +
+
+
+
+{% endblock %} diff --git a/phpmyfaq/assets/templates/setup/install.twig b/phpmyfaq/assets/templates/setup/install.twig new file mode 100644 index 0000000000..be6b69a653 --- /dev/null +++ b/phpmyfaq/assets/templates/setup/install.twig @@ -0,0 +1,50 @@ +{% extends 'setup/base.twig' %} + +{% block content %} +
+
+ +
+ +
+

phpMyFAQ {{ newVersion }}

+
+

+ Did you already read our + documentation + carefully before starting the phpMyFAQ setup? +

+
+
+ + {% if checkBasicError %} + + {% elseif installationError %} + + {% else %} +
+
+

Installation

+ + {{ feedbackIndicator }} + +

+ Wow, looks like the installation worked like a charm. This is pretty cool, isn't it? :-) +

+ +

+ You can visit your version of phpMyFAQ or login into your + admin section. +

+
+
+ {% endif %} + +
+
+
+{% endblock %} diff --git a/phpmyfaq/assets/templates/setup/update.twig b/phpmyfaq/assets/templates/setup/update.twig index 345a45bbc2..bd8407d36b 100644 --- a/phpmyfaq/assets/templates/setup/update.twig +++ b/phpmyfaq/assets/templates/setup/update.twig @@ -54,7 +54,7 @@ Database updates - {{ include('setup/update/step' ~ currentStep ~ '.twig') }} + {{ include('./setup/update/step' ~ currentStep ~ '.twig') }} diff --git a/phpmyfaq/setup/index.php b/phpmyfaq/setup/index.php index 0ce5c69c38..10c679263d 100644 --- a/phpmyfaq/setup/index.php +++ b/phpmyfaq/setup/index.php @@ -2,6 +2,7 @@ /** * The main phpMyFAQ Setup. + * * This script checks the complete environment, writes the database connection * parameters into the file config/database.php and the configuration into the database. * This Source Code Form is subject to the terms of the Mozilla Public License, @@ -10,480 +11,24 @@ * * @package phpMyFAQ * @author Thorsten Rinne - * @author Tom Rochester - * @author Johannes Schlüter - * @author Uwe Pries - * @author Matteo Scaramuccia - * @author Florian Anderiasch - * @copyright 2002-2024 phpMyFAQ Team + * @copyright 2024 phpMyFAQ Team * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 * @link https://www.phpmyfaq.de - * @since 2002-08-20 + * @since 2024-05-31 */ -use Composer\Autoload\ClassLoader; -use phpMyFAQ\Component\Alert; -use phpMyFAQ\Core\Exception; -use phpMyFAQ\Language\LanguageCodes; -use phpMyFAQ\Setup\Installer; -use phpMyFAQ\Strings; -use phpMyFAQ\System; -use phpMyFAQ\Translation; - -define('PMF_ROOT_DIR', dirname(__FILE__, 2)); -const PMF_SRC_DIR = PMF_ROOT_DIR . '/src'; -const IS_VALID_PHPMYFAQ = null; - -if (version_compare(PHP_VERSION, '8.1.0') < 0) { - die('Sorry, but you need PHP 8.1.0 or later!'); -} - -set_time_limit(0); - -if (!defined('DEBUG')) { - define('DEBUG', true); -} - -if (DEBUG) { - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); - error_reporting(E_ALL | E_STRICT); -} - -session_name('phpmyfaq-setup'); -session_start(); - -require PMF_ROOT_DIR . '/src/libs/autoload.php'; -require PMF_ROOT_DIR . '/src/constants.php'; -require PMF_ROOT_DIR . '/content/core/config/constants.php'; -require PMF_ROOT_DIR . '/content/core/config/constants_elasticsearch.php'; +use phpMyFAQ\Application; +use phpMyFAQ\Configuration; -$loader = new ClassLoader(); -$loader->add('phpMyFAQ', PMF_SRC_DIR); -$loader->register(); -?> - - - - - phpMyFAQ <?= System::getVersion() ?> Setup - - - - - - - - +require '../src/Bootstrap.php'; - +$faqConfig = Configuration::getConfigurationInstance(); -
-
+$routes = include PMF_SRC_DIR . '/public-routes.php'; -
-
- -
-

phpMyFAQ

-
-

- Did you already read our - documentation - carefully before starting the phpMyFAQ setup? -

-
-
- -
- Database Setup - LDAP Setup - Elasticsearch Setup - Admin user account -
- -setLanguagesDir(PMF_LANGUAGE_DIR) - ->setDefaultLanguage('en') - ->setCurrentLanguage('en') - ->setMultiByteLanguage(); -} catch (Exception $e) { - echo 'Error: ' . $e->getMessage(); -} - -$system = new System(); -$installer = new Installer($system); - -try { - $installer->checkBasicStuff(); -} catch (Exception $e) { - echo Alert::danger('ad_entryins_fail', $e->getMessage()); - System::renderFooter(); -} - -$installer->checkFilesystemPermissions(); - -// not yet POSTed -if (!isset($_POST['sql_server']) && !isset($_POST['sql_user']) && !isset($_POST['sql_db'])) { - $installer->checkNoncriticalSettings() - ?> - -
- -

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 enter the port your database server. -
-
-
- -
- - Please enter your database user. -
-
-
- -
-
- - - - -
- 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 a table prefix here if you want to install more phpMyFAQ installations in one - database. - -
-
-
- - -
-

Step 2/4: LDAP setup

- -
-
- - -
-
-
- -
- - 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. -

- -
- - - -
-

Step 3/4: Elasticsearch setup

- -
-
- - -
-
-
- -
-
- - - Add another Elasticsearch Host - -
- - Please enter the host (domain or IP) with port number of your Elasticsearch server. - -
-
-
- -
- - Please enter your Elasticsearch index name. -
-
- -
- - - -
-

Step 4/4: Admin user setup

- -
- -
- - Please select your default language. -
-
- -
- -
- - - Complexity of rights and permissions. - -
-
-
- -
- - Please enter your real name. -
-
-
- -
- - Please enter your email address. -
-
-
- -
- - Please enter your login name. -
-
-
- -
-
- - - - -
- Please enter your password with at least 8 characters. -
-
-
- -
-
- - - - -
- 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. -

-
-
-
- - - - - -
-
- - -
-
-

Installation

- startInstall(); - } catch (Exception $e) { - echo $e->getMessage(); - } - ?> -

- Wow, looks like the installation worked like a charm. This is pretty cool, isn't it? :-) -

- -

- You can visit your version of phpMyFAQ or login into your - admin section. -

-
-
- run($routes); +} catch (Exception $exception) { + echo $exception->getMessage(); } - - System::renderFooter(); diff --git a/phpmyfaq/setup/setup.php b/phpmyfaq/setup/setup.php new file mode 100644 index 0000000000..a5214a379d --- /dev/null +++ b/phpmyfaq/setup/setup.php @@ -0,0 +1,489 @@ + + * @author Tom Rochester + * @author Johannes Schlüter + * @author Uwe Pries + * @author Matteo Scaramuccia + * @author Florian Anderiasch + * @copyright 2002-2024 phpMyFAQ Team + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2002-08-20 + */ + +use Composer\Autoload\ClassLoader; +use Elastic\Elasticsearch\Exception\AuthenticationException;use phpMyFAQ\Component\Alert; +use phpMyFAQ\Core\Exception; +use phpMyFAQ\Language\LanguageCodes; +use phpMyFAQ\Setup\Installer; +use phpMyFAQ\Strings; +use phpMyFAQ\System; +use phpMyFAQ\Translation; + +define('PMF_ROOT_DIR', dirname(__FILE__, 2)); +const PMF_SRC_DIR = PMF_ROOT_DIR . '/src'; +const IS_VALID_PHPMYFAQ = null; + +if (version_compare(PHP_VERSION, '8.1.0') < 0) { + die('Sorry, but you need PHP 8.1.0 or later!'); +} + +set_time_limit(0); + +if (!defined('DEBUG')) { + define('DEBUG', true); +} + +if (DEBUG) { + ini_set('display_errors', 1); + ini_set('display_startup_errors', 1); + error_reporting(E_ALL | E_STRICT); +} + +session_name('phpmyfaq-setup'); +session_start(); + +require PMF_ROOT_DIR . '/src/libs/autoload.php'; +require PMF_ROOT_DIR . '/src/constants.php'; +require PMF_ROOT_DIR . '/content/core/config/constants.php'; +require PMF_ROOT_DIR . '/content/core/config/constants_elasticsearch.php'; + +$loader = new ClassLoader(); +$loader->add('phpMyFAQ', PMF_SRC_DIR); +$loader->register(); +?> + + + + + phpMyFAQ <?= System::getVersion() ?> Setup + + + + + + + + + + + +
+
+ +
+
+ +
+

phpMyFAQ

+
+

+ Did you already read our + documentation + carefully before starting the phpMyFAQ setup? +

+
+
+ +
+ Database Setup + LDAP Setup + Elasticsearch Setup + Admin user account +
+ +setLanguagesDir(PMF_LANGUAGE_DIR) + ->setDefaultLanguage('en') + ->setCurrentLanguage('en') + ->setMultiByteLanguage(); +} catch (Exception $e) { + echo 'Error: ' . $e->getMessage(); +} + +$system = new System(); +$installer = new Installer($system); + +try { + $installer->checkBasicStuff(); +} catch (Exception $e) { + echo Alert::danger('ad_entryins_fail', $e->getMessage()); + System::renderFooter(); +} + +$installer->checkFilesystemPermissions(); + +// not yet POSTed +if (!isset($_POST['sql_server']) && !isset($_POST['sql_user']) && !isset($_POST['sql_db'])) { + $installer->checkNoncriticalSettings() + ?> + +
+ +

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 enter the port your database server. +
+
+
+ +
+ + Please enter your database user. +
+
+
+ +
+
+ + + + +
+ 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 a table prefix here if you want to install more phpMyFAQ installations in one + database. + +
+
+
+ + +
+

Step 2/4: LDAP setup

+ +
+
+ + +
+
+
+ +
+ + 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. +

+ +
+ + + +
+

Step 3/4: Elasticsearch setup

+ +
+
+ + +
+
+
+ +
+
+ + + Add another Elasticsearch Host + +
+ + Please enter the host (domain or IP) with port number of your Elasticsearch server. + +
+
+
+ +
+ + Please enter your Elasticsearch index name. +
+
+ +
+ + + +
+

Step 4/4: Admin user setup

+ +
+ +
+ + Please select your default language. +
+
+ +
+ +
+ + + Complexity of rights and permissions. + +
+
+
+ +
+ + Please enter your real name. +
+
+
+ +
+ + Please enter your email address. +
+
+
+ +
+ + Please enter your login name. +
+
+
+ +
+
+ + + + +
+ Please enter your password with at least 8 characters. +
+
+
+ +
+
+ + + + +
+ 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. +

+
+
+
+ + + + + +
+
+ + +
+
+

Installation

+ startInstall(); + } catch (Exception | AuthenticationException $e) { + echo $e->getMessage(); + } + ?> +

+ Wow, looks like the installation worked like a charm. This is pretty cool, isn't it? :-) +

+ +

+ You can visit your version of phpMyFAQ or login into your + admin section. +

+
+
+ addExtension(new DebugExtension()); $template = $twigWrapper->loadTemplate($pathToTwigFile); $response->setContent($template->render($templateVars)); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Setup/SetupController.php b/phpmyfaq/src/phpMyFAQ/Controller/Api/SetupController.php similarity index 98% rename from phpmyfaq/src/phpMyFAQ/Controller/Setup/SetupController.php rename to phpmyfaq/src/phpMyFAQ/Controller/Api/SetupController.php index 8a482d21d7..1cc6e6aa08 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Setup/SetupController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Api/SetupController.php @@ -15,9 +15,8 @@ * @since 2023-10-17 */ -namespace phpMyFAQ\Controller\Setup; +namespace phpMyFAQ\Controller\Api; -use phpMyFAQ\Configuration; use phpMyFAQ\Controller\AbstractController; use phpMyFAQ\Core\Exception; use phpMyFAQ\Database; diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php new file mode 100644 index 0000000000..85daa9410e --- /dev/null +++ b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/SetupController.php @@ -0,0 +1,119 @@ + + * @copyright 2024 phpMyFAQ Team + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2024-06-01 + */ + +namespace phpMyFAQ\Controller\Frontend; + +use Elastic\Elasticsearch\Exception\AuthenticationException; +use phpMyFAQ\Controller\AbstractController; +use phpMyFAQ\Core\Exception; +use phpMyFAQ\Language\LanguageCodes; +use phpMyFAQ\Setup\Installer; +use phpMyFAQ\System; +use phpMyFAQ\Template\TemplateException; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; + +class SetupController extends AbstractController +{ + /** + * @throws TemplateException + * @throws \Exception + */ + #[Route('/setup', name: 'public.setup.update')] + public function index(): Response + { + $system = new System(); + $installer = new Installer($system); + + $checkBasicError = ''; + + try { + $installer->checkBasicStuff(); + } catch (Exception $e) { + $checkBasicError = $e->getMessage(); + } + + return $this->render( + 'setup/index.twig', + [ + 'newVersion' => System::getVersion(), + 'setupType' => 'Setup', + 'currentYear' => date('Y'), + 'currentLanguage' => 'en', + 'documentationUrl' => System::getDocumentationUrl(), + 'checkBasicError' => $checkBasicError, + 'nonCriticalSettings' => $installer->checkNoncriticalSettings(), + 'supportedDatabases' => $system->getSupportedSafeDatabases(), + 'currentPath' => dirname(__DIR__, 4), + 'isLdapEnabled' => $installer->hasLdapSupport(), + 'isElasticsearchEnabled' => $installer->hasElasticsearchSupport(), + 'supportedTranslations' => LanguageCodes::getAllSupported(), + ] + ); + } + + /** + * @throws TemplateException + * @throws \Exception + */ + #[Route('/setup/install', name: 'public.setup.install')] + public function install(): Response + { + $system = new System(); + $installer = new Installer($system); + + $checkBasicError = $installationError = ''; + + try { + $installer->checkBasicStuff(); + } catch (Exception $e) { + $checkBasicError = $e->getMessage(); + } + + try { + $installer->startInstall(); + } catch (Exception | AuthenticationException $e) { + $installationError = $e->getMessage(); + } + + return $this->render( + 'setup/install.twig', + [ + 'newVersion' => System::getVersion(), + 'setupType' => 'Setup', + 'currentYear' => date('Y'), + 'documentationUrl' => System::getDocumentationUrl(), + 'checkBasicError' => $checkBasicError, + 'installationError' => $installationError, + ] + ); + } + + /** + * @throws TemplateException + */ + #[Route('/setup/update', name: 'public.setup.update')] + public function update(): Response + { + return $this->render( + 'setup/update.twig', + [ + 'currentStep' => $step ?? 1, + ] + ); + } +} diff --git a/phpmyfaq/src/phpMyFAQ/Language.php b/phpmyfaq/src/phpMyFAQ/Language.php index 45421d32ac..4d4c4dd6e6 100644 --- a/phpmyfaq/src/phpMyFAQ/Language.php +++ b/phpmyfaq/src/phpMyFAQ/Language.php @@ -165,6 +165,24 @@ public function setLanguageByAcceptLanguage(): string return self::$language = $this->acceptLanguage; } + /** + * True if the language is supported by the current phpMyFAQ installation. + * + * @param string|null $langCode Language code + */ + public static function isASupportedLanguage(?string $langCode): bool + { + return $langCode !== null && LanguageCodes::getSupported($langCode) !== null; + } + + /** + * Returns the current language. + */ + public function getLanguage(): string + { + return self::$language; + } + /** * Gets the accepted language from the user agent. * @@ -193,22 +211,4 @@ private function getUserAgentLanguage(): void } } } - - /** - * True if the language is supported by the current phpMyFAQ installation. - * - * @param string|null $langCode Language code - */ - public static function isASupportedLanguage(?string $langCode): bool - { - return $langCode !== null && LanguageCodes::getSupported($langCode) !== null; - } - - /** - * Returns the current language. - */ - public function getLanguage(): string - { - return self::$language; - } } diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php index 3117eca1f3..af1c6afdcd 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php @@ -619,7 +619,7 @@ public function checkBasicStuff(): void if (!$this->system->checkInstallation()) { throw new Exception( - 'phpMyFAQ is already installed! Please use the update.' + 'phpMyFAQ is already installed! Please use the update.' ); } } @@ -704,43 +704,47 @@ public function checkFilesystemPermissions(): void /** * Checks some non-critical settings and print some hints. * - * @todo We should return an array of messages + * @return string[] */ - public function checkNoncriticalSettings(): void + public function checkNoncriticalSettings(): array { + $hints = []; if (!$this->system->getHttpsStatus()) { - echo '

phpMyFAQ could not find HTTPS support. For security reasons we ' . - 'recommend activating HTTPS.

'; + $hints[] = '

phpMyFAQ could not find HTTPS support. For security reasons ' . + 'we recommend activating HTTPS.

'; } if (!extension_loaded('gd')) { - echo '

You don\'t have GD support enabled in your PHP installation. Please ' . - "enable GD support in your php.ini file otherwise you can't use Captchas for spam protection.

"; + $hints[] = '

You don\'t have GD support enabled in your PHP installation. ' . + "Please enable GD support in your php.ini file otherwise you can't use Captchas for spam protection." . + "

"; } if (!function_exists('imagettftext')) { - echo '

You don\'t have Freetype support enabled in the GD extension of ' . - 'your PHP installation. Please enable Freetype support in GD extension otherwise the Captchas ' . + $hints[] = '

You don\'t have Freetype support enabled in the GD extension ' . + ' ofyour PHP installation. Please enable Freetype support in GD extension otherwise the Captchas ' . 'for spam protection will be quite easy to break.

'; } if (!extension_loaded('curl') || !extension_loaded('openssl')) { - echo '

You don\'t have cURL and/or OpenSSL support enabled in your PHP ' . - "installation. Please enable cURL and/or OpenSSL support in your php.ini file otherwise you can't " . - 'use Elasticsearch.

'; + $hints[] = '

You don\'t have cURL and/or OpenSSL support enabled in your ' . + "PHP installation. Please enable cURL and/or OpenSSL support in your php.ini file otherwise you " . + " can't use Elasticsearch.

"; } if (!extension_loaded('fileinfo')) { - echo '

You don\'t have Fileinfo support enabled in your PHP installation. ' . - "Please enable Fileinfo support in your php.ini file otherwise you can't use our backup/restore " . - 'functionality.

'; + $hints[] = '

You don\'t have Fileinfo support enabled in your PHP ' . + "installation. Please enable Fileinfo support in your php.ini file otherwise you can't use our " . + 'backup/restore functionality.

'; } if (!extension_loaded('sodium')) { - echo '

You don\'t have Sodium support enabled in your PHP installation. ' . - "Please enable Sodium support in your php.ini file otherwise you can't use our backup/restore " . - 'functionality.

'; + $hints[] = '

You don\'t have Sodium support enabled in your PHP ' . + "installation. Please enable Sodium support in your php.ini file otherwise you can't use our " . + 'backup/restore functionality.

'; } + + return $hints; } /** @@ -751,6 +755,7 @@ public function checkNoncriticalSettings(): void */ public function startInstall(array|null $setup = null): void { + $feedbacks = []; $ldapSetup = []; $query = []; $uninstall = []; @@ -1231,4 +1236,14 @@ public function adjustRewriteBaseHtaccess(string $path): bool return file_put_contents($htaccessPath, implode('', $newLines)) !== false; } + + public function hasLdapSupport(): bool + { + return extension_loaded('ldap'); + } + + public function hasElasticsearchSupport(): bool + { + return extension_loaded('curl') && extension_loaded('openssl'); + } } diff --git a/phpmyfaq/src/phpMyFAQ/System.php b/phpmyfaq/src/phpMyFAQ/System.php index 5bebde18a0..bb34f04d24 100644 --- a/phpmyfaq/src/phpMyFAQ/System.php +++ b/phpmyfaq/src/phpMyFAQ/System.php @@ -244,9 +244,9 @@ public function getAvailableTemplates(): array * * @return array */ - public function getSupportedSafeDatabases(bool $returnAsHtml = false): array + public function getSupportedSafeDatabases(): array { - $retVal = []; + $databases = []; foreach ($this->getSupportedDatabases() as $extension => $database) { if (!extension_loaded($extension)) { continue; @@ -254,14 +254,10 @@ public function getSupportedSafeDatabases(bool $returnAsHtml = false): array if (version_compare(PHP_VERSION, $database[0]) < 0) { continue; } - if ($returnAsHtml) { - $retVal[] = sprintf('', $extension, $database[1]); - } else { - $retVal[$extension] = $database; - } + $databases[$extension] = $database[1]; } - return $retVal; + return $databases; } /** diff --git a/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php b/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php index c1296c1048..ac5ea98501 100644 --- a/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php +++ b/phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php @@ -17,6 +17,7 @@ namespace phpMyFAQ\Template; +use phpMyFAQ\Core\Exception; use phpMyFAQ\System; use Twig\Environment; use Twig\Error\LoaderError; @@ -44,14 +45,14 @@ public function __construct(string $templatePath) } /** - * @throws TemplateException + * @throws Exception */ public function loadTemplate(string $templateFile): TemplateWrapper { try { return $this->twigEnvironment->load($templateFile); } catch (LoaderError | RuntimeError | SyntaxError $exception) { - throw new TemplateException($exception->getMessage()); + throw new Exception($exception->getMessage()); } } diff --git a/phpmyfaq/src/public-routes.php b/phpmyfaq/src/public-routes.php new file mode 100644 index 0000000000..e9587c90a6 --- /dev/null +++ b/phpmyfaq/src/public-routes.php @@ -0,0 +1,35 @@ + + * @copyright 2024 phpMyFAQ Team + * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 + * @link https://www.phpmyfaq.de + * @since 2024-05-31 + */ + +use phpMyFAQ\Controller\Frontend\SetupController; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; + +$routes = new RouteCollection(); + +$routeDefinitions = [ + // Setup and update + 'public.setup.index' => ['/', SetupController::class, 'index'], + 'public.setup.install' => ['/install', SetupController::class, 'install'], + 'public.setup.update' => ['/update', SetupController::class, 'update'], +]; + +foreach ($routeDefinitions as $name => [$path, $controller, $action]) { + $routes->add($name, new Route($path, ['_controller' => [$controller, $action]])); +} + +return $routes;