From 82837572d4c49ab02d9c37c08ec32949496fe135 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 19 Jul 2020 11:09:45 +0530 Subject: [PATCH] Add ionCube Loader support --- __tests__/extensions.test.ts | 9 +++++++- dist/index.js | 25 +++++++++++++++++++++ src/extensions.ts | 25 +++++++++++++++++++++ src/scripts/ext/ioncube.ps1 | 42 ++++++++++++++++++++++++++++++++++++ src/scripts/ext/ioncube.sh | 38 ++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/scripts/ext/ioncube.ps1 create mode 100644 src/scripts/ext/ioncube.sh diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 70f9d0f6..4c259209 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -11,7 +11,7 @@ describe('Extension tests', () => { }); it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'Xdebug, pcov, sqlite, :intl, phalcon4, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', + 'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', '7.4', 'win32' ); @@ -20,6 +20,7 @@ describe('Extension tests', () => { expect(win32).toContain('Add-Extension sqlite3'); expect(win32).toContain('Remove-Extension intl'); expect(win32).toContain('phalcon.ps1 phalcon4'); + expect(win32).toContain('ioncube.ps1 7.4'); expect(win32).toContain('oci.ps1 oci8 7.4'); expect(win32).toContain('oci.ps1 pdo_oci 7.4'); expect(win32).toContain('Add-Extension ast beta'); @@ -109,6 +110,9 @@ describe('Extension tests', () => { expect(linux).toContain('phalcon.sh phalcon3 7.3'); expect(linux).toContain('phalcon.sh phalcon4 7.3'); + linux = await extensions.addExtension('ioncube', '7.3', 'linux'); + expect(linux).toContain('ioncube.sh 7.3'); + linux = await extensions.addExtension('oci8, pdo_oci', '7.3', 'linux'); expect(linux).toContain('oci.sh oci8 7.3'); expect(linux).toContain('oci.sh pdo_oci 7.3'); @@ -142,6 +146,9 @@ describe('Extension tests', () => { darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); expect(darwin).toContain('phalcon_darwin.sh phalcon4 7.3'); + darwin = await extensions.addExtension('ioncube', '7.3', 'darwin'); + expect(darwin).toContain('ioncube.sh 7.3'); + darwin = await extensions.addExtension('oci8, pdo_oci', '7.3', 'darwin'); expect(darwin).toContain('oci.sh oci8 7.3'); expect(darwin).toContain('oci.sh pdo_oci 7.3'); diff --git a/dist/index.js b/dist/index.js index 56e48164..b8a24625 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3682,6 +3682,14 @@ async function addExtensionDarwin(extension_csv, version, pipe) { ' ' + version; return; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\nbash ' + + path.join(__dirname, '../src/scripts/ext/ioncube.sh') + + ' ' + + version; + return; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += @@ -3775,6 +3783,15 @@ async function addExtensionWindows(extension_csv, version) { version + '\n'; break; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\n& ' + + path.join(__dirname, '../src/scripts/ext/ioncube.ps1') + + ' ' + + version + + '\n'; + break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += @@ -3866,6 +3883,14 @@ async function addExtensionLinux(extension_csv, version, pipe) { ' ' + version; return; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\nbash ' + + path.join(__dirname, '../src/scripts/ext/ioncube.sh') + + ' ' + + version; + return; // match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += diff --git a/src/extensions.ts b/src/extensions.ts index 25afc6d2..e694d994 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -123,6 +123,14 @@ export async function addExtensionDarwin( ' ' + version; return; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\nbash ' + + path.join(__dirname, '../src/scripts/ext/ioncube.sh') + + ' ' + + version; + return; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += @@ -225,6 +233,15 @@ export async function addExtensionWindows( version + '\n'; break; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\n& ' + + path.join(__dirname, '../src/scripts/ext/ioncube.ps1') + + ' ' + + version + + '\n'; + break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += @@ -322,6 +339,14 @@ export async function addExtensionLinux( ' ' + version; return; + // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube + case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): + add_script += + '\nbash ' + + path.join(__dirname, '../src/scripts/ext/ioncube.sh') + + ' ' + + version; + return; // match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): add_script += diff --git a/src/scripts/ext/ioncube.ps1 b/src/scripts/ext/ioncube.ps1 new file mode 100644 index 00000000..6e920ebe --- /dev/null +++ b/src/scripts/ext/ioncube.ps1 @@ -0,0 +1,42 @@ +Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $version +) + +# Function to log result of a operation. +Function Add-Log($mark, $subject, $message) { + $code = if ($mark -eq $cross) { "31" } else { "32" } + printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message +} + +$tick = ([char]8730) +$cross = ([char]10007) +$status = 'Enabled' +$php_dir = 'C:\tools\php' +if($env:RUNNER -eq 'self-hosted') { $php_dir = "$php_dir$version" } +$ext_dir = "$php_dir\ext" +$installed = Get-Php $php_dir +try { + if (-not(Test-Path $ext_dir\php_ioncube.dll)) { + $status = 'Installed and enabled' + $arch = 'x86-64' + if (-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') { + $arch = 'x86' + } + $vc = $installed.VCVersion + $ts = "" + if (-not($installed.ThreadSafe)) { + $ts = "_nonts" + } + Invoke-WebRequest -UseBasicParsing -Uri "https://downloads.ioncube.com/loader_downloads/ioncube_loaders_win$ts`_vc$vc`_$arch.zip" -OutFile $ext_dir\ioncube.zip + Expand-Archive -Path $ext_dir\ioncube.zip -DestinationPath $ext_dir -Force + Copy-Item $ext_dir\ioncube\ioncube_loader_win_$version.dll $ext_dir\php_ioncube.dll + } + "zend_extension=$ext_dir\php_ioncube.dll`r`n" + (Get-Content $php_dir\php.ini -Raw) | Set-Content $php_dir\php.ini + printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick "ioncube" $status +} catch { + Add-Log $cross "ioncube" "Could not install ioncube on PHP $($installed.FullVersion)" +} \ No newline at end of file diff --git a/src/scripts/ext/ioncube.sh b/src/scripts/ext/ioncube.sh new file mode 100644 index 00000000..93b18202 --- /dev/null +++ b/src/scripts/ext/ioncube.sh @@ -0,0 +1,38 @@ +# Function to log result of a operation. +add_log() { + mark=$1 + subject=$2 + message=$3 + if [ "$mark" = "$tick" ]; then + printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" + else + printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" + fi +} + +# Function to test if extension is loaded. +check_extension() { + extension=$1 + php -m | grep -i -q -w "$extension" +} + +# Function to install ioncube. +install_ioncube() { + if [ ! -e $ext_dir/ioncube.so ]; then + os_name='lin' + status='Installed and enabled' + [ "$(uname -s)" = "Darwin" ] && os_name='mac' + curl -sSL https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp + sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"$version".so "$ext_dir/ioncube.so" + fi + echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "$scan_dir/00-ioncube.ini" +} + +version=$1 +tick='✓' +cross='✗' +scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") +ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") +status='Enabled' +install_ioncube >/dev/null 2>&1 +(check_extension "ioncube" && add_log "$tick" "ioncube" "$status") || add_log "$cross" "ioncube" "Could not install ioncube"