1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-25 14:46:08 +03:00

添加域名检测,打开防火墙端口(目前仅限于CentOS7)

This commit is contained in:
ProxySU 2020-03-23 15:00:56 +08:00
parent b78d14058e
commit 05c5c37cd3
5 changed files with 132 additions and 64 deletions

View File

@ -86,12 +86,12 @@
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button x:Name="ButtonGuideConfiguration" Visibility="Collapsed" Content="启用向导" Grid.Column="0" Grid.Row="0"></Button> <Button x:Name="ButtonGuideConfiguration" Visibility="Visible" Content="启用向导" Grid.Column="0" Grid.Row="0" Click="ButtonGuideConfiguration_Click"></Button>
<TextBlock Text="通过向导生成配置文件" Visibility="Collapsed" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock> <TextBlock Text="通过向导生成配置文件" Visibility="Visible" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>
<Button x:Name="ButtonTemplateConfiguration" Content="打开模板库" Grid.Column="1" Grid.Row="0" Click="ButtonTemplateConfiguration_Click"></Button> <Button x:Name="ButtonTemplateConfiguration" Content="打开模板库" Grid.Column="1" Grid.Row="0" Click="ButtonTemplateConfiguration_Click"></Button>
<TextBlock Text="模板库" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock> <TextBlock Text="模板库" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>
<Button x:Name="ButtonAdvancedConfiguration" Visibility="Collapsed" Content="配置编辑器" Grid.Column="2" Grid.Row="0"></Button> <Button x:Name="ButtonAdvancedConfiguration" Visibility="Visible" Content="配置编辑器" Grid.Column="2" Grid.Row="0" Click="ButtonAdvancedConfiguration_Click"></Button>
<TextBlock Text="配置文件高级生成器&#x0a;(有经验用户可以使用)" Visibility="Collapsed" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock> <TextBlock Text="配置文件高级生成器&#x0a;(有经验用户可以使用)" Visibility="Visible" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>
<!--<RadioButton x:Name="RadioButtonGuideConfiguration" Content="向导生成配置" Grid.Column="0" Grid.Row="0"></RadioButton> <!--<RadioButton x:Name="RadioButtonGuideConfiguration" Content="向导生成配置" Grid.Column="0" Grid.Row="0"></RadioButton>
<RadioButton x:Name="RadioButtonTemplateConfiguration" Content="模板配置" Grid.Column="0" Grid.Row="1"></RadioButton> <RadioButton x:Name="RadioButtonTemplateConfiguration" Content="模板配置" Grid.Column="0" Grid.Row="1"></RadioButton>
<RadioButton x:Name="RadioButtonAdvancedConfiguration" Content="高级配置" Grid.Column="0" Grid.Row="2"></RadioButton> <RadioButton x:Name="RadioButtonAdvancedConfiguration" Content="高级配置" Grid.Column="0" Grid.Row="2"></RadioButton>
@ -99,7 +99,7 @@
<Button x:Name="ButtonSetConfiguration" Margin="6" Content="配置" Grid.Column="2" Grid.Row="2" Click="ButtonSetConfiguration_Click"></Button>--> <Button x:Name="ButtonSetConfiguration" Margin="6" Content="配置" Grid.Column="2" Grid.Row="2" Click="ButtonSetConfiguration_Click"></Button>-->
</Grid> </Grid>
</TabItem> </TabItem>
<TabItem Header="BBR设置" Visibility="Collapsed" Width="150" Height="30"> <TabItem Header="测试面板" Visibility="Visible" Width="150" Height="30">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition>
@ -111,6 +111,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Content="测试接收到的模参数" Grid.Column="0" Grid.Row="0" Margin="10" Click="Button_Click"></Button> <Button Content="测试接收到的模参数" Grid.Column="0" Grid.Row="0" Margin="10" Click="Button_Click"></Button>
<Button Content="测试结果窗口" Grid.Column="0" Grid.Row="1" Margin="10" Click="Button_Click_1"></Button> <Button Content="测试结果窗口" Grid.Column="0" Grid.Row="1" Margin="10" Click="Button_Click_1"></Button>
<Button Content="测试ssh命令" Grid.Column="1" Grid.Row="0" Click="Button_Click_2"></Button>
</Grid> </Grid>
</TabItem> </TabItem>
</TabControl> </TabControl>

View File

