From 771b949618bb4e07c09c2fb94a7f92e13f471b9e Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 25 Dec 2025 19:59:26 +0100 Subject: Initial commit --- ShareGuard.Web/Components/App.razor | 22 +++++ ShareGuard.Web/Components/MainLayout.razor | 5 ++ ShareGuard.Web/Components/Pages/Admin.razor | 119 ++++++++++++++++++++++++++++ ShareGuard.Web/Components/Routes.razor | 6 ++ ShareGuard.Web/Components/_Imports.razor | 10 +++ 5 files changed, 162 insertions(+) create mode 100644 ShareGuard.Web/Components/App.razor create mode 100644 ShareGuard.Web/Components/MainLayout.razor create mode 100644 ShareGuard.Web/Components/Pages/Admin.razor create mode 100644 ShareGuard.Web/Components/Routes.razor create mode 100644 ShareGuard.Web/Components/_Imports.razor (limited to 'ShareGuard.Web/Components') diff --git a/ShareGuard.Web/Components/App.razor b/ShareGuard.Web/Components/App.razor new file mode 100644 index 0000000..0a3e255 --- /dev/null +++ b/ShareGuard.Web/Components/App.razor @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShareGuard.Web/Components/MainLayout.razor b/ShareGuard.Web/Components/MainLayout.razor new file mode 100644 index 0000000..f904d53 --- /dev/null +++ b/ShareGuard.Web/Components/MainLayout.razor @@ -0,0 +1,5 @@ +@inherits LayoutComponentBase + +
+ @Body +
diff --git a/ShareGuard.Web/Components/Pages/Admin.razor b/ShareGuard.Web/Components/Pages/Admin.razor new file mode 100644 index 0000000..3884630 --- /dev/null +++ b/ShareGuard.Web/Components/Pages/Admin.razor @@ -0,0 +1,119 @@ +@page "/admin/" +@using ShareGuard.Web.DbModels +@rendermode InteractiveServer + +ShareGuard Admin + +

ShareGuard Admin

+ +
Generate Share-Link
+
+ + +
+
+ + +
+ + +
WG-Quick Template
+

You can use the following placeholders: +
{ip} for the peer's ip address(es) +
{publicKey} for the peer's public key +
{privateKey} for the peer's private key

+
+ + This template will be generated for your users. +
+ + +@if (_links != null) +{ +
History
+ + + + + + + + + + + + @foreach (var link in _links) + { + + + + @if (link.PeerPublicKey == null) + { + + } + else + { + + } + + + + } + +
NameTokenClient Public KeyIP Address(es)Actions
@link.Name@link.TokenPending@link.PeerPublicKey@link.IpAddress + +
+} + +@code +{ + private const string TemplateFilePath = "./wg-quick-template.txt"; + private string? _template; + + private void SaveTemplate() + { + if (_template != null) + { + File.WriteAllText(TemplateFilePath, _template); + } + } + + private List? _links; + + protected override void OnInitialized() + { + if (File.Exists(TemplateFilePath)) _template = File.ReadAllText(TemplateFilePath); + using var db = new Database(); + _links = db.Links.ToList(); + } + + private string _newName = ""; + private string _newIpAddress = ""; + + private void GenerateNewLink() + { + using var db = new Database(); + db.Links.Add(new Link + { + Name = _newName, + IpAddress = _newIpAddress, + Token = Link.GenerateToken(db) + }); + db.SaveChanges(); + OnInitialized(); + } + + private void DeleteLink(Link link) + { + using var db = new Database(); + db.Remove(link); + db.SaveChanges(); + OnInitialized(); + } +} diff --git a/ShareGuard.Web/Components/Routes.razor b/ShareGuard.Web/Components/Routes.razor new file mode 100644 index 0000000..1f3983c --- /dev/null +++ b/ShareGuard.Web/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ShareGuard.Web/Components/_Imports.razor b/ShareGuard.Web/Components/_Imports.razor new file mode 100644 index 0000000..33e59de --- /dev/null +++ b/ShareGuard.Web/Components/_Imports.razor @@ -0,0 +1,10 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using ShareGuard.Web +@using ShareGuard.Web.Components \ No newline at end of file -- cgit v1.2.3