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]
Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; 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: "--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).")]
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; }
[Option('t', "Tracing", DefaultValue = false, HelpText = "Enable tracing")]
[Option('t', "Tracing", HelpText = "Enable tracing")]
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; }
[Option('s', "Start", HelpText = "Start the Jacket Windows service (Must be admin)")]

View File

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

View File

@ -34,6 +34,31 @@ namespace JackettConsole
}
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 ===== */
// Install service
@ -54,7 +79,6 @@ namespace JackettConsole
// Reserve urls
if (options.ReserveUrls)
{
Engine.ConfigService.CreateOrMigrateSettings();
Engine.Server.ReserveUrls(doInstall: true);
return;
}
@ -82,10 +106,7 @@ namespace JackettConsole
// Migrate settings
if (options.MigrateSettings)
{
if (Engine.ServiceConfig.ServiceRunning())
{
Engine.ConfigService.PerformMigration();
}
Engine.ConfigService.PerformMigration();
return;
}
@ -97,31 +118,14 @@ namespace JackettConsole
return;
}
/* ====== Options ===== */
// Logging
if (options.Logging)
{
Startup.LogRequests = true;
}
// Tracing
if (options.Tracing)
{
Startup.TracingEnabled = true;
}
// Use curl
if (options.UseCurlExec)
{
Startup.CurlSafe = true;
}
/* ====== Overrides ===== */
// Override listen public
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;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
@ -146,6 +150,7 @@ namespace JackettConsole
{
if (Engine.Server.Config.Port != options.Port)
{
Engine.Logger.Info("Overriding port to " + options.Port);
Engine.Server.Config.Port = options.Port;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{

View File

@ -308,23 +308,29 @@ namespace Jackett.Controllers
Engine.Server.Config.Port = port;
Engine.Server.SaveConfig();
if (!ServerUtil.IsUserAdministrator())
// On Windows change the url reservations
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
try {
processService.StartProcessAndLog(Application.ExecutablePath, "--ReserveUrls", true);
}
catch
if (!ServerUtil.IsUserAdministrator())
{
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);
try
{
processService.StartProcessAndLog(Application.ExecutablePath, "--ReserveUrls", true);
}
catch
{
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(() => {

View File

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

View File

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

View File

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

View File

@ -7,6 +7,8 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -47,7 +49,13 @@ namespace Jackett.Services
{
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());
@ -57,13 +65,14 @@ namespace Jackett.Services
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");
if (Directory.Exists(oldDir))
try
{
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.
if (ServerUtil.IsUserAdministrator())
{
@ -82,35 +91,51 @@ namespace Jackett.Services
return;
}
}
} else
}
else
{
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()
{
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, "");
var destFolder = GetAppDataFolder() + path;
if (!Directory.Exists(Path.GetDirectoryName(destFolder)))
foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories))
{
Directory.CreateDirectory(Path.GetDirectoryName(destFolder));
}
if (!File.Exists(destFolder))
{
File.Copy(file, destFolder);
var path = file.Replace(oldDir, "");
var destPath = GetAppDataFolder() + path;
var destFolder = Path.GetDirectoryName(destPath);
if (!Directory.Exists(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>()

View File

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

View File

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

View File

@ -72,7 +72,7 @@ namespace Jackett.Utils.Clients
string stdout = null;
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);
@ -126,6 +126,7 @@ namespace Jackett.Utils.Clients
dest++;
}
logger.Debug("WebClientByteResult returned " + result.Status);
return result;
}
}