1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-24 06:06:07 +03:00

update share link

This commit is contained in:
next-autumn 2021-03-15 17:58:20 +08:00
parent 3dfee31081
commit 4d5e15afb3
10 changed files with 388 additions and 97 deletions

4
.editorconfig Normal file
View File

@ -0,0 +1,4 @@
[*.cs]
# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = none

View File

@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySU", "ProxySU\ProxySU.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySU_Core", "ProxySU_Core\ProxySU_Core.csproj", "{B066015C-D347-4493-92F1-6556D3863996}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxySU_Core", "ProxySU_Core\ProxySU_Core.csproj", "{B066015C-D347-4493-92F1-6556D3863996}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{18714411-764D-47E5-AFE6-A96200B7CE41}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View File

@ -181,6 +181,9 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<None Include="..\.editorconfig">
<Link>.editorconfig</Link>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>

View File

@ -105,6 +105,6 @@ namespace ProxySU_Core.Models
VMESS_TCP_TLS, VMESS_TCP_TLS,
VMESS_WS_TLS, VMESS_WS_TLS,
Trojan_TCP_TLS Trojan_TCP_TLS,
} }
} }

View File

@ -62,7 +62,7 @@
<GenerateManifests>true</GenerateManifests> <GenerateManifests>true</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignManifests>true</SignManifests> <SignManifests>false</SignManifests>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ControlzEx, Version=5.0.0.0, Culture=neutral, PublicKeyToken=69f1c32f803d307e, processorArchitecture=MSIL"> <Reference Include="ControlzEx, Version=5.0.0.0, Culture=neutral, PublicKeyToken=69f1c32f803d307e, processorArchitecture=MSIL">

View File

