From b1d24fbdb7d1cc948c946295035dad6df550fb7e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 27 Dec 2024 12:12:49 +0100 Subject: PHPStan 2.0 (#7131) * PHPStan 2.0 fix https://github.com/FreshRSS/FreshRSS/issues/6989 https://github.com/phpstan/phpstan/releases/tag/2.0.0 https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md * More * More * Done * fix i18n CLI * Restore a PHPStan Next test For work towards PHPStan Level 10 * 4 more on Level 10 * fix getTagsForEntry * API at Level 10 * More Level 10 * Finish Minz at Level 10 * Finish CLI at Level 10 * Finish Controllers at Level 10 * More Level 10 * More * Pass bleedingEdge * Clean PHPStan options and add TODOs * Level 10 for main config * More * Consitency array vs. list * Sanitize themes get_infos * Simplify TagDAO->getTagsForEntries() * Finish reportAnyTypeWideningInVarTag * Prepare checkBenevolentUnionTypes and checkImplicitMixed * Fixes * Refix * Another fix * Casing of __METHOD__ constant --- app/install.php | 69 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'app/install.php') diff --git a/app/install.php b/app/install.php index a7b4ef09c..232d24c7c 100644 --- a/app/install.php +++ b/app/install.php @@ -10,7 +10,7 @@ require(LIB_PATH . '/lib_install.php'); Minz_Session::init('FreshRSS'); -if (isset($_GET['step'])) { +if (isset($_GET['step']) && is_numeric($_GET['step'])) { define('STEP', (int)$_GET['step']); } else { define('STEP', 0); @@ -41,7 +41,7 @@ function initTranslate(): void { } function get_best_language(): string { - $accept = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE']; + $accept = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) || !is_string($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE']; return strtolower(substr($accept, 0, 2)); } @@ -102,19 +102,22 @@ function saveStep2(): void { 'bd_prefix' => false, ]); } else { - if (empty($_POST['type']) || - empty($_POST['host']) || - empty($_POST['user']) || - empty($_POST['base'])) { + if (empty($_POST['type']) || !is_string($_POST['type']) || + empty($_POST['host']) || !is_string($_POST['host']) || + empty($_POST['user']) || !is_string($_POST['user']) || + empty($_POST['base']) || !is_string($_POST['base']) || + !is_string($_POST['pass'] ?? null) || !is_string($_POST['prefix'] ?? null) + ) { Minz_Session::_param('bd_error', 'Missing parameters!'); - } - Minz_Session::_params([ + } else { + Minz_Session::_params([ 'bd_base' => substr($_POST['base'], 0, 64), 'bd_host' => $_POST['host'], 'bd_user' => $_POST['user'], 'bd_password' => $_POST['pass'], 'bd_prefix' => substr($_POST['prefix'], 0, 16), ]); + } } // We use dirname to remove the /i part @@ -143,6 +146,9 @@ function saveStep2(): void { $customConfig = include($customConfigPath); if (is_array($customConfig)) { $config_array = array_merge($customConfig, $config_array); + if (!is_string($config_array['default_user'] ?? null)) { + $config_array['default_user'] = '_'; + } } } @@ -157,6 +163,9 @@ function saveStep2(): void { $ok = false; try { + if (!is_string($config_array['default_user'])) { + throw new Exception('Invalid default user name'); + } Minz_User::change($config_array['default_user']); $error = initDb(); Minz_User::change(); @@ -327,11 +336,11 @@ function checkStep3(): array { $form = Minz_Session::paramString('auth_type') != ''; - $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user']; - if ($defaultUser === null) { + $defaultUser = is_string($_POST['default_user'] ?? null) ? trim($_POST['default_user']) : ''; + if ($defaultUser === '') { $defaultUser = Minz_Session::paramString('default_user') == '' ? '' : Minz_Session::paramString('default_user'); } - $data = is_writable(join_path(USERS_PATH, $defaultUser, 'config.php')); + $data = is_writable(USERS_PATH . '/' . $defaultUser . '/config.php'); return [ 'conf' => $conf ? 'ok' : 'ko', @@ -445,16 +454,15 @@ function getProcessUsername(): string { /* check system environment */ function printStep1(): void { $res = checkRequirements(); - $processUsername = getProcessUsername(); ?>

-

+ (empty($_SESSION['bd_error']) || !is_string($_SESSION['bd_error']) ? '' : ' : ' . $_SESSION['bd_error']) ?>

@@ -527,19 +536,19 @@ function printStep2(): void { + $bd_host ?? $system_default_config->db['host'] ?? '' ?>" tabindex="2" /> @@ -560,7 +576,7 @@ function printStep2(): void {
+ $bd_user ?? '' ?>" tabindex="3" />
@@ -569,7 +585,7 @@ function printStep2(): void {
+ $bd_password ?? '' ?>" tabindex="4" autocomplete="off" />
@@ -579,7 +595,7 @@ function printStep2(): void {
+ $bd_base ?? '' ?>" tabindex="6" />
@@ -587,7 +603,7 @@ function printStep2(): void {
+ $bd_prefix ?? $system_default_config->db['prefix'] ?? '' ?>" tabindex="7" />
@@ -611,7 +627,8 @@ function no_auth(string $auth_type): bool { /* Create default user */ function printStep3(): void { - $auth_type = $_SESSION['auth_type'] ?? ''; + $auth_type = is_string($_SESSION['auth_type'] ?? null) ? $_SESSION['auth_type'] : ''; + $default_user = is_string($_SESSION['default_user'] ?? null) ? $_SESSION['default_user'] : ''; $s3 = checkStep3(); if ($s3['all'] == 'ok') { ?>

@@ -625,7 +642,7 @@ function printStep3(): void {

-- cgit v1.2.3