瀏覽代碼

add: WebGet

HOME 4 年之前
父節點
當前提交
e6c5cb69d2
共有 7 個文件被更改,包括 339 次插入0 次删除
  1. 35 0
      WebGet/Properties/AssemblyInfo.cs
  2. 31 0
      WebGet/Web.Debug.config
  3. 32 0
      WebGet/Web.Release.config
  4. 20 0
      WebGet/Web.config
  5. 111 0
      WebGet/WebGet.csproj
  6. 104 0
      WebGet/WebGetModule.cs
  7. 6 0
      WebServerTools.sln

+ 35 - 0
WebGet/Properties/AssemblyInfo.cs

@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过下列特性集
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("WebGet")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("WebGet")]
+[assembly: AssemblyCopyright("Copyright ©  2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+// 对 COM 组件不可见。如果需要
+// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
+[assembly: Guid("e1b2c941-7602-4042-ba27-5081d89718e8")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+//      主版本
+//      次版本
+//      内部版本号
+//      修订版本
+//
+// 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值,
+// 方法是按如下所示使用 "*":
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 31 - 0
WebGet/Web.Debug.config

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 有关使用 web.config 转换的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+  <!--
+    在下例中,“SetAttributes”转换将更改 
+    “connectionString”的值,以仅在“Match”定位器 
+    找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
+    
+    <connectionStrings>
+      <add name="MyDB" 
+        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
+        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+    </connectionStrings>
+  -->
+  <system.web>
+    <!--
+      
+      在下例中,“Replace”转换将替换 
+      web.config 文件的整个 <customErrors> 节。
+      请注意,由于 
+      在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
+      
+      <customErrors defaultRedirect="GenericError.htm"
+        mode="RemoteOnly" xdt:Transform="Replace">
+        <error statusCode="500" redirect="InternalError.htm"/>
+      </customErrors>
+    -->
+  </system.web>
+</configuration>

+ 32 - 0
WebGet/Web.Release.config

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 有关使用 web.config 转换的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+  <!--
+    在下例中,“SetAttributes”转换将更改 
+    “connectionString”的值,以仅在“Match”定位器 
+    找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
+    
+    <connectionStrings>
+      <add name="MyDB" 
+        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
+        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+    </connectionStrings>
+  -->
+  <system.web>
+    <compilation xdt:Transform="RemoveAttributes(debug)" />
+    <!--
+      
+      在下例中,“Replace”转换将替换 
+      web.config 文件的整个 <customErrors> 节。
+      请注意,由于 
+      在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
+      
+      <customErrors defaultRedirect="GenericError.htm"
+        mode="RemoteOnly" xdt:Transform="Replace">
+        <error statusCode="500" redirect="InternalError.htm"/>
+      </customErrors>
+    -->
+  </system.web>
+</configuration>

+ 20 - 0
WebGet/Web.config

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  有关如何配置 ASP.NET 应用程序的详细信息,请访问
+  https://go.microsoft.com/fwlink/?LinkId=169433
+-->
+<configuration>
+	<system.web>
+		<compilation debug="true" targetFramework="4.6.1"/>
+		<httpRuntime targetFramework="4.6.1"/>
+	</system.web>
+	<appSettings>
+		<add key="pass" value="fg"/>
+	</appSettings>
+	<system.webServer>
+		<modules runAllManagedModulesForAllRequests="true">
+			<add name="Terminal" type="WebGet.WebGetModule"/>
+		</modules>
+	</system.webServer>
+</configuration>

+ 111 - 0
WebGet/WebGet.csproj

@@ -0,0 +1,111 @@
+<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>
+    </ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{E1B2C941-7602-4042-BA27-5081D89718E8}</ProjectGuid>
+    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>WebGet</RootNamespace>
+    <AssemblyName>WebGet</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <UseIISExpress>true</UseIISExpress>
+    <Use64BitIISExpress />
+    <IISExpressSSLPort />
+    <IISExpressAnonymousAuthentication />
+    <IISExpressWindowsAuthentication />
+    <IISExpressUseClassicPipelineMode />
+    <UseGlobalApplicationHostFile />
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Web.DynamicData" />
+    <Reference Include="System.Web.Entity" />
+    <Reference Include="System.Web.ApplicationServices" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Web.Extensions" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Web" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Web.Services" />
+    <Reference Include="System.EnterpriseServices" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Web.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="WebGetModule.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Web.Debug.config">
+      <DependentUpon>Web.config</DependentUpon>
+    </None>
+    <None Include="Web.Release.config">
+      <DependentUpon>Web.config</DependentUpon>
+    </None>
+  </ItemGroup>
+  <PropertyGroup>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+  </PropertyGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
+  <ProjectExtensions>
+    <VisualStudio>
+      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
+        <WebProjectProperties>
+          <UseIIS>True</UseIIS>
+          <AutoAssignPort>True</AutoAssignPort>
+          <DevelopmentServerPort>28153</DevelopmentServerPort>
+          <DevelopmentServerVPath>/</DevelopmentServerVPath>
+          <IISUrl>http://localhost:28153/</IISUrl>
+          <NTLMAuthentication>False</NTLMAuthentication>
+          <UseCustomServer>False</UseCustomServer>
+          <CustomServerUrl>
+          </CustomServerUrl>
+          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
+        </WebProjectProperties>
+      </FlavorProperties>
+    </VisualStudio>
+  </ProjectExtensions>
+  <!-- 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">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 104 - 0
WebGet/WebGetModule.cs

@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Configuration;
+using System.EnterpriseServices;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web;
+using System.Web.Services.Configuration;
+
+namespace WebGet
+{
+    public class WebGetModule : IHttpModule
+    {
+
+        private static readonly ConcurrentDictionary<string, DownloadState> Sessions = new ConcurrentDictionary<string, DownloadState>();
+
+        public void Init(HttpApplication context)
+        {
+            context.PostMapRequestHandler += ContextOnPostMapRequestHandler;
+        }
+
+        private void ContextOnPostMapRequestHandler(object sender, EventArgs e)
+        {
+            var ctx = HttpContext.Current;
+            var req = ctx.Request;
+            var qs = req.QueryString;
+
+            var rsp = ctx.Response;
+            if (qs["pass"] != ConfigurationManager.AppSettings["pass"])
+            {
+                rsp.StatusCode = 403;
+                rsp.Write("403 Access Denied");
+                ctx.ApplicationInstance.CompleteRequest();
+                return;
+            }
+
+            var url = qs["url"];
+            if (string.IsNullOrEmpty(url))
+            {
+                rsp.StatusCode = 400;
+                rsp.Write("400 Bad Request: Missing URL param");
+                ctx.ApplicationInstance.CompleteRequest();
+                return;
+            }
+
+
+            rsp.ContentType = "text/html";
+            rsp.Write($"Download it - {url}<br/>");
+
+
+            try
+            {
+                var http = new HttpClient();
+                var r = http.GetAsync(url).Result;
+                if (!r.IsSuccessStatusCode) throw new HttpException((int)r.StatusCode, r.ReasonPhrase);
+
+                var fileName = r.Content.Headers.ContentDisposition?.FileName;
+                if (string.IsNullOrWhiteSpace(fileName)) fileName = Path.GetFileName(url);
+                if (string.IsNullOrWhiteSpace(fileName)) fileName = $"Download-{DateTime.Now:yyyyMMdd-HHmmssff}.bin";
+
+                var start = DateTime.Now;
+                rsp.Write($"Download start at {start}<br/>");
+
+                var buf = r.Content.ReadAsByteArrayAsync().Result;
+                var end = DateTime.Now;
+                rsp.Write($"Download end at {end}<br/>");
+
+                var len = buf.Length;
+
+                rsp.Write($"Len: {len}<br/>");
+                rsp.Write($"FileName: {fileName}<br/>");
+
+                rsp.Write($"Download dur {end - start}<br/>");
+
+
+                var saveTo = ctx.Server.MapPath("~/" + fileName);
+                File.WriteAllBytes(saveTo, buf);
+
+                rsp.Write($"File Saved<br/>");
+            }
+            catch (Exception exception)
+            {
+                rsp.StatusCode = 500;
+                rsp.Write($"Error: {exception.Message}<br/>");
+            }
+
+            ctx.ApplicationInstance.CompleteRequest();
+        }
+
+
+        private class DownloadState
+        {
+
+        }
+
+        public void Dispose()
+        {
+
+        }
+    }
+}

+ 6 - 0
WebServerTools.sln

@@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebSocketForwardClient", "W
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebV2rayHosting", "WebV2rayHosting\WebV2rayHosting.csproj", "{DE417D6D-1E51-47CE-86E7-20A25E15017B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebGet", "WebGet\WebGet.csproj", "{E1B2C941-7602-4042-BA27-5081D89718E8}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -68,6 +70,10 @@ Global
 		{DE417D6D-1E51-47CE-86E7-20A25E15017B}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{DE417D6D-1E51-47CE-86E7-20A25E15017B}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{DE417D6D-1E51-47CE-86E7-20A25E15017B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E1B2C941-7602-4042-BA27-5081D89718E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E1B2C941-7602-4042-BA27-5081D89718E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E1B2C941-7602-4042-BA27-5081D89718E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E1B2C941-7602-4042-BA27-5081D89718E8}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE