1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 05:06: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")); var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile"));
caddyStr = caddyStr.Replace("##domain##", parameters.Domain); 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 else
{ {

View File

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

View File

@ -52,10 +52,9 @@ namespace ProxySU_Core.ViewModels.Developers
UploadFile(stream, "/usr/share/caddy/caddy.zip"); UploadFile(stream, "/usr/share/caddy/caddy.zip");
RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy");
RunCmd("chmod -R 777 /usr/share/caddy"); RunCmd("chmod -R 777 /usr/share/caddy");
UploadCaddyFile(useCustomWeb: true);
RunCmd("systemctl restart caddy"); RunCmd("systemctl restart caddy");
WriteOutput("************"); WriteOutput("************\n上传网站模板完成\n************");
WriteOutput("上传网站模板完成");
WriteOutput("************");
} }
public void ReinstallCaddy() 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)); var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson));
RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back");
UploadFile(stream, "/etc/caddy/Caddyfile"); UploadFile(stream, "/etc/caddy/Caddyfile");
@ -179,7 +178,7 @@ namespace ProxySU_Core.ViewModels.Developers
RunCmd(GetInstallCmd("socat")); RunCmd(GetInstallCmd("socat"));
// 解决搬瓦工CentOS缺少问题 // 解决搬瓦工CentOS缺少问题
RunCmd("echo y | " + GetInstallCmd("automake autoconf libtool")); RunCmd(GetInstallCmd("automake autoconf libtool"));
// 安装Acme // 安装Acme
var result = RunCmd($"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m {GetRandomEmail()}"); 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 public class Terminal : BaseViewModel
{ {
private string outputText;
private bool hasConnected; private bool hasConnected;
public Terminal(Host host) public Terminal(Host host)
@ -34,26 +33,6 @@ namespace ProxySU_Core.ViewModels
public string CommandText { get; set; } public string CommandText { get; set; }
public string OutputText public string OutputText { get; set; }
{
get => outputText;
}
public void ClearOutput()
{
outputText = "";
Notify("OutputText");
}
public void AddOutput(string text)
{
outputText += text;
if (!text.EndsWith("\n"))
{
outputText += "\n";
}
Notify("OutputText");
}
} }
} }

View File

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

View File

@ -44,7 +44,7 @@ namespace ProxySU_Core
_vm = new Terminal(record.Host); _vm = new Terminal(record.Host);
DataContext = _vm; DataContext = _vm;
_vm.AddOutput("Connect ..."); WriteOutput("Connect ...");
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
try try
@ -108,17 +108,21 @@ namespace ProxySU_Core
var conneInfo = CreateConnectionInfo(host); var conneInfo = CreateConnectionInfo(host);
_sshClient = new SshClient(conneInfo); _sshClient = new SshClient(conneInfo);
_sshClient.Connect(); _sshClient.Connect();
_vm.AddOutput("Connected"); WriteOutput("Connected");
_vm.HasConnected = true; _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(() => Dispatcher.Invoke(() =>
{ {
OutputTextBox.AppendText(outShell);
OutputTextBox.ScrollToEnd(); OutputTextBox.ScrollToEnd();
}); });
} }