@ -29,52 +29,10 @@ namespace ProxySU_Core.ViewModels.Developers
{ {
} }
public void InstallCert()
{
EnsureRootAuth();
EnsureSystemEnv();
this.InstallCertToXray();
RunCmd("systemctl restart xray");
WriteOutput("************ 安装证书完成 ************");
}
public void UploadWeb(Stream stream)
{
EnsureRootAuth();
EnsureSystemEnv();
if (!FileExists("/usr/share/caddy"))
{
RunCmd("mkdir /usr/share/caddy");
}
RunCmd("rm -rf /usr/share/caddy/*");
UploadFile(stream, "/usr/share/caddy/caddy.zip");
RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy");
RunCmd("chmod -R 777 /usr/share/caddy");
UploadCaddyFile(useCustomWeb: true);
WriteOutput("************ 上传网站模板完成 ************");
}
public void UpdateXraySettings()
{
EnsureRootAuth();
EnsureSystemEnv();
var configJson = ConfigBuilder.BuildXrayConfig(Parameters);
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("rm -rf /usr/local/etc/xray/config.json");
UploadFile(stream, "/usr/local/etc/xray/config.json");
RunCmd("systemctl restart xray");
WriteOutput("************ 更新Xray配置成功更新配置不包含域名如果域名更换请重新安装。 ************");
}
public void ReinstallCaddy()
{
EnsureRootAuth();
EnsureSystemEnv();
InstallCaddy();
UploadCaddyFile();
WriteOutput("************ 重装Caddy完成 ************");
}
/// <summary>
/// 安装Xray
/// </summary>
public override void Install() public override void Install()
{ {
try try
@ -142,6 +100,130 @@ namespace ProxySU_Core.ViewModels.Developers
} }
} }
/// <summary>
/// 更新xray内核
/// </summary>
public void UpdateXrayCore()
{
EnsureRootAuth();
EnsureSystemEnv();
RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install");
RunCmd("systemctl restart xray");
WriteOutput("************ 更新xray内核完成 ************");
}
/// <summary>
/// 更新xray配置
/// </summary>
public void UpdateXraySettings()
{
EnsureRootAuth();
EnsureSystemEnv();
var configJson = ConfigBuilder.BuildXrayConfig(Parameters);
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("rm -rf /usr/local/etc/xray/config.json");
UploadFile(stream, "/usr/local/etc/xray/config.json");
RunCmd("systemctl restart xray");
WriteOutput("************ 更新Xray配置成功更新配置不包含域名如果域名更换请重新安装。 ************");
}
/// <summary>
/// 重装Caddy
/// </summary>
public void ReinstallCaddy()
{
EnsureRootAuth();
EnsureSystemEnv();
InstallCaddy();
UploadCaddyFile();
WriteOutput("************ 重装Caddy完成 ************");
}
/// <summary>
/// 安装证书
/// </summary>
public void InstallCert()
{
EnsureRootAuth();
EnsureSystemEnv();
this.InstallCertToXray();
RunCmd("systemctl restart xray");
WriteOutput("************ 安装证书完成 ************");
}
/// <summary>
/// 上传证书
/// </summary>
/// <param name="keyStrem"></param>
/// <param name="crtStream"></param>
public void UploadCert(Stream stream)
{
EnsureRootAuth();
EnsureSystemEnv();
// 转移旧文件
var oldFileName = $"ssl_{DateTime.Now.Ticks}";
RunCmd($"mv /usr/local/etc/xray/ssl /usr/local/etc/xray/{oldFileName}");
// 上传新文件
RunCmd("mkdir /usr/local/etc/xray/ssl");
UploadFile(stream, "/usr/local/etc/xray/ssl/ssl.zip");
RunCmd("unzip /usr/local/etc/xray/ssl/ssl.zip -d /usr/local/etc/xray/ssl");
// 改名
var crtFiles = RunCmd("find /usr/local/etc/xray/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (crtFiles.Length > 0)
{
RunCmd($"mv {crtFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.crt");
}
else
{
WriteOutput("************ 上传证书失败,请联系开发者 ************");
RunCmd("rm -rf /usr/local/etc/xray/ssl");
RunCmd($"mv /usr/local/etc/xray/ssl{oldFileName} /usr/local/etc/xray/ssl");
WriteOutput("操作已回滚");
return;
}
var keyFiles = RunCmd("find /usr/local/etc/xray/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (keyFiles.Length > 0)
{
RunCmd($"mv {keyFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.key");
}
else
{
WriteOutput("************ 上传证书失败,请联系开发者 ************");
RunCmd("rm -rf /usr/local/etc/xray/ssl");
RunCmd($"mv /usr/local/etc/xray/ssl{oldFileName} /usr/local/etc/xray/ssl");
WriteOutput("操作已回滚");
return;
}
RunCmd("systemctl restart xray");
WriteOutput("************ 上传证书完成 ************");
}
/// <summary>
/// 上传静态网站
/// </summary>
/// <param name="stream"></param>
public void UploadWeb(Stream stream)
{
EnsureRootAuth();
EnsureSystemEnv();
if (!FileExists("/usr/share/caddy"))
{
RunCmd("mkdir /usr/share/caddy");
}
RunCmd("rm -rf /usr/share/caddy/*");
UploadFile(stream, "/usr/share/caddy/caddy.zip");
RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy");
RunCmd("chmod -R 777 /usr/share/caddy");
UploadCaddyFile(useCustomWeb: true);
WriteOutput("************ 上传网站模板完成 ************");
}
private void UploadCaddyFile(bool useCustomWeb = false) private void UploadCaddyFile(bool useCustomWeb = false)
{ {
var configJson = ConfigBuilder.BuildCaddyConfig(Parameters, useCustomWeb); var configJson = ConfigBuilder.BuildCaddyConfig(Parameters, useCustomWeb);

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web;
using System.Windows; using System.Windows;
namespace ProxySU_Core.ViewModels namespace ProxySU_Core.ViewModels
@ -234,5 +235,116 @@ namespace ProxySU_Core.ViewModels
} }
} }
public string VLESS_TCP_XTLS_ShareLink
{
get => BuildVlessShareLink(XrayType.VLESS_TCP_XTLS);
}
public string VLESS_TCP_TLS_ShareLink
{
get => BuildVlessShareLink(XrayType.VLESS_TCP_TLS);
}
public string VLESS_WS_TLS_ShareLink
{
get => BuildVlessShareLink(XrayType.VLESS_WS_TLS);
}
public string VMESS_TCP_TLS_ShareLink
{
get => BuildVmessShareLink(XrayType.VMESS_TCP_TLS);
}
public string VMESS_WS_TLS_ShareLink
{
get => BuildVmessShareLink(XrayType.VMESS_WS_TLS);
}
public string Trojan_TCP_TLS_ShareLink
{
get => BuildVlessShareLink(XrayType.Trojan_TCP_TLS);
}
public string BuildVmessShareLink(XrayType xrayType)
{
return "vmess://xxxxxx";
}
public string BuildVlessShareLink(XrayType xrayType)
{
var _protocol = string.Empty;
var _uuid = settings.UUID;
var _domain = settings.Domain;
var _port = settings.Port;
var _type = string.Empty;
var _encryption = string.Empty;
var _security = "tls";
var _path = "/";
var _host = settings.Domain;
var _descriptiveText = string.Empty;
switch (xrayType)
{
case XrayType.VLESS_TCP_TLS:
_protocol = "vless";
_type = "tcp";
_path = VLESS_TCP_Path;
_encryption = "none";
_descriptiveText = "vless-tcp-tls";
break;
case XrayType.VLESS_TCP_XTLS:
_protocol = "vless";
_type = "tcp";
_security = "xtls";
_encryption = "none";
_descriptiveText = "vless-tcp-xtls";
break;
case XrayType.VLESS_WS_TLS:
_protocol = "vless";
_type = "ws";
_path = VLESS_WS_Path;
_encryption = "none";
_descriptiveText = "vless-ws-tls";
break;
case XrayType.VMESS_TCP_TLS:
_protocol = "vmess";
_type = "tcp";
_path = VMESS_TCP_Path;
_encryption = "auto";
_descriptiveText = "vmess-tcp-tls";
break;
case XrayType.VMESS_WS_TLS:
_protocol = "vmess";
_type = "ws";
_path = VMESS_WS_Path;
_encryption = "auto";
_descriptiveText = "vmess-ws-tls";
break;
case XrayType.Trojan_TCP_TLS:
_protocol = "trojan";
_descriptiveText = "trojan-tcp";
break;
default:
throw new Exception("暂未实现的协议");
}
string parametersURL = string.Empty;
if (xrayType != XrayType.Trojan_TCP_TLS)
{
// 4.3 传输层相关段
parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&host={_host}&path={HttpUtility.UrlEncode(_path)}";
// if mKCP
// if QUIC
// 4.4 TLS 相关段
if (xrayType == XrayType.VLESS_TCP_XTLS)
{
parametersURL += "&flow=xtls-rprx-direct";
}
}
return $"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}";
}
} }
} }

