Various bugfixes.

This commit is contained in:
KZ 2015-07-24 22:38:31 +01:00
parent 960720b3e4
commit f31f89037c
12 changed files with 114 additions and 77 deletions

View File

@ -51,6 +51,7 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChang
[Run] [Run]
Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated; Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "--ReserveUrls"; Flags: waituntilterminated; Filename: "{app}\JackettConsole.exe"; Parameters: "--ReserveUrls"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "--MigrateSettings"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "--Install"; Flags: waituntilterminated; Tasks: windowsService Filename: "{app}\JackettConsole.exe"; Parameters: "--Install"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{app}\JackettConsole.exe"; Parameters: "--Start"; Flags: waituntilterminated; Tasks: windowsService Filename: "{app}\JackettConsole.exe"; Parameters: "--Start"; Flags: waituntilterminated; Tasks: windowsService

View File

@ -18,13 +18,13 @@ namespace Jackett.Console
[Option('u', "Uninstall", HelpText = "Uninstall Jackett windows service (Must be admin).")] [Option('u', "Uninstall", HelpText = "Uninstall Jackett windows service (Must be admin).")]
public bool Uninstall { get; set; } public bool Uninstall { get; set; }
[Option('l', "Logging", DefaultValue = false, HelpText = "Log all requests/responses to Jackett")] [Option('l', "Logging", HelpText = "Log all requests/responses to Jackett")]
public bool Logging { get; set; } public bool Logging { get; set; }
[Option('t', "Tracing", DefaultValue = false, HelpText = "Enable tracing")] [Option('t', "Tracing", HelpText = "Enable tracing")]
public bool Tracing { get; set; } public bool Tracing { get; set; }
[Option('c', "UseCurlExec", DefaultValue = false, HelpText = "Execute curl rather than libcurl for all outgoing requests.")] [Option('c', "UseCurlExec", HelpText = "Execute curl rather than libcurl for all outgoing requests.")]
public bool UseCurlExec { get; set; } public bool UseCurlExec { get; set; }
[Option('s', "Start", HelpText = "Start the Jacket Windows service (Must be admin)")] [Option('s', "Start", HelpText = "Start the Jacket Windows service (Must be admin)")]

View File

@ -16,7 +16,7 @@
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>

View File

