mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Add /api/action/flush/arp flushing both the network and network_addresses tables in pihole-FTL.db
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
+16
-1
@@ -17,9 +17,10 @@
|
||||
// reboot()
|
||||
#include <sys/reboot.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// exit_code
|
||||
#include "signals.h"
|
||||
// flush_network_table()
|
||||
#include "database/network-table.h"
|
||||
|
||||
static int run_and_stream_command(struct ftl_conn *api, const char *path, const char *const args[])
|
||||
{
|
||||
@@ -172,3 +173,17 @@ int api_action_flush_logs(struct ftl_conn *api)
|
||||
"Cannot flush the logs",
|
||||
NULL);
|
||||
}
|
||||
|
||||
int api_action_flush_arp(struct ftl_conn *api)
|
||||
{
|
||||
log_info("Received API request to flush the ARP cache");
|
||||
|
||||
// Flush the ARP cache
|
||||
if(flush_network_table())
|
||||
return send_json_success(api);
|
||||
else
|
||||
return send_json_error(api, 500,
|
||||
"server_error",
|
||||
"Cannot flush the ARP cache",
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ static struct {
|
||||
{ "/api/action/poweroff", "", api_action_poweroff, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/api/action/restartdns", "", api_action_restartDNS, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/api/action/flush/logs", "", api_action_flush_logs, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/api/action/flush/arp", "", api_action_flush_arp, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/api/docs", "", api_docs, { false, true, 0 }, false, HTTP_GET },
|
||||
};
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ int api_action_poweroff(struct ftl_conn *api);
|
||||
int api_action_reboot(struct ftl_conn *api);
|
||||
int api_action_restartDNS(struct ftl_conn *api);
|
||||
int api_action_flush_logs(struct ftl_conn *api);
|
||||
int api_action_flush_arp(struct ftl_conn *api);
|
||||
|
||||
// Search methods
|
||||
int api_search(struct ftl_conn *api);
|
||||
|
||||
@@ -163,3 +163,28 @@ components:
|
||||
allOf:
|
||||
- $ref: 'common.yaml#/components/errors/unauthorized'
|
||||
- $ref: 'common.yaml#/components/schemas/took'
|
||||
flush_arp:
|
||||
post:
|
||||
summary: Flush the network table
|
||||
tags:
|
||||
- Actions
|
||||
operationId: "action_flusharp"
|
||||
description: |
|
||||
Flushes the network table. This includes emptying the ARP table and removing both all known devices and their associated addresses.
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: 'common.yaml#/components/schemas/success'
|
||||
- $ref: 'common.yaml#/components/schemas/took'
|
||||
'401':
|
||||
description: Unauthorized
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: 'common.yaml#/components/errors/unauthorized'
|
||||
- $ref: 'common.yaml#/components/schemas/took'
|
||||
|
||||
@@ -233,6 +233,9 @@ paths:
|
||||
/action/flush/logs:
|
||||
$ref: 'action.yaml#/components/paths/flush_logs'
|
||||
|
||||
/action/flush/arp:
|
||||
$ref: 'action.yaml#/components/paths/flush_arp'
|
||||
|
||||
/action/reboot:
|
||||
$ref: 'action.yaml#/components/paths/reboot'
|
||||
|
||||
|
||||
@@ -1218,6 +1218,26 @@ static bool clean_network_table(sqlite3* db)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flush_network_table(void)
|
||||
{
|
||||
sqlite3 *db = dbopen(false, false);
|
||||
if(db == NULL)
|
||||
return false;
|
||||
|
||||
// Remove all IP addresses
|
||||
if(dbquery(db, "DELETE FROM network_addresses;") != SQLITE_OK)
|
||||
return false;
|
||||
|
||||
// Remove all devices
|
||||
if(dbquery(db, "DELETE FROM network;") != SQLITE_OK)
|
||||
return false;
|
||||
|
||||
// Close database
|
||||
dbclose(&db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse kernel's neighbor cache
|
||||
void parse_neighbor_cache(sqlite3* db)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@ int getAliasclientIDfromIP(sqlite3 *db, const char *ipaddr);
|
||||
char* __attribute__((malloc)) getNameFromIP(sqlite3 *db, const char* ipaddr);
|
||||
char* __attribute__((malloc)) getIfaceFromIP(sqlite3 *db, const char* ipaddr);
|
||||
void resolveNetworkTableNames(void);
|
||||
bool flush_network_table(void);
|
||||
|
||||
typedef struct {
|
||||
unsigned int id;
|
||||
|
||||
Reference in New Issue
Block a user