From 5c2d2f34466ca142f35a980c0bbd428f00d22445 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 21 Sep 2022 18:59:09 -0300 Subject: [PATCH] Get port number directly from `pihole-FTL.conf` - Remove the code using FTL portfile - code simplification Signed-off-by: RD WebDesign --- scripts/pi-hole/php/FTL.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index ac7ecee8d..5a60d76de 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -10,7 +10,6 @@ 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'; function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = false) { @@ -29,18 +28,19 @@ function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = fals return $piholeFTLConfig; } -function connectFTL($address, $port) +function connectFTL() { - if ($address == DEFAULT_FTL_IP) { - $config = piholeFTLConfig(); - // Read port - $portfileName = isset($config['PORTFILE']) ? $config['PORTFILE'] : DEFAULT_FTL_PORTFILE; - if ($portfileName != '') { - $portfileContents = file_get_contents($portfileName); - if (is_numeric($portfileContents)) { - $port = intval($portfileContents); - } - } + // We only use the default IP + $address = DEFAULT_FTL_IP; + + // Try to read port from FTL config. Use default if not found. + $config = piholeFTLConfig(); + + // Use the port only if the value is numeric + if (isset($config['FTLPORT']) && is_numeric($config['FTLPORT'])) { + $port = intval($config['FTLPORT']); + } else { + $port = DEFAULT_FTL_PORT; } // Open Internet socket connection @@ -89,9 +89,9 @@ function disconnectFTL($socket) } } -function callFTLAPI($request, $FTL_IP = DEFAULT_FTL_IP, $port = DEFAULT_FTL_PORT) +function callFTLAPI($request) { - $socket = connectFTL($FTL_IP, $port); + $socket = connectFTL(); if (!is_resource($socket)) { $data = array('FTLnotrunning' => true);