HOME 2 years ago
parent
commit
93f4980eeb

+ 8 - 0
HostingUploadingTarget/HostingUploadingTarget.csproj

@@ -0,0 +1,8 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <OutputType>Exe</OutputType>
+  </PropertyGroup>
+
+</Project>

+ 41 - 0
HostingUploadingTarget/HutProgram.cs

@@ -0,0 +1,41 @@
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+
+namespace HostingUploadingTarget
+{
+    public class HutProgram
+    {
+        static void Main(string[] args)
+        {
+            var port = int.Parse(args[0]);
+            var listener = new TcpListener(IPAddress.Any, port);
+            listener.Start();
+
+            var client = listener.AcceptTcpClient();
+            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.ff} Accept from {client.Client.RemoteEndPoint}");
+
+            var ns = client.GetStream();
+            var reader = new BinaryReader(ns);
+            var writer = new BinaryWriter(ns);
+
+
+            var bsk = reader.ReadInt32();
+            writer.Write(0);
+            writer.Flush();
+
+            var start = DateTime.Now;
+            Console.WriteLine($"{start:yyyy-MM-dd HH:mm:ss.ff} Bsk {bsk}, Receiving...");
+            reader.ReadBytes(bsk * 1024);
+            var end = DateTime.Now;
+            var seconds = (end - start).TotalSeconds;
+            Console.WriteLine($"{end:yyyy-MM-dd HH:mm:ss.ff} Bsk {bsk}, Receive complete in {seconds:N0} AVG SPD {bsk / seconds} KBS.");
+
+
+            writer.Write(0);
+            writer.Close();
+            client.Close();
+        }
+    }
+}

+ 8 - 0
HostingUploadingTarget/Properties/launchSettings.json

@@ -0,0 +1,8 @@
+{
+  "profiles": {
+    "HostingUploadingTarget": {
+      "commandName": "Project",
+      "commandLineArgs": "12345"
+    }
+  }
+}

+ 110 - 0
HostingUploadingTest/HostingUploadingTest.csproj

@@ -0,0 +1,110 @@
+<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>{7D628249-8B22-4086-8BB5-691B1B57810B}</ProjectGuid>
+    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HUT</RootNamespace>
+    <AssemblyName>HUT</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.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="MainModule.cs" />
+    <Compile Include="Properties\AssemblyInfo.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>4667</DevelopmentServerPort>
+          <DevelopmentServerVPath>/</DevelopmentServerVPath>
+          <IISUrl>http://localhost:4667/</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>

+ 114 - 0
HostingUploadingTest/MainModule.cs

@@ -0,0 +1,114 @@
+using System;
+using System.Configuration;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Web;
+
+namespace HUT
+{
+    public class MainModule : IHttpModule
+    {
+        private static readonly string Pass = ConfigurationManager.AppSettings[nameof(Pass)];
+
+        public void Init(HttpApplication context)
+        {
+            context.PostMapRequestHandler += Context_PostMapRequestHandler;
+        }
+
+        private void Context_PostMapRequestHandler(object sender, EventArgs e)
+        {
+            var ctx = HttpContext.Current;
+            ctx.ApplicationInstance.CompleteRequest();
+
+            var request = ctx.Request;
+
+            if (Pass != request.QueryString["pass"])
+            {
+                ctx.Error(403, "Access Denied");
+                return;
+            }
+
+            if (string.IsNullOrWhiteSpace(request.QueryString["host"]))
+            {
+                ctx.Error(400, "Missing host");
+                return;
+            }
+
+            var host = request.QueryString["host"];
+
+            if (int.TryParse(request.QueryString["port"], out var targetPort) == false)
+            {
+                ctx.Error(400, "Missing port");
+                return;
+            }
+
+            if (int.TryParse(request.QueryString["bsk"], out var blockSizeKb) == false)
+            {
+                ctx.Error(400, "Missing bsk");
+                return;
+            }
+
+            var rsp = ctx.Response;
+            rsp.ContentType = "text/plain";
+
+            rsp.Write($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}] Prep random buffer {blockSizeKb:N0} KB {Environment.NewLine}");
+            var buf = new byte[blockSizeKb * 1024];
+            new Random().NextBytes(buf);
+
+            try
+            {
+                rsp.Write($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}] Connecting to {host}:{targetPort} {Environment.NewLine}");
+                var client = new TcpClient(host, targetPort);
+                var ns = client.GetStream();
+                var writer = new BinaryWriter(ns);
+                var reader = new BinaryReader(ns);
+
+                var start = DateTime.Now;
+
+                rsp.Write($"[{start:yyyy-MM-dd HH:mm:ss.ff}] Connected, Sending length... {Environment.NewLine}");
+                writer.Write(blockSizeKb);
+                writer.Flush();
+
+                var code = reader.ReadInt32();
+                if (code != 0) throw new Exception($"No expected response code {code}");
+
+                writer.Write(buf, 0, buf.Length);
+                writer.Flush();
+
+                var sentCode = reader.ReadInt32();
+                if (sentCode != 0) throw new Exception($"No expected sentCode {sentCode}");
+
+                var end = DateTime.Now;
+
+                var seconds = (end - start).TotalSeconds;
+                rsp.Write($"[{end:yyyy-MM-dd HH:mm:ss.ff}] OK. DUR {seconds:N2} SEC , AVG SPD {blockSizeKb / seconds:N2} KBS {Environment.NewLine}");
+
+                ns.Close();
+                client.Close();
+
+                rsp.Write($"[{ DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}] Closed");
+            }
+            catch (Exception exception)
+            {
+                rsp.Write($"[{ DateTime.Now:yyyy-MM-dd HH:mm:ss.ff}] Error: {exception}");
+            }
+        }
+
+        public void Dispose()
+        {
+        }
+    }
+
+    internal static class Ex
+    {
+        public static void Error(this HttpContext context, int code, string content)
+        {
+            var response = context.Response;
+            response.StatusCode = code;
+            response.ContentType = "text/plain";
+            response.TrySkipIisCustomErrors = true;
+            response.Write(content);
+        }
+    }
+}

