Exemple #1
0
        private void ToSSRJson()
        {
            var oSSR = new SSR();

            oSSR.configs = new List <Server>();
            // ConfigFromHtml(oSSR);
            ConfigFromJsonTxt(oSSR);
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(oSSR);

            System.IO.File.WriteAllText(getFilePath("ssr.json"), json);
            var sOutFile = $"{SSR_EXE_PATH}\\ssr.json";

            if (System.IO.File.Exists(sOutFile))
            {
                System.IO.File.Delete(sOutFile);
            }
            System.IO.File.Copy(getFilePath("ssr.json"), sOutFile);
            write_gui_config(sOutFile);
        }
Exemple #2
0
        /// <summary>
        /// 配置从Html来
        /// </summary>
        /// <param name="oSSR"></param>
        private void ConfigFromHtml(SSR oSSR)
        {
            var sFile = getFilePath("2.html");

            CsQuery.CQ dom = System.IO.File.ReadAllText(sFile);

            foreach (var row in dom["tr"])
            {
                CsQuery.CQ rowDom = row.InnerHTML;
                var        tds    = rowDom["td"].ToList();
                var        config = new Server();
                if (tds.Count > 0)
                {
                    var vtm = tds[0].InnerText;
                    try
                    {
                        if (int.Parse(vtm.Split('/')[1]) > 8) //T是电信线路,值越大越好
                        {
                            config.server      = tds[1].InnerText;
                            config.server_port = int.Parse(tds[2].InnerText);
                            var p1 = tds[3].InnerText;
                            var p2 = tds[4].InnerText;
                            if (p1 == "rc4-md5" || p1 == "chacha20" || p1.StartsWith("aes-"))
                            {
                                config.method   = p1;
                                config.password = p2;
                            }
                            else
                            {
                                config.method   = p2;
                                config.password = p1;
                            }
                            config.id = Guid.NewGuid().ToString("N");
                        }
                        if (!string.IsNullOrWhiteSpace(config.server))
                        {
                            oSSR.configs.Add(config);
                        }
                    }
                    catch { }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 配置从Html来
        /// </summary>
        /// <param name="oSSR"></param>
        private void ConfigFromJsonTxt(SSR oSSR)
        {
            var sFile = txtLogFilePath.Text;
            var txt   = System.IO.File.ReadAllText(txtLogFilePath.Text);
            var data  = JArray.Parse(txt);

            foreach (var item in data)
            {
                var config = new Server();
                var vtm    = item[0].ToString();
                try
                {
                    if (int.Parse(vtm.Split('/')[1]) > 8) //T是电信线路,值越大越好
                    {
                        config.server      = item[1].ToString();
                        config.server_port = int.Parse(item[2].ToString());
                        var p1 = item[3].ToString();
                        var p2 = item[4].ToString();
                        if (p1 == "rc4-md5" || p1 == "chacha20" || p1.StartsWith("aes-"))
                        {
                            config.method   = p1;
                            config.password = p2;
                        }
                        else
                        {
                            config.method   = p2;
                            config.password = p1;
                        }
                        config.id = Guid.NewGuid().ToString("N");
                    }
                    if (!string.IsNullOrWhiteSpace(config.server))
                    {
                        oSSR.configs.Add(config);
                    }
                }
                catch { }
                Console.WriteLine(item);
            }
        }