Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback mechanism for missing IDN functions #14077

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should read intl instead.

* 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.
Expand Down
2 changes: 1 addition & 1 deletion doc/de/Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier sollte stattdessen intl stehen.

* 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.
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ public function checkFunctions()
);
$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.'),
Comment on lines +499 to +500
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDN -> Intl

true
);
$returnVal = $returnVal ? $status : false;

return $returnVal;
}

Expand Down
15 changes: 12 additions & 3 deletions src/Util/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,29 @@
{
$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.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDN -> Intl

return $uri;

Check warning on line 554 in src/Util/Network.php

View check run for this annotation

Codecov / codecov/patch

src/Util/Network.php#L553-L554

Added lines #L553 - L554 were not covered by tests
}
return idn_to_ascii($uri);
}

/**
* Switch the scheme of an url between http and https
*
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Core/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ private function mockFunctionL10TCalls(bool $disableTimes = false)
$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);
}
Expand Down
62 changes: 35 additions & 27 deletions view/lang/C/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down