aboutsummaryrefslogtreecommitdiff
path: root/ShareGuard.Web/Components
diff options
context:
space:
mode:
Diffstat (limited to 'ShareGuard.Web/Components')
-rw-r--r--ShareGuard.Web/Components/App.razor22
-rw-r--r--ShareGuard.Web/Components/MainLayout.razor5
-rw-r--r--ShareGuard.Web/Components/Pages/Admin.razor119
-rw-r--r--ShareGuard.Web/Components/Routes.razor6
-rw-r--r--ShareGuard.Web/Components/_Imports.razor10
5 files changed, 162 insertions, 0 deletions
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 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="utf-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+ <base href="/"/>
+ <ResourcePreloader/>
+ <link rel="stylesheet" href="@Assets["beer.css"]"/>
+ <ImportMap/>
+ <link rel="icon" type="image/png" href="favicon.png"/>
+ <HeadOutlet/>
+</head>
+
+<body>
+<Routes/>
+<script src="@Assets["_framework/blazor.web.js"]"></script>
+<script src="@Assets["beer.js"]"></script>
+<script src="@Assets["wireguard.js"]"></script>
+</body>
+
+</html> \ 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
+
+<div style="margin-left: 3em;">
+ @Body
+</div>
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
+
+<PageTitle>ShareGuard Admin</PageTitle>
+
+<h2>ShareGuard Admin</h2>
+
+<h5>Generate Share-Link</h5>
+<div class="field label round border">
+ <input type="text" placeholder=" " @onchange="args => _newName = args.Value!.ToString()!">
+ <label>Name</label>
+</div>
+<div class="field label round border">
+ <input type="text" placeholder=" " @onchange="args => _newIpAddress = args.Value!.ToString()!">
+ <label>IP Address(es)</label>
+</div>
+<button class="border small-round large small-elevate" style="margin-top: 1em;" @onclick="GenerateNewLink">
+ <i>add_link</i>
+ <span>Generate</span>
+</button>
+
+<h5>WG-Quick Template</h5>
+<p>You can use the following placeholders:
+ <br/><code>{ip}</code> for the peer's ip address(es)
+ <br/><code>{publicKey}</code> for the peer's public key
+ <br/><code>{privateKey}</code> for the peer's private key</p>
+<div class="field extra border">
+ <textarea @onchange="args => _template = args.Value!.ToString()!">@_template</textarea>
+ <output>This template will be generated for your users.</output>
+</div>
+<button class="border small-round large small-elevate" style="margin-top: 1em;" @onclick="SaveTemplate">
+ <i>save</i>
+ <span>Save</span>
+</button>
+
+@if (_links != null)
+{
+ <h5>History</h5>
+ <table class="border medium-space">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Token</th>
+ <th>Client Public Key</th>
+ <th>IP Address(es)</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ @foreach (var link in _links)
+ {
+ <tr>
+ <td>@link.Name</td>
+ <td>@link.Token</td>
+ @if (link.PeerPublicKey == null)
+ {
+ <td>Pending</td>
+ }
+ else
+ {
+ <td><code>@link.PeerPublicKey</code></td>
+ }
+ <td>@link.IpAddress</td>
+ <td>
+ <button class="small-round tertiary small" @onclick="() => DeleteLink(link)">Delete link</button>
+ </td>
+ </tr>
+ }
+ </tbody>
+ </table>
+}
+
+@code
+{
+ private const string TemplateFilePath = "./wg-quick-template.txt";
+ private string? _template;
+
+ private void SaveTemplate()
+ {
+ if (_template != null)
+ {
+ File.WriteAllText(TemplateFilePath, _template);
+ }
+ }
+
+ private List<Link>? _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 @@
+<Router AppAssembly="typeof(Program).Assembly">
+ <Found Context="routeData">
+ <RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)"/>
+ <FocusOnNavigate RouteData="routeData" Selector="h1"/>
+ </Found>
+</Router> \ 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