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

Remove reboot and poweroff actions from the API #1606

Merged
merged 1 commit into from Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 0 additions & 40 deletions src/api/action.c
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/api/api.c
Expand Up @@ -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 },
Expand Down
7 changes: 0 additions & 7 deletions src/capabilities.c
Expand Up @@ -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);
Expand Down