start implementation of configuration via webfront

This commit is contained in:
RaidMax 2019-03-30 22:04:15 -05:00
parent 37d3f4f90d
commit 9393b35c39
10 changed files with 262 additions and 17 deletions

View File

@ -1,34 +1,58 @@
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace SharedLibraryCore.Configuration
{
public class ApplicationConfiguration : IBaseConfiguration
{
[LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")]
public bool EnableWebFront { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_MULTIOWN")]
public bool EnableMultipleOwners { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_STEPPEDPRIV")]
public bool EnableSteppedHierarchy { get; set; }
[LocalizedDisplayName("SETUP_DISPLAY_SOCIAL")]
public bool EnableSocialLink { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_CUSTOMSAY")]
public bool EnableCustomSayName { get; set; }
[LocalizedDisplayName("SETUP_SAY_NAME")]
public string CustomSayName { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_LINK")]
public string SocialLinkAddress { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_TITLE")]
public string SocialLinkTitle { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BIND_URL")]
public string WebfrontBindUrl { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MANUAL_URL")]
public string ManualWebfrontUrl { get; set; }
public string WebfrontUrl => string.IsNullOrEmpty(ManualWebfrontUrl) ? WebfrontBindUrl.Replace("0.0.0.0", "127.0.0.1") : ManualWebfrontUrl;
[LocalizedDisplayName("SETUP_USE_CUSTOMENCODING")]
public bool EnableCustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENCODING")]
public string CustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
public bool EnableCustomLocale { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
public string CustomLocale { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_DB_PROVIDER")]
public string DatabaseProvider { get; set; } = "sqlite";
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CONNECTION_STRING")]
public string ConnectionString { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_RCON_POLLRATE")]
public int RConPollRate { get; set; } = 5000;
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_IGNORE_BOTS")]
public bool IgnoreBots { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAX_TB")]
public TimeSpan MaximumTempBanTime { get; set; } = new TimeSpan(24 * 30, 0, 0);
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_WHITELIST")]
public bool EnableWebfrontConnectionWhitelist { get; set; }
public List<string> WebfrontConnectionWhitelist { get; set; }
public string Id { get; set; }
public List<ServerConfiguration> Servers { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
public int AutoMessagePeriod { get; set; }
public List<string> AutoMessages { get; set; }
public List<string> GlobalRules { get; set; }

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace SharedLibraryCore.Configuration
{
class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
private readonly string _localizationKey;
public LocalizedDisplayNameAttribute(string localizationKey)
{
_localizationKey = localizationKey;
}
public override string DisplayName => Utilities.CurrentLocalization.LocalizationIndex[_localizationKey];
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace WebfrontCore.Controllers
{
public class ConfigurationController : BaseController
{
public IActionResult Edit()
{
return View("Index", Manager.GetApplicationSettings().Configuration());
}
}
}

View File

@ -0,0 +1,150 @@
@model SharedLibraryCore.Configuration.ApplicationConfiguration
@{
ViewData["Title"] = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_TITLE"];
string optionalText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["COMMAND_HELP_OPTIONAL"];
string advancedText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADVANCED"];
string addText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADD"];
}
<div class="row">
<div class="col-12 text-white-50 configuration-form">
<form asp-action="Index">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<!-- start webfront settings -->
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input has-related-content" data-related-content="#enable_webfront_content" asp-for="EnableWebFront" /> @Html.DisplayNameFor(model => model.EnableWebFront)
</label>
</div>
<div id="enable_webfront_content" class="hide bg-dark pl-4 pr-4 pt-2 pb-2">
<div class="form-group">
<label asp-for="WebfrontBindUrl" class="control-label"></label>
<input asp-for="WebfrontBindUrl" class="form-control bg-dark text-white-50" />
<span asp-validation-for="WebfrontBindUrl" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ManualWebfrontUrl" class="control-label"></label>
<input asp-for="ManualWebfrontUrl" placeholder="@optionalText" class="form-control bg-dark text-white-50" />
<span asp-validation-for="ManualWebfrontUrl" class="text-danger"></span>
</div>
</div>
<!-- end webfront settings -->
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" asp-for="EnableMultipleOwners" /> @Html.DisplayNameFor(model => model.EnableMultipleOwners)
</label>
</div>
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" asp-for="EnableSteppedHierarchy" /> @Html.DisplayNameFor(model => model.EnableSteppedHierarchy)
</label>
</div>
<!-- start social link settings -->
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" data-related-content="#enable_social_content" asp-for="EnableSocialLink" /> @Html.DisplayNameFor(model => model.EnableSocialLink)
</label>
</div>
<div id="enable_social_content" class="hide bg-dark pl-4 pr-4 pt-2 pb-2">
<div class="form-group">
<label asp-for="SocialLinkAddress" class="control-label"></label>
<input asp-for="SocialLinkAddress" class="form-control bg-dark text-white-50" />
<span asp-validation-for="SocialLinkAddress" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="SocialLinkTitle" class="control-label"></label>
<input asp-for="SocialLinkTitle" class="form-control bg-dark text-white-50" />
<span asp-validation-for="SocialLinkTitle" class="text-danger"></span>
</div>
</div>
<!-- end social link settings -->
<!-- start custom say name settings -->
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" data-related-content="#enable_sayname_content" asp-for="EnableCustomSayName" /> @Html.DisplayNameFor(model => model.EnableCustomSayName)
</label>
</div>
<div id="enable_sayname_content" class="hide bg-dark pl-4 pr-4 pt-2 pb-2">
<div class="form-group">
<label asp-for="CustomSayName" class="control-label"></label>
<input asp-for="CustomSayName" class="form-control bg-dark text-white-50" />
<span asp-validation-for="CustomSayName" class="text-danger"></span>
</div>
</div>
<!-- end custom say name settings -->
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" asp-for="IgnoreBots" /> @Html.DisplayNameFor(model => model.IgnoreBots)
</label>
</div>
<div class="form-group form-check bg-primary mb-0">
<label class="form-check-label p-2 pl-4">
<input class="form-check-input" data-related-content="#enable_webfront_connection_whitelist_content" asp-for="EnableWebfrontConnectionWhitelist" /> @Html.DisplayNameFor(model => model.EnableWebfrontConnectionWhitelist)
</label>
</div>
<div id="enable_webfront_connection_whitelist_content" class="hide bg-dark pl-4 pr-4 pt-4 pb-4 ">
@Html.EditorFor(model => model.WebfrontConnectionWhitelist, new { htmlAttributes = new { @class = "form-control bg-dark text-white-50 mb-2" } })
<div class="btn btn-primary btn-block">@addText</div>
</div>
<div class="bg-primary mt-4">
<div class="p-2 pl-4">@advancedText</div>
</div>
<div class="bg-dark pl-4 pr-4 pt-2 pb-2">
<div class="form-group">
<label asp-for="CustomParserEncoding" class="control-label"></label>
<input asp-for="CustomParserEncoding" placeholder="@optionalText" class="form-control bg-dark text-white-50" />
<span asp-validation-for="CustomParserEncoding" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CustomLocale" class="control-label"></label>
<input asp-for="CustomLocale" placeholder="@optionalText" class="form-control bg-dark text-white-50" />
<span asp-validation-for="CustomLocale" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="DatabaseProvider" class="control-label"></label>
<input asp-for="DatabaseProvider" placeholder="@optionalText" class="form-control bg-dark text-white-50" />
<span asp-validation-for="DatabaseProvider" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ConnectionString" class="control-label"></label>
<input asp-for="ConnectionString" placeholder="@optionalText" class="form-control bg-dark text-white-50" />
<span asp-validation-for="ConnectionString" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="RConPollRate" class="control-label"></label>
<input asp-for="RConPollRate" class="form-control bg-dark text-white-50" />
<span asp-validation-for="RConPollRate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="MaximumTempBanTime" class="control-label"></label>
<input asp-for="MaximumTempBanTime" class="form-control bg-dark text-white-50" />
<span asp-validation-for="MaximumTempBanTime" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="AutoMessagePeriod" class="control-label"></label>
<input asp-for="AutoMessagePeriod" class="form-control bg-dark text-white-50" />
<span asp-validation-for="AutoMessagePeriod" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary btn-block" />
</div>
</form>
</div>
</div>
@section scripts {
<environment include="Development">
<script type="text/javascript" src="~/js/configuration.js"></script>
</environment>
}

View File

@ -28,53 +28,51 @@
</head>
<body>
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
@Html.ActionLink("IW4MAdmin", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item text-center text-md-left">@Html.ActionLink(loc["WEBFRONT_NAV_HOME"], "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-md-left">@Html.ActionLink(loc["WEBFRONT_NAV_PENALTIES"], "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-md-left">@Html.ActionLink(loc["WEBFRONT_NAV_PRIVILEGED"], "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-lg-left">@Html.ActionLink(loc["WEBFRONT_NAV_HOME"], "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-lg-left">@Html.ActionLink(loc["WEBFRONT_NAV_PENALTIES"], "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-lg-left">@Html.ActionLink(loc["WEBFRONT_NAV_PRIVILEGED"], "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
@foreach (var _page in ViewBag.Pages)
{
<li class="nav-item text-center text-md-left">
<li class="nav-item text-center text-lg-left">
<a class="nav-link" href="@_page.Location">@_page.Name</a>
</li>
}
<li class="nav-item text-center text-md-left"></li>
<li class="nav-item text-center text-lg-left"></li>
@if (!string.IsNullOrEmpty(ViewBag.SocialLink))
{
<li class="nav-item text-center text-md-left"><a href="@ViewBag.SocialLink" class="nav-link" target="_blank">@ViewBag.SocialTitle</a></li>
<li class="nav-item text-center text-lg-left"><a href="@ViewBag.SocialLink" class="nav-link" target="_blank">@ViewBag.SocialTitle</a></li>
}
@if (ViewBag.Authorized)
{
<li class="nav-link dropdown text-center text-md-left p-0">
<li class="nav-link dropdown text-center text-lg-left p-0">
<a href="#" class="nav-link oi oi-person dropdown-toggle oi-fix-navbar w-100" id="account_dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu p-0" aria-labelledby="account_dropdown">
@Html.ActionLink(loc["WEBFRONT_NAV_CONSOLE"], "Index", "Console", new { area = "" }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-md-left",
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Web Console"
})
@Html.ActionLink(loc["WEBFRONT_NAV_PROFILE"], "ProfileAsync", "Client", new { id = ViewBag.User.ClientId }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-md-left",
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Client Profile",
})
@Html.ActionLink(loc["WEBFRONT_NAV_LOGOUT"], "LogoutAsync", "Account", new { area = "" }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-md-left",
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Logout of account"
})
<a class="dropdown-item bg-dark text-muted text-center text-md-left profile-action" href="#" data-action="GenerateLoginToken" aria-hidden="true" title="@loc["WEBFRONT_ACTION_TOKEN"]">@loc["WEBFRONT_ACTION_TOKEN"]</a>
<a class="dropdown-item bg-dark text-muted text-center text-lg-left profile-action" href="#" data-action="GenerateLoginToken" aria-hidden="true" title="@loc["WEBFRONT_ACTION_TOKEN"]">@loc["WEBFRONT_ACTION_TOKEN"]</a>
</div>
</li>
<li class="nav-item text-center text-md-left"></li>
<li class="nav-item text-center text-md-left"></li>
}
else
{
@ -84,7 +82,7 @@
}
</ul>
<form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync">
<input id="client_search" name="clientName" class="form-control mr-auto ml-auto mr-md-2" type="text" placeholder="@loc["WEBFRONT_NAV_SEARCH"]" />
<input id="client_search" name="clientName" class="form-control mr-lg-2 w-100" type="text" placeholder="@loc["WEBFRONT_NAV_SEARCH"]" />
</form>
</div>
</nav>

View File

@ -66,6 +66,7 @@
<ItemGroup>
<PackageReference Include="Bower" Version="1.3.11" />
<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />
<PackageReference Include="Microsoft.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
@ -74,8 +75,16 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Update="Microsoft.NETCore.App" Version="2.2.2" />
<PackageReference Update="Microsoft.AspNetCore" Version="2.2.2" />
<PackageReference Update="Microsoft.AspNetCore" Version="2.2.0" />
</ItemGroup>
<ItemGroup>

View File

@ -25,7 +25,8 @@
"wwwroot/js/server.js",
"wwwroot/js/search.js",
"wwwroot/js/loader.js",
"wwwroot/js/stats.js"
"wwwroot/js/stats.js",
"wwwroot/js/configuration.js"
],
// Optionally specify minification options
"minify": {

View File

@ -6453,3 +6453,10 @@ form *, select {
.mt-n2 {
margin-top: -0.5rem !important; }
/* Configuration */
.configuration-form input[type='text'], .configuration-form input[type='number'] {
border: 1px solid #fd7e14; }
.hide {
display: none; }

View File

@ -265,3 +265,12 @@ form *, select {
.mt-n2 {
margin-top: -0.5rem !important;
}
/* Configuration */
.configuration-form input[type='text'], .configuration-form input[type='number'] {
border: 1px solid $orange;
}
.hide {
display: none;
}

View File

@ -0,0 +1,13 @@
$(document).ready(function() {
$.each($('.has-related-content'), function (key, value) {
value = $(value);
if (value.attr('checked').length > 0) {
$(value.data('related-content')).slideDown();
}
});
$('input:checkbox').change(function () {
var isChecked = $(this).is(':checked');
isChecked ? $($(this).data('related-content')).slideDown() : $($(this).data('related-content')).slideUp();
});
});