Example #1
0
        public void TestServerFromSSR()
        {
            const string normalCase =
                "ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUQ";

            var server = (ShadowsocksR)ShareLink.ParseText(normalCase).First();

            Assert.AreEqual(server.Hostname, "127.0.0.1");
            Assert.AreEqual(server.Port, (ushort)1234);
            Assert.AreEqual(server.Protocol, "auth_aes128_md5");
            Assert.AreEqual(server.EncryptMethod, "aes-128-cfb");
            Assert.AreEqual(server.OBFS, "tls1.2_ticket_auth");
            Assert.AreEqual(server.OBFSParam, "breakwa11.moe");
            Assert.AreEqual(server.Password, "aaabbb");


            const string normalCaseWithRemark =
                "ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUSZyZW1hcmtzPTVyV0w2Sy1WNUxpdDVwYUg";

            server = (ShadowsocksR)ShareLink.ParseText(normalCaseWithRemark).First();
            Assert.AreEqual(server.Hostname, "127.0.0.1");
            Assert.AreEqual(server.Port, (ushort)1234);
            Assert.AreEqual(server.Protocol, "auth_aes128_md5");
            Assert.AreEqual(server.EncryptMethod, "aes-128-cfb");
            Assert.AreEqual(server.OBFS, "tls1.2_ticket_auth");
            Assert.AreEqual(server.OBFSParam, "breakwa11.moe");
            Assert.AreEqual(server.Password, "aaabbb");
            Assert.AreEqual(server.Remark, "测试中文");
        }
Example #2
0
        private void ImportServersFromClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var texts = Clipboard.GetText();

            if (!string.IsNullOrWhiteSpace(texts))
            {
                Global.Settings.Server.AddRange(ShareLink.ParseText(texts));
                NotifyTip(i18N.TranslateFormat("Import {0} server(s) form Clipboard", ShareLink.ParseText(texts).Count));

                InitServer();
                Configuration.Save();
            }
        }
Example #3
0
        public void ParseV2RayNFormatUri()
        {
            var server = (VMess)ShareLink.ParseText(
                @"vmess://eyAidiI6ICIyIiwgInBzIjogIuWkh+azqOWIq+WQjSIsICJhZGQiOiAiMTExLjExMS4xMTEuMTExIiwgInBvcnQiOiAiMzIwMDAiLCAiaWQiOiAiMTM4NmY4NWUtNjU3Yi00ZDZlLTlkNTYtNzhiYWRiNzVlMWZkIiwgImFpZCI6ICIxMDAiLCAibmV0IjogInRjcCIsICJ0eXBlIjogIm5vbmUiLCAiaG9zdCI6ICJ3d3cuYmJiLmNvbSIsICJwYXRoIjogIi8iLCAidGxzIjogInRscyIgfQ==")
                         .First();

            Assert.AreEqual(server.Remark, "备注别名");
            Assert.AreEqual(server.Hostname, "111.111.111.111");
            Assert.AreEqual(server.Port, (ushort)32000);
            Assert.AreEqual(server.UserID, "1386f85e-657b-4d6e-9d56-78badb75e1fd");
            Assert.AreEqual(server.AlterID, 100);
            Assert.AreEqual(server.TransferProtocol, "tcp");
            Assert.AreEqual(server.FakeType, "none");
            Assert.AreEqual(server.Host, "www.bbb.com");
            Assert.AreEqual(server.Path, "/");
            Assert.AreEqual(server.TLSSecureType, "tls");
        }
