Skip to content

Commit

Permalink
add grpc params
Browse files Browse the repository at this point in the history
  • Loading branch information
next-autumn committed Jun 29, 2021
1 parent 2f0f9fb commit 9923437
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 61 deletions.
8 changes: 8 additions & 0 deletions ProxySuper.Core/Helpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ public static string GetTickID()
{
return DateTime.Now.Ticks.ToString();
}

private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
}
9 changes: 5 additions & 4 deletions ProxySuper.Core/Models/Projects/XraySettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using ProxySuper.Core.Services;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,13 +22,13 @@ public XraySettings()
UUID = guid;
Types = new List<XrayType>();

VLESS_WS_Path = "/vlessws";
VLESS_WS_Path = "/" + Utils.RandomString(6);
VLESS_KCP_Type = "none";
VLESS_KCP_Seed = guid;
VLESS_gRPC_ServiceName = "xray_gRPC";
VLESS_gRPC_ServiceName = "/" + Utils.RandomString(7);

VMESS_WS_Path = "/vmessws";
VMESS_TCP_Path = "/vmesstcp";
VMESS_WS_Path = "/" + Utils.RandomString(8);
VMESS_TCP_Path = "/" + Utils.RandomString(9);
VMESS_KCP_Seed = guid;
VMESS_KCP_Type = "none";

Expand Down
1 change: 0 additions & 1 deletion ProxySuper.Core/ProxySuper.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<Compile Include="Converters\ProxyTypeConverter.cs" />
<Compile Include="Converters\VisibleConverter.cs" />
<Compile Include="Helpers\DateTimeUtils.cs" />
<Compile Include="Helpers\Rand.cs" />
<Compile Include="Models\Hosts\Host.cs" />
<Compile Include="Models\Hosts\LocalProxyType.cs" />
<Compile Include="Models\Hosts\LoginSecretType.cs" />
Expand Down
15 changes: 14 additions & 1 deletion ProxySuper.Core/Services/XrayConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class XrayConfigBuilder
public static int VLESS_WS_Port = 1111;
public static int VLESS_H2_Port = 1112;
public static int VLESS_mKCP_Port = 1113;
public static int VLESS_gRPC_Port = 1114;

public static int VMESS_TCP_Port = 1210;
public static int VMESS_WS_Port = 1211;
Expand Down Expand Up @@ -93,6 +94,18 @@ public static string BuildCaddyConfig(XraySettings parameters, bool useCustomWeb
caddyStr = caddyStr.Replace("##reverse_proxy##", "");
}

if (parameters.Types.Contains(XrayType.VLESS_gRPC))
{
var grpcCaddyfile = File.ReadAllText(Path.Combine(CaddyFileDir, "grpc.caddyfile"));
grpcCaddyfile = grpcCaddyfile.Replace("##domain##", parameters.Domain);
grpcCaddyfile = grpcCaddyfile.Replace("##port##", parameters.VLESS_gRPC_Port.ToString());
grpcCaddyfile = grpcCaddyfile.Replace("##local_port##", VLESS_gRPC_Port.ToString());
grpcCaddyfile = grpcCaddyfile.Replace("##path##", parameters.VLESS_gRPC_ServiceName);

caddyStr += "\n";
caddyStr += grpcCaddyfile;
}

return caddyStr;
}

Expand Down Expand Up @@ -126,7 +139,7 @@ public static string BuildXrayConfig(XraySettings parameters)
if (parameters.Types.Contains(XrayType.VLESS_gRPC))
{
var gRPCInBound = GetBound("VLESS_gRPC.json");
gRPCInBound.port = parameters.VLESS_gRPC_Port;
gRPCInBound.port = VLESS_gRPC_Port;
gRPCInBound.settings.clients[0].id = parameters.UUID;
gRPCInBound.streamSettings.grpcSettings.serviceName = parameters.VLESS_gRPC_ServiceName;
xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound));
Expand Down
38 changes: 23 additions & 15 deletions ProxySuper.WPF/Controls/XraySettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<Label Content="{DynamicResource VlessKcpDesc}" FontSize="13" Foreground="LimeGreen" />
</CheckBox>

