]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Installer.php
Changed double-quotes to single
[friendica.git] / src / Core / Installer.php
index de75aa374f1333a1f4c51a1c265c3f69dceffcc5..9a9bdfb5f79f0cc5f72e7ecf547ba012bec45729 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,7 +23,7 @@ namespace Friendica\Core;
 
 use DOMDocument;
 use Exception;
-use Friendica\Core\Config\Cache;
+use Friendica\Core\Config\ValueObject\Cache;
 use Friendica\Database\Database;
 use Friendica\Database\DBStructure;
 use Friendica\DI;
@@ -129,14 +129,18 @@ class Installer
                        $returnVal = false;
                }
 
-               if (!$this->checkKeys()) {
+               if (!$this->checkTLS()) {
                        $returnVal = false;
                }
 
-               if (!$this->checkHtAccess($baseurl)) {
+               if (!$this->checkKeys()) {
                        $returnVal = false;
                }
 
+               /// @TODO This check should not block installations because of containerization issues
+               /// @see https://github.com/friendica/docker/issues/134
+               $this->checkHtAccess($baseurl);
+
                return $returnVal;
        }
 
@@ -185,14 +189,12 @@ class Installer
        /***
         * Installs the DB-Scheme for Friendica
         *
-        * @param string $basePath The base path of this application
-        *
         * @return bool true if the installation was successful, otherwise false
         * @throws Exception
         */
-       public function installDatabase($basePath)
+       public function installDatabase(): bool
        {
-               $result = DBStructure::install($basePath);
+               $result = DBStructure::install();
 
                if ($result) {
                        $txt = DI::l10n()->t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
@@ -274,7 +276,7 @@ class Installer
                        $cmd = "$phppath -v";
                        $result = trim(shell_exec($cmd));
                        $passed2 = (strpos($result, "(cli)") !== false);
-                       list($result) = explode("\n", $result);
+                       [$result] = explode("\n", $result);
                        $help = "";
                        if (!$passed2) {
                                $help .= DI::l10n()->t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29") . EOL;
@@ -465,7 +467,7 @@ class Installer
 
                $status = $this->checkFunction('proc_open',
                        DI::l10n()->t('Program execution functions'),
-                       DI::l10n()->t('Error: Program execution functions required but not enabled.'),
+                       DI::l10n()->t('Error: Program execution functions (proc_open) required but not enabled.'),
                        true
                );
                $returnVal = $returnVal ? $status : false;
@@ -484,6 +486,13 @@ class Installer
                );
                $returnVal = $returnVal ? $status : false;
 
+               $status = $this->checkFunction('gmp_strval',
+                       DI::l10n()->t('GNU Multiple Precision PHP module'),
+                       DI::l10n()->t('Error: GNU Multiple Precision PHP module required but not installed.'),
+                       true
+               );
+               $returnVal = $returnVal ? $status : false;
+
                return $returnVal;
        }
 
@@ -553,11 +562,11 @@ class Installer
                $help = "";
                $error_msg = "";
                if (function_exists('curl_init')) {
-                       $fetchResult = DI::httpRequest()->fetchFull($baseurl . "/install/testrewrite");
+                       $fetchResult = DI::httpClient()->fetchFull($baseurl . "/install/testrewrite");
 
                        $url = Strings::normaliseLink($baseurl . "/install/testrewrite");
                        if ($fetchResult->getReturnCode() != 204) {
-                               $fetchResult = DI::httpRequest()->fetchFull($url);
+                               $fetchResult = DI::httpClient()->fetchFull($url);
                        }
 
                        if ($fetchResult->getReturnCode() != 204) {
@@ -580,6 +589,38 @@ class Installer
                return $status;
        }
 
+       /**
+        * TLS Check
+        *
+        * Tries to determine whether the connection to the server is secured
+        * by TLS or not. If not the user will be warned that it is higly
+        * encuraged to use TLS.
+        *
+        * @return bool (true) as TLS is not mandatory
+        */
+       public function checkTLS()
+       {
+               $tls = false;
+
+               if (isset($_SERVER['HTTPS'])) {
+                       if (($_SERVER['HTTPS'] == 1) || ($_SERVER['HTTPS'] == 'on')) {
+                               $tls = true;
+                       }
+               }
+               
+               if (!$tls) {
+                       $help = DI::l10n()->t('The detection of TLS to secure the communication between the browser and the new Friendica server failed.');
+                       $help .= ' ' . DI::l10n()->t('It is highly encouraged to use Friendica only over a secure connection as sensitive information like passwords will be transmitted.');
+                       $help .= ' ' . DI::l10n()->t('Please ensure that the connection to the server is secure.');
+                       $this->addCheck(DI::l10n()->t('No TLS detected'), $tls, false, $help);
+               } else {
+                       $this->addCheck(DI::l10n()->t('TLS detected'), $tls, false, '');
+               }
+
+               // TLS is not required
+               return true;
+       }
+
        /**
         * Imagick Check
         *
@@ -620,7 +661,7 @@ class Installer
         * @return bool true if the check was successful, otherwise false
         * @throws Exception
         */
-       public function checkDB(Database $dba)
+       public function checkDB(Database $dba): bool
        {
                $dba->reconnect();
 
@@ -642,8 +683,8 @@ class Installer
        /**
         * Setup the default cache for a new installation
         *
-        * @param Cache  $configCache The configuration cache
-        * @param string $basePath    The determined basepath
+        * @param \Friendica\Core\Config\ValueObject\Cache $configCache The configuration cache
+        * @param string                                   $basePath    The determined basepath
         *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */