mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-25 06:36:08 +03:00
添加域名检测,打开防火墙端口(目前仅限于CentOS7)
This commit is contained in:
parent
b78d14058e
commit
05c5c37cd3
@ -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="配置文件高级生成器
(有经验用户可以使用)" Visibility="Collapsed" Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Center"></TextBlock>
|
<TextBlock Text="配置文件高级生成器
(有经验用户可以使用)" 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>
|
||||||
|
@ -438,12 +438,38 @@ namespace ProxySU
|
|||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
//如果使用如果是WebSocket + TLS + Web模式,需要检测域名解析是否正确
|
||||||
|
if (appConfig.Contains("WebSocketTLSWeb") == true)
|
||||||
{
|
{
|
||||||
currentStatus = "符合安装要求,布署中......";
|
currentStatus = "使用WebSocket + TLS + Web模式,正在检测域名是否解析到当前VPS的IP上......";
|
||||||
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
//Thread.Sleep(2000);
|
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
|
||||||
|
{
|
||||||
|
currentStatus = "域名未能正确解析到当前VPS的IP上!";
|
||||||
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
MessageBox.Show("域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentStatus = "符合安装要求,布署中......";
|
||||||
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
|
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,7 +518,64 @@ 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");
|
||||||
|
|
||||||
|
//如果是WebSocket + TLS + Web模式,需要安装Caddy
|
||||||
|
if (appConfig.Contains("WebSocketTLSWeb")==true)
|
||||||
|
{
|
||||||
|
currentStatus = "使用WebSocket + TLS + Web模式,正在安装Caddy......";
|
||||||
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
client.RunCommand("curl https://getcaddy.com -o getcaddy");
|
||||||
|
client.RunCommand("bash getcaddy personal hook.service");
|
||||||
|
client.RunCommand("mkdir -p /etc/caddy");
|
||||||
|
client.RunCommand("mkdir -p /var/www");
|
||||||
|
|
||||||
|
|
||||||
|
//currentStatus = "上传Caddy配置文件......";
|
||||||
|
//textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
|
//Thread.Sleep(1000);
|
||||||
|
appConfig = "TemplateConfg\\WebSocketTLSWeb_server_config.caddyfile";
|
||||||
|
upLoadPath = "/etc/caddy/Caddyfile";
|
||||||
|
UploadConfig(connectionInfo, appConfig, upLoadPath);
|
||||||
|
//string[] splitDomain = ReceiveConfigurationParameters[4].Split('.');
|
||||||
|
|
||||||
|
//设置Caddyfile文件中的tls 邮箱
|
||||||
|
string emailAddress = ReceiveConfigurationParameters[4];
|
||||||
|
string sshCmd = $"email={emailAddress};email=${{email/./@}};sed -i \"s/off/${{email:=\"off\"}}/\" /etc/caddy/Caddyfile";
|
||||||
|
client.RunCommand(sshCmd);
|
||||||
|
client.RunCommand("sed -i 's/##path##/\\" + ReceiveConfigurationParameters[3] + "/' " + upLoadPath);
|
||||||
|
client.RunCommand("sed -i 's/##domain##/" + ReceiveConfigurationParameters[4] + "/' " + upLoadPath);
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
|
//生成安装服务命令中的邮箱
|
||||||
|
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 = "生成客户端配置......";
|
currentStatus = "生成客户端配置......";
|
||||||
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
@ -507,61 +590,6 @@ namespace ProxySU
|
|||||||
client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
|
client.RunCommand("sed -i 's/##mkcpHeaderType##/" + ReceiveConfigurationParameters[5] + "/' " + upLoadPath);
|
||||||
DownloadConfig(connectionInfo, "config\\config.json", upLoadPath);
|
DownloadConfig(connectionInfo, "config\\config.json", upLoadPath);
|
||||||
|
|
||||||
//如果是WebSocket + TLS + Web模式,需要安装Caddy
|
|
||||||
if (appConfig.Contains("WebSocketTLSWeb")==true)
|
|
||||||
{
|
|
||||||
currentStatus = "使用WebSocket + TLS + Web模式,正在安装Caddy......";
|
|
||||||
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
|
|
||||||
client.RunCommand("curl https://getcaddy.com -o getcaddy");
|
|
||||||
client.RunCommand("bash getcaddy personal hook.service");
|
|
||||||
client.RunCommand("mkdir -p /etc/caddy");
|
|
||||||
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配置文件......";
|
|
||||||
//textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
|
||||||
//Thread.Sleep(1000);
|
|
||||||
appConfig = "TemplateConfg\\WebSocketTLSWeb_server_config.caddyfile";
|
|
||||||
upLoadPath = "/etc/caddy/Caddyfile";
|
|
||||||
UploadConfig(connectionInfo, appConfig, upLoadPath);
|
|
||||||
//string[] splitDomain = ReceiveConfigurationParameters[4].Split('.');
|
|
||||||
|
|
||||||
string emailAddress = ReceiveConfigurationParameters[4];
|
|
||||||
emailAddress = client.RunCommand("${"+ emailAddress+"/./@}").Result.ToString();
|
|
||||||
|
|
||||||
//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/##email##/${" + emailAddress + ":=\"off\"}/' " + upLoadPath);
|
|
||||||
//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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
|
|
||||||
currentStatus = "安装成功";
|
currentStatus = "安装成功";
|
||||||
@ -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("尚未完善,敬请期待");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,14 @@ 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";
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (RadioButtonTCPhttp.IsChecked == true)
|
else if (RadioButtonTCPhttp.IsChecked == true)
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user