Skip to content

Commit 8e02622

Browse files
committed
添加V2ray版本升级功能
1 parent d746ce5 commit 8e02622

File tree

3 files changed

+177
-2
lines changed

3 files changed

+177
-2
lines changed

ProxySU/MainWindow.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@
117117
<RowDefinition></RowDefinition>
118118
<RowDefinition></RowDefinition>
119119
<RowDefinition></RowDefinition>
120-
121120
</Grid.RowDefinitions>
121+
<Button x:Name="ButtonUpdateV2ray" Content="检测/升级V2Ray版本" Grid.Column="0" Grid.Row="0" Margin="5" Click="ButtonUpdateV2ray_Click"></Button>
122122
<!--<Button x:Name="ButtonGuideConfiguration" Visibility="Visible" Content="启用向导" Grid.Column="0" Grid.Row="0" Click="ButtonGuideConfiguration_Click"></Button>
123123
<TextBlock Text="通过向导生成配置文件" Visibility="Visible" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>-->
124124
<Button x:Name="ButtonTemplateConfiguration" Content="模板库" Grid.Column="1" Grid.Row="0" Margin="5" Click="ButtonTemplateConfiguration_Click"></Button>
125-
<TextBlock Text="模板库" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>
125+
<!--<TextBlock Text="模板库" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>-->
126126
<!--<Button x:Name="ButtonAdvancedConfiguration" Visibility="Visible" Content="配置编辑器" Grid.Column="2" Grid.Row="0" Click="ButtonAdvancedConfiguration_Click"></Button>
127127
<TextBlock Text="配置文件高级生成器&#x0a;(有经验用户可以使用)" Visibility="Visible" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>-->
128128
<!--<RadioButton x:Name="RadioButtonGuideConfiguration" Content="向导生成配置" Grid.Column="0" Grid.Row="0"></RadioButton>

ProxySU/MainWindow.xaml.cs

+175
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,181 @@ private static bool DetectKernelVersionBBR(string kernelVer)
25892589
}
25902590
return false;
25912591

