1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 05:06:08 +03:00

添加启用root证书密钥登录

This commit is contained in:
ProxySU 2020-10-25 13:37:54 +08:00
parent a9bd37bd27
commit eefa37c099
10 changed files with 8577 additions and 5761 deletions

View File

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProxySU"
mc:Ignorable="d"
Title="ProxySU - v2.4.10" Height="675" Width="650">
Title="ProxySU - v2.4.11" Height="675" Width="650">
<!--以下样式参考自https://yq.aliyun.com/articles/331878
https://docs.microsoft.com/en-us/dotnet/desktop-wpf/fundamentals/styles-templates-overview-->
<Window.Resources>
@ -665,6 +665,8 @@
<Button x:Name="ButtonTestAndEnableBBR" Content="{DynamicResource ButtonTestAndEnableBBR}" Grid.Column="2" Grid.Row="0" Margin="5" Click="ButtonTestAndEnableBBR_Click"></Button>
<Button x:Name="ButtonRemoveAllSoft" Content="{DynamicResource ButtonRemoveAllSoft}" Grid.Column="3" Grid.Row="0" Margin="5" Click="ButtonRemoveAllSoft_Click"></Button>
<Button x:Name="ButtonEnableRootPassWord" Content="{DynamicResource ButtonEnableRootPassWord}" Grid.Column="0" Grid.Row="1" Margin="5" Click="ButtonEnableRootPassWord_Click"></Button>
<Button x:Name="ButtonEnableRootCert" Content="{DynamicResource ButtonEnableRootCert}" Grid.Column="1" Grid.Row="1" Margin="5" Click="ButtonEnableRootCert_Click"></Button>
<Button x:Name="ButtonRootProhibitsPasswordLogin" Content="{DynamicResource ButtonRootProhibitsPasswordLogin}" Grid.Column="2" Grid.Row="1" Margin="5" Click="ButtonRootProhibitsPasswordLogin_Click"></Button>
<Button Content="test" Grid.Column="3" Grid.Row="2" Margin="10" Click="Button_Click" Visibility="Collapsed"></Button>
</Grid>
</TabItem>

View File

