Example #1
0
        public byte[] VeeConfig2Bytes(Models.Datas.VeeConfigs veeConfig)
        {
            var vee = new Models.VeeShareLinks.Http3b();

            vee.CopyFromVeeConfig(veeConfig);
            return(vee.ToBytes());
        }
Example #2
0
        public byte[] VeeConfig2Bytes(Models.Datas.VeeConfigs veeConfig)
        {
            var vee = new Models.VeeShareLinks.Obsolete.Vmess0a();

            vee.CopyFromVeeConfig(veeConfig);
            return(vee.ToBytes());
        }
Example #3
0
        public string VeeConfig2VeeLink(Models.Datas.VeeConfigs vc)
        {
            var proto = vc?.proto;

            if (encoders.ContainsKey(proto))
            {
                var encoder = encoders[proto];
                var b       = encoder.VeeConfig2Bytes(vc);
                return(Bytes2VeeLink(b));
            }
            return(null);
        }
Example #4
0
        public void FromCoreConfig(string config)
        {
            var sc = new Models.Datas.VeeConfigs(config);

            tboxName.Text        = sc.name;
            tboxDescription.Text = sc.description;

            SelectByText(cboxProtocol, sc.proto);

            tboxHost.Text = sc.host;
            tboxPort.Text = sc.port.ToString();

            tboxAuth1.Text = sc.auth1;
            cboxAuth2.Text = sc.auth2;

            var st = string.IsNullOrEmpty(sc.streamType) ? StreamTypeNone : sc.streamType;

            SelectByText(cboxStreamType, st);


            if (cboxStreamParma1.DropDownStyle == ComboBoxStyle.DropDownList)
            {
                SelectByText(cboxStreamParma1, sc.streamParam1);
            }
            else
            {
                cboxStreamParma1.Text = sc.streamParam1;
            }
            tboxStreamParam2.Text = sc.streamParam2;
            tboxStreamParam3.Text = sc.streamParam3;

            var tt = string.IsNullOrEmpty(sc.tlsType) ? StreamTypeNone : sc.tlsType;

            SelectByText(cboxTlsType, tt);
            tboxTlsServName.Text = sc.tlsServName;

            chkTlsCertSelfSign.Checked = sc.useSelfSignCert;
        }
Example #5
0
        public string ToVeeShareLink()
        {
            var sc = new Models.Datas.VeeConfigs();

            sc.name        = tboxName.Text;
            sc.description = tboxDescription.Text;
            sc.proto       = cboxProtocol.Text;
            sc.host        = tboxHost.Text;
            sc.port        = VgcApis.Misc.Utils.Str2Int(tboxPort.Text);
            sc.auth1       = tboxAuth1.Text;
            sc.auth2       = cboxAuth2.Text;
            sc.streamType  = cboxStreamType.Text;

            sc.tlsType         = cboxTlsType.Text;
            sc.tlsServName     = tboxTlsServName.Text;
            sc.useSelfSignCert = chkTlsCertSelfSign.Checked;

            sc.streamParam1 = cboxStreamParma1.Text;
            sc.streamParam2 = tboxStreamParam2.Text;
            sc.streamParam3 = tboxStreamParam3.Text;

            return(sc.ToVeeShareLink());
        }
Example #6
0
        Models.Datas.VeeConfigs ParseTrojanUrl(string url)
        {
            var proto  = "trojan";
            var header = proto + "://";

            if (!url.StartsWith(header))
            {
                return(null);
            }

            var port = url.Split(':').LastOrDefault();

            if (string.IsNullOrEmpty(port))
            {
                return(null);
            }

            var body = url.Substring(header.Length, url.Length - header.Length - port.Length - 1);
            var pa   = body.Split('@');

            if (pa.Length != 2)
            {
                return(null);
            }

            var vc = new Models.Datas.VeeConfigs();

            vc.proto = proto;
            vc.host  = pa[1];
            vc.port  = VgcApis.Misc.Utils.Str2Int(port);
            vc.auth1 = Uri.UnescapeDataString(pa[0]);

            vc.streamType   = "tcp";
            vc.tlsType      = "tls";
            vc.streamParam1 = "none";
            return(vc);
        }
Example #7
0
 public byte[] VeeConfig2Bytes(Models.Datas.VeeConfigs veeConfig)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public override void CopyFromVeeConfig(Models.Datas.VeeConfigs vc)
 {
     base.CopyFromVeeConfig(vc);
     userName     = vc.auth1;
     userPassword = vc.auth2;
 }
Example #9
0
 public override void CopyFromVeeConfig(Models.Datas.VeeConfigs vc)
 {
     base.CopyFromVeeConfig(vc);
     uuid = Guid.Parse(vc.auth1);
 }
