Add support for SourceGuardian Loader (#442)

pull/443/head
Michele Locati 2021-09-28 11:44:47 +02:00 committed by GitHub
parent 872d4e5302
commit f9cf2dedc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 4 deletions

View File

@ -82,6 +82,7 @@ snuffleupagus 7.0 7.1 7.2 7.3 7.4 8.0 8.1
soap 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1
sockets 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1
solr 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1
sourceguardian 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0
spx 5.6 7.0 7.1 7.2 7.3 7.4 8.0
sqlsrv 7.0 7.1 7.2 7.3 7.4 8.0 8.1
ssh2 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1

View File

@ -70,11 +70,16 @@ setDistro() {
# Set:
# - PHP_MAJMIN_VERSION: Major-Minor version, format MMmm (example 800 for PHP 8.0.1)
# - PHP_MAJDOTMIN_VERSION: Major-Minor version, format M.m (example 8.0 for PHP 8.0.1)
# - PHP_MAJMINPAT_VERSION: Major-Minor-Patch version, format MMmmpp (example 80001 for PHP 8.0.1) variables containing integers value
# - PHP_MAJDOTMINDOTPAT_VERSION: Major-Minor-Patch version, format M.m.p (example 8.0.1 for PHP 8.0.1)
# - PHP_THREADSAFE: 1 if PHP is thread-safe (TS), 0 if not thread-safe (NTS)
setPHPVersionVariables() {
setPHPVersionVariables_textual="$(php-config --version)"
PHP_MAJMIN_VERSION=$(printf '%s' "$setPHPVersionVariables_textual" | awk -F. '{print $1*100+$2}')
PHP_MAJMINPAT_VERSION=$(printf '%s' "$setPHPVersionVariables_textual" | awk -F. '{print $1*10000+$2*100+$3}')
PHP_MAJDOTMINDOTPAT_VERSION="$(php-config --version)"
PHP_MAJMIN_VERSION=$(printf '%s' "$PHP_MAJDOTMINDOTPAT_VERSION" | awk -F. '{print $1*100+$2}')
PHP_MAJDOTMIN_VERSION=$(printf '%s' "$PHP_MAJDOTMINDOTPAT_VERSION" | cut -d. -f1-2)
PHP_MAJMINPAT_VERSION=$(printf '%s' "$PHP_MAJDOTMINDOTPAT_VERSION" | awk -F. '{print $1*10000+$2*100+$3}')
PHP_THREADSAFE=$(php -r 'echo ZEND_THREAD_SAFE ? 1 : 0;')
}
# Fix apt-get being very slow on Debian Jessie
@ -1452,6 +1457,38 @@ actuallyInstallComposer() {
rm -- "$actuallyInstallComposer_installer"
}
# Install SourceGuardian Loader
installSourceGuardian() {
case $(uname -m) in
i386 | i686 | x86)
installSourceGuardian_url=https://www.sourceguardian.com/loaders/download/loaders.linux-i386.tar.gz
;;
aarch64 | arm64 | armv8)
installSourceGuardian_url=https://www.sourceguardian.com/loaders/download/loaders.linux-aarch64.tar.gz
;;
*)
installSourceGuardian_url=https://www.sourceguardian.com/loaders/download/loaders.linux-x86_64.tar.gz
;;
esac
printf 'Downloading SourceGuardian... '
installSourceGuardian_dir="$(getPackageSource $installSourceGuardian_url)"
printf 'done (version: %s)\n' "$(cat "$installSourceGuardian_dir/version")"
for installSourceGuardian_phpv in $PHP_MAJDOTMINDOTPAT_VERSION $PHP_MAJDOTMIN_VERSION; do
installSourceGuardian_file="$installSourceGuardian_dir/ixed.$PHP_MAJDOTMIN_VERSION"
if test $PHP_THREADSAFE -eq 1; then
installSourceGuardian_file="${installSourceGuardian_file}ts"
fi
installSourceGuardian_file="${installSourceGuardian_file}.lin"
if test -f "$installSourceGuardian_file"; then
mv "$installSourceGuardian_file" "$(getPHPExtensionsDir)/sourceguardian.so"
return
fi
done
printf 'Unable to find a SourceGuardian compatible with PHP %s or PHP %s.\nAvailable SourceGuardian versions:\n' "$PHP_MAJDOTMINDOTPAT_VERSION" "$PHP_MAJDOTMIN_VERSION" >&2
ls -1 "$installSourceGuardian_dir" | grep -E '^ixed\..*\.lin$' | sed -E 's/^[^0-9]+([0-9]+(\.[0-9]+)*).*$/\1/' | sort | uniq >&2
exit 1
}
# Install a bundled PHP module given its handle
#
# Arguments:
@ -2185,6 +2222,10 @@ installRemoteModule() {
fi
fi
;;
sourceguardian)
installSourceGuardian
installRemoteModule_manuallyInstalled=1
;;
spx)
if test -z "$installRemoteModule_version"; then
installRemoteModule_version=1367cbc70194d18888ec9cfe9b06c0a5b4426dff
@ -2581,7 +2622,7 @@ installRemoteModule() {
# event must be loaded after sockets
docker-php-ext-enable --ini-name "xx-php-ext-$installRemoteModule_module.ini" "$installRemoteModule_module"
;;
ioncube_loader)
ioncube_loader | sourceguardian)
# On PHP 5.5, docker-php-ext-enable fails to detect that ionCube Loader is a Zend Extension
if test $PHP_MAJMIN_VERSION -le 505; then
printf 'zend_extension=%s/%s.so\n' "$(getPHPExtensionsDir)" "$installRemoteModule_module" >"$PHP_INI_DIR/conf.d/docker-php-ext-$installRemoteModule_module.ini"

30
scripts/tests/sourceguardian Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php
set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
$msg = "Error {$errno}: {$errstr}\n";
if ($errfile) {
$msg .= "File: {$errfile}\n";
if ($errline) {
$msg .= "Line: {$errline}\n";
}
}
fwrite(STDERR, $msg);
exit(1);
},
-1
);
$rc = 0;
foreach ([false => 'PHP module', true => 'Zend extension'] as $type => $typeName) {
$extensions = get_loaded_extensions($type);
$extensionsLowerCase = array_map('strtolower', $extensions);
if (in_array('sourceguardian', $extensionsLowerCase, true)) {
fwrite(STDOUT, "The SourceGuardian {$typeName} is loaded.\n");
} else {
fwrite(STDERR, "The SourceGuardian {$typeName} is not loaded.\nLoaded extensions are: \n- " . implode("\n- ", $extensions));
$rc = 1;
}
}
exit($rc);