View File

@ -65,7 +65,12 @@
<StackPanel Orientation="Horizontal" Margin="0,10,0,0"> <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="传输安全(tls)" Width="120" /> <Label Content="传输安全(tls)" Width="120" />
<TextBox Text="xtls" IsReadOnly="True" Width="200" /> <TextBox Text="xtls" IsReadOnly="True" Width="200" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.VLESS_TCP_XTLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Width="200" <TabItem Width="200"
@ -122,6 +127,11 @@
<Label Content="传输安全(tls)" Width="120" /> <Label Content="传输安全(tls)" Width="120" />
<TextBox Text="tls" IsReadOnly="True" Width="200" /> <TextBox Text="tls" IsReadOnly="True" Width="200" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.VLESS_TCP_TLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Width="200" <TabItem Width="200"
@ -178,6 +188,11 @@
<Label Content="传输安全(tls)" Width="120" /> <Label Content="传输安全(tls)" Width="120" />
<TextBox Text="tls" IsReadOnly="True" Width="200" /> <TextBox Text="tls" IsReadOnly="True" Width="200" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.VLESS_WS_TLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Width="200" <TabItem Width="200"
@ -229,6 +244,11 @@
<Label Content="传输安全(tls)" Width="120" /> <Label Content="传输安全(tls)" Width="120" />
<TextBox Text="tls" IsReadOnly="True" Width="200" /> <TextBox Text="tls" IsReadOnly="True" Width="200" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.VMESS_TCP_TLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Width="200" <TabItem Width="200"
@ -280,6 +300,11 @@
<Label Content="传输安全(tls)" Width="120" /> <Label Content="传输安全(tls)" Width="120" />
<TextBox Text="tls" IsReadOnly="True" Width="200" /> <TextBox Text="tls" IsReadOnly="True" Width="200" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.VMESS_WS_TLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>
<TabItem Width="200" <TabItem Width="200"
@ -301,6 +326,11 @@
<Label Content="密码" Width="120" /> <Label Content="密码" Width="120" />
<TextBox Text="{Binding Settings.TrojanPassword}" IsReadOnly="True" Width="300" /> <TextBox Text="{Binding Settings.TrojanPassword}" IsReadOnly="True" Width="300" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="分享链接" Width="120" />
<TextBox Text="{Binding Settings.Trojan_TCP_TLS_ShareLink,Mode=OneTime}" Width="300" IsReadOnly="True" />
</StackPanel>
</StackPanel> </StackPanel>
</TabItem> </TabItem>

View File