2592+
}
2593+
//检测升级远程主机端的V2Ray版本
2594+
private void ButtonUpdateV2ray_Click(object sender, RoutedEventArgs e)
2595+
{
2596+
ConnectionInfo connectionInfo = GenerateConnectionInfo();
2597+
if (connectionInfo == null)
2598+
{
2599+
MessageBox.Show("远程主机连接信息有误,请检查");
2600+
return;
2601+
}
2602+
2603+
Thread thread = new Thread(() => UpdateV2ray(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing));
2604+
thread.SetApartmentState(ApartmentState.STA);
2605+
thread.Start();
2606+
}
2607+
2608+
private void UpdateV2ray(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar)
2609+
{
2610+
string currentStatus = "正在登录远程主机......";
2611+
Action<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(UpdateTextBlock);
2612+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2613+
2614+
try
2615+
{
2616+
#region 主机指纹,暂未启用
2617+
//byte[] expectedFingerPrint = new byte[] {
2618+
// 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31,
2619+
// 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b
2620+
// };
2621+
#endregion
2622+
using (var client = new SshClient(connectionInfo))
2623+
2624+
{
2625+
#region ssh登录验证主机指纹代码块,暂未启用
2626+
// client.HostKeyReceived += (sender, e) =>
2627+
// {
2628+
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
2629+
// {
2630+
// for (var i = 0; i < expectedFingerPrint.Length; i++)
2631+
// {
2632+
// if (expectedFingerPrint[i] != e.FingerPrint[i])
2633+
// {
2634+
// e.CanTrust = false;
2635+
// break;
2636+
// }
2637+
// }
2638+
// }
2639+
// else
2640+
// {
2641+
// e.CanTrust = false;
2642+
// }
2643+
// };
2644+
#endregion
2645+
2646+
client.Connect();
2647+
if (client.IsConnected == true)
2648+
{
2649+
currentStatus = "主机登录成功";
2650+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2651+
Thread.Sleep(1000);
2652+
}
2653+
//检测远程主机V2ray版本
2654+
currentStatus = "检测远程主机V2ray版本......";
2655+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2656+
Thread.Sleep(1000);
2657+
2658+
string cmdTestV2rayInstalled = @"find / -name v2ray";
2659+
//MessageBox.Show(cmdTestV2rayInstalled);
2660+
string resultCmdTestV2rayInstalled = client.RunCommand(cmdTestV2rayInstalled).Result;
2661+
//client.Disconnect();
2662+
//MessageBox.Show(resultCmdTestV2rayInstalled);
2663+
if (resultCmdTestV2rayInstalled.Contains("/usr/bin/v2ray") == false)
2664+
{
2665+
MessageBoxResult messageBoxResult = MessageBox.Show("远程主机未安装V2ray!");
2666+
2667+
currentStatus = "未安装V2ray,退出";
2668+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2669+
Thread.Sleep(1000);
2670+
return;
2671+
2672+
}
2673+
string sshcmd;
2674+
sshcmd = @"/usr/bin/v2ray/v2ray -version | head -n 1 | cut -d "" "" -f2";
2675+
//MessageBox.Show(sshcmd);
2676+
string v2rayCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v
2677+
//MessageBox.Show(v2rayCurrentVersion);
2678+
2679+
sshcmd = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2ray/v2ray-core/releases/latest"" --connect-timeout 10| grep 'tag_name' | cut -d\"" -f4";
2680+
//MessageBox.Show(sshcmd);
2681+
//client.RunCommand($"echo {sshcmd} >cmd.txt");
2682+
string v2rayNewVersion = client.RunCommand(sshcmd).Result;//包含字母v
2683+
//MessageBox.Show(v2rayNewVersion);
2684+
if (v2rayNewVersion.Contains(v2rayCurrentVersion)==false)
2685+
{
2686+
MessageBoxResult messageBoxResult = MessageBox.Show($"远程主机当前版本为:v{v2rayCurrentVersion}\n最新版本为:{v2rayNewVersion}\n是否升级为最新版本?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);
2687+
if (messageBoxResult == MessageBoxResult.No)
2688+
{
2689+
currentStatus = "升级取消,退出";
2690+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2691+
Thread.Sleep(1000);
2692+
return;
2693+
}
2694+
else
2695+
{
2696+
currentStatus = "正在升级V2ray到最新版本......";
2697+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2698+
Thread.Sleep(1000);
2699+
client.RunCommand(@"bash <(curl -L -s https://install.direct/go.sh)");
2700+
sshcmd = @"/usr/bin/v2ray/v2ray -version | head -n 1 | cut -d "" "" -f2";
2701+
//MessageBox.Show(sshcmd);
2702+
v2rayCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v
2703+
if (v2rayNewVersion.Contains(v2rayCurrentVersion) == true)
2704+
{
2705+
MessageBox.Show($"升级成功!!\n当前版本为:v{v2rayCurrentVersion}\n最新版本为:{v2rayNewVersion}");
2706+
currentStatus = "升级成功!当前已是最新版本!";
2707+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2708+
Thread.Sleep(1000);
2709+
}
2710+
else
2711+
{
2712+
MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!");
2713+
currentStatus = "升级失败!";
2714+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2715+
Thread.Sleep(1000);
2716+
}
2717+
}
2718+
}
2719+
else
2720+
{
2721+
MessageBox.Show($"远程主机当前已是最新版本:{v2rayNewVersion}\n无需升级!");
2722+
currentStatus = "已是最新版本,无需升级,退出";
2723+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2724+
Thread.Sleep(1000);
2725+
}
2726+
2727+
client.Disconnect();
2728+
return;
2729+
}
2730+
}
2731+
catch (Exception ex1)//例外处理
2732+
#region 例外处理
2733+
{
2734+
//MessageBox.Show(ex1.Message);
2735+
if (ex1.Message.Contains("连接尝试失败") == true)
2736+
{
2737+
MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作");
2738+
}
2739+
2740+
else if (ex1.Message.Contains("denied (password)") == true)
2741+
{
2742+
MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误");
2743+
}
2744+
else if (ex1.Message.Contains("Invalid private key file") == true)
2745+
{
2746+
MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对");
2747+
}
2748+
else if (ex1.Message.Contains("denied (publickey)") == true)
2749+
{
2750+
MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误");
2751+
}
2752+
else if (ex1.Message.Contains("目标计算机积极拒绝") == true)
2753+
{
2754+
MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误");
2755+
}
2756+
else
2757+
{
2758+
MessageBox.Show("发生错误");
2759+
MessageBox.Show(ex1.Message);
2760+
}
2761+
currentStatus = "主机登录失败";
2762+
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
2763+
2764+
}
2765+
#endregion
2766+
25922767
}
25932768
//private void ButtonTestTrojanClientInfoWin_Click(object sender, RoutedEventArgs e)
25942769
//{

ProxySU/bin/Beta/Beta.zip

782 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)