private void InstallXrayWithCert() { RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); if (!FileExists("/usr/local/bin/xray")) { WriteOutput("Xray-Core安装失败,请联系开发者"); throw new Exception("Xray-Core安装失败,请联系开发者"); } RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"); RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/xray.service"); RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/xray.service"); RunCmd($"systemctl daemon-reload"); if (FileExists("/usr/local/etc/xray/config.json")) { RunCmd(@"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"); } WriteOutput("安装TLS证书"); InstallCertToXray(); WriteOutput("TLS证书安装完成"); var configJson = XrayConfigBuilder.BuildXrayConfig(Parameters); var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); UploadFile(stream, "/usr/local/etc/xray/config.json"); RunCmd("systemctl restart xray"); }
/// <summary> /// 更新xray配置 /// </summary> public void UpdateXraySettings() { EnsureRootAuth(); EnsureSystemEnv(); ConfigureFirewall(); var configJson = XrayConfigBuilder.BuildXrayConfig(Parameters); var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); RunCmd("rm -rf /usr/local/etc/xray/config.json"); UploadFile(stream, "/usr/local/etc/xray/config.json"); ConfigurePort(); UploadCaddyFile(string.IsNullOrEmpty(Parameters.MaskDomain)); RunCmd("systemctl restart xray"); WriteOutput("************ 更新Xray配置成功,更新配置不包含域名,如果域名更换请重新安装。 ************"); }
public void UpdateSettings() { Task.Factory.StartNew(() => { try { Progress.Step = "更新Xray配置"; Progress.Percentage = 0; EnsureRootUser(); var index = 0; Progress.Desc = $"{index++}. 检测系统环境"; EnsureSystemEnv(); Progress.Percentage = 20; Progress.Desc = $"{index++}. 配置防火墙"; RunCmd("systemctl stop xray"); RunCmd("systemctl stop caddy"); ConfigFirewalld(); Progress.Percentage = 40; Progress.Desc = $"{index++}. 上传Xray配置文件"; var configJson = XrayConfigBuilder.BuildXrayConfig(Settings); WriteToFile(configJson, "/usr/local/etc/xray/config.json"); Progress.Percentage = 70; Progress.Desc = $"{index++}. 上传Caddy配置文件"; UploadCaddyFile(); Progress.Percentage = 90; Progress.Desc = $"{index++}. 重启xray服务"; RunCmd("systemctl restart caddy"); RunCmd("systemctl restart xray"); Progress.Percentage = 100; Progress.Desc = ("更新配置成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }); }
private void InstallXray() { Progress.Desc = ("开始安装Xray-Core"); RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); if (!FileExists("/usr/local/bin/xray")) { Progress.Desc = ("Xray-Core安装失败,请联系开发者"); throw new Exception("Xray-Core安装失败,请联系开发者"); } Progress.Desc = ("设置Xray-core权限"); RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"); RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/xray.service"); RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/xray.service"); RunCmd($"systemctl daemon-reload"); if (FileExists("/usr/local/etc/xray/config.json")) { RunCmd(@"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"); } Progress.Percentage = 60; if (Settings.WithTLS && !Settings.IsIPAddress) { Progress.Desc = ("安装TLS证书"); InstallCert( dirPath: "/usr/local/etc/xray/ssl", certName: "xray_ssl.crt", keyName: "xray_ssl.key"); Progress.Percentage = 75; } Progress.Desc = ("生成Xray服务器配置文件"); var configJson = XrayConfigBuilder.BuildXrayConfig(Settings); WriteToFile(configJson, "/usr/local/etc/xray/config.json"); }