@ -438,12 +438,38 @@ namespace ProxySU
Thread.Sleep(1000); Thread.Sleep(1000);
return; return;
} }
//如果使用如果是WebSocket + TLS + Web模式需要检测域名解析是否正确
if (appConfig.Contains("WebSocketTLSWeb") == true)
{
currentStatus = "使用WebSocket + TLS + Web模式正在检测域名是否解析到当前VPS的IP上......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString();
string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\"";
string resultCmd = client.RunCommand(testDomainCmd).Result.ToString();
//MessageBox.Show("nativeIp"+nativeIp);
//MessageBox.Show("resultCmd"+ resultCmd);
if (String.Equals(nativeIp, resultCmd) == true)
{
currentStatus = "解析正确!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
else else
{ {
currentStatus = "域名未能正确解析到当前VPS的IP上!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
MessageBox.Show("域名未能正确解析到当前VPS的IP上请检查若解析设置正确请等待生效后再重试安装。如果域名使用了CDN请先关闭");
return;
}
}
currentStatus = "符合安装要求,布署中......"; currentStatus = "符合安装要求,布署中......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
//Thread.Sleep(2000); Thread.Sleep(1000);
}
//在相应系统内安装curl(如果没有安装curl) //在相应系统内安装curl(如果没有安装curl)
if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true) if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true)
{ {
@ -492,20 +518,7 @@ namespace ProxySU
client.RunCommand("sed -i 's/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath); client.RunCommand("sed -i 's/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath);
//client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath); //client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath); client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
client.RunCommand("systemctl restart v2ray");
//生成客户端配置
currentStatus = "生成客户端配置......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
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\\config.json", upLoadPath);
//如果是WebSocket + TLS + Web模式需要安装Caddy //如果是WebSocket + TLS + Web模式需要安装Caddy
if (appConfig.Contains("WebSocketTLSWeb")==true) if (appConfig.Contains("WebSocketTLSWeb")==true)
@ -519,27 +532,7 @@ namespace ProxySU
client.RunCommand("mkdir -p /etc/caddy"); client.RunCommand("mkdir -p /etc/caddy");
client.RunCommand("mkdir -p /var/www"); client.RunCommand("mkdir -p /var/www");
//检测domain是否正确的解析到当前的VPS
currentStatus = "正在检测域名是否解析到当前VPS的IP上......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString();
string testDomain = client.RunCommand("ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0 - 9]{ 1,3}\\.){ 3}[0-9]{1,3}\"").Result.ToString();
if (String.Equals(nativeIp, testDomain) == false)
{
currentStatus = "域名未能正确解析到当前VPS的IP上!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
MessageBox.Show("域名未能正确解析到当前VPS的IP上请检查若解析设置正确请等待生效后再重试安装");
return;
}
else
{
currentStatus = "解析正确上传Caddy配置文件......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
//currentStatus = "上传Caddy配置文件......"; //currentStatus = "上传Caddy配置文件......";
//textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
//Thread.Sleep(1000); //Thread.Sleep(1000);
@ -548,19 +541,54 @@ namespace ProxySU
UploadConfig(connectionInfo, appConfig, upLoadPath); UploadConfig(connectionInfo, appConfig, upLoadPath);
//string[] splitDomain = ReceiveConfigurationParameters[4].Split('.'); //string[] splitDomain = ReceiveConfigurationParameters[4].Split('.');
//设置Caddyfile文件中的tls 邮箱
string emailAddress = ReceiveConfigurationParameters[4]; string emailAddress = ReceiveConfigurationParameters[4];
emailAddress = client.RunCommand("${"+ emailAddress+"/./@}").Result.ToString(); string sshCmd = $"email={emailAddress};email=${{email/./@}};sed -i \"s/off/${{email:=\"off\"}}/\" /etc/caddy/Caddyfile";
client.RunCommand(sshCmd);
//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/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath); client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath);
client.RunCommand("sed -i 's/##email##/${" + emailAddress + ":=\"off\"}/' " + upLoadPath); Thread.Sleep(2000);
//client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
client.RunCommand("caddy -service install -agree -email "+ emailAddress + " -conf /etc/caddy/Caddyfile"); //生成安装服务命令中的邮箱
client.RunCommand("caddy -service start"); string sshCmdEmail = $"email={emailAddress};email=${{email/./@}};echo $email";
string email= client.RunCommand(sshCmdEmail).Result.ToString();
//MessageBox.Show(email);
//安装Caddy服务
sshCmd = "caddy -service install -agree -conf /etc/caddy/Caddyfile -email " + email;
//MessageBox.Show(sshCmd);
client.RunCommand(sshCmd);
//打开防火墙端口
string openFireWallPort = ReceiveConfigurationParameters[1];
if (String.Equals(openFireWallPort, "443"))
{
client.RunCommand("firewall-cmd --zone=public --add-port=80/tcp --permanent");
client.RunCommand("firewall-cmd --zone=public --add-port=443/tcp --permanent");
client.RunCommand("firewall-cmd --reload");
}
else
{
client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent");
client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent");
client.RunCommand("firewall-cmd --reload");
} }
//启动Caddy服务
client.RunCommand("caddy -service start");
}
//生成客户端配置
currentStatus = "生成客户端配置......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
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\\config.json", upLoadPath);
client.Disconnect(); client.Disconnect();
@ -758,6 +786,40 @@ namespace ProxySU
ResultClientInformation resultClientInformation = new ResultClientInformation(); ResultClientInformation resultClientInformation = new ResultClientInformation();
resultClientInformation.ShowDialog(); resultClientInformation.ShowDialog();
} }
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string sshHostName = TextBoxHost.Text.ToString();
int sshPort = int.Parse(TextBoxPort.Text);
string sshUser = TextBoxUserName.Text.ToString();
string sshPassword = PasswordBoxHostPassword.Password.ToString();
ReceiveConfigurationParameters[4] = "";
//string emailAddress = ReceiveConfigurationParameters[4];
//string sshCmd;
//sshCmd = "ping "+ ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\"";
//string resultCmd;
//string upLoadPath = "/etc/caddy/Caddyfile";
var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
using (var client = new SshClient(connectionInfo))
{
//client.Connect();
//client.Disconnect();
return;
}
}
private void ButtonGuideConfiguration_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("尚未完善,敬请期待");
}
private void ButtonAdvancedConfiguration_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("尚未完善,敬请期待");
}
} }
} }

View File

@ -35,6 +35,11 @@ namespace ProxySU
} }
else if (RadioButtonWebSocketTLS2Web.IsChecked == true) else if (RadioButtonWebSocketTLS2Web.IsChecked == true)
{ {
if (string.IsNullOrEmpty(TextBoxDomain.Text.ToString()) == true)
{
MessageBox.Show("域名不能为空!");
return;
}
//传递模板类型 //传递模板类型
MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS2Web"; MainWindow.ReceiveConfigurationParameters[0] = "WebSocketTLS2Web";

Binary file not shown.

Binary file not shown.