0.5 Rc1 - Reimplement port change+tray, fix IPT+SSC. Installer fixes.

This commit is contained in:
KZ 2015-07-22 23:00:52 +01:00
parent 9ca7f641ad
commit c4d653bc2e
39 changed files with 1144 additions and 274 deletions

View File

@ -23,7 +23,8 @@ DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputBaseFilename=setup
SetupIconFile=O:\Documents\JackettKayo\src\Jackett.Console\jackett.ico
SetupIconFile=src\Jackett.Console\jackett.ico
UninstallDisplayIcon={app}\JackettConsole.exe
Compression=lzma
SolidCompression=yes
@ -35,8 +36,8 @@ Name: "windowsService"; Description: "Install as a Windows Service"
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "O:\Documents\JackettKayo\Build\JackettTray.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "O:\Documents\JackettKayo\Build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "Build\JackettTray.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "Build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
@ -51,6 +52,7 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChang
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
[UninstallRun]
Filename: "{app}\JackettConsole.exe"; Parameters: "/u"; Flags: waituntilterminated skipifdoesntexist

View File

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -75,12 +77,6 @@
<HintPath>..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Security">
<HintPath>..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Cookies">
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.3.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.StaticFiles, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.StaticFiles.3.0.1\lib\net45\Microsoft.Owin.StaticFiles.dll</HintPath>
<Private>True</Private>
@ -99,10 +95,19 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
<Private>True</Private>
@ -145,6 +150,13 @@
<Content Include="jackett.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -41,11 +41,27 @@ namespace JackettConsole
case "/t": // Tracing
Engine.TracingEnabled = true;
break;
case "/curlsafe": // Curl safe mode
Engine.CurlSafe = true;
break;
case "/start": // Start Service
if (!Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Start();
}
return;
case "/stop": // Stop Service
if (Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Stop();
}
return;
}
}
Engine.Server.Initalize();
Engine.Server.Start();
Engine.Logger.Info("Running in console mode.");
Engine.Logger.Info("Running in console mode!");
Engine.RunTime.Spin();
Engine.Logger.Info("Server thread exit");
}

View File

@ -1,24 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.0" targetFramework="net452" userInstalled="true" />
<package id="Autofac.Owin" version="3.1.0" targetFramework="net452" userInstalled="true" />
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net452" userInstalled="true" />
<package id="Autofac.WebApi2.Owin" version="3.2.0" targetFramework="net452" userInstalled="true" />
<package id="Autofac" version="3.5.0" targetFramework="net452" />
<package id="Autofac.Owin" version="3.1.0" targetFramework="net452" />
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net452" />
<package id="Autofac.WebApi2.Owin" version="3.2.0" targetFramework="net452" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net452" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.StaticFiles" version="3.0.1" targetFramework="net452" userInstalled="true" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" userInstalled="true" />
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" />
<package id="Microsoft.Owin.StaticFiles" version="3.0.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="NLog" version="4.0.1" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" userInstalled="true" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>

View File

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -83,10 +85,19 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
@ -134,6 +145,13 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -20,6 +20,7 @@ namespace Jackett.Service
protected override void OnStart(string[] args)
{
Engine.Logger.Info("Service starting");
Engine.Server.Initalize();
Engine.Server.Start();
Engine.Logger.Info("Service started");
}

View File

@ -9,6 +9,9 @@
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net452" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="3.0.1" targetFramework="net452" />

View File

@ -1,6 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -36,8 +38,81 @@
<ApplicationIcon>jackett.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.3.5.0\lib\net40\Autofac.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Autofac.Integration.Owin, Version=3.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.Owin.3.1.0\lib\net45\Autofac.Integration.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Autofac.Integration.WebApi, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.WebApi2.3.4.0\lib\net45\Autofac.Integration.WebApi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Autofac.Integration.WebApi.Owin, Version=3.2.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.WebApi2.Owin.3.2.0\lib\net45\Autofac.Integration.WebApi.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.FileSystems, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.FileSystems.3.0.1\lib\net45\Microsoft.Owin.FileSystems.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Hosting, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.StaticFiles, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.StaticFiles.3.0.1\lib\net45\Microsoft.Owin.StaticFiles.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.0.1\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Web.Http.Tracing, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Tracing.5.2.3\lib\net45\System.Web.Http.Tracing.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -69,6 +144,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -85,7 +161,31 @@
<ItemGroup>
<Content Include="jackett.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jackett\Jackett.csproj">
<Project>{e636d5f8-68b4-4903-b4ed-ccfd9c9e899f}</Project>
<Name>Jackett</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -32,9 +32,13 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemAutoStart = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebUI = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.backgroundMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.serviceControlMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemAutoStart = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemShutdown = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -48,31 +52,60 @@
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemAutoStart,
this.toolStripMenuItemWebUI,
this.toolStripSeparator1,
this.backgroundMenuItem,
this.serviceControlMenuItem,
this.toolStripSeparator2,
this.toolStripMenuItemAutoStart,
this.toolStripMenuItemShutdown});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(174, 92);
this.contextMenuStrip1.Size = new System.Drawing.Size(292, 148);
this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening);
//
// toolStripMenuItemWebUI
//
this.toolStripMenuItemWebUI.Name = "toolStripMenuItemWebUI";
this.toolStripMenuItemWebUI.Size = new System.Drawing.Size(291, 22);
this.toolStripMenuItemWebUI.Text = "Open Web UI";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(288, 6);
//
// backgroundMenuItem
//
this.backgroundMenuItem.Enabled = false;
this.backgroundMenuItem.Name = "backgroundMenuItem";
this.backgroundMenuItem.Size = new System.Drawing.Size(291, 22);
this.backgroundMenuItem.Text = "Jacket is running as a background service";
//
// serviceControlMenuItem
//
this.serviceControlMenuItem.Name = "serviceControlMenuItem";
this.serviceControlMenuItem.Size = new System.Drawing.Size(291, 22);
this.serviceControlMenuItem.Text = "Start Service";
this.serviceControlMenuItem.Click += new System.EventHandler(this.serviceControlMenuItem_Click);
//
// toolStripMenuItemAutoStart
//
this.toolStripMenuItemAutoStart.CheckOnClick = true;
this.toolStripMenuItemAutoStart.Name = "toolStripMenuItemAutoStart";
this.toolStripMenuItemAutoStart.Size = new System.Drawing.Size(173, 22);
this.toolStripMenuItemAutoStart.Size = new System.Drawing.Size(291, 22);
this.toolStripMenuItemAutoStart.Text = "Auto-start on boot";
//
// toolStripMenuItemWebUI
//
this.toolStripMenuItemWebUI.Name = "toolStripMenuItemWebUI";
this.toolStripMenuItemWebUI.Size = new System.Drawing.Size(173, 22);
this.toolStripMenuItemWebUI.Text = "Open Web UI";
//
// toolStripMenuItemShutdown
//
this.toolStripMenuItemShutdown.Name = "toolStripMenuItemShutdown";
this.toolStripMenuItemShutdown.Size = new System.Drawing.Size(173, 22);
this.toolStripMenuItemShutdown.Size = new System.Drawing.Size(291, 22);
this.toolStripMenuItemShutdown.Text = "Shutdown";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(288, 6);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -95,6 +128,9 @@
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemAutoStart;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebUI;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemShutdown;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem backgroundMenuItem;
private System.Windows.Forms.ToolStripMenuItem serviceControlMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
}
}