@ -15,47 +15,73 @@
FontSize="14" FontSize="14"
FontFamily="Consolas" FontFamily="Consolas"
x:Name="OutputTextBox" x:Name="OutputTextBox"
Height="320" Height="260"
Text="{Binding Path=OutputText}" Text="{Binding Path=OutputText}"
/> />
<StackPanel Margin="10" <StackPanel Margin="10"
Orientation="Horizontal" Orientation="Vertical"
HorizontalAlignment="Left"> HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="内核/配置"
VerticalAlignment="Center"
Margin="0,0,10,0"/>
<Button Content="安装Xray"
Click="Install"
Height="26"
IsEnabled="{Binding HasConnected}"
Width="120"/>
<Button Content="安装Xray" <Button Content="更新Xray内核"
Click="Install" Margin="10,0,0,0"
Height="32" Click="UpdateXrayCore"
IsEnabled="{Binding HasConnected}" Height="26"
Width="100"/> IsEnabled="{Binding HasConnected}"
Width="120"/>
<Button Content="更新Xray配置" <Button Content="更新Xray配置"
Margin="10,0,0,0" Margin="10,0,0,0"
Click="UpdateXraySettings" Click="UpdateXraySettings"
Height="32" Height="26"
IsEnabled="{Binding HasConnected}" IsEnabled="{Binding HasConnected}"
Width="120"/> Width="120"/>
</StackPanel>
<Button Content="申请TLS证书" <StackPanel Orientation="Horizontal"
Margin="10,0,0,0" Margin="0,10,0,0">
Height="32" <TextBlock Text="证书/网站"
Width="120" VerticalAlignment="Center"
IsEnabled="{Binding HasConnected}" Margin="0,0,10,0"/>
Click="InstallCert"/>
<Button Content="上传伪装网站" <Button Content="生成证书"
Margin="10,0,0,0" Margin="0,0,0,0"
Height="32" Height="26"
Width="120" Width="120"
IsEnabled="{Binding HasConnected}" IsEnabled="{Binding HasConnected}"
Click="UploadWeb"/> Click="InstallCert"/>
<Button Content="重装Caddy" <Button Content="上传自有证书"
Margin="10,0,0,0" Margin="10,0,0,0"
Click="ReinstallCaddy" Height="26"
Height="32" Width="120"
IsEnabled="{Binding HasConnected}" IsEnabled="{Binding HasConnected}"
Width="120"/> Click="UploadCert"/>
<Button Content="上传伪装网站"
Margin="10,0,0,0"
Height="26"
Width="120"
IsEnabled="{Binding HasConnected}"
Click="UploadWeb"/>
<Button Content="重装Caddy"
Margin="10,0,0,0"
Click="ReinstallCaddy"
Height="26"
IsEnabled="{Binding HasConnected}"
Width="120"/>
</StackPanel>
</StackPanel> </StackPanel>
<StackPanel Margin="10,0,0,0"> <StackPanel Margin="10,0,0,0">

View File

@ -135,26 +135,11 @@ namespace ProxySU_Core
}); });
} }
private void InstallCert(object sender, RoutedEventArgs e) private void UpdateXrayCore(object sender, RoutedEventArgs e)
{ {
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
project.InstallCert(); project.UpdateXrayCore();
});
}
private void UploadWeb(object sender, RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog();
fileDialog.FileOk += OnFileOk;
fileDialog.ShowDialog();
}
private void ReinstallCaddy(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
project.ReinstallCaddy();
}); });
} }
@ -166,7 +151,39 @@ namespace ProxySU_Core
}); });
} }
private void OnFileOk(object sender, CancelEventArgs e) private void InstallCert(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
project.InstallCert();
});
}
private void UploadCert(object sender, RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog();
fileDialog.Filter = "压缩文件|*.zip";
fileDialog.FileOk += DoUploadCert;
fileDialog.ShowDialog();
}
private void UploadWeb(object sender, RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog();
fileDialog.Filter = "压缩文件|*.zip";
fileDialog.FileOk += DoUploadWeb;
fileDialog.ShowDialog();
}
private void ReinstallCaddy(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
project.ReinstallCaddy();
});
}
private void DoUploadWeb(object sender, CancelEventArgs e)
{ {
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
@ -178,6 +195,18 @@ namespace ProxySU_Core
}); });
} }
private void DoUploadCert(object sender, CancelEventArgs e)
{
Task.Factory.StartNew(() =>
{
var file = sender as OpenFileDialog;
using (var stream = file.OpenFile())
{
project.UploadCert(stream);
}
});
}
private void OpenLink(object sender, RoutedEventArgs e) private void OpenLink(object sender, RoutedEventArgs e)
{ {
Hyperlink link = sender as Hyperlink; Hyperlink link = sender as Hyperlink;