mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Add ListenPublic/Private overrides
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using Jackett.Common.Models.Config;
|
using Jackett.Common.Models.Config;
|
||||||
using Jackett.Common.Services;
|
using Jackett.Common.Services;
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
|
using Jackett.Common.Utils;
|
||||||
using Jackett.Server.Services;
|
using Jackett.Server.Services;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
@@ -9,6 +10,7 @@ using NLog.Targets;
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Jackett.Server
|
namespace Jackett.Server
|
||||||
{
|
{
|
||||||
@@ -109,6 +111,58 @@ namespace Jackett.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ProcessConsoleOverrides(ConsoleOptions consoleOptions, IProcessService processService, ServerConfig serverConfig, IConfigurationService configurationService, Logger logger)
|
||||||
|
{
|
||||||
|
// Override port
|
||||||
|
if (consoleOptions.Port != 0)
|
||||||
|
{
|
||||||
|
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
||||||
|
|
||||||
|
if (configPort != consoleOptions.Port)
|
||||||
|
{
|
||||||
|
logger.Info("Overriding port to " + consoleOptions.Port);
|
||||||
|
serverConfig.Port = consoleOptions.Port;
|
||||||
|
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||||
|
if (isWindows)
|
||||||
|
{
|
||||||
|
if (ServerUtil.IsUserAdministrator())
|
||||||
|
{
|
||||||
|
ReserveUrls(processService, serverConfig, logger, doInstall: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error("Unable to switch ports when not running as administrator");
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configurationService.SaveConfig(serverConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override listen public
|
||||||
|
if (consoleOptions.ListenPublic || consoleOptions.ListenPrivate)
|
||||||
|
{
|
||||||
|
if (serverConfig.AllowExternal != consoleOptions.ListenPublic)
|
||||||
|
{
|
||||||
|
logger.Info("Overriding external access to " + consoleOptions.ListenPublic);
|
||||||
|
serverConfig.AllowExternal = consoleOptions.ListenPublic;
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
if (ServerUtil.IsUserAdministrator())
|
||||||
|
{
|
||||||
|
ReserveUrls(processService, serverConfig, logger, doInstall: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error("Unable to switch to public listening without admin rights.");
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configurationService.SaveConfig(serverConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ReserveUrls(IProcessService processService, ServerConfig serverConfig, Logger logger, bool doInstall = true)
|
public static void ReserveUrls(IProcessService processService, ServerConfig serverConfig, Logger logger, bool doInstall = true)
|
||||||
{
|
{
|
||||||
logger.Debug("Unreserving Urls");
|
logger.Debug("Unreserving Urls");
|
||||||
|
@@ -102,37 +102,17 @@ namespace Jackett.Server
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ServerConfig serverConfig = configurationService.BuildServerConfig(Settings);
|
|
||||||
|
|
||||||
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
|
||||||
|
|
||||||
if (!isWebHostRestart)
|
if (!isWebHostRestart)
|
||||||
{
|
{
|
||||||
// Override port
|
if (consoleOptions.Port != 0 || consoleOptions.ListenPublic || consoleOptions.ListenPrivate)
|
||||||
if (consoleOptions.Port != 0)
|
|
||||||
{
|
{
|
||||||
if (configPort != consoleOptions.Port)
|
ServerConfig serverConfiguration = configurationService.BuildServerConfig(Settings);
|
||||||
{
|
Initialisation.ProcessConsoleOverrides(consoleOptions, processService, serverConfiguration, configurationService, logger);
|
||||||
logger.Info("Overriding port to " + consoleOptions.Port);
|
|
||||||
serverConfig.Port = consoleOptions.Port;
|
|
||||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
||||||
if (isWindows)
|
|
||||||
{
|
|
||||||
if (ServerUtil.IsUserAdministrator())
|
|
||||||
{
|
|
||||||
Initialisation.ReserveUrls(processService, serverConfig, logger, doInstall: true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Error("Unable to switch ports when not running as administrator");
|
|
||||||
Environment.Exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
configurationService.SaveConfig(serverConfig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerConfig serverConfig = configurationService.BuildServerConfig(Settings);
|
||||||
|
Int32.TryParse(serverConfig.Port.ToString(), out Int32 configPort);
|
||||||
string[] url = serverConfig.GetListenAddresses(serverConfig.AllowExternal).Take(1).ToArray(); //Kestrel doesn't need 127.0.0.1 and localhost to be registered, remove once off OWIN
|
string[] url = serverConfig.GetListenAddresses(serverConfig.AllowExternal).Take(1).ToArray(); //Kestrel doesn't need 127.0.0.1 and localhost to be registered, remove once off OWIN
|
||||||
|
|
||||||
isWebHostRestart = false;
|
isWebHostRestart = false;
|
||||||
|
Reference in New Issue
Block a user