diff --git a/Build.bat b/Build.bat index 8ee0b9dc0..c524d6c2a 100644 --- a/Build.bat +++ b/Build.bat @@ -1,5 +1,6 @@ rmdir /s /q build +rmdir /s /q Output cd src Msbuild Jackett.sln /t:Clean,Build /p:Configuration=Release 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.Tray\bin\Release\JackettTray.exe build\JackettTray.exe 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 del *.pdb del *.xml diff --git a/Installer.iss b/Installer.iss index cae6ef11d..6733eda52 100644 --- a/Installer.iss +++ b/Installer.iss @@ -49,12 +49,13 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent [Run] -Filename: "{app}\JackettConsole.exe"; Parameters: "/u"; Flags: waituntilterminated; -Filename: "{app}\JackettConsole.exe"; Parameters: "/r"; Flags: waituntilterminated; -Filename: "{app}\JackettConsole.exe"; Parameters: "/i"; Flags: waituntilterminated; Tasks: windowsService -Filename: "{app}\JackettConsole.exe"; Parameters: "/start"; Flags: waituntilterminated; Tasks: windowsService +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 [UninstallRun] -Filename: "{app}\JackettConsole.exe"; Parameters: "/u"; Flags: waituntilterminated skipifdoesntexist +Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated skipifdoesntexist diff --git a/src/Jackett.Console/ConsoleOptions.cs b/src/Jackett.Console/ConsoleOptions.cs new file mode 100644 index 000000000..34030a6b2 --- /dev/null +++ b/src/Jackett.Console/ConsoleOptions.cs @@ -0,0 +1,51 @@ +using CommandLine; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jackett.Console +{ + public class ConsoleOptions + { + [Option('i', "Install", HelpText = "Install Jackett windows service (Must be admin)")] + public bool Install { get; set; } + + [Option('r', "ReserveUrls", HelpText = "(Re)Register windows port reservations (Required for listening on all interfaces).")] + public bool ReserveUrls { get; set; } + + [Option('u', "Uninstall", HelpText = "Uninstall Jackett windows service (Must be admin).")] + public bool Uninstall { get; set; } + + [Option('l', "Logging", HelpText = "Log all requests/responses to Jackett")] + public bool Logging { get; set; } + + [Option('t', "Tracing", HelpText = "Enable tracing")] + public bool Tracing { get; set; } + + [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)")] + public bool StartService { get; set; } + + [Option('k', "Stop", HelpText = "Stop the Jacket Windows service (Must be admin)")] + public bool StopService { get; set; } + + [Option('l', "ListenPublic", HelpText = "Listen publicly")] + public bool? ListenPublic { get; set; } + + [Option('h', "Help", HelpText = "Show Help")] + public bool ShowHelp { get; set; } + + [Option('v', "Version", HelpText = "Show Version")] + public bool ShowVersion { get; set; } + + [Option('p', "Port", HelpText = "Web server port")] + public int Port { get; set; } + + [Option('m', "MigrateSettings", HelpText = "Migrate settings manually (Must be admin on Windows)")] + public bool MigrateSettings { get; set; } + } +} diff --git a/src/Jackett.Console/Jackett.Console.csproj b/src/Jackett.Console/Jackett.Console.csproj index bf9675a02..f5063bb4f 100644 --- a/src/Jackett.Console/Jackett.Console.csproj +++ b/src/Jackett.Console/Jackett.Console.csproj @@ -16,7 +16,7 @@ - AnyCPU + x64 true full false @@ -55,6 +55,10 @@ ..\packages\Autofac.WebApi2.Owin.3.2.0\lib\net45\Autofac.Integration.WebApi.Owin.dll + + ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll + True + ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll @@ -127,6 +131,7 @@ + diff --git a/src/Jackett.Console/Program.cs b/src/Jackett.Console/Program.cs index f948fab86..afbbd5ce1 100644 --- a/src/Jackett.Console/Program.cs +++ b/src/Jackett.Console/Program.cs @@ -1,5 +1,9 @@ -using Jackett; +using CommandLine; +using CommandLine.Text; +using Jackett; +using Jackett.Console; using Jackett.Indexers; +using Jackett.Utils; using System; using System.Collections.Generic; using System.Diagnostics; @@ -18,44 +22,152 @@ namespace JackettConsole { try { - foreach (var arg in args) + var options = new ConsoleOptions(); + if (!Parser.Default.ParseArguments(args, options) || options.ShowHelp == true) { - switch (arg.ToLowerInvariant()) + var text = HelpText.AutoBuild(options, (HelpText current) => HelpText.DefaultParsingErrorsHandler(options, current)); + text.Copyright = " "; + text.Heading = "Jackett v" + Engine.ConfigService.GetVersion() + " options:"; + Console.WriteLine(text); + Environment.ExitCode = 1; + return; + } + 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 + if (options.Install) { - case "/i": // Install - Engine.ServiceConfig.Install(); - return; - case "/r": // Reserve port/url & install - Engine.Server.ReserveUrls(doInstall: true); - return; - case "/c": // Change port - Engine.Server.ReserveUrls(doInstall: false); - return; - case "/u": // Uninstall - Engine.Server.ReserveUrls(doInstall: false); - Engine.ServiceConfig.Uninstall(); - return; - case "/l": // Logging - Startup.LogRequests = true; - break; - case "/t": // Tracing - Startup.TracingEnabled = true; - break; - case "/curlsafe": // Curl safe mode - Startup.CurlSafe = true; - break; - case "/start": // Start Service - if (!Engine.ServiceConfig.ServiceRunning()) + Engine.ServiceConfig.Install(); + return; + } + + // Uninstall service + if (options.Uninstall) + { + Engine.Server.ReserveUrls(doInstall: false); + Engine.ServiceConfig.Uninstall(); + return; + } + + // Reserve urls + if (options.ReserveUrls) + { + Engine.Server.ReserveUrls(doInstall: true); + return; + } + + // Start Service + if (options.StartService) + { + if (!Engine.ServiceConfig.ServiceRunning()) + { + Engine.ServiceConfig.Start(); + } + return; + } + + // Stop Service + if (options.StopService) + { + if (Engine.ServiceConfig.ServiceRunning()) + { + Engine.ServiceConfig.Stop(); + } + return; + } + + // Migrate settings + if (options.MigrateSettings) + { + Engine.ConfigService.PerformMigration(); + return; + } + + + // Show Version + if (options.ShowVersion) + { + Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion()); + return; + } + + /* ====== Overrides ===== */ + + // Override listen public + if(options.ListenPublic.HasValue) + { + 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) { - Engine.ServiceConfig.Start(); + if (ServerUtil.IsUserAdministrator()) + { + Engine.Server.ReserveUrls(doInstall: true); + } + else + { + Engine.Logger.Error("Unable to switch to public listening without admin rights."); + Environment.ExitCode = 1; + return; + } } - return; - case "/stop": // Stop Service - if (Engine.ServiceConfig.ServiceRunning()) + + Engine.Server.SaveConfig(); + } + } + + // Override port + if(options.Port != 0) + { + 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) { - Engine.ServiceConfig.Stop(); + if (ServerUtil.IsUserAdministrator()) + { + Engine.Server.ReserveUrls(doInstall: true); + } + else + { + Engine.Logger.Error("Unable to switch ports when not running as administrator"); + Environment.ExitCode = 1; + return; + } } - return; + + Engine.Server.SaveConfig(); + } } } diff --git a/src/Jackett.Console/packages.config b/src/Jackett.Console/packages.config index 2b7546d65..30ec668de 100644 --- a/src/Jackett.Console/packages.config +++ b/src/Jackett.Console/packages.config @@ -4,6 +4,7 @@ + diff --git a/src/Jackett.Tray/Main.cs b/src/Jackett.Tray/Main.cs index 252e241de..fee4ca124 100644 --- a/src/Jackett.Tray/Main.cs +++ b/src/Jackett.Tray/Main.cs @@ -141,7 +141,7 @@ namespace JackettTray { try { - Engine.ProcessService.StartProcessAndLog(consolePath, "/stop", true); + Engine.ProcessService.StartProcessAndLog(consolePath, "--Stop", true); } catch { @@ -159,7 +159,7 @@ namespace JackettTray { try { - Engine.ProcessService.StartProcessAndLog(consolePath, "/start", true); + Engine.ProcessService.StartProcessAndLog(consolePath, "--Start", true); } catch { diff --git a/src/Jackett/Content/custom.css b/src/Jackett/Content/custom.css index 14280a204..9628b9cef 100644 --- a/src/Jackett/Content/custom.css +++ b/src/Jackett/Content/custom.css @@ -203,3 +203,7 @@ hr { margin-top: 10px; text-align: center; } + +#jackett-allowext { + width: 25px; +} diff --git a/src/Jackett/Content/custom.js b/src/Jackett/Content/custom.js index 8c4017828..7837ade39 100644 --- a/src/Jackett/Content/custom.js +++ b/src/Jackett/Content/custom.js @@ -7,6 +7,7 @@ function loadJackettSettings() { $("#api-key-input").val(data.config.api_key); $("#app-version").html(data.app_version); $("#jackett-port").val(data.config.port); + $("#jackett-allowext").attr('checked', data.config.external); var password = data.config.password; $("#jackett-adminpwd").val(password); if (password != null && password != '') { @@ -17,20 +18,21 @@ function loadJackettSettings() { $("#change-jackett-port").click(function () { 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) { - if (data.result == "error") { doNotify("Error: " + data.error, "danger", "glyphicon glyphicon-alert"); return; } else { 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 () { 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); } diff --git a/src/Jackett/Content/index.html b/src/Jackett/Content/index.html index ef01513c4..97c146c40 100644 --- a/src/Jackett/Content/index.html +++ b/src/Jackett/Content/index.html @@ -35,26 +35,33 @@ API Key: + +
+

Configured Indexers

+
+
+

Jackett Configuration

Admin Password: - +
Server port:
-
-

Configured Indexers

-
+
+ External access: + +