1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-29 00:26:09 +03:00

修改v2ray客户端配置文件生成方式

This commit is contained in:
ProxySU 2020-03-28 14:13:25 +08:00
parent 6b4fed0592
commit 02b6b478ac
6 changed files with 163 additions and 23 deletions

View File

@ -115,6 +115,7 @@
<Button Content="测试结果窗口" Grid.Column="0" Grid.Row="1" Margin="10" Click="Button_Click_1"></Button>
<Button Content="测试ssh命令" Grid.Column="1" Grid.Row="0" Margin="10" Click="Button_Click_2"></Button>
<Button Content="测试生成v2rayN导入格式" Grid.Column="2" Grid.Row="0" Margin="10" Click="Button_Click_3"></Button>
<Button Content="测试生成config.json文件" Grid.Column="1" Grid.Row="1" Margin="10" Click="Button_Click_4"></Button>
</Grid>
</TabItem>
</TabControl>

View File

@ -585,15 +585,46 @@ namespace ProxySU
currentStatus = "生成客户端配置......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
upLoadPath = "/tmp/config.json";
UploadConfig(connectionInfo, clientConfig, upLoadPath);
if (!Directory.Exists("config"))//如果不存在就创建file文件夹     
{
Directory.CreateDirectory("config");//创建该文件夹  
}
//string clientConfig = "TemplateConfg\\tcp_client_config.json";
using (StreamReader reader = File.OpenText(clientConfig))
{
JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
// do stuff
//MessageBox.Show(clientJson.ToString());
clientJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4];
clientJson["outbounds"][0]["settings"]["vnext"][0]["port"] = ReceiveConfigurationParameters[1];
clientJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2];
if (clientJson.Property("path") != null)
{
//成员path存在
clientJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3];
client.RunCommand("sed -i 's/##port##/" + ReceiveConfigurationParameters[1] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##uuid##/" + ReceiveConfigurationParameters[2] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
DownloadConfig(connectionInfo, "config\\config.json", upLoadPath);
}
if (clientJson.Property("type") != null)
{
//成员type存在
clientJson["outbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5];
}
using (StreamWriter sw = new StreamWriter(@"config\config.json"))
{
sw.Write(clientJson.ToString());
}
}
//upLoadPath = "/tmp/config.json";
//UploadConfig(connectionInfo, clientConfig, upLoadPath);
//client.RunCommand("sed -i 's/##port##/" + ReceiveConfigurationParameters[1] + "/' " + upLoadPath);
//client.RunCommand("sed -i 's/##uuid##/" + ReceiveConfigurationParameters[2] + "/' " + upLoadPath);
//client.RunCommand("sed -i 's/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath);
//client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath);
//client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
//DownloadConfig(connectionInfo, "config.json", upLoadPath);
client.Disconnect();
@ -870,6 +901,41 @@ namespace ProxySU
//MessageBox.Show(v2rayNjsonObject["v"].ToString());
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
if (!Directory.Exists("config"))//如果不存在就创建file文件夹     
{
Directory.CreateDirectory("config");//创建该文件夹  
}
string clientConfig= "TemplateConfg\\tcp_client_config.json";
using (StreamReader reader = File.OpenText(clientConfig))
{
JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
// do stuff
MessageBox.Show(clientJson.ToString());
clientJson["outbounds"][0]["settings"]["vnext"][0]["address"] = ReceiveConfigurationParameters[4];
clientJson["outbounds"][0]["settings"]["vnext"][0]["port"] = ReceiveConfigurationParameters[1];
clientJson["outbounds"][0]["settings"]["vnext"][0]["users"][0]["id"] = ReceiveConfigurationParameters[2];
if (clientJson.Property("path") != null)
{
//成员path存在
clientJson["outbounds"][0]["streamSettings"]["wsSettings"]["path"] = ReceiveConfigurationParameters[3];
}
if (clientJson.Property("type") != null)
{
//成员type存在
clientJson["outbounds"][0]["streamSettings"]["kcpSettings"]["header"]["type"] = ReceiveConfigurationParameters[5];
}
using (StreamWriter sw = new StreamWriter(@"config\config.json"))
{
sw.Write(clientJson.ToString());
}
}
}
}
}

