Пример #1
0
        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");
        }
Пример #2
0
        private void UploadCaddyFile(bool useCustomWeb = false)
        {
            var configJson = XrayConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb);

            if (FileExists("/etc/caddy/Caddyfile"))
            {
                RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back");
            }
            WriteToFile(configJson, "/etc/caddy/Caddyfile");
        }
Пример #3
0
        private void UploadCaddyFile(bool useCustomWeb = false)
        {
            var configJson = XrayConfigBuilder.BuildCaddyConfig(Parameters, useCustomWeb);
            var stream     = new MemoryStream(Encoding.UTF8.GetBytes(configJson));

            if (FileExists("/etc/caddy/Caddyfile"))
            {
                RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back");
            }
            UploadFile(stream, "/etc/caddy/Caddyfile");
            RunCmd("systemctl restart caddy");
        }
Пример #4
0
        /// <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配置成功,更新配置不包含域名,如果域名更换请重新安装。 ************");
        }
Пример #5
0
        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);
                }
            });
        }
Пример #6
0
        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");
        }