Skip to content

Commit

Permalink
Merge pull request #1295 from pi-hole/new/telnet_maxlogage
Browse files Browse the repository at this point in the history
Add >maxlogage telnet API endpoint
  • Loading branch information
DL6ER authored Feb 1, 2022
2 parents 01afc45 + a20d833 commit 61f72ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,3 +1495,9 @@ void getDNSport(const int *sock)
// Return DNS port used by FTL
ssend(*sock, "%d\n", config.dns_port);
}

void getMAXLOGAGE(const int *sock)
{
// Return maxlogage used by FTL
ssend(*sock, "%d\n", config.maxlogage);
}
1 change: 1 addition & 0 deletions src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void getClientID(const int *sock);
void getVersion(const int *sock);
void getDBstats(const int *sock);
void getUnknownQueries(const int *sock);
void getMAXLOGAGE(const int *sock);

// DNS resolver methods (dnsmasq_interface.c)
void getCacheInformation(const int *sock);
Expand Down
5 changes: 5 additions & 0 deletions src/api/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ void process_request(const char *client_message, int *sock)
processed = true;
getDNSport(sock);
}
else if(command(client_message, ">maxlogage"))
{
processed = true;
getMAXLOGAGE(sock);
}

// Test only at the end if we want to quit or kill
// so things can be processed before
Expand Down
9 changes: 8 additions & 1 deletion test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
[[ ${lines[6]} == "" ]]
}

@test "DNS server port is reported" {
@test "DNS server port is reported over Telnet API" {
run bash -c 'echo ">dns-port >quit" | nc -v 127.0.0.1 4711'
printf "%s\n" "${lines[@]}"
[[ ${lines[1]} == "53" ]]
[[ ${lines[2]} == "" ]]
}

@test "Maxlogage value is reported over Telnet API" {
run bash -c 'echo ">maxlogage >quit" | nc -v 127.0.0.1 4711'
printf "%s\n" "${lines[@]}"
[[ ${lines[1]} == "86400" ]]
[[ ${lines[2]} == "" ]]
}

@test "Running a second instance is detected and prevented" {
run bash -c 'su pihole -s /bin/sh -c "/home/pihole/pihole-FTL -f"'
printf "%s\n" "${lines[@]}"
Expand Down

0 comments on commit 61f72ad

Please sign in to comment.