mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Selecting the protocol
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
parent
a48750e257
commit
c9809371ab
1 changed files with 21 additions and 6 deletions
|
@ -164,19 +164,34 @@ ini_set("default_socket_timeout", 3);
|
|||
function queryAds($serverName) {
|
||||
// Determine the time it takes while querying adlists
|
||||
$preQueryTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"];
|
||||
|
||||
// Determine which protocol should be used
|
||||
$protocol = "http";
|
||||
if (
|
||||
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ||
|
||||
(isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') ||
|
||||
(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
|
||||
) {
|
||||
$protocol = "https";
|
||||
}
|
||||
|
||||
// Format the URL
|
||||
$queryAdsURL = sprintf(
|
||||
"http://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp",
|
||||
"%s://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp",
|
||||
$protocol,
|
||||
$_SERVER["SERVER_PORT"],
|
||||
$serverName
|
||||
);
|
||||
$queryAds = file($queryAdsURL, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
// $queryAds must be an array (to avoid PHP 8.0+ error)
|
||||
if (is_array($queryAds)) {
|
||||
$queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAds)));
|
||||
// Request the file and receive the response
|
||||
$queryAdsFile = file($queryAdsURL, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
// $queryAdsFile must be an array (to avoid PHP 8.0+ error)
|
||||
if (is_array($queryAdsFile)) {
|
||||
$queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAdsFile)));
|
||||
} else {
|
||||
// if not an array, return an error message
|
||||
return array("0" => "error", "1" => "Not an array:<br>(".gettype($queryAds).")<br>".print_r($queryAds, true));
|
||||
return array("0" => "error", "1" => "<br>Not an array: (".gettype($queryAdsFile).")<br>".print_r($queryAdsFile, true));
|
||||
}
|
||||
|
||||
$queryTime = sprintf("%.0f", (microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]) - $preQueryTime);
|
||||
|
|
Loading…
Reference in a new issue