Example #4
0
        public void ParseVLESSUri()
        {
            var servers = ShareLink.ParseText(@"vmess://[email protected]:31415?encryption=none#VMessTCPNaked
vmess://[email protected]:9265#VMessTCPAuto
vmess://[email protected]:35897?encryption=aes-128-gcm#VMessTCPAES
vmess://[email protected]:9323?encryption=none&security=tls#VMessTCPTLSNaked
vmess://[email protected]:8462?security=tls#VMessTCPTLS
vmess://[email protected]:64338?encryption=none&security=tls&sni=fastgit.org#VMessTCPTLSSNI
vless://[email protected]:3279?security=xtls&flow=rprx-xtls-splice#VLESSTCPXTLSSplice
vless://[email protected]:50288?type=kcp&seed=69f04be3-d64e-45a3-8550-af3172c63055#VLESSmKCPSeed
vless://[email protected]:41971?type=kcp&headerType=wireguard&seed=69f04be3-d64e-45a3-8550-af3172c63055#VLESSmKCPSeedWG
vmess://[email protected]:6939?type=ws&security=tls&host=qv2ray.net&path=%2Fsomewhere#VMessWebSocketTLS");

            foreach (var server in servers)
            {
                var jsonSerializerOptions = Global.NewDefaultJsonSerializerOptions;
                jsonSerializerOptions.WriteIndented = false;
                Console.WriteLine(JsonSerializer.Serialize <object>(server, jsonSerializerOptions) + "\n");
                Assert.IsNotNull(server);

                Assert.AreEqual(server.Hostname, "qv2ray.net");
            }
        }
Example #5
0
        private void ImportServersFromClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var texts = Clipboard.GetText();

            if (!string.IsNullOrWhiteSpace(texts))
            {
                var result = ShareLink.ParseText(texts);

                if (result != null)
                {
                    foreach (var server in result)
                    {
                        Global.Settings.Server.Add(server);
                    }
                }
                else
                {
                    MessageBoxX.Show(i18N.Translate("Import servers error!"), LogLevel.ERROR);
                }

                InitServer();
                Configuration.Save();
            }
        }
Example #6
0
        public async Task UpdateServersFromSubscribe()
        {
            void DisableItems(bool v)
            {
                MenuStrip.Enabled = ConfigurationGroupBox.Enabled = ProfileGroupBox.Enabled = ControlButton.Enabled = v;
            }

            if (Global.Settings.UseProxyToUpdateSubscription && ServerComboBox.SelectedIndex == -1)
            {
                Global.Settings.UseProxyToUpdateSubscription = false;
            }

            if (Global.Settings.UseProxyToUpdateSubscription && ServerComboBox.SelectedIndex == -1)
            {
                MessageBoxX.Show(i18N.Translate("Please select a server first"));
                return;
            }

            if (Global.Settings.SubscribeLink.Count <= 0)
            {
                MessageBoxX.Show(i18N.Translate("No subscription link"));
                return;
            }

            StatusText(i18N.Translate("Starting update subscription"));
            DisableItems(false);
            try
            {
                if (Global.Settings.UseProxyToUpdateSubscription)
                {
                    var mode = new Models.Mode
                    {
                        Remark = "ProxyUpdate",
                        Type   = 5
                    };
                    await MainController.Start(ServerComboBox.SelectedItem as Server, mode);
                }

                var serverLock = new object();

                await Task.WhenAll(Global.Settings.SubscribeLink.Select(async item => await Task.Run(async() =>
                {
                    try
                    {
                        var request = WebUtil.CreateRequest(item.Link);

                        if (!string.IsNullOrEmpty(item.UserAgent))
                        {
                            request.UserAgent = item.UserAgent;
                        }
                        if (Global.Settings.UseProxyToUpdateSubscription)
                        {
                            request.Proxy = new WebProxy($"http://127.0.0.1:{Global.Settings.HTTPLocalPort}");
                        }

                        var str = await WebUtil.DownloadStringAsync(request);

                        lock (serverLock)
                        {
                            Global.Settings.Server.RemoveAll(server => server.Group == item.Remark);

                            var result = ShareLink.ParseText(str);
                            if (result != null)
                            {
                                foreach (var server in result)
                                {
                                    server.Group = item.Remark;
                                    Global.Settings.Server.Add(server);
                                }
                            }

                            NotifyTip(i18N.TranslateFormat("Update {1} server(s) from {0}", item.Remark, result?.Count ?? 0));
                        }
                    }
                    catch (WebException e)
                    {
                        NotifyTip($"{i18N.TranslateFormat("Update servers error from {0}", item.Remark)}\n{e.Message}", info: false);
                    }
                    catch (Exception e)
                    {
                        Logging.Error(e.ToString());
                    }
                })).ToArray());

                InitServer();
                Configuration.Save();
                StatusText(i18N.Translate("Subscription updated"));
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                if (Global.Settings.UseProxyToUpdateSubscription)
                {
                    await MainController.Stop();
                }

                DisableItems(true);
            }
        }