first commit

This commit is contained in:
Llewellyn van der Merwe 2023-04-15 17:00:08 +02:00
commit ada2db7bc7
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
58 changed files with 5336 additions and 0 deletions

274
README.md Normal file
View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,153 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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;
}
}

View File

@ -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;
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -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)

View File

@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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')
);
}
}

View File

@ -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')
);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -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)

View File

@ -0,0 +1,117 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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);
}
}

View File

@ -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);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,199 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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;
}
}

View File

@ -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;
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,187 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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')
);
}
}

View File

@ -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')
);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,165 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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);
}
}

View File

@ -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);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -0,0 +1,21 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
> Error adding class diagram
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,26 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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
{
}

View File

@ -0,0 +1 @@
###CODEPOWER###

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,131 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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);
}
}

View File

@ -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);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,122 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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;
}
}

View File

@ -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;
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -0,0 +1,21 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
> Error adding class diagram
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,26 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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
{
}

View File

@ -0,0 +1 @@
###CODEPOWER###

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,285 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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;
}
}

View File

@ -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;
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -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)

View File

@ -0,0 +1,204 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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));
}
}

View File

@ -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));
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
}
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,153 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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';
}
}

View File

@ -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';
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

View File

@ -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)

View File

@ -0,0 +1,68 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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'
)
);
}
}

View File

@ -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'
)
);
}

View File

@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
}

142
super-powers.json Normal file
View File

@ -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"
}
}