<!--gRPC-->
<CheckBox Margin="0,15,0,0"
VerticalContentAlignment="Center"
Foreground="LimeGreen"
IsChecked="{Binding Path=Checked_VLESS_gRPC}">
<Label Content="VLESS gRPC&#x0a;基于http2,多路复用。" FontSize="13" Foreground="LimeGreen" />
</CheckBox>

<!--TCP-->
<!--<CheckBox Content="VMESS over TCP with TLS&#x0a;不推荐"
Margin="0,15,0,0"
Expand Down Expand Up @@ -78,13 +86,6 @@
<Label Content="{DynamicResource TrojanDesc}" FontSize="13" Foreground="CadetBlue" />
</CheckBox>

<!--gRPC-->
<!--<CheckBox Content="VLESS gRPC&#x0a;基于http2,多路复用。"
Margin="0,15,0,0"
Grid.Column="0"
Style="{StaticResource MahApps.Styles.CheckBox}"
IsChecked="{Binding Path=Checked_VLESS_gRPC}"/>-->

</StackPanel>

<!--************************** 参数 **************************-->
Expand Down Expand Up @@ -168,21 +169,28 @@
</StackPanel>

<!--gRPC Port-->
<!--<StackPanel Margin="30,15,0,0"
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VLESS_gRPC,
Converter={StaticResource VisibleConverter}
}">
<Label Content="gRPC端口" Width="120" Foreground="LimeGreen" />
<TextBox Text="{Binding Path=VLESS_gRPC_Port}" Width="120" />
<Label Content="{DynamicResource VlessRPCPort}" Width="120" Foreground="LimeGreen" />
<TextBox Text="{Binding Path=VLESS_gRPC_Port}" Width="200" />
</StackPanel>

<Label Content="服务器" Width="120" Margin="10,0,0,0" Foreground="LimeGreen" />
<TextBox Text="{Binding Path=VLESS_gRPC_ServiceName}" Width="120" />
</StackPanel>-->
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VLESS_gRPC,
Converter={StaticResource VisibleConverter}
}">
<Label Content="{DynamicResource VlessRPCName}" Width="120" Foreground="LimeGreen" />
<TextBox Text="{Binding Path=VLESS_gRPC_ServiceName}" Width="200" />
</StackPanel>

<!--Tcp Path-->
<!--<StackPanel Margin="30,15,0,0"
<!--Tcp Path
<StackPanel Margin="30,15,0,0"
Orientation="Horizontal"
Visibility="{
Binding Path=Checked_VMESS_TCP,
Expand Down
36 changes: 4 additions & 32 deletions ProxySuper.WPF/ProxySuper.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,7 @@
  <AllowedReferenceRelatedFileExtensions>
    <!-- 阻止默认的 XML 和 PDB 文件复制到 RELEASE 的输出目录. 只有*.allowedextension 扩展名的文件可以被包含, 当然这个扩展的文件并不存在.-->
    .allowedextension
  </AllowedReferenceRelatedFileExtensions>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B083EBFD-2925-46C9-8B00-E2C1300CEBA1}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ProxySuper.WPF</RootNamespace>
<AssemblyName>ProxySuper.WPF</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
  </AllowedReferenceRelatedFileExtensions><Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration><Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform><ProjectGuid>{B083EBFD-2925-46C9-8B00-E2C1300CEBA1}</ProjectGuid><OutputType>WinExe</OutputType><RootNamespace>ProxySuper.WPF</RootNamespace><AssemblyName>ProxySuper.WPF</AssemblyName><TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion><FileAlignment>512</FileAlignment><ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids><WarningLevel>4</WarningLevel><AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects><Deterministic>true</Deterministic><NuGetPackageImportStamp></NuGetPackageImportStamp><IsWebBootstrapper>false</IsWebBootstrapper><TargetFrameworkProfile /><PublishUrl>publish\</PublishUrl><Install>true</Install><InstallFrom>Disk</InstallFrom><UpdateEnabled>false</UpdateEnabled><UpdateMode>Foreground</UpdateMode><UpdateInterval>7</UpdateInterval><UpdateIntervalUnits>Days</UpdateIntervalUnits><UpdatePeriodically>false</UpdatePeriodically><UpdateRequired>false</UpdateRequired><MapFileExtensions>true</MapFileExtensions><ApplicationRevision>0</ApplicationRevision><ApplicationVersion>1.0.0.%2a</ApplicationVersion><UseApplicationTrust>false</UseApplicationTrust><BootstrapperEnabled>true</BootstrapperEnabled></PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -334,6 +303,9 @@
