mirror of
https://github.com/pi-hole/web.git
synced 2025-12-24 20:55:28 +00:00
- Fix multiple php warning/error messages when this scripts are executed from AJAX requests Example errors/warnings: 2019/01/15 13:22:22 [error] 1408#1408: *2535 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable: api in /var/www/html/admin/scripts/pi-hole/php/sub.php on line 16 PHP message: PHP Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/scripts/pi-hole/php/sub.php:8) in /var/www/html/admin/scripts/pi-hole/php/auth.php on line 81 PHP message: PHP Warning: session_start(): Cannot start session when headers already sent in /var/www/html/admin/scripts/pi-hole/php/auth.php on line 93 Signed-off-by: Michael Epstein <mepstein@mediabox.cl>
68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
/* Pi-hole: A black hole for Internet advertisements
|
|
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
* Network-wide ad blocking via your own hardware.
|
|
*
|
|
* This file is copyright under the latest version of the EUPL.
|
|
* Please see LICENSE file for your rights under this license. */
|
|
|
|
if(!isset($_GET['list']))
|
|
die("Missing parameter");
|
|
|
|
$listtype = $_GET['list'];
|
|
|
|
$basedir = "/etc/pihole/";
|
|
|
|
require_once "func.php";
|
|
|
|
switch ($listtype) {
|
|
case "white":
|
|
$list = array(getListContent("whitelist.txt"));
|
|
break;
|
|
|
|
case "black":
|
|
$exact = getListContent("blacklist.txt");
|
|
$regex = getListContent("regex.list");
|
|
$list = array($exact, $regex);
|
|
break;
|
|
|
|
default:
|
|
die("Invalid list parameter");
|
|
break;
|
|
}
|
|
|
|
|
|
function getListContent($listname) {
|
|
global $basedir;
|
|
$rawList = file_get_contents(checkfile($basedir.$listname));
|
|
$list = explode("\n", $rawList);
|
|
|
|
// Get rid of empty lines and comments
|
|
for($i = sizeof($list)-1; $i >= 0; $i--) {
|
|
if(strlen($list[$i]) < 1 || $list[$i][0] === '#')
|
|
unset($list[$i]);
|
|
}
|
|
|
|
// Re-index list after possible unset() activity
|
|
$newlist = array_values($list);
|
|
|
|
return $newlist;
|
|
|
|
}
|
|
|
|
function filterArray(&$inArray) {
|
|
$outArray = array();
|
|
foreach ($inArray as $key=>$value) {
|
|
if (is_array($value)) {
|
|
$outArray[htmlspecialchars($key)] = filterArray($value);
|
|
} else {
|
|
$outArray[htmlspecialchars($key)] = htmlspecialchars($value);
|
|
}
|
|
}
|
|
return $outArray;
|
|
}
|
|
|
|
// Protect against XSS attacks
|
|
$list = filterArray($list);
|
|
echo json_encode(array_values($list));
|