From 78dc61b59ef1a4db5a1f5770e08e171a1dc4a172 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Apr 2024 09:20:23 +0000 Subject: [PATCH] Fallback mechanism for missing IDN functions --- doc/Install.md | 2 +- doc/de/Install.md | 2 +- src/Core/Installer.php | 7 ++++ src/Util/Network.php | 15 ++++++-- tests/src/Core/InstallerTest.php | 2 ++ view/lang/C/messages.po | 62 ++++++++++++++++++-------------- 6 files changed, 58 insertions(+), 32 deletions(-) diff --git a/doc/Install.md b/doc/Install.md index c50854aaf2..d7cce941a4 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -30,7 +30,7 @@ Due to the large variety of operating systems and PHP platforms in existence we * Apache with mod-rewrite enabled and "Options All" so you can use a local `.htaccess` file * PHP 7.4+ * PHP *command line* access with register_argc_argv set to true in the php.ini file - * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip, IntlChar and OpenSSL extensions + * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip, IntlChar, IDN and OpenSSL extensions * The POSIX module of PHP needs to be activated (e.g. [RHEL, CentOS](http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7) have disabled it) * Some form of email server or email gateway such that PHP mail() works. If you cannot set up your own email server, you can use the [phpmailer](https://github.com/friendica/friendica-addons/tree/develop/phpmailer) addon and use a remote SMTP server. diff --git a/doc/de/Install.md b/doc/de/Install.md index 0122988c59..46e81ba24b 100644 --- a/doc/de/Install.md +++ b/doc/de/Install.md @@ -27,7 +27,7 @@ Requirements * Apache mit einer aktiverten mod-rewrite-Funktion und dem Eintrag "Options All", so dass du die lokale .htaccess-Datei nutzen kannst * PHP 7.4+ * PHP *Kommandozeilen*-Zugang mit register_argc_argv auf "true" gesetzt in der php.ini-Datei - * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip, IntlChar and OpenSSL-Erweiterung + * Curl, GD, GMP, PDO, mbstrings, MySQLi, hash, xml, zip, IntlChar, IDN und OpenSSL-Erweiterung * Das POSIX Modul muss aktiviert sein ([CentOS, RHEL](http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7) haben dies z.B. deaktiviert) * Einen E-Mail Server, so dass PHP `mail()` funktioniert. Wenn kein eigener E-Mail Server zur Verfügung steht, kann alternativ das [phpmailer](https://github.com/friendica/friendica-addons/tree/develop/phpmailer) Addon mit einem externen SMTP Account verwendet werden. diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 1c07f325ed..8f613ce3aa 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -495,6 +495,13 @@ class Installer ); $returnVal = $returnVal ? $status : false; + $status = $this->checkFunction('idn_to_ascii', + DI::l10n()->t('IDN Functions PHP module'), + DI::l10n()->t('Error: IDN Functions PHP module required but not installed.'), + true + ); + $returnVal = $returnVal ? $status : false; + return $returnVal; } diff --git a/src/Util/Network.php b/src/Util/Network.php index 1245d9ce96..5ea1552920 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -533,20 +533,29 @@ class Network { $parts = parse_url($uri); if (!empty($parts['scheme']) && !empty($parts['host'])) { - $parts['host'] = idn_to_ascii($parts['host']); + $parts['host'] = self::idnToAscii($parts['host']); $uri = (string)Uri::fromParts($parts); } else { $parts = explode('@', $uri); if (count($parts) == 2) { - $uri = $parts[0] . '@' . idn_to_ascii($parts[1]); + $uri = $parts[0] . '@' . self::idnToAscii($parts[1]); } else { - $uri = idn_to_ascii($uri); + $uri = self::idnToAscii($uri); } } return $uri; } + private static function idnToAscii(string $uri): string + { + if (!function_exists('idn_to_ascii')) { + Logger::error('IDN functions are missing.'); + return $uri; + } + return idn_to_ascii($uri); + } + /** * Switch the scheme of an url between http and https * diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index e16a7380e3..54cc64f23f 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -110,6 +110,8 @@ class InstallerTest extends MockedTest $this->mockL10nT('Error: File Information PHP module required but not installed.', 1); $this->mockL10nT('GNU Multiple Precision PHP module', 1); $this->mockL10nT('Error: GNU Multiple Precision PHP module required but not installed.', 1); + $this->mockL10nT('IDN Functions PHP module', 1); + $this->mockL10nT('Error: IDN Functions PHP module required but not installed.', 1); $this->mockL10nT('Program execution functions', 1); $this->mockL10nT('Error: Program execution functions (proc_open) required but not enabled.', 1); } diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 76744231e0..46b2e92d1f 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2024.06-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-05 07:28+0000\n" +"POT-Creation-Date: 2024-04-06 11:09+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2793,120 +2793,128 @@ msgstr "" msgid "Error: GNU Multiple Precision PHP module required but not installed." msgstr "" -#: src/Core/Installer.php:516 +#: src/Core/Installer.php:499 +msgid "IDN Functions PHP module" +msgstr "" + +#: src/Core/Installer.php:500 +msgid "Error: IDN Functions PHP module required but not installed." +msgstr "" + +#: src/Core/Installer.php:523 msgid "" "The web installer needs to be able to create a file called \"local.config.php" "\" in the \"config\" folder of your web server and it is unable to do so." msgstr "" -#: src/Core/Installer.php:517 +#: src/Core/Installer.php:524 msgid "" "This is most often a permission setting, as the web server may not be able " "to write files in your folder - even if you can." msgstr "" -#: src/Core/Installer.php:518 +#: src/Core/Installer.php:525 msgid "" "At the end of this procedure, we will give you a text to save in a file " "named local.config.php in your Friendica \"config\" folder." msgstr "" -#: src/Core/Installer.php:519 +#: src/Core/Installer.php:526 msgid "" "You can alternatively skip this procedure and perform a manual installation. " "Please see the file \"doc/INSTALL.md\" for instructions." msgstr "" -#: src/Core/Installer.php:522 +#: src/Core/Installer.php:529 msgid "config/local.config.php is writable" msgstr "" -#: src/Core/Installer.php:542 +#: src/Core/Installer.php:549 msgid "" "Friendica uses the Smarty3 template engine to render its web views. Smarty3 " "compiles templates to PHP to speed up rendering." msgstr "" -#: src/Core/Installer.php:543 +#: src/Core/Installer.php:550 msgid "" "In order to store these compiled templates, the web server needs to have " "write access to the directory view/smarty3/ under the Friendica top level " "folder." msgstr "" -#: src/Core/Installer.php:544 +#: src/Core/Installer.php:551 msgid "" "Please ensure that the user that your web server runs as (e.g. www-data) has " "write access to this folder." msgstr "" -#: src/Core/Installer.php:545 +#: src/Core/Installer.php:552 msgid "" "Note: as a security measure, you should give the web server write access to " "view/smarty3/ only--not the template files (.tpl) that it contains." msgstr "" -#: src/Core/Installer.php:548 +#: src/Core/Installer.php:555 msgid "view/smarty3 is writable" msgstr "" -#: src/Core/Installer.php:576 +#: src/Core/Installer.php:583 msgid "" "Url rewrite in .htaccess seems not working. Make sure you copied .htaccess-" "dist to .htaccess." msgstr "" -#: src/Core/Installer.php:577 +#: src/Core/Installer.php:584 msgid "" "In some circumstances (like running inside containers), you can skip this " "error." msgstr "" -#: src/Core/Installer.php:579 +#: src/Core/Installer.php:586 msgid "Error message from Curl when fetching" msgstr "" -#: src/Core/Installer.php:585 +#: src/Core/Installer.php:592 msgid "Url rewrite is working" msgstr "" -#: src/Core/Installer.php:614 +#: src/Core/Installer.php:621 msgid "" "The detection of TLS to secure the communication between the browser and the " "new Friendica server failed." msgstr "" -#: src/Core/Installer.php:615 +#: src/Core/Installer.php:622 msgid "" "It is highly encouraged to use Friendica only over a secure connection as " "sensitive information like passwords will be transmitted." msgstr "" -#: src/Core/Installer.php:616 +#: src/Core/Installer.php:623 msgid "Please ensure that the connection to the server is secure." msgstr "" -#: src/Core/Installer.php:617 +#: src/Core/Installer.php:624 msgid "No TLS detected" msgstr "" -#: src/Core/Installer.php:619 +#: src/Core/Installer.php:626 msgid "TLS detected" msgstr "" -#: src/Core/Installer.php:636 +#: src/Core/Installer.php:643 msgid "ImageMagick PHP extension is not installed" msgstr "" -#: src/Core/Installer.php:638 +#: src/Core/Installer.php:645 msgid "ImageMagick PHP extension is installed" msgstr "" -#: src/Core/Installer.php:659 +#: src/Core/Installer.php:666 msgid "Database already in use." msgstr "" -#: src/Core/Installer.php:664 +#: src/Core/Installer.php:671 msgid "Could not connect to database." msgstr "" @@ -6656,9 +6664,9 @@ msgstr[1] "" #: src/Module/Debug/ItemBody.php:38 src/Module/Diaspora/Receive.php:57 #: src/Module/Item/Display.php:96 src/Module/Item/Feed.php:59 #: src/Module/Item/Follow.php:41 src/Module/Item/Ignore.php:41 -#: src/Module/Item/Pin.php:41 src/Module/Item/Pin.php:56 -#: src/Module/Item/Searchtext.php:53 src/Module/Item/Star.php:42 -#: src/Module/Update/Display.php:37 +#: src/Module/Item/Language.php:53 src/Module/Item/Pin.php:41 +#: src/Module/Item/Pin.php:56 src/Module/Item/Searchtext.php:53 +#: src/Module/Item/Star.php:42 src/Module/Update/Display.php:37 msgid "Access denied." msgstr ""