Added port and public binding config options

This commit is contained in:
zone117x
2015-05-25 17:52:02 -06:00
parent 68c3f6ed4e
commit e2daa21914
3 changed files with 41 additions and 3 deletions

View File

@@ -88,6 +88,7 @@
<Compile Include="CookieContainerExtensions.cs" /> <Compile Include="CookieContainerExtensions.cs" />
<Compile Include="DataUrl.cs" /> <Compile Include="DataUrl.cs" />
<Compile Include="ExceptionWithConfigData.cs" /> <Compile Include="ExceptionWithConfigData.cs" />
<Compile Include="HttpClientExtensions.cs" />
<Compile Include="IndexerInterface.cs" /> <Compile Include="IndexerInterface.cs" />
<Compile Include="IndexerManager.cs" /> <Compile Include="IndexerManager.cs" />
<Compile Include="Indexers\BitHdtv.cs" /> <Compile Include="Indexers\BitHdtv.cs" />

View File

@@ -1,4 +1,6 @@
using NLog; using Jackett.Indexers;
using Newtonsoft.Json.Linq;
using NLog;
using NLog.Config; using NLog.Config;
using NLog.Targets; using NLog.Targets;
using System; using System;
@@ -28,6 +30,8 @@ namespace Jackett
public static bool IsWindows { get { return Environment.OSVersion.Platform == PlatformID.Win32NT; } } public static bool IsWindows { get { return Environment.OSVersion.Platform == PlatformID.Win32NT; } }
static void Main(string[] args) static void Main(string[] args)
{ {
ExitEvent = new ManualResetEvent(false); ExitEvent = new ManualResetEvent(false);
@@ -81,6 +85,8 @@ namespace Jackett
LogManager.Configuration = logConfig; LogManager.Configuration = logConfig;
LoggerInstance = LogManager.GetCurrentClassLogger(); LoggerInstance = LogManager.GetCurrentClassLogger();
ReadSettingsFile();
var serverTask = Task.Run(async () => var serverTask = Task.Run(async () =>
{ {
ServerInstance = new Server(); ServerInstance = new Server();
@@ -99,10 +105,32 @@ namespace Jackett
Console.WriteLine("Running in headless mode."); Console.WriteLine("Running in headless mode.");
Task.WaitAll(serverTask); Task.WaitAll(serverTask);
Console.WriteLine("Server thread exit"); Console.WriteLine("Server thread exit");
} }
static void ReadSettingsFile()
{
var path = Path.Combine(AppConfigDirectory, "config.json");
if (!File.Exists(path))
{
JObject f = new JObject();
f.Add("port", Server.DefaultPort);
f.Add("public", true);
File.WriteAllText(path, f.ToString());
}
var configJson = JObject.Parse(File.ReadAllText(path));
int port = (int)configJson.GetValue("port");
Server.Port = port;
Server.ListenPublic = (bool)configJson.GetValue("public");
Console.WriteLine("Config file path: " + path);
}
static public void RestartAsAdmin() static public void RestartAsAdmin()
{ {
var startInfo = new ProcessStartInfo(Application.ExecutablePath.ToString()) { Verb = "runas" }; var startInfo = new ProcessStartInfo(Application.ExecutablePath.ToString()) { Verb = "runas" };

View File

@@ -15,7 +15,9 @@ namespace Jackett
{ {
public class Server public class Server
{ {
public const int Port = 9117; public const int DefaultPort = 9117;
public static int Port = DefaultPort;
public static bool ListenPublic = true;
HttpListener listener; HttpListener listener;
IndexerManager indexerManager; IndexerManager indexerManager;
@@ -55,7 +57,13 @@ namespace Jackett
try try
{ {
listener = new HttpListener(); listener = new HttpListener();
listener.Prefixes.Add("http://*:9117/"); listener.Prefixes.Add(string.Format("http://127.0.0.1:{0}/", Port));
listener.Prefixes.Add(string.Format("http://localhost:{0}/", Port));
if (ListenPublic)
{
listener.Prefixes.Add(string.Format("http://*:{0}/", Port));
}
listener.Start(); listener.Start();
} }
catch (HttpListenerException ex) catch (HttpListenerException ex)
@@ -88,6 +96,7 @@ namespace Jackett
} }
Program.LoggerInstance.Info("Server started on port " + Port); Program.LoggerInstance.Info("Server started on port " + Port);
Program.LoggerInstance.Info("Accepting only requests from local system: " + (!ListenPublic));
while (true) while (true)
{ {