<None Include="Templates\xray\caddy\base.caddyfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Templates\xray\caddy\grpc.caddyfile">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Templates\xray\client\00_log\00_log.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 2 additions & 0 deletions ProxySuper.WPF/Resources/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<sys:String x:Key="VlessKcpSeed">VLESS KCP Seed</sys:String>
<sys:String x:Key="VlessKcpType">VLESS KCP Type</sys:String>
<sys:String x:Key="VlessKcpPort">VLESS KCP Port</sys:String>
<sys:String x:Key="VlessRPCName">gRPC Service Name</sys:String>
<sys:String x:Key="VlessRPCPort">gRPC Port</sys:String>
<sys:String x:Key="VmessWsPath">VMESS WS Path</sys:String>
<sys:String x:Key="VmessKcpSeed">VMESS KCP Seed</sys:String>
<sys:String x:Key="VmessKcpType">VMESS KCP Type</sys:String>
Expand Down
2 changes: 2 additions & 0 deletions ProxySuper.WPF/Resources/Languages/tw_cn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
<sys:String x:Key="VlessKcpSeed">VLESS KCP Seed</sys:String>
<sys:String x:Key="VlessKcpType">VLESS KCP偽裝</sys:String>
<sys:String x:Key="VlessKcpPort">VLESS KCP端口</sys:String>
<sys:String x:Key="VlessRPCName">gRPC路徑</sys:String>
<sys:String x:Key="VlessRPCPort">gRPC端口</sys:String>
<sys:String x:Key="VmessWsPath">VMESS WS路徑</sys:String>
<sys:String x:Key="VmessKcpSeed">VMESS KCP Seed</sys:String>
<sys:String x:Key="VmessKcpType">VMESS KCP偽裝</sys:String>
Expand Down
2 changes: 2 additions & 0 deletions ProxySuper.WPF/Resources/Languages/zh_cn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<sys:String x:Key="VlessKcpSeed">VLESS KCP Seed</sys:String>
<sys:String x:Key="VlessKcpType">VLESS KCP伪装</sys:String>
<sys:String x:Key="VlessKcpPort">VLESS KCP端口</sys:String>
<sys:String x:Key="VlessRPCName">gRPC路径</sys:String>
<sys:String x:Key="VlessRPCPort">gRPC端口</sys:String>
<sys:String x:Key="VmessWsPath">VMESS WS路径</sys:String>
<sys:String x:Key="VmessKcpSeed">VMESS KCP Seed</sys:String>
<sys:String x:Key="VmessKcpType">VMESS KCP伪装</sys:String>
Expand Down
10 changes: 10 additions & 0 deletions ProxySuper.WPF/Templates/xray/caddy/grpc.caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##domain##:##port## {
@grpc {
protocol grpc
path ##path##
}

reverse_proxy @grpc h2c://127.0.0.1:##local_port##
root * /var/www
file_server
}
10 changes: 2 additions & 8 deletions ProxySuper.WPF/Templates/xray/server/05_inbounds/VLESS_gRPC.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"port": 2002,
"port": 2003,
"listen": "127.0.0.1",
"protocol": "vless",
"settings": {
Expand All @@ -13,13 +13,7 @@
"streamSettings": {
"network": "grpc",
"grpcSettings": {
"serviceName": "",
"certificates": [
{
"certificateFile": "/usr/local/etc/xray/ssl/xray_ssl.crt",
"keyFile": "/usr/local/etc/xray/ssl/xray_ssl.key"
}
]
"serviceName": ""
}
}
}

0 comments on commit 9923437

Please sign in to comment.