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..5c65018f4e --- /dev/null +++ b/phpmyfaq/assets/templates/setup/base.twig @@ -0,0 +1,48 @@ + + + + + phpMyFAQ {{ newVersion }} {{ setupType }} + + + + + + + + + + +{% block content %}{% endblock %} + + + + + + diff --git a/phpmyfaq/assets/templates/setup/index.twig b/phpmyfaq/assets/templates/setup/index.twig index e69de29bb2..6797b204aa 100644 --- a/phpmyfaq/assets/templates/setup/index.twig +++ b/phpmyfaq/assets/templates/setup/index.twig @@ -0,0 +1,41 @@ +{% 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 +
+ + {% if checkBasicError %} + + {% else %} + + {% endif %} + +
+
+
+
+{% endblock %} diff --git a/phpmyfaq/assets/templates/setup/install.twig b/phpmyfaq/assets/templates/setup/install.twig new file mode 100644 index 0000000000..09223f8f25 --- /dev/null +++ b/phpmyfaq/assets/templates/setup/install.twig @@ -0,0 +1,41 @@ +{% 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 +
+ + {% if checkBasicError %} + + {% else %} + + {% endif %} + +
+
+
+
+{% endblock %} 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. +

+
+
+ + * @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 phpMyFAQ\Controller\AbstractController; +use phpMyFAQ\Core\Exception; +use phpMyFAQ\Setup\Installer; +use phpMyFAQ\System; +use phpMyFAQ\Template\TemplateException; +use Symfony\Component\HttpFoundation\Response; + +class SetupController extends AbstractController +{ + /** + * @throws TemplateException + */ + public function index(): Response + { + return $this->render('setup/index.twig'); + } + + /** + * @throws TemplateException + * @throws \Exception + */ + public function install(): Response + { + $system = new System(); + $installer = new Installer($system); + + $checkBasicError = ''; + + try { + $installer->checkBasicStuff(); + } catch (Exception $e) { + $checkBasicError = $e->getMessage(); + } + + $installer->checkFilesystemPermissions(); + + return $this->render( + 'setup/install.twig', + [ + 'newVersion' => System::getVersion(), + 'setupType' => 'Setup', + 'currentYear' => date('Y'), + 'documentationUrl' => System::getDocumentationUrl(), + 'checkBasicError' => $checkBasicError, + 'isLdapEnabled' => $installer->hasLdapSupport(), + ] + ); + } + + /** + * @throws TemplateException + */ + public function uppdate(): Response + { + return $this->render('setup/update.twig'); + } +} diff --git a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php index bb2acc8aee..f816c612e2 100644 --- a/phpmyfaq/src/phpMyFAQ/Setup/Installer.php +++ b/phpmyfaq/src/phpMyFAQ/Setup/Installer.php @@ -1232,4 +1232,9 @@ public function adjustRewriteBaseHtaccess(string $path): bool return file_put_contents($htaccessPath, implode('', $newLines)) !== false; } + + public function hasLdapSupport(): bool + { + return extension_loaded('ldap'); + } } 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..8c17ce2818 --- /dev/null +++ b/phpmyfaq/src/public-routes.php @@ -0,0 +1,37 @@ + + * @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(); + +$routes->add( + 'public.setup.index', + new Route('/', ['_controller' => [SetupController::class, 'index']]) +); +$routes->add( + 'public.setup.install', + new Route('/install', ['_controller' => [SetupController::class, 'install']]) +); +$routes->add( + 'public.setup.update', + new Route('/update', ['_controller' => [SetupController::class, 'update']]) +); + +return $routes;