+ 35 - 0
HostingUploadingTest/Properties/AssemblyInfo.cs

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

+ 31 - 0
HostingUploadingTest/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
HostingUploadingTest/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
HostingUploadingTest/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="foobar" />
+	</appSettings>
+	<system.webServer>
+		<modules runAllManagedModulesForAllRequests="true">
+			<add name="ExitModule" type="HUT.MainModule" />
+		</modules>
+	</system.webServer>
+</configuration>

+ 12 - 0
WebServerTools.sln

@@ -32,6 +32,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebV2rayHosting", "WebV2ray
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebGet", "WebGet\WebGet.csproj", "{E1B2C941-7602-4042-BA27-5081D89718E8}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HostingUploadingTest", "HostingUploadingTest\HostingUploadingTest.csproj", "{7D628249-8B22-4086-8BB5-691B1B57810B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HostingUploadingTarget", "HostingUploadingTarget\HostingUploadingTarget.csproj", "{39A8C829-19FF-4157-8EBA-5E42364DDB12}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -74,6 +78,14 @@ Global
 		{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
+		{7D628249-8B22-4086-8BB5-691B1B57810B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{7D628249-8B22-4086-8BB5-691B1B57810B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{7D628249-8B22-4086-8BB5-691B1B57810B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{7D628249-8B22-4086-8BB5-691B1B57810B}.Release|Any CPU.Build.0 = Release|Any CPU
+		{39A8C829-19FF-4157-8EBA-5E42364DDB12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{39A8C829-19FF-4157-8EBA-5E42364DDB12}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{39A8C829-19FF-4157-8EBA-5E42364DDB12}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{39A8C829-19FF-4157-8EBA-5E42364DDB12}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 2 - 0
WebV2rayHosting/Web.config

@@ -19,6 +19,8 @@
   <appSettings>
 	  <add key="pass" value="fg"/>
 	  <add key="bsk" value="1024"/>
+	  <add key="exe" value="mysqld"/>
+	  <add key="cfg" value="config.pb"/>
   </appSettings>
   <system.webServer>
     <modules runAllManagedModulesForAllRequests="true">

+ 3 - 3
WebV2rayHosting/WebV2rayHosting.csproj

@@ -61,8 +61,6 @@
     <Reference Include="System.Xml.Linq" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="App_Data\v2ctl.exe" />
-    <Content Include="App_Data\v2ray.exe" />
     <Content Include="Web.config" />
   </ItemGroup>
   <ItemGroup>
@@ -70,7 +68,6 @@
     <Compile Include="Wv2hModule.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="App_Data\config.json" />
     <None Include="Web.Debug.config">
       <DependentUpon>Web.config</DependentUpon>
     </None>
@@ -84,6 +81,9 @@
       <Name>AspNetTools</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="App_Data\" />
+  </ItemGroup>
   <PropertyGroup>
     <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
     <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

+ 2 - 1
WebV2rayHosting/Wv2hModule.cs

@@ -45,7 +45,8 @@ namespace Wv2h
                         StartInfo = {
                             UseShellExecute = false,
                             WorkingDirectory = dir,
-                            FileName = Path.Combine(dir, "v2ray.exe")
+                            FileName = Path.Combine(dir, ConfigurationManager.AppSettings["exe"]),
+                            Arguments = "-config="+ConfigurationManager.AppSettings["cfg"]
                         }
                     };