Example #10
0
        public string Encode(string config)
        {
            var vc = new Models.Datas.VeeConfigs(config);

            if (vc.proto != @"vless")
            {
                return(null);
            }

            var ps = new Dictionary <string, string>();

            ps["type"]     = vc.streamType;
            ps["security"] = vc.tlsType;

            if (!string.IsNullOrWhiteSpace(vc.auth2))
            {
                ps["flow"] = vc.auth2;
            }

            if (!string.IsNullOrWhiteSpace(vc.tlsServName))
            {
                ps["sni"] = vc.tlsServName;
            }

            switch (vc.streamType)
            {
            case "grpc":
                ps["serviceName"] = vc.streamParam2;
                ps["mode"]        = vc.streamParam1 == @"false" ? "gun" : "multi";
                // 不知道guna怎么配置T.T
                break;

            case "ws":
            case "h2":
                if (!string.IsNullOrWhiteSpace(vc.streamParam1))
                {
                    ps["path"] = vc.streamParam1;
                }
                if (!string.IsNullOrWhiteSpace(vc.streamParam2))
                {
                    ps["host"] = vc.streamParam2;
                }
                break;

            case "kcp":
                if (!string.IsNullOrWhiteSpace(vc.streamParam1))
                {
                    ps["headerType"] = vc.streamParam1;
                }
                if (!string.IsNullOrWhiteSpace(vc.streamParam2))
                {
                    ps["seed"] = vc.streamParam2;
                }
                break;

            case "quic":
                if (!string.IsNullOrWhiteSpace(vc.streamParam2))
                {
                    ps["quicSecurity"] = vc.streamParam2;
                }
                if (!string.IsNullOrWhiteSpace(vc.streamParam3))
                {
                    ps["key"] = vc.streamParam3;
                }
                if (!string.IsNullOrWhiteSpace(vc.streamParam1))
                {
                    ps["headerType"] = vc.streamParam1;
                }
                break;

            default:
                break;
            }

            var pms = ps
                      .Select(kv => string.Format("{0}={1}", kv.Key, Uri.EscapeDataString(kv.Value)))
                      .ToList();

            var url = string.Format(
                "{0}://{1}@{2}:{3}?{4}#{5}",
                vc.proto,
                Uri.EscapeDataString(vc.auth1),
                Uri.EscapeDataString(vc.host),
                vc.port,
                string.Join("&", pms),
                Uri.EscapeDataString(vc.name));

            return(url);
        }
Example #11
0
        Models.Datas.VeeConfigs ParseVlessUrl(string url)
        {
            var proto  = "vless";
            var header = proto + "://";

            if (!url.StartsWith(header))
            {
                return(null);
            }

            // 抄袭自: https://github.com/musva/V2RayW/commit/e54f387e8d8181da833daea8464333e41f0f19e6 GPLv3
            List <string> parts = url
                                  .Substring(header.Length)
                                  .Split(new char[6] {
                ':', '@', '?', '&', '#', '='
            }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(s => Uri.UnescapeDataString(s))
                                  .ToList();

            if (parts.Count < 5)
            {
                return(null);
            }

            var vc = new Models.Datas.VeeConfigs();

            vc.name  = parts.Last();
            vc.proto = proto;
            vc.host  = parts[1];
            vc.port  = VgcApis.Misc.Utils.Str2Int(parts[2]);
            vc.auth1 = parts[0];

            string GetValue(string key, string def)
            {
                return(parts.Contains(key) ? parts[parts.IndexOf(key) + 1] : def);
            }

            if (parts.Contains("flow"))
            {
                vc.auth2 = parts[parts.IndexOf("flow") + 1];
            }

            vc.streamType = GetValue("type", "tcp");

            vc.tlsType     = GetValue("security", "none");
            vc.tlsServName = GetValue("sni", parts[1]);

            switch (vc.streamType)
            {
            case "grpc":
                vc.streamParam2 = GetValue("serviceName", @"");
                vc.streamParam1 = (GetValue("mode", @"multi") == "multi").ToString().ToLower();
                // 不知道guna怎么配置T.T
                break;

            case "ws":
            case "h2":
                vc.streamParam2 = GetValue("host", parts[1]);
                vc.streamParam1 = GetValue("path", "/");
                break;

            case "tcp":
                // 木有 tcp.http ??
                vc.streamParam1 = "none";
                break;

            case "kcp":
                vc.streamParam1 = GetValue("headerType", "none");
                if (parts.Contains("seed"))
                {
                    vc.streamParam2 = parts[parts.IndexOf("seed") + 1];
                }
                break;

            case "quic":
                vc.streamParam2 = GetValue("quicSecurity", "none");
                vc.streamParam3 = GetValue("key", "");
                vc.streamParam1 = GetValue("headerType", "none");
                break;

            default:
                break;
            }

            return(vc);
        }