From 9890eb9d21eebf2495f22f5a48e9a4cf0050a92d Mon Sep 17 00:00:00 2001 From: Ivan Klimchuk Date: Sat, 6 Nov 2021 00:37:17 +0300 Subject: [PATCH] fix: but it should be reverted --- .github/CODEOWNERS | 1 - .github/CONTRIBUTING.md | 9 - .github/FUNDING.yml | 4 - .github/ISSUE_TEMPLATE/BUG.md | 10 - .github/ISSUE_TEMPLATE/STORY.md | 13 - .github/ISSUE_TEMPLATE/TASK.md | 6 - .github/PULL_REQUEST_TEMPLATE.md | 8 - .github/semantic.yml | 5 - .gitmodules | 4 - _build/build.transport.php | 301 ++++++++++-------- _build/composer.json | 28 ++ _build/composer.lock | 93 ++++++ _build/helpers/ArrayXMLConverter.php | 143 --------- _build/implants/encryptedvehicle.class.php | 205 ------------ _build/install.script.php | 57 +--- _build/resolvers/resolve.encryption.php | 28 +- _build/validators/php-extensions.php | 42 +++ _build/validators/validate.bcmath.php | 44 --- _build/validators/validate.modxversion.php | 47 --- _build/validators/validate.oldversion.php | 49 --- _build/validators/validate.phpversion.php | 44 --- assets/{components => }/mspbepaid/bepaid.php | 0 .../{components => }/mspbepaid/connector.php | 0 .../mspbepaid/js/mgr/bepaid.js | 0 .../mspbepaid/js/mgr/country.combo.js | 0 .../mspbepaid/js/mgr/language.combo.js | 0 .../mspbepaid/js/mgr/properties.grid.js | 0 .../mspbepaid/js/mgr/properties.tab.js | 0 .../mspbepaid/js/mgr/property.window.js | 0 .../mspbepaid/js/mgr/readonly.combo.js | 0 .../mspbepaid/js/mgr/resource.combo.js | 0 .../mspbepaid/js/mgr/settings.combo.js | 0 .../mspbepaid/js/mgr/status.combo.js | 0 .../mspbepaid/js/mgr/visible.combo.js | 0 .../mspbepaid/BePaid.class.php | 0 .../mspbepaid/elements/plugins/mspBePaid.php | 24 +- core/mspbepaid/encryptedvehicle.class.php | 240 ++++++++++++++ core/mspbepaid/helpers/xml.php | 58 ++++ .../lexicon/en/msp.bepaid.inc.php | 0 .../lexicon/ru/msp.bepaid.inc.php | 0 .../processors/mgr/properties/base.class.php | 0 .../mgr/properties/create.class.php | 0 .../mgr/properties/delete.class.php | 0 .../mgr/properties/getlist.class.php | 0 .../mgr/properties/update.class.php | 0 45 files changed, 652 insertions(+), 811 deletions(-) delete mode 100644 .github/CODEOWNERS delete mode 100644 .github/CONTRIBUTING.md delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/ISSUE_TEMPLATE/BUG.md delete mode 100644 .github/ISSUE_TEMPLATE/STORY.md delete mode 100644 .github/ISSUE_TEMPLATE/TASK.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/semantic.yml delete mode 100644 .gitmodules create mode 100644 _build/composer.json create mode 100644 _build/composer.lock delete mode 100644 _build/helpers/ArrayXMLConverter.php delete mode 100644 _build/implants/encryptedvehicle.class.php create mode 100644 _build/validators/php-extensions.php delete mode 100644 _build/validators/validate.bcmath.php delete mode 100644 _build/validators/validate.modxversion.php delete mode 100644 _build/validators/validate.oldversion.php delete mode 100644 _build/validators/validate.phpversion.php rename assets/{components => }/mspbepaid/bepaid.php (100%) rename assets/{components => }/mspbepaid/connector.php (100%) rename assets/{components => }/mspbepaid/js/mgr/bepaid.js (100%) rename assets/{components => }/mspbepaid/js/mgr/country.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/language.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/properties.grid.js (100%) rename assets/{components => }/mspbepaid/js/mgr/properties.tab.js (100%) rename assets/{components => }/mspbepaid/js/mgr/property.window.js (100%) rename assets/{components => }/mspbepaid/js/mgr/readonly.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/resource.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/settings.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/status.combo.js (100%) rename assets/{components => }/mspbepaid/js/mgr/visible.combo.js (100%) rename core/{components => }/mspbepaid/BePaid.class.php (100%) rename core/{components => }/mspbepaid/elements/plugins/mspBePaid.php (62%) create mode 100644 core/mspbepaid/encryptedvehicle.class.php create mode 100644 core/mspbepaid/helpers/xml.php rename core/{components/minishop2 => mspbepaid}/lexicon/en/msp.bepaid.inc.php (100%) rename core/{components/minishop2 => mspbepaid}/lexicon/ru/msp.bepaid.inc.php (100%) rename core/{components => }/mspbepaid/processors/mgr/properties/base.class.php (100%) rename core/{components => }/mspbepaid/processors/mgr/properties/create.class.php (100%) rename core/{components => }/mspbepaid/processors/mgr/properties/delete.class.php (100%) rename core/{components => }/mspbepaid/processors/mgr/properties/getlist.class.php (100%) rename core/{components => }/mspbepaid/processors/mgr/properties/update.class.php (100%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index eddbe26..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @Alroniks diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index cb1e28d..0000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,9 +0,0 @@ -# Contributing rules - -Before submitting a new issue or creating pull request, please, check if issue or pull request already exists.a - -When you create issue or pull request, please, follow the template provided by the repository. - -When you add new features or fix bugs, please, check [CHANGELOG](../CHANGELOG.md) file and adjust it by adding short human readable description of what you did. See [keepachangelog.com](https://keepachangelog.com/en/1.0.0/) for more information. - - diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 22b1035..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,4 +0,0 @@ -# These are supported funding model platforms -github: [Alroniks] -patreon: ivanklimchuk -custom: https://money.yandex.ru/to/41001878021446 diff --git a/.github/ISSUE_TEMPLATE/BUG.md b/.github/ISSUE_TEMPLATE/BUG.md deleted file mode 100644 index 0da1142..0000000 --- a/.github/ISSUE_TEMPLATE/BUG.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: "Bug Report" -about: 'Report issue if something works unexpected' ---- - -### Description: - - -### Steps To Reproduce: - diff --git a/.github/ISSUE_TEMPLATE/STORY.md b/.github/ISSUE_TEMPLATE/STORY.md deleted file mode 100644 index 4c66627..0000000 --- a/.github/ISSUE_TEMPLATE/STORY.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: "User Story" -about: 'Story or epic that describes general goal from user perspective' ---- - -### Story -As a [user], I [want to], [so that]. - -### Acceptance Criteria - -### Task list -- [ ] #124 - Task description - diff --git a/.github/ISSUE_TEMPLATE/TASK.md b/.github/ISSUE_TEMPLATE/TASK.md deleted file mode 100644 index 9efa64e..0000000 --- a/.github/ISSUE_TEMPLATE/TASK.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -name: "Task Issue" -about: 'Usual task with description what to do to achieve the goal of story' ---- - - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 8e37a3c..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,8 +0,0 @@ -### What does it do? -Describe the technical changes you did. - -### Why is it needed? -Describe the issue you are solving. - -### Related issue -Closes - _provide id of issue for solving which this changes applied_ diff --git a/.github/semantic.yml b/.github/semantic.yml deleted file mode 100644 index 40b6927..0000000 --- a/.github/semantic.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Always validate the PR title AND all the commits -titleAndCommits: true -# Allows use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns") -# this is only relevant when using commitsOnly: true (or titleAndCommits: true) -allowMergeCommits: true diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c90ba2b..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "_build/xpdo"] - path = _build/xpdo - url = https://github.com/modxcms/xpdo.git - branch = 2.x diff --git a/_build/build.transport.php b/_build/build.transport.php index 8a77569..f02ca58 100644 --- a/_build/build.transport.php +++ b/_build/build.transport.php @@ -1,75 +1,185 @@ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +/** @noinspection AutoloadingIssuesInspection */ /** - * mspBePaid package builder - * - * @author Ivan Klimchuk - * @package mspbepaid - * @subpackage build + * Copyright (c) Ivan Klimchuk - All Rights Reserved + * Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited. + * Written by Ivan Klimchuk , 2021 */ -set_time_limit(0); +declare(strict_types = 1); +use function alroniks\mspbepaid\helpers\xml\arrayToXml; +use function alroniks\mspbepaid\helpers\xml\xmlToArray; + +set_time_limit(0); +error_reporting(E_ALL | E_STRICT); +ini_set('display_errors', 'On'); ini_set('date.timezone', 'Europe/Minsk'); -define('PKG_NAME', 'mspBePaid'); -define('PKG_NAME_LOWER', strtolower(PKG_NAME)); -define('PKG_VERSION', '2.5.2'); -define('PKG_RELEASE', 'pl'); - -require_once __DIR__ . '/xpdo/xpdo/xpdo.class.php'; -require_once __DIR__ . '/xpdo/xpdo/transport/xpdotransport.class.php'; -require_once __DIR__ . '/xpdo/xpdo/transport/xpdovehicle.class.php'; -require_once __DIR__ . '/xpdo/xpdo/transport/xpdofilevehicle.class.php'; -require_once __DIR__ . '/xpdo/xpdo/transport/xpdoscriptvehicle.class.php'; -require_once __DIR__ . '/xpdo/xpdo/transport/xpdoobjectvehicle.class.php'; - -require_once __DIR__ . '/helpers/ArrayXMLConverter.php'; -require_once __DIR__ . '/implants/encryptedvehicle.class.php'; - -$xpdo = xPDO::getInstance('db', [ - xPDO::OPT_CACHE_PATH => __DIR__ . '/../cache/', - xPDO::OPT_HYDRATE_FIELDS => true, - xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, - xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, - xPDO::OPT_CONNECTIONS => [ - [ - 'dsn' => 'mysql:host=localhost;dbname=xpdotest;charset=utf8', - 'username' => 'test', - 'password' => 'test', - 'options' => [xPDO::OPT_CONN_MUTABLE => true], - 'driverOptions' => [], - ] - ] -]); +require_once __DIR__ . '/vendor/autoload.php'; + +$composer = json_decode(file_get_contents(__DIR__ . '/composer.json'), true, 512, JSON_THROW_ON_ERROR); -$xpdo->setLogLevel(); +[, $package] = explode('/', $composer['name']); + +define('PKG_NAME_LOWER', $package); +define('PKG_VERSION', $composer['version']); +define('PKG_RELEASE', $composer['minimum-stability']); + +require_once __DIR__ . '/vendor/modx/revolution/core/xpdo/xpdo.class.php'; + +/* instantiate xpdo instance */ +$xpdo = new xPDO( + 'mysql:host=localhost;dbname=modx;charset=utf8', 'root', '', + [xPDO::OPT_TABLE_PREFIX => 'modx_', xPDO::OPT_CACHE_PATH => __DIR__ . '/../../../core/cache/'], + [PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING] +); +$cacheManager = $xpdo->getCacheManager(); +$xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO); $xpdo->setLogTarget(); -class modNamespace extends xPDOObject {} +$signature = implode('-', [PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE]); + +if (!empty($argv) && $argc > 1) { + [, $release, $encryption] = array_replace(array_fill(0, 3,null), $argv); +} + +$directory = (isset($release) && $release === 'release') ? dirname(__DIR__) . '/_packages/' : __DIR__ . '/../../../core/packages/'; +$filename = $directory . $signature . '.transport.zip'; + +/* remove the package if it's already been made */ +if (file_exists($filename)) { + unlink($filename); +} +if (file_exists($directory . $signature) && is_dir($directory . $signature)) { + $cacheManager = $xpdo->getCacheManager(); + if ($cacheManager) { + $cacheManager->deleteTree($directory . $signature, true, false, []); + } +} + +$xpdo->loadClass('transport.xPDOTransport', XPDO_CORE_PATH, true, true); +$xpdo->loadClass('transport.xPDOVehicle', XPDO_CORE_PATH, true, true); +$xpdo->loadClass('transport.xPDOObjectVehicle', XPDO_CORE_PATH, true, true); +$xpdo->loadClass('transport.xPDOFileVehicle', XPDO_CORE_PATH, true, true); +$xpdo->loadClass('transport.xPDOScriptVehicle', XPDO_CORE_PATH, true, true); + +$credentials = $encryption ?? file_get_contents(__DIR__ . '/../.encryption'); +if ($credentials) { + [$username, $key] = explode(':', $credentials); +} + +if (empty($username) || empty($key)) { + $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Credentials not found'); + exit; +} + +$params = [ + 'api_key' => trim($key), + 'username' => trim($username), + 'http_host' => 'any-site.local.docker', + 'package' => PKG_NAME_LOWER, + 'version' => PKG_VERSION . '-' . PKG_RELEASE, + 'vehicle_version' => '2.0.0', +]; + +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, 'https://modstore.pro/extras/package/encode'); +curl_setopt($ch, CURLOPT_POST, 1); +curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xml']); +curl_setopt($ch, CURLOPT_POSTFIELDS, arrayToXml(['request' => $params])->outputMemory()); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); +curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); +$xml = trim(curl_exec($ch)); +curl_close($ch); + +$answer = xmlToArray($xml); + +if (isset($answer['message'])) { + $xpdo->log(xPDO::LOG_LEVEL_ERROR, $answer['message']); + exit; +} + +$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Encryption key is: ' . $answer['key']); + +define('PKG_ENCODE_KEY', $answer['key']); + +$package = new xPDOTransport($xpdo, $signature, $directory); + +$xpdo->setPackage('modx', __DIR__ . '/vendor/modx/revolution/core/model/'); +$xpdo->loadClass(modAccess::class); +$xpdo->loadClass(modAccessibleObject::class); +$xpdo->loadClass(modAccessibleSimpleObject::class); +$xpdo->loadClass(modPrincipal::class); +$xpdo->loadClass(modElement::class); +$xpdo->loadClass(modScript::class); + +// Put files into package +$package->put( + [ + 'source' => __DIR__ . '/../assets/' . PKG_NAME_LOWER, + 'target' => "return MODX_ASSETS_PATH . 'components/';", + ], + ['vehicle_class' => xPDOFileVehicle::class] +); +$package->put( + [ + 'source' => __DIR__ . '/../core/' . PKG_NAME_LOWER, + 'target' => "return MODX_CORE_PATH . 'components/';", + ], + ['vehicle_class' => xPDOFileVehicle::class] +); +$package->put( + ['source' => __DIR__ . '/resolvers/encryption.php'], + ['vehicle_class' => xPDOScriptVehicle::class] +); + +class EncryptedVehicle extends xPDOObjectVehicle {} + +$namespace = $xpdo->newObject(modNamespace::class); +$namespace->set('name', PKG_NAME_LOWER); +$namespace->fromArray( + [ + 'path' => '{core_path}components/' . PKG_NAME_LOWER . '/', + 'assets_path' => '{assets_path}components/' . PKG_NAME_LOWER . '/', + ] +); + +$package->put( + $namespace, + [ + 'vehicle_class' => EncryptedVehicle::class, + xPDOTransport::UNIQUE_KEY => 'name', + xPDOTransport::PRESERVE_KEYS => true, + xPDOTransport::UPDATE_OBJECT => true, + xPDOTransport::ABORT_INSTALL_ON_VEHICLE_FAIL => true, + 'validate' => [ + ['type' => 'php', 'source' => __DIR__ . '/validators/php-extensions.php'], + ], + ] +); + +$package->setAttribute('changelog', file_get_contents(__DIR__ . '/../changelog.md')); +$package->setAttribute('license', file_get_contents(__DIR__ . '/../license')); +$package->setAttribute('readme', file_get_contents(__DIR__ . '/../docs/about.md')); +$package->setAttribute( + 'requires', + [ + 'php' => '>=7.4', + 'modx' => '>=2.8', + 'miniShop2' => '>=2.5', + 'msPaymentProps' => '>=0.3.4-stable', + ] +); + + + +///============= + + + class modCategory extends xPDOObject { public function getFKDefinition($alias) { @@ -125,78 +235,9 @@ class msPayment extends xPDOObject {} ], ]; -$signature = join('-', [PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE]); -$directory = $root . '_packages/'; -//$directory = __DIR__ . '/../../../core/packages/'; -$filename = $directory . $signature . '.transport.zip'; - -/* remove the package if it's already been made */ -if (file_exists($filename)) { - unlink($filename); -} -if (file_exists($directory . $signature) && is_dir($directory . $signature)) { - $cacheManager = $xpdo->getCacheManager(); - if ($cacheManager) { - $cacheManager->deleteTree($directory . $signature, true, false, []); - } -} - -$credentials = file_get_contents(__DIR__ . '/../.encryption'); -list($username, $key) = explode(':', $credentials); - -if (empty($username) || empty($key)) { - $xpdo->log(xPDO::LOG_LEVEL_ERROR, "Credentials not found."); - exit; -} - -$params = [ - 'api_key' => $key, - 'username' => $username, - 'http_host' => 'anysite.docker', - 'package' => PKG_NAME, - 'version' => PKG_VERSION . '-' . PKG_RELEASE, - 'vehicle_version' => '2.0.0' -]; - -$ch = curl_init(); -curl_setopt($ch, CURLOPT_URL, 'https://modstore.pro/extras/package/encode'); -curl_setopt($ch, CURLOPT_POST, 1); -curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xml']); -curl_setopt($ch, CURLOPT_POSTFIELDS, ArrayXMLConverter::toXML($params,'request')); -curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); -curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); -$result = trim(curl_exec($ch)); -curl_close($ch); - -$answer = ArrayXMLConverter::toArray($result); - -if (isset($answer['message'])) { - $xpdo->log(xPDO::LOG_LEVEL_ERROR, $answer['message']); - echo $answer['message']; - exit; -} - -define('PKG_ENCODE_KEY', $answer['key']); - $package = new xPDOTransport($xpdo, $signature, $directory); -// insert class EncryptedVehicle -$package->put(new xPDOFileVehicle, [ - 'vehicle_class' => 'xPDOFileVehicle', - 'object' => [ - 'source' => $sources['implants'] . 'encryptedvehicle.class.php', - 'target' => "return MODX_CORE_PATH . 'components/" . PKG_NAME_LOWER . "/';" - ] -]); -// load class EncryptedVehicle -$package->put(new xPDOScriptVehicle, [ - 'vehicle_class' => 'xPDOScriptVehicle', - 'object' => [ - 'source' => $sources['resolvers'] . 'resolve.encryption.php' - ] -]); $namespace = new modNamespace($xpdo); $namespace->fromArray([ diff --git a/_build/composer.json b/_build/composer.json new file mode 100644 index 0000000..d91805d --- /dev/null +++ b/_build/composer.json @@ -0,0 +1,28 @@ +{ + "name": "alroniks/mspbepaid", + "description": "Payment provider for MODX miniShop2 e-commerce solutions based on bePaid system.", + "type": "metapackage", + "version": "2.5.2", + "license": "proprietary", + "authors": [ + { + "name": "Ivan Klimchuk", + "email": "ivan@klimchuk.com" + } + ], + "minimum-stability": "dev", + "prefer-stable": true, + "require-dev": { + "modx/revolution": "~2.0" + }, + "require": { + "php": ">=7.4", + "ext-pdo": "*", + "ext-curl": "*", + "ext-simplexml": "*", + "ext-json": "*", + "ext-xmlwriter": "*", + "ext-bcmath": "*", + "ext-openssl": "*" + } +} diff --git a/_build/composer.lock b/_build/composer.lock new file mode 100644 index 0000000..51809b2 --- /dev/null +++ b/_build/composer.lock @@ -0,0 +1,93 @@ +{ + "_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#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "45611284fdb651b9d0ce6ee29d5a7c9b", + "packages": [], + "packages-dev": [ + { + "name": "modx/revolution", + "version": "v2.8.3-pl", + "source": { + "type": "git", + "url": "https://github.com/modxcms/revolution.git", + "reference": "9f34bc936bcfa604d462a3f8b8fa3a36586b4395" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/modxcms/revolution/zipball/9f34bc936bcfa604d462a3f8b8fa3a36586b4395", + "reference": "9f34bc936bcfa604d462a3f8b8fa3a36586b4395", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "php-coveralls/php-coveralls": "~2.1", + "phpunit/phpunit": "~5.7|~6.5" + }, + "type": "project", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0+" + ], + "authors": [ + { + "name": "Jason Coward", + "email": "jason@opengeek.com", + "homepage": "http://jasoncoward.com/", + "role": "Developer" + }, + { + "name": "Shaun McCormick", + "email": "splittingred@gmail.com", + "homepage": "http://splittingred.com/", + "role": "Developer" + }, + { + "name": "Jan Peca", + "email": "pecajan@gmail.com", + "homepage": "http://www.bxr.cz/", + "role": "Developer" + } + ], + "description": "MODX Revolution is a Content Management System", + "homepage": "https://modx.com/", + "keywords": [ + "cms", + "content", + "routing", + "templating" + ], + "support": { + "chat": "https://modx.org/", + "docs": "https://docs.modx.com/", + "email": "help@modx.com", + "forum": "https://community.modx.com/", + "irc": "irc://irc.freenode.org/modx", + "issues": "https://github.com/modxcms/revolution/issues/", + "source": "https://github.com/modxcms/revolution/" + }, + "time": "2021-05-28T14:54:39+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": ">=7.4", + "ext-pdo": "*", + "ext-curl": "*", + "ext-simplexml": "*", + "ext-json": "*", + "ext-xmlwriter": "*", + "ext-bcmath": "*", + "ext-openssl": "*" + }, + "platform-dev": [], + "plugin-api-version": "2.1.0" +} diff --git a/_build/helpers/ArrayXMLConverter.php b/_build/helpers/ArrayXMLConverter.php deleted file mode 100644 index 51c33a6..0000000 --- a/_build/helpers/ArrayXMLConverter.php +++ /dev/null @@ -1,143 +0,0 @@ - - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * Utility class for array-to-XML transformations. - * @note Moved from original MODX sources for get independence from installed MODX - * @package modx - * @subpackage rest - */ -class ArrayXMLConverter -{ - /** - * The main function for converting to an XML document. - * Pass in a multi dimensional array and this recursively loops through and builds up an XML document. - * @param array $data - * @param string $rootNodeName - what you want the root node to be - defaults to data. - * @param SimpleXMLElement $xml - should only be used recursively - * @return string XML - */ - public static function toXML($data, $rootNodeName = 'ResultSet', &$xml = null) - { - // turn off compatibility mode as simple xml throws a wobbly if you don't. - if (ini_get('zend.ze1_compatibility_mode') == 1) { - ini_set('zend.ze1_compatibility_mode', 0); - } - - if (is_null($xml)) { - $xml = simplexml_load_string('<' . $rootNodeName . '>'); - } - - // loop through the data passed in. - foreach ($data as $key => $value) { - - // no numeric keys in our xml please! - if (is_numeric($key)) { - $numeric = 1; - $key = $rootNodeName; - } - - // delete any char not allowed in XML element names - $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key); - - // if there is another array found recursively call this function - if (is_array($value)) { - $node = static::isAssoc($value) || $numeric ? $xml->addChild($key) : $xml; - - // recrusive call. - if ($numeric) { - $key = 'anon'; - } - static::toXml($value, $key, $node); - } else { - - // add single node. - $value = htmlentities($value); - $xml->addChild($key, $value); - } - } - - // pass back as XML - //return $xml->asXML(); - - // if you want the XML to be formatted, use the below instead to return the XML - $doc = new DOMDocument('1.0'); - $doc->preserveWhiteSpace = false; - $doc->loadXML($xml->asXML()); - $doc->formatOutput = true; - - return $doc->saveXML(); - } - - /** - * Convert an XML document to a multi dimensional array - * Pass in an XML document (or SimpleXMLElement object) and this recrusively loops through and builds a representative array - * @param string $xml - XML document - can optionally be a SimpleXMLElement object - * @return array ARRAY - */ - public static function toArray($xml) - { - if (is_string($xml)) { - $xml = new SimpleXMLElement($xml); - } - $children = $xml->children(); - if (!$children) { - return (string) $xml; - } - $arr = array(); - foreach ($children as $key => $node) { - - $node = static::toArray($node); - - // support for 'anon' non-associative arrays - if ($key == 'anon') { - $key = count($arr); - } - - // if the node is already set, put it into an array - if (isset($arr[$key])) { - if (!is_array($arr[$key]) || $arr[$key][0] == null) { - $arr[$key] = array($arr[$key]); - } - $arr[$key][] = $node; - } else { - $arr[$key] = $node; - } - } - - return $arr; - } - - /** - * Determine if a variable is an associative array - * @static - * @param mixed $array The variable to check - * @return boolean True if is an array - */ - public static function isAssoc($array) - { - return (is_array($array) && 0 !== count(array_diff_key($array, array_keys(array_keys($array))))); - } -} diff --git a/_build/implants/encryptedvehicle.class.php b/_build/implants/encryptedvehicle.class.php deleted file mode 100644 index b919f8e..0000000 --- a/_build/implants/encryptedvehicle.class.php +++ /dev/null @@ -1,205 +0,0 @@ - - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * Class EncryptedVehicle - */ -class EncryptedVehicle extends xPDOObjectVehicle -{ - const VERSION = '2.0.0'; - const CIPHER = 'AES-256-CBC'; - - public $class = self::class; - - /** - * @param $transport xPDOTransport - * @param $object - * @param array $attributes - */ - public function put(&$transport, &$object, $attributes = array()) - { - parent::put($transport, $object, $attributes); - - if (defined('PKG_ENCODE_KEY')) { - - $this->payload['object_encrypted'] = $this->encode($this->payload['object'], PKG_ENCODE_KEY); - unset($this->payload['object']); - - if (isset($this->payload['related_objects'])) { - $this->payload['related_objects_encrypted'] = $this->encode($this->payload['related_objects'], PKG_ENCODE_KEY); - unset($this->payload['related_objects']); - } - - $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Package encrypted!'); - } - } - - /** - * @param $transport xPDOTransport - * @param $options - * - * @return bool - */ - public function install(&$transport, $options) - { - if (!$this->decodePayloads($transport, 'install')) { - $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Vehicle can not be decrypted!'); - return false; - } else { - $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Vehicle decrypted!'); - } - - return parent::install($transport, $options); - } - - /** - * @param $transport xPDOTransport - * @param $options - * - * @return bool - */ - public function uninstall(&$transport, $options) - { - if (!$this->decodePayloads($transport, 'uninstall')) { - $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Vehicle can not be decrypted!'); - return false; - } else { - $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Vehicle decrypted!'); - } - - return parent::uninstall($transport, $options); - } - - /** - * @param array $data - * @param string $key - * - * @return string - */ - protected function encode($data, $key) - { - $ivLen = openssl_cipher_iv_length(self::CIPHER); - $iv = openssl_random_pseudo_bytes($ivLen); - $cipher_raw = openssl_encrypt(serialize($data), self::CIPHER, $key, OPENSSL_RAW_DATA, $iv); - - return base64_encode($iv . $cipher_raw); - } - - /** - * @param string $string - * @param string $key - * - * @return string - */ - protected function decode($string, $key) - { - $ivLen = openssl_cipher_iv_length(self::CIPHER); - $encoded = base64_decode($string); - - if (ini_get('mbstring.func_overload')) { - $strLen = mb_strlen($encoded, '8bit'); - $iv = mb_substr($encoded, 0, $ivLen, '8bit'); - $cipher_raw = mb_substr($encoded, $ivLen, $strLen, '8bit'); - } else { - $iv = substr($encoded, 0, $ivLen); - $cipher_raw = substr($encoded, $ivLen); - } - - return unserialize(openssl_decrypt($cipher_raw, self::CIPHER, $key, OPENSSL_RAW_DATA, $iv)); - } - - /** - * @param $transport xPDOTransport - * @param string $action - * - * @return bool - */ - protected function decodePayloads(&$transport, $action = 'install') - { - if (isset($this->payload['object_encrypted']) || isset($this->payload['related_objects_encrypted'])) { - if (!$key = $this->getDecodeKey($transport, $action)) { - return false; - } - if (isset($this->payload['object_encrypted'])) { - $this->payload['object'] = $this->decode($this->payload['object_encrypted'], $key); - unset($this->payload['object_encrypted']); - } - if (isset($this->payload['related_objects_encrypted'])) { - $this->payload['related_objects'] = $this->decode($this->payload['related_objects_encrypted'], $key); - unset($this->payload['related_objects_encrypted']); - } - } - - return true; - } - - /** - * @param $transport xPDOTransport - * @param $action - * - * @return bool|string - */ - protected function getDecodeKey(&$transport, $action) - { - $key = false; - $endpoint = 'package/decode/' . $action; - - /** @var modTransportPackage $package */ - $package = $transport->xpdo->getObject('transport.modTransportPackage', [ - 'signature' => $transport->signature - ]); - - if ($package instanceof modTransportPackage) { - /** @var modTransportProvider $provider */ - if ($provider = $package->getOne('Provider')) { - - $provider->xpdo->setOption('contentType', 'default'); - $params = array( - 'package' => $package->package_name, - 'version' => $transport->version, - 'username' => $provider->username, - 'api_key' => $provider->api_key, - 'vehicle_version' => self::VERSION, - ); - - $response = $provider->request($endpoint, 'POST', $params); - - if ($response->isError()) { - $msg = $response->getError(); - $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, $msg); - } else { - $data = $response->toXml(); - if (!empty($data->key)) { - $key = $data->key; - } elseif (!empty($data->message)) { - $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, $data->message); - } - } - } - } - - return $key; - } -} diff --git a/_build/install.script.php b/_build/install.script.php index e00c927..ef5c898 100644 --- a/_build/install.script.php +++ b/_build/install.script.php @@ -1,63 +1,32 @@ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. +/** + * Copyright (c) Ivan Klimchuk - All Rights Reserved + * Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited. + * Written by Ivan Klimchuk , 2021 */ -define('MODX_API_MODE', true); +const MODX_API_MODE = true; require_once __DIR__ . '/../../../index.php'; +/** @var modX $modx */ $modx->initialize('mgr'); -$modx->setLogLevel(xPDO::LOG_LEVEL_ERROR); +$modx->setLogLevel(xPDO::LOG_LEVEL_INFO); $modx->setLogTarget(); $modx->runProcessor('workspace/packages/scanlocal'); -$answer = $modx->runProcessor('workspace/packages/install', - ['signature' => 'mspbepaid-2.5.2-pl'] -); -$response = $answer->getResponse(); - -echo $response['message'], PHP_EOL; +$composer = json_decode(file_get_contents(__DIR__ . '/composer.json'), true, 512, JSON_THROW_ON_ERROR); +[, $packageName] = explode('/', $composer['name']); -echo 'Need set system settings for work...', PHP_EOL; +$signature = implode('-', [$packageName, $composer['version'], $composer['minimum-stability']]); -// Shop without 3-D Secure -$id = 361; -$sc = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d'; +$answer = $modx->runProcessor('workspace/packages/install', ['signature' => $signature]); -// Shop with 3-D Secure -//$id = 362; -//$sc = '9ad8ad735945919845b9a1996af72d886ab43d3375502256dbf8dd16bca59a4e'; - -$sid = $modx->getObject('modSystemSetting', 'ms2_payment_bepaid_store_id'); -$sid->set('value', $id); -$sid->save(); +$response = $answer->getResponse(); -$ssc = $modx->getObject('modSystemSetting', 'ms2_payment_bepaid_secret_key'); -$ssc->set('value', $sc); -$ssc->save(); +echo $response['message'], PHP_EOL; $modx->getCacheManager()->refresh(['system_settings' => []]); $modx->reloadConfig(); diff --git a/_build/resolvers/resolve.encryption.php b/_build/resolvers/resolve.encryption.php index f616ac2..077ccfe 100644 --- a/_build/resolvers/resolve.encryption.php +++ b/_build/resolvers/resolve.encryption.php @@ -1,28 +1,12 @@ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. +/** + * Copyright (c) Ivan Klimchuk - All Rights Reserved + * Unauthorized copying, changing, distributing this file, via any medium, is strictly prohibited. + * Written by Ivan Klimchuk , 2021 */ +declare(strict_types = 1); + /** @var xPDOTransport $transport */ $transport->xpdo->loadClass('transport.xPDOObjectVehicle', XPDO_CORE_PATH, true, true); $transport->xpdo->loadClass('EncryptedVehicle', MODX_CORE_PATH . 'components/' . strtolower($transport->name) . '/', true, true); diff --git a/_build/validators/php-extensions.php b/_build/validators/php-extensions.php new file mode 100644 index 0000000..3c891a5 --- /dev/null +++ b/_build/validators/php-extensions.php @@ -0,0 +1,42 @@ +, 2019 + */ + +declare(strict_types = 1); + +/** @var xPDOTransport $transport */ +/** @var array $options */ + +if (!$transport->xpdo) { + return false; +} + +$extensions = [ + 'pdo' => 'PHP Data Objects', + 'curl' => 'Client URL Library', + 'simplexml' => 'SimpleXML', + 'json' => 'JavaScript Object Notation', + 'xmlwriter' => 'XMLWriter', + 'bcmath' => 'BCMath Arbitrary Precision Mathematics', // or gmp? + 'openssl' => 'OpenSSL' +]; + +foreach ($extensions as $ext => $title) { + if (!extension_loaded($ext)) { + $message = sprintf(' + PHP extension `%s` (https://php.net/manual/en/book.%s.php) does not loaded. + This PHP extension is required for a proper work of this package. + Please, ask your sysadmin or hosting company to install and configure it before continue.', + $title, $ext === 'bcmath' ? 'bc' : $ext + ); + + $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, $message); + + return false; + } +} + +return true; diff --git a/_build/validators/validate.bcmath.php b/_build/validators/validate.bcmath.php deleted file mode 100644 index 62bbaca..0000000 --- a/_build/validators/validate.bcmath.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @package mspBePaid - * @subpackage build - */ - -if (!$object->xpdo) { - return false; -} - -if (!extension_loaded('bcmath')) { - $object->xpdo->log(modX::LOG_LEVEL_ERROR, 'Extension BC Math (http://php.net/manual/en/book.bc.php) does not loaded. This extension is required for accurate calculations of money amounts.'); - - return false; -} - -return true; diff --git a/_build/validators/validate.modxversion.php b/_build/validators/validate.modxversion.php deleted file mode 100644 index 26a2e80..0000000 --- a/_build/validators/validate.modxversion.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * MODX version checker for MODX less then 2.4 - * - * @author Ivan Klimchuk - * @package mspBePaid - * @subpackage build - */ - -if (!$object->xpdo) { - return false; -} - -$version_data = $object->xpdo->getVersionData(); -$version = join('.', [$version_data['version'], $version_data['major_version'], $version_data['minor_version']]); - -if (!version_compare($version, '2.4', '>=')) { - $object->xpdo->log(modX::LOG_LEVEL_ERROR, 'Invalid MODX version. Minimal supported version – 2.4.'); - - return false; -} - -return true; diff --git a/_build/validators/validate.oldversion.php b/_build/validators/validate.oldversion.php deleted file mode 100644 index 2c8311a..0000000 --- a/_build/validators/validate.oldversion.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * MODX version checker for MODX less then 2.4 - * - * @author Ivan Klimchuk - * @package mspBePaid - * @subpackage build - */ - -if (!$object->xpdo) { - return false; -} - -if (file_exists($object->xpdo->getOption('minishop2.core_path', null, MODX_CORE_PATH . 'components/minishop2/') - . 'custom/payment/bepaid.class.php' -)) { - $object->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'IMPORTANT NOTE! - The installer found that you use an old version of mspBePaid with old mechanism of registration custom classes for miniShop2. - The new version uses a new service registration mechanism and provides new functions but files in the `core/compoments/minishop2/custom/payment` folder have higher priority and prevent to loading proper service class. - The installer can not delete these files, since you could make your edits to the payment mechanism, but for the correct work of the new version you should remove or move these files from the `core/compoments/minishop2/custom/payment` folder yourself.'); - - return false; -} - -return true; diff --git a/_build/validators/validate.phpversion.php b/_build/validators/validate.phpversion.php deleted file mode 100644 index 00e459f..0000000 --- a/_build/validators/validate.phpversion.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @package mspBePaid - * @subpackage build - */ - -if (!$object->xpdo) { - return false; -} - -if (!version_compare(PHP_VERSION, '5.5', '>=')) { - $object->xpdo->log(modX::LOG_LEVEL_ERROR, 'Invalid php version. Minimal supported version – 5.5, because less versions not supported more by PHP core team. Details here: http://php.net/supported-versions.php'); - - return false; -} - -return true; diff --git a/assets/components/mspbepaid/bepaid.php b/assets/mspbepaid/bepaid.php similarity index 100% rename from assets/components/mspbepaid/bepaid.php rename to assets/mspbepaid/bepaid.php diff --git a/assets/components/mspbepaid/connector.php b/assets/mspbepaid/connector.php similarity index 100% rename from assets/components/mspbepaid/connector.php rename to assets/mspbepaid/connector.php diff --git a/assets/components/mspbepaid/js/mgr/bepaid.js b/assets/mspbepaid/js/mgr/bepaid.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/bepaid.js rename to assets/mspbepaid/js/mgr/bepaid.js diff --git a/assets/components/mspbepaid/js/mgr/country.combo.js b/assets/mspbepaid/js/mgr/country.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/country.combo.js rename to assets/mspbepaid/js/mgr/country.combo.js diff --git a/assets/components/mspbepaid/js/mgr/language.combo.js b/assets/mspbepaid/js/mgr/language.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/language.combo.js rename to assets/mspbepaid/js/mgr/language.combo.js diff --git a/assets/components/mspbepaid/js/mgr/properties.grid.js b/assets/mspbepaid/js/mgr/properties.grid.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/properties.grid.js rename to assets/mspbepaid/js/mgr/properties.grid.js diff --git a/assets/components/mspbepaid/js/mgr/properties.tab.js b/assets/mspbepaid/js/mgr/properties.tab.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/properties.tab.js rename to assets/mspbepaid/js/mgr/properties.tab.js diff --git a/assets/components/mspbepaid/js/mgr/property.window.js b/assets/mspbepaid/js/mgr/property.window.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/property.window.js rename to assets/mspbepaid/js/mgr/property.window.js diff --git a/assets/components/mspbepaid/js/mgr/readonly.combo.js b/assets/mspbepaid/js/mgr/readonly.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/readonly.combo.js rename to assets/mspbepaid/js/mgr/readonly.combo.js diff --git a/assets/components/mspbepaid/js/mgr/resource.combo.js b/assets/mspbepaid/js/mgr/resource.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/resource.combo.js rename to assets/mspbepaid/js/mgr/resource.combo.js diff --git a/assets/components/mspbepaid/js/mgr/settings.combo.js b/assets/mspbepaid/js/mgr/settings.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/settings.combo.js rename to assets/mspbepaid/js/mgr/settings.combo.js diff --git a/assets/components/mspbepaid/js/mgr/status.combo.js b/assets/mspbepaid/js/mgr/status.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/status.combo.js rename to assets/mspbepaid/js/mgr/status.combo.js diff --git a/assets/components/mspbepaid/js/mgr/visible.combo.js b/assets/mspbepaid/js/mgr/visible.combo.js similarity index 100% rename from assets/components/mspbepaid/js/mgr/visible.combo.js rename to assets/mspbepaid/js/mgr/visible.combo.js diff --git a/core/components/mspbepaid/BePaid.class.php b/core/mspbepaid/BePaid.class.php similarity index 100% rename from core/components/mspbepaid/BePaid.class.php rename to core/mspbepaid/BePaid.class.php diff --git a/core/components/mspbepaid/elements/plugins/mspBePaid.php b/core/mspbepaid/elements/plugins/mspBePaid.php similarity index 62% rename from core/components/mspbepaid/elements/plugins/mspBePaid.php rename to core/mspbepaid/elements/plugins/mspBePaid.php index f152089..ac9be8f 100644 --- a/core/components/mspbepaid/elements/plugins/mspBePaid.php +++ b/core/mspbepaid/elements/plugins/mspBePaid.php @@ -1,27 +1,5 @@ - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ + /** * @param modX $modx diff --git a/core/mspbepaid/encryptedvehicle.class.php b/core/mspbepaid/encryptedvehicle.class.php new file mode 100644 index 0000000..07ba45b --- /dev/null +++ b/core/mspbepaid/encryptedvehicle.class.php @@ -0,0 +1,240 @@ +, 2021 + */ + +declare(strict_types = 1); + +require_once __DIR__ . '/helpers/xml.php'; + +use function alroniks\mspbepaid\helpers\xml\xmlToArray; +use function alroniks\mspbepaid\helpers\xml\arrayToXml; + +/** + * Class EncryptedVehicle + */ +class EncryptedVehicle extends xPDOObjectVehicle +{ + public const VERSION = '2.0.0'; + private const CIPHER = 'aes-256-cbc'; + + public $class = self::class; + + /** + * @param $transport xPDOTransport + * @param $object + * @param array $attributes + * + * @throws \Exception + */ + public function put(&$transport, &$object, $attributes = []): void + { + parent::put($transport, $object, $attributes); + + if (defined('PKG_ENCODE_KEY')) { + $this->payload['object_encrypted'] = $this->encode($this->payload['object'], PKG_ENCODE_KEY); + unset($this->payload['object']); + + if (isset($this->payload['related_objects'])) { + $this->payload['related_objects_encrypted'] = $this->encode( + $this->payload['related_objects'], + PKG_ENCODE_KEY + ); + unset($this->payload['related_objects']); + } + } + } + + /** + * @param $transport xPDOTransport + * @param $options + * + * @return bool + * @throws \JsonException + */ + public function install(&$transport, $options): bool + { + if (!$this->decodePayloads($transport)) { + $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Package can not be decrypted!'); + return false; + } + + $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Package decrypted!'); + + return parent::install($transport, $options); + } + + /** + * @param $transport xPDOTransport + * @param $options + * + * @return bool + * @throws \JsonException + */ + public function uninstall(&$transport, $options): bool + { + if (!$this->decodePayloads($transport, 'uninstall')) { + $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Package can not be decrypted!'); + return false; + } + + $transport->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Package decrypted!'); + + return parent::uninstall($transport, $options); + } + + /** + * @param array $data + * @param string $key + * + * @return string + * @throws Exception + */ + protected function encode(array $data, string $key): string + { + $iv = random_bytes(openssl_cipher_iv_length(self::CIPHER)); + + $encrypted = openssl_encrypt( + serialize($data), + self::CIPHER, + $key, + OPENSSL_RAW_DATA, + $iv + ); + + return base64_encode($iv . $encrypted); + } + + /** + * @param string $string + * @param string $key + * + * @return string + */ + protected function decode(string $string, string $key): string + { + $ivLen = openssl_cipher_iv_length(self::CIPHER); + $encoded = base64_decode($string); + + $iv = substr($encoded, 0, $ivLen); + $cipher_raw = substr($encoded, $ivLen); + + return unserialize(openssl_decrypt($cipher_raw, self::CIPHER, $key, OPENSSL_RAW_DATA, $iv)); + } + + /** + * @param $transport xPDOTransport + * @param string $action + * + * @return bool + * @throws \JsonException + */ + protected function decodePayloads(xPDOTransport $transport, string $action = 'install'): bool + { + $keysFound = count(array_intersect(['object_encrypted', 'related_objects_encrypted'], array_keys($this->payload))); + + if ($keysFound) { + if (!$key = $this->getDecodeKey($transport, $action)) { + return false; + } + if (isset($this->payload['object_encrypted'])) { + $this->payload['object'] = $this->decode($this->payload['object_encrypted'], $key); + unset($this->payload['object_encrypted']); + } + if (isset($this->payload['related_objects_encrypted'])) { + $this->payload['related_objects'] = $this->decode($this->payload['related_objects_encrypted'], $key); + unset($this->payload['related_objects_encrypted']); + } + } + + return true; + } + + /** + * @param $transport xPDOTransport + * @param string $action + * + * @return bool|string + * @throws \JsonException + */ + protected function getDecodeKey(xPDOTransport $transport, string $action) + { + $key = false; + $endpoint = 'package/decode/' . $action; + + /** @var modTransportPackage $package */ + $package = $transport->xpdo->getObject( + 'transport.modTransportPackage', + [ + 'signature' => $transport->signature, + ] + ); + + if ($package instanceof modTransportPackage) { + /** @var modTransportProvider $provider */ + if ($provider = $package->getOne('Provider')) { + $provider->xpdo->setOption('contentType', 'default'); + $params = [ + 'package' => $package->package_name, + 'version' => $transport->version, + 'username' => $provider->username, + 'api_key' => $provider->api_key, + 'vehicle_version' => self::VERSION, + ]; + + $response = $provider->request($endpoint, 'POST', $params); + + if ($response->isError()) { + $msg = $response->getError(); + $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, $msg); + } else { + $data = $response->toXml(); + if ($data->key !== null) { + $key = $data->key; + } elseif ($data->message !== null) { + $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, $data->message); + } + } + } else { + + $credentials = file_get_contents(sprintf('%spkg/%s/.encryption', MODX_BASE_PATH, $package->package_name)); + + $username = $secret = ''; + + if ($credentials) { + [$username, $secret] = explode(':', $credentials); + } + + // only for local installation during development + $params = [ + 'api_key' => $secret, + 'username' => $username, + 'http_host' => 'any-site.docker', + 'package' => $package->package_name, + 'version' => $transport->version, + 'vehicle_version' => self::VERSION, + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, sprintf('https://modstore.pro/extras/%s', $endpoint)); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xml']); + curl_setopt($ch, CURLOPT_POSTFIELDS, arrayToXml(['request' => $params])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + $result = trim(curl_exec($ch)); + curl_close($ch); + + $answer = xmlToArray($result); + + $key = $answer['key']; + } + } + + return $key; + } +} diff --git a/core/mspbepaid/helpers/xml.php b/core/mspbepaid/helpers/xml.php new file mode 100644 index 0000000..c070d39 --- /dev/null +++ b/core/mspbepaid/helpers/xml.php @@ -0,0 +1,58 @@ +, 2021 + */ + +declare(strict_types = 1); + +namespace alroniks\mspbepaid\helpers\xml; + +use JsonException; +use XMLWriter; + +/** + * @param string $content XML string + * + * @return array + * @throws JsonException + */ +function xmlToArray(string $content): array +{ + return json_decode( + json_encode(simplexml_load_string($content), JSON_THROW_ON_ERROR), + true, + 512, + JSON_THROW_ON_ERROR + ); +} + +/** + * @param array $data + * + * @param XmlWriter|null $writer + * @param int $nestingLevel Nesting level of recursive function + * + * @return XmlWriter + */ +function arrayToXml(array $data, XmlWriter $writer = null, int $nestingLevel = 0): XmlWriter +{ + if (!$writer) { + $writer = new XMLWriter(); + $writer->openMemory(); + $writer->startDocument('1.0', 'utf-8'); + } + foreach ($data as $key => $value) { + if (is_array($value)) { + $writer->startElement($key); + arrayToXml($value, $writer, $nestingLevel++); + $writer->endElement(); + continue; + } + $writer->writeElement($key, $value); + } + + return $writer; +} diff --git a/core/components/minishop2/lexicon/en/msp.bepaid.inc.php b/core/mspbepaid/lexicon/en/msp.bepaid.inc.php similarity index 100% rename from core/components/minishop2/lexicon/en/msp.bepaid.inc.php rename to core/mspbepaid/lexicon/en/msp.bepaid.inc.php diff --git a/core/components/minishop2/lexicon/ru/msp.bepaid.inc.php b/core/mspbepaid/lexicon/ru/msp.bepaid.inc.php similarity index 100% rename from core/components/minishop2/lexicon/ru/msp.bepaid.inc.php rename to core/mspbepaid/lexicon/ru/msp.bepaid.inc.php diff --git a/core/components/mspbepaid/processors/mgr/properties/base.class.php b/core/mspbepaid/processors/mgr/properties/base.class.php similarity index 100% rename from core/components/mspbepaid/processors/mgr/properties/base.class.php rename to core/mspbepaid/processors/mgr/properties/base.class.php diff --git a/core/components/mspbepaid/processors/mgr/properties/create.class.php b/core/mspbepaid/processors/mgr/properties/create.class.php similarity index 100% rename from core/components/mspbepaid/processors/mgr/properties/create.class.php rename to core/mspbepaid/processors/mgr/properties/create.class.php diff --git a/core/components/mspbepaid/processors/mgr/properties/delete.class.php b/core/mspbepaid/processors/mgr/properties/delete.class.php similarity index 100% rename from core/components/mspbepaid/processors/mgr/properties/delete.class.php rename to core/mspbepaid/processors/mgr/properties/delete.class.php diff --git a/core/components/mspbepaid/processors/mgr/properties/getlist.class.php b/core/mspbepaid/processors/mgr/properties/getlist.class.php similarity index 100% rename from core/components/mspbepaid/processors/mgr/properties/getlist.class.php rename to core/mspbepaid/processors/mgr/properties/getlist.class.php diff --git a/core/components/mspbepaid/processors/mgr/properties/update.class.php b/core/mspbepaid/processors/mgr/properties/update.class.php similarity index 100% rename from core/components/mspbepaid/processors/mgr/properties/update.class.php rename to core/mspbepaid/processors/mgr/properties/update.class.php