Added configuration page in settings
This commit is contained in:
parent
9ad2ce50e3
commit
5e01835826
3 changed files with 133 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using NLog.Targets;
|
||||
using LANCommander.SDK.Enums;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace LANCommander.Models
|
||||
{
|
||||
|
|
@ -23,6 +24,7 @@ namespace LANCommander.Models
|
|||
public LANCommanderArchiveSettings Archives { get; set; } = new LANCommanderArchiveSettings();
|
||||
public LANCommanderMediaSettings Media { get; set; } = new LANCommanderMediaSettings();
|
||||
public LANCommanderIPXRelaySettings IPXRelay { get; set; } = new LANCommanderIPXRelaySettings();
|
||||
public LANCommanderVPNSettings VPN { get; set; } = new LANCommanderVPNSettings();
|
||||
public LANCommanderWikiSettings Wiki { get; set; } = new LANCommanderWikiSettings();
|
||||
public LANCommanderUpdateSettings Update { get; set; } = new LANCommanderUpdateSettings();
|
||||
public LANCommanderLogSettings Logs { get; set; } = new LANCommanderLogSettings();
|
||||
|
|
@ -90,6 +92,14 @@ namespace LANCommander.Models
|
|||
public bool Logging { get; set; } = false;
|
||||
}
|
||||
|
||||
public class LANCommanderVPNSettings
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
public IEnumerable<Guid> AllowedRoles { get; set; }
|
||||
public VPNType Type { get; set; } = VPNType.ZeroTier;
|
||||
public object Configuration { get; set; }
|
||||
}
|
||||
|
||||
public class LANCommanderWikiSettings
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
|
|
|
|||
27
LANCommander/UI/Pages/Settings/VPN/Forms/ZeroTier.razor
Normal file
27
LANCommander/UI/Pages/Settings/VPN/Forms/ZeroTier.razor
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
@using LANCommander.SDK.VPN.Configurations
|
||||
|
||||
<FormItem Label="Network ID">
|
||||
<Input @bind-Value="Configuration.NetworkId" />
|
||||
</FormItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public string Value { get; set; } = "";
|
||||
[Parameter] public EventCallback<string> ValueChanged { get; set; }
|
||||
|
||||
[Parameter] public ZeroTierConfiguration Configuration { get; set; } = new ZeroTierConfiguration();
|
||||
[Parameter] public EventCallback<ZeroTierConfiguration> ConfigurationChanged { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Configuration == null)
|
||||
{
|
||||
Configuration = new ZeroTierConfiguration();
|
||||
await ConfigurationChanged.InvokeAsync(Configuration);
|
||||
}
|
||||
}
|
||||
|
||||
async Task Changed()
|
||||
{
|
||||
await ConfigurationChanged.InvokeAsync(Configuration);
|
||||
}
|
||||
}
|
||||
95
LANCommander/UI/Pages/Settings/VPN/Index.razor
Normal file
95
LANCommander/UI/Pages/Settings/VPN/Index.razor
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
@page "/Settings/VPN"
|
||||
@using LANCommander.SDK.VPN.Configurations
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using LANCommander.Models;
|
||||
@using LANCommander.Extensions
|
||||
@using LANCommander.SDK.Enums
|
||||
@layout SettingsLayout
|
||||
@inject SettingService SettingService
|
||||
@inject IMessageService MessageService
|
||||
@inject RoleManager<Role> RoleManager
|
||||
@attribute [Authorize(Roles = "Administrator")]
|
||||
|
||||
<PageHeader Title="VPN" />
|
||||
|
||||
<div style="padding: 0 24px;">
|
||||
<Form Model="Settings" Layout="@FormLayout.Vertical">
|
||||
<FormItem Label="Enable">
|
||||
<Switch @bind-Checked="context.VPN.Enabled" />
|
||||
</FormItem>
|
||||
|
||||
<FormItem Label="Type">
|
||||
<Select @bind-Value="@context.VPN.Type" TItem="VPNType" TItemValue="VPNType" DataSource="Enum.GetValues<VPNType>()">
|
||||
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
||||
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
||||
</Select>
|
||||
</FormItem>
|
||||
|
||||
<FormItem Label="Allowed Roles">
|
||||
<Transfer DataSource="AllowedRolesTransferItems" TargetKeys="AllowedRolesTargetKeys" OnChange="OnChangeAllowedRoles" Titles="@(new string[] { "Available", "Allowed" })" />
|
||||
</FormItem>
|
||||
|
||||
@switch (context.VPN.Type)
|
||||
{
|
||||
case VPNType.ZeroTier:
|
||||
<LANCommander.UI.Pages.Settings.VPN.Forms.ZeroTier Configuration="context.VPN.Configuration as ZeroTierConfiguration" ConfigurationChanged="config => context.VPN.Configuration = config" />
|
||||
break;
|
||||
}
|
||||
|
||||
<FormItem>
|
||||
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
LANCommanderSettings Settings;
|
||||
|
||||
ICollection<Role> Roles = new List<Role>();
|
||||
IEnumerable<TransferItem> AllowedRolesTransferItems { get; set; } = new List<TransferItem>();
|
||||
List<string> AllowedRolesTargetKeys { get; set; } = new List<string>();
|
||||
ICollection<Role> SelectedAllowedRoles = new List<Role>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Settings = SettingService.GetSettings();
|
||||
Roles = await RoleManager.Roles.ToListAsync();
|
||||
|
||||
SelectedAllowedRoles = Roles.Where(r => Settings.VPN.AllowedRoles.Contains(r.Id)).ToList();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
AllowedRolesTransferItems = Roles.Select(r => new TransferItem()
|
||||
{
|
||||
Key = r.Id.ToString(),
|
||||
Title = r.Name
|
||||
});
|
||||
|
||||
if (SelectedAllowedRoles != null)
|
||||
AllowedRolesTargetKeys = SelectedAllowedRoles.Select(i => i.Id.ToString()).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
async Task OnChangeAllowedRoles(TransferChangeArgs e)
|
||||
{
|
||||
SelectedAllowedRoles = Roles.Where(r => e.TargetKeys.Contains(r.Id.ToString())).ToList();
|
||||
|
||||
Settings.VPN.AllowedRoles = SelectedAllowedRoles.Select(r => r.Id);
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
SettingService.SaveSettings(Settings);
|
||||
MessageService.Success("Settings saved!");
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageService.Error("An unknown error occurred.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue