Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get port number directly from pihole-FTL.conf #2371

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions scripts/pi-hole/php/FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down