Added UI for allowing external access, stop server listening on the old port when changing ports. Config migration bug fixes.

This commit is contained in:
KZ
2015-07-24 20:15:08 +01:00
parent 84c2b0c8b9
commit 960720b3e4
15 changed files with 149 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
rmdir /s /q build rmdir /s /q build
rmdir /s /q Output
cd src cd src
Msbuild Jackett.sln /t:Clean,Build /p:Configuration=Release Msbuild Jackett.sln /t:Clean,Build /p:Configuration=Release
cd .. cd ..
@@ -9,6 +10,8 @@ copy /Y src\Jackett.Service\bin\Release\JackettService.exe build\JackettService.
copy /Y src\Jackett.Service\bin\Release\JackettService.exe.config build\JackettService.exe.config copy /Y src\Jackett.Service\bin\Release\JackettService.exe.config build\JackettService.exe.config
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe build\JackettTray.exe copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe build\JackettTray.exe
copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe.config build\JackettTray.exe.config copy /Y src\Jackett.Tray\bin\Release\JackettTray.exe.config build\JackettTray.exe.config
copy /Y LICENSE build\LICENSE
copy /Y README.md build\README.md
cd build cd build
del *.pdb del *.pdb
del *.xml del *.xml

View File

@@ -9,8 +9,6 @@ namespace Jackett.Console
{ {
public class ConsoleOptions public class ConsoleOptions
{ {
private bool listenPublic = false;
[Option('i', "Install", HelpText = "Install Jackett windows service (Must be admin)")] [Option('i', "Install", HelpText = "Install Jackett windows service (Must be admin)")]
public bool Install { get; set; } public bool Install { get; set; }
@@ -47,5 +45,7 @@ namespace Jackett.Console
[Option('p', "Port", HelpText = "Web server port")] [Option('p', "Port", HelpText = "Web server port")]
public int Port { get; set; } public int Port { get; set; }
[Option('m', "MigrateSettings", HelpText = "Migrate settings manually (Must be admin on Windows)")]
public bool MigrateSettings { get; set; }
} }
} }

View File

@@ -54,6 +54,7 @@ namespace JackettConsole
// Reserve urls // Reserve urls
if (options.ReserveUrls) if (options.ReserveUrls)
{ {
Engine.ConfigService.CreateOrMigrateSettings();
Engine.Server.ReserveUrls(doInstall: true); Engine.Server.ReserveUrls(doInstall: true);
return; return;
} }
@@ -78,6 +79,16 @@ namespace JackettConsole
return; return;
} }
// Migrate settings
if (options.MigrateSettings)
{
if (Engine.ServiceConfig.ServiceRunning())
{
Engine.ConfigService.PerformMigration();
}
return;
}
// Show Version // Show Version
if (options.ShowVersion) if (options.ShowVersion)
@@ -125,6 +136,8 @@ namespace JackettConsole
return; return;
} }
} }
Engine.Server.SaveConfig();
} }
} }
@@ -147,6 +160,8 @@ namespace JackettConsole
return; return;
} }
} }
Engine.Server.SaveConfig();
} }
} }
} }

View File

@@ -203,3 +203,7 @@ hr {
margin-top: 10px; margin-top: 10px;
text-align: center; text-align: center;
} }
#jackett-allowext {
width: 25px;
}

View File