@ -268,21 +268,7 @@ namespace ProxySU
}
}
//判断目录是否存在,不存在则创建
private static bool CheckDir(string folder)
{
try
{
if (!Directory.Exists(folder))//如果不存在就创建file文件夹
Directory.CreateDirectory(folder);//创建该文件夹  
return true;
}
catch (Exception)
{
return false;
}
}
//更新新版本提醒显示
Action<TextBlock, TextBlock, Button, string> updateNewVersionProxySUAction = new Action<TextBlock, TextBlock, Button, string>(UpdateNewVersionProxySU);
private static void UpdateNewVersionProxySU(TextBlock TextBlockLastVersionProxySU, TextBlock TextBlockNewVersionReminder, Button ButtonUpgradeProxySU, string theLatestVersion)
@ -5011,6 +4997,50 @@ namespace ProxySU
return random.Next(10001, 60000);
}
//判断目录是否存在,不存在则创建
private static bool CheckDir(string folder)
{
try
{
if (!Directory.Exists(folder))//如果不存在就创建file文件夹
Directory.CreateDirectory(folder);//创建该文件夹  
return true;
}
catch (Exception)
{
return false;
}
}
//目录已存在则生成序号递增,并返回所创建的目录路径。
private string CreateConfigSaveDir(string upperDir, string configDir)
{
try
{
//string saveFileFolderFirst = configDir;
int num = 1;
//string saveFileFolder;
//saveFileFolder = EncodeURIComponent(configDir);
string saveFileFolder = configDir.Replace(":", "_");
CheckDir(upperDir);
while (Directory.Exists(upperDir + @"\" + saveFileFolder) == true)
{
saveFileFolder = configDir + "_copy_" + num.ToString();
num++;
}
CheckDir(upperDir + @"\" + saveFileFolder);
return upperDir + @"\" + saveFileFolder;
}
catch (Exception)
{
//string saveFileFolder = "";
//return upperDir + @"\" + saveFileFolder;
return upperDir;
}
}
//上传配置文件
private void UploadConfig(ConnectionInfo connectionInfo, string uploadConfig, string upLoadPath)
{
@ -5035,15 +5065,15 @@ namespace ProxySU
}
//下载配置文件
private void DownloadConfig(ConnectionInfo connectionInfo, string downloadConfig, string downloadPath)
private void DownloadConfig(ConnectionInfo connectionInfo, string localConfigSavePathAndFileName, string remoteConfigPathAndFileName)
{
try
{
using (var sftpClient = new SftpClient(connectionInfo))
{
sftpClient.Connect();
FileStream createDownloadConfig = File.Open(downloadConfig, FileMode.Create);
sftpClient.DownloadFile(downloadPath, createDownloadConfig);
FileStream createDownloadConfig = File.Open(localConfigSavePathAndFileName, FileMode.Create);
sftpClient.DownloadFile(remoteConfigPathAndFileName, createDownloadConfig);
createDownloadConfig.Close();
sftpClient.Disconnect();
@ -8361,6 +8391,7 @@ namespace ProxySU
}
ReceiveConfigurationParameters[4] = TextBoxHost.Text;//传递主机地址
ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password;//传递当前账户密码
installationDegree = 0;
TextBoxMonitorCommandResults.Text = "";
@ -8443,7 +8474,7 @@ namespace ProxySU
}
SetUpProgressBarProcessing(10);
string hostPassword = "'" + PasswordBoxHostPassword.Password + "'";
string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'";
//MessageBox.Show(hostPassword);
sshShellCommand = $"echo {hostPassword} | sudo -S id -u";
//MessageBox.Show(sshShellCommand);
@ -8499,6 +8530,10 @@ namespace ProxySU
client.Disconnect();
//***保存密码信息***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootPasswordSavePasswordInfo").ToString();
MainWindowsShowInfo(currentStatus);
string filePath = ReceiveConfigurationParameters[4].Replace(':', '_');
CheckDir(filePath);
using (StreamWriter sw = new StreamWriter($"{filePath}\\host_password_info.txt"))
@ -8531,6 +8566,482 @@ namespace ProxySU
}
#endregion
#region Root证书密钥登录
private void ButtonEnableRootCert_Click(object sender, RoutedEventArgs e)
{
//******"本功能需要当前登录的账户具有root或者sudo权限是否为远程主机启用root证书密钥登录"******
string messageShow = Application.Current.FindResource("MessageBoxShow_ButtonEnableRootCert").ToString();
MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.Yes)
{
ConnectionInfo connectionInfo = GenerateConnectionInfo();
if (connectionInfo == null)
{
//****** "远程主机连接信息有误,请检查!" ******
MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString());
return;
}
ReceiveConfigurationParameters[4] = TextBoxHost.Text;//传递主机地址
ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password;
installationDegree = 0;
TextBoxMonitorCommandResults.Text = "";
Thread thread = new Thread(() => EnableRootCert(connectionInfo));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
//启用Root证书密钥登录进程
private void EnableRootCert(ConnectionInfo connectionInfo)
{
functionResult = true;
getApt = false;
getDnf = false;
getYum = false;
onlyIpv6 = false;
string filePath = String.Empty;
//******"正在登录远程主机......"******
SetUpProgressBarProcessing(1);
string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString();
MainWindowsShowInfo(currentStatus);
try
{
#region
//byte[] expectedFingerPrint = new byte[] {
// 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31,
// 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b
// };
#endregion
using (var client = new SshClient(connectionInfo))
{
#region ssh登录验证主机指纹代码块
// client.HostKeyReceived += (sender, e) =>
// {
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
// {
// for (var i = 0; i < expectedFingerPrint.Length; i++)
// {
// if (expectedFingerPrint[i] != e.FingerPrint[i])
// {
// e.CanTrust = false;
// break;
// }
// }
// }
// else
// {
// e.CanTrust = false;
// }
// };
#endregion
client.Connect();
if (client.IsConnected == true)
{
//******"主机登录成功"******
SetUpProgressBarProcessing(5);
currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString();
MainWindowsShowInfo(currentStatus);
}
//检测root权限 5--7
//******"检测是否运行在root权限下..."******01
SetUpProgressBarProcessing(5);
currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = @"id -u";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == true)
{
SetUpProgressBarProcessing(20);
//***正在生成密钥......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertGenerateCert").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = @"rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"yes | ssh-keygen -b 2048 -t rsa -f /tmp/rootuser.key -q -N ''";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"yes | ssh-keygen -p -P '' -N '' -m PEM -f /tmp/rootuser.key";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"mkdir -p /root/.ssh";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"cat /tmp/rootuser.key.pub | tee -a /root/.ssh/authorized_keys";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"chmod 777 /tmp/rootuser.key";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(30);
//***正在下载密钥......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertDownloadCert").ToString();
MainWindowsShowInfo(currentStatus);
filePath = CreateConfigSaveDir(@"root_cert", ReceiveConfigurationParameters[4].Replace(':', '_'));
string localConfigSavePathAndFileName = $"{filePath}\\rootuser.key";
string remoteConfigPathAndFileName = @"/tmp/rootuser.key";
DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName);
localConfigSavePathAndFileName = $"{filePath}\\rootuser.key.pub";
remoteConfigPathAndFileName = @"/tmp/rootuser.key.pub";
DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName);
sshShellCommand = @"rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(50);
//***远程主机启用密钥登录......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertSetCertEnable").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = @"sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"sed -i 's/StrictModes /#StrictModes /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(70);
sshShellCommand = @"sed -i 's/PubkeyAuthentication /#PubkeyAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"sed -i 's/#AuthorizedKeysFile /AuthorizedKeysFile /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(80);
sshShellCommand = @"sed -i 's/#RSAAuthentication /RSAAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"echo 'PermitRootLogin yes' | tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(90);
sshShellCommand = @"echo 'StrictModes no' | tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"echo 'PubkeyAuthentication yes' | tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"systemctl restart sshd";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
}
else
{
SetUpProgressBarProcessing(10);
string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'";
//MessageBox.Show(hostPassword);
sshShellCommand = $"echo {hostPassword} | sudo -S id -u";
//MessageBox.Show(sshShellCommand);
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
//MessageBox.Show(currentShellCommandResult);
if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == false)
{
//******"当前账户无法获取sudo权限设置失败"******
currentStatus = Application.Current.FindResource("MessageBoxShow_NoSudoToAccount").ToString();
MainWindowsShowInfo(currentStatus);
MessageBox.Show(currentStatus);
client.Disconnect();
return;
}
SetUpProgressBarProcessing(20);
string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';';
//***正在生成密钥......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertGenerateCert").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = cmdPre + @"sudo rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"yes | sudo ssh-keygen -b 2048 -t rsa -f /tmp/rootuser.key -q -N ''";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"yes | sudo ssh-keygen -p -P '' -N '' -m PEM -f /tmp/rootuser.key";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo mkdir -p /root/.ssh";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"cat /tmp/rootuser.key.pub | sudo tee -a /root/.ssh/authorized_keys";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo chmod 777 /tmp/rootuser.key";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(30);
//***正在下载密钥......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertDownloadCert").ToString();
MainWindowsShowInfo(currentStatus);
filePath = CreateConfigSaveDir(@"root_cert", ReceiveConfigurationParameters[4].Replace(':', '_'));
string localConfigSavePathAndFileName = $"{filePath}\\rootuser.key";
string remoteConfigPathAndFileName = @"/tmp/rootuser.key";
DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName);
localConfigSavePathAndFileName = $"{filePath}\\rootuser.key.pub";
remoteConfigPathAndFileName = @"/tmp/rootuser.key.pub";
DownloadConfig(connectionInfo, localConfigSavePathAndFileName, remoteConfigPathAndFileName);
sshShellCommand = cmdPre + @"sudo rm -rf /tmp/rootuser.key /tmp/rootuser.key.pub";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(50);
//***远程主机启用密钥登录......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableRootCertSetCertEnable").ToString();
MainWindowsShowInfo(currentStatus);
//string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';';
sshShellCommand = cmdPre + @"sudo sed -i 's/PermitRootLogin /#PermitRootLogin /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo sed -i 's/StrictModes /#StrictModes /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(70);
sshShellCommand = cmdPre + @"sudo sed -i 's/PubkeyAuthentication /#PubkeyAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo sed -i 's/#AuthorizedKeysFile /AuthorizedKeysFile /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(80);
sshShellCommand = cmdPre + @"sudo sed -i 's/#RSAAuthentication /RSAAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
SetUpProgressBarProcessing(90);
sshShellCommand = cmdPre + @"echo 'StrictModes no' | sudo tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"echo 'PubkeyAuthentication yes' | sudo tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo systemctl restart sshd";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
}
client.Disconnect();
SetUpProgressBarProcessing(100);
//******"远程主机root账户证书密钥登录已启用密钥文件rootuser.key保存在随后打开的文件夹中"******
currentStatus = Application.Current.FindResource("MessageBoxShow_ButtonEnableRootCertSuccess").ToString();
MainWindowsShowInfo(currentStatus);
MessageBox.Show(currentStatus);
System.Diagnostics.Process.Start("explorer.exe", filePath);
return;
}
}
catch (Exception ex1)//例外处理
#region
{
ProcessException(ex1.Message);
//****** "主机登录失败!" ******
currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString();
MainWindowsShowInfo(currentStatus);
}
#endregion
}
#endregion
//root禁止密码登录
private void ButtonRootProhibitsPasswordLogin_Click(object sender, RoutedEventArgs e)
{
//******"本功能需要远程主机已经开启了其他登录方式如密钥方式等否则将可能造成远程主机无法连接是否禁止远程主机的root账户密码登录方式"******
string messageShow = Application.Current.FindResource("MessageBoxShow_ButtonRootProhibitsPasswordLogin").ToString();
MessageBoxResult messageBoxResult = MessageBox.Show(messageShow, "", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.Yes)
{
ConnectionInfo connectionInfo = GenerateConnectionInfo();
if (connectionInfo == null)
{
//****** "远程主机连接信息有误,请检查!" ******
MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString());
return;
}
ReceiveConfigurationParameters[4] = TextBoxHost.Text;//传递主机地址
ReceiveConfigurationParameters[2] = PasswordBoxHostPassword.Password;//传递主机密码
installationDegree = 0;
TextBoxMonitorCommandResults.Text = "";
Thread thread = new Thread(() => RootProhibitsPasswordLogin(connectionInfo));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
//禁止root密码登录进程
private void RootProhibitsPasswordLogin(ConnectionInfo connectionInfo)
{
functionResult = true;
getApt = false;
getDnf = false;
getYum = false;
onlyIpv6 = false;
string filePath = String.Empty;
//******"正在登录远程主机......"******
SetUpProgressBarProcessing(1);
string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString();
MainWindowsShowInfo(currentStatus);
try
{
#region
//byte[] expectedFingerPrint = new byte[] {
// 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31,
// 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b
// };
#endregion
using (var client = new SshClient(connectionInfo))
{
#region ssh登录验证主机指纹代码块
// client.HostKeyReceived += (sender, e) =>
// {
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
// {
// for (var i = 0; i < expectedFingerPrint.Length; i++)
// {
// if (expectedFingerPrint[i] != e.FingerPrint[i])
// {
// e.CanTrust = false;
// break;
// }
// }
// }
// else
// {
// e.CanTrust = false;
// }
// };
#endregion
client.Connect();
if (client.IsConnected == true)
{
//******"主机登录成功"******
SetUpProgressBarProcessing(5);
currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString();
MainWindowsShowInfo(currentStatus);
}
//检测root权限 5--7
//******"检测是否运行在root权限下..."******01
SetUpProgressBarProcessing(5);
currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = @"id -u";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == true)
{
SetUpProgressBarProcessing(20);
//***正在关闭root账户密码登录方式......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetRootProhibitsPasswordLogin").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = @"sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"echo 'PasswordAuthentication no' | tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"echo 'PermitEmptyPasswords no' | tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = @"systemctl restart sshd";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
}
else
{
SetUpProgressBarProcessing(10);
string hostPassword = "'" + ReceiveConfigurationParameters[2] + "'";
//MessageBox.Show(hostPassword);
sshShellCommand = $"echo {hostPassword} | sudo -S id -u";
//MessageBox.Show(sshShellCommand);
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
//MessageBox.Show(currentShellCommandResult);
if (currentShellCommandResult.TrimEnd('\r', '\n').Equals("0") == false)
{
//******"当前账户无法获取sudo权限设置失败"******
currentStatus = Application.Current.FindResource("MessageBoxShow_NoSudoToAccount").ToString();
MainWindowsShowInfo(currentStatus);
MessageBox.Show(currentStatus);
client.Disconnect();
return;
}
SetUpProgressBarProcessing(20);
string cmdPre = $"echo {hostPassword} | sudo -S id -u" + ';';
//***正在关闭root账户密码登录方式......***
currentStatus = Application.Current.FindResource("DisplayInstallInfo_SetRootProhibitsPasswordLogin").ToString();
MainWindowsShowInfo(currentStatus);
sshShellCommand = cmdPre + @"sudo sed -i 's/PasswordAuthentication /#PasswordAuthentication /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo sed -i 's/PermitEmptyPasswords /#PermitEmptyPasswords /g' /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"echo 'PasswordAuthentication no' | sudo tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"echo 'PermitEmptyPasswords no' | sudo tee -a /etc/ssh/sshd_config";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
sshShellCommand = cmdPre + @"sudo systemctl restart sshd";
currentShellCommandResult = MainWindowsShowCmd(client, sshShellCommand);
}
client.Disconnect();
SetUpProgressBarProcessing(100);
//******"远程主机root账户密码登录方式已关闭"******
currentStatus = Application.Current.FindResource("MessageBoxShow_RootProhibitsPasswordLoginOK").ToString();
MainWindowsShowInfo(currentStatus);
MessageBox.Show(currentStatus);
return;
}
}
catch (Exception ex1)//例外处理
#region
{
ProcessException(ex1.Message);
//****** "主机登录失败!" ******
currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString();
MainWindowsShowInfo(currentStatus);
}
#endregion
}
}
}

