public string ImportShadowsocks(string url) { var link = url.Contains("#") ? url.Substring(5, url.IndexOf("#") - 5) : url.Substring(5); var tag = url.Contains("#") ? url.Substring(url.IndexOf("#") + 1).Trim() : "Newtag" + new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000); var linkParseArray = ExtraUtils.Base64Decode(link).Split(new char[2] { ':', '@' }); Dictionary <string, object> ShadowsocksProfiles = Utilities.outboundTemplate; Dictionary <string, object> ShadowsocksTemplate = Utilities.ShadowsocksOutboundTemplateNew(); ShadowsocksProfiles["protocol"] = "shadowsocks"; ShadowsocksProfiles["tag"] = tag; ShadowsocksTemplate["email"] = "*****@*****.**"; ShadowsocksTemplate["address"] = linkParseArray[2]; ShadowsocksTemplate["port"] = Convert.ToInt32(linkParseArray[3]); ShadowsocksTemplate["method"] = linkParseArray[0]; ShadowsocksTemplate["password"] = linkParseArray[1]; ShadowsocksTemplate["ota"] = false; ShadowsocksTemplate["level"] = 0; ShadowsocksProfiles["settings"] = new Dictionary <string, object> { { "servers", new List <Dictionary <string, object> > { ShadowsocksTemplate } } }; outbounds.Add(Utilities.DeepClone(ShadowsocksProfiles)); return(tag); }
private void HideWindow(object sender, RoutedEventArgs e) { if (sender == saveConfigButton) { try { UInt16.Parse(localPortBox.Text); UInt16.Parse(httpPortBox.Text); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Not a valid port number!"); return; } Dictionary <string, Dictionary <string, object> > allUniqueTagOutbounds = new Dictionary <string, Dictionary <string, object> >(); List <Dictionary <string, object> > allOutbounds = new List <Dictionary <string, object> >(profiles); allOutbounds.AddRange(outbounds); foreach (Dictionary <string, object> outbound in allOutbounds) { if (outbound["tag"] as string == "") { MessageBox.Show("tag can not be empty"); return; } if (Utilities.RESERVED_TAGS.FindIndex(x => x == outbound["tag"] as string) != -1) { MessageBox.Show($"tag {outbound["tag"]} is reserved."); return; } if (allUniqueTagOutbounds.ContainsKey(outbound["tag"] as string)) { MessageBox.Show($"tag {outbound["tag"]} is not unique"); return; } else { allUniqueTagOutbounds[outbound["tag"] as string] = outbound; } } mainWindow.profiles = new List <Dictionary <string, object> >(allUniqueTagOutbounds.Values); mainWindow.routingRuleSets = routingRuleSets; mainWindow.subscribeUrl = subscribeUrl; mainWindow.httpPort = UInt16.Parse(httpPortBox.Text); mainWindow.localPort = UInt16.Parse(localPortBox.Text); mainWindow.dnsString = dnsBox.Text; mainWindow.enableRestore = enableRestore; mainWindow.shareOverLan = shareOverLanBox.IsChecked ?? false; mainWindow.udpSupport = udpSupportBox.IsChecked ?? false; mainWindow.logLevel = logLevelBox.SelectedItem.ToString(); mainWindow.OverallChanged(this, null); ExtraUtils.AutoStartSet((bool)autoStartBox.IsChecked); } this.Close(); }
private void ImportClipboard_Click(object sender, RoutedEventArgs e) { try { ImportURL(ExtraUtils.GetClipboardData()); RefreshListBox(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "format exception!"); return; } }
void subscribeWorker_DoWork(object sender, DoWorkEventArgs e) { mainWindow.subscribeTag = ""; List <string> subscribeTag = new List <string>(); foreach (string url in subscribeUrl) { var tag = ImportURL(ExtraUtils.Base64Decode(ExtraUtils.GetUrl(url))); subscribeTag = subscribeTag.Concat(tag).ToList(); this.Dispatcher.Invoke(() => { RefreshListBox(); }); } mainWindow.subscribeTag = String.Join(",", subscribeTag); }
public void InitializeData() { // copy data routingRuleSets = Utilities.DeepClone(mainWindow.routingRuleSets); subscribeUrl = Utilities.DeepClone(mainWindow.subscribeUrl); enableRestore = mainWindow.enableRestore; outbounds = new List <Dictionary <string, object> >(); profiles = new List <Dictionary <string, object> >(); foreach (Dictionary <string, object> outbound in Utilities.DeepClone(mainWindow.profiles)) { if (VmessForUI(outbound)) { Utilities.AddMissingKeysForVmess(outbound); profiles.Add(outbound); } else { outbounds.Add(outbound); } } // fill in data autoStartBox.IsChecked = ExtraUtils.AutoStartCheck(); udpSupportBox.IsChecked = mainWindow.udpSupport; shareOverLanBox.IsChecked = mainWindow.shareOverLan; localPortBox.Text = mainWindow.localPort.ToString(); httpPortBox.Text = mainWindow.httpPort.ToString(); dnsBox.Text = mainWindow.dnsString; logLevelBox.SelectedIndex = Utilities.LOG_LEVEL_LIST.FindIndex(x => x == mainWindow.logLevel); vmessListBox.Items.Clear(); foreach (Dictionary <string, object> profile in profiles) { vmessListBox.Items.Add(profile["tag"]); } vmessListBox.SelectionChanged += VmessListBox_SelectionChanged; vmessListBox.SelectedIndex = 0; coreVersionCheckWorker.DoWork += CoreVersionCheckWorker_DoWork; coreVersionCheckWorker.RunWorkerAsync(); }
void threadSpeedTest(Dictionary <string, object> outbound, int tag) { try { Process v2rayProcessTest = new Process(); v2rayProcessTest.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"v2ray-core\v2ray.exe"; v2rayJsonConfigTest = GenerateConfigFileTest(outbound, tag); v2rayProcessTest.StartInfo.Arguments = @" -config http://127.0.0.1:18000/test/config.json"; #if DEBUG v2rayProcessTest.StartInfo.WindowStyle = ProcessWindowStyle.Normal; #else v2rayProcessTest.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; #endif v2rayProcessTest.Start(); speedTestResultDic.Add(outbound["tag"].ToString(), ExtraUtils.GetHttpStatusTime(SpeedTestUrl, httpPort + tag)); v2rayProcessTest.Kill(); Debug.WriteLine("outbonds result : {0} {1}", outbound["tag"].ToString(), speedTestResultDic[outbound["tag"].ToString()]); } catch {} }
public string ImportVmess(string url) { Dictionary <string, object> VmessProfiles = Utilities.VmessOutboundTemplateNew(); Dictionary <string, object> muxSettings = VmessProfiles["mux"] as Dictionary <string, object>; Dictionary <string, object> streamSettings = VmessProfiles["streamSettings"] as Dictionary <string, object>; 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>; VmessLink VmessLink = JsonConvert.DeserializeObject <VmessLink>(ExtraUtils.Base64Decode(url.Substring(8))); UserInfo["id"] = VmessLink.id; UserInfo["alterId"] = Convert.ToInt32(VmessLink.aid); vnext["address"] = VmessLink.add; vnext["port"] = Convert.ToInt32(VmessLink.port); streamSettings["network"] = VmessLink.net == "h2" ? "http" : VmessLink.net; streamSettings["security"] = VmessLink.tls == "" ? "none" : VmessLink.tls; tlsSettings["serverName"] = VmessLink.add; VmessProfiles["tag"] = VmessLink.ps; switch (VmessLink.net) { case "ws": wsSettingsT["host"] = VmessLink.host; wsSettings["path"] = VmessLink.path; break; case "h2": httpSettings["host"] = VmessLink.host.Split(','); httpSettings["path"] = VmessLink.path; break; case "tcp": tcpSettingsT["type"] = VmessLink.type; break; case "kcp": kcpSettingsT["type"] = VmessLink.type; break; case "quic": quicSettingsT["type"] = VmessLink.type; quicSettings["securty"] = VmessLink.host; quicSettings["key"] = VmessLink.path; break; default: break; } profiles.Add(VmessProfiles); return(VmessLink.ps); }
private void ShareMenuItem_Click(object sender, RoutedEventArgs e) { if (vmessListBox.SelectedIndex >= 0 && vmessListBox.SelectedIndex < profiles.Count) { Dictionary <string, object> selectedProfile = profiles[vmessListBox.SelectedIndex]; Dictionary <string, object> selectedVnext = ((selectedProfile["settings"] as Dictionary <string, object>)["vnext"] as IList <object>)[0] as Dictionary <string, object>; Dictionary <string, object> selectedUserInfo = (selectedVnext["users"] as IList <object>)[0] as Dictionary <string, object>; Dictionary <string, object> streamSettings = selectedProfile["streamSettings"] 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>; VmessLink vlink = new VmessLink(); vlink.v = "2"; vlink.ps = selectedProfile["tag"].ToString(); vlink.add = selectedVnext["address"].ToString(); vlink.port = selectedVnext["port"].ToString(); vlink.id = selectedUserInfo["id"].ToString(); vlink.aid = selectedUserInfo["alterId"].ToString(); vlink.net = streamSettings["network"].ToString(); vlink.tls = streamSettings["security"].ToString(); vlink.type = ""; vlink.host = ""; vlink.path = ""; switch (streamSettings["network"].ToString()) { case "ws": vlink.host = wsSettingsT["host"].ToString(); vlink.path = wsSettings["path"].ToString() == "" ? "/" : wsSettings["path"].ToString(); break; case "http": vlink.net = "h2"; vlink.host = httpSettings.ContainsKey("host") ? String.Join(",", httpSettings["host"] as object[]) : ""; vlink.path = httpSettings["path"].ToString() == "" ? "/" : httpSettings["path"].ToString(); break; case "tcp": vlink.type = tcpSettingsT["type"].ToString() == "" ? "none" : tcpSettingsT["type"].ToString(); break; case "kcp": vlink.type = kcpSettingsT["type"].ToString() == "" ? "none" : kcpSettingsT["type"].ToString(); break; case "quic": vlink.type = quicSettingsT["type"].ToString() == "" ? "none" : quicSettingsT["type"].ToString(); vlink.host = quicSettings["securty"].ToString() == "" ? "none" : quicSettings["securty"].ToString(); vlink.path = quicSettings["key"].ToString(); break; default: break; } var sharejson = Utilities.javaScriptSerializer.Serialize(vlink); ExtraUtils.SetClipboardData(ExtraUtils.Base64Encode(sharejson).Insert(0, "vmess://")); } }