View File

@ -1,4 +1,6 @@
using Microsoft.Win32;
using Jackett;
using Jackett.Utils;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -27,13 +29,19 @@ namespace JackettTray
toolStripMenuItemWebUI.Click += toolStripMenuItemWebUI_Click;
toolStripMenuItemShutdown.Click += toolStripMenuItemShutdown_Click;
//if (Server.IsFirstRun)
// AutoStart = true;
Engine.Server.Initalize();
if (!Engine.ServiceConfig.ServiceExists())
{
// We are not installed as a service so just the web server too and run from the tray.
Engine.Logger.Info("Starting server from tray");
Engine.Server.Start();
}
}
void toolStripMenuItemWebUI_Click(object sender, EventArgs e)
{
// Process.Start("http://127.0.0.1:" + Server.Port);
Process.Start("http://127.0.0.1:" + Engine.Server.Config.Port);
}
void toolStripMenuItemShutdown_Click(object sender, EventArgs e)
@ -83,12 +91,82 @@ namespace JackettTray
private void CreateShortcut()
{
/* var appPath = Assembly.GetExecutingAssembly().Location;
var appPath = Assembly.GetExecutingAssembly().Location;
var shell = new IWshRuntimeLibrary.WshShell();
var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutPath);
shortcut.Description = Assembly.GetExecutingAssembly().GetName().Name;
shortcut.TargetPath = appPath;
shortcut.Save();*/
shortcut.Save();
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
if (Engine.ServiceConfig.ServiceExists())
{
backgroundMenuItem.Visible = true;
serviceControlMenuItem.Visible = true;
toolStripSeparator1.Visible = true;
toolStripSeparator2.Visible = true;
if (Engine.ServiceConfig.ServiceRunning())
{
serviceControlMenuItem.Text = "Stop background service";
} else
{
serviceControlMenuItem.Text = "Start background service";
}
toolStripMenuItemShutdown.Text = "Close tray icon";
} else
{
backgroundMenuItem.Visible = false;
serviceControlMenuItem.Visible = false;
toolStripSeparator1.Visible = false;
toolStripSeparator2.Visible = false;
toolStripMenuItemShutdown.Text = "Shutdown";
}
}
private void serviceControlMenuItem_Click(object sender, EventArgs e)
{
var consolePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "JackettConsole.exe");
if (Engine.ServiceConfig.ServiceRunning())
{
if (ServerUtil.IsUserAdministrator())
{
Engine.ServiceConfig.Stop();
} else
{
try
{
Engine.ProcessService.StartProcessAndLog(consolePath, "/stop", true);
}
catch
{
MessageBox.Show("Failed to get admin rights to stop the service.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else
{
if (ServerUtil.IsUserAdministrator())
{
Engine.ServiceConfig.Start();
}
else
{
try
{
Engine.ProcessService.StartProcessAndLog(consolePath, "/start", true);
}
catch
{
MessageBox.Show("Failed to get admin rights to start the service.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.0" targetFramework="net452" />
<package id="Autofac.Owin" version="3.1.0" targetFramework="net452" />
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net452" />
<package id="Autofac.WebApi2.Owin" version="3.2.0" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net452" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" />
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" />
<package id="Microsoft.Owin.StaticFiles" version="3.0.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="NLog" version="4.0.1" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>

View File

@ -160,6 +160,7 @@ hr {
}
.input-area {
margin: 4px 0px;
}
.input-area > * {
@ -172,7 +173,7 @@ hr {
.input-header {
font-size: 18px;
width: 140px;
width: 160px;
display: inline-block;
}

View File

@ -20,13 +20,13 @@ function loadJackettSettings() {
$("#change-jackett-port").click(function () {
var jackett_port = $("#jackett-port").val();
var jsonObject = { port: jackett_port};
var jqxhr = $.post("/admin/apply_jackett_config", JSON.stringify(jsonObject), function (data) {
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. Jackett will now restart...", "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 () {

View File

@ -32,27 +32,25 @@
<li>For <b>API key</b> using the key below</li>
<li>Turn off <b>Enable RageID Lookup</b></li>
</ol>
<span class="input-header">Jackett 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="">
</div>
<div class="input-area">
<span class="input-header">Admin Password: </span>
<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">
Set <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
Set Password <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
</button>
<a href="Dashboard?logout=true" id="logoutBtn" style="display:none" class="btn btn-danger btn-sm">
Logout
</a>
</div>
<hr />
<div class="input-area">
<span class="input-header">Jackett port: </span>
<span class="input-header">Server port: </span>
<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">
Configure <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
Change Port <span class="glyphicon glyphicon-ok-wrench" aria-hidden="true"></span>
</button>
<span title="Jackett will restart after changing the port" class="glyphicon glyphicon-info-sign"></span>
</div>
<hr />
<h3>Configured Indexers</h3>

View File

@ -39,7 +39,7 @@ namespace Jackett.Controllers
return Request.CreateResponse(HttpStatusCode.Forbidden, "Incorrect API key");
}
if (torznabQuery.QueryType == "caps")
if (string.Equals(torznabQuery.QueryType, "caps", StringComparison.InvariantCultureIgnoreCase))
{
return new HttpResponseMessage()
{
@ -49,7 +49,7 @@ namespace Jackett.Controllers
var releases = await indexer.PerformQuery(torznabQuery);
logger.Debug(string.Format("Found {0} releases from {1}", releases.Length, indexer.DisplayName));
logger.Info(string.Format("Found {0} releases from {1}", releases.Length, indexer.DisplayName));
var severUrl = string.Format("{0}://{1}:{2}/", Request.RequestUri.Scheme, Request.RequestUri.Host, Request.RequestUri.Port);
var resultPage = new ResultPage(new ChannelInfo

View File

@ -12,11 +12,13 @@ using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Security;
using System.Windows.Forms;
namespace Jackett.Controllers
{
@ -28,13 +30,15 @@ namespace Jackett.Controllers
private IIndexerManagerService indexerService;
private IServerService serverService;
private ISecuityService securityService;
private IProcessService processService;
public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss, ISecuityService s)
public AdminController(IConfigurationService config, IIndexerManagerService i, IServerService ss, ISecuityService s, IProcessService p)
{
this.config = config;
indexerService = i;
serverService = ss;
securityService = s;
processService = p;
}
private async Task<JToken> ReadPostDataJson()
@ -168,7 +172,7 @@ namespace Jackett.Controllers
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
//jsonReply["error"] = Newtonsoft.Json.JsonConvert.SerializeObject(ex);
if (ex is ExceptionWithConfigData)
{
jsonReply["config"] = ((ExceptionWithConfigData)ex).ConfigData.ToJson();
@ -278,17 +282,58 @@ namespace Jackett.Controllers
return Json(jsonReply);
}
[Route("apply_jackett_config")]
[Route("set_port")]
[HttpPost]
public async Task<IHttpActionResult> SetConfig()
{
var originalPort = Engine.Server.Config.Port;
var jsonReply = new JObject();
try
{
var postData = await ReadPostDataJson();
// int port = await WebServer.ApplyPortConfiguration(postData);
int port = (int)postData["port"];
if (port != Engine.Server.Config.Port)
{
if (ServerUtil.RestrictedPorts.Contains(port))
{
jsonReply["result"] = "error";
jsonReply["error"] = "The port you have selected is restricted, try a different one.";
return Json(jsonReply);
}
Engine.Server.Config.Port = port;
Engine.Server.SaveConfig();
if (!ServerUtil.IsUserAdministrator())
{
try {
processService.StartProcessAndLog(Application.ExecutablePath, "/r", true);
}
catch
{
Engine.Server.Config.Port = originalPort;
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);
}
// This is giving a warning - is there a better way of doing this?
Task.Run(() =>
{
Thread.Sleep(500);
serverService.Start();
});
}
jsonReply["result"] = "success";
// jsonReply["port"] = port;
jsonReply["port"] = port;
}
catch (Exception ex)
{

View File

@ -7,13 +7,13 @@ using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http.Headers;
using Jackett.Utils;
using System.Net;
namespace Jackett
{
public static class CurlHelper
{
private const string ChromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36";
public class CurlRequest
{
@ -44,18 +44,21 @@ namespace Jackett
public byte[] Content { get; private set; }
public HttpStatusCode Status { get; private set;}
public Dictionary<string, string> Cookies { get; private set; }
public List<string> CookiesFlat { get { return Cookies.Select(c => c.Key + "=" + c.Value).ToList(); } }
public string CookieHeader { get { return string.Join("; ", CookiesFlat); } }
public CurlResponse(List<string[]> headers, byte[] content)
public CurlResponse(List<string[]> headers, byte[] content, HttpStatusCode s)
{
Headers = new Dictionary<string, string>();
Cookies = new Dictionary<string, string>();
HeaderList = headers;
Content = content;
Status = s;
foreach (var h in headers)
{
Headers[h[0]] = h[1];
@ -145,7 +148,7 @@ namespace Jackett
{
easy.Url = curlRequest.Url;
easy.BufferSize = 64 * 1024;
easy.UserAgent = ChromeUserAgent;
easy.UserAgent = BrowserUtil.ChromeUserAgent;
easy.WriteFunction = (byte[] buf, int size, int nmemb, object data) =>
{
contentBuffers.Add(buf);
@ -173,23 +176,35 @@ namespace Jackett
easy.Perform();
}
var headerBytes = Combine(headerBuffers.ToArray());
var headerString = Encoding.UTF8.GetString(headerBytes);
var headerParts = headerString.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var headers = new List<string[]>();
foreach (var headerPart in headerParts.Skip(1))
var headerCount = 0;
HttpStatusCode status = HttpStatusCode.InternalServerError;
foreach (var headerPart in headerParts)
{
var keyVal = headerPart.Split(new char[] { ':' }, 2);
if (keyVal.Length > 1)
if (headerCount == 0)
{
headers.Add(new[] { keyVal[0].ToLower().Trim(), keyVal[1].Trim() });
var responseCode = int.Parse(headerPart.Split(' ')[1]);
status = (HttpStatusCode)responseCode;
}
else
{
var keyVal = headerPart.Split(new char[] { ':' }, 2);
if (keyVal.Length > 1)
{
headers.Add(new[] { keyVal[0].ToLower().Trim(), keyVal[1].Trim() });
}
}
headerCount++;
}
var contentBytes = Combine(contentBuffers.ToArray());
var curlResponse = new CurlResponse(headers, contentBytes);
var curlResponse = new CurlResponse(headers, contentBytes, status);
if (!string.IsNullOrEmpty(curlRequest.Cookies))
curlResponse.AddCookiesFromHeaderValue(curlRequest.Cookies);
curlResponse.AddCookiesFromHeaders(headers);

View File

@ -12,94 +12,107 @@ using System.Threading.Tasks;
namespace Jackett
{
public class Engine
public class Engine
{
private static IContainer container = null;
private static IContainer container = null;
static Engine()
{
static Engine()
{
BuildContainer();
Logger.Info("Starting Jackett " + ConfigService.GetVersion());
}
#if DEBUG
TracingEnabled = true;
#endif
public static bool TracingEnabled
{
get;
set;
}
var builder = new ContainerBuilder();
builder.RegisterModule<JackettModule>();
container = builder.Build();
public static bool LogRequests
{
get;
set;
}
// Register the container in itself to allow for late resolves
var secondaryBuilder = new ContainerBuilder();
secondaryBuilder.RegisterInstance<IContainer>(container).SingleInstance();
SetupLogging(secondaryBuilder);
secondaryBuilder.Update(container);
public static bool CurlSafe
{
get;
set;
}
Logger.Info("Starting Jackett " + ConfigService.GetVersion());
}
public static void BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterModule<JackettModule>();
container = builder.Build();
public static bool TracingEnabled
{
get;
set;
}
// Register the container in itself to allow for late resolves
var secondaryBuilder = new ContainerBuilder();
secondaryBuilder.RegisterInstance<IContainer>(container).SingleInstance();
SetupLogging(secondaryBuilder);
secondaryBuilder.Update(container);
}
public static bool LogRequests
{
get;
set;
}
public static IContainer GetContainer()
{
return container;
}
public static IContainer GetContainer()
{
return container;
}
public static bool IsWindows
{
get
{
return Environment.OSVersion.Platform == PlatformID.Win32NT;
}
}
return Environment.OSVersion.Platform == PlatformID.Win32NT;
}
}
public static IConfigurationService ConfigService
{
get
{
return container.Resolve<IConfigurationService>();
}
}
public static IConfigurationService ConfigService
{
get
{
return container.Resolve<IConfigurationService>();
}
}
public static IServiceConfigService ServiceConfig
{
get
{
return container.Resolve<IServiceConfigService>();
}
}
public static IProcessService ProcessService
{
get
{
return container.Resolve<IProcessService>();
}
}
public static IServerService Server
{
get
{
return container.Resolve<IServerService>();
}
}
public static IServiceConfigService ServiceConfig
{
get
{
return container.Resolve<IServiceConfigService>();
}
}
public static IRunTimeService RunTime
{
get
{
return container.Resolve<IRunTimeService>();
}
}
public static IServerService Server
{
get
{
return container.Resolve<IServerService>();
}
}
public static Logger Logger
{
get
{
return container.Resolve<Logger>();
}
}
public static IRunTimeService RunTime
{
get
{
return container.Resolve<IRunTimeService>();
}
}
public static Logger Logger
{
get
{
return container.Resolve<Logger>();
}
}
public static ISecuityService SecurityService
{
@ -108,32 +121,32 @@ namespace Jackett
return container.Resolve<ISecuityService>();
}
}
private static void SetupLogging(ContainerBuilder builder)
{
var logConfig = new LoggingConfiguration();
var logFile = new FileTarget();
logConfig.AddTarget("file", logFile);
logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
logFile.FileName = Path.Combine(ConfigurationService.GetAppDataFolderStatic(), "log.txt");
logFile.ArchiveFileName = "log.{#####}.txt";
logFile.ArchiveAboveSize = 500000;
logFile.MaxArchiveFiles = 1;
logFile.KeepFileOpen = false;
logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence;
var logFileRule = new LoggingRule("*", LogLevel.Debug, logFile);
logConfig.LoggingRules.Add(logFileRule);
private static void SetupLogging(ContainerBuilder builder)
{
var logConfig = new LoggingConfiguration();
var logConsole = new ConsoleTarget();
logConfig.AddTarget("console", logConsole);
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
var logConsoleRule = new LoggingRule("*", LogLevel.Debug, logConsole);
logConfig.LoggingRules.Add(logConsoleRule);
var logFile = new FileTarget();
logConfig.AddTarget("file", logFile);
logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
logFile.FileName = Path.Combine(ConfigurationService.GetAppDataFolderStatic(), "log.txt");
logFile.ArchiveFileName = "log.{#####}.txt";
logFile.ArchiveAboveSize = 500000;
logFile.MaxArchiveFiles = 1;
logFile.KeepFileOpen = false;
logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence;
var logFileRule = new LoggingRule("*", TracingEnabled?LogLevel.Debug: LogLevel.Info, logFile);
logConfig.LoggingRules.Add(logFileRule);
LogManager.Configuration = logConfig;
builder.RegisterInstance<Logger>(LogManager.GetCurrentClassLogger()).SingleInstance();
}
var logConsole = new ConsoleTarget();
logConfig.AddTarget("console", logConsole);
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
var logConsoleRule = new LoggingRule("*", TracingEnabled ? LogLevel.Debug : LogLevel.Info, logConsole);
logConfig.LoggingRules.Add(logConsoleRule);
LogManager.Configuration = logConfig;
builder.RegisterInstance<Logger>(LogManager.GetCurrentClassLogger()).SingleInstance();
}
}
}

View File

@ -24,6 +24,7 @@ namespace Jackett.Indexers
protected Logger logger;
protected IIndexerManagerService indexerService;
// protected IWebClient webClient;
protected static List<CachedResult> cache = new List<CachedResult>();
protected static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0);
@ -33,7 +34,7 @@ namespace Jackett.Indexers
return StringUtil.StripNonAlphaNumeric(type.Name.ToLowerInvariant());
}
public BaseIndexer(string name, string description, Uri link, TorznabCapabilities caps, IIndexerManagerService manager, Logger logger)
public BaseIndexer(string name, string description, Uri link, TorznabCapabilities caps, IIndexerManagerService manager,Logger logger)
{
DisplayName = name;
DisplayDescription = description;
@ -41,6 +42,7 @@ namespace Jackett.Indexers
TorznabCaps = caps;
this.logger = logger;
indexerService = manager;
// webClient = wc;
}
protected void SaveConfig(JToken config)

View File

@ -2,6 +2,7 @@
using Jackett.Models;
using Jackett.Services;
using Jackett.Utils;
using Jackett.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;
using System;
@ -19,34 +20,26 @@ namespace Jackett.Indexers
public class IPTorrents : BaseIndexer, IIndexer
{
private readonly string SearchUrl = "";
CookieContainer cookies;
HttpClientHandler handler;
HttpClient client;
private string cookieHeader = "";
public IPTorrents(IIndexerManagerService i, Logger l)
private IWebClient webclient;
public IPTorrents(IIndexerManagerService i, IWebClient wc, Logger l)
: base(name: "IPTorrents",
description: "Always a step ahead.",
link: new Uri("https://iptorrents.com"),
link: new Uri("https://iptorrents.com/"),
caps: TorznabCapsUtil.CreateDefaultTorznabTVCaps(),
manager: i,
logger: l)
{
SearchUrl = SiteLink + "t?q=";
cookies = new CookieContainer();
handler = new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = true,
UseCookies = true,
};
client = new HttpClient(handler);
webclient =wc;
}
public async Task<ConfigurationData> GetConfigurationForSetup()
public Task<ConfigurationData> GetConfigurationForSetup()
{
await client.GetAsync(SiteLink);
var config = new ConfigurationDataBasicLogin();
return (ConfigurationData)config;
return Task.FromResult<ConfigurationData>((ConfigurationData)config);
}
public async Task ApplyConfiguration(JToken configJson)
@ -60,16 +53,27 @@ namespace Jackett.Indexers
{ "password", config.Password.Value }
};
var content = new FormUrlEncodedContent(pairs);
var message = new HttpRequestMessage();
message.Method = HttpMethod.Post;
message.Content = content;
message.RequestUri = SiteLink;
message.Headers.Referrer = SiteLink;
message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent);
var response = await webclient.GetString(new Utils.Clients.WebRequest()
{
Url = SiteLink.ToString(),
PostData = pairs,
Referer = SiteLink.ToString(),
Type = RequestType.POST
});
var response = await client.SendAsync(message);
var responseContent = await response.Content.ReadAsStringAsync();
cookieHeader = response.Cookies;
if (response.Status == HttpStatusCode.Found)
{
response = await webclient.GetString(new Utils.Clients.WebRequest()
{
Url = SearchUrl,
PostData = pairs,
Referer = SiteLink.ToString(),
Cookies = response.Cookies
});
}
var responseContent = response.Content;
if (!responseContent.Contains("/my.php"))
{
@ -81,7 +85,7 @@ namespace Jackett.Indexers
else
{
var configSaveData = new JObject();
cookies.DumpToJson(SiteLink, configSaveData);
configSaveData["cookies"] = cookieHeader;
SaveConfig(configSaveData);
IsConfigured = true;
}
@ -98,7 +102,7 @@ namespace Jackett.Indexers
public void LoadFromSavedConfiguration(Newtonsoft.Json.Linq.JToken jsonConfig)
{
cookies.FillFromJson(SiteLink, jsonConfig, logger);
cookieHeader = (string)jsonConfig["cookies"];
IsConfigured = true;
}
@ -108,10 +112,14 @@ namespace Jackett.Indexers
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
var response = await client.SendAsync(request);
var results = await response.Content.ReadAsStringAsync();
var response = await webclient.GetString(new Utils.Clients.WebRequest()
{
Url = episodeSearchUrl,
Referer = SiteLink.ToString(),
Cookies = cookieHeader
});
var results = response.Content;
try
{
CQ dom = results;
@ -175,10 +183,13 @@ namespace Jackett.Indexers
public async Task<byte[]> Download(Uri link)
{
var request = CreateHttpRequest(link);
var response = await client.SendAsync(request);
var bytes = await response.Content.ReadAsByteArrayAsync();
return bytes;
var response = await webclient.GetBytes(new Utils.Clients.WebRequest()
{
Url = link.ToString(),
Cookies = cookieHeader
});
return response.Content;
}
}
}

View File

@ -29,7 +29,7 @@ namespace Jackett.Indexers
public SceneTime(IIndexerManagerService i, Logger l)
: base(name: "SceneTime",
description: "Always on time",
link: new Uri("https://www.scenetime.com"),
link: new Uri("https://www.scenetime.com/"),
caps: TorznabCapsUtil.CreateDefaultTorznabTVCaps(),
manager: i,
logger: l)

View File

@ -95,12 +95,6 @@
<HintPath>..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Owin.Security">
<HintPath>..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Security.Cookies">
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.3.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.StaticFiles, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.StaticFiles.3.0.1\lib\net45\Microsoft.Owin.StaticFiles.dll</HintPath>
<Private>True</Private>
@ -118,10 +112,16 @@
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Web" />
@ -159,6 +159,9 @@
<Compile Include="Models\TorznabCapabilities.cs" />
<Compile Include="Models\Config\ServerConfig.cs" />
<Compile Include="Models\TorznabCategory.cs" />
<Compile Include="Utils\Clients\UnixLibCurlWebClient.cs" />
<Compile Include="Utils\Clients\WebByteResult.cs" />
<Compile Include="Utils\Clients\WebClientResult.cs" />
<Compile Include="Services\ProcessService.cs" />
<Compile Include="Services\SecuityService.cs" />
<Compile Include="Services\SerializeService.cs" />
@ -173,6 +176,7 @@
<Compile Include="Models\ConfigurationDataUrl.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="CookieContainerExtensions.cs" />
<Compile Include="Utils\Clients\WebRequest.cs" />
<Compile Include="Utils\DataUrl.cs" />
<Compile Include="ExceptionWithConfigData.cs" />
<Compile Include="HttpClientExtensions.cs" />
@ -199,6 +203,7 @@
<Compile Include="Indexers\Torrentz.cs" />
<Compile Include="JackettModule.cs" />
<Compile Include="Utils\DateTimeUtil.cs" />
<Compile Include="Utils\Clients\IWebClient.cs" />
<Compile Include="Utils\JackettAuthorizedAttribute.cs" />
<Compile Include="Utils\ParseUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -219,9 +224,11 @@
<Compile Include="Indexers\AlphaRatio.cs" />
<Compile Include="Utils\StringUtil.cs" />
<Compile Include="Utils\TorznabCapsUtil.cs" />
<Compile Include="Utils\Clients\UnixSafeCurlWebClient.cs" />
<Compile Include="Utils\WebApiRootRedirectMiddleware.cs" />
<Compile Include="Utils\WebAPIRequestLogger.cs" />
<Compile Include="Utils\WebAPIToNLogTracer.cs" />
<Compile Include="Utils\Clients\WindowsWebClient.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@ -397,17 +404,6 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@ -426,4 +422,9 @@
</Properties>
</MonoDevelop>
</ProjectExtensions>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
</Project>

View File

@ -6,6 +6,8 @@ using System.Text;
using System.Threading.Tasks;
using Autofac.Integration.WebApi;
using Jackett.Indexers;
using Jackett.Utils;
using Jackett.Utils.Clients;
namespace Jackett
{
@ -18,6 +20,20 @@ namespace Jackett
builder.RegisterAssemblyTypes(thisAssembly).Except<IIndexer>().AsImplementedInterfaces().SingleInstance();
builder.RegisterApiControllers(thisAssembly).InstancePerRequest();
// Register the best web client for the platform or exec curl as a safe option
if (Engine.CurlSafe)
{
builder.RegisterType<UnixSafeCurlWebClient>().As<IWebClient>();
}
else if(System.Environment.OSVersion.Platform == PlatformID.Unix)
{
builder.RegisterType<UnixLibCurlWebClient>().As<IWebClient>();
}
else
{
builder.RegisterType<WindowsWebClient>().As<IWebClient>();
}
// Register indexers
foreach (var indexer in thisAssembly.GetTypes()
.Where(p => typeof(IIndexer).IsAssignableFrom(p) && !p.IsInterface)

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.3.1")]
[assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -150,7 +150,14 @@ namespace Jackett.Services
/// <returns></returns>
public static string GetAppDataFolderStatic()
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett");
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
}
else
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Jackett");
}
}
public string GetIndexerConfigDir()

View File

@ -10,7 +10,8 @@ namespace Jackett.Services
{
public interface IProcessService
{
void StartProcessAndLog(string exe, string args);
void StartProcessAndLog(string exe, string args, bool asAdmin = false);
string StartProcessAndGetOutput(string exe, string args, bool keepnewlines = false, bool asAdmin = false);
}
public class ProcessService : IProcessService
@ -22,7 +23,7 @@ namespace Jackett.Services
logger = l;
}
public void StartProcessAndLog(string exe, string args)
private void Run(string exe, string args, bool asAdmin, DataReceivedEventHandler d, DataReceivedEventHandler r)
{
var startInfo = new ProcessStartInfo()
{
@ -35,30 +36,71 @@ namespace Jackett.Services
RedirectStandardInput = true
};
if (asAdmin)
{
startInfo.Verb = "runas";
startInfo.UseShellExecute = true;
startInfo.RedirectStandardError = false;
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardInput = false;
}
var proc = Process.Start(startInfo);
proc.OutputDataReceived += proc_OutputDataReceived;
proc.ErrorDataReceived += proc_ErrorDataReceived;
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
if (!asAdmin)
{
proc.OutputDataReceived += d;
proc.ErrorDataReceived += r;
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
}
proc.WaitForExit();
proc.OutputDataReceived -= proc_OutputDataReceived;
proc.ErrorDataReceived -= proc_ErrorDataReceived;
}
void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrWhiteSpace(e.Data))
if (!asAdmin)
{
logger.Error(e.Data);
proc.OutputDataReceived -= d;
proc.ErrorDataReceived -= r;
}
}
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
public string StartProcessAndGetOutput(string exe, string args, bool keepnewlines = false, bool asAdmin = false)
{
if (!string.IsNullOrWhiteSpace(e.Data))
var sb = new StringBuilder();
DataReceivedEventHandler rxData = (a, e) => {
if (keepnewlines || !string.IsNullOrWhiteSpace(e.Data))
{
sb.AppendLine(e.Data);
}
};
DataReceivedEventHandler rxError = (s, e) => {
if (keepnewlines || !string.IsNullOrWhiteSpace(e.Data))
{
sb.AppendLine(e.Data);
}
};
Run(exe, args, asAdmin, rxData, rxError);
return sb.ToString();
}
public void StartProcessAndLog(string exe, string args, bool asAdmin = false)
{
var sb = new StringBuilder();
DataReceivedEventHandler rxData = (a, e) =>
{
logger.Debug(e.Data);
}
if (!string.IsNullOrWhiteSpace(e.Data))
{
logger.Debug(e.Data);
}
};
DataReceivedEventHandler rxError = (s, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
logger.Error(e.Data);
}
};
Run(exe, args, asAdmin, rxData, rxError);
}
}
}

View File

@ -22,6 +22,7 @@ namespace Jackett.Services
{
public interface IServerService
{
void Initalize();
void Start();
void Stop();
void ReserveUrls(bool doInstall = true);
@ -100,7 +101,7 @@ namespace Jackett.Services
configService.SaveConfig<ServerConfig>(config);
}
public void Start()
public void Initalize()
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
@ -109,7 +110,10 @@ namespace Jackett.Services
// Load indexers
indexerService.InitIndexers();
}
public void Start()
{
// Start the server
logger.Debug("Starting web server at " + config.GetListenAddresses()[0]);
var startOptions = new StartOptions();

View File

@ -16,6 +16,10 @@ namespace Jackett.Services
{
void Install();
void Uninstall();
bool ServiceExists();
bool ServiceRunning();
void Start();
void Stop();
}
class ServiceConfigService : IServiceConfigService
@ -33,11 +37,32 @@ namespace Jackett.Services
logger = l;
}
public bool Exists()
public bool ServiceExists()
{
return GetService(NAME) != null;
}
public bool ServiceRunning()
{
var service = GetService(NAME);
if (service == null)
return false;
return service.Status == ServiceControllerStatus.Running;
}
public void Start()
{
var service = GetService(NAME);
service.Start();
}
public void Stop()
{
var service = GetService(NAME);
service.Stop();
}
public ServiceController GetService(string serviceName)
{
return ServiceController.GetServices().FirstOrDefault(c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase));
@ -45,15 +70,15 @@ namespace Jackett.Services
public void Install()
{
if (Exists())
if (ServiceExists())
{
logger.Warn("The service is already installed!");
}
else
{
var installer = new ServiceProcessInstaller
{
Account = ServiceAccount.NetworkService
Account = ServiceAccount.LocalSystem
};
var serviceInstaller = new ServiceInstaller();
@ -80,20 +105,18 @@ namespace Jackett.Services
public void Uninstall()
{
Stop();
RemoveService();
var serviceInstaller = new ServiceInstaller();
var context = new InstallContext("jackettservice_uninstall.log", null);
serviceInstaller.Context = context;
serviceInstaller.ServiceName = NAME;
serviceInstaller.Uninstall(null);
logger.Info("The service was uninstalled.");
}
public void Stop()
public void RemoveService()
{
var service = GetService(NAME);
if (service.Status != ServiceControllerStatus.Stopped)

View File

@ -15,7 +15,6 @@ using Autofac;
using Jackett.Services;
using System.Web.Http.Tracing;
using Jackett.Utils;
using Microsoft.Owin.Security.Cookies;
using Microsoft.AspNet.Identity;
[assembly: OwinStartup(typeof(Startup))]
@ -68,12 +67,6 @@ namespace Jackett
defaults: new { controller = "Download", action = "Download" }
);
appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Admin/Login")
});
appBuilder.UseFileServer(new FileServerOptions
{
RequestPath = new PathString(string.Empty),

View File

@ -0,0 +1,15 @@
using Jackett.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
public interface IWebClient
{
Task<WebClientStringResult> GetString(WebRequest request);
Task<WebClientByteResult> GetBytes(WebRequest request);
}
}

View File

@ -0,0 +1,61 @@
using Jackett.Models;
using Jackett.Services;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using static Jackett.CurlHelper;
namespace Jackett.Utils.Clients
{
public class UnixLibCurlWebClient : IWebClient
{
private Logger logger;
public UnixLibCurlWebClient(Logger l)
{
logger = l;
}
public async Task<WebClientByteResult> GetBytes(WebRequest request)
{
CurlResponse response;
logger.Debug(string.Format("UnixLibCurlWebClient:GetBytes(Url:{0})", request.Url));
if (request.Type == RequestType.GET)
{
response = await CurlHelper.GetAsync(request.Url, request.Cookies, request.Referer);
}
else
{
response = await CurlHelper.PostAsync(request.Url, request.PostData, request.Cookies, request.Referer);
}
return new WebClientByteResult()
{
Content = response.Content,
Cookies = response.CookieHeader,
Status = response.Status
};
}
public async Task<WebClientStringResult> GetString(WebRequest request)
{
logger.Debug(string.Format("UnixLibCurlWebClient:GetString(Url:{0})", request.Url));
var result = await GetBytes(request);
return new WebClientStringResult()
{
Content = Encoding.UTF8.GetString(result.Content),
Cookies = result.Cookies,
Status = result.Status
};
}
}
}

View File

@ -0,0 +1,126 @@
using Jackett.Models;
using Jackett.Services;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
public class UnixSafeCurlWebClient : IWebClient
{
private IProcessService processService;
private Logger logger;
public UnixSafeCurlWebClient(IProcessService p, Logger l)
{
processService = p;
logger = l;
}
public Task<WebClientByteResult> GetBytes(WebRequest request)
{
logger.Debug(string.Format("UnixSafeCurlWebClient:GetBytes(Url:{0})", request.Url));
return Run(request);
}
public async Task<WebClientStringResult> GetString(WebRequest request)
{
logger.Debug(string.Format("UnixSafeCurlWebClient:GetString(Url:{0})", request.Url));
var byteResult = await Run(request);
return new WebClientStringResult()
{
Cookies = byteResult.Cookies,
Status = byteResult.Status,
Content = Encoding.UTF8.GetString(byteResult.Content)
};
}
private async Task<WebClientByteResult> Run(WebRequest request)
{
var args = new StringBuilder();
args.AppendFormat("--url \"{0}\" ", request.Url);
args.AppendFormat("-i -sS --user-agent \"{0}\" ", BrowserUtil.ChromeUserAgent);
if (!string.IsNullOrWhiteSpace(request.Cookies))
{
args.AppendFormat("--cookie \"{0}\" ", request.Cookies);
}
if (!string.IsNullOrWhiteSpace(request.Referer))
{
args.AppendFormat("--referer \"{0}\" ", request.Referer);
}
if (request.PostData != null && request.PostData.Count > 0)
{
var postString = new FormUrlEncodedContent(request.PostData).ReadAsStringAsync().Result;
args.AppendFormat("--data \"{0}\" ", postString);
}
var tempFile = Path.GetTempFileName();
args.AppendFormat("--output \"{0}\" ", tempFile);
string stdout = null;
await Task.Run(() =>
{
stdout = processService.StartProcessAndGetOutput("curl", args.ToString(), true);
});
var outputData = File.ReadAllBytes(tempFile);
File.Delete(tempFile);
stdout = Encoding.UTF8.GetString(outputData);
var result = new WebClientByteResult();
var headSplit = stdout.IndexOf("\r\n\r\n");
if (headSplit < 0)
throw new Exception("Invalid response");
var headers = stdout.Substring(0, headSplit);
var headerCount = 0;
foreach (var header in headers.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
{
if (headerCount == 0)
{
var responseCode = int.Parse(header.Split(' ')[1]);
result.Status = (HttpStatusCode)responseCode;
}
else
{
var headerSplitIndex = header.IndexOf(':');
if (headerSplitIndex > 0)
{
var name = header.Substring(0, headerSplitIndex);
var value = header.Substring(headerSplitIndex + 1);
if (string.Equals(name, "set-cookie", StringComparison.InvariantCultureIgnoreCase))
{
var cookieDataSplit = value.IndexOf(';');
if (cookieDataSplit > 0)
{
result.Cookies += value.Substring(0, cookieDataSplit + 1) + " ";
}
}
}
}
headerCount++;
}
result.Content = new byte[outputData.Length - (headSplit + 3)];
var dest = 0;
for (int i= headSplit+4;i< outputData.Length; i++)
{
result.Content[dest] = outputData[i];
dest++;
}
return result;
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
public class WebClientByteResult
{
public HttpStatusCode Status { get; set; }
public string Cookies { get; set; }
public byte[] Content { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
public class WebClientStringResult
{
public HttpStatusCode Status { get; set; }
public string Cookies { get; set; }
public string Content { get; set; }
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
public class WebRequest
{
public WebRequest()
{
PostData = new Dictionary<string, string>();
Type = RequestType.GET;
}
public string Url { get; set; }
public Dictionary<string, string> PostData { get; set; }
public string Cookies { get; set; }
public string Referer { get; set; }
public RequestType Type { get; set; }
}
public enum RequestType
{
GET,
POST
}
}

View File

@ -0,0 +1,119 @@
using Jackett.Models;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Utils.Clients
{
class WindowsWebClient : IWebClient
{
private Logger logger;
public WindowsWebClient(Logger l)
{
logger = l;
}
public async Task<WebClientByteResult> GetBytes(WebRequest request)
{
logger.Debug(string.Format("WindowsWebClient:GetBytes(Url:{0})", request.Url));
var cookies = new CookieContainer();
if (!string.IsNullOrEmpty(request.Cookies))
{
var uri = new Uri(request.Url);
foreach (var c in request.Cookies.Split(';'))
{
try
{
cookies.SetCookies(uri, c);
}
catch (CookieException ex)
{
logger.Info("(Non-critical) Problem loading cookie {0}, {1}, {2}", uri, c, ex.Message);
}
}
}
var client = new HttpClient(new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = false,
UseCookies = true,
});
client.DefaultRequestHeaders.Add("User-Agent", BrowserUtil.ChromeUserAgent);
HttpResponseMessage response = null;
if (request.Type == RequestType.POST)
{
var content = new FormUrlEncodedContent(request.PostData);
response = await client.PostAsync(request.Url, content);
}
else
{
response = await client.GetAsync(request.Url);
}
var result = new WebClientByteResult();
result.Content = await response.Content.ReadAsByteArrayAsync();
result.Cookies = cookies.GetCookieHeader(new Uri(request.Url));
result.Status = response.StatusCode;
return result;
}
public async Task<WebClientStringResult> GetString(WebRequest request)
{
logger.Debug(string.Format("WindowsWebClient:GetString(Url:{0})", request.Url));
var cookies = new CookieContainer();
if (!string.IsNullOrEmpty(request.Cookies))
{
var uri = new Uri(request.Url);
foreach (var c in request.Cookies.Split(';'))
{
try
{
cookies.SetCookies(uri, c);
}
catch (CookieException ex)
{
logger.Info("(Non-critical) Problem loading cookie {0}, {1}, {2}", uri, c, ex.Message);
}
}
}
var client = new HttpClient(new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = false,
UseCookies = true,
});
client.DefaultRequestHeaders.Add("User-Agent", BrowserUtil.ChromeUserAgent);
HttpResponseMessage response = null;
if (request.Type == RequestType.POST)
{
var content = new FormUrlEncodedContent(request.PostData);
response = await client.PostAsync(request.Url, content);
} else
{
response = await client.GetAsync(request.Url);
}
var result = new WebClientStringResult();
result.Content = await response.Content.ReadAsStringAsync();
result.Cookies = cookies.GetCookieHeader(new Uri(request.Url));
result.Status = response.StatusCode;
return result;
}
}
}

View File

@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Jackett.Utils
{
public static class ServerUtil
public class ServerUtil
{
public static int[] RestrictedPorts = new int[] {
1, // tcpmux
@ -75,26 +76,27 @@ namespace Jackett.Utils
6668, // Alternate IRC [Apple addition]
6669, // Alternate IRC [Apple addition]};
};
public static bool IsPort(string value)
public static bool IsUserAdministrator()
{
if (string.IsNullOrEmpty(value))
return false;
Regex numeric = new Regex(@"^[0-9]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (numeric.IsMatch(value))
//bool value to hold our return value
bool isAdmin;
try
{
try
{
if (Convert.ToInt32(value) < 65536)
return true;
}
catch (OverflowException)
{
}
//get the currently logged in user
var user = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
return false;
catch (UnauthorizedAccessException)
{
isAdmin = false;
}
catch
{
isAdmin = false;
}
return isAdmin;
}
}
}

View File

@ -12,13 +12,14 @@
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net451" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net451" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net451" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net451" />
<package id="Microsoft.Owin" version="3.0.1" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.Owin.FileSystems" version="3.0.1" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net451" userInstalled="true" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net451" />
<package id="Microsoft.Owin.StaticFiles" version="3.0.1" targetFramework="net451" userInstalled="true" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" userInstalled="true" />
<package id="NLog" version="4.0.1" targetFramework="net451" userInstalled="true" />