View File

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProxySU"
mc:Ignorable="d"
Title="ResultClientInformation" Height="400" Width="600">
Title="ResultClientInformation" Height="650" Width="600">
<Grid>
<GroupBox Header="服务器连接配置">
<Grid>
@ -26,6 +26,13 @@
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="地址(address)" Grid.Column="0" Grid.Row="0" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxHostAddress" IsReadOnly="True" Grid.Column="1" Grid.Row="0" Margin="8"></TextBox>
@ -48,14 +55,26 @@
<TextBlock Text="伪装类型" Grid.Column="0" Grid.Row="6" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxCamouflageType" IsReadOnly="True" Grid.Column="1" Grid.Row="6" Margin="8"></TextBox>
<TextBlock Text="说明" Grid.Column="2" Grid.Row="6"></TextBlock>
<TextBlock x:Name="TextBlockPath" Text="路径(Path)" Grid.Column="0" Grid.Row="7" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxPath" IsReadOnly="True" Grid.Column="1" Grid.Row="7" Margin="8"></TextBox>
<TextBlock x:Name="TextBlockPathExplain" Text="说明" Grid.Column="2" Grid.Row="7"></TextBlock>
<TextBlock x:Name="TextBlocTLSonOrNo" Text="是否使用TLS" Grid.Column="0" Grid.Row="8" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxTLS" IsReadOnly="True" Grid.Column="1" Grid.Row="8" Margin="8"></TextBox>
<TextBlock x:Name="TextBlocTLSonOrNoExplain" Text="说明" Grid.Column="2" Grid.Row="8"></TextBlock>
<TextBlock x:Name="TextBlocTLSonOrNo" Text="是否使用TLS" Grid.Column="0" Grid.Row="7" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxTLS" IsReadOnly="True" Grid.Column="1" Grid.Row="7" Margin="8"></TextBox>
<TextBlock x:Name="TextBlocTLSonOrNoExplain" Text="说明" Grid.Column="2" Grid.Row="7"></TextBlock>
<TextBlock x:Name="TextBlockPath" Text="路径(Path)" Grid.Column="0" Grid.Row="8" Margin="8"></TextBlock>
<TextBox x:Name="TextBoxPath" IsReadOnly="True" Grid.Column="1" Grid.Row="8" Margin="8"></TextBox>
<TextBlock x:Name="TextBlockPathExplain" Text="说明" Grid.Column="2" Grid.Row="8"></TextBlock>
<TextBlock Text="以上参数可以手动输入客户端用于V2ray官方客户端的配置文件已经存放入config目录下点击确定可打开" Grid.Column="0" Grid.Row="9" Grid.ColumnSpan="2" TextWrapping="Wrap"></TextBlock>
<Button Content="确定" Grid.Column="2" Grid.Row="9" Grid.RowSpan="2" Margin="20" Click="Button_Click"></Button>
<Grid Grid.Column="0" Grid.Row="11" Grid.ColumnSpan="2" Grid.RowSpan="7">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="85"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="二维码和vmess链接可用于&#x0a;&#x0a;v2rayN(windows)&#x0a;&#x0a;Shadowrocket(ios)&#x0a;&#x0a;v2rayNG(Android)&#x0a;&#x0a;导入v2ray节点" TextWrapping="Wrap" Grid.Column="0"></TextBlock>
<Image x:Name="ImageShareQRcode" Grid.Column="1"></Image>
</Grid>
</Grid>
<TextBox x:Name="TextBoxvVmessUrl" TextWrapping="Wrap" Grid.Column="2" Grid.Row="11" Grid.RowSpan="7"></TextBox>
</Grid>
</GroupBox>

View File

