Update website
This commit is contained in:
parent
bb4b0f9be8
commit
011b183e28
4263 changed files with 3014 additions and 720369 deletions
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Utils;
|
||||
|
||||
use function strtolower;
|
||||
use function strtoupper;
|
||||
use function substr;
|
||||
use function version_compare;
|
||||
|
||||
final class ForeignKey
|
||||
{
|
||||
/**
|
||||
* Verifies if this table's engine supports foreign keys
|
||||
*
|
||||
* @param string $engine engine
|
||||
*/
|
||||
public static function isSupported($engine): bool
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
$engine = strtoupper((string) $engine);
|
||||
if (($engine === 'INNODB') || ($engine === 'PBXT')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($engine === 'NDBCLUSTER' || $engine === 'NDB') {
|
||||
$ndbver = strtolower(
|
||||
$dbi->fetchValue('SELECT @@ndb_version_string') ?: ''
|
||||
);
|
||||
if (substr($ndbver, 0, 4) === 'ndb-') {
|
||||
$ndbver = substr($ndbver, 4);
|
||||
}
|
||||
|
||||
return version_compare($ndbver, '7.3', '>=');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Foreign key check enabled?
|
||||
*/
|
||||
public static function isCheckEnabled(): bool
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
if ($GLOBALS['cfg']['DefaultForeignKeyChecks'] === 'enable') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['DefaultForeignKeyChecks'] === 'disable') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $dbi->getVariable('FOREIGN_KEY_CHECKS') === 'ON';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle foreign key check request
|
||||
*/
|
||||
public static function handleDisableCheckInit(): bool
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
$defaultCheckValue = $dbi->getVariable('FOREIGN_KEY_CHECKS') === 'ON';
|
||||
if (isset($_REQUEST['fk_checks'])) {
|
||||
if (empty($_REQUEST['fk_checks'])) {
|
||||
// Disable foreign key checks
|
||||
$dbi->setVariable('FOREIGN_KEY_CHECKS', 'OFF');
|
||||
} else {
|
||||
// Enable foreign key checks
|
||||
$dbi->setVariable('FOREIGN_KEY_CHECKS', 'ON');
|
||||
}
|
||||
}
|
||||
|
||||
return $defaultCheckValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup changes done for foreign key check
|
||||
*
|
||||
* @param bool $defaultCheckValue original value for 'FOREIGN_KEY_CHECKS'
|
||||
*/
|
||||
public static function handleDisableCheckCleanup(bool $defaultCheckValue): void
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
$dbi->setVariable('FOREIGN_KEY_CHECKS', $defaultCheckValue ? 'ON' : 'OFF');
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Format converter
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Utils;
|
||||
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
use function bin2hex;
|
||||
use function hex2bin;
|
||||
use function inet_ntop;
|
||||
use function inet_pton;
|
||||
use function ip2long;
|
||||
use function long2ip;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
* Format converter
|
||||
*/
|
||||
class FormatConverter
|
||||
{
|
||||
/**
|
||||
* Transforms a binary to an IP
|
||||
*
|
||||
* @param mixed $buffer Data to transform
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function binaryToIp($buffer, bool $isBinary)
|
||||
{
|
||||
if (strpos($buffer, '0x') !== 0) {
|
||||
return $isBinary ? bin2hex($buffer) : $buffer;
|
||||
}
|
||||
|
||||
$ipHex = substr($buffer, 2);
|
||||
$ipBin = hex2bin($ipHex);
|
||||
|
||||
if ($ipBin === false) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
return @inet_ntop($ipBin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an IP to a binary
|
||||
*
|
||||
* @param mixed $buffer Data to transform
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ipToBinary($buffer)
|
||||
{
|
||||
$val = @inet_pton($buffer);
|
||||
if ($val !== false) {
|
||||
return '0x' . bin2hex($val);
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an IP to a long
|
||||
*
|
||||
* @param string $buffer Data to transform
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function ipToLong(string $buffer)
|
||||
{
|
||||
$ipLong = ip2long($buffer);
|
||||
if ($ipLong === false) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
return $ipLong;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a long to an IP
|
||||
*
|
||||
* @param mixed $buffer Data to transform
|
||||
*/
|
||||
public static function longToIp($buffer): string
|
||||
{
|
||||
if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
return (string) long2ip((int) $buffer);
|
||||
}
|
||||
}
|
|
@ -1,325 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Utils;
|
||||
|
||||
use function array_map;
|
||||
use function bin2hex;
|
||||
use function mb_strtolower;
|
||||
use function preg_match;
|
||||
use function trim;
|
||||
|
||||
final class Gis
|
||||
{
|
||||
/**
|
||||
* Converts GIS data to Well Known Text format
|
||||
*
|
||||
* @param string $data GIS data
|
||||
* @param bool $includeSRID Add SRID to the WKT
|
||||
*
|
||||
* @return string GIS data in Well Know Text format
|
||||
*/
|
||||
public static function convertToWellKnownText($data, $includeSRID = false): string
|
||||
{
|
||||
global $dbi;
|
||||
|
||||
// Convert to WKT format
|
||||
$hex = bin2hex($data);
|
||||
$spatialAsText = 'ASTEXT';
|
||||
$spatialSrid = 'SRID';
|
||||
$axisOrder = '';
|
||||
$mysqlVersionInt = $dbi->getVersion();
|
||||
if ($mysqlVersionInt >= 50600) {
|
||||
$spatialAsText = 'ST_ASTEXT';
|
||||
$spatialSrid = 'ST_SRID';
|
||||
}
|
||||
|
||||
if ($mysqlVersionInt >= 80001 && ! $dbi->isMariaDb()) {
|
||||
$axisOrder = ', \'axis-order=long-lat\'';
|
||||
}
|
||||
|
||||
$wktsql = 'SELECT ' . $spatialAsText . "(x'" . $hex . "'" . $axisOrder . ')';
|
||||
if ($includeSRID) {
|
||||
$wktsql .= ', ' . $spatialSrid . "(x'" . $hex . "')";
|
||||
}
|
||||
|
||||
$wktresult = $dbi->tryQuery($wktsql);
|
||||
$wktarr = [];
|
||||
if ($wktresult) {
|
||||
$wktarr = $wktresult->fetchRow();
|
||||
}
|
||||
|
||||
$wktval = $wktarr[0] ?? '';
|
||||
|
||||
if ($includeSRID) {
|
||||
$srid = $wktarr[1] ?? null;
|
||||
$wktval = "'" . $wktval . "'," . $srid;
|
||||
}
|
||||
|
||||
return $wktval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return GIS data types
|
||||
*
|
||||
* @param bool $upperCase whether to return values in upper case
|
||||
*
|
||||
* @return string[] GIS data types
|
||||
*/
|
||||
public static function getDataTypes($upperCase = false): array
|
||||
{
|
||||
$gisDataTypes = [
|
||||
'geometry',
|
||||
'point',
|
||||
'linestring',
|
||||
'polygon',
|
||||
'multipoint',
|
||||
'multilinestring',
|
||||
'multipolygon',
|
||||
'geometrycollection',
|
||||
];
|
||||
if ($upperCase) {
|
||||
$gisDataTypes = array_map('mb_strtoupper', $gisDataTypes);
|
||||
}
|
||||
|
||||
return $gisDataTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates GIS data based on the string passed.
|
||||
*
|
||||
* @param string $gisString GIS string
|
||||
* @param int $mysqlVersion The mysql version as int
|
||||
*
|
||||
* @return string GIS data enclosed in 'ST_GeomFromText' or 'GeomFromText' function
|
||||
*/
|
||||
public static function createData($gisString, $mysqlVersion)
|
||||
{
|
||||
$geomFromText = $mysqlVersion >= 50600 ? 'ST_GeomFromText' : 'GeomFromText';
|
||||
$gisString = trim($gisString);
|
||||
$geomTypes = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
|
||||
if (preg_match("/^'" . $geomTypes . "\(.*\)',[0-9]*$/i", $gisString)) {
|
||||
return $geomFromText . '(' . $gisString . ')';
|
||||
}
|
||||
|
||||
if (preg_match('/^' . $geomTypes . '\(.*\)$/i', $gisString)) {
|
||||
return $geomFromText . "('" . $gisString . "')";
|
||||
}
|
||||
|
||||
return $gisString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names and details of the functions
|
||||
* that can be applied on geometry data types.
|
||||
*
|
||||
* @param string $geomType if provided the output is limited to the functions
|
||||
* that are applicable to the provided geometry type.
|
||||
* @param bool $binary if set to false functions that take two geometries
|
||||
* as arguments will not be included.
|
||||
* @param bool $display if set to true separators will be added to the
|
||||
* output array.
|
||||
*
|
||||
* @return array<int|string,array<string,int|string>> names and details of the functions that can be applied on
|
||||
* geometry data types.
|
||||
*/
|
||||
public static function getFunctions(
|
||||
$geomType = null,
|
||||
$binary = true,
|
||||
$display = false
|
||||
): array {
|
||||
global $dbi;
|
||||
|
||||
$funcs = [];
|
||||
if ($display) {
|
||||
$funcs[] = ['display' => ' '];
|
||||
}
|
||||
|
||||
// Unary functions common to all geometry types
|
||||
$funcs['Dimension'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['Envelope'] = [
|
||||
'params' => 1,
|
||||
'type' => 'Polygon',
|
||||
];
|
||||
$funcs['GeometryType'] = [
|
||||
'params' => 1,
|
||||
'type' => 'text',
|
||||
];
|
||||
$funcs['SRID'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['IsEmpty'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['IsSimple'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
|
||||
$geomType = mb_strtolower(trim((string) $geomType));
|
||||
if ($display && $geomType !== 'geometry' && $geomType !== 'multipoint') {
|
||||
$funcs[] = ['display' => '--------'];
|
||||
}
|
||||
|
||||
$spatialPrefix = '';
|
||||
if ($dbi->getVersion() >= 50601) {
|
||||
// If MySQL version is greater than or equal 5.6.1,
|
||||
// use the ST_ prefix.
|
||||
$spatialPrefix = 'ST_';
|
||||
}
|
||||
|
||||
// Unary functions that are specific to each geometry type
|
||||
if ($geomType === 'point') {
|
||||
$funcs[$spatialPrefix . 'X'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Y'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
} elseif ($geomType === 'linestring') {
|
||||
$funcs['EndPoint'] = [
|
||||
'params' => 1,
|
||||
'type' => 'point',
|
||||
];
|
||||
$funcs['GLength'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
$funcs['NumPoints'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['StartPoint'] = [
|
||||
'params' => 1,
|
||||
'type' => 'point',
|
||||
];
|
||||
$funcs['IsRing'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
} elseif ($geomType === 'multilinestring') {
|
||||
$funcs['GLength'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
$funcs['IsClosed'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
} elseif ($geomType === 'polygon') {
|
||||
$funcs['Area'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
$funcs['ExteriorRing'] = [
|
||||
'params' => 1,
|
||||
'type' => 'linestring',
|
||||
];
|
||||
$funcs['NumInteriorRings'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
} elseif ($geomType === 'multipolygon') {
|
||||
$funcs['Area'] = [
|
||||
'params' => 1,
|
||||
'type' => 'float',
|
||||
];
|
||||
$funcs['Centroid'] = [
|
||||
'params' => 1,
|
||||
'type' => 'point',
|
||||
];
|
||||
// Not yet implemented in MySQL
|
||||
//$funcs['PointOnSurface'] = array('params' => 1, 'type' => 'point');
|
||||
} elseif ($geomType === 'geometrycollection') {
|
||||
$funcs['NumGeometries'] = [
|
||||
'params' => 1,
|
||||
'type' => 'int',
|
||||
];
|
||||
}
|
||||
|
||||
// If we are asked for binary functions as well
|
||||
if ($binary) {
|
||||
// section separator
|
||||
if ($display) {
|
||||
$funcs[] = ['display' => '--------'];
|
||||
}
|
||||
|
||||
$funcs[$spatialPrefix . 'Crosses'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Contains'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Disjoint'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Equals'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Intersects'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Overlaps'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Touches'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs[$spatialPrefix . 'Within'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
|
||||
if ($display) {
|
||||
$funcs[] = ['display' => '--------'];
|
||||
}
|
||||
|
||||
// Minimum bounding rectangle functions
|
||||
$funcs['MBRContains'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBRDisjoint'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBREquals'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBRIntersects'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBROverlaps'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBRTouches'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
$funcs['MBRWithin'] = [
|
||||
'params' => 2,
|
||||
'type' => 'int',
|
||||
];
|
||||
}
|
||||
|
||||
return $funcs;
|
||||
}
|
||||
}
|
|
@ -1,308 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Utils;
|
||||
|
||||
use Composer\CaBundle\CaBundle;
|
||||
|
||||
use function base64_encode;
|
||||
use function curl_exec;
|
||||
use function curl_getinfo;
|
||||
use function curl_init;
|
||||
use function curl_setopt;
|
||||
use function file_get_contents;
|
||||
use function function_exists;
|
||||
use function getenv;
|
||||
use function ini_get;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_dir;
|
||||
use function parse_url;
|
||||
use function preg_match;
|
||||
use function stream_context_create;
|
||||
use function strlen;
|
||||
|
||||
use const CURL_IPRESOLVE_V4;
|
||||
use const CURLINFO_HTTP_CODE;
|
||||
use const CURLOPT_CAINFO;
|
||||
use const CURLOPT_CAPATH;
|
||||
use const CURLOPT_CONNECTTIMEOUT;
|
||||
use const CURLOPT_CUSTOMREQUEST;
|
||||
use const CURLOPT_FOLLOWLOCATION;
|
||||
use const CURLOPT_HTTPHEADER;
|
||||
use const CURLOPT_IPRESOLVE;
|
||||
use const CURLOPT_POSTFIELDS;
|
||||
use const CURLOPT_PROXY;
|
||||
use const CURLOPT_PROXYUSERPWD;
|
||||
use const CURLOPT_RETURNTRANSFER;
|
||||
use const CURLOPT_SSL_VERIFYHOST;
|
||||
use const CURLOPT_SSL_VERIFYPEER;
|
||||
use const CURLOPT_TIMEOUT;
|
||||
use const CURLOPT_USERAGENT;
|
||||
use const PHP_SAPI;
|
||||
|
||||
/**
|
||||
* Handles HTTP requests
|
||||
*/
|
||||
class HttpRequest
|
||||
{
|
||||
/** @var string */
|
||||
private $proxyUrl;
|
||||
|
||||
/** @var string */
|
||||
private $proxyUser;
|
||||
|
||||
/** @var string */
|
||||
private $proxyPass;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$this->proxyUrl = $cfg['ProxyUrl'];
|
||||
$this->proxyUser = $cfg['ProxyUser'];
|
||||
$this->proxyPass = $cfg['ProxyPass'];
|
||||
}
|
||||
|
||||
public static function setProxySettingsFromEnv(): void
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$httpProxy = getenv('http_proxy');
|
||||
$urlInfo = parse_url((string) $httpProxy);
|
||||
if (PHP_SAPI !== 'cli' || ! is_array($urlInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cfg['ProxyUrl'] = ($urlInfo['host'] ?? '')
|
||||
. (isset($urlInfo['port']) ? ':' . $urlInfo['port'] : '');
|
||||
$cfg['ProxyUser'] = $urlInfo['user'] ?? '';
|
||||
$cfg['ProxyPass'] = $urlInfo['pass'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information with regards to handling the http request
|
||||
*
|
||||
* @param array $context Data about the context for which
|
||||
* to http request is sent
|
||||
*
|
||||
* @return array of updated context information
|
||||
*/
|
||||
private function handleContext(array $context)
|
||||
{
|
||||
if (strlen($this->proxyUrl) > 0) {
|
||||
$context['http'] = [
|
||||
'proxy' => $this->proxyUrl,
|
||||
'request_fulluri' => true,
|
||||
];
|
||||
if (strlen($this->proxyUser) > 0) {
|
||||
$auth = base64_encode($this->proxyUser . ':' . $this->proxyPass);
|
||||
$context['http']['header'] = 'Proxy-Authorization: Basic '
|
||||
. $auth . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTTP request using curl
|
||||
*
|
||||
* @param mixed $response HTTP response
|
||||
* @param int $httpStatus HTTP response status code
|
||||
* @param bool $returnOnlyStatus If set to true, the method would only return response status
|
||||
*
|
||||
* @return string|bool|null
|
||||
*/
|
||||
private function response(
|
||||
$response,
|
||||
$httpStatus,
|
||||
$returnOnlyStatus
|
||||
) {
|
||||
if ($httpStatus == 404) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($httpStatus != 200) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($returnOnlyStatus) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTTP request using curl
|
||||
*
|
||||
* @param string $url Url to send the request
|
||||
* @param string $method HTTP request method (GET, POST, PUT, DELETE, etc)
|
||||
* @param bool $returnOnlyStatus If set to true, the method would only return response status
|
||||
* @param mixed $content Content to be sent with HTTP request
|
||||
* @param string $header Header to be set for the HTTP request
|
||||
*
|
||||
* @return string|bool|null
|
||||
*/
|
||||
private function curl(
|
||||
$url,
|
||||
$method,
|
||||
$returnOnlyStatus = false,
|
||||
$content = null,
|
||||
$header = ''
|
||||
) {
|
||||
$curlHandle = curl_init($url);
|
||||
if ($curlHandle === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$curlStatus = 1;
|
||||
if (strlen($this->proxyUrl) > 0) {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_PROXY, $this->proxyUrl);
|
||||
if (strlen($this->proxyUser) > 0) {
|
||||
$curlStatus &= (int) curl_setopt(
|
||||
$curlHandle,
|
||||
CURLOPT_PROXYUSERPWD,
|
||||
$this->proxyUser . ':' . $this->proxyPass
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_USERAGENT, 'phpMyAdmin');
|
||||
|
||||
if ($method !== 'GET') {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $method);
|
||||
}
|
||||
|
||||
if ($header) {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_HTTPHEADER, [$header]);
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $content);
|
||||
}
|
||||
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, true);
|
||||
|
||||
$caPathOrFile = CaBundle::getSystemCaRootBundlePath();
|
||||
if (is_dir($caPathOrFile)) {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAPATH, $caPathOrFile);
|
||||
} else {
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAINFO, $caPathOrFile);
|
||||
}
|
||||
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, 0);
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
|
||||
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
|
||||
if (! $curlStatus) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$response = @curl_exec($curlHandle);
|
||||
if ($response === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$httpStatus = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
|
||||
|
||||
return $this->response($response, $httpStatus, $returnOnlyStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTTP request using file_get_contents
|
||||
*
|
||||
* @param string $url Url to send the request
|
||||
* @param string $method HTTP request method (GET, POST, PUT, DELETE, etc)
|
||||
* @param bool $returnOnlyStatus If set to true, the method would only return response status
|
||||
* @param mixed $content Content to be sent with HTTP request
|
||||
* @param string $header Header to be set for the HTTP request
|
||||
*
|
||||
* @return string|bool|null
|
||||
*/
|
||||
private function fopen(
|
||||
$url,
|
||||
$method,
|
||||
$returnOnlyStatus = false,
|
||||
$content = null,
|
||||
$header = ''
|
||||
) {
|
||||
$context = [
|
||||
'http' => [
|
||||
'method' => $method,
|
||||
'request_fulluri' => true,
|
||||
'timeout' => 10,
|
||||
'user_agent' => 'phpMyAdmin',
|
||||
'header' => 'Accept: */*',
|
||||
],
|
||||
'ssl' => [
|
||||
'verify_peer' => true,
|
||||
'verify_peer_name' => true,
|
||||
],
|
||||
];
|
||||
if ($header) {
|
||||
$context['http']['header'] .= "\n" . $header;
|
||||
}
|
||||
|
||||
if ($method === 'POST') {
|
||||
$context['http']['content'] = $content;
|
||||
}
|
||||
|
||||
$caPathOrFile = CaBundle::getSystemCaRootBundlePath();
|
||||
if (is_dir($caPathOrFile)) {
|
||||
$context['ssl']['capath'] = $caPathOrFile;
|
||||
} else {
|
||||
$context['ssl']['cafile'] = $caPathOrFile;
|
||||
}
|
||||
|
||||
$context = $this->handleContext($context);
|
||||
$response = @file_get_contents(
|
||||
$url,
|
||||
false,
|
||||
stream_context_create($context)
|
||||
);
|
||||
|
||||
if (! isset($http_response_header)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
preg_match('#HTTP/[0-9\.]+\s+([0-9]+)#', $http_response_header[0], $out);
|
||||
$httpStatus = intval($out[1]);
|
||||
|
||||
return $this->response($response, $httpStatus, $returnOnlyStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates HTTP request
|
||||
*
|
||||
* @param string $url Url to send the request
|
||||
* @param string $method HTTP request method (GET, POST, PUT, DELETE, etc)
|
||||
* @param bool $returnOnlyStatus If set to true, the method would only return response status
|
||||
* @param mixed $content Content to be sent with HTTP request
|
||||
* @param string $header Header to be set for the HTTP request
|
||||
*
|
||||
* @return string|bool|null
|
||||
*/
|
||||
public function create(
|
||||
$url,
|
||||
$method,
|
||||
$returnOnlyStatus = false,
|
||||
$content = null,
|
||||
$header = ''
|
||||
) {
|
||||
if (function_exists('curl_init')) {
|
||||
return $this->curl($url, $method, $returnOnlyStatus, $content, $header);
|
||||
}
|
||||
|
||||
if (ini_get('allow_url_fopen')) {
|
||||
return $this->fopen($url, $method, $returnOnlyStatus, $content, $header);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Utils;
|
||||
|
||||
final class SessionCache
|
||||
{
|
||||
private static function key(): string
|
||||
{
|
||||
global $cfg, $server;
|
||||
|
||||
$key = 'server_' . $server;
|
||||
|
||||
if (isset($cfg['Server']['user'])) {
|
||||
return $key . '_' . $cfg['Server']['user'];
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
public static function has(string $name): bool
|
||||
{
|
||||
return isset($_SESSION['cache'][self::key()][$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function get(string $name, ?callable $defaultValueCallback = null)
|
||||
{
|
||||
if (self::has($name)) {
|
||||
return $_SESSION['cache'][self::key()][$name];
|
||||
}
|
||||
|
||||
if ($defaultValueCallback !== null) {
|
||||
$value = $defaultValueCallback();
|
||||
self::set($name, $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function set(string $name, $value): void
|
||||
{
|
||||
$_SESSION['cache'][self::key()][$name] = $value;
|
||||
}
|
||||
|
||||
public static function remove(string $name): void
|
||||
{
|
||||
unset($_SESSION['cache'][self::key()][$name]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue