Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc105f9295 | ||
|
|
053ab69330 | ||
|
|
fd079316f5 | ||
|
|
08664e9834 | ||
|
|
e063162161 | ||
|
|
7fbc449a5c | ||
|
|
72912c8c90 | ||
|
|
de2ed8be3d | ||
|
|
9d65f5d7c1 | ||
|
|
fbe827e989 | ||
|
|
c778a4eb81 |
@@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phive xmlns="https://phar.io/phive">
|
<phive xmlns="https://phar.io/phive">
|
||||||
<phar name="phpunit" version="^9.6" installed="9.6.21" location="./tools/phpunit" copy="false"/>
|
<phar name="phpunit" version="^10.3.5" installed="10.3.5" location="./tools/phpunit" copy="false"/>
|
||||||
<phar name="phpcbf" version="^3.7.2" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
|
<phar name="phpcbf" version="^3.7.2" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
|
||||||
<phar name="phpcs" version="^3.7.2" installed="3.10.3" location="./tools/phpcs" copy="false"/>
|
<phar name="phpcs" version="^3.10.3" installed="3.10.3" location="./tools/phpcs" copy="false"/>
|
||||||
<phar name="phpstan" version="^1.10.37" installed="1.12.4" location="./tools/phpstan" copy="false"/>
|
<phar name="phpstan" version="^2.0" installed="2.0.4" location="./tools/phpstan" copy="false"/>
|
||||||
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
|
<phar name="phan" version="^5.4.3" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||||
<phar name="psalm" version="^5.15.0" installed="5.24.0" location="./tools/psalm" copy="false"/>
|
<phar name="psalm" version="^5.15.0" installed="5.24.0" location="./tools/psalm" copy="false"/>
|
||||||
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
||||||
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
# must be run in ${base}
|
# must be run in ${base}
|
||||||
cd $base;
|
cd $base || exit;
|
||||||
${base}tools/phan --progress-bar -C --analyze-twice;
|
${base}tools/phan --progress-bar -C --analyze-twice;
|
||||||
cd ~;
|
cd ~ || exit;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
# must be run in ${base}
|
# must be run in ${base}
|
||||||
cd $base;
|
cd $base || exit;
|
||||||
${base}tools/phpstan;
|
${base}tools/phpstan;
|
||||||
cd ~;
|
cd ~ || exit;
|
||||||
|
|||||||
@@ -1,49 +1,96 @@
|
|||||||
#!/bin/env bash
|
#!/bin/env bash
|
||||||
|
|
||||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
function error() {
|
||||||
|
if [ -t 1 ]; then echo "[MAK] ERROR: $*" >&2; fi; exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-t] [-v] [-p VERSION]
|
||||||
|
|
||||||
|
Runs all the PHP unit tests.
|
||||||
|
|
||||||
|
If -p is not set, the default intalled PHP is used.
|
||||||
|
|
||||||
|
Available options:
|
||||||
|
|
||||||
|
-h, --help Print this help and exit
|
||||||
|
-t, --testdox Enable testdox output for phpunit
|
||||||
|
-v, --verbose Enable verbose output for PHPunit
|
||||||
|
-p, --php VERSION Chose PHP version in the form of "N.N", if not found will exit
|
||||||
|
EOF
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# set base variables
|
||||||
|
BASE_PATH="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||||
|
PHPUNIT_CONFIG="${BASE_PATH}phpunit.xml";
|
||||||
|
PHP_BIN_PATH=$(which php);
|
||||||
|
if [ -z "${PHP_BIN_PATH}" ]; then
|
||||||
|
echo "Cannot find php binary";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
DEFAULT_PHP_VERSION=$(${PHP_BIN_PATH} -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;");
|
||||||
|
if [ -z "${DEFAULT_PHP_VERSION}" ]; then
|
||||||
|
echo "Cannot set default PHP version";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
# -c phpunit.xml
|
# -c phpunit.xml
|
||||||
# --testdox
|
# --testdox
|
||||||
# call with "t" to give verbose testdox output
|
# call with "-tt" to give verbose testdox output
|
||||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||||
# call with php version number to force a certain php version
|
# call with -p <php version number> to force a certain php version
|
||||||
|
|
||||||
opt_testdox="";
|
opt_testdox="";
|
||||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
opt_verbose="";
|
||||||
opt_testdox="--testdox";
|
php_version="";
|
||||||
fi;
|
no_php_version=0;
|
||||||
php_bin="";
|
while [ -n "${1-}" ]; do
|
||||||
if [ -n "${1}" ]; then
|
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
-t | --testdox)
|
||||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
opt_testdox="--testdox";
|
||||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
;;
|
||||||
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
-v | --verbose)
|
||||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
opt_verbose="--verbose";
|
||||||
"8.3") php_bin="/usr/bin/php8.4 "; ;;
|
;;
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
-p | --php)
|
||||||
esac;
|
php_version="${2-}";
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
# invalid option
|
||||||
|
-?*)
|
||||||
|
error "[!] Unknown option: '$1'."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift;
|
||||||
|
done;
|
||||||
|
|
||||||
|
if [ -z "${php_version}" ]; then
|
||||||
|
php_version="${DEFAULT_PHP_VERSION}";
|
||||||
|
no_php_version=1;
|
||||||
fi;
|
fi;
|
||||||
if [ -n "${2}" ] && [ -z "${php_bin}" ]; then
|
php_bin="${PHP_BIN_PATH}${php_version}";
|
||||||
case "${2}" in
|
echo "Use PHP Version: ${php_version}";
|
||||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
|
||||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
if [ ! -f "${php_bin}" ]; then
|
||||||
# "8.0") php_bin="/usr/bin/php8.0 "; ;;
|
echo "Set php ${php_bin} does not exist";
|
||||||
# "8.1") php_bin="/usr/bin/php8.1 "; ;;
|
exit;
|
||||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
|
||||||
"8.3") php_bin="/usr/bin/php8.3 "; ;;
|
|
||||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
|
||||||
esac;
|
|
||||||
fi;
|
fi;
|
||||||
|
php_bin="${php_bin} ";
|
||||||
|
|
||||||
# Note 4dev/tests/bootstrap.php has to be set as bootstrap file in phpunit.xml
|
# Note 4dev/tests/bootstrap.php has to be set as bootstrap file in phpunit.xml
|
||||||
phpunit_call="${php_bin}${base}vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
phpunit_call="${php_bin}${BASE_PATH}vendor/bin/phpunit ${opt_testdox} ${opt_verbose} -c ${PHPUNIT_CONFIG} ${BASE_PATH}4dev/tests/";
|
||||||
|
|
||||||
${phpunit_call};
|
${phpunit_call};
|
||||||
|
|
||||||
if [ ! -z "${php_bin}" ]; then
|
echo -e "\nPHPUnit Config: ${PHPUNIT_CONFIG}";
|
||||||
echo "CALLED WITH PHP: ${php_bin}"$(${php_bin} --version);
|
if [ "${no_php_version}" -eq 0 ]; then
|
||||||
|
echo "CALLED WITH PHP: ${php_bin}$(${php_bin} --version)";
|
||||||
else
|
else
|
||||||
echo "Default PHP used: "$(php --version);
|
echo "Default PHP used: $(php --version)";
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
# __END__
|
# __END__
|
||||||
|
|||||||
@@ -1531,6 +1531,12 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_uid']),
|
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_uid']),
|
||||||
'Assert check access uid to cuid valid'
|
'Assert check access uid to cuid valid'
|
||||||
);
|
);
|
||||||
|
// - loginGetEditAccessCuidFromId
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected['check_access_cuid'],
|
||||||
|
$login_mock->loginGetEditAccessCuidFromUid($mock_settings['edit_access_id']),
|
||||||
|
'Assert check access id to cuid valid'
|
||||||
|
);
|
||||||
// Deprecated
|
// Deprecated
|
||||||
// - loginCheckEditAccess
|
// - loginCheckEditAccess
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsSecurityPasswordTest extends TestCase
|
final class CoreLibsSecurityPasswordTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function passwordProvider(): array
|
public function passwordProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -21,6 +26,11 @@ final class CoreLibsSecurityPasswordTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: we need different hash types for PHP versions
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function passwordRehashProvider(): array
|
public function passwordRehashProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@@ -63,6 +73,10 @@ final class CoreLibsSecurityPasswordTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testPasswordRehashCheck(string $input, bool $expected): void
|
public function testPasswordRehashCheck(string $input, bool $expected): void
|
||||||
{
|
{
|
||||||
|
// in PHP 8.4 the length is $12
|
||||||
|
if (PHP_VERSION_ID > 80400) {
|
||||||
|
$input = str_replace('$2y$10$', '$2y$12$', $input);
|
||||||
|
}
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Security\Password::passwordRehashCheck($input)
|
\CoreLibs\Security\Password::passwordRehashCheck($input)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<phpunit
|
<phpunit
|
||||||
cacheResultFile="/tmp/phpunit-corelibs.result.cache"
|
cacheResultFile="/tmp/phpunit-corelibs.result.cache"
|
||||||
colors="true"
|
colors="true"
|
||||||
verbose="true"
|
verbose="false"
|
||||||
convertDeprecationsToExceptions="true"
|
convertDeprecationsToExceptions="true"
|
||||||
bootstrap="4dev/tests/bootstrap.php"
|
bootstrap="4dev/tests/bootstrap.php"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -273,8 +273,8 @@ $query_insert = <<<SQL
|
|||||||
INSERT INTO
|
INSERT INTO
|
||||||
test_foo
|
test_foo
|
||||||
(
|
(
|
||||||
test, some_bool, string_a, number_a, number_a_numeric,
|
test, some_bool, string_a, number_a, numeric_a,
|
||||||
some_time, some_timestamp, json_string
|
some_internval, some_timestamp, json_string
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5,
|
$1, $2, $3, $4, $5,
|
||||||
$6, $7, $8
|
$6, $7, $8
|
||||||
@@ -283,8 +283,8 @@ RETURNING test
|
|||||||
SQL;
|
SQL;
|
||||||
$query_select = <<<SQL
|
$query_select = <<<SQL
|
||||||
SELECT
|
SELECT
|
||||||
test, some_bool, string_a, number_a, number_a_numeric,
|
test, some_bool, string_a, number_a, numeric_a,
|
||||||
some_time, some_time, some_timestamp, json_string
|
some_time, some_internval, some_timestamp, json_string
|
||||||
FROM
|
FROM
|
||||||
test_foo
|
test_foo
|
||||||
WHERE
|
WHERE
|
||||||
@@ -554,7 +554,7 @@ print "<b>PREPARE QUERIES</b><br>";
|
|||||||
// READ PREPARE
|
// READ PREPARE
|
||||||
$q_prep = <<<SQL
|
$q_prep = <<<SQL
|
||||||
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
||||||
number_a_numeric, some_time
|
numeric_a, some_time
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE test = $1
|
WHERE test = $1
|
||||||
ORDER BY test_foo_id DESC LIMIT 5
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
@@ -582,7 +582,7 @@ if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
|
|||||||
|
|
||||||
// sel test with ANY () type
|
// sel test with ANY () type
|
||||||
$q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, "
|
$q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, "
|
||||||
. "number_a_numeric, some_time "
|
. "numeric_a, some_time "
|
||||||
. "FROM test_foo "
|
. "FROM test_foo "
|
||||||
. "WHERE test = ANY($1) "
|
. "WHERE test = ANY($1) "
|
||||||
. "ORDER BY test_foo_id DESC LIMIT 5";
|
. "ORDER BY test_foo_id DESC LIMIT 5";
|
||||||
@@ -618,7 +618,7 @@ $test_bar = $db->dbEscapeLiteral('SOMETHING DIFFERENT');
|
|||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
||||||
-- comment
|
-- comment
|
||||||
number_a_numeric, some_time
|
numeric_a, some_time
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE test = $test_bar
|
WHERE test = $test_bar
|
||||||
ORDER BY test_foo_id DESC LIMIT 5
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
@@ -631,7 +631,7 @@ print "DB RETURN PARAMS<br>";
|
|||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
SELECT test_foo_id, test, some_bool, string_a, number_a,
|
||||||
-- comment
|
-- comment
|
||||||
number_a_numeric, some_time
|
numeric_a, some_time
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE test = $1
|
WHERE test = $1
|
||||||
ORDER BY test_foo_id DESC LIMIT 5
|
ORDER BY test_foo_id DESC LIMIT 5
|
||||||
@@ -646,7 +646,7 @@ echo "<hr>";
|
|||||||
print "DB RETURN PARAMS LIKE<br>";
|
print "DB RETURN PARAMS LIKE<br>";
|
||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
SELECT
|
SELECT
|
||||||
test_foo_id, test, some_bool, string_a, number_a, number_a_numeric
|
test_foo_id, test, some_bool, string_a, number_a, numeric_a
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE string_a LIKE $1;
|
WHERE string_a LIKE $1;
|
||||||
SQL;
|
SQL;
|
||||||
@@ -660,7 +660,7 @@ echo "<hr>";
|
|||||||
print "DB RETURN PARAMS ANY<br>";
|
print "DB RETURN PARAMS ANY<br>";
|
||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
SELECT
|
SELECT
|
||||||
test_foo_id, test, some_bool, string_a, number_a, number_a_numeric
|
test_foo_id, test, some_bool, string_a, number_a, numeric_a
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE string_a = ANY($1);
|
WHERE string_a = ANY($1);
|
||||||
SQL;
|
SQL;
|
||||||
|
|||||||
@@ -57,6 +57,43 @@ if (($dbh = $db->dbGetDbh()) instanceof \PgSql\Connection) {
|
|||||||
print "<b>TRUNCATE test_foo</b><br>";
|
print "<b>TRUNCATE test_foo</b><br>";
|
||||||
$db->dbExec("TRUNCATE test_foo");
|
$db->dbExec("TRUNCATE test_foo");
|
||||||
|
|
||||||
|
/*
|
||||||
|
BELOW IS THE FULL TABLE WITH ALL PostgreSQL Types
|
||||||
|
=> \d test_foo
|
||||||
|
Table "public.test_foo"
|
||||||
|
Column | Type | Nullable | Default
|
||||||
|
------------------+-----------------------------+----------+-----------------------------------------------
|
||||||
|
test | character varying | |
|
||||||
|
some_bool | boolean | |
|
||||||
|
string_a | character varying | |
|
||||||
|
number_a | integer | |
|
||||||
|
numeric_a | numeric | |
|
||||||
|
some_internval | interval | |
|
||||||
|
test_foo_id | integer | not null | generated always as identity
|
||||||
|
json_string | jsonb | |
|
||||||
|
some_timestamp | timestamp without time zone | |
|
||||||
|
some_binary | bytea | |
|
||||||
|
null_var | character varying | |
|
||||||
|
smallint_a | smallint | |
|
||||||
|
number_real | real | |
|
||||||
|
number_double | double precision | |
|
||||||
|
number_serial | integer | not null | nextval('test_foo_number_serial_seq'::regclass)
|
||||||
|
array_char_1 | character varying[] | |
|
||||||
|
array_char_2 | character varying[] | |
|
||||||
|
array_int_1 | integer[] | |
|
||||||
|
array_int_2 | integer[] | |
|
||||||
|
composite_item | inventory_item | |
|
||||||
|
array_composite | inventory_item[] | |
|
||||||
|
numeric_3 | numeric(3,0) | |
|
||||||
|
identity_always | bigint | not null | generated always as identity
|
||||||
|
identitiy_default | bigint | not null | generated by default as identity
|
||||||
|
uuid_var | uuid | | gen_random_uuid()
|
||||||
|
some_date | date | |
|
||||||
|
some_time | time without time zone | |
|
||||||
|
bigint_a | bigint | |
|
||||||
|
default_uuid | uuid | | gen_random_uuid()
|
||||||
|
*/
|
||||||
|
|
||||||
/* $q = <<<SQL
|
/* $q = <<<SQL
|
||||||
INSERT INTO test_foo (test, array_composite) VALUES ('C', '{"(a,1,1.5)","(b,2,2.5)"}')
|
INSERT INTO test_foo (test, array_composite) VALUES ('C', '{"(a,1,1.5)","(b,2,2.5)"}')
|
||||||
SQL;
|
SQL;
|
||||||
@@ -90,7 +127,7 @@ $query_params = [
|
|||||||
|
|
||||||
$query_insert = <<<SQL
|
$query_insert = <<<SQL
|
||||||
INSERT INTO test_foo (
|
INSERT INTO test_foo (
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
test, some_bool, string_a, number_a, numeric_a, smallint_a,
|
||||||
some_time, some_timestamp, json_string, null_var,
|
some_time, some_timestamp, json_string, null_var,
|
||||||
array_char_1, array_int_1,
|
array_char_1, array_int_1,
|
||||||
array_composite,
|
array_composite,
|
||||||
@@ -106,7 +143,7 @@ INSERT INTO test_foo (
|
|||||||
)
|
)
|
||||||
RETURNING
|
RETURNING
|
||||||
test_foo_id,
|
test_foo_id,
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
test, some_bool, string_a, number_a, numeric_a, smallint_a,
|
||||||
some_time, some_timestamp, json_string, null_var,
|
some_time, some_timestamp, json_string, null_var,
|
||||||
array_char_1, array_int_1,
|
array_char_1, array_int_1,
|
||||||
array_composite,
|
array_composite,
|
||||||
@@ -127,8 +164,8 @@ echo "<hr>";
|
|||||||
$query_select = <<<SQL
|
$query_select = <<<SQL
|
||||||
SELECT
|
SELECT
|
||||||
test_foo_id,
|
test_foo_id,
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
test, some_bool, string_a, number_a, numeric_a, smallint_a,
|
||||||
number_real, number_double, number_numeric_3, number_serial,
|
number_real, number_double, numeric_3, number_serial,
|
||||||
some_time, some_timestamp, json_string, null_var,
|
some_time, some_timestamp, json_string, null_var,
|
||||||
array_char_1, array_char_2, array_int_1, array_int_2, array_composite,
|
array_char_1, array_char_2, array_int_1, array_int_2, array_composite,
|
||||||
composite_item, (composite_item).*,
|
composite_item, (composite_item).*,
|
||||||
|
|||||||
@@ -29,15 +29,17 @@ $table_arrays = [];
|
|||||||
$table_arrays[\CoreLibs\Get\System::getPageName(1)] = [
|
$table_arrays[\CoreLibs\Get\System::getPageName(1)] = [
|
||||||
// form fields mtaching up with db fields
|
// form fields mtaching up with db fields
|
||||||
'table_array' => [
|
'table_array' => [
|
||||||
|
'foo',
|
||||||
|
'bar'
|
||||||
],
|
],
|
||||||
// laod query
|
// laod query
|
||||||
'load_query' => '',
|
'load_query' => 'SELECT uuid_nr, foo, bar FROM test',
|
||||||
// database table to load from
|
// database table to load from
|
||||||
'table_name' => '',
|
'table_name' => 'test',
|
||||||
// for load dro pdown, format output
|
// for load dro pdown, format output
|
||||||
'show_fields' => [
|
'show_fields' => [
|
||||||
[
|
[
|
||||||
'name' => 'name'
|
'name' => 'foo'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'enabled',
|
'name' => 'enabled',
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
print "PHP Version: " . PHP_VERSION . "<br>";
|
||||||
|
|
||||||
$password = 'something1234';
|
$password = 'something1234';
|
||||||
$enc_password = $_password->passwordSet($password);
|
$enc_password = $_password->passwordSet($password);
|
||||||
print "PASSWORD: $password: " . $enc_password . "<br>";
|
print "PASSWORD: $password: " . $enc_password . "<br>";
|
||||||
@@ -51,6 +53,20 @@ print "PASSWORD REHASH: " . (string)$password_class::passwordRehashCheck($enc_pa
|
|||||||
// direct static
|
// direct static
|
||||||
print "S::PASSWORD VERFIY: " . (string)PwdChk::passwordVerify($password, $enc_password) . "<br>";
|
print "S::PASSWORD VERFIY: " . (string)PwdChk::passwordVerify($password, $enc_password) . "<br>";
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID < 80400) {
|
||||||
|
$rehash_test = '$2y$10$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W';
|
||||||
|
$rehash_test_throw = '$2y$12$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W';
|
||||||
|
} else {
|
||||||
|
$rehash_test = '$2y$12$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W';
|
||||||
|
$rehash_test_throw = '$2y$10$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W';
|
||||||
|
}
|
||||||
|
if (PwdChk::passwordRehashCheck($rehash_test)) {
|
||||||
|
print "Bad password [BAD]<br>";
|
||||||
|
}
|
||||||
|
if (PwdChk::passwordRehashCheck($rehash_test_throw)) {
|
||||||
|
print "Bad password [OK]<br>";
|
||||||
|
}
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// FIXME: Smarty Class must be updated for PHP 8.4
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
@@ -33,6 +35,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
|||||||
);
|
);
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend(
|
$smarty = new CoreLibs\Template\SmartyExtend(
|
||||||
$l10n,
|
$l10n,
|
||||||
|
$log,
|
||||||
CACHE_ID,
|
CACHE_ID,
|
||||||
COMPILE_ID,
|
COMPILE_ID,
|
||||||
);
|
);
|
||||||
@@ -45,6 +48,7 @@ $adm = new CoreLibs\Admin\Backend(
|
|||||||
);
|
);
|
||||||
$adm->DATA['adm_set'] = 'SET from admin class';
|
$adm->DATA['adm_set'] = 'SET from admin class';
|
||||||
|
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: SMARTY';
|
$PAGE_NAME = 'TEST CLASS: SMARTY';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"egrajp/smarty-extended": "^4.3",
|
"egrajp/smarty-extended": "^5.4",
|
||||||
"php": ">=8.1",
|
"php": ">=8.1",
|
||||||
"gullevek/dotenv": "^2.0",
|
"gullevek/dotenv": "^2.0",
|
||||||
"psr/log": "^2.0 || ^3.0"
|
"psr/log": "^2.0 || ^3.0"
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// create smarty object
|
// create smarty object
|
||||||
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, CACHE_ID, COMPILE_ID);
|
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, $log, CACHE_ID, COMPILE_ID);
|
||||||
// create new Backend class with db and loger attached
|
// create new Backend class with db and loger attached
|
||||||
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, DEFAULT_ACL_LEVEL);
|
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, DEFAULT_ACL_LEVEL);
|
||||||
// the menu show flag (what menu to show)
|
// the menu show flag (what menu to show)
|
||||||
@@ -116,7 +116,7 @@ $data = [
|
|||||||
// log action
|
// log action
|
||||||
// no log if login
|
// no log if login
|
||||||
if (!$login->loginActionRun()) {
|
if (!$login->loginActionRun()) {
|
||||||
$login->writeLog('Submit', $data, $cms->adbGetActionSet(), 'BINARY');
|
$login->writeLog('Submit', $data, action_set:$cms->adbGetActionSet(), write_type:'BINARY');
|
||||||
}
|
}
|
||||||
//------------------------------ logging end
|
//------------------------------ logging end
|
||||||
|
|
||||||
|
|||||||
@@ -1418,6 +1418,7 @@ class Login
|
|||||||
'additional_acl' => Json::jsonConvertToArray($res['additional_acl']),
|
'additional_acl' => Json::jsonConvertToArray($res['additional_acl']),
|
||||||
'data' => $ea_data
|
'data' => $ea_data
|
||||||
];
|
];
|
||||||
|
// LEGACY LOOKUP
|
||||||
$unit_access_eaid[$res['edit_access_id']] = [
|
$unit_access_eaid[$res['edit_access_id']] = [
|
||||||
'cuid' => $res['cuid'],
|
'cuid' => $res['cuid'],
|
||||||
];
|
];
|
||||||
@@ -1552,8 +1553,10 @@ class Login
|
|||||||
$this->acl['unit_legacy'][$unit['id']] = $this->acl['unit'][$ea_cuid];
|
$this->acl['unit_legacy'][$unit['id']] = $this->acl['unit'][$ea_cuid];
|
||||||
// detail name/level set
|
// detail name/level set
|
||||||
$this->acl['unit_detail'][$ea_cuid] = [
|
$this->acl['unit_detail'][$ea_cuid] = [
|
||||||
|
'id' => $unit['id'],
|
||||||
'name' => $unit['name'],
|
'name' => $unit['name'],
|
||||||
'uid' => $unit['uid'],
|
'uid' => $unit['uid'],
|
||||||
|
'cuuid' => $unit['cuuid'],
|
||||||
'level' => $this->default_acl_list[$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
'level' => $this->default_acl_list[$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
||||||
'default' => $unit['default'],
|
'default' => $unit['default'],
|
||||||
'data' => $unit['data'],
|
'data' => $unit['data'],
|
||||||
@@ -3277,6 +3280,20 @@ HTML;
|
|||||||
return (int)$_SESSION['LOGIN_UNIT_CUID'][$uid];
|
return (int)$_SESSION['LOGIN_UNIT_CUID'][$uid];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legacy lookup for edit access id to cuid
|
||||||
|
*
|
||||||
|
* @param int $id edit access id PK
|
||||||
|
* @return string|false edit access cuid or false if not found
|
||||||
|
*/
|
||||||
|
public function loginGetEditAccessCuidFromId(int $id): string|false
|
||||||
|
{
|
||||||
|
if (!isset($_SESSION['LOGIN_UNIT_ACL_LEVEL'][$id])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (string)$_SESSION['LOGIN_UNIT_ACL_LEVEL'][$id]['cuid'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if admin flag is set
|
* Check if admin flag is set
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ class Backend
|
|||||||
* JSON, STRING/SERIEAL, BINARY/BZIP or ZLIB
|
* JSON, STRING/SERIEAL, BINARY/BZIP or ZLIB
|
||||||
* @param string|null $db_schema [default=null] override target schema
|
* @param string|null $db_schema [default=null] override target schema
|
||||||
* @return void
|
* @return void
|
||||||
* @deprecated Use $login->writeLog() and set action_set from ->adbGetActionSet()
|
* @deprecated Use $login->writeLog($event, $data, action_set:$cms->adbGetActionSet(), write_type:$write_type)
|
||||||
*/
|
*/
|
||||||
public function adbEditLog(
|
public function adbEditLog(
|
||||||
string $event = '',
|
string $event = '',
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace CoreLibs\Admin;
|
namespace CoreLibs\Admin;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use SmartyException;
|
|
||||||
|
|
||||||
class EditBase
|
class EditBase
|
||||||
{
|
{
|
||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
@@ -63,6 +60,7 @@ class EditBase
|
|||||||
// smarty template engine (extended Translation version)
|
// smarty template engine (extended Translation version)
|
||||||
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
||||||
$l10n,
|
$l10n,
|
||||||
|
$log,
|
||||||
$options['cache_id'] ?? '',
|
$options['cache_id'] ?? '',
|
||||||
$options['compile_id'] ?? '',
|
$options['compile_id'] ?? '',
|
||||||
);
|
);
|
||||||
@@ -538,8 +536,7 @@ class EditBase
|
|||||||
* builds the smarty content and runs smarty display output
|
* builds the smarty content and runs smarty display output
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws \Smarty\Exception
|
||||||
* @throws SmartyException
|
|
||||||
*/
|
*/
|
||||||
public function editBaseRun(
|
public function editBaseRun(
|
||||||
?string $template_dir = null,
|
?string $template_dir = null,
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace CoreLibs\Template;
|
namespace CoreLibs\Template;
|
||||||
|
|
||||||
// leading slash if this is in lib\Smarty
|
class SmartyExtend extends \Smarty\Smarty
|
||||||
class SmartyExtend extends \Smarty
|
|
||||||
{
|
{
|
||||||
// internal translation engine
|
// internal translation engine
|
||||||
/** @var \CoreLibs\Language\L10n */
|
/** @var \CoreLibs\Language\L10n language class */
|
||||||
public \CoreLibs\Language\L10n $l10n;
|
public \CoreLibs\Language\L10n $l10n;
|
||||||
|
/** @var \CoreLibs\Logging\Logging $log logging class */
|
||||||
|
public \CoreLibs\Logging\Logging $log;
|
||||||
|
|
||||||
// lang & encoding
|
// lang & encoding
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@@ -157,14 +158,18 @@ class SmartyExtend extends \Smarty
|
|||||||
* calls L10 for pass on internaly in smarty
|
* calls L10 for pass on internaly in smarty
|
||||||
* also registers the getvar caller plugin
|
* also registers the getvar caller plugin
|
||||||
*
|
*
|
||||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
* @param string|null $cache_id
|
* @param \CoreLibs\Logging\Logging $log Logger class
|
||||||
* @param string|null $compile_id
|
* @param string|null $cache_id [default=null]
|
||||||
|
* @param string|null $compile_id [default=null]
|
||||||
|
* @param array<string,mixed> $options [default=[]]
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\Language\L10n $l10n,
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
\CoreLibs\Logging\Logging $log,
|
||||||
?string $cache_id = null,
|
?string $cache_id = null,
|
||||||
?string $compile_id = null
|
?string $compile_id = null,
|
||||||
|
array $options = []
|
||||||
) {
|
) {
|
||||||
// trigger deprecation
|
// trigger deprecation
|
||||||
if (
|
if (
|
||||||
@@ -177,14 +182,33 @@ class SmartyExtend extends \Smarty
|
|||||||
E_USER_DEPRECATED
|
E_USER_DEPRECATED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// set variables (to be deprecated)
|
// set variables from global constants (deprecated)
|
||||||
$cache_id = $cache_id ??
|
if ($cache_id === null && defined('CACHE_ID')) {
|
||||||
(defined('CACHE_ID') ? CACHE_ID : '');
|
trigger_error(
|
||||||
$compile_id = $compile_id ??
|
'SmartyExtended: No cache_id set and CACHE_ID constant set, this is deprecated',
|
||||||
(defined('COMPILE_ID') ? COMPILE_ID : '');
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
$cache_id = CACHE_ID;
|
||||||
|
}
|
||||||
|
if ($compile_id === null && defined('COMPILE_ID')) {
|
||||||
|
trigger_error(
|
||||||
|
'SmartyExtended: No compile_id set and COMPILE_ID constant set, this is deprecated',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
$compile_id = COMPILE_ID;
|
||||||
|
}
|
||||||
|
if (empty($cache_id)) {
|
||||||
|
throw new \BadMethodCallException('cache_id parameter is not set');
|
||||||
|
}
|
||||||
|
if (empty($compile_id)) {
|
||||||
|
throw new \BadMethodCallException('compile_id parameter is not set');
|
||||||
|
}
|
||||||
|
|
||||||
// call basic smarty
|
// call basic smarty
|
||||||
// or Smarty::__construct();
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->log = $log;
|
||||||
|
|
||||||
// init lang
|
// init lang
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
// parse and read, legacy stuff
|
// parse and read, legacy stuff
|
||||||
@@ -194,7 +218,6 @@ class SmartyExtend extends \Smarty
|
|||||||
$this->lang_short = $locale['lang_short'];
|
$this->lang_short = $locale['lang_short'];
|
||||||
$this->domain = $locale['domain'];
|
$this->domain = $locale['domain'];
|
||||||
$this->lang_dir = $locale['path'];
|
$this->lang_dir = $locale['path'];
|
||||||
|
|
||||||
// opt load functions so we can use legacy init for smarty run perhaps
|
// opt load functions so we can use legacy init for smarty run perhaps
|
||||||
\CoreLibs\Language\L10n::loadFunctions();
|
\CoreLibs\Language\L10n::loadFunctions();
|
||||||
_setlocale(LC_MESSAGES, $locale['locale']);
|
_setlocale(LC_MESSAGES, $locale['locale']);
|
||||||
@@ -203,7 +226,6 @@ class SmartyExtend extends \Smarty
|
|||||||
_bind_textdomain_codeset($this->domain, $this->encoding);
|
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||||
|
|
||||||
// register smarty variable
|
// register smarty variable
|
||||||
// $this->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
|
||||||
$this->registerPlugin(self::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
$this->registerPlugin(self::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
||||||
|
|
||||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||||
@@ -211,6 +233,77 @@ class SmartyExtend extends \Smarty
|
|||||||
// set internal settings
|
// set internal settings
|
||||||
$this->CACHE_ID = $cache_id;
|
$this->CACHE_ID = $cache_id;
|
||||||
$this->COMPILE_ID = $compile_id;
|
$this->COMPILE_ID = $compile_id;
|
||||||
|
// set options
|
||||||
|
$this->setOptions($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set options
|
||||||
|
*
|
||||||
|
* @param array<string,mixed> $options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function setOptions(array $options): void
|
||||||
|
{
|
||||||
|
// set escape html if option is set
|
||||||
|
if (!empty($options['escape_html'])) {
|
||||||
|
$this->setEscapeHtml(true);
|
||||||
|
}
|
||||||
|
// load plugins
|
||||||
|
// plugin array:
|
||||||
|
// 'file': string, path to plugin content to load
|
||||||
|
// 'type': a valid smarty type see Smarty PLUGIN_ constants for correct names
|
||||||
|
// 'tag': the smarty tag
|
||||||
|
// 'callback': the function to call in 'file'
|
||||||
|
if (!empty($options['plugins'])) {
|
||||||
|
foreach ($options['plugins'] as $plugin) {
|
||||||
|
// file is readable
|
||||||
|
if (
|
||||||
|
empty($plugin['file']) ||
|
||||||
|
!is_file($plugin['file']) ||
|
||||||
|
!is_readable($plugin['file'])
|
||||||
|
) {
|
||||||
|
$this->log->warning('SmartyExtended plugin load failed, file not accessable', [
|
||||||
|
'plugin' => $plugin,
|
||||||
|
]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// tag is alphanumeric
|
||||||
|
if (!preg_match("/^\w+$/", $plugin['tag'] ?? '')) {
|
||||||
|
$this->log->warning('SmartyExtended plugin load failed, invalid tag', [
|
||||||
|
'plugin' => $plugin,
|
||||||
|
]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// callback is alphanumeric
|
||||||
|
if (!preg_match("/^\w+$/", $plugin['callback'] ?? '')) {
|
||||||
|
$this->log->warning('SmartyExtended plugin load failed, invalid callback', [
|
||||||
|
'plugin' => $plugin,
|
||||||
|
]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
/** @phan-suppress-next-line PhanNoopNew */
|
||||||
|
new \ReflectionClassConstant($this, $plugin['type']);
|
||||||
|
} catch (\ReflectionException $e) {
|
||||||
|
$this->log->error('SmartyExtended plugin load failed, type is not valid', [
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'plugin' => $plugin,
|
||||||
|
]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
require $plugin['file'];
|
||||||
|
$this->registerPlugin($plugin['type'], $plugin['tag'], $plugin['callback']);
|
||||||
|
} catch (\Smarty\Exception $e) {
|
||||||
|
$this->log->error('SmartyExtended plugin load failed with exception', [
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'plugin' => $plugin,
|
||||||
|
]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user