1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-21 20:56:08 +03:00
This commit is contained in:
next-autumn 2021-03-11 12:05:50 +08:00
parent ae1c06f6af
commit 14401058dc
6 changed files with 25 additions and 47 deletions

View File

@ -60,13 +60,13 @@ namespace ProxySU_Core.ViewModels.Developers
};
}
public static string BuildCaddyConfig(XraySettings parameters)
public static string BuildCaddyConfig(XraySettings parameters, bool useCustomWeb = false)
{
var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile"));
caddyStr = caddyStr.Replace("##domain##", parameters.Domain);
if (!string.IsNullOrEmpty(parameters.MaskDomain))
if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain))
{
caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy http://{parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}");
caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}");
}
else
{

View File

@ -553,15 +553,15 @@ namespace ProxySU_Core.ViewModels.Developers
{
if (CmdType == CmdType.Apt)
{
return "apt-get install " + soft;
return "echo y | apt-get install " + soft;
}
else if (CmdType == CmdType.Dnf)
{
return "dnf -y install " + soft;
return "echo y | dnf -y install " + soft;
}
else if (CmdType == CmdType.Yum)
{
return "yum -y install " + soft;
return "echo y | yum -y install " + soft;
}
throw new Exception("未识别的系统");

View File

@ -52,10 +52,9 @@ namespace ProxySU_Core.ViewModels.Developers
UploadFile(stream, "/usr/share/caddy/caddy.zip");
RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy");
RunCmd("chmod -R 777 /usr/share/caddy");
UploadCaddyFile(useCustomWeb: true);
RunCmd("systemctl restart caddy");
WriteOutput("************");
WriteOutput("上传网站模板完成");
WriteOutput("************");
WriteOutput("************\n上传网站模板完成\n************");
}
public void ReinstallCaddy()
@ -133,9 +132,9 @@ namespace ProxySU_Core.ViewModels.Developers
}
}
private void UploadCaddyFile()
private void UploadCaddyFile(bool useCustomWeb = false)
{
var configJson = ConfigBuilder.BuildCaddyConfig(Parameters);
var configJson = ConfigBuilder.BuildCaddyConfig(Parameters, useCustomWeb);
var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back");
UploadFile(stream, "/etc/caddy/Caddyfile");
@ -179,7 +178,7 @@ namespace ProxySU_Core.ViewModels.Developers
RunCmd(GetInstallCmd("socat"));
// 解决搬瓦工CentOS缺少问题
RunCmd("echo y | " + GetInstallCmd("automake autoconf libtool"));
RunCmd(GetInstallCmd("automake autoconf libtool"));
// 安装Acme
var result = RunCmd($"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m {GetRandomEmail()}");

View File

@ -8,7 +8,6 @@ namespace ProxySU_Core.ViewModels
{
public class Terminal : BaseViewModel
{
private string outputText;
private bool hasConnected;
public Terminal(Host host)
@ -34,26 +33,6 @@ namespace ProxySU_Core.ViewModels
public string CommandText { get; set; }
public string OutputText
{
get => outputText;
}
public void ClearOutput()
{
outputText = "";
Notify("OutputText");
}
public void AddOutput(string text)
{
outputText += text;
if (!text.EndsWith("\n"))
{
outputText += "\n";
}
Notify("OutputText");
}
public string OutputText { get; set; }
}
}

View File

@ -8,20 +8,16 @@
mc:Ignorable="d"
Title="主机控制台" Height="500" Width="800">
<StackPanel>
<RichTextBox IsReadOnly="True"
<TextBox IsReadOnly="True"
Block.LineHeight="18"
Background="#000"
Foreground="LawnGreen"
FontSize="14"
FontFamily="Consolas"
x:Name="OutputTextBox"
Height="320">
<FlowDocument>
<Paragraph>
<Run Text="{Binding Path=OutputText, Mode=OneWay}" />
</Paragraph>
</FlowDocument>
</RichTextBox>
Height="320"
Text="{Binding Path=OutputText}"
/>
<StackPanel Margin="10"
Orientation="Horizontal"

View File

@ -44,7 +44,7 @@ namespace ProxySU_Core
_vm = new Terminal(record.Host);
DataContext = _vm;
_vm.AddOutput("Connect ...");
WriteOutput("Connect ...");
Task.Factory.StartNew(() =>
{
try
@ -108,17 +108,21 @@ namespace ProxySU_Core
var conneInfo = CreateConnectionInfo(host);
_sshClient = new SshClient(conneInfo);
_sshClient.Connect();
_vm.AddOutput("Connected");
WriteOutput("Connected");
_vm.HasConnected = true;
project = new XrayProject(_sshClient, Record.Settings, WriteShell);
project = new XrayProject(_sshClient, Record.Settings, WriteOutput);
}
private void WriteShell(string outShell)
private void WriteOutput(string outShell)
{
_vm.AddOutput(outShell);
if (!outShell.EndsWith("\n"))
{
outShell += "\n";
}
Dispatcher.Invoke(() =>
{
OutputTextBox.AppendText(outShell);
OutputTextBox.ScrollToEnd();
});
}