Run PHP-CS-Fixer on all files

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2022-08-07 10:52:23 +02:00
parent 69e118ad45
commit 6ec4b8a529
47 changed files with 2643 additions and 2831 deletions

View File

@@ -7,12 +7,13 @@
* Please see LICENSE file for your rights under this license.
*/
const DEFAULT_FTLCONFFILE = "/etc/pihole/pihole-FTL.conf";
const DEFAULT_FTL_IP = "127.0.0.1";
const DEFAULT_FTLCONFFILE = '/etc/pihole/pihole-FTL.conf';
const DEFAULT_FTL_IP = '127.0.0.1';
const DEFAULT_FTL_PORT = 4711;
const DEFAULT_FTL_PORTFILE = "/run/pihole-FTL.port";
const DEFAULT_FTL_PORTFILE = '/run/pihole-FTL.port';
function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = false) {
function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = false)
{
static $piholeFTLConfig;
if (isset($piholeFTLConfig) && !$force) {
@@ -28,12 +29,13 @@ function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = fals
return $piholeFTLConfig;
}
function connectFTL($address, $port) {
if ($address == DEFAULT_FTL_IP) {
function connectFTL($address, $port)
{
if (DEFAULT_FTL_IP == $address) {
$config = piholeFTLConfig();
// Read port
$portfileName = isset($config['PORTFILE']) ? $config['PORTFILE'] : DEFAULT_FTL_PORTFILE;
if ($portfileName != '') {
if ('' != $portfileName) {
$portfileContents = file_get_contents($portfileName);
if (is_numeric($portfileContents)) {
$port = intval($portfileContents);
@@ -42,32 +44,32 @@ function connectFTL($address, $port) {
}
// Open Internet socket connection
$socket = @fsockopen($address, $port, $errno, $errstr, 1.0);
return $socket;
return @fsockopen($address, $port, $errno, $errstr, 1.0);
}
function sendRequestFTL($requestin, $socket) {
$request = ">".$requestin;
fwrite($socket, $request) or die('{"error":"Could not send data to server"}');
function sendRequestFTL($requestin, $socket)
{
$request = '>'.$requestin;
fwrite($socket, $request) or exit('{"error":"Could not send data to server"}');
}
function getResponseFTL($socket) {
$response = [];
function getResponseFTL($socket)
{
$response = array();
$errCount = 0;
while (true) {
$out = fgets($socket);
if ($out == "") {
$errCount++;
if ('' == $out) {
++$errCount;
}
if ($errCount > 100) {
// Tried 100 times, but never got proper reply, fail to prevent busy loop
die('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}');
exit('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}');
}
if (strrpos($out,"---EOM---") !== false) {
if (false !== strrpos($out, '---EOM---')) {
break;
}
@@ -80,22 +82,24 @@ function getResponseFTL($socket) {
return $response;
}
function disconnectFTL($socket) {
function disconnectFTL($socket)
{
if (is_resource($socket)) {
fclose($socket);
}
}
function callFTLAPI($request, $FTL_IP = DEFAULT_FTL_IP, $port = DEFAULT_FTL_PORT) {
function callFTLAPI($request, $FTL_IP = DEFAULT_FTL_IP, $port = DEFAULT_FTL_PORT)
{
$socket = connectFTL($FTL_IP, $port);
if (!is_resource($socket)) {
$data = array("FTLnotrunning" => true);
$data = array('FTLnotrunning' => true);
} else {
sendRequestFTL($request, $socket);
$data = getResponseFTL($socket);
}
disconnectFTL($socket);
return $data;
}
?>