@ -34,6 +34,31 @@ namespace JackettConsole
} }
else else
{ {
/* ====== Options ===== */
// Use curl
if (options.UseCurlExec)
Startup.CurlSafe = true;
// Logging
if (options.Logging)
Startup.LogRequests = true;
// Tracing
if (options.Tracing)
Startup.TracingEnabled = true;
// Log after the fact as using the logger will cause the options above to be used
if (options.UseCurlExec)
Engine.Logger.Info("Safe curl enabled.");
if (options.Logging)
Engine.Logger.Info("Logging enabled.");
if (options.Tracing)
Engine.Logger.Info("Tracing enabled.");
/* ====== Actions ===== */ /* ====== Actions ===== */
// Install service // Install service
@ -54,7 +79,6 @@ 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;
} }
@ -82,10 +106,7 @@ namespace JackettConsole
// Migrate settings // Migrate settings
if (options.MigrateSettings) if (options.MigrateSettings)
{ {
if (Engine.ServiceConfig.ServiceRunning()) Engine.ConfigService.PerformMigration();
{
Engine.ConfigService.PerformMigration();
}
return; return;
} }
@ -97,31 +118,14 @@ namespace JackettConsole
return; return;
} }
/* ====== Options ===== */ /* ====== Overrides ===== */
// Logging
if (options.Logging)
{
Startup.LogRequests = true;
}
// Tracing
if (options.Tracing)
{
Startup.TracingEnabled = true;
}
// Use curl
if (options.UseCurlExec)
{
Startup.CurlSafe = true;
}
// Override listen public // Override listen public
if(options.ListenPublic.HasValue) if(options.ListenPublic.HasValue)
{ {
if(Engine.Server.Config.AllowExternal != options.ListenPublic) if (Engine.Server.Config.AllowExternal != options.ListenPublic)
{ {
Engine.Logger.Info("Overriding external access to " + options.ListenPublic);
Engine.Server.Config.AllowExternal = options.ListenPublic.Value; Engine.Server.Config.AllowExternal = options.ListenPublic.Value;
if (System.Environment.OSVersion.Platform != PlatformID.Unix) if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{ {
@ -146,6 +150,7 @@ namespace JackettConsole
{ {
if (Engine.Server.Config.Port != options.Port) if (Engine.Server.Config.Port != options.Port)
{ {
Engine.Logger.Info("Overriding port to " + options.Port);
Engine.Server.Config.Port = options.Port; Engine.Server.Config.Port = options.Port;
if (System.Environment.OSVersion.Platform != PlatformID.Unix) if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{ {

View File

@ -308,23 +308,29 @@ namespace Jackett.Controllers
Engine.Server.Config.Port = port; Engine.Server.Config.Port = port;
Engine.Server.SaveConfig(); Engine.Server.SaveConfig();
if (!ServerUtil.IsUserAdministrator()) // On Windows change the url reservations
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{ {
try { if (!ServerUtil.IsUserAdministrator())
processService.StartProcessAndLog(Application.ExecutablePath, "--ReserveUrls", true);
}
catch
{ {
Engine.Server.Config.Port = originalPort; try
Engine.Server.Config.AllowExternal = originalAllowExternal; {
Engine.Server.SaveConfig(); processService.StartProcessAndLog(Application.ExecutablePath, "--ReserveUrls", true);
jsonReply["result"] = "error"; }
jsonReply["error"] = "Failed to acquire admin permissions to reserve the new port."; catch
return Json(jsonReply); {
Engine.Server.Config.Port = originalPort;
Engine.Server.Config.AllowExternal = originalAllowExternal;
Engine.Server.SaveConfig();
jsonReply["result"] = "error";
jsonReply["error"] = "Failed to acquire admin permissions to reserve the new port.";
return Json(jsonReply);
}
}
else
{
serverService.ReserveUrls(true);
} }
} else
{
serverService.ReserveUrls(true);
} }
(new Thread(() => { (new Thread(() => {

View File

@ -85,7 +85,7 @@ namespace Jackett.Indexers
else else
{ {
var configSaveData = new JObject(); var configSaveData = new JObject();
configSaveData["cookies"] = cookieHeader; configSaveData["cookie_header"] = cookieHeader;
SaveConfig(configSaveData); SaveConfig(configSaveData);
IsConfigured = true; IsConfigured = true;
} }
@ -93,7 +93,7 @@ namespace Jackett.Indexers
public void LoadFromSavedConfiguration(JToken jsonConfig) public void LoadFromSavedConfiguration(JToken jsonConfig)
{ {
cookieHeader = (string)jsonConfig["cookies"]; cookieHeader = (string)jsonConfig["cookie_header"];
IsConfigured = true; IsConfigured = true;
} }

View File

@ -52,21 +52,20 @@ namespace Jackett.Indexers
{ {
var config = new ConfigurationDataBasicLogin(); var config = new ConfigurationDataBasicLogin();
config.LoadValuesFromJson(configJson); config.LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string> { var pairs = new Dictionary<string, string> {
{ "username", config.Username.Value }, { "username", config.Username.Value },
{ "password", config.Password.Value }, { "password", config.Password.Value },
{ "login", "Log in" }, { "login", "Log in" },
{ "keeplogged", "1" } { "keeplogged", "1" }
}; };
var loginResponse = await client.GetString(new Utils.Clients.WebRequest() var loginResponse = await client.GetString(new Utils.Clients.WebRequest()
{ {
PostData = pairs, PostData = pairs,
Url = LoginUrl, Url = LoginUrl,
Type = RequestType.POST Type = RequestType.POST
}); });
if (loginResponse.Status == HttpStatusCode.Found) if (loginResponse.Status == HttpStatusCode.Found)
{ {
cookieHeader = loginResponse.Cookies; cookieHeader = loginResponse.Cookies;
@ -88,7 +87,7 @@ namespace Jackett.Indexers
else else
{ {
var configSaveData = new JObject(); var configSaveData = new JObject();
configSaveData["cookies"] = cookieHeader; configSaveData["cookie_header"] = cookieHeader;
SaveConfig(configSaveData); SaveConfig(configSaveData);
IsConfigured = true; IsConfigured = true;
} }
@ -96,12 +95,8 @@ namespace Jackett.Indexers
public void LoadFromSavedConfiguration(JToken jsonConfig) public void LoadFromSavedConfiguration(JToken jsonConfig)
{ {
// The old config used an array - just fail to load it cookieHeader = (string)jsonConfig["cookie_header"];
if (!(jsonConfig["cookies"] is JArray)) IsConfigured = true;
{
cookieHeader = (string)jsonConfig["cookies"];
IsConfigured = true;
}
} }
private void FillReleaseInfoFromJson(ReleaseInfo release, JObject r) private void FillReleaseInfoFromJson(ReleaseInfo release, JObject r)

View File

@ -24,14 +24,17 @@ namespace Jackett
if (Startup.CurlSafe) if (Startup.CurlSafe)
{ {
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>(); builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
Console.WriteLine("Using UnixSafeCurlWebClient");
} }
else if(System.Environment.OSVersion.Platform == PlatformID.Unix) else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
{ {
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>(); builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
Console.WriteLine("Using UnixLibCurlWebClient");
} }
else else
{ {
builder.RegisterType<WindowsWebClient>().As<IWebClient>(); builder.RegisterType<WindowsWebClient>().As<IWebClient>();
Console.WriteLine("Using WindowsWebClient");
} }
// Register indexers // Register indexers

View File

@ -7,6 +7,8 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -47,7 +49,13 @@ namespace Jackett.Services
{ {
if (!Directory.Exists(GetAppDataFolder())) if (!Directory.Exists(GetAppDataFolder()))
{ {
Directory.CreateDirectory(GetAppDataFolder()); var dir = Directory.CreateDirectory(GetAppDataFolder());
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
var access = dir.GetAccessControl();
access.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(GetAppDataFolder(), access);
}
} }
logger.Debug("App config/log directory: " + GetAppDataFolder()); logger.Debug("App config/log directory: " + GetAppDataFolder());
@ -57,13 +65,14 @@ namespace Jackett.Services
throw new Exception("Could not create settings directory. " + ex.Message); throw new Exception("Could not create settings directory. " + ex.Message);
} }
try if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{ {
string oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett"); try
if (Directory.Exists(oldDir))
{ {
if (System.Environment.OSVersion.Platform != PlatformID.Unix) string oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
if (Directory.Exists(oldDir))
{ {
// On Windows we need admin permissions to migrate as they were made with admin permissions. // On Windows we need admin permissions to migrate as they were made with admin permissions.
if (ServerUtil.IsUserAdministrator()) if (ServerUtil.IsUserAdministrator())
{ {
@ -82,35 +91,51 @@ namespace Jackett.Services
return; return;
} }
} }
} else }
else
{ {
PerformMigration(); PerformMigration();
} }
}
catch (Exception ex)
{
logger.Error("ERROR could not migrate settings directory " + ex);
} }
}
catch (Exception ex)
{
logger.Error("ERROR could not migrate settings directory " + ex);
} }
} }
public void PerformMigration() public void PerformMigration()
{ {
var oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett"); var oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories)) if (Directory.Exists(oldDir))
{ {
var path = file.Replace(oldDir, ""); foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories))
var destFolder = GetAppDataFolder() + path;
if (!Directory.Exists(Path.GetDirectoryName(destFolder)))
{ {
Directory.CreateDirectory(Path.GetDirectoryName(destFolder)); var path = file.Replace(oldDir, "");
} var destPath = GetAppDataFolder() + path;
if (!File.Exists(destFolder)) var destFolder = Path.GetDirectoryName(destPath);
{ if (!Directory.Exists(destFolder))
File.Copy(file, destFolder); {
var dir = Directory.CreateDirectory(destFolder);
var access = dir.GetAccessControl();
access.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(destFolder, access);
}
if (!File.Exists(destPath))
{
File.Copy(file, destPath);
// The old files were created when running as admin so make sure they are editable by normal users / services.
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
var access = File.GetAccessControl(destPath);
access.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
File.SetAccessControl(destPath, access);
}
}
} }
Directory.Delete(oldDir, true);
} }
Directory.Delete(oldDir, true);
} }
public T GetConfig<T>() public T GetConfig<T>()

View File

@ -44,7 +44,7 @@ namespace Jackett.Services
startInfo.RedirectStandardOutput = false; startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardInput = false; startInfo.RedirectStandardInput = false;
} }
logger.Debug("Running " + startInfo.FileName + " " + startInfo.Arguments);
var proc = Process.Start(startInfo); var proc = Process.Start(startInfo);
if (!asAdmin) if (!asAdmin)

View File

@ -55,6 +55,7 @@ namespace Jackett.Utils.Clients
} }
} }
logger.Debug("WebClientByteResult returned " + result.Status);
return result; return result;
} }

View File

@ -72,7 +72,7 @@ namespace Jackett.Utils.Clients
string stdout = null; string stdout = null;
await Task.Run(() => await Task.Run(() =>
{ {
stdout = processService.StartProcessAndGetOutput(@"C:\Apps\curl.exe", args.ToString(), true); stdout = processService.StartProcessAndGetOutput(System.Environment.OSVersion.Platform == PlatformID.Unix?"curl":"curl.exe", args.ToString(), true);
}); });
var outputData = File.ReadAllBytes(tempFile); var outputData = File.ReadAllBytes(tempFile);
@ -126,6 +126,7 @@ namespace Jackett.Utils.Clients
dest++; dest++;
} }
logger.Debug("WebClientByteResult returned " + result.Status);
return result; return result;
} }
} }