validate username for webserver/fcgid/php-fpm in global settings to ensure it exists and is not a froxlor-managed user, fixes #1332

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2025-06-05 11:28:27 +02:00
parent 8f3228716a
commit 5beeae8fd1
5 changed files with 53 additions and 0 deletions

View File

@@ -359,4 +359,41 @@ class Check
return [self::FORMFIELDS_PLAUSIBILITY_CHECK_OK];
}
/**
* @param $fieldname
* @param $fielddata
* @param $newfieldvalue
* @param $allnewfieldvalues
* @return array|int[]
* @throws \Exception
*/
public static function checkSystemUsername($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
if (empty($newfieldvalue) || $fielddata['value'] == $newfieldvalue) {
$returnvalue = [
self::FORMFIELDS_PLAUSIBILITY_CHECK_OK
];
} elseif (function_exists('posix_getpwnam') && posix_getpwnam($newfieldvalue) == false) {
$returnvalue = [
self::FORMFIELDS_PLAUSIBILITY_CHECK_ERROR,
'local_user_invalid'
];
} else {
// user exists, but cannot be one of the froxlor-customers
$sel_stmt = Database::prepare("SELECT COUNT(*) as numUsers FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `loginname` = :username");
$result = Database::pexecute_first($sel_stmt, [':username' => $newfieldvalue]);
if ($result && $result['numUsers'] > 0) {
$returnvalue = [
self::FORMFIELDS_PLAUSIBILITY_CHECK_ERROR,
'local_user_isfroxloruser'
];
} else {
$returnvalue = [
self::FORMFIELDS_PLAUSIBILITY_CHECK_OK
];
}
}
return $returnvalue;
}
}