Files
web/php/get.php
Adam Warner ee41a78bdd More codacy fixes (#256)
* single quotes to double

* Avoid variables with short names like $a. Configured minimum length is 3.

* list_type > listType https://www.codacy.com/app/Pi-hole/AdminLTE/file/4753758893/issues/source?bid=3919163&fileBranchId=3919163#l30

* define `refresh` before it is used

* single to double quotes

* EsLint expects `{}` after `if`

* singlequotes to doublequotes

* https://www.codacy.com/app/Pi-hole/AdminLTE/file/4753758894/issues/source?bid=3919163&fileBranchId=3919163#l49

* Copy filterArray Function from api.php

* missed a single-quote

* single>double

* `===`, `==`

* single to double

* Usages come AFTER declarations

* missing semi

* function delcaration order change

* more codacy complaints
2016-12-16 13:52:51 +00:00

34 lines
795 B
PHP

<?php
if(!isset($_GET['list']))
die();
$type = $_GET['list'];
if($type !== "white" && $type !== "black")
die("Invalid list parameter");
$rawList = file_get_contents("/etc/pihole/${type}list.txt");
$list = explode("\n", $rawList);
// Get rid of empty lines
for($i = sizeof($list)-1; $i >= 0; $i--) {
if($list[$i] == "")
unset($list[$i]);
}
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));