├── kiosk-server ├── Pages │ ├── Blank.razor.css │ ├── kiosk.razor.css │ ├── Blank.razor │ ├── Blank.razor.cs │ ├── _Host.cshtml │ ├── Error.cshtml.cs │ ├── Index.razor │ ├── Error.cshtml │ ├── Kiosk.razor │ ├── Kiosk.razor.cs │ ├── _Layout.cshtml │ ├── Index.razor.cs │ ├── Setup.razor.cs │ └── Setup.razor ├── Shared │ ├── EmptyLayout.razor.css │ ├── MainLayout.razor.css │ ├── EmptyLayout.razor │ ├── EmptyLayout.razor.cs │ ├── MainLayout.razor │ └── MainLayout.razor.cs ├── ILLink.Descriptors.xml ├── wwwroot │ ├── css │ │ └── site.css │ ├── favicon.ico │ ├── icons │ │ ├── icon-192.png │ │ ├── icon-512.png │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── mstile-150x150.png │ │ ├── apple-touch-icon.png │ │ └── browserconfig.xml │ └── manifest.json ├── appsettings.Development.json ├── .config │ └── dotnet-tools.json ├── Model │ └── SetupModel.cs ├── _Imports.razor ├── kiosk-server.service ├── App.razor ├── Services │ ├── MyEventService.cs │ └── LayoutService.cs ├── Properties │ ├── launchSettings.json │ └── PublishProfiles │ │ └── FolderProfile.pubxml ├── appsettings.json ├── Metrics │ ├── DiskMetrics.cs │ ├── MemoryMetrics.cs │ ├── CPUMetrics.cs │ └── TemperatureMetrics.cs ├── kiosk-server.csproj ├── Api │ └── ApiController.cs └── Program.cs ├── LICENSE.txt ├── kiosk-server.sln ├── .gitattributes ├── .gitignore └── README.md /kiosk-server/Pages/Blank.razor.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /kiosk-server/Pages/kiosk.razor.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /kiosk-server/Shared/EmptyLayout.razor.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /kiosk-server/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /kiosk-server/ILLink.Descriptors.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Blank.razor: -------------------------------------------------------------------------------- 1 | @page "/blank" 2 | @layout EmptyLayout 3 | 4 | -------------------------------------------------------------------------------- /kiosk-server/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .hideme { 5 | display: none; 6 | } 7 | -------------------------------------------------------------------------------- /kiosk-server/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/favicon.ico -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/icon-192.png -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/icon-512.png -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/favicon-16x16.png -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/favicon-32x32.png -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/mstile-150x150.png -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mhwlng/kiosk-server/HEAD/kiosk-server/wwwroot/icons/apple-touch-icon.png -------------------------------------------------------------------------------- /kiosk-server/Pages/Blank.razor.cs: -------------------------------------------------------------------------------- 1 | namespace kiosk_server.Pages 2 | { 3 | public partial class Blank 4 | { 5 | 6 | 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /kiosk-server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /kiosk-server/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @namespace kiosk_server.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | @{ 5 | Layout = "_Layout"; 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /kiosk-server/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "6.0.9", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /kiosk-server/wwwroot/icons/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #373740 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /kiosk-server/Model/SetupModel.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Metrics; 2 | 3 | namespace kiosk_server.Model 4 | { 5 | public class SetupModel 6 | { 7 | public DiskMetrics Disk { get; set; } = null!; 8 | public TemperatureMetrics Temperature { get; set; } = null!; 9 | public MemoryMetrics Memory { get; set; } = null!; 10 | public CpuMetrics Cpu { get; set; } = null!; 11 | 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /kiosk-server/Shared/EmptyLayout.razor: -------------------------------------------------------------------------------- 1 | @using kiosk_server.Services 2 | @inherits LayoutComponentBase 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @Body 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /kiosk-server/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using MudBlazor 10 | @using kiosk_server 11 | @using kiosk_server.Shared 12 | -------------------------------------------------------------------------------- /kiosk-server/kiosk-server.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Kiosk Server 3 | Wants=network-online.target 4 | After=network.target network-online.target 5 | 6 | [Service] 7 | Type=notify 8 | WorkingDirectory=/home/pi/kiosk-server/ 9 | ExecStart=/home/pi/kiosk-server/kiosk-server 10 | SyslogIdentifier=KioskServer 11 | User=pi 12 | Environment=ASPNETCORE_ENVIRONMENT=Production 13 | Restart=always 14 | RestartSec=5 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | -------------------------------------------------------------------------------- /kiosk-server/wwwroot/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Kiosk Server", 3 | "short_name": "Kiosk Server", 4 | "start_url": "/", 5 | "display": "standalone", 6 | "background_color": "#373740", 7 | "theme_color": "#373740", 8 | "icons": [ 9 | { 10 | "src": "/icons/icon-192.png", 11 | "type": "image/png", 12 | "sizes": "192x192" 13 | }, 14 | { 15 | "src": "/icons/icon-512.png", 16 | "type": "image/png", 17 | "sizes": "512x512" 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /kiosk-server/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /kiosk-server/Services/MyEventService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) MudBlazor 2021 2 | // MudBlazor licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | namespace kiosk_server.Services 6 | { 7 | public class MyEventService 8 | { 9 | public event Action OnUrlChange = null!; 10 | 11 | public void NavigateToUrl(string? url) 12 | { 13 | OnUrlChange?.Invoke(url); 14 | 15 | } 16 | 17 | 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | using System.Diagnostics; 4 | 5 | namespace kiosk_server.Pages 6 | { 7 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 8 | [IgnoreAntiforgeryToken] 9 | public class ErrorModel(ILogger logger) : PageModel 10 | { 11 | public string? RequestId { get; set; } 12 | 13 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 14 | 15 | private readonly ILogger _logger = logger; 16 | 17 | public void OnGet() 18 | { 19 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /kiosk-server/Shared/EmptyLayout.razor.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Services; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace kiosk_server.Shared 5 | { 6 | public partial class EmptyLayout 7 | { 8 | [Inject] private LayoutService LayoutService { get; set; } = null!; 9 | 10 | protected override void OnInitialized() 11 | { 12 | LayoutService.MajorUpdateOccured += LayoutServiceOnMajorUpdateOccured; 13 | base.OnInitialized(); 14 | } 15 | 16 | public void Dispose() 17 | { 18 | LayoutService.MajorUpdateOccured -= LayoutServiceOnMajorUpdateOccured; 19 | } 20 | 21 | private void LayoutServiceOnMajorUpdateOccured(object? sender, EventArgs e) => StateHasChanged(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /kiosk-server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:21050", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "kiosk-server": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "externalUrlConfiguration": true, 16 | "applicationUrl": "http://localhost:5000", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /kiosk-server/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @using kiosk_server.Services 2 | @inherits LayoutComponentBase 3 | 4 | 5 | 6 | @Title 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | @Title 15 | 16 | 17 | 18 | 19 | @Body 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /kiosk-server/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | true 8 | false 9 | true 10 | Release 11 | Any CPU 12 | FileSystem 13 | bin\Release\net10.0\publish\ 14 | FileSystem 15 | <_TargetId>Folder 16 | 17 | net10.0 18 | linux-arm64 19 | false 20 | 2fb23800-8c51-41de-b9e9-ec0b28be1a28 21 | true 22 | 23 | -------------------------------------------------------------------------------- /kiosk-server/Shared/MainLayout.razor.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Services; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace kiosk_server.Shared 5 | { 6 | public partial class MainLayout 7 | { 8 | [Inject] private LayoutService LayoutService { get; set; } = null!; 9 | 10 | private string? _title; 11 | 12 | public string Title 13 | { 14 | get => _title ?? ""; 15 | set 16 | { 17 | _title = value ?? ""; 18 | InvokeAsync(StateHasChanged); 19 | } 20 | } 21 | protected override void OnInitialized() 22 | { 23 | LayoutService.MajorUpdateOccured += LayoutServiceOnMajorUpdateOccured; 24 | base.OnInitialized(); 25 | } 26 | 27 | public void Dispose() 28 | { 29 | LayoutService.MajorUpdateOccured -= LayoutServiceOnMajorUpdateOccured; 30 | } 31 | 32 | private void LayoutServiceOnMajorUpdateOccured(object? sender, EventArgs e) => StateHasChanged(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | External Urls 11 | 12 | 13 | 14 | @foreach (var url in WebServerUrls) 15 | { 16 | 17 | 18 | @url 19 | 20 | 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | Kiosk Urls 29 | 30 | 31 | 32 | @foreach (var url in RedirectUrlList) 33 | { 34 | 35 | 36 | @url.Name 37 | 38 | 39 | @url.Url 40 | 41 | 42 | } 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 mhwlng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /kiosk-server.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32901.215 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "kiosk-server", "kiosk-server\kiosk-server.csproj", "{2FB23800-8C51-41DE-B9E9-EC0B28BE1A28}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2FB23800-8C51-41DE-B9E9-EC0B28BE1A28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2FB23800-8C51-41DE-B9E9-EC0B28BE1A28}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2FB23800-8C51-41DE-B9E9-EC0B28BE1A28}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2FB23800-8C51-41DE-B9E9-EC0B28BE1A28}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {3C7448DC-FF88-4BA1-A122-5D60A1CD7B6C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /kiosk-server/Services/LayoutService.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace kiosk_server.Services 4 | { 5 | public class LayoutService 6 | { 7 | public static bool IsDarkMode => Program.ConfigurationRoot.GetValue("DarkMode"); 8 | 9 | public event EventHandler MajorUpdateOccured = null!; 10 | 11 | private void OnMajorUpdateOccured() => MajorUpdateOccured?.Invoke(this, EventArgs.Empty); 12 | 13 | private static async Task UpdateAppSettings(bool darkMode) 14 | { 15 | #if DEBUG 16 | var path = Path.Combine(Environment.CurrentDirectory, "appsettings.json"); 17 | #else 18 | var path = Path.Combine(AppContext.BaseDirectory, "appsettings.json"); 19 | #endif 20 | 21 | var configJson = await File.ReadAllTextAsync(path); 22 | var config = JsonSerializer.Deserialize>(configJson); 23 | 24 | if (config != null) 25 | { 26 | config["DarkMode"] = darkMode; 27 | 28 | var updatedConfigJson = 29 | JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); 30 | await File.WriteAllTextAsync(path, updatedConfigJson); 31 | 32 | Program.ConfigurationRoot.Reload(); 33 | } 34 | } 35 | 36 | public async Task ToggleDarkMode() 37 | { 38 | await UpdateAppSettings(!IsDarkMode); 39 | 40 | OnMajorUpdateOccured(); 41 | } 42 | 43 | 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model kiosk_server.Pages.ErrorModel 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Error 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Error.

19 |

An error occurred while processing your request.

20 | 21 | @if (Model.ShowRequestId) 22 | { 23 |

24 | Request ID: @Model.RequestId 25 |

26 | } 27 | 28 |

Development Mode

29 |

30 | Swapping to the Development environment displays detailed information about the error that occurred. 31 |

32 |

33 | The Development environment shouldn't be enabled for deployed applications. 34 | It can result in displaying sensitive information from exceptions to end users. 35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 36 | and restarting the app. 37 |

38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /kiosk-server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information", 7 | "Microsoft.AspNetCore": "Warning" 8 | } 9 | }, 10 | "DarkMode": true, 11 | "AllowedHosts": "*", 12 | "Port": 5000, 13 | "RedirectUrl": [ 14 | { 15 | "Name": "home", 16 | "Url": "https://www.msn.com" 17 | } 18 | ], 19 | "Serilog": { 20 | "Using": [ 21 | "Serilog.Sinks.File" 22 | ], 23 | "MinimumLevel": { 24 | "Default": "Information", 25 | "Override": { 26 | "Microsoft": "Warning", 27 | "Microsoft.Hosting.Lifetime": "Information" 28 | } 29 | }, 30 | "WriteTo": [ 31 | { 32 | "Name": "File", 33 | "Args": { 34 | "path": "log.txt", 35 | "fileSizeLimitBytes": "1000000", 36 | "rollOnFileSizeLimit": "True", 37 | "retainedFileCountLimit": "10", 38 | "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} ({ThreadID}) [{Level}] {Message}{NewLine}{Exception}" 39 | } 40 | } 41 | ], 42 | "Enrich": [ 43 | "FromLogContext", 44 | "WithMachineName", 45 | "WithThreadId" 46 | ], 47 | "Destructure": [ 48 | { 49 | "Name": "ToMaximumDepth", 50 | "Args": { 51 | "maximumDestructuringDepth": 4 52 | } 53 | }, 54 | { 55 | "Name": "ToMaximumStringLength", 56 | "Args": { 57 | "maximumStringLength": 100 58 | } 59 | }, 60 | { 61 | "Name": "ToMaximumCollectionCount", 62 | "Args": { 63 | "maximumCollectionCount": 10 64 | } 65 | } 66 | ] 67 | } 68 | } -------------------------------------------------------------------------------- /kiosk-server/Metrics/DiskMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace kiosk_server.Metrics 4 | { 5 | public class DiskMetrics 6 | { 7 | public double TotalDiskSpace { get; set; } 8 | public double AvailableDiskSpace { get; set; } 9 | 10 | 11 | } 12 | 13 | public class DiskMetricsClient 14 | { 15 | public static DiskMetrics GetMetrics() 16 | { 17 | return IsLinux() ? GetLinuxMetrics() : GetWindowsMetrics(); 18 | } 19 | 20 | private static bool IsLinux() 21 | { 22 | var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || 23 | RuntimeInformation.IsOSPlatform(OSPlatform.Linux); 24 | 25 | return isLinux; 26 | } 27 | 28 | private static DiskMetrics GetWindowsMetrics() 29 | { 30 | var metrics = new DiskMetrics(); 31 | 32 | var f = new FileInfo(AppContext.BaseDirectory); 33 | var drive = Path.GetPathRoot(f.FullName); 34 | 35 | var driveInfo = new DriveInfo(drive ?? "c:\\"); 36 | metrics.AvailableDiskSpace = driveInfo.AvailableFreeSpace / Math.Pow(1024, 3); 37 | metrics.TotalDiskSpace = driveInfo.TotalSize / Math.Pow(1024, 3); 38 | 39 | return metrics; 40 | } 41 | 42 | private static DiskMetrics GetLinuxMetrics() 43 | { 44 | var metrics = new DiskMetrics(); 45 | 46 | var driveInfo = new DriveInfo("/"); 47 | metrics.AvailableDiskSpace = driveInfo.AvailableFreeSpace / Math.Pow(1024, 3); 48 | metrics.TotalDiskSpace = driveInfo.TotalSize / Math.Pow(1024, 3); 49 | 50 | return metrics; 51 | 52 | 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Kiosk.razor: -------------------------------------------------------------------------------- 1 | @page "/kiosk" 2 | @using kiosk_server.Services 3 | @layout EmptyLayout 4 | 5 | 6 | 7 | 8 | @foreach (var url in RedirectUrlList) 9 | { 10 | 11 | } 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /kiosk-server/Metrics/MemoryMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace kiosk_server.Metrics 5 | { 6 | public class MemoryMetrics 7 | { 8 | public double TotalMemory { get; set; } 9 | public double UsedMemory { get; set; } 10 | public double FreeMemory { get; set; } 11 | } 12 | 13 | // copied from https://gunnarpeipman.com/dotnet-core-system-memory/ 14 | 15 | public class MemoryMetricsClient 16 | { 17 | public static MemoryMetrics GetMetrics() 18 | { 19 | return IsLinux() ? GetLinuxMetrics() : GetWindowsMetrics(); 20 | } 21 | 22 | private static bool IsLinux() 23 | { 24 | var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || 25 | RuntimeInformation.IsOSPlatform(OSPlatform.Linux); 26 | 27 | return isLinux; 28 | } 29 | 30 | private static MemoryMetrics GetWindowsMetrics() 31 | { 32 | var output = ""; 33 | 34 | var info = new ProcessStartInfo 35 | { 36 | FileName = "wmic", 37 | Arguments = "OS get FreePhysicalMemory,TotalVisibleMemorySize /Value", 38 | RedirectStandardOutput = true 39 | }; 40 | 41 | using (var process = Process.Start(info)) 42 | { 43 | output = process?.StandardOutput.ReadToEnd(); 44 | } 45 | 46 | var metrics = new MemoryMetrics(); 47 | 48 | var lines = output?.Trim().Split("\n"); 49 | if (lines != null) 50 | { 51 | var freeMemoryParts = lines[0].Split("=", StringSplitOptions.RemoveEmptyEntries); 52 | var totalMemoryParts = lines[1].Split("=", StringSplitOptions.RemoveEmptyEntries); 53 | 54 | metrics.TotalMemory = Math.Round(double.Parse(totalMemoryParts[1]) / 1024, 0); 55 | metrics.FreeMemory = Math.Round(double.Parse(freeMemoryParts[1]) / 1024, 0); 56 | metrics.UsedMemory = metrics.TotalMemory - metrics.FreeMemory; 57 | } 58 | 59 | return metrics; 60 | } 61 | 62 | private static MemoryMetrics GetLinuxMetrics() 63 | { 64 | var output = ""; 65 | 66 | var info = new ProcessStartInfo("free -m") 67 | { 68 | FileName = "/bin/bash", 69 | Arguments = "-c \"free -m\"", 70 | RedirectStandardOutput = true 71 | }; 72 | 73 | using (var process = Process.Start(info)) 74 | { 75 | output = process?.StandardOutput.ReadToEnd(); 76 | } 77 | 78 | var metrics = new MemoryMetrics(); 79 | 80 | var lines = output?.Split("\n"); 81 | if (lines != null) 82 | { 83 | var memory = lines[1].Split(" ", StringSplitOptions.RemoveEmptyEntries); 84 | 85 | metrics.TotalMemory = double.Parse(memory[1]); 86 | metrics.UsedMemory = double.Parse(memory[2]); 87 | metrics.FreeMemory = double.Parse(memory[3]); 88 | 89 | } 90 | 91 | return metrics; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Kiosk.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using System.Diagnostics; 3 | using kiosk_server.Services; 4 | 5 | namespace kiosk_server.Pages 6 | { 7 | public partial class Kiosk 8 | { 9 | [Inject] private LayoutService LayoutService { get; set; } = null!; 10 | [Inject] private MyEventService EventService { get; set; } = null!; 11 | [Inject] private NavigationManager NavigationManager { get; set; } = null!; 12 | 13 | private List RedirectUrlList { get; set; } = null!; 14 | 15 | private string? CurrentIframeUrl; 16 | 17 | private string? TabHeaderClass; 18 | 19 | protected override async Task OnAfterRenderAsync(bool firstRender) 20 | { 21 | await base.OnAfterRenderAsync(firstRender); 22 | if (firstRender) 23 | { 24 | CurrentIframeUrl = RedirectUrlList.FirstOrDefault()?.Url ?? ""; 25 | 26 | StateHasChanged(); 27 | } 28 | } 29 | 30 | 31 | protected override async Task OnInitializedAsync() 32 | { 33 | EventService.OnUrlChange += NavigateToUrl; 34 | 35 | RedirectUrlList = Program.ConfigurationRoot.GetSection("RedirectUrl").Get>() ?? []; 36 | 37 | await base.OnInitializedAsync(); 38 | 39 | } 40 | 41 | public void Dispose() 42 | { 43 | EventService.OnUrlChange -= NavigateToUrl; 44 | 45 | } 46 | 47 | private void NavigateToUrl(string? url) 48 | { 49 | InvokeAsync(() => 50 | { 51 | if (string.IsNullOrEmpty(url)) 52 | { 53 | NavigationManager.NavigateTo(NavigationManager.Uri, true); 54 | } 55 | else 56 | { 57 | CurrentIframeUrl = url; 58 | TabHeaderClass = "hideme"; 59 | StateHasChanged(); 60 | } 61 | 62 | }); 63 | } 64 | 65 | private void ActivePanelIndexChanged(int index) 66 | { 67 | CurrentIframeUrl = RedirectUrlList[index].Url; 68 | 69 | StateHasChanged(); 70 | } 71 | 72 | private static void HandleShutdown() 73 | { 74 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "shutdown now" }); 75 | } 76 | 77 | private static void HandleStopChromium() 78 | { 79 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"ps aux | awk '/chromium/ { print $2 } ' | xargs kill \"" })?.WaitForExit(); 80 | } 81 | 82 | private static void HandleFullScreen() 83 | { 84 | //Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-1 ; export XDG_RUNTIME_DIR=/run/user/1000 ; wtype -P F11 \"" })?.WaitForExit(); // wayfire 85 | 86 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-0 ; export XDG_RUNTIME_DIR=/run/user/1000 ; wtype -P F11 \"" })?.WaitForExit(); // labwc 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /kiosk-server/Pages/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Components.Web 2 | @namespace kiosk_server.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 48 | @**@ 49 | 50 | 51 | 52 | 53 | @RenderBody() 54 | 55 |
56 | 57 | An error has occurred. This application may no longer respond until reloaded. 58 | 59 | 60 | An unhandled exception has occurred. See browser dev tools for details. 61 | 62 | Reload 63 | 🗙 64 |
65 | 66 | 67 | 68 | @* 69 | @if (Request.Host.Host.Contains("127.0.0.1")) 70 | { 71 | 72 | 73 | } 74 | else 75 | { 76 | 87 | } 88 | *@ 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Index.razor.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Shared; 2 | using Microsoft.AspNetCore.Components; 3 | using System.Net.NetworkInformation; 4 | using System.Net.Sockets; 5 | using System.Text.Json.Serialization; 6 | 7 | namespace kiosk_server.Pages 8 | { 9 | public class RedirectItem 10 | { 11 | [JsonIgnore] public int Id { get; set; } 12 | 13 | 14 | public string? Name { get; set; } 15 | public string? Url { get; set; } 16 | 17 | } 18 | 19 | public partial class Index 20 | { 21 | [CascadingParameter] public MainLayout MainLayout { get; set; } = null!; 22 | 23 | [Inject] private NavigationManager NavigationManager { get; set; } = null!; 24 | 25 | private List WebServerUrls { get; set; } = []; 26 | 27 | private List RedirectUrlList { get; set; } = null!; 28 | 29 | protected override async Task OnAfterRenderAsync(bool firstRender) 30 | { 31 | await base.OnAfterRenderAsync(firstRender); 32 | 33 | if (firstRender) 34 | { 35 | #if !DEBUG 36 | if (RedirectUrlList.Count(x => !string.IsNullOrEmpty(x.Url)) > 1) 37 | { 38 | NavigationManager.NavigateTo("/kiosk", true); 39 | } 40 | else if (!string.IsNullOrEmpty(RedirectUrlList.FirstOrDefault()?.Url)) 41 | { 42 | NavigationManager.NavigateTo(RedirectUrlList.FirstOrDefault()?.Url ?? "?", true); 43 | } 44 | #else 45 | NavigationManager.NavigateTo("/setup", true); 46 | #endif 47 | //StateHasChanged(); 48 | } 49 | } 50 | 51 | 52 | protected override async Task OnInitializedAsync() 53 | { 54 | MainLayout.Title = "Kiosk Server"; 55 | 56 | var port = Program.ConfigurationRoot.GetValue("Port"); 57 | 58 | foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) 59 | { 60 | if (!item.Description.Contains("virtual", StringComparison.CurrentCultureIgnoreCase) && 61 | item.NetworkInterfaceType != NetworkInterfaceType.Loopback && 62 | item.OperationalStatus == OperationalStatus.Up) 63 | { 64 | foreach (var ip in item.GetIPProperties().UnicastAddresses) 65 | { 66 | if (ip.Address.AddressFamily == AddressFamily.InterNetwork) 67 | { 68 | WebServerUrls.Add($"http://{ip.Address}:{port}"); 69 | } 70 | } 71 | } 72 | } 73 | 74 | RedirectUrlList = Program.ConfigurationRoot.GetSection("RedirectUrl").Get>() ?? []; 75 | 76 | #if !DEBUG 77 | var localhost = NavigationManager.Uri.Contains("127.0.0.1"); 78 | 79 | if (!localhost) 80 | { 81 | RedirectUrlList.Clear(); 82 | RedirectUrlList.Add(new RedirectItem 83 | { 84 | Name = "setup", 85 | Url = "/setup" 86 | }); 87 | } 88 | #endif 89 | await base.OnInitializedAsync(); 90 | 91 | 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /kiosk-server/kiosk-server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0 5 | enable 6 | enable 7 | kiosk_server 8 | AnyCPU 9 | 10 | 11 | 12 | 13 | 14 | wwwroot\favicon.ico 15 | 0.0.2.0 16 | Copyright © 2025 17 | 18 | 19 | 0.0.2.0 20 | 0.0.2.0 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | ILLink.Descriptors.xml 42 | 43 | 44 | 45 | 46 | 47 | Always 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | Always 58 | 59 | 60 | Always 61 | 62 | 63 | Always 64 | 65 | 66 | Always 67 | 68 | 69 | Always 70 | 71 | 72 | Always 73 | 74 | 75 | Always 76 | 77 | 78 | Always 79 | 80 | 81 | Always 82 | 83 | 84 | Always 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /kiosk-server/Api/ApiController.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Metrics; 2 | using kiosk_server.Services; 3 | using Microsoft.AspNetCore.Authorization; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Diagnostics; 6 | 7 | 8 | namespace kiosk_server.Api 9 | { 10 | [ApiController] 11 | [AllowAnonymous] 12 | public class ApiController(MyEventService myEventService) : ControllerBase 13 | { 14 | private class StatusData 15 | { 16 | public DiskMetrics Disk { get; set; } = null!; 17 | public TemperatureMetrics Temperature { get; set; } = null!; 18 | public MemoryMetrics Memory { get; set; } = null!; 19 | public CpuMetrics Cpu { get; set; } = null!; 20 | } 21 | 22 | [Route("api/status")] 23 | [HttpGet] 24 | public IActionResult Get() 25 | { 26 | var statusData = new StatusData 27 | { 28 | Memory = MemoryMetricsClient.GetMetrics(), 29 | Temperature = TemperatureMetricsClient.GetMetrics(), 30 | Disk = DiskMetricsClient.GetMetrics(), 31 | Cpu = CpuMetricsClient.GetMetrics() 32 | }; 33 | return Ok(statusData); 34 | } 35 | 36 | [Route("api/shutdown")] 37 | [HttpPost] 38 | public IActionResult Shutdown() 39 | { 40 | 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 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "reboot now" }); 51 | 52 | return Ok(); 53 | } 54 | 55 | 56 | [Route("api/screenon")] // Pi 4 X11 57 | [HttpPost] 58 | public IActionResult ScreenOn() 59 | { 60 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "vcgencmd display_power 1" }); 61 | 62 | return Ok(); 63 | } 64 | 65 | [Route("api/screenoff")] // Pi 4 X11 66 | 67 | [HttpPost] 68 | public IActionResult ScreenOff() 69 | { 70 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "vcgencmd display_power 0" }); 71 | 72 | return Ok(); 73 | } 74 | 75 | [Route("api/screenon2")] // Pi 5 labwc 76 | [HttpPost] 77 | public IActionResult ScreenOn2() 78 | { 79 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-0 ; export XDG_RUNTIME_DIR=/run/user/1000 ; /usr/bin/wlr-randr --output HDMI-A-1 --on \"" })?.WaitForExit(); 80 | 81 | return Ok(); 82 | } 83 | 84 | [Route("api/screenoff2")] // Pi 5 labwc 85 | 86 | [HttpPost] 87 | public IActionResult ScreenOff2() 88 | { 89 | //If monitor turns back on by itself after ~10 secs add “vc4.force_hotplug = 1”(1 = hmdi1 / 2 = hdmi2 / 3 = both) to the end of your / boot / firmware / cmdline.txt without creating a new line 90 | 91 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-0 ; export XDG_RUNTIME_DIR=/run/user/1000 ; /usr/bin/wlr-randr --output HDMI-A-1 --off \"" })?.WaitForExit(); 92 | 93 | return Ok(); 94 | } 95 | 96 | [Route("api/screenon3")] // Pi 5 wayfire 97 | [HttpPost] 98 | public IActionResult ScreenOn3() 99 | { 100 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-1 ; export XDG_RUNTIME_DIR=/run/user/1000 ; /usr/bin/wlr-randr --output HDMI-A-1 --on; sleep 5; wtype -P F11 \"" })?.WaitForExit(); 101 | 102 | return Ok(); 103 | } 104 | 105 | [Route("api/screenoff3")] // Pi 5 wayfire 106 | 107 | [HttpPost] 108 | public IActionResult ScreenOff3() 109 | { 110 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"export WAYLAND_DISPLAY=wayland-1 ; export XDG_RUNTIME_DIR=/run/user/1000 ; /usr/bin/wlr-randr --output HDMI-A-1 --off \"" })?.WaitForExit(); 111 | 112 | return Ok(); 113 | } 114 | 115 | [Route("api/stopchromium")] 116 | 117 | [HttpPost] 118 | public IActionResult StopChromium() 119 | { 120 | Process.Start(new ProcessStartInfo { FileName = "/usr/bin/bash", Arguments = "-c \"ps aux | awk '/chromium/ { print $2 } ' | xargs kill \"" })?.WaitForExit(); 121 | 122 | return Ok(); 123 | } 124 | 125 | 126 | [Route("api/navigatetourl")] 127 | [HttpPost] 128 | public IActionResult NavigateToUrl([FromQuery]string? url = null) 129 | { 130 | myEventService.NavigateToUrl(url); 131 | 132 | return Ok(); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Setup.razor.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Model; 2 | using Microsoft.AspNetCore.Components; 3 | using System.Diagnostics; 4 | using System.Text.Json; 5 | using kiosk_server.Shared; 6 | using kiosk_server.Metrics; 7 | using kiosk_server.Services; 8 | 9 | namespace kiosk_server.Pages 10 | { 11 | public partial class Setup 12 | { 13 | [Inject] private LayoutService LayoutService { get; set; } = null!; 14 | 15 | [CascadingParameter] public MainLayout Layout { get; set; } = null!; 16 | 17 | private readonly SetupModel SetupModel = new(); 18 | 19 | private List RedirectUrlList { get; set; } = null!; 20 | 21 | 22 | protected override async Task OnAfterRenderAsync(bool firstRender) 23 | { 24 | await base.OnAfterRenderAsync(firstRender); 25 | if (firstRender) 26 | { 27 | 28 | //StateHasChanged(); 29 | } 30 | } 31 | 32 | private void RenumberRedirectUrlListIndexes() 33 | { 34 | for (var index = 0; index < RedirectUrlList.Count; index++) 35 | { 36 | RedirectUrlList[index].Id = index + 1; 37 | } 38 | } 39 | 40 | protected override async Task OnInitializedAsync() 41 | { 42 | Layout.Title = "Kiosk Server Setup"; 43 | 44 | // called twice in case server mode = serverprerendered 45 | 46 | var memoryMetricsClient = new MemoryMetricsClient(); 47 | SetupModel.Memory = MemoryMetricsClient.GetMetrics(); 48 | 49 | var temperatureMetricsClient = new TemperatureMetricsClient(); 50 | SetupModel.Temperature = TemperatureMetricsClient.GetMetrics(); 51 | 52 | var diskMetricsClient = new DiskMetricsClient(); 53 | SetupModel.Disk = DiskMetricsClient.GetMetrics(); 54 | 55 | var cpuMetricsClient = new CpuMetricsClient(); 56 | SetupModel.Cpu = CpuMetricsClient.GetMetrics(); 57 | 58 | RedirectUrlList = Program.ConfigurationRoot.GetSection("RedirectUrl").Get>() ?? []; 59 | 60 | RenumberRedirectUrlListIndexes(); 61 | 62 | RedirectUrlList.Add(new RedirectItem 63 | { 64 | Id = RedirectUrlList.Count + 1, 65 | Name = "", 66 | Url = "" 67 | }); 68 | 69 | await base.OnInitializedAsync(); 70 | 71 | } 72 | 73 | private async Task UpdateAppSettings() 74 | { 75 | #if DEBUG 76 | var path = Path.Combine(Environment.CurrentDirectory, "appsettings.json"); 77 | #else 78 | var path = Path.Combine(AppContext.BaseDirectory, "appsettings.json"); 79 | #endif 80 | 81 | var configJson = await File.ReadAllTextAsync(path); 82 | var config = JsonSerializer.Deserialize>(configJson); 83 | 84 | if (config != null) 85 | { 86 | config["RedirectUrl"] = RedirectUrlList 87 | .Where(x => !string.IsNullOrEmpty(x.Name) && !string.IsNullOrEmpty(x.Url)).ToArray(); 88 | 89 | var updatedConfigJson = 90 | JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); 91 | await File.WriteAllTextAsync(path, updatedConfigJson); 92 | 93 | Program.ConfigurationRoot.Reload(); 94 | } 95 | } 96 | 97 | private async Task CommittedItemChanges(RedirectItem item) 98 | { 99 | if (!string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Url)) 100 | { 101 | RedirectUrlList[item.Id - 1].Name = item.Name; 102 | RedirectUrlList[item.Id - 1].Url = item.Url; 103 | 104 | if (item.Id == RedirectUrlList.Count) 105 | { 106 | RedirectUrlList.Add(new RedirectItem 107 | { 108 | Id = RedirectUrlList.Count + 1, 109 | Name = "", 110 | Url = "" 111 | }); 112 | } 113 | 114 | await UpdateAppSettings(); 115 | 116 | StateHasChanged(); 117 | } 118 | } 119 | 120 | private async Task DeleteUrl(RedirectItem item) 121 | { 122 | 123 | RedirectUrlList.RemoveAt(item.Id - 1); 124 | 125 | RenumberRedirectUrlListIndexes(); 126 | 127 | await UpdateAppSettings(); 128 | 129 | StateHasChanged(); 130 | 131 | } 132 | 133 | private static void HandleReboot() 134 | { 135 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "reboot now" }); 136 | } 137 | 138 | private static void HandleShutdown() 139 | { 140 | Process.Start(new ProcessStartInfo { FileName = "sudo", Arguments = "shutdown now" }); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /kiosk-server/Program.cs: -------------------------------------------------------------------------------- 1 | using kiosk_server.Services; 2 | using Microsoft.AspNetCore.ResponseCompression; 3 | using MudBlazor.Services; 4 | using System.Net; 5 | using System.Net.NetworkInformation; 6 | using System.Net.Sockets; 7 | using Serilog; 8 | using Serilog.Core; 9 | using Serilog.Events; 10 | 11 | 12 | 13 | class Program 14 | { 15 | public static IConfigurationRoot ConfigurationRoot { get; set; } = null!; 16 | 17 | private class ThreadIdEnricher : ILogEventEnricher 18 | { 19 | public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) 20 | { 21 | logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty( 22 | "ThreadID", Environment.CurrentManagedThreadId.ToString("D4"))); 23 | } 24 | } 25 | 26 | static void Main(string[] args) 27 | { 28 | MainAsync(args).GetAwaiter().GetResult(); 29 | } 30 | 31 | static async Task MainAsync(string[] args) 32 | { 33 | 34 | var builder = WebApplication.CreateBuilder(args); 35 | 36 | ConfigurationRoot = builder.Configuration; 37 | 38 | builder.Host.UseSystemd(); 39 | 40 | builder.Host.UseSerilog(); 41 | //builder.Logging.AddSerilog(); 42 | 43 | Log.Logger = new LoggerConfiguration() 44 | .Enrich.With(new ThreadIdEnricher()) 45 | .ReadFrom.Configuration(configuration: ConfigurationRoot) 46 | .CreateLogger(); 47 | 48 | Log.Information("Starting up!"); 49 | 50 | Log.Information("Logging enabled"); 51 | 52 | builder.WebHost.UseUrls(); 53 | 54 | builder.WebHost.ConfigureKestrel(serverOptions => 55 | { 56 | var port = ConfigurationRoot.GetValue("Port"); 57 | 58 | serverOptions.Listen(IPAddress.Loopback, port); 59 | 60 | foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) 61 | { 62 | if (!item.Description.Contains("virtual", StringComparison.CurrentCultureIgnoreCase) && 63 | item.NetworkInterfaceType != NetworkInterfaceType.Loopback && 64 | item.OperationalStatus == OperationalStatus.Up) 65 | { 66 | foreach (var ip in item.GetIPProperties().UnicastAddresses) 67 | { 68 | if (ip.Address.AddressFamily == AddressFamily.InterNetwork) 69 | { 70 | serverOptions.Listen(ip.Address, port); 71 | } 72 | } 73 | } 74 | } 75 | 76 | }); 77 | 78 | builder.WebHost.UseStaticWebAssets(); 79 | 80 | builder.Services.AddHttpClient(); 81 | 82 | // Add services to the container. 83 | builder.Services.AddRazorPages(); 84 | builder.Services.AddServerSideBlazor(); 85 | builder.Services.AddMudServices(); 86 | 87 | // Add services to manage API controller 88 | builder.Services.AddControllers(); 89 | 90 | builder.Services.AddCors(); 91 | 92 | //builder.Services.AddSingleton(); 93 | 94 | builder.Services.AddScoped(); 95 | 96 | builder.Services.AddSingleton(); 97 | 98 | builder.Services.AddResponseCompression(opts => 99 | { 100 | opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat( 101 | ["application/octet-stream"]); 102 | }); 103 | 104 | var app = builder.Build(); 105 | 106 | if (!app.Environment.IsDevelopment()) // response compression currently conflicts with dotnet watch browser reload 107 | { 108 | app.UseResponseCompression(); 109 | } 110 | 111 | if (app.Environment.IsDevelopment()) 112 | { 113 | app.UseDeveloperExceptionPage(); 114 | } 115 | else 116 | { 117 | app.UseExceptionHandler("/Error"); 118 | } 119 | 120 | /* 121 | var strExeFilePath = Assembly.GetEntryAssembly().Location; 122 | var exePath = Path.GetDirectoryName(strExeFilePath); 123 | 124 | app.UseStaticFiles(new StaticFileOptions 125 | { 126 | FileProvider = new PhysicalFileProvider( 127 | Path.Combine(exePath, @"wwwroot")), 128 | });*/ 129 | 130 | app.MapStaticAssets(); 131 | 132 | app.UseRouting(); 133 | 134 | // global cors policy 135 | app.UseCors(x => x 136 | .AllowAnyMethod() 137 | .AllowAnyHeader() 138 | .SetIsOriginAllowed(origin => true) // allow any origin 139 | .AllowCredentials()); // allow credentials 140 | 141 | app.MapControllers(); 142 | 143 | app.MapBlazorHub(); 144 | app.MapFallbackToPage("/_Host"); 145 | 146 | /* 147 | app.UseEndpoints(endpoints => 148 | { 149 | endpoints.MapBlazorHub(); 150 | //endpoints.MapHub("/myhub"); 151 | endpoints.MapFallbackToPage("/_Host"); 152 | });*/ 153 | /* 154 | app.MapGet("/aaa/bbb", () => 155 | { 156 | string[] data = new string[] { 157 | "Hello World!", 158 | "Hello Galaxy!", 159 | "Hello Universe!" 160 | }; 161 | return Results.Ok(data); 162 | });*/ 163 | 164 | await app.RunAsync(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /kiosk-server/Metrics/CPUMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Runtime.InteropServices; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace kiosk_server.Metrics 6 | { 7 | 8 | public class CpuMetrics 9 | { 10 | public string OsDescription { get; set; } = null!; 11 | public string OsName { get; set; } = null!; 12 | 13 | public string CpuModel { get; set; } = null!; 14 | public string CpuModelName { get; set; } = null!; 15 | public string CpuHardware { get; set; } = null!; 16 | 17 | public double CpuUsage { get; set; } 18 | 19 | } 20 | 21 | public class CpuMetricsClient 22 | { 23 | public static CpuMetrics GetMetrics() 24 | { 25 | return IsLinux() ? GetLinuxMetrics() : GetWindowsMetrics(); 26 | } 27 | 28 | private static bool IsLinux() 29 | { 30 | var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || 31 | RuntimeInformation.IsOSPlatform(OSPlatform.Linux); 32 | 33 | return isLinux; 34 | } 35 | 36 | private static CpuMetrics GetWindowsMetrics() 37 | { 38 | var metrics = new CpuMetrics 39 | { 40 | OsDescription = RuntimeInformation.OSDescription 41 | }; 42 | 43 | return metrics; 44 | } 45 | 46 | public class RegExMatch 47 | { 48 | public Regex regex; 49 | public Action updateValue; 50 | 51 | private RegExMatch(string pattern, Action update) 52 | { 53 | regex = new Regex(pattern, RegexOptions.Compiled); 54 | updateValue = update; 55 | } 56 | 57 | public static RegExMatch CreateInstance(string pattern, Action update) 58 | { 59 | return new RegExMatch(pattern, update); 60 | } 61 | } 62 | 63 | 64 | private static void HandleRegExMatches(ref string[] lines,ref RegExMatch[] matches) 65 | { 66 | 67 | foreach (var line in lines) 68 | { 69 | foreach (var matchItem in matches) 70 | { 71 | var match = matchItem.regex.Match(line); 72 | if (match.Groups[0].Success) 73 | { 74 | var value = match.Groups[1].Value; 75 | matchItem.updateValue(value); 76 | } 77 | } 78 | } 79 | } 80 | 81 | /*private static string GetLinuxOsName() 82 | { 83 | var prettyName = ""; 84 | 85 | var releaseLines = File.ReadAllLines(@"/etc/os-release"); 86 | 87 | var releaseMatches = new[] { 88 | RegExMatch.CreateInstance("^PRETTY_NAME+=\"(.+)\"", value => prettyName = value), 89 | }; 90 | 91 | HandleRegExMatches(ref releaseLines, ref releaseMatches); 92 | 93 | return prettyName; 94 | }*/ 95 | 96 | // https://github.com/MhyrAskri/Linux-CPU-Usage/blob/master/CpuUsage.cs 97 | private static double GetLinuxCpuUsage() 98 | { 99 | var output = ""; 100 | 101 | var info = new ProcessStartInfo("top -b -n 1") 102 | { 103 | FileName = "/bin/bash", 104 | Arguments = "-c \"top -b -n 1\"", 105 | RedirectStandardOutput = true 106 | }; 107 | 108 | using (var process = Process.Start(info)) 109 | { 110 | output = process?.StandardOutput.ReadToEnd(); 111 | } 112 | 113 | var lines = output?.Split("\n"); 114 | if (lines != null) 115 | { 116 | var cpuLine2 = lines[2].Split(",", StringSplitOptions.RemoveEmptyEntries); 117 | var firstPart = cpuLine2[0].Split(":", StringSplitOptions.RemoveEmptyEntries); 118 | var secondPart = cpuLine2[1].Split("s", StringSplitOptions.RemoveEmptyEntries); 119 | var thirdPart = cpuLine2[2].Split("n", StringSplitOptions.RemoveEmptyEntries); 120 | 121 | var cpuUsage = double.Parse(firstPart[1].Split("u", StringSplitOptions.RemoveEmptyEntries)[0]) + 122 | double.Parse(secondPart[0]) + 123 | double.Parse(thirdPart[0]); 124 | 125 | return cpuUsage; 126 | 127 | } 128 | 129 | return 0; 130 | } 131 | 132 | private static CpuMetrics GetLinuxMetrics() 133 | { 134 | var metrics = new CpuMetrics 135 | { 136 | OsDescription = RuntimeInformation.OSDescription 137 | //OsName = GetLinuxOsName() 138 | }; 139 | 140 | var cpuInfoLines = File.ReadAllLines("/proc/cpuinfo"); 141 | 142 | var cpuInfoMatches = new[] { 143 | RegExMatch.CreateInstance(@"^Model\s+:\s+(.+)", value => metrics.CpuModel = value), 144 | //RegExMatch.CreateInstance(@"^model name\s+:\s+(.+)", value => metrics.CpuModelName = value), 145 | RegExMatch.CreateInstance(@"^Hardware\s+:\s+(.+)", value => metrics.CpuHardware = value), 146 | }; 147 | 148 | HandleRegExMatches(ref cpuInfoLines, ref cpuInfoMatches); 149 | 150 | var output = ""; 151 | 152 | var info = new ProcessStartInfo("lscpu") 153 | { 154 | FileName = "/bin/bash", 155 | Arguments = "-c \"lscpu\"", 156 | RedirectStandardOutput = true 157 | }; 158 | 159 | using (var process = Process.Start(info)) 160 | { 161 | output = process?.StandardOutput.ReadToEnd(); 162 | } 163 | 164 | var lscpuLines = output?.Split("\n") ; 165 | 166 | if (lscpuLines != null) 167 | { 168 | var lscpuMatches = new[] { 169 | RegExMatch.CreateInstance(@"^Model name:\s+(.+)", value => metrics.CpuModelName = value) 170 | }; 171 | 172 | HandleRegExMatches(ref lscpuLines, ref lscpuMatches); 173 | 174 | } 175 | 176 | metrics.CpuUsage = GetLinuxCpuUsage(); 177 | 178 | return metrics; 179 | } 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /kiosk-server/Metrics/TemperatureMetrics.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Globalization; 3 | using System.Runtime.InteropServices; 4 | #pragma warning disable IDE0057 5 | 6 | namespace kiosk_server.Metrics 7 | { 8 | // from https://github.com/VincentPestana/RpiStats 9 | 10 | public class TemperatureMetrics 11 | { 12 | public float CpuTemperature { get; set; } 13 | 14 | public string ThrottledState { get; set; } = null!; 15 | 16 | } 17 | 18 | public class TemperatureMetricsClient 19 | { 20 | public static TemperatureMetrics GetMetrics() 21 | { 22 | return IsLinux() ? GetLinuxMetrics() : GetWindowsMetrics(); 23 | } 24 | 25 | private static bool IsLinux() 26 | { 27 | var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || 28 | RuntimeInformation.IsOSPlatform(OSPlatform.Linux); 29 | 30 | return isLinux; 31 | } 32 | 33 | private static TemperatureMetrics GetWindowsMetrics() 34 | { 35 | var metrics = new TemperatureMetrics(); 36 | 37 | // todo ??? 38 | 39 | /* 40 | Double CPUtprt = 0; 41 | System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(@"root\WMI", "Select * From MSAcpi_ThermalZoneTemperature"); 42 | foreach (System.Management.ManagementObject mo in mos.Get()) 43 | { 44 | CPUtprt = Convert.ToDouble(Convert.ToDouble(mo.GetPropertyValue("CurrentTemperature").ToString()) - 2732) / 10; 45 | Console.WriteLine("CPU temp : " + CPUtprt.ToString() + " °C"); 46 | }*/ 47 | 48 | return metrics; 49 | } 50 | 51 | private enum ThrottledState : long 52 | { 53 | UnderVoltageDetected = 0x1L, 54 | FrequencyCapped = 0x2L, 55 | CurrentlyThrottled = 0x4L, 56 | SoftTemperatureLimit = 0x8L, 57 | 58 | UnderVoltHasOccuredSinceBoot = 0x10000L, 59 | FrequencyCapHasOccured = 0x20000L, 60 | ThrottlingHasOccured = 0x40000L, 61 | SoftTemperatureLimitHasOccured = 0x80000L 62 | } 63 | /* 64 | private static string FormatThrottledState(string throttledStateCallOutput) 65 | { 66 | var enumState = Enum.Parse(throttledStateCallOutput); 67 | 68 | return enumState.ToString(); 69 | }*/ 70 | 71 | private static TemperatureMetrics GetLinuxMetrics() 72 | { 73 | var output = ""; 74 | 75 | var info = new ProcessStartInfo 76 | { 77 | FileName = "/bin/bash", 78 | Arguments = "-c \"/usr/bin/vcgencmd measure_temp\"", 79 | RedirectStandardOutput = true, 80 | UseShellExecute = false, 81 | CreateNoWindow = true, 82 | }; 83 | 84 | using (var process = Process.Start(info)) 85 | { 86 | output = process?.StandardOutput.ReadToEnd(); 87 | } 88 | 89 | var metrics = new TemperatureMetrics(); 90 | 91 | if (!string.IsNullOrEmpty(output)) 92 | { 93 | var temperatureOutput = output 94 | .Substring(output.IndexOf('=') + 1, 95 | output.IndexOf('\'', StringComparison.Ordinal) - (output.IndexOf('=') + 1)); 96 | 97 | if (float.TryParse(temperatureOutput, NumberStyles.Number, CultureInfo.CreateSpecificCulture("en-US"), out var cpuTemp)) 98 | { 99 | metrics.CpuTemperature = cpuTemp; 100 | } 101 | } 102 | 103 | var info2 = new ProcessStartInfo 104 | { 105 | FileName = "/bin/bash", 106 | Arguments = "-c \"/usr/bin/vcgencmd get_throttled\"", 107 | RedirectStandardOutput = true, 108 | UseShellExecute = false, 109 | CreateNoWindow = true, 110 | }; 111 | 112 | using (var process2 = Process.Start(info2)) 113 | { 114 | output = process2?.StandardOutput.ReadToEnd(); 115 | } 116 | 117 | if (!string.IsNullOrEmpty(output)) 118 | { 119 | var throttledStateList = new List(); 120 | 121 | output = output.Trim(); 122 | var throttledOutput = Convert.ToInt64(output.Substring(output.IndexOf("=0x", StringComparison.Ordinal) + 1), 16); 123 | 124 | if ((throttledOutput & (long)ThrottledState.UnderVoltageDetected) > 0) 125 | { 126 | throttledStateList.Add("Undervoltage"); 127 | } 128 | if ((throttledOutput & (long)ThrottledState.FrequencyCapped) > 0) 129 | { 130 | throttledStateList.Add("FrequencyCapped"); 131 | } 132 | if ((throttledOutput & (long)ThrottledState.CurrentlyThrottled) > 0) 133 | { 134 | throttledStateList.Add("CurrentlyThrottled"); 135 | } 136 | if ((throttledOutput & (long)ThrottledState.SoftTemperatureLimit) > 0) 137 | { 138 | throttledStateList.Add("SoftTemperatureLimit"); 139 | } 140 | if ((throttledOutput & (long)ThrottledState.UnderVoltHasOccuredSinceBoot) > 0) 141 | { 142 | throttledStateList.Add("UnderVoltHasOccuredSinceBoot"); 143 | } 144 | if ((throttledOutput & (long)ThrottledState.FrequencyCapHasOccured) > 0) 145 | { 146 | throttledStateList.Add("FrequencyCapHasOccured"); 147 | } 148 | if ((throttledOutput & (long)ThrottledState.ThrottlingHasOccured) > 0) 149 | { 150 | throttledStateList.Add("ThrottlingHasOccured"); 151 | } 152 | if ((throttledOutput & (long)ThrottledState.SoftTemperatureLimitHasOccured) > 0) 153 | { 154 | throttledStateList.Add("SoftTemperatureLimitHasOccured"); 155 | } 156 | 157 | metrics.ThrottledState = string.Join(", ", throttledStateList); 158 | } 159 | 160 | return metrics; 161 | 162 | 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /kiosk-server/Pages/Setup.razor: -------------------------------------------------------------------------------- 1 | @page "/setup" 2 | @using kiosk_server.Services 3 | 4 | 5 | 6 | 7 | 10 | 11 | Kiosk Urls 12 | 13 | Reboot 14 | Shutdown 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | @if (!string.IsNullOrEmpty(context.Item.Url)) 34 | { 35 | 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Memory 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | Total 59 | Used 60 | Free 61 | 62 | 63 | 64 | 65 | 66 | @SetupModel.Memory.TotalMemory.ToString("N0") MB 67 | 68 | 69 | @SetupModel.Memory.UsedMemory.ToString("N0") MB 70 | 71 | 72 | @SetupModel.Memory.FreeMemory.ToString("N0") MB 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | Disk Space 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | Total 92 | Used 93 | Free 94 | 95 | 96 | 97 | 98 | 99 | @SetupModel.Disk.TotalDiskSpace.ToString("N1") GB 100 | 101 | 102 | @((SetupModel.Disk.TotalDiskSpace -SetupModel.Disk.AvailableDiskSpace).ToString("N1")) GB 103 | 104 | 105 | @SetupModel.Disk.AvailableDiskSpace.ToString("N1") GB 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | @if (SetupModel.Temperature.CpuTemperature > 0) 114 | { 115 | 116 | 117 | 118 | CPU 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Usage 127 | Temperature 128 | State 129 | 130 | 131 | 132 | 133 | 134 | @SetupModel.Cpu.CpuUsage.ToString("N1") % 135 | 136 | 137 | @SetupModel.Temperature.CpuTemperature.ToString("N1") °C 138 | 139 | 140 | @(string.IsNullOrEmpty(SetupModel.Temperature.ThrottledState) ? "Normal" : SetupModel.Temperature.ThrottledState) 141 | 142 | 143 | 144 | 145 | 146 | 147 | } 148 | 149 | 150 | 151 | 152 | @SetupModel.Cpu.OsDescription 153 | @if (!string.IsNullOrEmpty(SetupModel.Cpu.OsName)) 154 | { 155 |
156 | @SetupModel.Cpu.OsName 157 | } 158 | @if (!string.IsNullOrEmpty(SetupModel.Cpu.CpuHardware)) 159 | { 160 |
161 | @SetupModel.Cpu.CpuHardware 162 | } 163 | @if (!string.IsNullOrEmpty(SetupModel.Cpu.CpuModel)) 164 | { 165 |
166 | @SetupModel.Cpu.CpuModel 167 | } 168 | @if (!string.IsNullOrEmpty(SetupModel.Cpu.CpuModelName)) 169 | { 170 |
171 | @SetupModel.Cpu.CpuModelName 172 | } 173 |
174 | 175 |
176 |
177 | 178 |
179 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | 365 | log.txt 366 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kiosk-server 2 | 3 | Touch screen kiosk with multi-platform remote control web server, using blazor and net9. 4 | 5 | Display when no Kiosk URL is defined yet: 6 | 7 | ![touch screen](https://i.imgur.com/bTQtqSe.png) 8 | 9 | When using the external setup URL (http://x.x.x.x:5000/setup, no password authentication) you can enter one or more Kiosk URLs and then either reboot or shutdown the raspberry pi. 10 | 11 | The Kiosk URL is only shown after a reboot. 12 | 13 | If there is only one Kiosk URL, then the software will redirect to that URL at startup. 14 | 15 | If there is more than one Kiosk URL defined, then the software will redirect to an internal page (http://x.x.x.x:5000/kiosk) that has a tab bar at the top and an iframe filling the rest of the screen. 16 | 17 | The contents of the iframe is changed to the Kiosk URL, after pressing the tab button with the name of the Kiosk URL. 18 | 19 | If you see a blank iframe with an error like 'www.msn.com refused to connect.' : 20 | That means that the remote web server does not allow rendering inside an iframe. (via the X-Frame-Options http response header) 21 | 22 | You won't have this problem, if you define just one Kiosk URL. 23 | 24 | There is also a page http://x.x.x.x:5000/blank that shows a blank page. 25 | 26 | 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. 27 | 28 | There are also (POST) rest api endpoints (http://x.x.x.x:5000/api/shutdown , http://x.x.x.x:5000/api/reboot , http://x.x.x.x:5000/api/screenoff and http://x.x.x.x:5000/api/screenon) NOTE that there is no authentication! 29 | 30 | Also, a (POST) rest api endpoint has been added (http://x.x.x.x:5000/api/stopchromium) , that kills the chromium process. 31 | 32 | There is also a (POST) rest api endpoint http://x.x.x.x:5000/api/navigatetourl?url=xxxxxxx that ONLY works, when the kiosk screen is being displayed. 33 | 34 | When this url is POSTed, with ANY url as query parameter (e.g. http://x.x.x.x:5000/api/navigatetourl?url=http://x.x.x.x:5000/blank) that page will be loaded into the kiosk iframe and the tab bar at the top is hidden. 35 | 36 | When this url is POSTed, without any url as query parameter (e.g. http://x.x.x.x:5000/api/navigatetourl?url=) then the kiosk is reloaded and the tab bar at the top reappears. 37 | 38 | ![touch screen](https://i.imgur.com/Wzp5kqm.png) 39 | 40 | ![touch screen](https://i.imgur.com/cXrHx23.png) 41 | 42 | ## Test Environment 43 | 44 | **This software works with any kind of display. I have been testing with ultra-wide displays :** 45 | 46 | 3D-printed enclosures, for these displays, can be found : https://www.printables.com/@mhwlng_888536/collections/920676 47 | 48 | Touch Display 1920x480 (8.8 inch, IPS panel, default orientation is portrait): 49 | 50 | https://www.aliexpress.com/item/1005003014364673.html 51 | 52 | ![touch screen](https://i.imgur.com/QWs2S9S.jpg) 53 | 54 | ![touch screen](https://i.imgur.com/GfcSTTd.jpg) 55 | 56 | The 3 Dials have an ESP32 processor and are made by M5Stack : 57 | 58 | https://shop.m5stack.com/products/m5stack-dial-esp32-s3-smart-rotary-knob-w-1-28-round-touch-screen 59 | 60 | ![touch screen](https://i.imgur.com/0NSFRaz.jpg) 61 | 62 | Touch Display 1920x515 (12.6 inch, IPS panel): 63 | 64 | https://www.aliexpress.com/item/1005001966967133.html 65 | 66 | [3d printed modular dashboard](https://www.printables.com/@mhwlng_888536/collections/920676) 67 | 68 | ![touch screen](https://i.imgur.com/hFIeCUD.jpg) 69 | 70 | ![touch screen](https://i.imgur.com/4YI13mJ.jpg) 71 | 72 | ![touch screen](https://i.imgur.com/erLvZY7.jpg) 73 | 74 | Touch display 3840x1100 (14 inch, IPS panel, uses usb-c connector for power and touch screen): 75 | 76 | https://www.aliexpress.com/item/1005003332731770.html 77 | 78 | [3d printed modular dashboard](https://www.printables.com/@mhwlng_888536/collections/920676) 79 | 80 | ![touch screen](https://i.imgur.com/MjmCNvf.jpg) 81 | 82 | ![touch screen](https://i.imgur.com/ysxHEvS.jpg) 83 | 84 | Raspberry Pi Compute Module 4 (I only have the 8GB RAM / 16GB EMMC version) 85 | 86 | The Waveshare CM4-NANO-B expansion board (also available on Amazon) 87 | 88 | https://www.waveshare.com/wiki/CM4-NANO-B 89 | 90 | The USB-C port is connected to the 5V power. (Also used to put the OS image onto the EMMC flash.) 91 | 92 | The USB-A port is connected to the display. (To power it and also for the touch screen) 93 | 94 | The HDMI port is connected to the display HDMI port. 95 | 96 | Pressing the pushbutton (GPIO21) shuts down the CM4 97 | 98 | # Installation Instructions 99 | 100 | I mainly used this document as a guideline: (note that for the CM4 it's not exactly the same) 101 | 102 | https://gist.github.com/fjctp/210f4e870f913416b8d0e17fd36153c2 103 | 104 | 105 | ## Install bootloader on CM4 106 | 107 | https://www.raspberrypi.com/documentation/computers/compute-module.html 108 | 109 | Set boot switch to on, plug in usb-c 110 | 111 | Download rpiboot_setup.exe, run rpiboot.exe 112 | 113 | Also see waveshare CM4-NANO-B wiki page. 114 | 115 | https://github.com/raspberrypi/usbboot/raw/master/win32/rpiboot_setup.exe 116 | 117 | - Install raspberry pi os lite 64 bit (bookworm) 118 | - Set up wifi 119 | - Set up ssh 120 | - Set up an account (The instructions and various configuration files assume pi/raspberry Adjust as required.) 121 | 122 | After connecting via ssh : 123 | ``` 124 | sudo apt-get update 125 | 126 | sudo apt-get upgrade 127 | 128 | sudo raspi-config 129 | 130 | Select system \ boot+autologin \ B2 Console autologin text console 131 | 132 | sudo apt-get install -y --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox 133 | 134 | sudo apt-get install -y --no-install-recommends chromium-browser 135 | ``` 136 | 137 | ## Edit /boot/firmware/config.txt 138 | 139 | **Note: These HDMI resolution configurations do NOT work on Raspberry Pi 5 / CM5 !** 140 | 141 | For Touch Display 1920x480 (portrait orientation, default) : 142 | ``` 143 | dtoverlay=vc4-fkms-v3d # note that this was vc4-kms-v3d before !!!!! 144 | 145 | max_framebuffer_height=1920 146 | hdmi_timings=480 1 48 32 80 1920 0 3 10 56 0 0 0 60 0 75840000 3 147 | hdmi_group=2 148 | hdmi_mode=87 149 | 150 | #otg_mode=1 151 | dtoverlay=dwc2,dr_mode=host 152 | dtoverlay=gpio-shutdown,gpio_pin=21 153 | 154 | gpu_mem=256 155 | ``` 156 | 157 | For Touch Display 1920x480 (landscape orientation, rotate 90°) also add: 158 | ``` 159 | display_hdmi_rotate=1 160 | ``` 161 | 162 | For landscape orientation: the touchscreen also needs to be rotated 90° : 163 | 164 | Edit /usr/share/X11/xorg.conf.d/40-libinput.conf 165 | 166 | Add the TransformationMatrix option to the existing touchscreen InputClass: 167 | ``` 168 | Section "InputClass" 169 | Identifier "libinput touchscreen catchall" 170 | MatchIsTouchscreen "on" 171 | Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1" 172 | MatchDevicePath "/dev/input/event*" 173 | Driver "libinput" 174 | EndSection 175 | ``` 176 | 177 | For Touch Display 1920x515 : 178 | ``` 179 | dtoverlay=vc4-fkms-v3d # note that this was vc4-kms-v3d before !!!!! 180 | 181 | hdmi_group=2 182 | hdmi_mode=87 183 | hdmi_cvt=1920 515 60 6 0 0 0 184 | 185 | #otg_mode=1 186 | dtoverlay=dwc2,dr_mode=host 187 | dtoverlay=gpio-shutdown,gpio_pin=21 188 | 189 | gpu_mem=256 190 | ``` 191 | 192 | For Touch Display 3840x1100 : 193 | ``` 194 | dtoverlay=vc4-fkms-v3d # note that this was vc4-kms-v3d before !!!!! 195 | 196 | hdmi_enable_4kp60=1 197 | hdmi_group=2 198 | hdmi_mode=87 199 | hdmi_cvt=3840 1100 60 200 | 201 | #otg_mode=1 202 | dtoverlay=dwc2,dr_mode=host 203 | dtoverlay=gpio-shutdown,gpio_pin=21 204 | 205 | gpu_mem=256 206 | ``` 207 | 208 | ## Edit /etc/xdg/openbox/autostart 209 | 210 | ``` 211 | xset s off 212 | xset s noblank 213 | xset -dpms 214 | 215 | setxkbmap -option terminate:ctrl_alt_bksp 216 | 217 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State' 218 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences 219 | 220 | # delete all chromium cached data 221 | rm -rf ~/.cache/chromium 222 | 223 | # delete cookies 224 | #rm -rf ~/.config/chromium 225 | 226 | chromium-browser --noerrdialogs --disable-infobars --kiosk 'http://127.0.0.1:5000' 227 | ``` 228 | 229 | For the 3840x1100 screen, you can increase the zoom level of chromium using --force-device-scale-factor=1.5 on the command line. 230 | 231 | If the web page checks for the dark mode system setting, --force-dark-mode --enable-features=WebContentsForceDark can be added to the command line. 232 | 233 | To disable the cache mechanism, --disk-cache-dir=/dev/null can be added to the command line. 234 | 235 | Some chromium performance related flags can be found here : 236 | 237 | https://github.com/Botspot/pi-apps/blob/master/apps/Better%20Chromium/install 238 | 239 | some more chromium flags can be found here : 240 | 241 | https://itnext.io/raspberry-pi-read-only-kiosk-mode-2022-complete-tutorial-df7fc051fdaf 242 | 243 | ``` 244 | chromium-browser --ignore-gpu-blacklist --enable-checker-imaging --cc-scroll-animation-duration-in-seconds=0.6 --disable-quic --enable-tcp-fast-open --enable-experimental-canvas-features --enable-scroll-prediction --enable-simple-cache-backend --max-tiles-for-interest-area=512 --num-raster-threads=4 --default-tile-height=512 --enable-features=VaapiVideoDecoder,VaapiVideoEncoder --disable-features=UseChromeOSDirectVideoDecoder,TouchpadOverscrollHistoryNavigation --enable-accelerated-video-decode --enable-low-res-tiling --process-per-site --start-fullscreen --disable-translate --no-first-run --fast --fast-start --disable-features=TranslateUI --password-store=basic --disable-pinch --overscroll-history-navigation=disabled --noerrdialogs --disable-infobars --kiosk 'http://127.0.0.1:5000' 245 | ``` 246 | 247 | ## Edit ~/.profile 248 | 249 | ``` 250 | [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor 251 | ``` 252 | 253 | ## CM5 254 | 255 | On CM5, (tested on Bookworm), I could not get custom resolutions to work. So, I use a standard 1920x1080 touch screen. 256 | 257 | I installed the full 64-bit Raspberry Pi OS, with auto login into the graphical desktop. 258 | 259 | By default, the combination wayland + labwc is installed. 260 | 261 | In this situation, scrolling the chromium browser with your finger does not work. 262 | (It acts like a mouse, so you must drag on the scrollbar with your finger, to scroll.) 263 | 264 | On Trixie, I changed : control center \ screens \ HDMI-A-1 \ Touchscreen \ Mode \ Multitouch (The default was Mouse Emulation) 265 | 266 | Note, that I don't always see the touchscreen option, after every reboot or shutdown+power up. 267 | In that case, the mouse emulation is back. I don't know why... 268 | 269 | 270 | On Bookworm, I switched to the wayland + wayfire combination. (This option doesn't exist anymore on Trixie): 271 | 272 | ``` 273 | sudo raspi-config 274 | 275 | Select advanced options \ wayland \ W2 wayfire 276 | ``` 277 | 278 | I then created a script file, with the desired command line options, to start the kiosk: 279 | 280 | ~/run_kiosk.sh 281 | 282 | ``` 283 | sleep 6 284 | 285 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State' 286 | sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences 287 | 288 | # delete all chromium cached data 289 | rm -rf ~/.cache/chromium 290 | 291 | # delete cookies 292 | #rm -rf ~/.config/chromium 293 | 294 | /bin/chromium-browser --no-first-run --noerrdialogs --disable-infobars --ozone-platform=wayland --start-fullscreen --force-dark-mode --enable-features=WebContentsForceDark http://127.0.0.1:5000 & 295 | ``` 296 | 297 | Make script runnable using : 298 | ``` 299 | sudo chmod +x ~/run_kiosk.sh 300 | ``` 301 | 302 | Note, that on Trixie, the file name chromium is used, instead of chromium-browser. 303 | 304 | Note, that I did not add the --kiosk option. Now, the button, to toggle full screen mode, works. (By simulating the F11 key. This requires the 'wtype' application to be installed.) 305 | 306 | With the --kiosk option, this F11 key is blocked, UNTIL the first screen off/on cycle, on Bookworm, when kiosk mode is disabled anyway.... 307 | 308 | To install wtype, use: 309 | 310 | ``` 311 | sudo apt install wtype 312 | ``` 313 | 314 | The default desktop installation comes with an on screen keyboard, with a button on the top right, to activate it. 315 | 316 | The keyboard is not activated automatically in chromium. So, this requires 'full screen' mode to be turned off, before being able to press the keyboard button. 317 | 318 | On Trixie, using wayland + labwc, I created the file ~/.config/labwc/autostart 319 | 320 | and added the line: 321 | 322 | ``` 323 | ~/run_kiosk.sh 324 | ``` 325 | 326 | On Bookworm, using wayland + wayfire, I added to ~/.config/wayfire.ini 327 | 328 | ``` 329 | [autostart] 330 | kiosk = ~/run_kiosk.sh 331 | ``` 332 | 333 | Note, that this wayfire.ini file does not exist, when using the default labwc configuration. 334 | 335 | HDMI monitor on / off works different for each environment: 336 | 337 | Use the screenoff2 / screenon2 rest api functions for labwc. This is what I use for Trixie (with labwc) 338 | 339 | Use the screenoff3 / screenon3 rest api functions for wayfire. This is what I used for Bookworm (with wayfire). 340 | 341 | After turning the screen back on, the browser is no longer full screen. 342 | 343 | the screenon3 api function also calls 'wtype' to send the F11 key, to go back to full screen. 344 | 345 | 346 | ## Web Server 347 | 348 | Copy all the web server application files and subdirectories to ~/kiosk-server 349 | 350 | Make application runnable using : 351 | ``` 352 | sudo chmod +x ~/kiosk-server/kiosk-server 353 | ``` 354 | 355 | Install the application as a service (Adjust kiosk-server.service if user or directory is different) : 356 | ``` 357 | sudo systemctl stop kiosk-server 358 | 359 | sudo cp ~/kiosk-server/kiosk-server.service /etc/systemd/system/kiosk-server.service 360 | 361 | sudo systemctl daemon-reload 362 | 363 | sudo systemctl enable kiosk-server 364 | 365 | sudo systemctl start kiosk-server 366 | ``` 367 | 368 | Check if service is running ok : 369 | ``` 370 | sudo systemctl status kiosk-server 371 | 372 | or 373 | 374 | sudo journalctl -u kiosk-server 375 | ``` 376 | 377 | ## Visual Studio Publish Action 378 | 379 | When using 'Publish' -> Visual Studio automatically synchronises all files to ~/kiosk-server using WinSCP. 380 | 381 | Adjust paths, ip address, user and password in .csproj file as required : 382 | ``` 383 | 384 | 385 | 386 | ``` 387 | 388 | Alternatively, you could also copy all the files using pscp, that comes with putty: 389 | 390 | ``` 391 | Target Name="PiCopy" AfterTargets="AfterPublish"> 392 | 393 | 394 | ``` 395 | 396 | First stop the web server, before updating the files : 397 | ``` 398 | sudo systemctl stop kiosk-server 399 | ``` 400 | 401 | ## Home Assistant Dashboards 402 | 403 | home assistant doesn't work inside an iframe, until you add to the configuration.yaml 404 | 405 | ``` 406 | http: 407 | use_x_frame_options : false 408 | ``` 409 | 410 | There is no on-screen keyboard, so an auto login mechanism is required: 411 | 412 | Add a new user 'Kiosk' 413 | 414 | The user id can be found on the details pop-up: 415 | ![home assistant](https://i.imgur.com/MzeJlGT.png) 416 | 417 | Then, add the IP address of the kiosk as trusted network and the Kiosk user id as a trusted user to configuration.yaml: 418 | ``` 419 | # Allow login without password from local network 420 | homeassistant: 421 | auth_providers: 422 | - type: trusted_networks 423 | trusted_networks: 424 | - 192.168.2.36/32 425 | trusted_users: 426 | 192.168.2.36: 427 | - dacfc03879144b31b57104cc00f6a1a2 ## specific user for kiosk 428 | allow_bypass_login: true 429 | - type: homeassistant 430 | ``` 431 | 432 | You can use the normal home assistant header navigation buttons, to switch between dashboards. 433 | 434 | Or you can also add each dashboard URL separately to the Kiosk URL List: 435 | 436 | ![touch screen](https://i.imgur.com/cXrHx23.png) 437 | 438 | ![home assistant](https://i.imgur.com/xlLNF75.jpg) 439 | 440 | I installed the 'Kiosk Mode' HACS frontend repository. See https://github.com/NemesisRE/kiosk-mode 441 | 442 | Now, you can use the kiosk query parameter, to hide the header and sidebar on the dashboard: 443 | 444 | For example : http://192.168.2.73:8123/lovelace/home?kiosk 445 | 446 | Note, that this only works correctly, if you hide the sidebar by default, for the Kiosk user: 447 | 448 | ![home assistant](https://i.imgur.com/pKVELn4.png) 449 | 450 | ## Transfer system status data to Home Assistant 451 | 452 | ``` 453 | 454 | sensor: 455 | - platform: rest 456 | name: kiosk_sensors 457 | scan_interval: 60 458 | resource: http://192.168.2.38:5000/api/status 459 | json_attributes: 460 | - disk 461 | - temperature 462 | - memory 463 | - cpu 464 | value_template: "OK" 465 | 466 | - platform: template 467 | sensors: 468 | kiosk_temperature: 469 | unique_id: kiosk_temperature 470 | friendly_name: "CPU Temperature" 471 | value_template: "{{ state_attr('sensor.kiosk_sensors', 'temperature')['cpuTemperature'] | round(1) }}" 472 | device_class: temperature 473 | unit_of_measurement: "°C" 474 | kiosk_cpu_percent: 475 | unique_id: kiosk_cpu_percent 476 | friendly_name: "CPU Usage" 477 | value_template: "{{ state_attr('sensor.kiosk_sensors', 'cpu')['cpuUsage'] | round(1)}}" 478 | unit_of_measurement: "%" 479 | ``` 480 | 481 | 482 | ## Turn off kiosk when PC is turned off 483 | 484 | ``` 485 | 486 | rest_command: 487 | kiosk_off: 488 | url: "http://192.168.2.38:5000/api/shutdown" 489 | method: POST 490 | 491 | binary_sensor: 492 | - platform: ping 493 | host: 192.168.2.35 494 | name: dev5_ping 495 | scan_interval: 60 496 | - platform: template 497 | sensors: 498 | dev5_online: 499 | unique_id: dev5_online 500 | friendly_name: "DEV5 Online" 501 | delay_off: 502 | minutes: 2 503 | value_template: "{{ states('binary_sensor.dev5_ping')}}" 504 | 505 | automation 506 | 507 | - id: '...........' 508 | alias: kiosk off when DEV5 off 509 | description: '' 510 | trigger: 511 | - platform: state 512 | entity_id: 513 | - binary_sensor.dev5_online 514 | from: 'on' 515 | to: 'off' 516 | condition: [] 517 | action: 518 | - service: rest_command.kiosk_off 519 | data: {} 520 | mode: single 521 | 522 | ``` 523 | --------------------------------------------------------------------------------