Add support for host redirect and set local network ip addrress
This commit is contained in:
parent
1c262fe5b3
commit
3a59c639a5
@ -8,5 +8,6 @@
|
||||
<add key="SeCount" value="25"/>
|
||||
<add key="TitleCount" value="4942"/>
|
||||
<add key="MusicDBName" value="music.db3"/>
|
||||
<add key="ServerIp" value="127.0.0.1"/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
|
@ -16,7 +16,7 @@ internal class Program
|
||||
|
||||
LogConfigValues();
|
||||
|
||||
var urlPrefixes = args.Length > 0 ? args : new[] { "http://*:80", "https://*:443" };
|
||||
var urlPrefixes = args.Length > 0 ? new List<string>(args) : new List<string> { "http://+:80", "https://+:443"};
|
||||
|
||||
using (var cts = new CancellationTokenSource())
|
||||
{
|
||||
@ -50,7 +50,7 @@ internal class Program
|
||||
/// </summary>
|
||||
/// <param name="urlPrefixes"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
private static async Task RunWebServerAsync(string[] urlPrefixes, CancellationToken cancellationToken)
|
||||
private static async Task RunWebServerAsync(IEnumerable<string> urlPrefixes, CancellationToken cancellationToken)
|
||||
{
|
||||
using var server = Server.CreateWebServer(urlPrefixes);
|
||||
await server.RunAsync(cancellationToken).ConfigureAwait(false);
|
||||
@ -93,7 +93,8 @@ internal class Program
|
||||
$"{nameof(Configs.TITLE_COUNT)} : {Configs.TITLE_COUNT}\n" +
|
||||
$"{nameof(Configs.AVATAR_COUNT)} : {Configs.AVATAR_COUNT}\n" +
|
||||
$"{nameof(Configs.NAVIGATOR_COUNT)} : {Configs.NAVIGATOR_COUNT}\n" +
|
||||
$"{nameof(Configs.MUSIC_DB_NAME)} : {Configs.MUSIC_DB_NAME}\n";
|
||||
$"{nameof(Configs.MUSIC_DB_NAME)} : {Configs.MUSIC_DB_NAME}\n" +
|
||||
$"{nameof(Configs.SERVER_ADDR)} : {Configs.SERVER_ADDR}\n";
|
||||
configs.Info();
|
||||
|
||||
var paths = $"Paths: {nameof(PathHelper.HtmlRootPath)}: {PathHelper.HtmlRootPath}\n" +
|
||||
|
@ -15,8 +15,9 @@ public static class CertificateHelper
|
||||
X509KeyUsageFlags.KeyEncipherment |
|
||||
X509KeyUsageFlags.DigitalSignature;
|
||||
|
||||
private const X509KeyStorageFlags X509_KEY_STORAGE_FLAGS_MACHINE = X509KeyStorageFlags.PersistKeySet
|
||||
| X509KeyStorageFlags.MachineKeySet;
|
||||
private const X509KeyStorageFlags X509_KEY_STORAGE_FLAGS_MACHINE = X509KeyStorageFlags.PersistKeySet |
|
||||
X509KeyStorageFlags.MachineKeySet |
|
||||
X509KeyStorageFlags.Exportable;
|
||||
|
||||
private const X509KeyUsageFlags CERT_X509_KEY_USAGE_FLAGS = X509KeyUsageFlags.DataEncipherment |
|
||||
X509KeyUsageFlags.KeyEncipherment |
|
||||
@ -50,10 +51,8 @@ public static class CertificateHelper
|
||||
|
||||
private static readonly SubjectAlternativeName SUBJECT_ALTERNATIVE_NAME = new()
|
||||
{
|
||||
DnsName = new List<string>
|
||||
{
|
||||
"localhost"
|
||||
}
|
||||
DnsName = Configs.DOMAINS,
|
||||
IpAddress = System.Net.IPAddress.Parse(Configs.SERVER_ADDR)
|
||||
};
|
||||
|
||||
private static readonly ValidityPeriod VALIDITY_PERIOD = new()
|
||||
@ -77,6 +76,7 @@ public static class CertificateHelper
|
||||
{
|
||||
return existingCert;
|
||||
}
|
||||
"Existing CN not found! Removing old certificates and genrate new ones...".Info();
|
||||
}
|
||||
|
||||
RemovePreviousCert(StoreName.My, StoreLocation.LocalMachine);
|
||||
|
@ -136,7 +136,11 @@ public static class Configs
|
||||
|
||||
public static readonly string MUSIC_DB_NAME;
|
||||
|
||||
private static readonly Configuration CONFIG = ConfigurationManager.OpenExeConfiguration(PathHelper.ConfigFilePath);
|
||||
public static readonly string SERVER_ADDR;
|
||||
|
||||
public static readonly List<string> DOMAINS;
|
||||
|
||||
private static readonly Configuration CONFIG = ConfigurationManager.OpenExeConfiguration(PathHelper.ConfigFilePath);
|
||||
|
||||
private const string AVATAR_COUNT_CONFIG_NAME = "AvatarCount";
|
||||
private const string NAVIGATOR_COUNT_CONFIG_NAME = "NavigatorCount";
|
||||
@ -145,38 +149,54 @@ public static class Configs
|
||||
private const string SKIN_COUNT_CONFIG_NAME = "SkinCount";
|
||||
private const string SE_COUNT_CONFIG_NAME = "SeCount";
|
||||
private const string MUSIC_DB_CONFIG_NAME = "MusicDBName";
|
||||
private const string SERVER_IP_CONFIG_NAME = "ServerIp";
|
||||
|
||||
private const int AVATAR_DEFAULT_COUNT = 294;
|
||||
private const int NAVIGATOR_DEFAULT_COUNT = 71;
|
||||
private const int ITEM_DEFAULT_COUNT = 21;
|
||||
private const int TITLE_DEFAULT_COUNT = 4942;
|
||||
private const int SKIN_DEFAULT_COUNT = 21;
|
||||
private const int SE_DEFAULT_COUNT = 25;
|
||||
private const string MUSIC_DB_DEFAULT_NAME = "music.db3";
|
||||
private const int DEFAULT_AVATAR_COUNT = 294;
|
||||
private const int DEFAULT_NAVIGATOR_COUNT = 71;
|
||||
private const int DEFAULT_ITEM_COUNT = 21;
|
||||
private const int DEFAULT_TITLE_COUNT = 4942;
|
||||
private const int DEFAULT_SKIN_COUNT = 21;
|
||||
private const int DEFAULT_SE_COUNT = 25;
|
||||
private const string DEFAULT_MUSIC_DB_NAME = "music.db3";
|
||||
private const string DEFAULT_SERVER_IP = "127.0.0.1";
|
||||
|
||||
|
||||
static Configs()
|
||||
{
|
||||
void GetIntValueFromConfig(string configFieldName, int defaultValue, out int field )
|
||||
static void GetIntValueFromConfig(string configFieldName, int defaultValue, out int field )
|
||||
{
|
||||
var success = int.TryParse(CONFIG.AppSettings.Settings[configFieldName].Value, out var count);
|
||||
|
||||
field = success ? count:defaultValue;
|
||||
}
|
||||
|
||||
GetIntValueFromConfig(AVATAR_COUNT_CONFIG_NAME, AVATAR_DEFAULT_COUNT, out AVATAR_COUNT);
|
||||
GetIntValueFromConfig(NAVIGATOR_COUNT_CONFIG_NAME, NAVIGATOR_DEFAULT_COUNT, out NAVIGATOR_COUNT);
|
||||
GetIntValueFromConfig(ITEM_COUNT_CONFIG_NAME, ITEM_DEFAULT_COUNT, out ITEM_COUNT);
|
||||
GetIntValueFromConfig(TITLE_COUNT_CONFIG_NAME, TITLE_DEFAULT_COUNT, out TITLE_COUNT);
|
||||
GetIntValueFromConfig(SKIN_COUNT_CONFIG_NAME, SKIN_DEFAULT_COUNT, out SKIN_COUNT);
|
||||
GetIntValueFromConfig(SE_COUNT_CONFIG_NAME, SE_DEFAULT_COUNT, out SE_COUNT);
|
||||
GetIntValueFromConfig(AVATAR_COUNT_CONFIG_NAME, DEFAULT_AVATAR_COUNT, out AVATAR_COUNT);
|
||||
GetIntValueFromConfig(NAVIGATOR_COUNT_CONFIG_NAME, DEFAULT_NAVIGATOR_COUNT, out NAVIGATOR_COUNT);
|
||||
GetIntValueFromConfig(ITEM_COUNT_CONFIG_NAME, DEFAULT_ITEM_COUNT, out ITEM_COUNT);
|
||||
GetIntValueFromConfig(TITLE_COUNT_CONFIG_NAME, DEFAULT_TITLE_COUNT, out TITLE_COUNT);
|
||||
GetIntValueFromConfig(SKIN_COUNT_CONFIG_NAME, DEFAULT_SKIN_COUNT, out SKIN_COUNT);
|
||||
GetIntValueFromConfig(SE_COUNT_CONFIG_NAME, DEFAULT_SE_COUNT, out SE_COUNT);
|
||||
|
||||
MUSIC_DB_NAME = CONFIG.AppSettings.Settings[MUSIC_DB_CONFIG_NAME].Value;
|
||||
|
||||
if (MUSIC_DB_NAME == string.Empty)
|
||||
if (string.IsNullOrWhiteSpace(MUSIC_DB_NAME))
|
||||
{
|
||||
MUSIC_DB_NAME = MUSIC_DB_DEFAULT_NAME;
|
||||
MUSIC_DB_NAME = DEFAULT_MUSIC_DB_NAME;
|
||||
}
|
||||
|
||||
SERVER_ADDR = CONFIG.AppSettings.Settings[SERVER_IP_CONFIG_NAME].Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SERVER_ADDR))
|
||||
{
|
||||
SERVER_ADDR = DEFAULT_SERVER_IP;
|
||||
}
|
||||
|
||||
DOMAINS = new()
|
||||
{
|
||||
"localhost",
|
||||
"cert.nesys.jp",
|
||||
"nesys.taito.co.jp",
|
||||
"fjm170920zero.nesica.net"
|
||||
};
|
||||
}
|
||||
}
|
@ -69,8 +69,8 @@ public class ServerController : WebApiController
|
||||
"pref=nesys\n" +
|
||||
"addr=nesys@home\n" +
|
||||
"x-next-time=15\n" +
|
||||
$"x-img=http://localhost{Configs.STATIC_BASE_ROUTE}/news.png\n" +
|
||||
$"x-ranking=http://localhost{Configs.RANK_BASE_ROUTE}/ranking.php\n" +
|
||||
$"x-img=http://{Configs.SERVER_ADDR}{Configs.STATIC_BASE_ROUTE}/news.png\n" +
|
||||
$"x-ranking=http://{Configs.SERVER_ADDR}{Configs.RANK_BASE_ROUTE}/ranking.php\n" +
|
||||
$"ticket={ticket}";
|
||||
|
||||
return response;
|
||||
|
@ -12,7 +12,7 @@ namespace GCLocalServerRewrite.server;
|
||||
|
||||
public class Server
|
||||
{
|
||||
public static WebServer CreateWebServer(string[] urlPrefixes)
|
||||
public static WebServer CreateWebServer(IEnumerable<string> urlPrefixes)
|
||||
{
|
||||
InitializeDatabase();
|
||||
var cert = CertificateHelper.InitializeCertificate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user