コード例 #1
0
ファイル: V2rayService.cs プロジェクト: yuxuan0107/windows
        private void UploadCaddyFile(bool useCustomWeb = false)
        {
            var configJson = V2rayConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb);

            if (FileExists("/etc/caddy/Caddyfile"))
            {
                RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back");
            }
            WriteToFile(configJson, "/etc/caddy/Caddyfile");
        }
コード例 #2
0
ファイル: V2rayService.cs プロジェクト: yuxuan0107/windows
        public void UpdateSettings()
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    Progress.Step       = "更新V2ray配置";
                    Progress.Percentage = 0;
                    EnsureRootUser();
                    var index = 0;

                    Progress.Desc = $"{index++}. 检测系统环境";
                    EnsureSystemEnv();
                    Progress.Percentage = 20;

                    Progress.Desc = $"{index++}. 配置防火墙";
                    RunCmd("systemctl stop v2ray");
                    RunCmd("systemctl stop caddy");
                    ConfigFirewalld();
                    Progress.Percentage = 40;

                    Progress.Desc  = $"{index++}. 上传V2ray配置文件";
                    var configJson = V2rayConfigBuilder.BuildV2rayConfig(Settings);
                    WriteToFile(configJson, "/usr/local/etc/v2ray/config.json");
                    Progress.Percentage = 70;

                    Progress.Desc = $"{index++}. 上传Caddy配置文件";
                    UploadCaddyFile();
                    Progress.Percentage = 90;

                    Progress.Desc = $"{index++}. 重启v2ray服务";
                    RunCmd("systemctl restart caddy");
                    RunCmd("systemctl restart v2ray");
                    Progress.Percentage = 100;

                    Progress.Desc = ("更新配置成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });
        }
コード例 #3
0
ファイル: V2rayService.cs プロジェクト: yuxuan0107/windows
        private void InstallV2ray()
        {
            Progress.Desc = ("开始安装V2ray-Core");
            RunCmd("bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)");

            if (!FileExists("/usr/local/bin/v2ray"))
            {
                Progress.Desc = ("V2ray-Core安装失败,请联系开发者");
                throw new Exception("V2ray-Core安装失败,请联系开发者");
            }

            Progress.Desc = ("设置V2ray-Core权限");
            RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/v2ray.service");
            RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/v2ray.service");
            RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/v2ray.service");
            RunCmd($"systemctl daemon-reload");
            RunCmd("systemctl enable v2ray");

            if (FileExists("/usr/local/etc/v2ray/config.json"))
            {
                RunCmd(@"mv /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.1");
            }
            Progress.Percentage = 60;

            if (Settings.WithTLS && !Settings.IsIPAddress)
            {
                Progress.Desc = ("安装TLS证书");
                InstallCert(
                    dirPath: "/usr/local/etc/v2ray/ssl",
                    certName: "v2ray_ssl.crt",
                    keyName: "v2ray_ssl.key");
                Progress.Percentage = 75;
            }

            Progress.Desc = ("生成v2ray服务器配置文件");
            var configJson = V2rayConfigBuilder.BuildV2rayConfig(Settings);

            WriteToFile(configJson, "/usr/local/etc/v2ray/config.json");
        }