Remove hostname global variable
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
a01fed10cf
commit
d253986eb5
@ -3510,24 +3510,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/Controllers/Server/PrivilegesController.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$hostname of method PhpMyAdmin\\Server\\Privileges\:\:getHtmlForRoutineSpecificPrivileges\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Controllers/Server/PrivilegesController.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$initial of method PhpMyAdmin\\Server\\Privileges\:\:getHtmlForUserOverview\(\) expects string\|null, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Controllers/Server/PrivilegesController.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#4 \$hostname of method PhpMyAdmin\\Server\\Privileges\:\:getHtmlForUserProperties\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Controllers/Server/PrivilegesController.php
|
||||
|
||||
-
|
||||
message: '#^Only booleans are allowed in an if condition, mixed given\.$#'
|
||||
identifier: if.condNotBoolean
|
||||
@ -5370,12 +5358,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Controllers/UserPasswordController.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$hostname of method PhpMyAdmin\\UserPassword\:\:getFormForChangePassword\(\) expects string\|null, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Controllers/UserPasswordController.php
|
||||
|
||||
-
|
||||
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
|
||||
identifier: notEqual.notAllowed
|
||||
@ -15006,12 +14988,6 @@ parameters:
|
||||
count: 2
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function mb_strtolower expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function mb_substr expects string, string\|null given\.$#'
|
||||
identifier: argument.type
|
||||
@ -15024,12 +15000,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$hostname of method PhpMyAdmin\\Server\\Privileges\:\:getUserHostCondition\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
@ -15060,12 +15030,6 @@ parameters:
|
||||
count: 2
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#4 \$hostname of method PhpMyAdmin\\Server\\Privileges\:\:getSqlQueryForDisplayPrivTable\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/Server/Privileges.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#5 \$tablename of method PhpMyAdmin\\Server\\Privileges\:\:getUserLink\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
|
||||
@ -50,7 +50,6 @@
|
||||
errno: int,
|
||||
file_handle: resource|null,
|
||||
from_cookie: bool,
|
||||
hostname: string,
|
||||
import_text: string,
|
||||
knjenc: string,
|
||||
maxsize: string,
|
||||
|
||||
@ -46,8 +46,6 @@ final class PrivilegesController implements InvocableController
|
||||
|
||||
public function __invoke(ServerRequest $request): Response
|
||||
{
|
||||
$GLOBALS['hostname'] ??= null;
|
||||
|
||||
$userPrivileges = $this->userPrivilegesFactory->getPrivileges();
|
||||
|
||||
$relationParameters = $this->relation->getRelationParameters();
|
||||
@ -80,7 +78,7 @@ final class PrivilegesController implements InvocableController
|
||||
}
|
||||
|
||||
$serverPrivileges->username = $serverPrivileges->getUsernameParam($request);
|
||||
$GLOBALS['hostname'] = $serverPrivileges->getHostnameParam($request);
|
||||
$serverPrivileges->hostname = $serverPrivileges->getHostnameParam($request);
|
||||
$databaseName = $serverPrivileges->getDbname($request);
|
||||
$tablename = $serverPrivileges->getTablename($request);
|
||||
$routinename = $serverPrivileges->getRoutinename($request);
|
||||
@ -115,7 +113,7 @@ final class PrivilegesController implements InvocableController
|
||||
if (
|
||||
$request->hasBodyParam('change_copy')
|
||||
&& $serverPrivileges->username === $request->getParsedBodyParam('old_username')
|
||||
&& $GLOBALS['hostname'] === $request->getParsedBodyParam('old_hostname')
|
||||
&& $serverPrivileges->hostname === $request->getParsedBodyParam('old_hostname')
|
||||
) {
|
||||
$this->response->addHTML(
|
||||
Message::error(
|
||||
@ -150,7 +148,7 @@ final class PrivilegesController implements InvocableController
|
||||
if ($request->hasBodyParam('adduser_submit') || $request->hasBodyParam('change_copy')) {
|
||||
$hostname = $serverPrivileges->getHostname(
|
||||
$request->getParsedBodyParamAsString('pred_hostname', ''),
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
);
|
||||
[
|
||||
$retMessage,
|
||||
@ -178,12 +176,12 @@ final class PrivilegesController implements InvocableController
|
||||
if (
|
||||
$request->hasBodyParam('change_copy')
|
||||
&& $serverPrivileges->username !== null
|
||||
&& $GLOBALS['hostname'] !== null
|
||||
&& $serverPrivileges->hostname !== null
|
||||
) {
|
||||
$queries = $serverPrivileges->getDbSpecificPrivsQueriesForChangeOrCopyUser(
|
||||
$queries,
|
||||
$serverPrivileges->username,
|
||||
$GLOBALS['hostname'],
|
||||
$serverPrivileges->hostname,
|
||||
$request->getParsedBodyParamAsString('old_username'),
|
||||
$request->getParsedBodyParamAsString('old_hostname'),
|
||||
);
|
||||
@ -203,7 +201,7 @@ final class PrivilegesController implements InvocableController
|
||||
foreach ($databaseName as $key => $dbName) {
|
||||
[$statements[$key], Current::$message] = $serverPrivileges->updatePrivileges(
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$tablename ?? $routinename ?? '',
|
||||
$dbName,
|
||||
$itemType,
|
||||
@ -214,7 +212,7 @@ final class PrivilegesController implements InvocableController
|
||||
} else {
|
||||
[Current::$sqlQuery, Current::$message] = $serverPrivileges->updatePrivileges(
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$tablename ?? $routinename ?? '',
|
||||
$databaseName ?? '',
|
||||
$itemType,
|
||||
@ -244,7 +242,7 @@ final class PrivilegesController implements InvocableController
|
||||
is_string($databaseName) ? $databaseName : '',
|
||||
$tablename ?? $routinename ?? '',
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$itemType,
|
||||
);
|
||||
}
|
||||
@ -256,7 +254,7 @@ final class PrivilegesController implements InvocableController
|
||||
Current::$message = $serverPrivileges->updatePassword(
|
||||
$errorUrl,
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@ -308,7 +306,7 @@ final class PrivilegesController implements InvocableController
|
||||
$extraData = $serverPrivileges->getExtraDataForAjaxBehavior(
|
||||
$password ?? '',
|
||||
Current::$sqlQuery,
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$serverPrivileges->username ?? '',
|
||||
! is_array($databaseName) ? $databaseName : null,
|
||||
);
|
||||
@ -337,18 +335,18 @@ final class PrivilegesController implements InvocableController
|
||||
|
||||
$title = $this->getExportPageTitle(
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$selectedUsers,
|
||||
);
|
||||
|
||||
$export = $serverPrivileges->getExportUserDefinitionTextarea(
|
||||
$serverPrivileges->username ?? '',
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$selectedUsers,
|
||||
);
|
||||
|
||||
$serverPrivileges->username = null;
|
||||
unset($GLOBALS['hostname']);
|
||||
$serverPrivileges->hostname = null;
|
||||
|
||||
if ($request->isAjax()) {
|
||||
$this->response->addJSON('message', $export);
|
||||
@ -387,7 +385,7 @@ final class PrivilegesController implements InvocableController
|
||||
$this->response->addHTML(
|
||||
$serverPrivileges->getHtmlForRoutineSpecificPrivileges(
|
||||
$serverPrivileges->username,
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
is_string($databaseName) ? $databaseName : '',
|
||||
$routinename,
|
||||
$serverPrivileges->escapeGrantWildcards($urlDbname ?? ''),
|
||||
@ -405,7 +403,7 @@ final class PrivilegesController implements InvocableController
|
||||
$dbnameIsWildcard,
|
||||
$serverPrivileges->escapeGrantWildcards($urlDbname ?? ''),
|
||||
$serverPrivileges->username,
|
||||
$GLOBALS['hostname'] ?? '',
|
||||
$serverPrivileges->hostname ?? '',
|
||||
$databaseName ?? '',
|
||||
$tablename ?? '',
|
||||
$request->getRoute(),
|
||||
|
||||
@ -30,8 +30,6 @@ final class UserPasswordController implements InvocableController
|
||||
|
||||
public function __invoke(ServerRequest $request): Response
|
||||
{
|
||||
$GLOBALS['hostname'] ??= null;
|
||||
|
||||
$this->response->addScriptFiles(['server/privileges.js', 'vendor/zxcvbn-ts.js']);
|
||||
|
||||
$config = Config::getInstance();
|
||||
@ -103,11 +101,7 @@ final class UserPasswordController implements InvocableController
|
||||
$this->response->addHTML($message->getDisplay());
|
||||
}
|
||||
|
||||
$this->response->addHTML($this->userPassword->getFormForChangePassword(
|
||||
'',
|
||||
$GLOBALS['hostname'],
|
||||
$request->getRoute(),
|
||||
));
|
||||
$this->response->addHTML($this->userPassword->getFormForChangePassword('', '', $request->getRoute()));
|
||||
|
||||
return $this->response->response();
|
||||
}
|
||||
|
||||
@ -71,6 +71,7 @@ use function uksort;
|
||||
class Privileges
|
||||
{
|
||||
public string|null $username = null;
|
||||
public string|null $hostname = null;
|
||||
private string|null $sslType = null;
|
||||
private string|null $sslCipher = null;
|
||||
private string|null $x509Issuer = null;
|
||||
@ -473,7 +474,7 @@ class Privileges
|
||||
$row = [];
|
||||
if ($this->username !== null) {
|
||||
$username = $this->username;
|
||||
$hostname = $GLOBALS['hostname'];
|
||||
$hostname = $this->hostname ?? '';
|
||||
$sqlQuery = $this->getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname);
|
||||
$row = $this->dbi->fetchSingleRow($sqlQuery);
|
||||
}
|
||||
@ -596,7 +597,6 @@ class Privileges
|
||||
): string {
|
||||
$GLOBALS['pred_username'] ??= null;
|
||||
$GLOBALS['pred_hostname'] ??= null;
|
||||
$GLOBALS['hostname'] ??= null;
|
||||
$GLOBALS['new_username'] ??= null;
|
||||
|
||||
[$usernameLength, $hostnameLength] = $this->getUsernameAndHostnameLength();
|
||||
@ -618,8 +618,8 @@ class Privileges
|
||||
);
|
||||
}
|
||||
|
||||
if (! isset($GLOBALS['pred_hostname']) && isset($GLOBALS['hostname'])) {
|
||||
$GLOBALS['pred_hostname'] = match (mb_strtolower($GLOBALS['hostname'])) {
|
||||
if (! isset($GLOBALS['pred_hostname']) && $this->hostname !== null) {
|
||||
$GLOBALS['pred_hostname'] = match (mb_strtolower($this->hostname)) {
|
||||
'localhost', '127.0.0.1' => 'localhost',
|
||||
'%' => 'any',
|
||||
default => 'userdefined',
|
||||
@ -651,7 +651,7 @@ class Privileges
|
||||
'hostname_length' => $hostnameLength,
|
||||
'username' => $this->username,
|
||||
'new_username' => $GLOBALS['new_username'] ?? null,
|
||||
'hostname' => $GLOBALS['hostname'] ?? null,
|
||||
'hostname' => $this->hostname,
|
||||
'this_host' => $thisHost,
|
||||
'is_change' => $user !== null && $host !== null,
|
||||
'auth_plugin' => $authPlugin,
|
||||
|
||||
@ -599,11 +599,11 @@ class PrivilegesTest extends AbstractTestCase
|
||||
|
||||
public function testGetHtmlToDisplayPrivilegesTable(): void
|
||||
{
|
||||
$GLOBALS['hostname'] = 'hostname';
|
||||
$dbi = $this->createDatabaseInterface();
|
||||
|
||||
$serverPrivileges = $this->getPrivileges($dbi);
|
||||
$serverPrivileges->username = 'username';
|
||||
$serverPrivileges->hostname = 'hostname';
|
||||
$html = $serverPrivileges->getHtmlToDisplayPrivilegesTable();
|
||||
|
||||
//validate 2: button
|
||||
@ -877,7 +877,7 @@ class PrivilegesTest extends AbstractTestCase
|
||||
$serverPrivileges->dbi = $dbi;
|
||||
|
||||
$serverPrivileges->username = 'PMA_username';
|
||||
$GLOBALS['hostname'] = 'PMA_hostname';
|
||||
$serverPrivileges->hostname = 'PMA_hostname';
|
||||
$html = $serverPrivileges->getHtmlToDisplayPrivilegesTable('PMA_db', 'PMA_table');
|
||||
|
||||
self::assertStringContainsString('checkbox_Update_priv_none', $html);
|
||||
@ -1473,7 +1473,7 @@ class PrivilegesTest extends AbstractTestCase
|
||||
$serverPrivileges = $this->getPrivileges($this->dbi);
|
||||
|
||||
$serverPrivileges->username = 'user';
|
||||
$GLOBALS['hostname'] = 'host';
|
||||
$serverPrivileges->hostname = 'host';
|
||||
|
||||
$actual = $serverPrivileges->getHtmlForUserProperties(
|
||||
false,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user