Skip to content

Commit

Permalink
add api/shutdown and api/reboot (POST) rest endpoints (no authenticat…
Browse files Browse the repository at this point in the history
…ion!)
  • Loading branch information
mhwlng committed Dec 25, 2022
1 parent 8936c4f commit cce403e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ That means that the remote web server does not allow rendering inside an iframe.

You won't have this problem, if you define just one Kiosk URL.

There is also a rest api endpoint (http://x.x.x.x:5000/api/status) that returns a JSON object, containing system status data.
There is also a (GET) rest api endpoint (http://x.x.x.x:5000/api/status) that returns a JSON object, containing system status data.

There are also (POST) rest api endpoints (http://x.x.x.x:5000/api/shutdown and http://x.x.x.x:5000/api/reboot) NOTE that there is no authentication!

![touch screen](https://i.imgur.com/Wzp5kqm.png)

Expand Down Expand Up @@ -329,7 +331,7 @@ Note, that this only works correctly, if you hide the sidebar by default, for th

![home assistant](https://i.imgur.com/pKVELn4.png)

## transfer system status data to home assistant
## Transfer system status data to Home Assistant

```
- platform: rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using kiosk_server.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Xml.Linq;

namespace kiosk_server.Api
{
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class StatusController : ControllerBase
public class ApiController : ControllerBase
{
private class StatusData
{
Expand All @@ -19,6 +19,7 @@ private class StatusData
public CpuMetrics Cpu { get; set; } = default!;
}

[Route("api/status")]
[HttpGet]
public IActionResult Get()
{
Expand All @@ -31,5 +32,24 @@ public IActionResult Get()
};
return Ok(statusData);
}

[Route("api/shutdown")]
[HttpPost]
public IActionResult Shutdown()
{
System.Diagnostics.Process.Start(new ProcessStartInfo() { FileName = "sudo", Arguments = "shutdown now" });

return Ok();
}

[Route("api/reboot")]

[HttpPost]
public IActionResult Reboot()
{
System.Diagnostics.Process.Start(new ProcessStartInfo() { FileName = "sudo", Arguments = "reboot now" });

return Ok();
}
}
}
6 changes: 3 additions & 3 deletions kiosk-server/kiosk-server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PreBuildEvent>
</PreBuildEvent>
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
<Version>0.0.0.8</Version>
<Version>0.0.0.9</Version>
<Copyright>Copyright © 2022</Copyright>
<Company />
<Authors />
<AssemblyVersion>0.0.0.8</AssemblyVersion>
<FileVersion>0.0.0.8</FileVersion>
<AssemblyVersion>0.0.0.9</AssemblyVersion>
<FileVersion>0.0.0.9</FileVersion>
</PropertyGroup>

<Target Name="PiCopy" AfterTargets="AfterPublish">
Expand Down

0 comments on commit cce403e

Please sign in to comment.