Release of v5.0.0-alpha8

Add power path override option on component level. Fix the sql build feature. #1032.
This commit is contained in:
2024-04-06 23:41:34 +02:00
parent 2f64eec95b
commit 2b7b8f90e1
762 changed files with 1900 additions and 1246 deletions

View File

@@ -0,0 +1,154 @@
<?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 array of variables
$signature = [];
parse_str((string) $this->details->signature, $signature);
// set options
if (isset($signature['options']) && ArrayHelper::check($signature['options']))
{
foreach ($signature['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($signature['host']) && $signature['host'] != 'HOSTNAME' &&
isset($signature['port']) && $signature['port'] != 'PORT_INT' &&
isset($signature['username']) && $signature['username'] != 'user@name.com' &&
isset($signature['password']) && $signature['password'] != 'password')
{
// this is a singleton
return FtpClient::getInstance($host, $port, $options, $username, $password);
}
}
return null;
}
}

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\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,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\Interfaces\ModelInterface;
use VDM\Joomla\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 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,271 @@
<?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\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Application\CMSApplication;
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;
/**
* Application object.
*
* @var CMSApplication
* @since 3.2.0
**/
protected CMSApplication $app;
/**
* Constructor
*
* @param KeyLoader $key The key loader object.
* @param CMSApplication|null $app The app object.
*
* @since 3.2.0
*/
public function __construct(KeyLoader $key, ?CMSApplication $app = null)
{
$this->key = $key;
$this->app = $app ?: Factory::getApplication();
}
/**
* 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);
$path = '/' . trim($path, '/') . '/';
}
try
{
return $this->client->put($path . trim($fileName), $data);
}
catch(\Exception $e)
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_MOVING_OF_THE_S_FAILED', $fileName) . ': ' . $e->getMessage(),
'Error'
);
}
}
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 = (int)($this->details->port ?? 22);
// open the connection
$sftp = new SftpClient($this->details->host, $port);
// set the passphrase if it exist
$passphrase = (isset($this->details->secret) && StringHelper::check(trim($this->details->secret))) ? trim($this->details->secret) : false;
// set the password if it exist
$password = (isset($this->details->password) && StringHelper::check(trim($this->details->password))) ? trim($this->details->password) : false;
// now login based on authentication type
$key = null;
switch($this->details->authentication)
{
case 1: // password
$key = $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)
{
try
{
$key = $this->key::load(trim($private_key), $passphrase);
}
catch(\Exception $e)
{
$this->app->enqueueMessage(
Text::_('COM_COMPONENTBUILDER_LOADING_THE_PRIVATE_KEY_FILE_FAILED') . ': ' . $e->getMessage(),
'Error'
);
$key = null;
}
}
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))
{
try
{
$key = $this->key::load(trim($this->details->private_key), $passphrase);
}
catch(\Exception $e)
{
$this->app->enqueueMessage(
Text::_('COM_COMPONENTBUILDER_LOADING_THE_PRIVATE_KEY_TEXT_FAILED') . ': ' . $e->getMessage(),
'Error'
);
$key = null;
}
}
break;
}
// remove any null bites from the username
$this->details->username = trim($this->details->username);
// login
if (!empty($key) && !empty($password))
{
try
{
$sftp->login($this->details->username, $key, $password);
return $sftp;
}
catch(\Exception $e)
{
$this->app->enqueueMessage(
Text::_('COM_COMPONENTBUILDER_LOGIN_FAILED') . ': ' . $e->getMessage(),
'Error'
);
}
}
elseif (!empty($key))
{
try
{
$sftp->login($this->details->username, $key);
return $sftp;
}
catch(\Exception $e)
{
$this->app->enqueueMessage(
Text::_('COM_COMPONENTBUILDER_LOGIN_FAILED') . ': ' . $e->getMessage(),
'Error'
);
}
}
}
return null;
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>