mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
cleaned up configuration files to use appsettings
This commit is contained in:
96
WebfrontCore/Application/ConfigurationGenerater.cs
Normal file
96
WebfrontCore/Application/ConfigurationGenerater.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using SharedLibrary;
|
||||
using SharedLibrary.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IW4MAdmin
|
||||
{
|
||||
class ConfigurationGenerator
|
||||
{
|
||||
public static List<ServerConfiguration> GenerateServerConfig(List<ServerConfiguration> configList)
|
||||
{
|
||||
|
||||
var newConfig = new ServerConfiguration();
|
||||
|
||||
while (string.IsNullOrEmpty(newConfig.IPAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Enter server IP Address: ");
|
||||
string input = Console.ReadLine();
|
||||
IPAddress.Parse(input);
|
||||
newConfig.IPAddress = input;
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while (newConfig.Port == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Enter server port: ");
|
||||
newConfig.Port = Int16.Parse(Console.ReadLine());
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Console.Write("Enter server RCON password: ");
|
||||
newConfig.Password = Console.ReadLine();
|
||||
|
||||
configList.Add(newConfig);
|
||||
|
||||
Console.Write("Configuration saved, add another? [y/n]:");
|
||||
if (Console.ReadLine().ToLower().First() == 'y')
|
||||
GenerateServerConfig(configList);
|
||||
|
||||
return configList;
|
||||
}
|
||||
|
||||
public static ApplicationConfiguration GenerateApplicationConfig()
|
||||
{
|
||||
var config = new ApplicationConfiguration();
|
||||
|
||||
Console.Write("Enable multiple owners? [y/n]: ");
|
||||
config.EnableMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Enable trusted rank? [y/n]: ");
|
||||
config.EnableTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Enable server-side anti-cheat [y/n]: ");
|
||||
config.EnableAntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Enable client VPNS [y/n]: ");
|
||||
config.EnableClientVPNs = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
if (!config.EnableClientVPNs)
|
||||
{
|
||||
Console.Write("Enter iphub.info api key: ");
|
||||
config.IPHubAPIKey = Console.ReadLine();
|
||||
}
|
||||
|
||||
Console.Write("Display Discord link on webfront [y/n]: ");
|
||||
config.EnableDiscordLink = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
if (config.EnableDiscordLink)
|
||||
{
|
||||
Console.Write("Enter Discord invite link: ");
|
||||
config.DiscordInviteCode = Console.ReadLine();
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,11 @@ using SharedLibrary.Exceptions;
|
||||
using SharedLibrary.Objects;
|
||||
using SharedLibrary.Services;
|
||||
using WebfrontCore.Application.API;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using WebfrontCore;
|
||||
using SharedLibrary.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace IW4MAdmin
|
||||
{
|
||||
@ -32,6 +37,7 @@ namespace IW4MAdmin
|
||||
ClientService ClientSvc;
|
||||
AliasService AliasSvc;
|
||||
PenaltyService PenaltySvc;
|
||||
IConfigurationRoot AppSettings;
|
||||
#if FTP_LOG
|
||||
const int UPDATE_FREQUENCY = 700;
|
||||
#else
|
||||
@ -40,7 +46,7 @@ namespace IW4MAdmin
|
||||
|
||||
private ApplicationManager()
|
||||
{
|
||||
Logger = new Logger($@"{SharedLibrary.Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log");
|
||||
Logger = new Logger($@"{Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log");
|
||||
_servers = new List<Server>();
|
||||
Commands = new List<Command>();
|
||||
TaskStatuses = new List<AsyncStatus>();
|
||||
@ -52,6 +58,13 @@ namespace IW4MAdmin
|
||||
ServerEventOccurred += EventAPI.OnServerEventOccurred;
|
||||
}
|
||||
|
||||
private void BuildConfiguration()
|
||||
{
|
||||
AppSettings = new ConfigurationBuilder()
|
||||
.AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json")
|
||||
.Build();
|
||||
}
|
||||
|
||||
public IList<Server> GetServers()
|
||||
{
|
||||
return Servers;
|
||||
@ -95,15 +108,21 @@ namespace IW4MAdmin
|
||||
#endregion
|
||||
|
||||
#region CONFIG
|
||||
var Configs = Directory.EnumerateFiles($"{Program.OperatingDirectory}config/servers").Where(x => x.Contains(".cfg"));
|
||||
BuildConfiguration();
|
||||
var settings = AppSettings.Get<ApplicationConfiguration>();
|
||||
|
||||
if (Configs.Count() == 0)
|
||||
ServerConfigurationGenerator.Generate();
|
||||
|
||||
foreach (var file in Configs)
|
||||
if (settings == null)
|
||||
{
|
||||
var Conf = ServerConfiguration.Read(file);
|
||||
settings = ConfigurationGenerator.GenerateApplicationConfig();
|
||||
settings.Servers = ConfigurationGenerator.GenerateServerConfig(new List<ServerConfiguration>());
|
||||
|
||||
var appConfigJSON = JsonConvert.SerializeObject(settings, Formatting.Indented);
|
||||
File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json", appConfigJSON);
|
||||
BuildConfiguration();
|
||||
}
|
||||
|
||||
foreach (var Conf in settings.Servers)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ServerInstance = new IW4MServer(this, Conf);
|
||||
@ -126,7 +145,7 @@ namespace IW4MAdmin
|
||||
|
||||
catch (ServerException e)
|
||||
{
|
||||
Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors");
|
||||
Logger.WriteError($"Not monitoring server {Conf.IPAddress}:{Conf.Port} due to uncorrectable errors");
|
||||
if (e.GetType() == typeof(DvarException))
|
||||
Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)");
|
||||
else if (e.GetType() == typeof(NetworkException))
|
||||
@ -260,5 +279,7 @@ namespace IW4MAdmin
|
||||
public ClientService GetClientService() => ClientSvc;
|
||||
public AliasService GetAliasService() => AliasSvc;
|
||||
public PenaltyService GetPenaltyService() => PenaltySvc;
|
||||
|
||||
public ApplicationConfiguration GetApplicationSettings() => AppSettings.Get<ApplicationConfiguration>();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace WebfrontCore.Application.Misc
|
||||
{
|
||||
public class VPNCheck
|
||||
{
|
||||
public static async Task<bool> UsingVPN(string ip)
|
||||
public static async Task<bool> UsingVPN(string ip, string apiKey)
|
||||
{
|
||||
#if DEBUG
|
||||
return false;
|
||||
@ -18,7 +18,7 @@ namespace WebfrontCore.Application.Misc
|
||||
{
|
||||
using (var RequestClient = new System.Net.Http.HttpClient())
|
||||
{
|
||||
RequestClient.DefaultRequestHeaders.Add("X-Key", Startup.Configuration["VPN:APIKey"]);
|
||||
RequestClient.DefaultRequestHeaders.Add("X-Key", apiKey);
|
||||
string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}");
|
||||
var responseJson = JsonConvert.DeserializeObject<JObject>(response);
|
||||
int blockType = Convert.ToInt32(responseJson["block"]);
|
||||
|
@ -14,6 +14,7 @@ using SharedLibrary.Services;
|
||||
using SharedLibrary.Database.Models;
|
||||
using SharedLibrary.Dtos;
|
||||
using WebfrontCore.Application.Misc;
|
||||
using SharedLibrary.Configuration;
|
||||
|
||||
namespace IW4MAdmin
|
||||
{
|
||||
@ -143,7 +144,8 @@ namespace IW4MAdmin
|
||||
await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this));
|
||||
|
||||
|
||||
if (Config.AllowClientVpn && await VPNCheck.UsingVPN(player.IPAddressString))
|
||||
if (!Manager.GetApplicationSettings().EnableClientVPNs &&
|
||||
await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().IPHubAPIKey))
|
||||
{
|
||||
await player.Kick("VPNs are not allowed on this server", new Player() { ClientId = 1 });
|
||||
}
|
||||
@ -621,7 +623,7 @@ namespace IW4MAdmin
|
||||
|
||||
string logPath = (game.Value == "" || onelog?.Value == 1) ?
|
||||
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" :
|
||||
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
||||
$"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}";
|
||||
|
||||
if (!File.Exists(logPath))
|
||||
{
|
||||
@ -661,7 +663,7 @@ namespace IW4MAdmin
|
||||
await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports");
|
||||
|
||||
// give trusted rank
|
||||
if (Config.AllowTrustedRank &&
|
||||
if (Manager.GetApplicationSettings().EnableTrustedRank &&
|
||||
E.Origin.TotalConnectionTime / 60.0 >= 2880 &&
|
||||
E.Origin.Level < Player.Permission.Trusted &&
|
||||
E.Origin.Level != Player.Permission.Flagged)
|
||||
|
@ -1,90 +0,0 @@
|
||||
using SharedLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IW4MAdmin
|
||||
{
|
||||
class ServerConfigurationGenerator
|
||||
{
|
||||
public static ServerConfiguration Generate()
|
||||
{
|
||||
string IP = String.Empty;
|
||||
int Port = 0;
|
||||
string Password;
|
||||
bool AllowMultipleOwners;
|
||||
bool AllowTrustedRank;
|
||||
bool AntiCheat;
|
||||
bool AllowVpns;
|
||||
|
||||
while (IP == String.Empty)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Enter server IP: ");
|
||||
string input = Console.ReadLine();
|
||||
IPAddress.Parse(input);
|
||||
IP = input;
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while (Port == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Write("Enter server port: ");
|
||||
Port = Int32.Parse(Console.ReadLine());
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write("Enter server RCON password: ");
|
||||
Password = Console.ReadLine();
|
||||
|
||||
Console.Write("Allow multiple owners? [y/n]: ");
|
||||
AllowMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Allow trusted rank? [y/n]: ");
|
||||
AllowTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Allow server-side anti-cheat [y/n]: ");
|
||||
AntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
Console.Write("Allow client VPNS [y/n]: ");
|
||||
AllowVpns = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
var config = new ServerConfiguration()
|
||||
{
|
||||
IP = IP,
|
||||
Password = Password,
|
||||
Port = Port,
|
||||
AllowMultipleOwners = AllowMultipleOwners,
|
||||
AllowTrustedRank = AllowTrustedRank,
|
||||
RestartPassword = "",
|
||||
RestartUsername = "",
|
||||
EnableAntiCheat = AntiCheat,
|
||||
AllowClientVpn = AllowVpns
|
||||
};
|
||||
|
||||
config.Write();
|
||||
|
||||
Console.Write("Configuration saved, add another? [y/n]:");
|
||||
if (Console.ReadLine().ToLower().First() == 'y')
|
||||
Generate();
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ namespace WebfrontCore.Controllers
|
||||
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
|
||||
ViewBag.Authorized = Authorized;
|
||||
ViewBag.Url = Startup.Configuration["Web:Address"];
|
||||
ViewBag.DiscordLink = Startup.Configuration["Discord:InviteLink"];
|
||||
ViewBag.DiscordLink = Manager.GetApplicationSettings().DiscordInviteCode;
|
||||
base.OnActionExecuting(context);
|
||||
}
|
||||
}
|
||||
|
0
WebfrontCore/IW4MAdminSettings.json
Normal file
0
WebfrontCore/IW4MAdminSettings.json
Normal file
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibrary.Configuration;
|
||||
|
||||
namespace WebfrontCore
|
||||
{
|
||||
@ -16,8 +17,7 @@ namespace WebfrontCore
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||||
.AddEnvironmentVariables();
|
||||
Configuration = builder.Build();
|
||||
|
||||
|
@ -34,9 +34,9 @@
|
||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Penalties", "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
|
||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Admins", "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
|
||||
<li class="nav-item text-center text-md-left">@Html.ActionLink("Console", "Index", "Console", new { area = "" }, new { @class = "nav-link" })</li>
|
||||
@if (ViewBag.DiscordLink != string.Empty)
|
||||
@if (!string.IsNullOrEmpty(ViewBag.DiscordLink))
|
||||
{
|
||||
<li class="nav-item text-center text-md-left"><a href="@ViewBag.DiscordLink" target="_blank"></a></li>
|
||||
<li class="nav-item text-center text-md-left"><a href="@ViewBag.DiscordLink" class="nav-link" target="_blank">Discord</a></li>
|
||||
}
|
||||
</ul>
|
||||
<form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync">
|
||||
|
@ -63,6 +63,12 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="IW4MAdminSettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="xcopy /Y "$(SolutionDir)BUILD\Plugins" "$(TargetDir)Plugins\"
xcopy /Y /I /E "$(SolutionDir)BUILD\Lib" "$(TargetDir)" 

xcopy /Y /I /E "$(ProjectDir)Application\Config" "$(TargetDir)Config"" />
|
||||
</Target>
|
||||
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
"Default": "Trace",
|
||||
"System": "Information",
|
||||
"Microsoft": "None"
|
||||
}
|
||||
},
|
||||
"Web": {
|
||||
"Address": "127.0.0.1:5000"
|
||||
},
|
||||
"VPN": {
|
||||
"APIKey": ""
|
||||
},
|
||||
"IW4MAdmin": {
|
||||
},
|
||||
"Discord": {
|
||||
"InviteLink" : ""
|
||||
}
|
||||
}
|
@ -9,13 +9,5 @@
|
||||
},
|
||||
"Web": {
|
||||
"Address": "http://127.0.0.1:5000"
|
||||
},
|
||||
"VPN": {
|
||||
"APIKey": ""
|
||||
},
|
||||
"IW4MAdmin": {
|
||||
},
|
||||
"Discord": {
|
||||
"InviteLink" : ""
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user