From 3bff3555a0373f6b82ab06db8d3c15c32b771d73 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 22 Nov 2023 12:47:14 +0100 Subject: [PATCH] Added a test due to `Failed loading libs.min.js` #358, #862, #890, #895, #1238, #1320 --- .../app/libraries/RainLoop/ServiceActions.php | 7 ++ .../app/libraries/snappymail/integrity.php | 107 ++++++++++++++++++ snappymail/v/0.0.0/setup.php | 55 ++------- 3 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 snappymail/v/0.0.0/app/libraries/snappymail/integrity.php diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 85aaf1c95..edad11c62 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -528,6 +528,13 @@ class ServiceActions return 'Pong'; } + public function ServiceTest() : string + { + $this->oHttp->ServerNoCache(); + \SnappyMail\Integrity::test(); + return ''; + } + /** * Login with the \RainLoop\API::CreateUserSsoHash() generated hash */ diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/integrity.php b/snappymail/v/0.0.0/app/libraries/snappymail/integrity.php new file mode 100644 index 000000000..90ad4ce86 --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/snappymail/integrity.php @@ -0,0 +1,107 @@ +' . $result . '

'; + return; + } + + $result = static::phpExtensions(); + if ($result) { + echo '

The following PHP extensions are not available in your PHP configuration!

'; + echo ''; + } + + $uri = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] + . \RainLoop\Utils::WebVersionPath(); + $HTTP = \SnappyMail\HTTP\Request::factory(); + $files = [ +// 'static/css/app.css', +// 'static/js/libs.js', +// 'static/js/app.js', +// 'static/js/openpgp.js', + 'static/css/app.min.css', + 'static/js/min/libs.min.js', + 'static/js/min/app.min.js', + 'static/js/min/openpgp.min.js' + ]; + foreach ($files as $file) { + echo "

{$uri}{$file}

"; + $response = $HTTP->doRequest('HEAD', $uri . $file); + echo '
Status: ' . $response->status . '
' . \print_r($response->headers, 1) . '
'; + $size = \filesize(APP_VERSION_ROOT_PATH.$file); + if ($size == intval($response->getHeader('content-length'))) { + echo 'content-length matches size ' . $size; + } else { + echo 'content-length mismatch, should be ' . $size; + } +/* + echo "

encoding

"; + $response = $HTTP->doRequest('GET', $uri . $file, null, ['Accept-Encoding' => 'gzip, deflate, br']); + echo '
Status: ' . $response->status . '
' . \print_r($response->headers, 1) . '
'; +*/ + echo "

gzip encoded

"; + $response = $HTTP->doRequest('HEAD', $uri . $file . '.gz'); + echo '
Status: ' . $response->status . '
' . \print_r($response->headers, 1) . '
'; + $size = \filesize(APP_VERSION_ROOT_PATH.$file . '.gz'); + if ($size == intval($response->getHeader('content-length'))) { + echo 'content-length matches size ' . $size; + } else { + echo 'content-length mismatch, should be ' . $size; + } + + echo "

brotli encoded

"; + $response = $HTTP->doRequest('HEAD', $uri . $file . '.br'); + echo '
Status: ' . $response->status . '
' . \print_r($response->headers, 1) . '
'; + $size = \filesize(APP_VERSION_ROOT_PATH.$file . '.br'); + if ($size == intval($response->getHeader('content-length'))) { + echo 'content-length matches size ' . $size; + } else { + echo 'content-length mismatch, should be ' . $size; + } + } + } + + public static function phpVersion() + { + if (PHP_VERSION_ID < 70400) { + return 'Your PHP version ('.PHP_VERSION.') is lower than the minimal required 7.4.0!'; + } + } + + public static function phpExtensions() + { + $aRequirements = array( + 'mbstring' => extension_loaded('mbstring'), + 'Zlib' => extension_loaded('zlib'), + // enabled by default: + 'ctype' => extension_loaded('ctype'), + 'json' => function_exists('json_decode'), + 'libxml' => function_exists('libxml_use_internal_errors'), + 'dom' => class_exists('DOMDocument') + // https://github.com/the-djmaze/snappymail/issues/392 + // 'phar' => class_exists('PharData') + ); + + $aMissing = []; + if (in_array(false, $aRequirements)) { + foreach ($aRequirements as $sKey => $bValue) { + if (!$bValue) { + $aMissing[] = $sKey; + } + } + } + return $aMissing; + } + +} diff --git a/snappymail/v/0.0.0/setup.php b/snappymail/v/0.0.0/setup.php index c219f6cf3..870436d39 100644 --- a/snappymail/v/0.0.0/setup.php +++ b/snappymail/v/0.0.0/setup.php @@ -1,56 +1,17 @@ '; - echo '[301] Your PHP version ('.PHP_VERSION.') is lower than the minimal required 7.4.0!'; - echo '

'; +require_once __DIR__ . 'app/libraries/snappymail/integrity.php'; + +$result = \SnappyMail\Integrity::phpVersion(); +if ($result) { + echo '

[301] ' . $result . '

'; exit(301); } -$aOptional = array( - 'cURL' => extension_loaded('curl'), - 'exif' => extension_loaded('exif'), - 'finfo' => class_exists('finfo'), - 'gd' => extension_loaded('gd'), - 'gnupg' => extension_loaded('gnupg'), - 'gmagick' => extension_loaded('gmagick'), - 'imagick' => extension_loaded('imagick'), - 'iconv' => function_exists('iconv'), - 'intl' => function_exists('idn_to_ascii'), - 'ldap' => extension_loaded('ldap'), - 'OpenSSL' => extension_loaded('openssl'), - 'mysql' => extension_loaded('pdo_mysql'), - 'pgsql' => extension_loaded('pdo_pgsql'), - 'redis' => extension_loaded('redis'), - 'Sodium' => extension_loaded('sodium'), - 'sqlite' => extension_loaded('pdo_sqlite'), - 'tidy' => extension_loaded('tidy'), - 'uuid' => extension_loaded('uuid'), - 'xxtea' => extension_loaded('xxtea'), - 'zip' => extension_loaded('zip') -); - -$aRequirements = array( - 'mbstring' => extension_loaded('mbstring'), - 'Zlib' => extension_loaded('zlib'), - // enabled by default: - 'ctype' => extension_loaded('ctype'), - 'json' => function_exists('json_decode'), - 'libxml' => function_exists('libxml_use_internal_errors'), - 'dom' => class_exists('DOMDocument') - // https://github.com/the-djmaze/snappymail/issues/392 -// 'phar' => class_exists('PharData') -); - -if (in_array(false, $aRequirements)) { +$result = \SnappyMail\Integrity::phpExtensions(); +if ($result) { echo '

[302] The following PHP extensions are not available in your PHP configuration!

'; - echo ''; + echo ''; exit(302); }