mirror of
https://github.com/pi-hole/web.git
synced 2026-04-24 02:39:25 +01:00
Squashed commit of the following:
- Dynamically fall back to PHP API functions to ensure API does always repond even if FTL is not runnung for some reason - Update PHP API from current devel branch - Increase flexibility in getQueryTypes API call - Hide top ads list if nothing to display - Proper display of activated privacy mode - Remove spinner (would otherwise not be removed for zero results) - Update tables every 10 seconds - Update query types and forward destinations plots every 10 seconds - More verbose output in top lists (total number next to percentage in tooltip) - Implemented "recentBlocked" keyword for API - Ensure compatibility with PHP5 version < 5.4 - Adjust output format of overTimeData10mins to comply with PHP API - Further speedup of Query Log page by showing only the recent 10 minutes by default - Hide temperature if FTL is not running and show FTL status - Add information to Settings page - Adjust error message when loading of query log failed - Move processing of domainname, clientIP, clientname and time interval filters for the Query Log page to FTL for speed enhancement - Generate link if pi.hole comes up in the Top Domains list - Remove resolve DNS names option - this is now enabled by default (daemon will only do it once per day instead of PHP-API which did it on every reloading of the web interface) - Add socket timeout of 10 seconds + modification to Settings page since FTL backend supports API_EXCLUDE_CLIENTS filtering with both IP addresses and host names (also mixed) - Improved Query Log page
This commit is contained in:
103
scripts/pi-hole/php/FTL.php
Normal file
103
scripts/pi-hole/php/FTL.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
function testFTL()
|
||||
{
|
||||
return (strpos(exec("ps -p `cat /var/run/pihole-FTL.pid` -o comm="), "pihole-FTL") !== false);
|
||||
}
|
||||
|
||||
function connectFTL($address, $port=4711, $quiet=true)
|
||||
{
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "Attempting to connect to '$address' on port '$port'...\n";
|
||||
}
|
||||
|
||||
if($address == "127.0.0.1")
|
||||
{
|
||||
// Read port
|
||||
$portfile = file_get_contents("/var/run/pihole-FTL.port");
|
||||
if(is_numeric($portfile))
|
||||
$port = intval($portfile);
|
||||
}
|
||||
|
||||
// Create a TCP/IP socket
|
||||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)
|
||||
or die("socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n");
|
||||
|
||||
$result = socket_connect($socket, $address, $port)
|
||||
or die("socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n");
|
||||
|
||||
// Set timeout to 10 seconds
|
||||
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec'=>10, 'usec'=>0]);
|
||||
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, ['sec'=>10, 'usec'=>0]);
|
||||
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "Success!\n\n";
|
||||
}
|
||||
|
||||
return $socket;
|
||||
}
|
||||
function sendRequestFTL($requestin, $quiet=true)
|
||||
{
|
||||
global $socket;
|
||||
|
||||
$request = ">".$requestin;
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "Sending request (".$request.")...\n";
|
||||
}
|
||||
|
||||
socket_write($socket, $request, strlen($request)) or die("Could not send data to server\n");
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "OK.\n";
|
||||
}
|
||||
}
|
||||
|
||||
function getResponseFTL($quiet=true)
|
||||
{
|
||||
global $socket;
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "Reading response:\n";
|
||||
}
|
||||
|
||||
$response = [];
|
||||
|
||||
while(true)
|
||||
{
|
||||
$out = socket_read($socket, 2048, PHP_NORMAL_READ);
|
||||
if(!$quiet)
|
||||
{
|
||||
echo $out;
|
||||
}
|
||||
if(strrpos($out,"---EOM---") !== false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
$out = rtrim($out);
|
||||
if(strlen($out) > 0)
|
||||
{
|
||||
$response[] = $out;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function disconnectFTL($quiet=true)
|
||||
{
|
||||
global $socket;
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "Closing socket...";
|
||||
}
|
||||
|
||||
socket_close($socket);
|
||||
|
||||
if(!$quiet)
|
||||
{
|
||||
echo "OK.\n\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user