LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
C:/Develope/SVN/upload/framework/classes/lepton_secure_database.php

Public "shortcut" for executing a single mySql-query without passing values.

Parameters
string$aQueryA valid mySQL query.
bool$bFetchFetch the result - default is false.
array$aStorageA storage array for the fetched results. Pass by reference!
bool$bFetchAllTry to get all entries. Default is true.
array$aListOfFieldsA linear array with the fieldnames to de-crypt.
Returns
bool False if fails, otherwise true.

$results_array = array();
$this->db_handle->execute_query( "SELECT * from ".TABLE_PREFIX."pages WHERE page_id = ".$page_id." ", true, $results_array, false, array('modify_by') );

<?php
declare(strict_types=1);
{
static private string $db_key = "";
static private string $default_openssl_method = "";
static private string $default_openssl_iv = "";
static private string $default_openssl_ivlen = "";
static private int $default_openssl_options = 0;
protected function cryptString(string $sSource=""): string|bool
{
if( "" === self::$default_openssl_method )
{
echo LEPTON_tools::display("UNABLE to crypt source! Keep source untouched.", "pre", "ui message red");
return $sSource;
}
return openssl_encrypt(
$sSource,
self::$default_openssl_method,
self::$db_key,
self::$default_openssl_options,
self::$default_openssl_iv
);
}
protected function decryptString(string $sSource): string|bool
{
if( "" === self::$default_openssl_method )
{
return $sSource;
}
return openssl_decrypt(
$sSource,
self::$default_openssl_method,
self::$db_key,
self::$default_openssl_options,
self::$default_openssl_iv
);
}
public function setOpenSSLMethod(string $sMethodName): void
{
self::$default_openssl_method = $sMethodName;
}
public function setOpenSSLIv(string $sNewIV): void
{
self::$default_openssl_iv = $sNewIV;
}
public function secure_get_one(string $SQL): string|null
{
$result = $this->get_one($SQL);
return (is_null($result))
? NULL
: $this->decryptString( $result )
;
}
public function secure_execute_query(
string $aQuery = "",
bool $bFetch = false,
array &$aStorage = array(),
bool $bFetchAll = true,
array $aListOfFields = array()
): bool
{
if (!is_array($aListOfFields))
{
LEPTON_tools::display("REQUIRED list of fieldnames must be an array!", "div", "ui message red");
return false;
}
$result = $this->execute_query(
$aQuery,
$bFetch,
$aStorage,
$bFetchAll
);
if (false === $result)
{
LEPTON_tools::display($this->get_error(), "div", "ui message red");
return false;
}
if (true === $bFetchAll)
{
foreach ($aStorage as &$ref)
{
foreach ($aListOfFields as $sFieldname)
{
if (isset($ref[$sFieldname]))
{
$ref[$sFieldname] = $this->decryptString($ref[$sFieldname]);
}
}
}
} else {
foreach ($aListOfFields as $sFieldname)
{
if (isset($aStorage[$sFieldname]))
{
$aStorage[$sFieldname] = $this->decryptString($aStorage[$sFieldname]);
}
}
}
return true;
}
public function secure_build_and_execute(
string $type,
string $table_name,
array $table_values = [] ,
string $condition = "",
array $aListOfFields = [],
string $key=""
): int
{
if (!is_array($aListOfFields))
{
LEPTON_tools::display("REQUIRED list of fieldnames must be an array!", "div", "ui message red");
return 0;
}
foreach ($aListOfFields as $sName)
{
if (isset($table_values[$sName]))
{
$table_values[ $sName ] = $this->cryptString( $table_values[ $sName ] );
}
}
return $this->build_and_execute(
$type,
$table_name,
$table_values,
$condition,
$key
);
}
public static function __callStatic($method, $args)
{
switch (strtolower($method))
{
case 'cryptstring':
return self::$instance->cryptString($args[0]);
break;
case 'decryptstring':
return self::$instance->decryptString($args[0]);
break;
default:
echo LEPTON_tools::display("Static call to unknown method!", "pre", "ui message red");
return NULL;
break;
}
}
}
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
setOpenSSLIv(string $sNewIV)
secure_execute_query(string $aQuery="", bool $bFetch=false, array &$aStorage=array(), bool $bFetchAll=true, array $aListOfFields=array())
cryptString(string $sSource="")
secure_build_and_execute(string $type, string $table_name, array $table_values=[], string $condition="", array $aListOfFields=[], string $key="")
trait LEPTON_secure_database
secure_get_one(string $SQL)
decryptString(string $sSource)
setOpenSSLMethod(string $sMethodName)