mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-22 05:06:08 +03:00
添加模板配置文件
This commit is contained in:
parent
b0ef4c13a7
commit
bca6cc2b39
@ -30,12 +30,12 @@
|
|||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Text="主机名" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="0" Grid.Row="0"></TextBlock>
|
<TextBlock Text="主机名" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="0" Grid.Row="0"></TextBlock>
|
||||||
<TextBlock Text="端口" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="2" Grid.Row="0"></TextBlock>
|
<TextBlock Text="端口" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="2" Grid.Row="0"></TextBlock>
|
||||||
<TextBox x:Name="TextBoxHost" Text="192.168.200.200" Margin="5" Grid.Column="1" Grid.Row="0"></TextBox>
|
<TextBox x:Name="TextBoxHost" Text="" Margin="5" Grid.Column="1" Grid.Row="0"></TextBox>
|
||||||
<TextBox x:Name="TextBoxPort" CommandManager.PreviewExecuted="TextBoxPort_PreviewExecuted" Text="22" Margin="5" Grid.Column="3" Grid.Row="0" PreviewTextInput="TextBoxPort_PreviewTextInput"/>
|
<TextBox x:Name="TextBoxPort" CommandManager.PreviewExecuted="TextBoxPort_PreviewExecuted" Text="22" Margin="5" Grid.Column="3" Grid.Row="0" PreviewTextInput="TextBoxPort_PreviewTextInput"/>
|
||||||
<TextBlock Text="用户名:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="0" Grid.Row="1"></TextBlock>
|
<TextBlock Text="用户名:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="0" Grid.Row="1"></TextBlock>
|
||||||
<TextBlock x:Name="TextBlockPassword" Text="密码:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="2" Grid.Row="1"></TextBlock>
|
<TextBlock x:Name="TextBlockPassword" Text="密码:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" Grid.Column="2" Grid.Row="1"></TextBlock>
|
||||||
<TextBox x:Name="TextBoxUserName" Text="root" Margin="5" Grid.Column="1" Grid.Row="1"></TextBox>
|
<TextBox x:Name="TextBoxUserName" Text="root" Margin="5" Grid.Column="1" Grid.Row="1"></TextBox>
|
||||||
<PasswordBox x:Name="PasswordBoxHostPassword" Password="Tianlong71605" Margin="5" Grid.Column="3" Grid.Row="1"></PasswordBox>
|
<PasswordBox x:Name="PasswordBoxHostPassword" Password="" Margin="5" Grid.Column="3" Grid.Row="1"></PasswordBox>
|
||||||
<RadioButton x:Name="RadioButtonPasswordLogin" GroupName="CertIsYesNo" Content="密码登录" Grid.Column="0" Grid.Row="2" Checked="RadioButtonPasswordLogin_Checked"></RadioButton>
|
<RadioButton x:Name="RadioButtonPasswordLogin" GroupName="CertIsYesNo" Content="密码登录" Grid.Column="0" Grid.Row="2" Checked="RadioButtonPasswordLogin_Checked"></RadioButton>
|
||||||
<RadioButton x:Name="RadioButtonCertLogin" GroupName="CertIsYesNo" Content="密钥登录" Grid.Column="1" Grid.Row="2" Checked="RadioButtonCertLogin_Checked"></RadioButton>
|
<RadioButton x:Name="RadioButtonCertLogin" GroupName="CertIsYesNo" Content="密钥登录" Grid.Column="1" Grid.Row="2" Checked="RadioButtonCertLogin_Checked"></RadioButton>
|
||||||
<Button x:Name="ButtonOpenFileDialog" Content="浏览..." Margin="8" Grid.Column="2" Grid.Row="2" Click="ButtonOpenFileDialog_Click"></Button>
|
<Button x:Name="ButtonOpenFileDialog" Content="浏览..." Margin="8" Grid.Column="2" Grid.Row="2" Click="ButtonOpenFileDialog_Click"></Button>
|
||||||
@ -60,7 +60,29 @@
|
|||||||
<!--<StatusBar x:Name="StatusBarStatusMonitoring" Grid.Column="0" Grid.Row="7" Grid.ColumnSpan="4"></StatusBar>-->
|
<!--<StatusBar x:Name="StatusBarStatusMonitoring" Grid.Column="0" Grid.Row="7" Grid.ColumnSpan="4"></StatusBar>-->
|
||||||
<TextBlock x:Name="TextBlockSetUpProcessing" Text="等待安装布署" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0" Grid.Row="7" Grid.ColumnSpan="4"></TextBlock>
|
<TextBlock x:Name="TextBlockSetUpProcessing" Text="等待安装布署" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="0" Grid.Row="7" Grid.ColumnSpan="4"></TextBlock>
|
||||||
<ProgressBar x:Name="ProgressBarSetUpProcessing" Minimum="0" Maximum="100" Value="0" IsIndeterminate="False" Margin="7" Grid.Column="0" Grid.Row="8" Grid.ColumnSpan="4"></ProgressBar>
|
<ProgressBar x:Name="ProgressBarSetUpProcessing" Minimum="0" Maximum="100" Value="0" IsIndeterminate="False" Margin="7" Grid.Column="0" Grid.Row="8" Grid.ColumnSpan="4"></ProgressBar>
|
||||||
|
<TabControl Grid.Column="0" Grid.Row="9" Grid.ColumnSpan="4" Grid.RowSpan="2">
|
||||||
|
<TabItem Header="V2ray配置" Width="150" Height="30">
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition></ColumnDefinition>
|
||||||
|
<ColumnDefinition></ColumnDefinition>
|
||||||
|
<ColumnDefinition></ColumnDefinition>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition></RowDefinition>
|
||||||
|
<RowDefinition></RowDefinition>
|
||||||
|
<RowDefinition></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<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="RadioButtonAdvancedConfiguration" Content="高级配置" Grid.Column="0" Grid.Row="2"></RadioButton>
|
||||||
|
<TextBox x:Name="TextBoxJsonPath" Margin="10" Grid.Column="1" Grid.Row="1"></TextBox>
|
||||||
|
<Button x:Name="ButtonSetConfiguration" Margin="6" Content="配置" Grid.Column="2" Grid.Row="2" Click="ButtonSetConfiguration_Click"></Button>
|
||||||
|
</Grid>
|
||||||
|
</TabItem>
|
||||||
|
<TabItem Header="BBR设置" Width="150" Height="30"></TabItem>
|
||||||
|
</TabControl>
|
||||||
|
|
||||||
|
|
||||||
<Button x:Name="Button_Login" Content="布署安装" Grid.ColumnSpan="2" Margin="10" Grid.Column="0" Grid.Row="11" Click="Button_Login_Click"></Button>
|
<Button x:Name="Button_Login" Content="布署安装" Grid.ColumnSpan="2" Margin="10" Grid.Column="0" Grid.Row="11" Click="Button_Login_Click"></Button>
|
||||||
<Button x:Name="Button_canel" Content="取消" Grid.ColumnSpan="2" Margin="10" Grid.Column="2" Grid.Row="11" Click="Button_canel_Click"></Button>
|
<Button x:Name="Button_canel" Content="取消" Grid.ColumnSpan="2" Margin="10" Grid.Column="2" Grid.Row="11" Click="Button_canel_Click"></Button>
|
||||||
|
@ -30,6 +30,8 @@ namespace ProxySU
|
|||||||
RadioButtonPasswordLogin.IsChecked = true;
|
RadioButtonPasswordLogin.IsChecked = true;
|
||||||
RadioButtonNoProxy.IsChecked = true;
|
RadioButtonNoProxy.IsChecked = true;
|
||||||
RadioButtonProxyNoLogin.IsChecked = true;
|
RadioButtonProxyNoLogin.IsChecked = true;
|
||||||
|
//GuideConfiguration.IsChecked = true;
|
||||||
|
RadioButtonTemplateConfiguration.IsChecked = true;
|
||||||
}
|
}
|
||||||
//System.Diagnostics.Process exitProgram = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id);
|
//System.Diagnostics.Process exitProgram = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id);
|
||||||
private void Button_Login_Click(object sender, RoutedEventArgs e)
|
private void Button_Login_Click(object sender, RoutedEventArgs e)
|
||||||
@ -102,12 +104,25 @@ namespace ProxySU
|
|||||||
//ProgressBarSetUpProcessing.IsIndeterminate = true;
|
//ProgressBarSetUpProcessing.IsIndeterminate = true;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// try
|
|
||||||
//{
|
|
||||||
|
|
||||||
//var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
|
//var connectionInfo = new PasswordConnectionInfo(sshHostName, sshPort, sshUser, sshPassword);
|
||||||
|
|
||||||
var connectionInfo = new ConnectionInfo(
|
var connectionInfo = new ConnectionInfo(
|
||||||
|
sshHostName,
|
||||||
|
sshPort,
|
||||||
|
sshUser,
|
||||||
|
proxyTypes,
|
||||||
|
sshProxyHost,
|
||||||
|
sshProxyPort,
|
||||||
|
sshProxyUser,
|
||||||
|
sshProxyPassword,
|
||||||
|
new PasswordAuthenticationMethod(sshUser, sshPassword)
|
||||||
|
//new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (RadioButtonCertLogin.IsChecked == true)
|
||||||
|
{
|
||||||
|
connectionInfo = new ConnectionInfo(
|
||||||
sshHostName,
|
sshHostName,
|
||||||
sshPort,
|
sshPort,
|
||||||
sshUser,
|
sshUser,
|
||||||
@ -116,31 +131,17 @@ namespace ProxySU
|
|||||||
sshProxyPort,
|
sshProxyPort,
|
||||||
sshProxyUser,
|
sshProxyUser,
|
||||||
sshProxyPassword,
|
sshProxyPassword,
|
||||||
new PasswordAuthenticationMethod(sshUser, sshPassword)
|
//new PasswordAuthenticationMethod(sshUser, sshPassword)
|
||||||
//new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (RadioButtonCertLogin.IsChecked == true)
|
}
|
||||||
{
|
|
||||||
connectionInfo = new ConnectionInfo(
|
|
||||||
sshHostName,
|
|
||||||
sshPort,
|
|
||||||
sshUser,
|
|
||||||
proxyTypes,
|
|
||||||
sshProxyHost,
|
|
||||||
sshProxyPort,
|
|
||||||
sshProxyUser,
|
|
||||||
sshProxyPassword,
|
|
||||||
//new PasswordAuthenticationMethod(sshUser, sshPassword)
|
|
||||||
new PrivateKeyAuthenticationMethod(sshUser, new PrivateKeyFile(sshPrivateKey))
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
//using (var client = new SshClient(sshHostName, sshPort, sshUser, sshPassword))
|
||||||
|
//Action<ConnectionInfo, TextBlock> startSetUpAction = new Action<ConnectionInfo, TextBlock>(StartSetUpRemoteHost);
|
||||||
//using (var client = new SshClient(sshHostName, sshPort, sshUser, sshPassword))
|
string appConfig = TextBoxJsonPath.Text.ToString().Replace("\\","\\\\");
|
||||||
//Action<ConnectionInfo, TextBlock> startSetUpAction = new Action<ConnectionInfo, TextBlock>(StartSetUpRemoteHost);
|
Task task = new Task(() => StartSetUpRemoteHost(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing, appConfig));
|
||||||
Task task = new Task(() => StartSetUpRemoteHost(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing));
|
task.Start();
|
||||||
task.Start();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -327,7 +328,7 @@ namespace ProxySU
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//登录远程主机布署程序
|
//登录远程主机布署程序
|
||||||
private void StartSetUpRemoteHost(ConnectionInfo connectionInfo,TextBlock textBlockName, ProgressBar progressBar)
|
private void StartSetUpRemoteHost(ConnectionInfo connectionInfo,TextBlock textBlockName, ProgressBar progressBar, string appConfig)
|
||||||
{
|
{
|
||||||
string currentStatus = "正在登录远程主机......";
|
string currentStatus = "正在登录远程主机......";
|
||||||
Action<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(UpdateTextBlock);
|
Action<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(UpdateTextBlock);
|
||||||
@ -440,39 +441,26 @@ namespace ProxySU
|
|||||||
|
|
||||||
client.RunCommand("curl -o /tmp/go.sh https://install.direct/go.sh");
|
client.RunCommand("curl -o /tmp/go.sh https://install.direct/go.sh");
|
||||||
client.RunCommand("bash /tmp/go.sh");
|
client.RunCommand("bash /tmp/go.sh");
|
||||||
client.RunCommand("move /etc/v2ray/config.json /etc/v2ray/config.json.1");
|
client.RunCommand("mv /etc/v2ray/config.json /etc/v2ray/config.json.1");
|
||||||
|
|
||||||
|
//client.RunCommand("echo 1111 >> test.json");
|
||||||
//上传配置文件
|
//上传配置文件
|
||||||
string v2rayConfig = "";
|
//string uploadConfig = "config\\http_server.json";
|
||||||
try
|
currentStatus = "程序安装完毕,配置文件上传中......";
|
||||||
{
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
using (var sftpClient = new SftpClient(connectionInfo))
|
Thread.Sleep(2000);
|
||||||
{
|
UploadConfig(connectionInfo, appConfig);
|
||||||
sftpClient.Connect();
|
|
||||||
//MessageBox.Show("sftp信息1" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
|
||||||
sftpClient.UploadFile(File.OpenRead(v2rayConfig), "/etc/v2ray/config.json", true);
|
|
||||||
//sftpClient.DownloadFile("/root/id_rsa.pub", File.Create("config\\server_config.json"));
|
|
||||||
MessageBox.Show("sftp信息" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
|
||||||
sftpClient.Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex2)
|
|
||||||
{
|
|
||||||
MessageBox.Show("sftp" + ex2.ToString());
|
|
||||||
MessageBox.Show("sftp出现未知错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
client.RunCommand("echo 1111 >> test.json");
|
|
||||||
|
|
||||||
currentStatus = "安装成功";
|
currentStatus = "安装成功";
|
||||||
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
MessageBox.Show("安装成功");
|
//MessageBox.Show("安装成功");
|
||||||
//MessageBox.Show("ssh信息"+client.ConnectionInfo.ServerVersion.ToString());
|
//MessageBox.Show("ssh信息"+client.ConnectionInfo.ServerVersion.ToString());
|
||||||
|
|
||||||
//MessageBox.Show(client);
|
//MessageBox.Show(client);
|
||||||
client.Disconnect();
|
client.Disconnect();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex1)//例外处理
|
catch (Exception ex1)//例外处理
|
||||||
@ -511,7 +499,55 @@ namespace ProxySU
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//上传配置文件
|
||||||
|
private void UploadConfig(ConnectionInfo connectionInfo,string uploadConfig)
|
||||||
|
{
|
||||||
|
|
||||||
|
//v2rayConfig = "config\\http_server.json";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var sftpClient = new SftpClient(connectionInfo))
|
||||||
|
{
|
||||||
|
sftpClient.Connect();
|
||||||
|
//MessageBox.Show("sftp信息1" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
||||||
|
sftpClient.UploadFile(File.OpenRead(uploadConfig), "/etc/v2ray/config.json", true);
|
||||||
|
//sftpClient.DownloadFile("/root/id_rsa.pub", File.Create("config\\server_config.json"));
|
||||||
|
MessageBox.Show("sftp信息" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
||||||
|
sftpClient.Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex2)
|
||||||
|
{
|
||||||
|
MessageBox.Show("sftp" + ex2.ToString());
|
||||||
|
MessageBox.Show("sftp出现未知错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//下载配置文件
|
||||||
|
private void DownloadConfig(ConnectionInfo connectionInfo, string downloadConfig)
|
||||||
|
{
|
||||||
|
|
||||||
|
//v2rayConfig = "config\\http_server.json";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var sftpClient = new SftpClient(connectionInfo))
|
||||||
|
{
|
||||||
|
sftpClient.Connect();
|
||||||
|
//MessageBox.Show("sftp信息1" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
||||||
|
//sftpClient.UploadFile(File.OpenRead(v2rayConfig), "/etc/v2ray/config.json", true);
|
||||||
|
sftpClient.DownloadFile("/etc/v2ray/config.json", File.Create(downloadConfig));
|
||||||
|
MessageBox.Show("sftp信息" + sftpClient.ConnectionInfo.ServerVersion.ToString());
|
||||||
|
sftpClient.Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex2)
|
||||||
|
{
|
||||||
|
MessageBox.Show("sftp" + ex2.ToString());
|
||||||
|
MessageBox.Show("sftp出现未知错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//更新UI显示内容
|
//更新UI显示内容
|
||||||
private void UpdateTextBlock(TextBlock textBlockName, ProgressBar progressBar, string currentStatus)
|
private void UpdateTextBlock(TextBlock textBlockName, ProgressBar progressBar, string currentStatus)
|
||||||
{
|
{
|
||||||
@ -592,9 +628,33 @@ namespace ProxySU
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void ButtonSetConfiguration_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (RadioButtonGuideConfiguration.IsChecked == true)
|
||||||
|
{
|
||||||
|
MessageBox.Show("还未完善,敬请期待!");
|
||||||
|
}
|
||||||
|
else if (RadioButtonTemplateConfiguration.IsChecked == true)
|
||||||
|
{
|
||||||
|
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
|
||||||
|
{
|
||||||
|
Filter = "Cert Files (*.json)|*.json"
|
||||||
|
};
|
||||||
|
var result = openFileDialog.ShowDialog();
|
||||||
|
if (result == true)
|
||||||
|
{
|
||||||
|
TextBoxJsonPath.Text = openFileDialog.FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("还未完善,敬请期待!");
|
||||||
|
}
|
||||||
|
MessageBox.Show(TextBoxJsonPath.Text.ToString());
|
||||||
|
string appConfig = TextBoxJsonPath.Text.ToString().Replace("\\", "\\\\");
|
||||||
|
MessageBox.Show(appConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user