@ -26,6 +26,7 @@ namespace ProxySU
/// </summary>
public partial class ResultClientInformation : Window
{
private string saveFileFolder = "";
public ResultClientInformation()
{
InitializeComponent();
@ -121,8 +122,12 @@ namespace ProxySU
TextBoxTLS.Text = "none";
HidePathAndTLS();
}
GenerateV2rayNshareQRcodeAndBase64Url();
CheckDir("config");
//if (!Directory.Exists("config"))//如果不存在就创建file文件夹     
//{
// Directory.CreateDirectory("config");//创建该文件夹  
//}
GenerateV2rayShareQRcodeAndBase64Url();
}
private void HidePathAndTLS()
@ -144,7 +149,7 @@ namespace ProxySU
//TextBlocTLSonOrNoExplain.Visibility = Visibility.Visible;
}
//生成v2rayN客户端导入文件
private void GenerateV2rayNshareQRcodeAndBase64Url()
private void GenerateV2rayShareQRcodeAndBase64Url()
{
//生成v2rayN的json文件
string v2rayNjsonFile = @"
@ -176,16 +181,45 @@ namespace ProxySU
v2rayNjsonObject["ps"] = v2rayNjsonObject["add"]; //设置备注
//MessageBox.Show(v2rayNjsonObject["v"].ToString());
MessageBox.Show(v2rayNjsonObject.ToString());
saveFileFolder = v2rayNjsonObject["ps"].ToString();
CheckDir(@"config\" + saveFileFolder);
//MessageBox.Show(v2rayNjsonObject.ToString());
string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString());
using (StreamWriter sw = new StreamWriter(@"config\v2rayNvmessUrl.txt"))
TextBoxvVmessUrl.Text = vmessUrl;
using (StreamWriter sw = new StreamWriter($"config\\{saveFileFolder}\\url.txt"))
{
sw.WriteLine(vmessUrl);
}
CreateQRCode(vmessUrl);
if (File.Exists(@"config\config.json"))
{
File.Move(@"config\config.json", @"config\" + saveFileFolder + @"\config.json");
//File.Delete(@"config\config.json");//删除该文件
}
using (StreamWriter sw = new StreamWriter($"config\\{saveFileFolder}\\说明.txt"))
{
sw.WriteLine("config.json");
sw.WriteLine("此文件为v2ray官方程序所使用的客户端配置文件配置为全局模式socks5地址127.0.0.1:1080http代理地址127.0.0.1:1081");
sw.WriteLine("v2ray官方网站https://www.v2ray.com/");
sw.WriteLine("v2ray官方程序下载地址https://github.com/v2ray/v2ray-core/releases");
sw.WriteLine("下载相应版本Windows选择v2ray-windows-64.zip或者v2ray-windows-32.zip解压后提取v2ctl.exe和v2ray.exe。与config.json放在同一目录运行v2ray.exe即可。");
sw.WriteLine("-----------------------------------------");
sw.WriteLine("QR.bmp");
sw.WriteLine("此文件为v2rayN、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点");
sw.WriteLine("v2rayN下载网址https://github.com/2dust/v2rayN/releases");
sw.WriteLine("v2rayNG(Android)下载网址https://github.com/2dust/v2rayNG/releases");
sw.WriteLine("v2rayNG(Android)在Google Play下载网址https://play.google.com/store/apps/details?id=com.v2ray.ang");
sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。");
sw.WriteLine("-----------------------------------------");
sw.WriteLine("url.txt");
sw.WriteLine("此文件为v2rayN、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址");
}
}
//生成base64
@ -207,8 +241,28 @@ namespace ProxySU
QRCodeData qrCodeData = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);
qrCodeImage.Save(@"config\v2rayN.bmp");
IntPtr myImagePtr = qrCodeImage.GetHbitmap();
BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
ImageShareQRcode.Source = imgsource;
//DeleteObject(myImagePtr);
qrCodeImage.Save($"config\\{saveFileFolder}\\QR.bmp");
//ImageShareQRcode.Source = @"config\v2rayN.bmp";
}
//判断目录是否存在,不存在则创建
public static bool CheckDir(string folder)
{
try
{
if (!Directory.Exists(folder))//如果不存在就创建file文件夹     
Directory.CreateDirectory(folder);//创建该文件夹  
return true;
}
catch (Exception ex)
{
return false;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string openFolderPath = @"config";

Binary file not shown.

Binary file not shown.