diff --git a/server-php/CHANGELOG.md b/server-php/CHANGELOG.md index cbc2519..e0d6f6a 100644 --- a/server-php/CHANGELOG.md +++ b/server-php/CHANGELOG.md @@ -1,5 +1,9 @@ # CheckMyHTTPS API server Changelog +## 1.5.2 - 2024-01-24 +- Add the possibility to handle POST requests +- Delete the dependance to composer + ## 1.5.1 - 2022-01-27 - Add the possibility to specify an IP in the query diff --git a/server-php/Dockerfile b/server-php/Dockerfile index b32007e..dab8da8 100644 --- a/server-php/Dockerfile +++ b/server-php/Dockerfile @@ -16,5 +16,6 @@ RUN chown www-data:www-data /var/tmp/cmh_cache/ COPY ./www /var/www/cmh_api/ -COPY ./vendor-static.tar.gz /tmp/ -RUN tar -xzf /tmp/vendor-static.tar.gz -C /var/www/cmh_api/ && rm -f /tmp/vendor.tar.gz +RUN apt-get update && apt-get install -y \ + libicu-dev \ + && docker-php-ext-install intl diff --git a/server-php/README.md b/server-php/README.md index 3ba285d..5910fda 100644 --- a/server-php/README.md +++ b/server-php/README.md @@ -6,7 +6,7 @@ **REQUIRMENTS** -* You need an HTTPS server with PHP and php-filter module +* You need an HTTPS server with PHP, the PHP class Normalizer (php-intl) and php-filter module * You also need a TMPFS partition for the cache. Here is the process (Linux): 1. Add your administrator user to the group of your server. Example with an Apache server: `[root]# usermod -a -G apache administrator` 2. Change the gid of the administrator (valid during this session only): `[administrator]$ newgrp apache` @@ -31,8 +31,7 @@ The cache is enabled by default, but you can turn it off by setting the variable **INSTALLATION** 1. Copy the content of the `www` folder to your webroot. -2. Install dependencies with composer: `composer install` inside your webroot (else you can extract `vendor-static.tar.gz`). -3. Then configure your clients to use your own check server. +2. Then configure your clients to use your own check server. ### Scripted installation diff --git a/server-php/install.sh b/server-php/install.sh index ae98fa3..007e3c3 100755 --- a/server-php/install.sh +++ b/server-php/install.sh @@ -53,21 +53,4 @@ if [ -n "$TMPDIR" ]; then fi -( - - cd $OUT; - COM=composer - composer || { - echo "installing composer" - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" - php composer-setup.php - php -r "unlink('composer-setup.php');" - COM='php composer.phar' - - } - echo "Installing composer deps" - $COM install -) - echo "All done" diff --git a/server-php/vendor-static.tar.gz b/server-php/vendor-static.tar.gz deleted file mode 100644 index 923e4ee..0000000 Binary files a/server-php/vendor-static.tar.gz and /dev/null differ diff --git a/server-php/www/api.php b/server-php/www/api.php index 5036449..ef54af8 100644 --- a/server-php/www/api.php +++ b/server-php/www/api.php @@ -1,7 +1,5 @@ encode($request_url), FILTER_VALIDATE_URL))) + if ((!filter_var($request_url, FILTER_VALIDATE_URL)) && (!filter_var(unicodeToPunycode($request_url), FILTER_VALIDATE_URL))) { echo json_encode(hashAndEncrypt((object)['error' => 'INVALID_URL'], $sign)); exit(); @@ -100,7 +102,7 @@ else { // Convert IDNA 2008 - $request_host = (new \Mso\IdnaConvert\IdnaConvert)->encode($request_host); + $request_host = unicodeToPunycode($request_host); if (preg_match('/^[a-zA-Z0-9-_.]+$/', $request_host)) $service->host = $request_host; @@ -449,4 +451,17 @@ function checkHostWhitelisted($host) } return false; } + +function unicodeToPunycode($input) { + $normalized = \Normalizer::normalize($input, \Normalizer::FORM_C); + $punycode = idn_to_ascii($normalized, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); + return $punycode; +} + +function punycodeToUnicode($input) { + $unicode = idn_to_utf8($input, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); + $normalized = \Normalizer::normalize($unicode, \Normalizer::FORM_C); + return $normalized; +} + ?> diff --git a/server-php/www/composer.json b/server-php/www/composer.json deleted file mode 100644 index 9a90118..0000000 --- a/server-php/www/composer.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "checkmyhttps/server-api", - "version": "1.1.0", - "require": { - "mso/idna-convert": "^1.1" - } -} diff --git a/server-php/www/composer.lock b/server-php/www/composer.lock deleted file mode 100644 index f0a2cc4..0000000 --- a/server-php/www/composer.lock +++ /dev/null @@ -1,68 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "2e3e3db0ef7935dee4af74b035ae9f51", - "content-hash": "caaf6c7071b1e19315004b0a9917d088", - "packages": [ - { - "name": "mso/idna-convert", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/phlylabs/idna-convert.git", - "reference": "a6dfb6f87611e3a89d2eec4924a0f51db755c573" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phlylabs/idna-convert/zipball/a6dfb6f87611e3a89d2eec4924a0f51db755c573", - "reference": "a6dfb6f87611e3a89d2eec4924a0f51db755c573", - "shasum": "" - }, - "require": { - "ext-pcre": "*", - "php": ">=5.6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Mso\\IdnaConvert\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-2.1+" - ], - "authors": [ - { - "name": "Matthias Sommerfeld", - "email": "mso@phlylabs.de", - "role": "Developer" - } - ], - "description": "A library for encoding and decoding internationalized domain names", - "homepage": "http://idnaconv.net/", - "keywords": [ - "idn", - "idna", - "php" - ], - "time": "2016-06-19 18:08:43" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -}