From ada2db7bc79b4036c20373429a700a8871d2e5a9 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 15 Apr 2023 17:00:08 +0200 Subject: [PATCH] first commit --- README.md | 274 +++++++++++++++++ .../README.md | 63 ++++ .../code.php | 153 ++++++++++ .../code.power | 122 ++++++++ .../settings.json | 33 ++ .../README.md | 69 +++++ .../code.php | 114 +++++++ .../code.power | 82 +++++ .../settings.json | 38 +++ .../README.md | 54 ++++ .../code.php | 117 +++++++ .../code.power | 89 ++++++ .../settings.json | 29 ++ .../README.md | 71 +++++ .../code.php | 199 ++++++++++++ .../code.power | 167 ++++++++++ .../settings.json | 46 +++ .../README.md | 101 +++++++ .../code.php | 187 ++++++++++++ .../code.power | 151 ++++++++++ .../settings.json | 59 ++++ .../README.md | 76 +++++ .../code.php | 165 ++++++++++ .../code.power | 133 ++++++++ .../settings.json | 35 +++ .../README.md | 21 ++ .../code.php | 26 ++ .../code.power | 1 + .../settings.json | 28 ++ .../README.md | 55 ++++ .../code.php | 131 ++++++++ .../code.power | 102 +++++++ .../settings.json | 34 +++ .../README.md | 64 ++++ .../code.php | 122 ++++++++ .../code.power | 93 ++++++ .../settings.json | 31 ++ .../README.md | 21 ++ .../code.php | 26 ++ .../code.power | 1 + .../settings.json | 28 ++ .../README.md | 130 ++++++++ .../code.php | 285 ++++++++++++++++++ .../code.power | 253 ++++++++++++++++ .../settings.json | 43 +++ .../README.md | 84 ++++++ .../code.php | 204 +++++++++++++ .../code.power | 175 +++++++++++ .../settings.json | 34 +++ .../README.md | 85 ++++++ .../code.php | 153 ++++++++++ .../code.power | 119 ++++++++ .../settings.json | 41 +++ .../README.md | 46 +++ .../code.php | 68 +++++ .../code.power | 40 +++ .../settings.json | 23 ++ super-powers.json | 142 +++++++++ 58 files changed, 5336 insertions(+) create mode 100644 README.md create mode 100644 src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md create mode 100644 src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php create mode 100644 src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power create mode 100644 src/11be6be3-ee3e-4771-8663-5545b76b73ab/settings.json create mode 100644 src/42ceff0b-226d-42ff-9ffa-3d5935890337/README.md create mode 100644 src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.php create mode 100644 src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.power create mode 100644 src/42ceff0b-226d-42ff-9ffa-3d5935890337/settings.json create mode 100644 src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md create mode 100644 src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php create mode 100644 src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power create mode 100644 src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/settings.json create mode 100644 src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md create mode 100644 src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php create mode 100644 src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power create mode 100644 src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json create mode 100644 src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/README.md create mode 100644 src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.php create mode 100644 src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.power create mode 100644 src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/settings.json create mode 100644 src/66355f70-c26c-4765-ba48-498e3df740ef/README.md create mode 100644 src/66355f70-c26c-4765-ba48-498e3df740ef/code.php create mode 100644 src/66355f70-c26c-4765-ba48-498e3df740ef/code.power create mode 100644 src/66355f70-c26c-4765-ba48-498e3df740ef/settings.json create mode 100644 src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md create mode 100644 src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.php create mode 100644 src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.power create mode 100644 src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/settings.json create mode 100644 src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md create mode 100644 src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php create mode 100644 src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power create mode 100644 src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json create mode 100644 src/a3414824-e99d-4878-b3d1-b5deef0cae17/README.md create mode 100644 src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.php create mode 100644 src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.power create mode 100644 src/a3414824-e99d-4878-b3d1-b5deef0cae17/settings.json create mode 100644 src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md create mode 100644 src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.php create mode 100644 src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.power create mode 100644 src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/settings.json create mode 100644 src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md create mode 100644 src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php create mode 100644 src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power create mode 100644 src/d357e796-9f22-4615-9ebc-970b42cbd280/settings.json create mode 100644 src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md create mode 100644 src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php create mode 100644 src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power create mode 100644 src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json create mode 100644 src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md create mode 100644 src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.php create mode 100644 src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.power create mode 100644 src/f37ee8b7-2909-4319-bdf8-769bd7635490/settings.json create mode 100644 src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/README.md create mode 100644 src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.php create mode 100644 src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.power create mode 100644 src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/settings.json create mode 100644 super-powers.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..a93a9c2 --- /dev/null +++ b/README.md @@ -0,0 +1,274 @@ +``` +███████╗██╗ ██╗██████╗ ███████╗██████╗ +██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗ +███████╗██║ ██║██████╔╝█████╗ ██████╔╝ +╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗ +███████║╚██████╔╝██║ ███████╗██║ ██║ +╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝ +``` + +### What is JCB Super Powers? +The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki). + +In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki). + +### What can I find here? +This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities. + +# Index of powers + +- **Namespace**: [VDM\Joomla\Componentbuilder](#vdm-joomla-componentbuilder) + + - **class Crypt** | [Details](src/d357e796-9f22-4615-9ebc-970b42cbd280) | [Code](src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php) | [Settings](src/d357e796-9f22-4615-9ebc-970b42cbd280/settings.json) | [d357e796-9f22-4615-9ebc-970b42cbd280](src/d357e796-9f22-4615-9ebc-970b42cbd280) + - **class Server** | [Details](src/66355f70-c26c-4765-ba48-498e3df740ef) | [Code](src/66355f70-c26c-4765-ba48-498e3df740ef/code.php) | [Settings](src/66355f70-c26c-4765-ba48-498e3df740ef/settings.json) | [66355f70-c26c-4765-ba48-498e3df740ef](src/66355f70-c26c-4765-ba48-498e3df740ef) +- **Namespace**: [VDM\Joomla\Componentbuilder\Crypt](#vdm-joomla-componentbuilder-crypt) + + - **class Aes** | [Details](src/a25c82c8-14c2-40df-adae-f832709ab49b) | [Code](src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php) | [Settings](src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json) | [a25c82c8-14c2-40df-adae-f832709ab49b](src/a25c82c8-14c2-40df-adae-f832709ab49b) + - **class FOF** | [Details](src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe) | [Code](src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php) | [Settings](src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json) | [e98b4edc-25b9-49d7-98a0-e42ad3b75efe](src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe) + - **class Password** | [Details](src/fea2b107-3ee4-4ebf-84be-d3f2829c8614) | [Code](src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.php) | [Settings](src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/settings.json) | [fea2b107-3ee4-4ebf-84be-d3f2829c8614](src/fea2b107-3ee4-4ebf-84be-d3f2829c8614) +- **Namespace**: [VDM\Joomla\Componentbuilder\Server](#vdm-joomla-componentbuilder-server) + + - **class Ftp** | [Details](src/11be6be3-ee3e-4771-8663-5545b76b73ab) | [Code](src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php) | [Settings](src/11be6be3-ee3e-4771-8663-5545b76b73ab/settings.json) | [11be6be3-ee3e-4771-8663-5545b76b73ab](src/11be6be3-ee3e-4771-8663-5545b76b73ab) + - **class Load** | [Details](src/a3414824-e99d-4878-b3d1-b5deef0cae17) | [Code](src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.php) | [Settings](src/a3414824-e99d-4878-b3d1-b5deef0cae17/settings.json) | [a3414824-e99d-4878-b3d1-b5deef0cae17](src/a3414824-e99d-4878-b3d1-b5deef0cae17) + - **class Sftp** | [Details](src/490b6aa5-5de7-4be5-a61a-f634f6e004c0) | [Code](src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php) | [Settings](src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json) | [490b6aa5-5de7-4be5-a61a-f634f6e004c0](src/490b6aa5-5de7-4be5-a61a-f634f6e004c0) +- **Namespace**: [VDM\Joomla\Componentbuilder\Service](#vdm-joomla-componentbuilder-service) + + - **class Crypt** | [Details](src/4d8f38ef-8f3a-463d-8678-0bf087ac6815) | [Code](src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.php) | [Settings](src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/settings.json) | [4d8f38ef-8f3a-463d-8678-0bf087ac6815](src/4d8f38ef-8f3a-463d-8678-0bf087ac6815) + - **class Server** | [Details](src/42ceff0b-226d-42ff-9ffa-3d5935890337) | [Code](src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.php) | [Settings](src/42ceff0b-226d-42ff-9ffa-3d5935890337/settings.json) | [42ceff0b-226d-42ff-9ffa-3d5935890337](src/42ceff0b-226d-42ff-9ffa-3d5935890337) +- **Namespace**: [VDM\Joomla\Componentbuilder\Crypt\Aes](#vdm-joomla-componentbuilder-crypt-aes) + + - **class Legacy** | [Details](src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0) | [Code](src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php) | [Settings](src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/settings.json) | [437af6b0-ca02-49d7-8739-4edfc8a9ccb0](src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0) +- **Namespace**: [VDM\Joomla\Componentbuilder\Server\Model](#vdm-joomla-componentbuilder-server-model) + + - **class Load** | [Details](src/f37ee8b7-2909-4319-bdf8-769bd7635490) | [Code](src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.php) | [Settings](src/f37ee8b7-2909-4319-bdf8-769bd7635490/settings.json) | [f37ee8b7-2909-4319-bdf8-769bd7635490](src/f37ee8b7-2909-4319-bdf8-769bd7635490) + +# Class Diagrams + +## VDM Joomla Componentbuilder +> namespace VDM\Joomla\Componentbuilder +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder #DarkCyan { + + + class Crypt #Gold { + # FOF $fof + # Aes $aes + # Legacy $legacy + # Password $password + # array $options + # array $passwords + + __construct() + + encrypt() : string + + decrypt() : string + + exist() : bool + - getClassName() : ?string + - getClassNameFromRegistry() : ?string + - getClassNameFromOptions() : ?string + - getPassword() : ?string + - getPasswordKey() : string + - name() : string + } + + class Server #Gold { + # Load $load + # Ftp $ftp + # Sftp $sftp + # User $user + + __construct() + + move() : bool + + legacyMove() : bool + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Crypt +> namespace VDM\Joomla\Componentbuilder\Crypt +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Crypt #Olive { + + + class Aes #Gold { + # BASEAES $aes + # Random $random + # int $size + + __construct() + + encrypt() : string + + decrypt() : string + } + + class FOF #Gold { + # AES $aes + # Random $random + # int $size + + __construct() + + encrypt() : string + + decrypt() : string + # getExpandedKey() : string + # resizeKey() : ?string + } + + class Password #Gold { + + get() : ?string + - local() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Server +> namespace VDM\Joomla\Componentbuilder\Server +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Server #Olive { + + + class Ftp #Gold { + # ?FtpClient $client + # ?object $details + + set() : Ftp + + move() : bool + - connected() : bool + - getClient() : ?FtpClient + } + + class Load #Gold { + # Database $db + # Model $model + + __construct() + + value() : mixed|null + + item() : ?object + # setDatabaseFields() : array + } + + class Sftp #Gold { + # KeyLoader $key + # ?SftpClient $client + # ?object $details + + __construct() + + set() : Sftp + + move() : bool + - connected() : bool + - getClient() : ?SftpClient + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Service +> namespace VDM\Joomla\Componentbuilder\Service +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Service #Olive { + + + class Crypt #Gold { + + register() : void + + getCrypt() : Crypto + + getPassword() : Password + + getRandom() : Random + + getKeyLoader() : KeyLoader + + getBASEAESCBC() : BASEAES + + getAesCBC() : Aes + + getAesLEGACY() : Legacy + + getFOF() : FOF + } + + class Server #Gold { + + register() : void + + getServer() : Client + + getServerLoad() : Load + + getServerFtp() : Ftp + + getServerSftp() : Sftp + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Crypt Aes +> namespace VDM\Joomla\Componentbuilder\Crypt\Aes +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Crypt\Aes #LightGreen { + + + class Legacy #Gold { + # BASEAES $aes + # int $size + + __construct() + + encrypt() : string + + decrypt() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Server Model +> namespace VDM\Joomla\Componentbuilder\Server\Model +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Server\Model #LightGreen { + + + class Load #Gold { + # Crypt $crypt + + __construct() + + value() : mixed + # validateBefore() : bool + # validateAfter() : bool + # getTable() : string + } +} + + +@enduml +``` + + +--- +``` + ██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗ + ██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗ + ██║██║ ██║██║ ██║██╔████╔██║██║ ███████║ +██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║ +╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║ + ╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ + ██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗ +██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝ +██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║ +██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║ +╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║ + ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝ +██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗ +██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗ +██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗ +██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║ +╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md new file mode 100644 index 0000000..9d3d4be --- /dev/null +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md @@ -0,0 +1,63 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Ftp (Details) +> namespace: **VDM\Joomla\Componentbuilder\Server** +```uml +@startuml +class Ftp #Gold { + # ?FtpClient $client + # ?object $details + + set(object $details) : Ftp + + move(string $localPath, string $fileName) : bool + - connected() : bool + - getClient() : ?FtpClient +} + +note right of Ftp::set + set the server details + + since: 3.2.0 + return: Ftp +end note + +note right of Ftp::move + move a file to server with the FTP client + + since: 3.2.0 + return: bool +end note + +note right of Ftp::connected + Make sure we are connected + + since: 3.2.0 + return: bool +end note + +note right of Ftp::getClient + get the FtpClient object + + since: 3.2.0 + return: ?FtpClient +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php new file mode 100644 index 0000000..792332f --- /dev/null +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php @@ -0,0 +1,153 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Server; + + +use Joomla\CMS\Client\FtpClient; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\ObjectHelper; +use VDM\Joomla\Componentbuilder\Interfaces\Serverinterface; + + +/** + * Ftp Class + * + * @since 3.2.0 + */ +class Ftp implements Serverinterface +{ + /** + * The client object + * + * @var FtpClient|null + * @since 3.2.0 + **/ + protected ?FtpClient $client = null; + + /** + * The server details + * + * @var object + * @since 3.2.0 + **/ + protected ?object $details = null; + + /** + * set the server details + * + * @param object $details The server details + * + * @return Ftp + * @since 3.2.0 + **/ + public function set(object $details): Ftp + { + // we need to make sure the if the details changed to get a new server client + if (!ObjectHelper::equal($details, $this->details)) + { + // set the details + $this->details = $details; + + // reset the client if it was set before + $this->client = null; + } + + return $this; + } + + /** + * move a file to server with the FTP client + * + * @param string $localPath The full local path to the file + * @param string $fileName The file name + * + * @return bool + * @since 3.2.0 + **/ + public function move(string $localPath, string $fileName): bool + { + if ($this->connected()) + { + return $this->client->store($localPath, $fileName); + } + + return false; + } + + /** + * Make sure we are connected + * + * @return bool + * @since 3.2.0 + **/ + private function connected(): bool + { + // check if we have a connection + if ($this->client instanceof FtpClient && $this->client->isConnected()) + { + return true; + } + + $this->client = $this->getClient(); + + return $this->client instanceof FtpClient; + } + + /** + * get the FtpClient object + * + * @return FtpClient|null + * @since 3.2.0 + **/ + private function getClient(): ?FtpClient + { + // make sure we have a string and it is not default or empty + if (StringHelper::check($this->details->signature)) + { + // turn into variables + parse_str((string) $this->details->signature); + // set options + if (isset($options) && ArrayHelper::check($options)) + { + foreach ($options as $o__p0t1on => $vAln3) + { + if ('timeout' === $o__p0t1on) + { + $options[$o__p0t1on] = (int) $vAln3; + } + if ('type' === $o__p0t1on) + { + $options[$o__p0t1on] = (string) $vAln3; + } + } + } + else + { + $options = []; + } + // get ftp object + if (isset($host) && $host != 'HOSTNAME' && + isset($port) && $port != 'PORT_INT' && + isset($username) && $username != 'user@name.com' && + isset($password) && $password != 'password') + { + // this is a singleton + return FtpClient::getInstance($host, $port, $options, $username, $password); + } + } + + return null; + } + +} + diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power new file mode 100644 index 0000000..b3909c0 --- /dev/null +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power @@ -0,0 +1,122 @@ + /** + * The client object + * + * @var FtpClient|null + * @since 3.2.0 + **/ + protected ?FtpClient $client = null; + + /** + * The server details + * + * @var object + * @since 3.2.0 + **/ + protected ?object $details = null; + + /** + * set the server details + * + * @param object $details The server details + * + * @return Ftp + * @since 3.2.0 + **/ + public function set(object $details): Ftp + { + // we need to make sure the if the details changed to get a new server client + if (!ObjectHelper::equal($details, $this->details)) + { + // set the details + $this->details = $details; + + // reset the client if it was set before + $this->client = null; + } + + return $this; + } + + /** + * move a file to server with the FTP client + * + * @param string $localPath The full local path to the file + * @param string $fileName The file name + * + * @return bool + * @since 3.2.0 + **/ + public function move(string $localPath, string $fileName): bool + { + if ($this->connected()) + { + return $this->client->store($localPath, $fileName); + } + + return false; + } + + /** + * Make sure we are connected + * + * @return bool + * @since 3.2.0 + **/ + private function connected(): bool + { + // check if we have a connection + if ($this->client instanceof FtpClient && $this->client->isConnected()) + { + return true; + } + + $this->client = $this->getClient(); + + return $this->client instanceof FtpClient; + } + + /** + * get the FtpClient object + * + * @return FtpClient|null + * @since 3.2.0 + **/ + private function getClient(): ?FtpClient + { + // make sure we have a string and it is not default or empty + if (StringHelper::check($this->details->signature)) + { + // turn into variables + parse_str((string) $this->details->signature); + // set options + if (isset($options) && ArrayHelper::check($options)) + { + foreach ($options as $o__p0t1on => $vAln3) + { + if ('timeout' === $o__p0t1on) + { + $options[$o__p0t1on] = (int) $vAln3; + } + if ('type' === $o__p0t1on) + { + $options[$o__p0t1on] = (string) $vAln3; + } + } + } + else + { + $options = []; + } + // get ftp object + if (isset($host) && $host != 'HOSTNAME' && + isset($port) && $port != 'PORT_INT' && + isset($username) && $username != 'user@name.com' && + isset($password) && $password != 'password') + { + // this is a singleton + return FtpClient::getInstance($host, $port, $options, $username, $password); + } + } + + return null; + } diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/settings.json b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/settings.json new file mode 100644 index 0000000..d94b279 --- /dev/null +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/settings.json @@ -0,0 +1,33 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "11be6be3-ee3e-4771-8663-5545b76b73ab", + "implements": [ + "86ac0760-26f5-4746-9c7f-ce77860f80f8" + ], + "load_selection": null, + "name": "Ftp", + "power_version": "1.0.0", + "system_name": "JCB.Server.Ftp", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection1": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection2": { + "use": "91004529-94a9-4590-b842-e7c6b624ecf5", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Server.Ftp", + "description": "Ftp Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Client\\FtpClient;", + "composer": "" +} \ No newline at end of file diff --git a/src/42ceff0b-226d-42ff-9ffa-3d5935890337/README.md b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/README.md new file mode 100644 index 0000000..e0b06fe --- /dev/null +++ b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/README.md @@ -0,0 +1,69 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Server (Details) +> namespace: **VDM\Joomla\Componentbuilder\Service** +```uml +@startuml +class Server #Gold { + + register(Container $container) : void + + getServer(Container $container) : Client + + getServerLoad(Container $container) : Load + + getServerFtp(Container $container) : Ftp + + getServerSftp(Container $container) : Sftp +} + +note right of Server::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Server::getServer + Get the Server Client class + + since: 3.2.0 + return: Client +end note + +note right of Server::getServerLoad + Get the Server Load class + + since: 3.2.0 + return: Load +end note + +note right of Server::getServerFtp + Get the Server Ftp class + + since: 3.2.0 + return: Ftp +end note + +note right of Server::getServerSftp + Get the Server Sftp class + + since: 3.2.0 + return: Sftp +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.php b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.php new file mode 100644 index 0000000..98933f0 --- /dev/null +++ b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.php @@ -0,0 +1,114 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Server as Client; +use VDM\Joomla\Componentbuilder\Server\Load; +use VDM\Joomla\Componentbuilder\Server\Ftp; +use VDM\Joomla\Componentbuilder\Server\Sftp; + + +/** + * Server Service Provider + * + * @since 3.2.0 + */ +class Server implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Client::class, 'Server') + ->share('Server', [$this, 'getServer'], true); + + $container->alias(Load::class, 'Server.Load') + ->share('Server.Load', [$this, 'getServerLoad'], true); + + $container->alias(Ftp::class, 'Server.FTP') + ->share('Server.FTP', [$this, 'getServerFtp'], true); + $container->alias(Sftp::class, 'Server.SFTP') + ->share('Server.SFTP', [$this, 'getServerSftp'], true); + } + + /** + * Get the Server Client class + * + * @param Container $container The DI container. + * + * @return Client + * @since 3.2.0 + */ + public function getServer(Container $container): Client + { + return new Client( + $container->get('Server.Load'), + $container->get('Server.FTP'), + $container->get('Server.SFTP') + ); + } + + /** + * Get the Server Load class + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getServerLoad(Container $container): Load + { + return new Load( + $container->get('Load'), + $container->get('Model.Server.Load') + ); + } + + /** + * Get the Server Ftp class + * + * @param Container $container The DI container. + * + * @return Ftp + * @since 3.2.0 + */ + public function getServerFtp(Container $container): Ftp + { + return new Ftp(); + } + + /** + * Get the Server Sftp class + * + * @param Container $container The DI container. + * + * @return Sftp + * @since 3.2.0 + */ + public function getServerSftp(Container $container): Sftp + { + return new Sftp( + $container->get('Crypt.Key') + ); + } + +} + diff --git a/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.power b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.power new file mode 100644 index 0000000..1959d37 --- /dev/null +++ b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/code.power @@ -0,0 +1,82 @@ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Client::class, 'Server') + ->share('Server', [$this, 'getServer'], true); + + $container->alias(Load::class, 'Server.Load') + ->share('Server.Load', [$this, 'getServerLoad'], true); + + $container->alias(Ftp::class, 'Server.FTP') + ->share('Server.FTP', [$this, 'getServerFtp'], true); + $container->alias(Sftp::class, 'Server.SFTP') + ->share('Server.SFTP', [$this, 'getServerSftp'], true); + } + + /** + * Get the Server Client class + * + * @param Container $container The DI container. + * + * @return Client + * @since 3.2.0 + */ + public function getServer(Container $container): Client + { + return new Client( + $container->get('Server.Load'), + $container->get('Server.FTP'), + $container->get('Server.SFTP') + ); + } + + /** + * Get the Server Load class + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getServerLoad(Container $container): Load + { + return new Load( + $container->get('Load'), + $container->get('Model.Server.Load') + ); + } + + /** + * Get the Server Ftp class + * + * @param Container $container The DI container. + * + * @return Ftp + * @since 3.2.0 + */ + public function getServerFtp(Container $container): Ftp + { + return new Ftp(); + } + + /** + * Get the Server Sftp class + * + * @param Container $container The DI container. + * + * @return Sftp + * @since 3.2.0 + */ + public function getServerSftp(Container $container): Sftp + { + return new Sftp( + $container->get('Crypt.Key') + ); + } diff --git a/src/42ceff0b-226d-42ff-9ffa-3d5935890337/settings.json b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/settings.json new file mode 100644 index 0000000..48adaec --- /dev/null +++ b/src/42ceff0b-226d-42ff-9ffa-3d5935890337/settings.json @@ -0,0 +1,38 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "42ceff0b-226d-42ff-9ffa-3d5935890337", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Server", + "power_version": "1.0.0", + "system_name": "JCB.Service.Server", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "66355f70-c26c-4765-ba48-498e3df740ef", + "as": "Client" + }, + "use_selection1": { + "use": "a3414824-e99d-4878-b3d1-b5deef0cae17", + "as": "default" + }, + "use_selection2": { + "use": "11be6be3-ee3e-4771-8663-5545b76b73ab", + "as": "default" + }, + "use_selection3": { + "use": "490b6aa5-5de7-4be5-a61a-f634f6e004c0", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Service.Server", + "description": "Server Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md new file mode 100644 index 0000000..eb93926 --- /dev/null +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md @@ -0,0 +1,54 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Legacy (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt\Aes** +```uml +@startuml +class Legacy #Gold { + # BASEAES $aes + # int $size + + __construct(BASEAES $aes) + + encrypt(string $string, string $key) : string + + decrypt(string $string, string $key) : string +} + +note right of Legacy::__construct + Constructor + + since: 3.2.0 +end note + +note right of Legacy::encrypt + Encrypt a string as needed + + since: 3.2.0 + return: string +end note + +note right of Legacy::decrypt + Decrypt a string as needed + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php new file mode 100644 index 0000000..e73c5bd --- /dev/null +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php @@ -0,0 +1,117 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt\Aes; + + +use phpseclib3\Crypt\AES as BASEAES; +use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; + + +/** + * Legacy Class for Aes Encryption + * + * @since 3.2.0 + */ +class Legacy implements Cryptinterface +{ + /** + * The Aes class + * + * @var BASEAES + * @since 3.2.0 + */ + protected BASEAES $aes; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 128; + + /** + * Constructor + * + * @param BASEAES $aes The Aes class + * + * @since 3.2.0 + */ + public function __construct(BASEAES $aes) + { + $this->aes = $aes; + + // we set the length once + $this->aes->setKeyLength($this->size); + + // enable padding + $this->aes->enablePadding(); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = str_repeat("\0", $iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + // encrypt the string, and base 64 encode the result + return base64_encode($this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // remove base 64 encoding + $string = base64_decode($string); + + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = str_repeat("\0", $iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + return $this->aes->decrypt($string); + } + +} + diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power new file mode 100644 index 0000000..9940635 --- /dev/null +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power @@ -0,0 +1,89 @@ + /** + * The Aes class + * + * @var BASEAES + * @since 3.2.0 + */ + protected BASEAES $aes; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 128; + + /** + * Constructor + * + * @param BASEAES $aes The Aes class + * + * @since 3.2.0 + */ + public function __construct(BASEAES $aes) + { + $this->aes = $aes; + + // we set the length once + $this->aes->setKeyLength($this->size); + + // enable padding + $this->aes->enablePadding(); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = str_repeat("\0", $iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + // encrypt the string, and base 64 encode the result + return base64_encode($this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // remove base 64 encoding + $string = base64_decode($string); + + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = str_repeat("\0", $iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + return $this->aes->decrypt($string); + } diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/settings.json b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/settings.json new file mode 100644 index 0000000..81d4575 --- /dev/null +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/settings.json @@ -0,0 +1,29 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "437af6b0-ca02-49d7-8739-4edfc8a9ccb0", + "implements": [ + "81de8f57-dd9c-4a17-964f-848cd4a0743b" + ], + "load_selection": null, + "name": "Legacy", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.Aes.Legacy", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.Aes.Legacy", + "description": "Legacy Class for Aes Encryption\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\AES as BASEAES" + } + } + } + } +} \ No newline at end of file diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md new file mode 100644 index 0000000..afe5495 --- /dev/null +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md @@ -0,0 +1,71 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Sftp (Details) +> namespace: **VDM\Joomla\Componentbuilder\Server** +```uml +@startuml +class Sftp #Gold { + # KeyLoader $key + # ?SftpClient $client + # ?object $details + + __construct(KeyLoader $key) + + set(object $details) : Sftp + + move(string $localPath, string $fileName) : bool + - connected() : bool + - getClient() : ?SftpClient +} + +note right of Sftp::__construct + Constructor + + since: 3.2.0 +end note + +note right of Sftp::set + set the server details + + since: 3.2.0 + return: Sftp +end note + +note right of Sftp::move + move a file to server with the FTP client + + since: 3.2.0 + return: bool +end note + +note right of Sftp::connected + Make sure we are connected + + since: 3.2.0 + return: bool +end note + +note right of Sftp::getClient + get the SftpClient object + + since: 3.2.0 + return: ?SftpClient +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php new file mode 100644 index 0000000..d272460 --- /dev/null +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php @@ -0,0 +1,199 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Server; + + +use phpseclib3\Net\SFTP as SftpClient; +use VDM\Joomla\Componentbuilder\Crypt\KeyLoader; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\FileHelper; +use VDM\Joomla\Utilities\ObjectHelper; +use VDM\Joomla\Componentbuilder\Interfaces\Serverinterface; + + +/** + * Sftp Class + * + * @since 3.2.0 + */ +class Sftp implements Serverinterface +{ + /** + * The KeyLoader + * + * @var KeyLoader + * @since 3.2.0 + */ + protected KeyLoader $key; + + /** + * The client object + * + * @var SftpClient|null + * @since 3.2.0 + **/ + protected ?SftpClient $client = null; + + /** + * The server details + * + * @var object + * @since 3.2.0 + **/ + protected ?object $details = null; + + /** + * Constructor + * + * @param KeyLoader $key The key loader object. + * + * @since 3.2.0 + */ + public function __construct(KeyLoader $key) + { + $this->key = $key; + } + + /** + * set the server details + * + * @param object $details The server details + * + * @return Sftp + * @since 3.2.0 + **/ + public function set(object $details): Sftp + { + // we need to make sure the if the details changed to get a new server client + if (!ObjectHelper::equal($details, $this->details)) + { + // set the details + $this->details = $details; + + // reset the client if it was set before + $this->client = null; + } + + return $this; + } + + /** + * move a file to server with the FTP client + * + * @param string $localPath The full local path to the file + * @param string $fileName The file name + * + * @return bool + * @since 3.2.0 + **/ + public function move(string $localPath, string $fileName): bool + { + if ($this->connected() && + ($data = FileHelper::getContent($localPath, null)) !== null) + { + // get the remote path + $path = ''; + if (isset($this->details->path) && + StringHelper::check($this->details->path) && + $this->details->path !== '/') + { + $path = '/' . trim((string) $this->details->path, '/'); + } + + return $this->client->put($path . '/' . $fileName, $data); + } + + return false; + } + + /** + * Make sure we are connected + * + * @return bool + * @since 3.2.0 + **/ + private function connected(): bool + { + // check if we have a connection + if ($this->client instanceof SftpClient && ($this->client->isConnected() || $this->client->ping())) + { + return true; + } + + $this->client = $this->getClient(); + + return $this->client instanceof SftpClient; + } + + /** + * get the SftpClient object + * + * @return SftpClient|null + * @since 3.2.0 + **/ + private function getClient(): ?SftpClient + { + // make sure we have a host value set + if (isset($this->details->host) && StringHelper::check($this->details->host) && + isset($this->details->username) && StringHelper::check($this->details->username)) + { + // insure the port is set + $port = (isset($this->details->port) && is_numeric($this->details->port) && $this->details->port > 0) + ? (int) $this->details->port : 22; + + // open the connection + $sftp = new SftpClient($this->details->host, $port); + + // set the passphrase if it exist + $passphrase = $this->details->secret ?? null; + + // set the password if it exist + $password = $this->details->password ?? null; + + // now login based on authentication type + $key = null; + switch($this->details->authentication) + { + case 1: // password + $key = $this->details->password ?? null; + $password = null; + break; + case 2: // private key file + case 3: // both password and private key file + if (isset($this->details->private) && StringHelper::check($this->details->private) && + ($private_key = FileHelper::getContent($this->details->private, null)) !== null) + { + $key = $this->key::load($private_key, $passphrase); + } + break; + case 4: // private key field + case 5: // both password and private key field + if (isset($this->details->private_key) && StringHelper::check($this->details->private_key)) + { + $key = $this->key::load($this->details->private_key, $passphrase); + } + break; + } + + // login + if ((!empty($key) && !empty($password) && $sftp->login($this->details->username, $key, $password)) || + (!empty($key) && $sftp->login($this->details->username, $key))) + { + return $sftp; + } + } + + return null; + } + +} + diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power new file mode 100644 index 0000000..dd9fd6f --- /dev/null +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power @@ -0,0 +1,167 @@ + /** + * The KeyLoader + * + * @var KeyLoader + * @since 3.2.0 + */ + protected KeyLoader $key; + + /** + * The client object + * + * @var SftpClient|null + * @since 3.2.0 + **/ + protected ?SftpClient $client = null; + + /** + * The server details + * + * @var object + * @since 3.2.0 + **/ + protected ?object $details = null; + + /** + * Constructor + * + * @param KeyLoader $key The key loader object. + * + * @since 3.2.0 + */ + public function __construct(KeyLoader $key) + { + $this->key = $key; + } + + /** + * set the server details + * + * @param object $details The server details + * + * @return Sftp + * @since 3.2.0 + **/ + public function set(object $details): Sftp + { + // we need to make sure the if the details changed to get a new server client + if (!ObjectHelper::equal($details, $this->details)) + { + // set the details + $this->details = $details; + + // reset the client if it was set before + $this->client = null; + } + + return $this; + } + + /** + * move a file to server with the FTP client + * + * @param string $localPath The full local path to the file + * @param string $fileName The file name + * + * @return bool + * @since 3.2.0 + **/ + public function move(string $localPath, string $fileName): bool + { + if ($this->connected() && + ($data = FileHelper::getContent($localPath, null)) !== null) + { + // get the remote path + $path = ''; + if (isset($this->details->path) && + StringHelper::check($this->details->path) && + $this->details->path !== '/') + { + $path = '/' . trim((string) $this->details->path, '/'); + } + + return $this->client->put($path . '/' . $fileName, $data); + } + + return false; + } + + /** + * Make sure we are connected + * + * @return bool + * @since 3.2.0 + **/ + private function connected(): bool + { + // check if we have a connection + if ($this->client instanceof SftpClient && ($this->client->isConnected() || $this->client->ping())) + { + return true; + } + + $this->client = $this->getClient(); + + return $this->client instanceof SftpClient; + } + + /** + * get the SftpClient object + * + * @return SftpClient|null + * @since 3.2.0 + **/ + private function getClient(): ?SftpClient + { + // make sure we have a host value set + if (isset($this->details->host) && StringHelper::check($this->details->host) && + isset($this->details->username) && StringHelper::check($this->details->username)) + { + // insure the port is set + $port = (isset($this->details->port) && is_numeric($this->details->port) && $this->details->port > 0) + ? (int) $this->details->port : 22; + + // open the connection + $sftp = new SftpClient($this->details->host, $port); + + // set the passphrase if it exist + $passphrase = $this->details->secret ?? null; + + // set the password if it exist + $password = $this->details->password ?? null; + + // now login based on authentication type + $key = null; + switch($this->details->authentication) + { + case 1: // password + $key = $this->details->password ?? null; + $password = null; + break; + case 2: // private key file + case 3: // both password and private key file + if (isset($this->details->private) && StringHelper::check($this->details->private) && + ($private_key = FileHelper::getContent($this->details->private, null)) !== null) + { + $key = $this->key::load($private_key, $passphrase); + } + break; + case 4: // private key field + case 5: // both password and private key field + if (isset($this->details->private_key) && StringHelper::check($this->details->private_key)) + { + $key = $this->key::load($this->details->private_key, $passphrase); + } + break; + } + + // login + if ((!empty($key) && !empty($password) && $sftp->login($this->details->username, $key, $password)) || + (!empty($key) && $sftp->login($this->details->username, $key))) + { + return $sftp; + } + } + + return null; + } diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json new file mode 100644 index 0000000..cfe41f2 --- /dev/null +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json @@ -0,0 +1,46 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "490b6aa5-5de7-4be5-a61a-f634f6e004c0", + "implements": [ + "86ac0760-26f5-4746-9c7f-ce77860f80f8" + ], + "load_selection": null, + "name": "Sftp", + "power_version": "1.0.0", + "system_name": "JCB.Server.Sftp", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "6da44dff-a221-4f22-b9d9-b2fc2a724b4b", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection2": { + "use": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0", + "as": "default" + }, + "use_selection3": { + "use": "91004529-94a9-4590-b842-e7c6b624ecf5", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Server.Sftp", + "description": "Sftp Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Net\\SFTP as SftpClient" + } + } + } + } +} \ No newline at end of file diff --git a/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/README.md b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/README.md new file mode 100644 index 0000000..577ea92 --- /dev/null +++ b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/README.md @@ -0,0 +1,101 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Crypt (Details) +> namespace: **VDM\Joomla\Componentbuilder\Service** +```uml +@startuml +class Crypt #Gold { + + register(Container $container) : void + + getCrypt(Container $container) : Crypto + + getPassword(Container $container) : Password + + getRandom(Container $container) : Random + + getKeyLoader(Container $container) : KeyLoader + + getBASEAESCBC(Container $container) : BASEAES + + getAesCBC(Container $container) : Aes + + getAesLEGACY(Container $container) : Legacy + + getFOF(Container $container) : FOF +} + +note right of Crypt::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note left of Crypt::getCrypt + Get the Crypto class + + since: 3.2.0 + return: Crypto +end note + +note right of Crypt::getPassword + Get the Password class + + since: 3.2.0 + return: Password +end note + +note left of Crypt::getRandom + Get the Random class + + since: 3.2.0 + return: Random +end note + +note right of Crypt::getKeyLoader + Get the KeyLoader class + + since: 3.2.0 + return: KeyLoader +end note + +note left of Crypt::getBASEAESCBC + Get the AES Cyper with CBC mode + + since: 3.2.0 + return: BASEAES +end note + +note right of Crypt::getAesCBC + Get the Wrapper AES Cyper with CBC mode + + since: 3.2.0 + return: Aes +end note + +note left of Crypt::getAesLEGACY + Get the Wrapper AES Legacy Cyper with CBC mode + + since: 3.2.0 + return: Legacy +end note + +note right of Crypt::getFOF + Get the FOF AES Cyper with CBC mode + + since: 3.2.0 + return: FOF +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.php b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.php new file mode 100644 index 0000000..65947df --- /dev/null +++ b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.php @@ -0,0 +1,187 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use phpseclib3\Crypt\AES as BASEAES; +use VDM\Joomla\Componentbuilder\Crypt as Crypto; +use VDM\Joomla\Componentbuilder\Crypt\KeyLoader; +use VDM\Joomla\Componentbuilder\Crypt\Random; +use VDM\Joomla\Componentbuilder\Crypt\Password; +use VDM\Joomla\Componentbuilder\Crypt\FOF; +use VDM\Joomla\Componentbuilder\Crypt\Aes; +use VDM\Joomla\Componentbuilder\Crypt\Aes\Legacy; + + +/** + * Phpseclib Crypt Service Provider + * + * @since 3.2.0 + */ +class Crypt implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Crypto::class, 'Crypt') + ->share('Crypt', [$this, 'getCrypt'], true); + + $container->alias(Random::class, 'Crypt.Random') + ->share('Crypt.Random', [$this, 'getRandom'], true); + + $container->alias(Password::class, 'Crypt.Password') + ->share('Crypt.Password', [$this, 'getPassword'], true); + + $container->alias(KeyLoader::class, 'Crypt.Key') + ->share('Crypt.Key', [$this, 'getKeyLoader'], true); + + $container->alias(BASEAES::class, 'Crypt.AESCBC') + ->share('Crypt.AESCBC', [$this, 'getBASEAESCBC'], false); + + $container->alias(FOF::class, 'Crypt.FOF') + ->share('Crypt.FOF', [$this, 'getFOF'], true); + + $container->alias(Aes::class, 'Crypt.AES.CBC') + ->share('Crypt.AES.CBC', [$this, 'getAesCBC'], true); + + $container->alias(Legacy::class, 'Crypt.AES.LEGACY') + ->share('Crypt.AES.LEGACY', [$this, 'getAesLEGACY'], true); + } + + /** + * Get the Crypto class + * + * @param Container $container The DI container. + * + * @return Crypto + * @since 3.2.0 + */ + public function getCrypt(Container $container): Crypto + { + return new Crypto( + $container->get('Crypt.FOF'), + $container->get('Crypt.AES.CBC'), + $container->get('Crypt.AES.LEGACY'), + $container->get('Crypt.Password') + ); + } + + /** + * Get the Password class + * + * @param Container $container The DI container. + * + * @return Password + * @since 3.2.0 + */ + public function getPassword(Container $container): Password + { + return new Password(); + } + + /** + * Get the Random class + * + * @param Container $container The DI container. + * + * @return Random + * @since 3.2.0 + */ + public function getRandom(Container $container): Random + { + return new Random(); + } + + /** + * Get the KeyLoader class + * + * @param Container $container The DI container. + * + * @return KeyLoader + * @since 3.2.0 + */ + public function getKeyLoader(Container $container): KeyLoader + { + return new KeyLoader(); + } + + /** + * Get the AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return BASEAES + * @since 3.2.0 + */ + public function getBASEAESCBC(Container $container): BASEAES + { + return new BASEAES('cbc'); + } + + /** + * Get the Wrapper AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return Aes + * @since 3.2.0 + */ + public function getAesCBC(Container $container): Aes + { + return new Aes( + $container->get('Crypt.AESCBC'), + $container->get('Crypt.Random') + ); + } + + /** + * Get the Wrapper AES Legacy Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return Legacy + * @since 3.2.0 + */ + public function getAesLEGACY(Container $container): Legacy + { + return new Legacy( + $container->get('Crypt.AESCBC') + ); + } + + /** + * Get the FOF AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return FOF + * @since 3.2.0 + */ + public function getFOF(Container $container): FOF + { + return new FOF( + $container->get('Crypt.AESCBC'), + $container->get('Crypt.Random') + ); + } + +} + diff --git a/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.power b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.power new file mode 100644 index 0000000..0f9e16a --- /dev/null +++ b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/code.power @@ -0,0 +1,151 @@ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Crypto::class, 'Crypt') + ->share('Crypt', [$this, 'getCrypt'], true); + + $container->alias(Random::class, 'Crypt.Random') + ->share('Crypt.Random', [$this, 'getRandom'], true); + + $container->alias(Password::class, 'Crypt.Password') + ->share('Crypt.Password', [$this, 'getPassword'], true); + + $container->alias(KeyLoader::class, 'Crypt.Key') + ->share('Crypt.Key', [$this, 'getKeyLoader'], true); + + $container->alias(BASEAES::class, 'Crypt.AESCBC') + ->share('Crypt.AESCBC', [$this, 'getBASEAESCBC'], false); + + $container->alias(FOF::class, 'Crypt.FOF') + ->share('Crypt.FOF', [$this, 'getFOF'], true); + + $container->alias(Aes::class, 'Crypt.AES.CBC') + ->share('Crypt.AES.CBC', [$this, 'getAesCBC'], true); + + $container->alias(Legacy::class, 'Crypt.AES.LEGACY') + ->share('Crypt.AES.LEGACY', [$this, 'getAesLEGACY'], true); + } + + /** + * Get the Crypto class + * + * @param Container $container The DI container. + * + * @return Crypto + * @since 3.2.0 + */ + public function getCrypt(Container $container): Crypto + { + return new Crypto( + $container->get('Crypt.FOF'), + $container->get('Crypt.AES.CBC'), + $container->get('Crypt.AES.LEGACY'), + $container->get('Crypt.Password') + ); + } + + /** + * Get the Password class + * + * @param Container $container The DI container. + * + * @return Password + * @since 3.2.0 + */ + public function getPassword(Container $container): Password + { + return new Password(); + } + + /** + * Get the Random class + * + * @param Container $container The DI container. + * + * @return Random + * @since 3.2.0 + */ + public function getRandom(Container $container): Random + { + return new Random(); + } + + /** + * Get the KeyLoader class + * + * @param Container $container The DI container. + * + * @return KeyLoader + * @since 3.2.0 + */ + public function getKeyLoader(Container $container): KeyLoader + { + return new KeyLoader(); + } + + /** + * Get the AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return BASEAES + * @since 3.2.0 + */ + public function getBASEAESCBC(Container $container): BASEAES + { + return new BASEAES('cbc'); + } + + /** + * Get the Wrapper AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return Aes + * @since 3.2.0 + */ + public function getAesCBC(Container $container): Aes + { + return new Aes( + $container->get('Crypt.AESCBC'), + $container->get('Crypt.Random') + ); + } + + /** + * Get the Wrapper AES Legacy Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return Legacy + * @since 3.2.0 + */ + public function getAesLEGACY(Container $container): Legacy + { + return new Legacy( + $container->get('Crypt.AESCBC') + ); + } + + /** + * Get the FOF AES Cyper with CBC mode + * + * @param Container $container The DI container. + * + * @return FOF + * @since 3.2.0 + */ + public function getFOF(Container $container): FOF + { + return new FOF( + $container->get('Crypt.AESCBC'), + $container->get('Crypt.Random') + ); + } diff --git a/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/settings.json b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/settings.json new file mode 100644 index 0000000..d1c4cdc --- /dev/null +++ b/src/4d8f38ef-8f3a-463d-8678-0bf087ac6815/settings.json @@ -0,0 +1,59 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "4d8f38ef-8f3a-463d-8678-0bf087ac6815", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Crypt", + "power_version": "1.0.0", + "system_name": "JCB.Service.Crypt", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "d357e796-9f22-4615-9ebc-970b42cbd280", + "as": "Crypto" + }, + "use_selection1": { + "use": "6da44dff-a221-4f22-b9d9-b2fc2a724b4b", + "as": "default" + }, + "use_selection2": { + "use": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "as": "default" + }, + "use_selection3": { + "use": "fea2b107-3ee4-4ebf-84be-d3f2829c8614", + "as": "default" + }, + "use_selection4": { + "use": "e98b4edc-25b9-49d7-98a0-e42ad3b75efe", + "as": "default" + }, + "use_selection5": { + "use": "a25c82c8-14c2-40df-adae-f832709ab49b", + "as": "default" + }, + "use_selection6": { + "use": "437af6b0-ca02-49d7-8739-4edfc8a9ccb0", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Service.Crypt", + "description": "Phpseclib Crypt Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\AES as BASEAES" + } + } + } + } +} \ No newline at end of file diff --git a/src/66355f70-c26c-4765-ba48-498e3df740ef/README.md b/src/66355f70-c26c-4765-ba48-498e3df740ef/README.md new file mode 100644 index 0000000..c4c8d7d --- /dev/null +++ b/src/66355f70-c26c-4765-ba48-498e3df740ef/README.md @@ -0,0 +1,76 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Server (Details) +> namespace: **VDM\Joomla\Componentbuilder** +```uml +@startuml +class Server #Gold { + # Load $load + # Ftp $ftp + # Sftp $sftp + # User $user + + __construct(Load $load, Ftp $ftp, ...) + + move(int $id, string $localPath, ...) : bool + + legacyMove(string $localPath, string $fileName, ...) : bool +} + +note right of Server::__construct + Constructor + + since: 3.2.0 + + arguments: + Load $load + Ftp $ftp + Sftp $sftp + ?User $user = null +end note + +note right of Server::move + Move File to Server + + since: 3.2.0 + return: bool + + arguments: + int $id + string $localPath + string $fileName + ?int $protocol = null + string $permission = 'core.export' +end note + +note right of Server::legacyMove + Move File to Server (Legacy Signature) + + since: 3.2.0 + return: bool + + arguments: + string $localPath + string $fileName + int $serverID + int $protocol = null + string $permission = 'core.export' +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/66355f70-c26c-4765-ba48-498e3df740ef/code.php b/src/66355f70-c26c-4765-ba48-498e3df740ef/code.php new file mode 100644 index 0000000..46220dc --- /dev/null +++ b/src/66355f70-c26c-4765-ba48-498e3df740ef/code.php @@ -0,0 +1,165 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder; + + +use Joomla\CMS\Factory as JoomlaFactory; +use Joomla\CMS\User\User; +use VDM\Joomla\Componentbuilder\Server\Load; +use VDM\Joomla\Componentbuilder\Server\Ftp; +use VDM\Joomla\Componentbuilder\Server\Sftp; +use VDM\Joomla\Utilities\StringHelper; + + +/** + * Server Class + * + * @since 3.2.0 + */ +class Server +{ + /** + * The Loader + * + * @var Load + * @since 3.2.0 + */ + protected Load $load; + + /** + * The Ftp object + * + * @var Ftp + * @since 3.2.0 + **/ + protected Ftp $ftp; + + /** + * The Sftp object + * + * @var Sftp + * @since 3.2.0 + **/ + protected Sftp $sftp; + + /** + * Current User object + * + * @var User + * @since 3.2.0 + */ + protected User $user; + + /** + * Constructor + * + * @param Load $load The server details loader object. + * @param Ftp $ftp The server ftp object. + * @param Sftp $sftp The server sftp object. + * @param User|null $user The user object. + * + * @since 3.2.0 + */ + public function __construct(Load $load, Ftp $ftp, Sftp $sftp, ?User $user = null) + { + $this->load = $load; + $this->ftp = $ftp; + $this->sftp = $sftp; + $this->user = $user ?: JoomlaFactory::getUser(); + } + + /** + * Move File to Server + * + * @param int $id The server local id to use + * @param string $localPath The local path to the file + * @param string $fileName The actual file name + * @param int|null $protocol The protocol to use (if set) + * @param string $permission The permission validation area + * + * @return bool true on success + * @since 3.2.0 + */ + public function move(int $id, string $localPath, string $fileName, + ?int $protocol = null, string $permission = 'core.export'): bool + { + // get the server + if ($this->user->authorise($permission, 'com_componentbuilder') && + ( + ( + is_numeric($protocol) && + ($protocol == 1 || $protocol == 2) + ) || ( + ($protocol = $this->load->value($id, 'protocol')) !== null && + ($protocol == 1 || $protocol == 2) + ) + ) + ) + { + // use the FTP protocol + if (1 == $protocol) + { + $protocol = 'ftp'; + $fields = [ + 'name', + 'signature' + ]; + } + // use the SFTP protocol + else + { + $protocol = 'sftp'; + $fields = [ + 'name', + 'authentication', + 'username', + 'host', + 'password', + 'path', + 'port', + 'private', + 'private_key', + 'secret' + ]; + } + + // get the details + if (StringHelper::check($protocol) && ($details = $this->load->item($id, $fields)) !== null) + { + // now move the file + return $this->{$protocol}->set($details)->move($localPath, $fileName); + } + } + + return false; + } + + /** + * Move File to Server (Legacy Signature) + * + * @param string $localPath The local path to the file + * @param string $fileName The actual file name + * @param int $serverID The server local id to use + * @param int $protocol The server protocol to use + * @param string $permission The permission validation area + * + * @return bool true on success + * @since 3.2.0 + * @deprecated 4.0 + */ + public function legacyMove($localPath, $fileName, $serverID, $protocol = null, $permission = 'core.export'): bool + { + return $this->move($serverID, $localPath, $fileName, $protocol, $permission); + } + +} + diff --git a/src/66355f70-c26c-4765-ba48-498e3df740ef/code.power b/src/66355f70-c26c-4765-ba48-498e3df740ef/code.power new file mode 100644 index 0000000..2cf16ee --- /dev/null +++ b/src/66355f70-c26c-4765-ba48-498e3df740ef/code.power @@ -0,0 +1,133 @@ + /** + * The Loader + * + * @var Load + * @since 3.2.0 + */ + protected Load $load; + + /** + * The Ftp object + * + * @var Ftp + * @since 3.2.0 + **/ + protected Ftp $ftp; + + /** + * The Sftp object + * + * @var Sftp + * @since 3.2.0 + **/ + protected Sftp $sftp; + + /** + * Current User object + * + * @var User + * @since 3.2.0 + */ + protected User $user; + + /** + * Constructor + * + * @param Load $load The server details loader object. + * @param Ftp $ftp The server ftp object. + * @param Sftp $sftp The server sftp object. + * @param User|null $user The user object. + * + * @since 3.2.0 + */ + public function __construct(Load $load, Ftp $ftp, Sftp $sftp, ?User $user = null) + { + $this->load = $load; + $this->ftp = $ftp; + $this->sftp = $sftp; + $this->user = $user ?: JoomlaFactory::getUser(); + } + + /** + * Move File to Server + * + * @param int $id The server local id to use + * @param string $localPath The local path to the file + * @param string $fileName The actual file name + * @param int|null $protocol The protocol to use (if set) + * @param string $permission The permission validation area + * + * @return bool true on success + * @since 3.2.0 + */ + public function move(int $id, string $localPath, string $fileName, + ?int $protocol = null, string $permission = 'core.export'): bool + { + // get the server + if ($this->user->authorise($permission, 'com_componentbuilder') && + ( + ( + is_numeric($protocol) && + ($protocol == 1 || $protocol == 2) + ) || ( + ($protocol = $this->load->value($id, 'protocol')) !== null && + ($protocol == 1 || $protocol == 2) + ) + ) + ) + { + // use the FTP protocol + if (1 == $protocol) + { + $protocol = 'ftp'; + $fields = [ + 'name', + 'signature' + ]; + } + // use the SFTP protocol + else + { + $protocol = 'sftp'; + $fields = [ + 'name', + 'authentication', + 'username', + 'host', + 'password', + 'path', + 'port', + 'private', + 'private_key', + 'secret' + ]; + } + + // get the details + if (StringHelper::check($protocol) && ($details = $this->load->item($id, $fields)) !== null) + { + // now move the file + return $this->{$protocol}->set($details)->move($localPath, $fileName); + } + } + + return false; + } + + /** + * Move File to Server (Legacy Signature) + * + * @param string $localPath The local path to the file + * @param string $fileName The actual file name + * @param int $serverID The server local id to use + * @param int $protocol The server protocol to use + * @param string $permission The permission validation area + * + * @return bool true on success + * @since 3.2.0 + * @deprecated 4.0 + */ + public function legacyMove($localPath, $fileName, $serverID, $protocol = null, $permission = 'core.export'): bool + { + return $this->move($serverID, $localPath, $fileName, $protocol, $permission); + } diff --git a/src/66355f70-c26c-4765-ba48-498e3df740ef/settings.json b/src/66355f70-c26c-4765-ba48-498e3df740ef/settings.json new file mode 100644 index 0000000..46e1ee5 --- /dev/null +++ b/src/66355f70-c26c-4765-ba48-498e3df740ef/settings.json @@ -0,0 +1,35 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "66355f70-c26c-4765-ba48-498e3df740ef", + "implements": null, + "load_selection": null, + "name": "Server", + "power_version": "1.0.0", + "system_name": "JCB.Server", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "a3414824-e99d-4878-b3d1-b5deef0cae17", + "as": "default" + }, + "use_selection1": { + "use": "11be6be3-ee3e-4771-8663-5545b76b73ab", + "as": "default" + }, + "use_selection2": { + "use": "490b6aa5-5de7-4be5-a61a-f634f6e004c0", + "as": "default" + }, + "use_selection3": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Server", + "description": "Server Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Factory as JoomlaFactory;\r\nuse Joomla\\CMS\\User\\User;", + "composer": "" +} \ No newline at end of file diff --git a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md new file mode 100644 index 0000000..8e5d4c1 --- /dev/null +++ b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md @@ -0,0 +1,21 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +> Error adding class diagram + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.php b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.php new file mode 100644 index 0000000..e6ed5f0 --- /dev/null +++ b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.php @@ -0,0 +1,26 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt; + + +use phpseclib3\Crypt\PublicKeyLoader; + + +/** + * KeyLoader Class + * + * @since 3.2.0 + */ +class KeyLoader extends PublicKeyLoader +{ +} + diff --git a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.power b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.power new file mode 100644 index 0000000..69309b0 --- /dev/null +++ b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/code.power @@ -0,0 +1 @@ +###CODEPOWER### \ No newline at end of file diff --git a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/settings.json b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/settings.json new file mode 100644 index 0000000..b496bbe --- /dev/null +++ b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/settings.json @@ -0,0 +1,28 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "-1", + "guid": "6da44dff-a221-4f22-b9d9-b2fc2a724b4b", + "implements": null, + "load_selection": null, + "name": "KeyLoader", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.KeyLoader", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.KeyLoader", + "description": "KeyLoader Class\r\n\r\n@since 3.2.0", + "extends_custom": "PublicKeyLoader", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\PublicKeyLoader" + } + } + } + } +} \ No newline at end of file diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md b/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md new file mode 100644 index 0000000..907ab40 --- /dev/null +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md @@ -0,0 +1,55 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Aes (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt** +```uml +@startuml +class Aes #Gold { + # BASEAES $aes + # Random $random + # int $size + + __construct(BASEAES $aes, Random $random) + + encrypt(string $string, string $key) : string + + decrypt(string $string, string $key) : string +} + +note right of Aes::__construct + Constructor + + since: 3.2.0 +end note + +note right of Aes::encrypt + Encrypt a string as needed + + since: 3.2.0 + return: string +end note + +note right of Aes::decrypt + Decrypt a string as needed + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php new file mode 100644 index 0000000..e940f57 --- /dev/null +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php @@ -0,0 +1,131 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt; + + +use phpseclib3\Crypt\AES as BASEAES; +use VDM\Joomla\Componentbuilder\Crypt\Random; +use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; + + +/** + * Class for Aes Encryption + * + * @since 3.2.0 + */ +class Aes implements Cryptinterface +{ + /** + * The Aes class + * + * @var BASEAES + * @since 3.2.0 + */ + protected BASEAES $aes; + + /** + * The Random class + * + * @var Random + * @since 3.2.0 + */ + protected Random $random; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 256; + + /** + * Constructor + * + * @param BASEAES $aes The Aes class + * @param Random $random The Random class + * + * @since 3.2.0 + */ + public function __construct(BASEAES $aes, Random $random) + { + $this->aes = $aes; + $this->random = $random; + + // we set the length once + $this->aes->setKeyLength($this->size); + + // enable padding + $this->aes->enablePadding(); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = $this->random::string($iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + // encrypt the string, and base 64 encode the result + return base64_encode($iv . $this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // remove base 64 encoding + $string = base64_decode($string); + + // get the IV + $iv = substr($string, 0, $iv_length); + + // remove the IV + $string = substr($string, $iv_length); + + // set the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + return $this->aes->decrypt($string); + } + +} + diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power new file mode 100644 index 0000000..0b8b103 --- /dev/null +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power @@ -0,0 +1,102 @@ + /** + * The Aes class + * + * @var BASEAES + * @since 3.2.0 + */ + protected BASEAES $aes; + + /** + * The Random class + * + * @var Random + * @since 3.2.0 + */ + protected Random $random; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 256; + + /** + * Constructor + * + * @param BASEAES $aes The Aes class + * @param Random $random The Random class + * + * @since 3.2.0 + */ + public function __construct(BASEAES $aes, Random $random) + { + $this->aes = $aes; + $this->random = $random; + + // we set the length once + $this->aes->setKeyLength($this->size); + + // enable padding + $this->aes->enablePadding(); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = $this->random::string($iv_length); + + // Load the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + // encrypt the string, and base 64 encode the result + return base64_encode($iv . $this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // remove base 64 encoding + $string = base64_decode($string); + + // get the IV + $iv = substr($string, 0, $iv_length); + + // remove the IV + $string = substr($string, $iv_length); + + // set the IV + $this->aes->setIV($iv); + + // set the password + $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); + + return $this->aes->decrypt($string); + } diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json b/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json new file mode 100644 index 0000000..4f54f93 --- /dev/null +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json @@ -0,0 +1,34 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "a25c82c8-14c2-40df-adae-f832709ab49b", + "implements": [ + "81de8f57-dd9c-4a17-964f-848cd4a0743b" + ], + "load_selection": null, + "name": "Aes", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.Aes", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.Aes", + "description": "Class for Aes Encryption\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\AES as BASEAES" + } + } + } + } +} \ No newline at end of file diff --git a/src/a3414824-e99d-4878-b3d1-b5deef0cae17/README.md b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/README.md new file mode 100644 index 0000000..0d91de5 --- /dev/null +++ b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/README.md @@ -0,0 +1,64 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Load (Details) +> namespace: **VDM\Joomla\Componentbuilder\Server** +```uml +@startuml +class Load #Gold { + # Database $db + # Model $model + + __construct(?Database $db = null, ?Model $model = null) + + value(int $id, string $field) : mixed|null + + item(int $id, array $fields) : ?object + # setDatabaseFields(array $fields, string $key = 'a') : array +} + +note right of Load::__construct + Constructor + + since: 3.2.0 +end note + +note right of Load::value + Get a value from a given server +Example: $this->value(23, 'protocol'); + + since: 3.2.0 + return: mixed|null +end note + +note right of Load::item + Get values from a given server +Example: $this->item(23, ['name', 'of', 'fields']); + + since: 3.2.0 + return: ?object +end note + +note right of Load::setDatabaseFields + Set Fields ready to use in database call + + since: 3.2.0 + return: array +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.php b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.php new file mode 100644 index 0000000..fa1a93a --- /dev/null +++ b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.php @@ -0,0 +1,122 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Server; + + +use VDM\Joomla\Componentbuilder\Compiler\Factory; +use VDM\Joomla\Componentbuilder\Database\Load as Database; +use VDM\Joomla\Componentbuilder\Server\Model\Load as Model; + + +/** + * Server Load Class + * + * @since 3.2.0 + */ +class Load +{ + /** + * Database Load + * + * @var Database + * @since 3.2.0 + */ + protected Database $db; + + /** + * Model Class + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Constructor + * + * @param Database|null $db The database object. + * @param Model|null $model The core crypt object. + * + * @since 3.2.0 + */ + public function __construct(?Database $db = null, ?Model $model = null) + { + $this->db = $db ?: Factory::_('Load'); + $this->model = $model ?: Factory::_('Model.Server.Load'); + } + + /** + * Get a value from a given server + * Example: $this->value(23, 'protocol'); + * + * @param int $id The item ID + * @param string $field The table field + * + * @return mixed|null + * @since 3.2.0 + */ + public function value(int $id, string $field) + { + if ($id > 0 && ($value = $this->db->value( + $this->setDatabaseFields([$field]), ['a' => 'server'], ['a.id' => $id] + )) !== null) + { + return $this->model->value($value, $field, 'server'); + } + + return null; + } + + /** + * Get values from a given server + * Example: $this->item(23, ['name', 'of', 'fields']); + * + * @param int $id The item ID + * @param array $fields The table fields + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, array $fields): ?object + { + if ($id > 0 && ($item = $this->db->item( + $this->setDatabaseFields($fields), ['a' => 'server'], ['a.id' => $id] + )) !== null) + { + return $this->model->item($item, 'server'); + } + + return null; + } + + /** + * Set Fields ready to use in database call + * + * @param array $fields The table + * @param string $key The table key to which the fields belong + * + * @return array + * @since 3.2.0 + */ + protected function setDatabaseFields(array $fields, string $key = 'a'): array + { + $bucket = []; + foreach ($fields as $field) + { + $bucket[$key . '.' . $field] = $field; + } + + return $bucket; + } + +} + diff --git a/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.power b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.power new file mode 100644 index 0000000..4efddbe --- /dev/null +++ b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/code.power @@ -0,0 +1,93 @@ + /** + * Database Load + * + * @var Database + * @since 3.2.0 + */ + protected Database $db; + + /** + * Model Class + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Constructor + * + * @param Database|null $db The database object. + * @param Model|null $model The core crypt object. + * + * @since 3.2.0 + */ + public function __construct(?Database $db = null, ?Model $model = null) + { + $this->db = $db ?: Factory::_('Load'); + $this->model = $model ?: Factory::_('Model.Server.Load'); + } + + /** + * Get a value from a given server + * Example: $this->value(23, 'protocol'); + * + * @param int $id The item ID + * @param string $field The table field + * + * @return mixed|null + * @since 3.2.0 + */ + public function value(int $id, string $field) + { + if ($id > 0 && ($value = $this->db->value( + $this->setDatabaseFields([$field]), ['a' => 'server'], ['a.id' => $id] + )) !== null) + { + return $this->model->value($value, $field, 'server'); + } + + return null; + } + + /** + * Get values from a given server + * Example: $this->item(23, ['name', 'of', 'fields']); + * + * @param int $id The item ID + * @param array $fields The table fields + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, array $fields): ?object + { + if ($id > 0 && ($item = $this->db->item( + $this->setDatabaseFields($fields), ['a' => 'server'], ['a.id' => $id] + )) !== null) + { + return $this->model->item($item, 'server'); + } + + return null; + } + + /** + * Set Fields ready to use in database call + * + * @param array $fields The table + * @param string $key The table key to which the fields belong + * + * @return array + * @since 3.2.0 + */ + protected function setDatabaseFields(array $fields, string $key = 'a'): array + { + $bucket = []; + foreach ($fields as $field) + { + $bucket[$key . '.' . $field] = $field; + } + + return $bucket; + } diff --git a/src/a3414824-e99d-4878-b3d1-b5deef0cae17/settings.json b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/settings.json new file mode 100644 index 0000000..c11a03f --- /dev/null +++ b/src/a3414824-e99d-4878-b3d1-b5deef0cae17/settings.json @@ -0,0 +1,31 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "a3414824-e99d-4878-b3d1-b5deef0cae17", + "implements": null, + "load_selection": null, + "name": "Load", + "power_version": "1.0.0", + "system_name": "JCB.Server.Load", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac", + "as": "default" + }, + "use_selection1": { + "use": "06f8eada-d59b-441c-b287-0aea1793da5a", + "as": "Database" + }, + "use_selection2": { + "use": "f37ee8b7-2909-4319-bdf8-769bd7635490", + "as": "Model" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Server.Load", + "description": "Server Load Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md new file mode 100644 index 0000000..8e5d4c1 --- /dev/null +++ b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md @@ -0,0 +1,21 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +> Error adding class diagram + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.php b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.php new file mode 100644 index 0000000..4815684 --- /dev/null +++ b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.php @@ -0,0 +1,26 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt; + + +use phpseclib3\Crypt\Random as CryptRandom; + + +/** + * Random Class + * + * @since 3.2.0 + */ +class Random extends CryptRandom +{ +} + diff --git a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.power b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.power new file mode 100644 index 0000000..69309b0 --- /dev/null +++ b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/code.power @@ -0,0 +1 @@ +###CODEPOWER### \ No newline at end of file diff --git a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/settings.json b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/settings.json new file mode 100644 index 0000000..d94164d --- /dev/null +++ b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/settings.json @@ -0,0 +1,28 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "-1", + "guid": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "implements": null, + "load_selection": null, + "name": "Random", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.Random", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.Random", + "description": "Random Class\r\n\r\n@since 3.2.0", + "extends_custom": "CryptRandom", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\Random as CryptRandom" + } + } + } + } +} \ No newline at end of file diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md b/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md new file mode 100644 index 0000000..18106a7 --- /dev/null +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md @@ -0,0 +1,130 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Crypt (Details) +> namespace: **VDM\Joomla\Componentbuilder** +```uml +@startuml +class Crypt #Gold { + # FOF $fof + # Aes $aes + # Legacy $legacy + # Password $password + # array $options + # array $passwords + + __construct(FOF $fof, Aes $aes, ...) + + encrypt(string $string, string $method, ...) : string + + decrypt(string $string, string $method, ...) : string + + exist(string $method) : bool + - getClassName(string $method) : ?string + - getClassNameFromRegistry(string $method) : ?string + - getClassNameFromOptions(string $method) : ?string + - getPassword(string $method, ?string $password = null) : ?string + - getPasswordKey(string $method) : string + - name(string $method) : string +} + +note right of Crypt::__construct + Constructor + + since: 3.2.0 + + arguments: + FOF $fof + Aes $aes + Legacy $legacy + Password $password +end note + +note left of Crypt::encrypt + Encrypt a string as needed + + since: 3.2.0 + return: string + + arguments: + string $string + string $method + ?string $password = null +end note + +note right of Crypt::decrypt + Decrypt a string as needed + + since: 3.2.0 + return: string + + arguments: + string $string + string $method + ?string $default = null +end note + +note left of Crypt::exist + Check if a decryption method exist and is supported + + since: 3.2.0 + return: bool +end note + +note right of Crypt::getClassName + Get crypto class name to use + + since: 3.2.0 + return: ?string +end note + +note left of Crypt::getClassNameFromRegistry + Get the crypto class name from the registry + + since: 3.2.0 + return: ?string +end note + +note right of Crypt::getClassNameFromOptions + Get the crypto class name for the given encryption method and options + + since: 3.2.0 + return: ?string +end note + +note left of Crypt::getPassword + Get the password + + since: 3.2.0 + return: ?string +end note + +note right of Crypt::getPasswordKey + Get the key + + since: 3.2.0 + return: string +end note + +note left of Crypt::name + Get the class name + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php new file mode 100644 index 0000000..27ad5fb --- /dev/null +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php @@ -0,0 +1,285 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder; + + +use VDM\Joomla\Componentbuilder\Crypt\FOF; +use VDM\Joomla\Componentbuilder\Crypt\Aes; +use VDM\Joomla\Componentbuilder\Crypt\Aes\Legacy; +use VDM\Joomla\Componentbuilder\Crypt\Password; +use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; +use VDM\Joomla\Utilities\StringHelper; + + +/** + * Crypto Class + * + * @since 3.2.0 + */ +class Crypt +{ + /** + * The Crypt AES FOF class + * replacement class + * + * @var FOF + * @since 3.2.0 + */ + protected FOF $fof; + + /** + * The Crypt AES CBC class + * + * @var Aes + * @since 3.2.0 + */ + protected Aes $aes; + + /** + * The Crypt AES Legacy class + * + * @var Legacy + * @since 3.2.0 + */ + protected Legacy $legacy; + + /** + * The Password class + * + * @var Password + * @since 3.2.0 + */ + protected Password $password; + + /** + * Active encryption options + * + * @var array + * @since 3.2.0 + */ + protected array $options = [ + 'basic' => 'fof', + 'medium' => 'fof', + 'local' => 'aes' + ]; + + /** + * Active passwords + * + * @var array + * @since 3.2.0 + */ + protected array $passwords = []; + + /** + * Constructor + * + * @param FOF $fof The FOF class + * @param Aes $aes The AES CBC class + * @param Legacy $legacy The AES Legacy class + * @param Password $password The Password class + * + * @since 3.2.0 + */ + public function __construct(FOF $fof, Aes $aes, Legacy $legacy, Password $password) + { + $this->fof = $fof; + $this->aes = $aes; + $this->legacy = $legacy; + $this->password = $password; + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $method The encryption method to use + * @param string|null $password The password + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $method, + ?string $password = null): string + { + if (($password = $this->getPassword($method, $password)) !== null + && ($name = $this->getClassName($method)) !== null) + { + return $this->{$name}->encrypt($string, $password); + } + + return $string; + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $method The encryption method to use + * @param string|null $default The default password + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $method, + ?string $default = null): string + { + if (($password = $this->getPassword($method, $default)) !== null + && ($name = $this->getClassName($method)) !== null) + { + return $this->{$name}->decrypt($string, $password); + } + + return $string; + } + + /** + * Check if a decryption method exist and is supported + * + * @param string $method The encryption method to find + * + * @return bool true if it exist + * @since 3.2.0 + **/ + public function exist(string $method): bool + { + return is_string($this->getClassName($method)) ?? false; + } + + /** + * Get crypto class name to use + * + * @param string $method The encryption method to find + * + * @return string|null The crypto class name + * @since 3.2.0 + **/ + private function getClassName(string $method): ?string + { + if (($name = $this->getClassNameFromRegistry($method)) !== null) + { + return $name; + } + + return $this->getClassNameFromOptions($method); + } + + /** + * Get the crypto class name from the registry + * + * @param string $method The encryption method to use + * + * @return string|null The crypto class name, or null if not found + * @since 3.2.0 + **/ + private function getClassNameFromRegistry(string $method): ?string + { + $name = $this->name($method); + + if (isset($this->{$name}) && $this->{$name} instanceof Cryptinterface) + { + return $name; + } + + return null; + } + + /** + * Get the crypto class name for the given encryption method and options + * + * @param string $method The encryption method to use + * + * @return string|null The crypto class name, or null if not found + * @since 3.2.0 + **/ + private function getClassNameFromOptions(string $method): ?string + { + $key = $this->getPasswordKey($method); + + if (isset($this->options[$key])) + { + $name = $this->options[$key]; + + if (isset($this->{$name}) && $this->{$name} instanceof Cryptinterface) + { + return $name; + } + } + + return null; + } + + /** + * Get the password + * + * @param string $method The encryption method to find + * @param string|null $password The password + * + * @return string|null the password or null + * @since 3.2.0 + **/ + private function getPassword(string $method, ?string $password = null): ?string + { + if (StringHelper::check($password)) + { + return $password; + } + + // get password key name + $key = $this->getPasswordKey($method); + + if (empty($this->passwords[$key])) + { + $this->passwords[$key] = $this->password->get($key); + } + + return $this->passwords[$key]; + } + + /** + * Get the key + * + * @param string $method The encryption method to find + * + * @return string the password key name + * @since 3.2.0 + **/ + private function getPasswordKey(string $method): string + { + if (($pos = strpos($method, '.')) !== false) + { + return substr($method, 0, $pos); + } + + return $method; + } + + /** + * Get the class name + * + * @param string $method The encryption method to find + * + * @return string the class name + * @since 3.2.0 + **/ + private function name(string $method): string + { + if (($pos = strpos($method, '.')) !== false) + { + return substr($method, $pos + 1); + } + + return $method; + } + +} + diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power new file mode 100644 index 0000000..19e0e6e --- /dev/null +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power @@ -0,0 +1,253 @@ + /** + * The Crypt AES FOF class + * replacement class + * + * @var FOF + * @since 3.2.0 + */ + protected FOF $fof; + + /** + * The Crypt AES CBC class + * + * @var Aes + * @since 3.2.0 + */ + protected Aes $aes; + + /** + * The Crypt AES Legacy class + * + * @var Legacy + * @since 3.2.0 + */ + protected Legacy $legacy; + + /** + * The Password class + * + * @var Password + * @since 3.2.0 + */ + protected Password $password; + + /** + * Active encryption options + * + * @var array + * @since 3.2.0 + */ + protected array $options = [ + 'basic' => 'fof', + 'medium' => 'fof', + 'local' => 'aes' + ]; + + /** + * Active passwords + * + * @var array + * @since 3.2.0 + */ + protected array $passwords = []; + + /** + * Constructor + * + * @param FOF $fof The FOF class + * @param Aes $aes The AES CBC class + * @param Legacy $legacy The AES Legacy class + * @param Password $password The Password class + * + * @since 3.2.0 + */ + public function __construct(FOF $fof, Aes $aes, Legacy $legacy, Password $password) + { + $this->fof = $fof; + $this->aes = $aes; + $this->legacy = $legacy; + $this->password = $password; + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $method The encryption method to use + * @param string|null $password The password + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $method, + ?string $password = null): string + { + if (($password = $this->getPassword($method, $password)) !== null + && ($name = $this->getClassName($method)) !== null) + { + return $this->{$name}->encrypt($string, $password); + } + + return $string; + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $method The encryption method to use + * @param string|null $default The default password + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $method, + ?string $default = null): string + { + if (($password = $this->getPassword($method, $default)) !== null + && ($name = $this->getClassName($method)) !== null) + { + return $this->{$name}->decrypt($string, $password); + } + + return $string; + } + + /** + * Check if a decryption method exist and is supported + * + * @param string $method The encryption method to find + * + * @return bool true if it exist + * @since 3.2.0 + **/ + public function exist(string $method): bool + { + return is_string($this->getClassName($method)) ?? false; + } + + /** + * Get crypto class name to use + * + * @param string $method The encryption method to find + * + * @return string|null The crypto class name + * @since 3.2.0 + **/ + private function getClassName(string $method): ?string + { + if (($name = $this->getClassNameFromRegistry($method)) !== null) + { + return $name; + } + + return $this->getClassNameFromOptions($method); + } + + /** + * Get the crypto class name from the registry + * + * @param string $method The encryption method to use + * + * @return string|null The crypto class name, or null if not found + * @since 3.2.0 + **/ + private function getClassNameFromRegistry(string $method): ?string + { + $name = $this->name($method); + + if (isset($this->{$name}) && $this->{$name} instanceof Cryptinterface) + { + return $name; + } + + return null; + } + + /** + * Get the crypto class name for the given encryption method and options + * + * @param string $method The encryption method to use + * + * @return string|null The crypto class name, or null if not found + * @since 3.2.0 + **/ + private function getClassNameFromOptions(string $method): ?string + { + $key = $this->getPasswordKey($method); + + if (isset($this->options[$key])) + { + $name = $this->options[$key]; + + if (isset($this->{$name}) && $this->{$name} instanceof Cryptinterface) + { + return $name; + } + } + + return null; + } + + /** + * Get the password + * + * @param string $method The encryption method to find + * @param string|null $password The password + * + * @return string|null the password or null + * @since 3.2.0 + **/ + private function getPassword(string $method, ?string $password = null): ?string + { + if (StringHelper::check($password)) + { + return $password; + } + + // get password key name + $key = $this->getPasswordKey($method); + + if (empty($this->passwords[$key])) + { + $this->passwords[$key] = $this->password->get($key); + } + + return $this->passwords[$key]; + } + + /** + * Get the key + * + * @param string $method The encryption method to find + * + * @return string the password key name + * @since 3.2.0 + **/ + private function getPasswordKey(string $method): string + { + if (($pos = strpos($method, '.')) !== false) + { + return substr($method, 0, $pos); + } + + return $method; + } + + /** + * Get the class name + * + * @param string $method The encryption method to find + * + * @return string the class name + * @since 3.2.0 + **/ + private function name(string $method): string + { + if (($pos = strpos($method, '.')) !== false) + { + return substr($method, $pos + 1); + } + + return $method; + } diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/settings.json b/src/d357e796-9f22-4615-9ebc-970b42cbd280/settings.json new file mode 100644 index 0000000..d33598a --- /dev/null +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/settings.json @@ -0,0 +1,43 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "d357e796-9f22-4615-9ebc-970b42cbd280", + "implements": null, + "load_selection": null, + "name": "Crypt", + "power_version": "1.0.0", + "system_name": "JCB.Crypt", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "e98b4edc-25b9-49d7-98a0-e42ad3b75efe", + "as": "default" + }, + "use_selection1": { + "use": "a25c82c8-14c2-40df-adae-f832709ab49b", + "as": "default" + }, + "use_selection2": { + "use": "437af6b0-ca02-49d7-8739-4edfc8a9ccb0", + "as": "default" + }, + "use_selection3": { + "use": "fea2b107-3ee4-4ebf-84be-d3f2829c8614", + "as": "default" + }, + "use_selection4": { + "use": "81de8f57-dd9c-4a17-964f-848cd4a0743b", + "as": "default" + }, + "use_selection5": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt", + "description": "Crypto Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md new file mode 100644 index 0000000..7e869b9 --- /dev/null +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md @@ -0,0 +1,84 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class FOF (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt** +```uml +@startuml +class FOF #Gold { + # AES $aes + # Random $random + # int $size + + __construct(AES $aes, Random $random) + + encrypt(string $string, string $key) : string + + decrypt(string $string, string $key) : string + # getExpandedKey(string $key, int $blockSize, ...) : string + # resizeKey(string $key, int $size) : ?string +} + +note right of FOF::__construct + Constructor + + since: 3.2.0 +end note + +note right of FOF::encrypt + Encrypt a string as needed + + since: 3.2.0 + return: string +end note + +note right of FOF::decrypt + Decrypt a string as needed + + since: 3.2.0 + return: string +end note + +note right of FOF::getExpandedKey + Function taken from FOFEncryptAes +changed a little but basically the same +to ensure we get the same passwords (not ideal) +we should use `$this->aes->setPassword(...)` instead +but can't for backwards compatibility issues with already encrypted string + + since: 3.2.0 + return: string + + arguments: + string $key + int $blockSize + string $iv +end note + +note right of FOF::resizeKey + Function taken from FOFEncryptAes +changed a little but basically the same +to ensure we get the same passwords (not ideal) +we should use `$this->aes->setPassword(...)` instead +but can't for backwards compatibility issues with already encrypted string + + since: 3.2.0 + return: ?string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php new file mode 100644 index 0000000..f6493d8 --- /dev/null +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php @@ -0,0 +1,204 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt; + + +use phpseclib3\Crypt\AES; +use VDM\Joomla\Componentbuilder\Crypt\Random; +use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; + + +/** + * Replacement Class for FOFEncryptAes + * + * @since 3.2.0 + */ +class FOF implements Cryptinterface +{ + /** + * The Aes class + * + * @var AES + * @since 3.2.0 + */ + protected AES $aes; + + /** + * The Random class + * + * @var Random + * @since 3.2.0 + */ + protected Random $random; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 128; + + /** + * Constructor + * + * @param AES $aes The Aes class + * @param Random $random The Random class + * + * @since 3.2.0 + */ + public function __construct(AES $aes, Random $random) + { + $this->aes = $aes; + $this->random = $random; + + // we set the length once + $this->aes->setKeyLength($this->size); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = $this->random::string($iv_length); + // Load the IV + $this->aes->setIV($iv); + + // load the key + $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); + + // encrypt the string, and base 64 encode the result + return base64_encode($iv . $this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // remove base 64 encoding + $string = base64_decode($string); + + // get the IV + $iv = substr($string, 0, $iv_length); + // remove the IV + $string = substr($string, $iv_length); + + // set the key + $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); + + // set the IV + $this->aes->setIV($iv); + + return $this->aes->decrypt($string); + } + + /** + * Function taken from FOFEncryptAes + * changed a little but basically the same + * to ensure we get the same passwords (not ideal) + * we should use `$this->aes->setPassword(...)` instead + * but can't for backwards compatibility issues with already encrypted string + * + * @param string $key The key to expand + * @param int $blockSize The size of the block + * @param string $iv The IV used + * + * @return string + * @since 3.2.0 + */ + protected function getExpandedKey(string $key, int $blockSize, string $iv): string + { + $pass_length = strlen($key); + + if (function_exists('mb_strlen')) + { + $pass_length = mb_strlen($key, 'ASCII'); + } + + if ($pass_length != $blockSize) + { + $iterations = 1000; + $salt = $this->resizeKey($iv, 16); + $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $blockSize, true); + } + + return $key; + } + + /** + * Function taken from FOFEncryptAes + * changed a little but basically the same + * to ensure we get the same passwords (not ideal) + * we should use `$this->aes->setPassword(...)` instead + * but can't for backwards compatibility issues with already encrypted string + * + * @param string $key The key to resize + * @param int $size The size of the block + * + * @return string|null + * @since 3.2.0 + */ + protected function resizeKey(string $key, int $size): ?string + { + if (empty($key)) + { + return null; + } + + $key_length = strlen($key); + + if (function_exists('mb_strlen')) + { + $key_length = mb_strlen($key, 'ASCII'); + } + + if ($key_length == $size) + { + return $key; + } + + if ($key_length > $size) + { + if (function_exists('mb_substr')) + { + return mb_substr($key, 0, $size, 'ASCII'); + } + + return substr($key, 0, $size); + } + + return $key . str_repeat("\0", ($size - $key_length)); + } + +} + diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power new file mode 100644 index 0000000..3438b56 --- /dev/null +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power @@ -0,0 +1,175 @@ + /** + * The Aes class + * + * @var AES + * @since 3.2.0 + */ + protected AES $aes; + + /** + * The Random class + * + * @var Random + * @since 3.2.0 + */ + protected Random $random; + + /** + * The block size + * + * @var int + * @since 3.2.0 + */ + protected int $size = 128; + + /** + * Constructor + * + * @param AES $aes The Aes class + * @param Random $random The Random class + * + * @since 3.2.0 + */ + public function __construct(AES $aes, Random $random) + { + $this->aes = $aes; + $this->random = $random; + + // we set the length once + $this->aes->setKeyLength($this->size); + } + + /** + * Encrypt a string as needed + * + * @param string $string The string to encrypt + * @param string $key The encryption key + * + * @return string + * @since 3.2.0 + **/ + public function encrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // get the IV value + $iv = $this->random::string($iv_length); + // Load the IV + $this->aes->setIV($iv); + + // load the key + $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); + + // encrypt the string, and base 64 encode the result + return base64_encode($iv . $this->aes->encrypt($string)); + } + + /** + * Decrypt a string as needed + * + * @param string $string The string to decrypt + * @param string $key The decryption key + * + * @return string + * @since 3.2.0 + **/ + public function decrypt(string $string, string $key): string + { + // we get the IV length + $iv_length = (int) $this->aes->getBlockLength() >> 3; + + // remove base 64 encoding + $string = base64_decode($string); + + // get the IV + $iv = substr($string, 0, $iv_length); + // remove the IV + $string = substr($string, $iv_length); + + // set the key + $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); + + // set the IV + $this->aes->setIV($iv); + + return $this->aes->decrypt($string); + } + + /** + * Function taken from FOFEncryptAes + * changed a little but basically the same + * to ensure we get the same passwords (not ideal) + * we should use `$this->aes->setPassword(...)` instead + * but can't for backwards compatibility issues with already encrypted string + * + * @param string $key The key to expand + * @param int $blockSize The size of the block + * @param string $iv The IV used + * + * @return string + * @since 3.2.0 + */ + protected function getExpandedKey(string $key, int $blockSize, string $iv): string + { + $pass_length = strlen($key); + + if (function_exists('mb_strlen')) + { + $pass_length = mb_strlen($key, 'ASCII'); + } + + if ($pass_length != $blockSize) + { + $iterations = 1000; + $salt = $this->resizeKey($iv, 16); + $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $blockSize, true); + } + + return $key; + } + + /** + * Function taken from FOFEncryptAes + * changed a little but basically the same + * to ensure we get the same passwords (not ideal) + * we should use `$this->aes->setPassword(...)` instead + * but can't for backwards compatibility issues with already encrypted string + * + * @param string $key The key to resize + * @param int $size The size of the block + * + * @return string|null + * @since 3.2.0 + */ + protected function resizeKey(string $key, int $size): ?string + { + if (empty($key)) + { + return null; + } + + $key_length = strlen($key); + + if (function_exists('mb_strlen')) + { + $key_length = mb_strlen($key, 'ASCII'); + } + + if ($key_length == $size) + { + return $key; + } + + if ($key_length > $size) + { + if (function_exists('mb_substr')) + { + return mb_substr($key, 0, $size, 'ASCII'); + } + + return substr($key, 0, $size); + } + + return $key . str_repeat("\0", ($size - $key_length)); + } diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json new file mode 100644 index 0000000..1cf7e3e --- /dev/null +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json @@ -0,0 +1,34 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "e98b4edc-25b9-49d7-98a0-e42ad3b75efe", + "implements": [ + "81de8f57-dd9c-4a17-964f-848cd4a0743b" + ], + "load_selection": null, + "name": "FOF", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.FOF", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.FOF", + "description": "Replacement Class for FOFEncryptAes\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": { + "composer0": { + "access_point": "phpseclib3\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "phpseclib3\\Crypt\\AES" + } + } + } + } +} \ No newline at end of file diff --git a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md new file mode 100644 index 0000000..e13b232 --- /dev/null +++ b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md @@ -0,0 +1,85 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Load (Details) +> namespace: **VDM\Joomla\Componentbuilder\Server\Model** +```uml +@startuml +class Load #Gold { + # Crypt $crypt + + __construct(?Crypt $crypt = null, ?Table $table = null) + + value(mixed $value, string $field, ...) : mixed + # validateBefore(mixed $value, ?string $field = null, ...) : bool + # validateAfter(mixed $value, ?string $field = null, ...) : bool + # getTable() : string +} + +note right of Load::__construct + Constructor + + since: 3.2.0 +end note + +note right of Load::value + Model the value +Example: $this->value(value, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + mixed $value + string $field + ?string $table = null +end note + +note right of Load::validateBefore + Validate before the value is modelled + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Load::validateAfter + Validate after the value is modelled + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Load::getTable + Get the current active table + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.php b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.php new file mode 100644 index 0000000..2a8553c --- /dev/null +++ b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.php @@ -0,0 +1,153 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Server\Model; + + +use Joomla\Registry\Registry; +use VDM\Joomla\Componentbuilder\Compiler\Factory; +use VDM\Joomla\Componentbuilder\Crypt; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\JsonHelper; +use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface; +use VDM\Joomla\Componentbuilder\Abstraction\Model; + + +/** + * Server Model Load Class + * + * @since 3.2.0 + */ +class Load extends Model implements ModelInterface +{ + /** + * Decryption Class + * + * @var Crypt + * @since 3.2.0 + */ + protected Crypt $crypt; + + /** + * Constructor + * + * @param Crypt|null $crypt The core crypt object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Crypt $crypt = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->crypt = $crypt ?: Factory::_('Crypt'); + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'basic_encryption': + $value = $this->crypt->decrypt($value, 'basic'); + break; + case 'medium_encryption': + $value = $this->crypt->decrypt($value, 'medium'); + break; + case 'base64': + $value = base64_decode((string) $value); + break; + case 'json': + // check if there is a json string + if (JsonHelper::check($value)) + { + $registry = new Registry; + $registry->loadString($value); + $value = $registry->toArray(); + } + break; + default: + if ($this->crypt->exist($store)) + { + $value = $this->crypt->decrypt($value, $store); + } + break; + } + } + + return $value; + } + + /** + * Validate before the value is modelled + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + // remove none + return true; + } + + /** + * Validate after the value is modelled + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return 'server'; + } + +} + diff --git a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.power b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.power new file mode 100644 index 0000000..46c4e3f --- /dev/null +++ b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/code.power @@ -0,0 +1,119 @@ + /** + * Decryption Class + * + * @var Crypt + * @since 3.2.0 + */ + protected Crypt $crypt; + + /** + * Constructor + * + * @param Crypt|null $crypt The core crypt object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Crypt $crypt = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->crypt = $crypt ?: Factory::_('Crypt'); + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'basic_encryption': + $value = $this->crypt->decrypt($value, 'basic'); + break; + case 'medium_encryption': + $value = $this->crypt->decrypt($value, 'medium'); + break; + case 'base64': + $value = base64_decode((string) $value); + break; + case 'json': + // check if there is a json string + if (JsonHelper::check($value)) + { + $registry = new Registry; + $registry->loadString($value); + $value = $registry->toArray(); + } + break; + default: + if ($this->crypt->exist($store)) + { + $value = $this->crypt->decrypt($value, $store); + } + break; + } + } + + return $value; + } + + /** + * Validate before the value is modelled + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + // remove none + return true; + } + + /** + * Validate after the value is modelled + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return 'server'; + } diff --git a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/settings.json b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/settings.json new file mode 100644 index 0000000..f2d46e4 --- /dev/null +++ b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "584747d1-3a86-453d-b7a3-a2219de8d777", + "guid": "f37ee8b7-2909-4319-bdf8-769bd7635490", + "implements": [ + "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff" + ], + "load_selection": null, + "name": "Load", + "power_version": "1.0.0", + "system_name": "JCB.Server.Model.Load", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac", + "as": "default" + }, + "use_selection1": { + "use": "d357e796-9f22-4615-9ebc-970b42cbd280", + "as": "default" + }, + "use_selection2": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection3": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection4": { + "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Server.Model.Load", + "description": "Server Model Load Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\Registry\\Registry;", + "composer": "" +} \ No newline at end of file diff --git a/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/README.md b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/README.md new file mode 100644 index 0000000..8cf3925 --- /dev/null +++ b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/README.md @@ -0,0 +1,46 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Password (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt** +```uml +@startuml +class Password #Gold { + + get(string $type, ?string $default = null) : ?string + - local() : string +} + +note right of Password::get + Get the type of password +Example: $this->get('basic', 'default-password'); + + since: 3.2.0 + return: ?string +end note + +note right of Password::local + Get the local password + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.php b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.php new file mode 100644 index 0000000..de5e790 --- /dev/null +++ b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.php @@ -0,0 +1,68 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Crypt; + + +use Joomla\CMS\Language\Text; +use VDM\Joomla\Utilities\Component\Helper; + + +/** + * Password Class + * + * @since 3.2.0 + */ +class Password +{ + /** + * Get the type of password + * Example: $this->get('basic', 'default-password'); + * + * @param string $type The value of password to get + * @param string|null $default The default password if the type is not found + * + * @return string|null + * @since 3.2.0 + */ + public function get(string $type, ?string $default = null): ?string + { + // we have a local key for JCB only use + if ('local' === $type) + { + return $this->local(); + } + elseif (($password = Helper::_('getCryptKey', [$type, $default])) !== null) + { + return $password; + } + + return $default; + } + + /** + * Get the local password + * + * @return string + * @since 3.2.0 + */ + private function local(): string + { + return base64_decode( + Text::sprintf( + 'COM_COMPONENTBUILDER_VJRZDESSMHBTRWFIFTYTWVZEROAESFLVVXJTMTHREEJTWOIXM', + 'QzdmV', '9kQ' + ) + ); + } + +} + diff --git a/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.power b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.power new file mode 100644 index 0000000..1d8803b --- /dev/null +++ b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/code.power @@ -0,0 +1,40 @@ + /** + * Get the type of password + * Example: $this->get('basic', 'default-password'); + * + * @param string $type The value of password to get + * @param string|null $default The default password if the type is not found + * + * @return string|null + * @since 3.2.0 + */ + public function get(string $type, ?string $default = null): ?string + { + // we have a local key for JCB only use + if ('local' === $type) + { + return $this->local(); + } + elseif (($password = Helper::_('getCryptKey', [$type, $default])) !== null) + { + return $password; + } + + return $default; + } + + /** + * Get the local password + * + * @return string + * @since 3.2.0 + */ + private function local(): string + { + return base64_decode( + Text::sprintf( + JustTEXT::_('VjRzdE%ssMHBtRW50TWV0aE%sFlvVXJTM3J2IXM='), + 'QzdmV', '9kQ' + ) + ); + } diff --git a/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/settings.json b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/settings.json new file mode 100644 index 0000000..9185db8 --- /dev/null +++ b/src/fea2b107-3ee4-4ebf-84be-d3f2829c8614/settings.json @@ -0,0 +1,23 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "fea2b107-3ee4-4ebf-84be-d3f2829c8614", + "implements": null, + "load_selection": null, + "name": "Password", + "power_version": "1.0.0", + "system_name": "JCB.Crypt.Password", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.Password", + "description": "Password Class\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Language\\Text;", + "composer": "" +} \ No newline at end of file diff --git a/super-powers.json b/super-powers.json new file mode 100644 index 0000000..474f3f9 --- /dev/null +++ b/super-powers.json @@ -0,0 +1,142 @@ +{ + "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c": { + "name": "Random", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt", + "code": "src\/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c\/code.php", + "power": "src\/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c\/code.power", + "settings": "src\/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c\/settings.json", + "path": "src\/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "guid": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c" + }, + "e98b4edc-25b9-49d7-98a0-e42ad3b75efe": { + "name": "FOF", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt", + "code": "src\/e98b4edc-25b9-49d7-98a0-e42ad3b75efe\/code.php", + "power": "src\/e98b4edc-25b9-49d7-98a0-e42ad3b75efe\/code.power", + "settings": "src\/e98b4edc-25b9-49d7-98a0-e42ad3b75efe\/settings.json", + "path": "src\/e98b4edc-25b9-49d7-98a0-e42ad3b75efe", + "guid": "e98b4edc-25b9-49d7-98a0-e42ad3b75efe" + }, + "a25c82c8-14c2-40df-adae-f832709ab49b": { + "name": "Aes", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt", + "code": "src\/a25c82c8-14c2-40df-adae-f832709ab49b\/code.php", + "power": "src\/a25c82c8-14c2-40df-adae-f832709ab49b\/code.power", + "settings": "src\/a25c82c8-14c2-40df-adae-f832709ab49b\/settings.json", + "path": "src\/a25c82c8-14c2-40df-adae-f832709ab49b", + "guid": "a25c82c8-14c2-40df-adae-f832709ab49b" + }, + "437af6b0-ca02-49d7-8739-4edfc8a9ccb0": { + "name": "Legacy", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt\\Aes", + "code": "src\/437af6b0-ca02-49d7-8739-4edfc8a9ccb0\/code.php", + "power": "src\/437af6b0-ca02-49d7-8739-4edfc8a9ccb0\/code.power", + "settings": "src\/437af6b0-ca02-49d7-8739-4edfc8a9ccb0\/settings.json", + "path": "src\/437af6b0-ca02-49d7-8739-4edfc8a9ccb0", + "guid": "437af6b0-ca02-49d7-8739-4edfc8a9ccb0" + }, + "fea2b107-3ee4-4ebf-84be-d3f2829c8614": { + "name": "Password", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt", + "code": "src\/fea2b107-3ee4-4ebf-84be-d3f2829c8614\/code.php", + "power": "src\/fea2b107-3ee4-4ebf-84be-d3f2829c8614\/code.power", + "settings": "src\/fea2b107-3ee4-4ebf-84be-d3f2829c8614\/settings.json", + "path": "src\/fea2b107-3ee4-4ebf-84be-d3f2829c8614", + "guid": "fea2b107-3ee4-4ebf-84be-d3f2829c8614" + }, + "d357e796-9f22-4615-9ebc-970b42cbd280": { + "name": "Crypt", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder", + "code": "src\/d357e796-9f22-4615-9ebc-970b42cbd280\/code.php", + "power": "src\/d357e796-9f22-4615-9ebc-970b42cbd280\/code.power", + "settings": "src\/d357e796-9f22-4615-9ebc-970b42cbd280\/settings.json", + "path": "src\/d357e796-9f22-4615-9ebc-970b42cbd280", + "guid": "d357e796-9f22-4615-9ebc-970b42cbd280" + }, + "6da44dff-a221-4f22-b9d9-b2fc2a724b4b": { + "name": "KeyLoader", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Crypt", + "code": "src\/6da44dff-a221-4f22-b9d9-b2fc2a724b4b\/code.php", + "power": "src\/6da44dff-a221-4f22-b9d9-b2fc2a724b4b\/code.power", + "settings": "src\/6da44dff-a221-4f22-b9d9-b2fc2a724b4b\/settings.json", + "path": "src\/6da44dff-a221-4f22-b9d9-b2fc2a724b4b", + "guid": "6da44dff-a221-4f22-b9d9-b2fc2a724b4b" + }, + "4d8f38ef-8f3a-463d-8678-0bf087ac6815": { + "name": "Crypt", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Service", + "code": "src\/4d8f38ef-8f3a-463d-8678-0bf087ac6815\/code.php", + "power": "src\/4d8f38ef-8f3a-463d-8678-0bf087ac6815\/code.power", + "settings": "src\/4d8f38ef-8f3a-463d-8678-0bf087ac6815\/settings.json", + "path": "src\/4d8f38ef-8f3a-463d-8678-0bf087ac6815", + "guid": "4d8f38ef-8f3a-463d-8678-0bf087ac6815" + }, + "f37ee8b7-2909-4319-bdf8-769bd7635490": { + "name": "Load", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Server\\Model", + "code": "src\/f37ee8b7-2909-4319-bdf8-769bd7635490\/code.php", + "power": "src\/f37ee8b7-2909-4319-bdf8-769bd7635490\/code.power", + "settings": "src\/f37ee8b7-2909-4319-bdf8-769bd7635490\/settings.json", + "path": "src\/f37ee8b7-2909-4319-bdf8-769bd7635490", + "guid": "f37ee8b7-2909-4319-bdf8-769bd7635490" + }, + "a3414824-e99d-4878-b3d1-b5deef0cae17": { + "name": "Load", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Server", + "code": "src\/a3414824-e99d-4878-b3d1-b5deef0cae17\/code.php", + "power": "src\/a3414824-e99d-4878-b3d1-b5deef0cae17\/code.power", + "settings": "src\/a3414824-e99d-4878-b3d1-b5deef0cae17\/settings.json", + "path": "src\/a3414824-e99d-4878-b3d1-b5deef0cae17", + "guid": "a3414824-e99d-4878-b3d1-b5deef0cae17" + }, + "11be6be3-ee3e-4771-8663-5545b76b73ab": { + "name": "Ftp", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Server", + "code": "src\/11be6be3-ee3e-4771-8663-5545b76b73ab\/code.php", + "power": "src\/11be6be3-ee3e-4771-8663-5545b76b73ab\/code.power", + "settings": "src\/11be6be3-ee3e-4771-8663-5545b76b73ab\/settings.json", + "path": "src\/11be6be3-ee3e-4771-8663-5545b76b73ab", + "guid": "11be6be3-ee3e-4771-8663-5545b76b73ab" + }, + "490b6aa5-5de7-4be5-a61a-f634f6e004c0": { + "name": "Sftp", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Server", + "code": "src\/490b6aa5-5de7-4be5-a61a-f634f6e004c0\/code.php", + "power": "src\/490b6aa5-5de7-4be5-a61a-f634f6e004c0\/code.power", + "settings": "src\/490b6aa5-5de7-4be5-a61a-f634f6e004c0\/settings.json", + "path": "src\/490b6aa5-5de7-4be5-a61a-f634f6e004c0", + "guid": "490b6aa5-5de7-4be5-a61a-f634f6e004c0" + }, + "66355f70-c26c-4765-ba48-498e3df740ef": { + "name": "Server", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder", + "code": "src\/66355f70-c26c-4765-ba48-498e3df740ef\/code.php", + "power": "src\/66355f70-c26c-4765-ba48-498e3df740ef\/code.power", + "settings": "src\/66355f70-c26c-4765-ba48-498e3df740ef\/settings.json", + "path": "src\/66355f70-c26c-4765-ba48-498e3df740ef", + "guid": "66355f70-c26c-4765-ba48-498e3df740ef" + }, + "42ceff0b-226d-42ff-9ffa-3d5935890337": { + "name": "Server", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Service", + "code": "src\/42ceff0b-226d-42ff-9ffa-3d5935890337\/code.php", + "power": "src\/42ceff0b-226d-42ff-9ffa-3d5935890337\/code.power", + "settings": "src\/42ceff0b-226d-42ff-9ffa-3d5935890337\/settings.json", + "path": "src\/42ceff0b-226d-42ff-9ffa-3d5935890337", + "guid": "42ceff0b-226d-42ff-9ffa-3d5935890337" + } +} \ No newline at end of file