mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Remove reboot and poweroff actions from the API
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -120,46 +120,6 @@ int api_action_gravity(struct ftl_conn *api)
|
||||
return run_and_stream_command(api, "/usr/local/bin/pihole", (const char *const []){ "pihole", "-g", NULL });
|
||||
}
|
||||
|
||||
int api_action_poweroff(struct ftl_conn *api)
|
||||
{
|
||||
if(!config.webserver.api.allow_destructive.v.b)
|
||||
return send_json_error(api, 403,
|
||||
"forbidden",
|
||||
"Power off is not allowed",
|
||||
"Check setting webserver.api.allow_destructive");
|
||||
|
||||
log_info("Received API request to power off the machine");
|
||||
// Sync filesystems and power off
|
||||
sync();
|
||||
// Needs capabiliy CAP_SYS_BOOT
|
||||
if(reboot(RB_POWER_OFF) != 0)
|
||||
return send_json_error(api, 500,
|
||||
"server_error",
|
||||
"Cannot power off the system, power off has been cancelled",
|
||||
strerror(errno));
|
||||
return send_json_success(api);
|
||||
}
|
||||
|
||||
int api_action_reboot(struct ftl_conn *api)
|
||||
{
|
||||
if(!config.webserver.api.allow_destructive.v.b)
|
||||
return send_json_error(api, 403,
|
||||
"forbidden",
|
||||
"Reboot is not allowed",
|
||||
"Check setting webserver.api.allow_destructive");
|
||||
|
||||
log_info("Received API request to reboot the machine");
|
||||
// Sync filesystems and reboot
|
||||
sync();
|
||||
// Needs capabiliy CAP_SYS_BOOT
|
||||
if(reboot(RB_AUTOBOOT) != 0)
|
||||
return send_json_error(api, 500,
|
||||
"server_error",
|
||||
"Cannot reboot the system, reboot has been cancelled",
|
||||
strerror(errno));
|
||||
return send_json_success(api);
|
||||
}
|
||||
|
||||
int api_action_restartDNS(struct ftl_conn *api)
|
||||
{
|
||||
if(!config.webserver.api.allow_destructive.v.b)
|
||||
|
||||
@@ -86,8 +86,6 @@ static struct {
|
||||
{ "/api/dhcp/leases", "", api_dhcp_leases_GET, { false, true, 0 }, true, HTTP_GET },
|
||||
{ "/api/dhcp/leases", "/{hwaddr}/{ip}/{clid}", api_dhcp_leases_DELETE, { false, true, 0 }, true, HTTP_DELETE },
|
||||
{ "/api/action/gravity", "", api_action_gravity, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/api/action/reboot", "", api_action_reboot, { false, true, 0 }, true, HTTP_POST },
|
||||
{ "/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 },
|
||||
|
||||
@@ -141,13 +141,6 @@ bool check_capabilities(void)
|
||||
log_warn("Required Linux capability CAP_CHOWN not available");
|
||||
capabilities_okay = false;
|
||||
}
|
||||
if (!(data->permitted & (1 << CAP_SYS_BOOT)) ||
|
||||
!(data->effective & (1 << CAP_SYS_BOOT)))
|
||||
{
|
||||
// Necessary to reboot/poweroff the system through the API
|
||||
log_warn("Required Linux capability CAP_SYS_BOOT not available");
|
||||
capabilities_okay = false;
|
||||
}
|
||||
|
||||
// Free allocated memory
|
||||
free(hdr);
|
||||
|
||||
Reference in New Issue
Block a user