View File

@ -51,5 +51,5 @@ using System.Windows;
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.10.0")]
[assembly: AssemblyFileVersion("2.4.10.0")]
[assembly: AssemblyVersion("2.4.11.0")]
[assembly: AssemblyFileVersion("2.4.11.0")]

View File

@ -64,6 +64,7 @@
<sys:String x:Key="TextBlockMtgFakeDomainExplanation">Making domain name:</sys:String>
<sys:String x:Key="TextBlockMtgPortExplanation">Recommended https ports 443, 2053, 2083, 2087, 2096, 8443</sys:String>
<sys:String x:Key="TextBlockMtgSecretExplanation">The secret key will be randomly generated by the server.</sys:String>
<!-- 以下SS设置参数标签页界面 -->
<sys:String x:Key="ButtonSetUpSS">SS install</sys:String>
<sys:String x:Key="ButtonTemplateConfigurationSS">SS plug-in library</sys:String>
@ -93,16 +94,29 @@
<sys:String x:Key="TextBlockPluginNameExplainSS">Plugin program:</sys:String>
<sys:String x:Key="TextBlockPluginOptionExplainSS">Plugin options:</sys:String>
<sys:String x:Key="DisplayInstallInfo_ExplainBuildSS">Use the compilation method, it will take a little longer, please be patient...</sys:String>
<!-- The following system tool tab interface -->
<sys:String x:Key="ButtonProofreadTime">Proofreading Time</sys:String>
<sys:String x:Key="ButtonClearOccupiedPorts">Release 80/443</sys:String>
<sys:String x:Key="ButtonTestAndEnableBBR">Enable BBR</sys:String>
<sys:String x:Key="ButtonRemoveAllSoft">Uninstall Proxy</sys:String>
<sys:String x:Key="ButtonEnableRootPassWord">Enable Root password login</sys:String>
<sys:String x:Key="ButtonRootProhibitsPasswordLogin">root prohibits password login</sys:String>
<sys:String x:Key="ButtonEnableRootCert">Enable Root certificate key login</sys:String>
<sys:String x:Key="MessageBoxShow_RemoveAllSoft">Only the proxy software installed by ProxySU and related configurations are supported. Please make sure that important configurations have been backed up. Uninstalling agents installed using other methods or scripts is not supported. Are you sure you want to uninstall the agent software on the remote host?</sys:String>
<sys:String x:Key="MessageBoxShow_EnableRootPassword">This function requires that the currently logged-in account has sudo permissions. Is the root account enabled and password set for the remote host?</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCert">This function requires that the currently logged-in account has root or sudo authority. Is root certificate key login enabled for the remote host?</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonRootProhibitsPasswordLogin">This function requires that the remote host has enabled other login methods, such as key mode, etc., otherwise the remote host may not be able to connect. Is the root account password login method of the remote host prohibited?</sys:String>
<sys:String x:Key="DisplayInstallInfo_SetRootProhibitsPasswordLogin">is closing the root account password login method.....</sys:String>
<sys:String x:Key="MessageBoxShow_RootProhibitsPasswordLoginOK">The remote host root account password login method is closed!</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCertSuccess">The root account certificate key login of the remote host has been enabled, and the key file rootuser.key is saved in the subsequent opened folder!</sys:String>
<sys:String x:Key="MessageBoxShow_AlreadyRoot">The current account already has root privileges, no need to set it up!</sys:String>
<sys:String x:Key="MessageBoxShow_NoSudoToAccount">The current account cannot obtain sudo permission, the setting failed!</sys:String>
<sys:String x:Key="DisplayInstallInfo_GenerateRandomPassword">Generate a 20-digit random password!</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSavePasswordInfo">Save password information!</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertGenerateCert">Generating a key...</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertDownloadCert">The key is being downloaded...</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertSetCertEnable">The remote host enables key login.......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSuccess">The remote host Root account password login is enabled, and the password is saved in the folder opened afterwards!</sys:String>
<sys:String x:Key="DisplayInstallInfo_StartRemoveProxy">Start uninstall......</sys:String>
<sys:String x:Key="DisplayInstallInfo_DiscoverProxySoft">Detected installed</sys:String>

