Added a test due to Failed loading libs.min.js #358, #862, #890, #895, #1238, #1320

This commit is contained in:
the-djmaze 2023-11-22 12:47:14 +01:00
parent 4f5db79e27
commit 3bff3555a0
3 changed files with 122 additions and 47 deletions

View file

@ -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
*/

View file

@ -0,0 +1,107 @@
<?php
namespace SnappyMail;
abstract class Integrity
{
/**
* Called by https://webmail.tld/?/Test
*/
public static function test()
{
$result = static::phpVersion();
if ($result) {
echo '<p style="color: red">' . $result . '</p>';
return;
}
$result = static::phpExtensions();
if ($result) {
echo '<p>The following PHP extensions are not available in your PHP configuration!</p>';
echo '<ul><li>' . \implode('</li>li><li>', $result) . '</li></ul>';
}
$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 "<h2>{$uri}{$file}</h2>";
$response = $HTTP->doRequest('HEAD', $uri . $file);
echo '<details><summary>Status: ' . $response->status . '</summary><pre>' . \print_r($response->headers, 1) . '</pre></details>';
$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 "<h3>encoding</h3>";
$response = $HTTP->doRequest('GET', $uri . $file, null, ['Accept-Encoding' => 'gzip, deflate, br']);
echo '<details><summary>Status: ' . $response->status . '</summary><pre>' . \print_r($response->headers, 1) . '</pre></details>';
*/
echo "<h3>gzip encoded</h3>";
$response = $HTTP->doRequest('HEAD', $uri . $file . '.gz');
echo '<details><summary>Status: ' . $response->status . '</summary><pre>' . \print_r($response->headers, 1) . '</pre></details>';
$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 "<h3>brotli encoded</h3>";
$response = $HTTP->doRequest('HEAD', $uri . $file . '.br');
echo '<details><summary>Status: ' . $response->status . '</summary><pre>' . \print_r($response->headers, 1) . '</pre></details>';
$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;
}
}

View file

@ -1,56 +1,17 @@
<?php
if (PHP_VERSION_ID < 70400) {
echo '<p style="color: red">';
echo '[301] Your PHP version ('.PHP_VERSION.') is lower than the minimal required 7.4.0!';
echo '</p>';
require_once __DIR__ . 'app/libraries/snappymail/integrity.php';
$result = \SnappyMail\Integrity::phpVersion();
if ($result) {
echo '<p style="color: red">[301] ' . $result . '</p>';
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 '<p>[302] The following PHP extensions are not available in your PHP configuration!</p>';
echo '<ul>';
foreach ($aRequirements as $sKey => $bValue) {
if (!$bValue) {
echo '<li>'.$sKey.'</li>';
}
}
echo '</ul>';
echo '<ul><li>' . \implode('</li>li><li>', $result) . '</li></ul>';
exit(302);
}