Exemple #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            ServerProfile serverProfile = new ServerProfile();

            addedProfiles.Add(serverProfile);
            refreshListServBox(addedProfiles.Count() - 1);
        }
Exemple #2
0
        public ServerProfile ImportVmess(string vmessUrl)
        {
            VmessConf     vmessConf = js.Deserialize <VmessConf>(Utils.Base64Decode(vmessUrl.Substring(8)));
            ServerProfile tmp       = Utils.GenVmessConfig(vmessConf);

            //tmp.groupId = groupId;
            //subsProfiles.Add(tmp);
            return(tmp);
        }
Exemple #3
0
        List <string> ImportURL(string importUrl, SubsProfile subsProfile)
        {
            List <string> linkMark = new List <string>();

            foreach (var link in importUrl.Split(Environment.NewLine.ToCharArray()))
            {
                if (link.StartsWith("vmess"))
                {
                    ServerProfile sp = ImportVmess(link);
                    linkMark.Add(sp.remark);
                    sp.groupId = subsProfile.groupId;
                    subsProfile.VmessConfList.Add(sp);
                    subsProfiles.Add(sp);
                }
            }
            Debug.WriteLine("importurl " + String.Join(",", linkMark));
            return(linkMark);
        }
Exemple #4
0
        private void FormTransSetting_Load(object sender, EventArgs e)
        {
            currentProfile = Program.mainForm.configForm.SelectedProfile();
            JavaScriptSerializer js = new JavaScriptSerializer();

            // load current settings to view
            //kcp
            dynamic streamSettings = currentProfile.streamSettings;

            textBoxKcpMtu.Text           = streamSettings["kcpSettings"]["mtu"].ToString();
            textBoxKcpTti.Text           = streamSettings["kcpSettings"]["tti"].ToString();
            textBoxKcpUc.Text            = streamSettings["kcpSettings"]["uplinkCapacity"].ToString();
            textBoxKcpDc.Text            = streamSettings["kcpSettings"]["downlinkCapacity"].ToString();
            textBoxKcpRb.Text            = streamSettings["kcpSettings"]["readBufferSize"].ToString();
            textBoxKcpWb.Text            = streamSettings["kcpSettings"]["writeBufferSize"].ToString();
            comboBoxKcpCon.SelectedIndex = streamSettings["kcpSettings"]["congestion"] == false ? 0 : 1;
            var headertype = streamSettings["kcpSettings"]["header"]["type"].ToString();

            comboBoxKcpHt.SelectedIndex = headertype == "wechat-video" ? 3 : (int)Enum.Parse(typeof(KcpHeaderType), headertype);

            //tcp
            checkBoxTcpHeader.Checked = streamSettings["tcpSettings"]["header"]["type"] == "none" ? false : true;
            if (checkBoxTcpHeader.Checked)
            {
                textBoxTcpHeader.Text = js.Serialize(streamSettings["tcpSettings"]["header"]);
            }
            else
            {
                textBoxTcpHeader.Text = "{\"type\": \"none\"}";
            }

            // ws
            textBoxWsPath.Text   = streamSettings["wsSettings"]["path"];
            textBoxWsHeader.Text = js.Serialize(streamSettings["wsSettings"]["headers"]);

            //http2
            textBoxHttp2Path.Text = streamSettings["httpSettings"]["path"];
            System.Collections.ArrayList httpHosts = streamSettings["httpSettings"]["host"];
            List <string> hostList = new List <string>();

            foreach (var h in httpHosts)
            {
                hostList.Add(h.ToString());
            }
            if (hostList.Count > 0)
            {
                textBoxHttp2Hosts.Text = String.Join(",", hostList);
            }
            else
            {
                textBoxHttp2Hosts.Text = "";
            }

            // tls
            checkBoxTLSEnable.Checked = streamSettings["security"] == "tls";
            checkBoxTLSAI.Checked     = streamSettings["tlsSettings"]["allowInsecure"];
            textBoxTLSSn.Text         = streamSettings["tlsSettings"]["serverName"];

            // mux
            dynamic muxSettings = currentProfile.muxSettings;

            checkBoxMuxEnable.Checked = muxSettings["enabled"];
            textBoxMuxCc.Text         = muxSettings["concurrency"].ToString();

            // proxy
            //checkBoxProxy.Checked = currentProfile.proxyOutboundJson.Length > 0;
            //textBoxOutProxyJson.Text = currentProfile.proxyOutboundJson;
        }
        /// <summary>
        /// gen Vmess Config
        /// </summary>
        /// <param name=vmessConf></param>
        /// <returns></returns>
        public static ServerProfile GenVmessConfig(VmessConf vmessConf)
        {
            ServerProfile serverProfile = new ServerProfile();

            //Dictionary<string, object> VmessProfiles = Utils.VmessOutboundTemplateNew();
            Dictionary <string, object> muxSettings    = serverProfile.muxSettings;
            Dictionary <string, object> streamSettings = serverProfile.streamSettings;
            //Dictionary<string, object> settings = VmessProfiles["settings"] as Dictionary<string, object>;
            //Dictionary<string, object> vnext = (settings["vnext"] as IList<object>)[0] as Dictionary<string, object>;
            //Dictionary<string, object> UserInfo = (vnext["users"] as IList<object>)[0] as Dictionary<string, object>;
            Dictionary <string, object> kcpSettings   = streamSettings["kcpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> kcpSettingsT  = kcpSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> tcpSettings   = streamSettings["tcpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> tcpSettingsT  = tcpSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> wsSettings    = streamSettings["wsSettings"] as Dictionary <string, object>;
            Dictionary <string, object> wsSettingsT   = wsSettings["headers"] as Dictionary <string, object>;
            Dictionary <string, object> httpSettings  = streamSettings["httpSettings"] as Dictionary <string, object>;
            Dictionary <string, object> quicSettings  = streamSettings["quicSettings"] as Dictionary <string, object>;
            Dictionary <string, object> quicSettingsT = quicSettings["header"] as Dictionary <string, object>;
            Dictionary <string, object> tlsSettings   = streamSettings["tlsSettings"] as Dictionary <string, object>;


            serverProfile.address = vmessConf.add;
            serverProfile.port    = Convert.ToInt32(vmessConf.port);
            serverProfile.userId  = vmessConf.id;
            serverProfile.alterId = Convert.ToInt32(vmessConf.aid);
            serverProfile.remark  = vmessConf.ps;
            serverProfile.tag     = vmessConf.ps;
            serverProfile.network = (NetWorkType)Enum.Parse(typeof(NetWorkType), vmessConf.net, true);

            //streamSettings["network"] = vmessConf.net == "h2" ? "http" : vmessConf.net;
            streamSettings["security"] = vmessConf.tls == "" ? "none" : vmessConf.tls;
            //tlsSettings["serverName"] = vmessConf.add;

            string type = vmessConf.type == null ? "none" : vmessConf.type;

            switch (vmessConf.net)
            {
            case "ws":
                wsSettingsT["Host"] = vmessConf.host;
                wsSettings["path"]  = vmessConf.path;
                break;

            case "h2":
                httpSettings["host"] = vmessConf.host.Split(',');
                httpSettings["path"] = vmessConf.path;
                break;

            case "tcp":
                tcpSettingsT["type"] = type;
                break;

            case "kcp":
                kcpSettingsT["type"] = type;
                break;

            case "quic":
                quicSettingsT["type"]    = type;
                quicSettings["security"] = vmessConf.host;
                quicSettings["key"]      = vmessConf.path;
                break;

            default:
                break;
            }
            return(serverProfile);
        }