Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRD WebDesign <github@rdwebdesign.com.br>2022-03-24 00:33:15 +0300
committerRD WebDesign <github@rdwebdesign.com.br>2022-03-24 00:33:15 +0300
commitc9809371abf89efe4f39c25170773eb2a5f39929 (patch)
treed05196d8b7691d01a683299107c1ed08f1ac86b2
parenta48750e257f2a7a3869008bc680de2a29353da21 (diff)
Selecting the protocol
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
-rw-r--r--advanced/index.php27
1 files changed, 21 insertions, 6 deletions
diff --git a/advanced/index.php b/advanced/index.php
index 95afcdff..054e8063 100644
--- a/advanced/index.php
+++ b/advanced/index.php
@@ -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);