@@ -7,6 +7,7 @@ function loadJackettSettings() {
$("#api-key-input").val(data.config.api_key); $("#api-key-input").val(data.config.api_key);
$("#app-version").html(data.app_version); $("#app-version").html(data.app_version);
$("#jackett-port").val(data.config.port); $("#jackett-port").val(data.config.port);
$("#jackett-allowext").attr('checked', data.config.external);
var password = data.config.password; var password = data.config.password;
$("#jackett-adminpwd").val(password); $("#jackett-adminpwd").val(password);
if (password != null && password != '') { if (password != null && password != '') {
@@ -17,20 +18,21 @@ function loadJackettSettings() {
$("#change-jackett-port").click(function () { $("#change-jackett-port").click(function () {
var jackett_port = $("#jackett-port").val(); var jackett_port = $("#jackett-port").val();
var jsonObject = { port: jackett_port}; var jackett_external = $("#jackett-allowext").is(':checked');
var jsonObject = { port: jackett_port, external: jackett_external};
var jqxhr = $.post("/admin/set_port", JSON.stringify(jsonObject), function (data) { var jqxhr = $.post("/admin/set_port", JSON.stringify(jsonObject), function (data) {
if (data.result == "error") { if (data.result == "error") {
doNotify("Error: " + data.error, "danger", "glyphicon glyphicon-alert"); doNotify("Error: " + data.error, "danger", "glyphicon glyphicon-alert");
return; return;
} else { } else {
doNotify("The port has been changed. Redirecting you to the new port.", "success", "glyphicon glyphicon-ok"); doNotify("The port has been changed. Redirecting you to the new port.", "success", "glyphicon glyphicon-ok");
var jqxhr0 = $.post("admin/jackett_restart", null, function (data_restart) { });
window.setTimeout(function () { window.setTimeout(function () {
url = window.location.href; url = window.location.href;
window.location.href = url.substr(0, url.lastIndexOf(":") + 1) + data.port; if (data.external) {
window.location.href = url.substr(0, url.lastIndexOf(":") + 1) + data.port;
} else {
window.location.href = 'http://127.0.0.1:' + data.port;
}
}, 3000); }, 3000);
} }

View File

@@ -35,26 +35,33 @@
<span class="input-header">API Key: </span> <span class="input-header">API Key: </span>
<input id="api-key-input" class="form-control input-right" type="text" value="" placeholder="API Key" readonly=""> <input id="api-key-input" class="form-control input-right" type="text" value="" placeholder="API Key" readonly="">
</div> </div>
<hr />
<h3>Configured Indexers</h3>
<div id="indexers"> </div>
<hr />
<h3>Jackett Configuration</h3>
<div class="input-area"> <div class="input-area">
<span class="input-header">Admin Password: </span> <span class="input-header">Admin Password: </span>
<input id="jackett-adminpwd" class="form-control input-right" type="password" value="" placeholder="Blank to disable"> <input id="jackett-adminpwd" class="form-control input-right" type="password" value="" placeholder="Blank to disable" />
<button id="change-jackett-password" class="btn btn-primary btn-sm"> <button id="change-jackett-password" class="btn btn-primary btn-sm">
Set Password <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span> Set Password <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
</button> </button>
<a href="Dashboard?logout=true" id="logoutBtn" style="display:none" class="btn btn-danger btn-sm"> <a href="Dashboard?logout=true" id="logoutBtn" style="display:none" class="btn btn-danger btn-sm">
Logout Logout
</a> </a>
</div> </div>
<div class="input-area"> <div class="input-area">
<span class="input-header">Server port: </span> <span class="input-header">Server port: </span>
<input id="jackett-port" class="form-control input-right" type="text" value="" placeholder="9117"> <input id="jackett-port" class="form-control input-right" type="text" value="" placeholder="9117">
<button id="change-jackett-port" class="btn btn-primary btn-sm"> <button id="change-jackett-port" class="btn btn-primary btn-sm">
Change Port <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span> Apply server settings <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
</button> </button>
</div> </div>
<hr /> <div class="input-area">
<h3>Configured Indexers</h3> <span class="input-header">External access: </span>
<div id="indexers"> </div> <input id="jackett-allowext" class="form-control input-right" type="checkbox" />
</div>
<hr /> <hr />
<div id="footer"> <div id="footer">
Jackett Version <span id="app-version"></span> Jackett Version <span id="app-version"></span>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@@ -44,12 +44,21 @@ namespace Jackett.Controllers
if (!string.Equals(torznabQuery.ApiKey, serverService.Config.APIKey, StringComparison.InvariantCultureIgnoreCase)) if (!string.Equals(torznabQuery.ApiKey, serverService.Config.APIKey, StringComparison.InvariantCultureIgnoreCase))
{ {
logger.Warn(string.Format("A request from {0} was made with an incorrect API key.", Request.GetOwinContext().Request.RemoteIpAddress));
return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key"); return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key");
} }
var releases = await indexer.PerformQuery(torznabQuery); var releases = await indexer.PerformQuery(torznabQuery);
logger.Info(string.Format("Found {0} releases from {1}", releases.Length, indexer.DisplayName)); if (string.IsNullOrWhiteSpace(torznabQuery.SanitizedSearchTerm))
{
logger.Info(string.Format("Found {0} releases from {1}", releases.Length, indexer.DisplayName));
}
else
{
logger.Info(string.Format("Found {0} releases from {1} for: {2}", releases.Length, indexer.DisplayName, torznabQuery.SanitizedSearchTerm));
}
var severUrl = string.Format("{0}://{1}:{2}/", Request.RequestUri.Scheme, Request.RequestUri.Host, Request.RequestUri.Port); var severUrl = string.Format("{0}://{1}:{2}/", Request.RequestUri.Scheme, Request.RequestUri.Host, Request.RequestUri.Port);
var resultPage = new ResultPage(new ChannelInfo var resultPage = new ResultPage(new ChannelInfo

View File

@@ -260,6 +260,7 @@ namespace Jackett.Controllers
{ {
var cfg = new JObject(); var cfg = new JObject();
cfg["port"] = serverService.Config.Port; cfg["port"] = serverService.Config.Port;
cfg["external"] = serverService.Config.AllowExternal;
cfg["api_key"] = serverService.Config.APIKey; cfg["api_key"] = serverService.Config.APIKey;
cfg["password"] = string.IsNullOrEmpty(serverService.Config.AdminPassword )? string.Empty:serverService.Config.AdminPassword.Substring(0,10); cfg["password"] = string.IsNullOrEmpty(serverService.Config.AdminPassword )? string.Empty:serverService.Config.AdminPassword.Substring(0,10);
@@ -285,13 +286,15 @@ namespace Jackett.Controllers
public async Task<IHttpActionResult> SetConfig() public async Task<IHttpActionResult> SetConfig()
{ {
var originalPort = Engine.Server.Config.Port; var originalPort = Engine.Server.Config.Port;
var originalAllowExternal = Engine.Server.Config.AllowExternal;
var jsonReply = new JObject(); var jsonReply = new JObject();
try try
{ {
var postData = await ReadPostDataJson(); var postData = await ReadPostDataJson();
int port = (int)postData["port"]; int port = (int)postData["port"];
bool external = (bool)postData["external"];
if (port != Engine.Server.Config.Port) if (port != Engine.Server.Config.Port || external != Engine.Server.Config.AllowExternal)
{ {
if (ServerUtil.RestrictedPorts.Contains(port)) if (ServerUtil.RestrictedPorts.Contains(port))
{ {
@@ -300,6 +303,8 @@ namespace Jackett.Controllers
return Json(jsonReply); return Json(jsonReply);
} }
// Save port to the config so it can be picked up by the if needed when running as admin below.
Engine.Server.Config.AllowExternal = external;
Engine.Server.Config.Port = port; Engine.Server.Config.Port = port;
Engine.Server.SaveConfig(); Engine.Server.SaveConfig();
@@ -311,6 +316,7 @@ namespace Jackett.Controllers
catch catch
{ {
Engine.Server.Config.Port = originalPort; Engine.Server.Config.Port = originalPort;
Engine.Server.Config.AllowExternal = originalAllowExternal;
Engine.Server.SaveConfig(); Engine.Server.SaveConfig();
jsonReply["result"] = "error"; jsonReply["result"] = "error";
jsonReply["error"] = "Failed to acquire admin permissions to reserve the new port."; jsonReply["error"] = "Failed to acquire admin permissions to reserve the new port.";
@@ -323,12 +329,16 @@ namespace Jackett.Controllers
(new Thread(() => { (new Thread(() => {
Thread.Sleep(500); Thread.Sleep(500);
serverService.Start(); serverService.Stop();
Engine.BuildContainer();
Engine.Server.Initalize();
Engine.Server.Start();
})).Start(); })).Start();
} }
jsonReply["result"] = "success"; jsonReply["result"] = "success";
jsonReply["port"] = port; jsonReply["port"] = port;
jsonReply["external"] = external;
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -2,6 +2,7 @@
using Jackett.Services; using Jackett.Services;
using NLog; using NLog;
using NLog.Config; using NLog.Config;
using NLog.LayoutRenderers;
using NLog.Targets; using NLog.Targets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -107,8 +108,10 @@ namespace Jackett
private static void SetupLogging(ContainerBuilder builder) private static void SetupLogging(ContainerBuilder builder)
{ {
var logConfig = new LoggingConfiguration(); // Add custom date time format renderer as the default is too long
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("simpledatetime", typeof(SimpleDateTimeRenderer));
var logConfig = new LoggingConfiguration();
var logFile = new FileTarget(); var logFile = new FileTarget();
logConfig.AddTarget("file", logFile); logConfig.AddTarget("file", logFile);
logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}"; logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
@@ -124,7 +127,7 @@ namespace Jackett
var logConsole = new ColoredConsoleTarget(); var logConsole = new ColoredConsoleTarget();
logConfig.AddTarget("console", logConsole); logConfig.AddTarget("console", logConsole);
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}"; logConsole.Layout = "${simpledatetime} ${level} ${message} ${exception:format=ToString}";
var logConsoleRule = new LoggingRule("*", Startup.TracingEnabled ? LogLevel.Debug : LogLevel.Info, logConsole); var logConsoleRule = new LoggingRule("*", Startup.TracingEnabled ? LogLevel.Debug : LogLevel.Info, logConsole);
logConfig.LoggingRules.Add(logConsoleRule); logConfig.LoggingRules.Add(logConsoleRule);
@@ -132,4 +135,13 @@ namespace Jackett
builder.RegisterInstance<Logger>(LogManager.GetCurrentClassLogger()).SingleInstance(); builder.RegisterInstance<Logger>(LogManager.GetCurrentClassLogger()).SingleInstance();
} }
} }
[LayoutRenderer("simpledatetime")]
public class SimpleDateTimeRenderer : LayoutRenderer
{
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
builder.Append(DateTime.Now.ToString("MM-dd HH:mm:ss"));
}
}
} }

View File

@@ -103,12 +103,27 @@ namespace Jackett.Indexers
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString(); var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString); var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
var response = await webclient.GetString(new Utils.Clients.WebRequest() WebClientStringResult response = null;
// Their web server is fairly flakey - try up to three times.
for (int i = 0; i < 3; i++)
{ {
Url = episodeSearchUrl, try
Referer = SiteLink.ToString(), {
Cookies = cookieHeader response = await webclient.GetString(new Utils.Clients.WebRequest()
}); {
Url = episodeSearchUrl,
Referer = SiteLink.ToString(),
Cookies = cookieHeader
});
break;
}
catch (Exception e)
{
logger.Error("On attempt " + (i + 1) + " checking for results from IPTorrents: " + e.Message);
}
}
var results = response.Content; var results = response.Content;
try try

View File

@@ -138,7 +138,7 @@ namespace Jackett.Indexers
break; break;
} }
catch (Exception e){ catch (Exception e){
logger.Error(e, "Error checking for results from MoreThanTv."); logger.Error("On attempt " + (i+1) + " checking for results from MoreThanTv: " + e.Message );
} }
} }

View File

@@ -272,6 +272,7 @@
<Content Include="Content\logos\animebytes.png"> <Content Include="Content\logos\animebytes.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\logos\BakaBT.png" />
<Content Include="Content\logos\bb.png"> <Content Include="Content\logos\bb.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Jackett.Utils;
using Newtonsoft.Json.Linq;
using NLog; using NLog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -22,21 +23,25 @@ namespace Jackett.Services
T GetConfig<T>(); T GetConfig<T>();
void SaveConfig<T>(T config); void SaveConfig<T>(T config);
string ApplicationFolder(); string ApplicationFolder();
void CreateOrMigrateSettings();
void PerformMigration();
} }
public class ConfigurationService : IConfigurationService public class ConfigurationService : IConfigurationService
{ {
private ISerializeService serializeService; private ISerializeService serializeService;
private Logger logger; private Logger logger;
private IProcessService processService;
public ConfigurationService(ISerializeService s, Logger l) public ConfigurationService(ISerializeService s, IProcessService p, Logger l)
{ {
serializeService = s; serializeService = s;
logger = l; logger = l;
processService = p;
CreateOrMigrateSettings(); CreateOrMigrateSettings();
} }
private void CreateOrMigrateSettings() public void CreateOrMigrateSettings()
{ {
try try
{ {
@@ -57,20 +62,30 @@ namespace Jackett.Services
string oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett"); string oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
if (Directory.Exists(oldDir)) if (Directory.Exists(oldDir))
{ {
foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories)) if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{ {
var path = file.Replace(oldDir, ""); // On Windows we need admin permissions to migrate as they were made with admin permissions.
var destFolder = GetAppDataFolder() + path; if (ServerUtil.IsUserAdministrator())
if (!Directory.Exists(Path.GetDirectoryName(destFolder)))
{ {
Directory.CreateDirectory(Path.GetDirectoryName(destFolder)); PerformMigration();
} }
if (!File.Exists(destFolder)) else
{ {
File.Move(file, destFolder); try
{
processService.StartProcessAndLog(Application.ExecutablePath, "--MigrateSettings", true);
}
catch
{
Engine.Logger.Error("Unable to migrate settings when not running as administrator.");
Environment.ExitCode = 1;
return;
}
} }
} else
{
PerformMigration();
} }
Directory.Delete(oldDir, true);
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -79,6 +94,25 @@ namespace Jackett.Services
} }
} }
public void PerformMigration()
{
var oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories))
{
var path = file.Replace(oldDir, "");
var destFolder = GetAppDataFolder() + path;
if (!Directory.Exists(Path.GetDirectoryName(destFolder)))
{
Directory.CreateDirectory(Path.GetDirectoryName(destFolder));
}
if (!File.Exists(destFolder))
{
File.Copy(file, destFolder);
}
}
Directory.Delete(oldDir, true);
}
public T GetConfig<T>() public T GetConfig<T>()
{ {
var type = typeof(T); var type = typeof(T);

View File

@@ -131,7 +131,7 @@ namespace Jackett.Services
if (doInstall) if (doInstall)
{ {
logger.Debug("Reserving Urls"); logger.Debug("Reserving Urls");
config.GetListenAddresses(true).ToList().ForEach(u => RunNetSh(string.Format("http add urlacl {0} sddl=D:(A;;GX;;;S-1-1-0)", u))); config.GetListenAddresses(config.AllowExternal).ToList().ForEach(u => RunNetSh(string.Format("http add urlacl {0} sddl=D:(A;;GX;;;S-1-1-0)", u)));
logger.Debug("Urls reserved"); logger.Debug("Urls reserved");
} }
} }