View File

@ -101,11 +101,22 @@
<sys:String x:Key="ButtonTestAndEnableBBR">启用BBR</sys:String>
<sys:String x:Key="ButtonRemoveAllSoft">卸载代理</sys:String>
<sys:String x:Key="ButtonEnableRootPassWord">启用Root密码登录</sys:String>
<sys:String x:Key="ButtonEnableRootCert">启用Root证书密钥登录</sys:String>
<sys:String x:Key="ButtonRootProhibitsPasswordLogin">root禁止密码登录</sys:String>
<sys:String x:Key="MessageBoxShow_RemoveAllSoft">仅支持卸载由ProxySU安装的代理软件及相关配置请确保重要配置已备份。不支持卸载使用其他方法或脚本安装的代理。确定要卸载远程主机上的代理软件吗</sys:String>
<sys:String x:Key="MessageBoxShow_EnableRootPassword">本功能需要当前登录的账户具有sudo权限是否为远程主机启用root账户并设置密码</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCert">本功能需要当前登录的账户具有root或者sudo权限是否为远程主机启用root证书密钥登录</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonRootProhibitsPasswordLogin">本功能需要远程主机已经开启了其他登录方式如密钥方式等否则将可能造成远程主机无法连接是否禁止远程主机的root账户密码登录方式</sys:String>
<sys:String x:Key="DisplayInstallInfo_SetRootProhibitsPasswordLogin">正在关闭root账户密码登录方式.....</sys:String>
<sys:String x:Key="MessageBoxShow_RootProhibitsPasswordLoginOK">远程主机root账户密码登录方式已关闭</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCertSuccess">远程主机root账户证书密钥登录已启用密钥文件rootuser.key保存在随后打开的文件夹中</sys:String>
<sys:String x:Key="MessageBoxShow_AlreadyRoot">当前账户已经具有root权限无需再设置</sys:String>
<sys:String x:Key="MessageBoxShow_NoSudoToAccount">当前账户无法获取sudo权限设置失败</sys:String>
<sys:String x:Key="DisplayInstallInfo_GenerateRandomPassword">生成20位随机密码</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSavePasswordInfo">保存密码信息!</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertGenerateCert">正在生成密钥......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertDownloadCert">正在下载密钥......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertSetCertEnable">远程主机启用密钥登录.......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSuccess">远程主机Root账户密码登录已启用密码保存在随后打开的文件夹中</sys:String>
<sys:String x:Key="DisplayInstallInfo_StartRemoveProxy">开始卸载</sys:String>
<sys:String x:Key="DisplayInstallInfo_DiscoverProxySoft">检测到已安装</sys:String>

