Skip to content

Commit cce403e

Browse files
committed
add api/shutdown and api/reboot (POST) rest endpoints (no authentication!)
1 parent 8936c4f commit cce403e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ That means that the remote web server does not allow rendering inside an iframe.
2626

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

29-
There is also a rest api endpoint (http://x.x.x.x:5000/api/status) that returns a JSON object, containing system status data.
29+
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.
30+
31+
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!
3032

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

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

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

332-
## transfer system status data to home assistant
334+
## Transfer system status data to Home Assistant
333335

334336
```
335337
- platform: rest

kiosk-server/Api/StatusController.cs kiosk-server/Api/ApiController.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using kiosk_server.Model;
33
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Mvc;
5+
using System.Diagnostics;
56
using System.Xml.Linq;
67

78
namespace kiosk_server.Api
89
{
9-
[Route("api/[controller]")]
1010
[ApiController]
1111
[AllowAnonymous]
12-
public class StatusController : ControllerBase
12+
public class ApiController : ControllerBase
1313
{
1414
private class StatusData
1515
{
@@ -19,6 +19,7 @@ private class StatusData
1919
public CpuMetrics Cpu { get; set; } = default!;
2020
}
2121

22+
[Route("api/status")]
2223
[HttpGet]
2324
public IActionResult Get()
2425
{
@@ -31,5 +32,24 @@ public IActionResult Get()
3132
};
3233
return Ok(statusData);
3334
}
35+
36+
[Route("api/shutdown")]
37+
[HttpPost]
38+
public IActionResult Shutdown()
39+
{
40+
System.Diagnostics.Process.Start(new ProcessStartInfo() { FileName = "sudo", Arguments = "shutdown now" });
41+
42+
return Ok();
43+
}
44+
45+
[Route("api/reboot")]
46+
47+
[HttpPost]
48+
public IActionResult Reboot()
49+
{
50+
System.Diagnostics.Process.Start(new ProcessStartInfo() { FileName = "sudo", Arguments = "reboot now" });
51+
52+
return Ok();
53+
}
3454
}
3555
}

kiosk-server/kiosk-server.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<PreBuildEvent>
1313
</PreBuildEvent>
1414
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
15-
<Version>0.0.0.8</Version>
15+
<Version>0.0.0.9</Version>
1616
<Copyright>Copyright © 2022</Copyright>
1717
<Company />
1818
<Authors />
19-
<AssemblyVersion>0.0.0.8</AssemblyVersion>
20-
<FileVersion>0.0.0.8</FileVersion>
19+
<AssemblyVersion>0.0.0.9</AssemblyVersion>
20+
<FileVersion>0.0.0.9</FileVersion>
2121
</PropertyGroup>
2222

2323
<Target Name="PiCopy" AfterTargets="AfterPublish">

0 commit comments

Comments
 (0)