View File

@ -100,11 +100,23 @@
<sys:String x:Key="ButtonClearOccupiedPorts">釋放80/443端口</sys:String>
<sys:String x:Key="ButtonTestAndEnableBBR">啟用BBR</sys:String>
<sys:String x:Key="ButtonRemoveAllSoft">卸載代理</sys:String>
<sys:String x:Key="ButtonEnableRootPassWord">啟用Root密碼登錄</sys:String>
<sys:String x:Key="ButtonRootProhibitsPasswordLogin">root禁止密碼登錄</sys:String>
<sys:String x:Key="ButtonEnableRootCert">啟用Root證書密鑰登錄</sys:String>
<sys:String x:Key="MessageBoxShow_RemoveAllSoft">僅支持卸載由ProxySU安裝的代理軟件及相關配置請確保重要配置已備份。不支持卸載使用其他方法或腳本安裝的代理。確定要卸載遠程主機上的代理軟件嗎</sys:String>
<sys:String x:Key="MessageBoxShow_EnableRootPassword">本功能需要當前登錄的賬戶具有sudo權限是否為遠程主機啟用root賬戶並設置密碼</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCert">本功能需要當前登錄的賬戶具有root或者sudo權限是否為遠程主機啟用root證書密鑰登錄</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonRootProhibitsPasswordLogin">本功能需要遠程主機已經開啟了其他登錄方式如密鑰方式等否則將可能造成遠程主機無法連接是否禁止遠程主機的root賬戶密碼登錄方式</sys:String>
<sys:String x:Key="DisplayInstallInfo_SetRootProhibitsPasswordLogin">正在關閉root賬戶密碼登錄方式.....</sys:String>
<sys:String x:Key="MessageBoxShow_RootProhibitsPasswordLoginOK">遠程主機root賬戶密碼登錄方式已關閉</sys:String>
<sys:String x:Key="MessageBoxShow_ButtonEnableRootCertSuccess">遠程主機root賬戶證書密鑰登錄已啟用密鑰文件rootuser.key保存在隨後打開的文件夾中</sys:String>
<sys:String x:Key="MessageBoxShow_AlreadyRoot">當前賬戶已經具有root權限無需再設置</sys:String>
<sys:String x:Key="MessageBoxShow_NoSudoToAccount">當前賬戶無法獲取sudo權限設置失敗</sys:String>
<sys:String x:Key="DisplayInstallInfo_GenerateRandomPassword">生成20位隨機密碼</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSavePasswordInfo">保存密碼信息!</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertGenerateCert">正在生成密鑰......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertDownloadCert">正在下載密鑰......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootCertSetCertEnable">遠程主機啟用密鑰登錄.......</sys:String>
<sys:String x:Key="DisplayInstallInfo_EnableRootPasswordSuccess">遠程主機Root賬戶密碼登錄已啟用密碼保存在隨後打開的文件夾中</sys:String>
<sys:String x:Key="DisplayInstallInfo_StartRemoveProxy">開始卸載......</sys:String>
<sys:String x:Key="DisplayInstallInfo_DiscoverProxySoft">檢測到已安裝</sys:String>

Binary file not shown.

View File

@ -1 +0,0 @@
forked from https://github.com/sshnet/SSH.NET

Binary file not shown.

File diff suppressed because it is too large Load Diff