/// <summary> /// 保存基础设置 /// </summary> /// <returns></returns> private int SaveBase() { //日志 bool logEnabled = chklogEnabled.Checked; string loglevel = cmbloglevel.Text.TrimEx(); //Mux bool muxEnabled = chkmuxEnabled.Checked; //本地监听 string localPort = txtlocalPort.Text.TrimEx(); string protocol = cmbprotocol.Text.TrimEx(); bool udpEnabled = chkudpEnabled.Checked; bool sniffingEnabled = chksniffingEnabled.Checked; if (Utils.IsNullOrEmpty(localPort) || !Utils.IsNumberic(localPort)) { UI.Show(UIRes.I18N("FillLocalListeningPort")); return(-1); } if (Utils.IsNullOrEmpty(protocol)) { UI.Show(UIRes.I18N("PleaseSelectProtocol")); return(-1); } config.inbound[0].localPort = Utils.ToInt(localPort); config.inbound[0].protocol = protocol; config.inbound[0].udpEnabled = udpEnabled; config.inbound[0].sniffingEnabled = sniffingEnabled; //本地监听2 string localPort2 = txtlocalPort2.Text.TrimEx(); string protocol2 = cmbprotocol2.Text.TrimEx(); bool udpEnabled2 = chkudpEnabled2.Checked; bool sniffingEnabled2 = chksniffingEnabled2.Checked; if (chkAllowIn2.Checked) { if (Utils.IsNullOrEmpty(localPort2) || !Utils.IsNumberic(localPort2)) { UI.Show(UIRes.I18N("FillLocalListeningPort")); return(-1); } if (Utils.IsNullOrEmpty(protocol2)) { UI.Show(UIRes.I18N("PleaseSelectProtocol")); return(-1); } if (config.inbound.Count < 2) { config.inbound.Add(new Mode.InItem()); } config.inbound[1].localPort = Utils.ToInt(localPort2); config.inbound[1].protocol = protocol2; config.inbound[1].udpEnabled = udpEnabled2; config.inbound[1].sniffingEnabled = sniffingEnabled2; } else { if (config.inbound.Count > 1) { config.inbound.RemoveAt(1); } } //日志 config.logEnabled = logEnabled; config.loglevel = loglevel; //Mux config.muxEnabled = muxEnabled; //remoteDNS config.remoteDNS = txtremoteDNS.Text.TrimEx(); config.defAllowInsecure = chkdefAllowInsecure.Checked; return(0); }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { if (v2rayUpdateHandle == null) { v2rayUpdateHandle = new V2rayUpdateHandle(); v2rayUpdateHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) { return; } else { v2rayUpdateHandle.DownloadFileAsync(config, url); } })); } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); AppendText(false, UIRes.I18N("MsgUnpacking")); try { CloseV2ray(); string fileName = v2rayUpdateHandle.DownloadFileName; fileName = Utils.GetPath(fileName); using (ZipArchive archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.Length == 0) { continue; } entry.ExtractToFile(Utils.GetPath(entry.Name), true); } } AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); Global.reloadV2ray = true; LoadV2ray(); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); } catch (Exception ex) { AppendText(false, ex.Message); } } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, UIRes.I18N("MsgStartUpdatingV2rayCore")); v2rayUpdateHandle.AbsoluteV2rayCore(config); }
/// <summary> /// 从剪贴板导入URL /// </summary> /// <param name="fileName"></param> /// <param name="msg"></param> /// <returns></returns> public static VmessItem ImportFromClipboardConfig(string clipboardData, out string msg) { msg = string.Empty; VmessItem vmessItem = new VmessItem(); try { //载入配置文件 string result = clipboardData.TrimEx();// Utils.GetClipboardData(); if (Utils.IsNullOrEmpty(result)) { msg = UIRes.I18N("FailedReadConfiguration"); return(null); } if (result.StartsWith(Global.vmessProtocol)) { int indexSplit = result.IndexOf("?"); if (indexSplit > 0) { vmessItem = ResolveStdVmess(result) ?? ResolveVmess4Kitsunebi(result); } else { vmessItem = ResolveVmess(result, out msg); } ConfigHandler.UpgradeServerVersion(ref vmessItem); } else if (result.StartsWith(Global.ssProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem = ResolveSSLegacy(result); if (vmessItem == null) { vmessItem = ResolveSip002(result); } if (vmessItem == null) { return(null); } if (vmessItem.address.Length == 0 || vmessItem.port == 0 || vmessItem.security.Length == 0 || vmessItem.id.Length == 0) { return(null); } vmessItem.configType = (int)EConfigType.Shadowsocks; } else if (result.StartsWith(Global.socksProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem = ResolveSocksNew(result); if (vmessItem == null) { vmessItem = ResolveSocks(result); } if (vmessItem == null) { return(null); } if (vmessItem.address.Length == 0 || vmessItem.port == 0) { return(null); } vmessItem.configType = (int)EConfigType.Socks; } else if (result.StartsWith(Global.trojanProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem = ResolveTrojan(result); } else if (result.StartsWith(Global.vlessProtocol)) { vmessItem = ResolveStdVLESS(result); ConfigHandler.UpgradeServerVersion(ref vmessItem); } else { msg = UIRes.I18N("NonvmessOrssProtocol"); return(null); } } catch { msg = UIRes.I18N("Incorrectconfiguration"); return(null); } return(vmessItem); }
private void tsbLanguageZhHans_Click(object sender, EventArgs e) { SetCurrentLanguage("zh-Hans"); UI.Show(UIRes.I18N("RestartService")); }
public void UpdateSubscriptionProcess(Config config, bool blProxy, Action <bool, string> update) { _config = config; _updateFunc = update; _updateFunc(false, UIRes.I18N("MsgUpdateSubscriptionStart")); if (config.subItem == null || config.subItem.Count <= 0) { _updateFunc(false, UIRes.I18N("MsgNoValidSubscription")); return; } for (int k = 1; k <= config.subItem.Count; k++) { string id = config.subItem[k - 1].id.TrimEx(); string url = config.subItem[k - 1].url.TrimEx(); string userAgent = config.subItem[k - 1].userAgent.TrimEx(); string groupId = config.subItem[k - 1].groupId.TrimEx(); string hashCode = $"{k}){config.subItem[k - 1].remarks}->"; if (config.subItem[k - 1].enabled == false) { continue; } if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) { _updateFunc(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); continue; } DownloadHandle downloadHandle3 = new DownloadHandle(); downloadHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { _updateFunc(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); //string result = Utils.Base64Decode(args.Msg); string result = args.Msg; if (Utils.IsNullOrEmpty(result)) { _updateFunc(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); return; } //ConfigHandler.RemoveServerViaSubid(ref config, id); //_updateFunc(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); // RefreshServers(); int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId); if (ret > 0) { // RefreshServers(); } else { _updateFunc(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); } _updateFunc(true, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); } else { _updateFunc(false, args.Msg); } }; downloadHandle3.Error += (sender2, args) => { _updateFunc(false, args.GetException().Message); }; WebProxy webProxy = blProxy ? new WebProxy(Global.Loopback, _config.GetLocalPort(Global.InboundHttp)) : null; downloadHandle3.WebDownloadString(url, webProxy, userAgent); _updateFunc(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); } }
public void CheckUpdateGuiN(Config config, Action <bool, string> update) { _config = config; _updateFunc = update; var url = string.Empty; DownloadHandle downloadHandle = null; if (downloadHandle == null) { downloadHandle = new DownloadHandle(); downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { _updateFunc(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); try { string fileName = Utils.GetPath(Utils.GetDownloadFileName(url)); fileName = Utils.UrlEncode(fileName); Process process = new Process { StartInfo = new ProcessStartInfo { FileName = "v2rayUpgrade.exe", Arguments = "\"" + fileName + "\"", WorkingDirectory = Utils.StartupPath() } }; process.Start(); if (process.Id > 0) { _updateFunc(true, ""); } } catch (Exception ex) { _updateFunc(false, ex.Message); } } else { _updateFunc(false, args.Msg); } }; downloadHandle.Error += (sender2, args) => { _updateFunc(false, args.GetException().Message); }; } AbsoluteCompleted += (sender2, args) => { if (args.Success) { _updateFunc(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "v2rayN")); url = args.Msg; askToDownload(downloadHandle, url, true); } else { _updateFunc(false, args.Msg); } }; _updateFunc(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN")); CheckUpdateAsync(ECoreType.v2rayN); }
/// <summary> /// 生成v2ray的客户端配置文件 /// </summary> /// <param name="config"></param> /// <param name="fileName"></param> /// <param name="msg"></param> /// <returns></returns> public static int GenerateClientConfig(Config config, string fileName, bool blExport, out string msg) { msg = string.Empty; try { //检查GUI设置 if (config == null || config.index < 0 || config.vmess.Count <= 0 || config.index > config.vmess.Count - 1 ) { msg = UIRes.I18N("CheckServerSettings"); return(-1); } msg = UIRes.I18N("InitialConfiguration"); if (config.configType() == (int)EConfigType.Custom) { return(GenerateClientCustomConfig(config, fileName, out msg)); } //取得默认配置 string result = Utils.GetEmbedText(SampleClient); if (Utils.IsNullOrEmpty(result)) { msg = UIRes.I18N("FailedGetDefaultConfiguration"); return(-1); } //转成Json V2rayConfig v2rayConfig = Utils.FromJson <V2rayConfig>(result); if (v2rayConfig == null) { msg = UIRes.I18N("FailedGenDefaultConfiguration"); return(-1); } //开始修改配置 log(config, ref v2rayConfig, blExport); //本地端口 inbound(config, ref v2rayConfig); //路由 routing(config, ref v2rayConfig); //outbound outbound(config, ref v2rayConfig); //dns dns(config, ref v2rayConfig); Utils.ToJsonFile(v2rayConfig, fileName); msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), config.getSummary()); } catch { msg = UIRes.I18N("FailedGenDefaultConfiguration"); return(-1); } return(0); }
private void btnOK_Click(object sender, EventArgs e) { string address = txtAddress.Text; string port = txtPort.Text; string id = txtId.Text; string alterId = txtAlterId.Text; string security = cmbSecurity.Text; string network = cmbNetwork.Text; string remarks = txtRemarks.Text; string headerType = cmbHeaderType.Text; string requestHost = txtRequestHost.Text; string path = txtPath.Text; string streamSecurity = cmbStreamSecurity.Text; string allowInsecure = cmbAllowInsecure.Text; string sni = txtSNI.Text; if (Utils.IsNullOrEmpty(address)) { UI.Show(UIRes.I18N("FillServerAddress")); return; } if (Utils.IsNullOrEmpty(port) || !Utils.IsNumberic(port)) { UI.Show(UIRes.I18N("FillCorrectServerPort")); return; } if (Utils.IsNullOrEmpty(id)) { UI.Show(UIRes.I18N("FillUUID")); return; } if (Utils.IsNullOrEmpty(alterId) || !Utils.IsNumberic(alterId)) { UI.Show(UIRes.I18N("FillCorrectAlterId")); return; } vmessItem.address = address; vmessItem.port = Utils.ToInt(port); vmessItem.id = id; vmessItem.alterId = Utils.ToInt(alterId); vmessItem.security = security; vmessItem.network = network; vmessItem.remarks = remarks; vmessItem.headerType = headerType; vmessItem.requestHost = requestHost.Replace(" ", ""); vmessItem.path = path.Replace(" ", ""); vmessItem.streamSecurity = streamSecurity; vmessItem.allowInsecure = allowInsecure; vmessItem.sni = sni; if (ConfigHandler.AddServer(ref config, vmessItem, EditIndex) == 0) { this.DialogResult = DialogResult.OK; } else { UI.ShowWarning(UIRes.I18N("OperationFailed")); } }
private void tsbTestMe_Click(object sender, EventArgs e) { string result = httpProxyTest() + "ms"; AppendText(false, string.Format(UIRes.I18N("TestMeOutput"), result)); }
/// <summary> /// 从剪贴板导入URL /// </summary> /// <param name="fileName"></param> /// <param name="msg"></param> /// <returns></returns> public static VmessItem ImportFromClipboardConfig(string clipboardData, out string msg) { msg = string.Empty; VmessItem vmessItem = new VmessItem(); try { //载入配置文件 string result = clipboardData.Trim();// Utils.GetClipboardData(); if (Utils.IsNullOrEmpty(result)) { msg = UIRes.I18N("FailedReadConfiguration"); return(null); } if (result.StartsWith(Global.vmessProtocol)) { int indexSplit = result.IndexOf("?"); if (indexSplit > 0) { vmessItem = ResolveVmess4Kitsunebi(result); } else { vmessItem.configType = (int)EConfigType.Vmess; result = result.Substring(Global.vmessProtocol.Length); result = Utils.Base64Decode(result); //转成Json VmessQRCode vmessQRCode = Utils.FromJson <VmessQRCode>(result); if (vmessQRCode == null) { msg = UIRes.I18N("FailedConversionConfiguration"); return(null); } vmessItem.security = Global.DefaultSecurity; vmessItem.network = Global.DefaultNetwork; vmessItem.headerType = Global.None; vmessItem.configVersion = Utils.ToInt(vmessQRCode.v); vmessItem.remarks = vmessQRCode.ps; vmessItem.address = vmessQRCode.add; vmessItem.port = Utils.ToInt(vmessQRCode.port); vmessItem.id = vmessQRCode.id; vmessItem.alterId = Utils.ToInt(vmessQRCode.aid); vmessItem.network = vmessQRCode.net; vmessItem.headerType = vmessQRCode.type; vmessItem.requestHost = vmessQRCode.host; vmessItem.path = vmessQRCode.path; vmessItem.streamSecurity = vmessQRCode.tls; } ConfigHandler.UpgradeServerVersion(ref vmessItem); } else if (result.StartsWith(Global.ssProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem.configType = (int)EConfigType.Shadowsocks; result = result.Substring(Global.ssProtocol.Length); //remark int indexRemark = result.IndexOf("#"); if (indexRemark > 0) { try { vmessItem.remarks = WebUtility.UrlDecode(result.Substring(indexRemark + 1, result.Length - indexRemark - 1)); } catch { } result = result.Substring(0, indexRemark); } //part decode int indexS = result.IndexOf("@"); if (indexS > 0) { result = Utils.Base64Decode(result.Substring(0, indexS)) + result.Substring(indexS, result.Length - indexS); } else { result = Utils.Base64Decode(result); } string[] arr1 = result.Split('@'); if (arr1.Length != 2) { return(null); } string[] arr21 = arr1[0].Split(':'); //string[] arr22 = arr1[1].Split(':'); int indexPort = arr1[1].LastIndexOf(":"); if (arr21.Length != 2 || indexPort < 0) { return(null); } vmessItem.address = arr1[1].Substring(0, indexPort); vmessItem.port = Utils.ToInt(arr1[1].Substring(indexPort + 1, arr1[1].Length - (indexPort + 1))); vmessItem.security = arr21[0]; vmessItem.id = arr21[1]; } else if (result.StartsWith(Global.socksProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem.configType = (int)EConfigType.Socks; result = result.Substring(Global.socksProtocol.Length); //remark int indexRemark = result.IndexOf("#"); if (indexRemark > 0) { try { vmessItem.remarks = WebUtility.UrlDecode(result.Substring(indexRemark + 1, result.Length - indexRemark - 1)); } catch { } result = result.Substring(0, indexRemark); } //part decode int indexS = result.IndexOf(":"); if (indexS > 0) { } else { result = Utils.Base64Decode(result); } string[] arr21 = result.Split(':'); int indexPort = result.LastIndexOf(":"); if (arr21.Length != 2 || indexPort < 0) { return(null); } vmessItem.address = result.Substring(0, indexPort); vmessItem.port = Utils.ToInt(result.Substring(indexPort + 1, result.Length - (indexPort + 1))); } else { msg = UIRes.I18N("NonvmessOrssProtocol"); return(null); } } catch { msg = UIRes.I18N("Incorrectconfiguration"); return(null); } return(vmessItem); }
private void tsbCheckUpdateCore_Click(object sender, EventArgs e) { DownloadHandle downloadHandle = null; if (downloadHandle == null) { downloadHandle = new DownloadHandle(); downloadHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { askToDownload(downloadHandle, url); })); } else { AppendText(false, args.Msg); } }; downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); AppendText(false, UIRes.I18N("MsgUnpacking")); try { CloseV2ray(); string fileName = downloadHandle.DownloadFileName; fileName = Utils.GetPath(fileName); FileManager.ZipExtractToFile(fileName); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore")); Global.reloadV2ray = true; LoadV2ray(); AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfully")); } catch (Exception ex) { AppendText(false, ex.Message); } } else { AppendText(false, args.Msg); } }; downloadHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayCore")); downloadHandle.CheckUpdateAsync("Core"); }
private void tsbCheckUpdateN_Click(object sender, EventArgs e) { //System.Diagnostics.Process.Start(Global.UpdateUrl); DownloadHandle downloadHandle = null; if (downloadHandle == null) { downloadHandle = new DownloadHandle(); downloadHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgParsingV2rayCoreSuccessfully")); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.No) { return; } else { downloadHandle.DownloadFileAsync(url, null, -1); } })); } else { AppendText(false, args.Msg); } }; downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); try { string fileName = Utils.GetPath(downloadHandle.DownloadFileName); Process process = Process.Start("v2rayUpgrade.exe", fileName); if (process.Id > 0) { menuExit_Click(null, null); } } catch (Exception ex) { AppendText(false, ex.Message); } } else { AppendText(false, args.Msg); } }; downloadHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN")); downloadHandle.CheckUpdateAsync("v2rayN"); }
/// <summary> /// 从剪贴板导入URL /// </summary> /// <param name="fileName"></param> /// <param name="msg"></param> /// <returns></returns> public static VmessItem ImportFromClipboardConfig(string clipboardData, out string msg) { msg = string.Empty; VmessItem vmessItem = new VmessItem(); try { //载入配置文件 string result = clipboardData.TrimEx();// Utils.GetClipboardData(); if (Utils.IsNullOrEmpty(result)) { msg = UIRes.I18N("FailedReadConfiguration"); return(null); } if (result.StartsWith(Global.vmessProtocol)) { int indexSplit = result.IndexOf("?"); if (indexSplit > 0) { vmessItem = ResolveStdVmess(result) ?? ResolveVmess4Kitsunebi(result); } else { vmessItem.configType = (int)EConfigType.Vmess; result = result.Substring(Global.vmessProtocol.Length); result = Utils.Base64Decode(result); //转成Json VmessQRCode vmessQRCode = Utils.FromJson <VmessQRCode>(result); if (vmessQRCode == null) { msg = UIRes.I18N("FailedConversionConfiguration"); return(null); } vmessItem.network = Global.DefaultNetwork; vmessItem.headerType = Global.None; vmessItem.configVersion = Utils.ToInt(vmessQRCode.v); vmessItem.remarks = Utils.ToString(vmessQRCode.ps); vmessItem.address = Utils.ToString(vmessQRCode.add); vmessItem.port = Utils.ToInt(vmessQRCode.port); vmessItem.id = Utils.ToString(vmessQRCode.id); vmessItem.alterId = Utils.ToInt(vmessQRCode.aid); vmessItem.security = Utils.ToString(vmessQRCode.scy); if (!Utils.IsNullOrEmpty(vmessQRCode.scy)) { vmessItem.security = vmessQRCode.scy; } else { vmessItem.security = Global.DefaultSecurity; } if (!Utils.IsNullOrEmpty(vmessQRCode.net)) { vmessItem.network = vmessQRCode.net; } if (!Utils.IsNullOrEmpty(vmessQRCode.type)) { vmessItem.headerType = vmessQRCode.type; } vmessItem.requestHost = Utils.ToString(vmessQRCode.host); vmessItem.path = Utils.ToString(vmessQRCode.path); vmessItem.streamSecurity = Utils.ToString(vmessQRCode.tls); vmessItem.sni = Utils.ToString(vmessQRCode.sni); } ConfigHandler.UpgradeServerVersion(ref vmessItem); } else if (result.StartsWith(Global.ssProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem = ResolveSSLegacy(result); if (vmessItem == null) { vmessItem = ResolveSip002(result); } if (vmessItem == null) { return(null); } if (vmessItem.address.Length == 0 || vmessItem.port == 0 || vmessItem.security.Length == 0 || vmessItem.id.Length == 0) { return(null); } vmessItem.configType = (int)EConfigType.Shadowsocks; } else if (result.StartsWith(Global.socksProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem.configType = (int)EConfigType.Socks; result = result.Substring(Global.socksProtocol.Length); //remark int indexRemark = result.IndexOf("#"); if (indexRemark > 0) { try { vmessItem.remarks = Utils.UrlDecode(result.Substring(indexRemark + 1, result.Length - indexRemark - 1)); } catch { } result = result.Substring(0, indexRemark); } //part decode int indexS = result.IndexOf("@"); if (indexS > 0) { } else { result = Utils.Base64Decode(result); } string[] arr1 = result.Split('@'); if (arr1.Length != 2) { return(null); } string[] arr21 = arr1[0].Split(':'); //string[] arr22 = arr1[1].Split(':'); int indexPort = arr1[1].LastIndexOf(":"); if (arr21.Length != 2 || indexPort < 0) { return(null); } vmessItem.address = arr1[1].Substring(0, indexPort); vmessItem.port = Utils.ToInt(arr1[1].Substring(indexPort + 1, arr1[1].Length - (indexPort + 1))); vmessItem.security = arr21[0]; vmessItem.id = arr21[1]; } else if (result.StartsWith(Global.trojanProtocol)) { msg = UIRes.I18N("ConfigurationFormatIncorrect"); vmessItem.configType = (int)EConfigType.Trojan; Uri uri = new Uri(result); vmessItem.address = uri.IdnHost; vmessItem.port = uri.Port; vmessItem.id = uri.UserInfo; var qurery = HttpUtility.ParseQueryString(uri.Query); vmessItem.sni = qurery["sni"] ?? ""; var remarks = uri.Fragment.Replace("#", ""); if (Utils.IsNullOrEmpty(remarks)) { vmessItem.remarks = "NONE"; } else { vmessItem.remarks = Utils.UrlDecode(remarks); } } else if (result.StartsWith(Global.vlessProtocol)) { vmessItem = ResolveStdVLESS(result); ConfigHandler.UpgradeServerVersion(ref vmessItem); } else { msg = UIRes.I18N("NonvmessOrssProtocol"); return(null); } } catch { msg = UIRes.I18N("Incorrectconfiguration"); return(null); } return(vmessItem); }
private void tsbSubUpdate_Click(object sender, EventArgs e) { AppendText(false, UIRes.I18N("MsgUpdateSubscriptionStart")); if (config.subItem == null || config.subItem.Count <= 0) { AppendText(false, UIRes.I18N("MsgNoValidSubscription")); return; } for (int k = 1; k <= config.subItem.Count; k++) { string id = config.subItem[k - 1].id.TrimEx(); string url = config.subItem[k - 1].url.TrimEx(); string hashCode = $"{k}->"; if (config.subItem[k - 1].enabled == false) { continue; } if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}"); continue; } V2rayUpdateHandle v2rayUpdateHandle3 = new V2rayUpdateHandle(); v2rayUpdateHandle3.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}"); var result = Utils.Base64Decode(args.Msg); if (Utils.IsNullOrEmpty(result)) { AppendText(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}"); return; } ConfigHandler.RemoveServerViaSubid(ref config, id); AppendText(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}"); RefreshServers(); if (AddBatchServers(result, id) == 0) { } else { AppendText(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}"); } AppendText(false, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}"); } else { AppendText(false, args.Msg); } }; v2rayUpdateHandle3.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; v2rayUpdateHandle3.WebDownloadString(url); AppendText(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}"); } }
/// <summary> /// 导入v2ray服务端配置 /// </summary> /// <param name="fileName"></param> /// <param name="msg"></param> /// <returns></returns> public static VmessItem ImportFromServerConfig(string fileName, out string msg) { msg = string.Empty; VmessItem vmessItem = new VmessItem(); try { //载入配置文件 string result = Utils.LoadResource(fileName); if (Utils.IsNullOrEmpty(result)) { msg = UIRes.I18N("FailedReadConfiguration"); return(null); } //转成Json V2rayConfig v2rayConfig = Utils.FromJson <V2rayConfig>(result); if (v2rayConfig == null) { msg = UIRes.I18N("FailedConversionConfiguration"); return(null); } if (v2rayConfig.inbounds == null || v2rayConfig.inbounds.Count <= 0) { msg = UIRes.I18N("IncorrectServerConfiguration"); return(null); } var inbound = v2rayConfig.inbounds[0]; if (inbound == null || Utils.IsNullOrEmpty(inbound.protocol) || inbound.protocol != "vmess" || inbound.settings == null || inbound.settings.clients == null || inbound.settings.clients.Count <= 0) { msg = UIRes.I18N("IncorrectServerConfiguration"); return(null); } vmessItem.security = Global.DefaultSecurity; vmessItem.network = Global.DefaultNetwork; vmessItem.headerType = Global.None; vmessItem.address = string.Empty; vmessItem.port = inbound.port; vmessItem.id = inbound.settings.clients[0].id; vmessItem.alterId = inbound.settings.clients[0].alterId; vmessItem.remarks = string.Format("import@{0}", DateTime.Now.ToShortDateString()); //tcp or kcp if (inbound.streamSettings != null && inbound.streamSettings.network != null && !Utils.IsNullOrEmpty(inbound.streamSettings.network)) { vmessItem.network = inbound.streamSettings.network; } //tcp伪装http if (inbound.streamSettings != null && inbound.streamSettings.tcpSettings != null && inbound.streamSettings.tcpSettings.header != null && !Utils.IsNullOrEmpty(inbound.streamSettings.tcpSettings.header.type)) { if (inbound.streamSettings.tcpSettings.header.type.Equals(Global.TcpHeaderHttp)) { vmessItem.headerType = inbound.streamSettings.tcpSettings.header.type; string request = Convert.ToString(inbound.streamSettings.tcpSettings.header.request); if (!Utils.IsNullOrEmpty(request)) { V2rayTcpRequest v2rayTcpRequest = Utils.FromJson <V2rayTcpRequest>(request); if (v2rayTcpRequest != null && v2rayTcpRequest.headers != null && v2rayTcpRequest.headers.Host != null && v2rayTcpRequest.headers.Host.Count > 0) { vmessItem.requestHost = v2rayTcpRequest.headers.Host[0]; } } } } //kcp伪装 //if (v2rayConfig.outbound.streamSettings != null // && v2rayConfig.outbound.streamSettings.kcpSettings != null // && v2rayConfig.outbound.streamSettings.kcpSettings.header != null // && !Utils.IsNullOrEmpty(v2rayConfig.outbound.streamSettings.kcpSettings.header.type)) //{ // cmbHeaderType.Text = v2rayConfig.outbound.streamSettings.kcpSettings.header.type; //} //ws if (inbound.streamSettings != null && inbound.streamSettings.wsSettings != null) { if (!Utils.IsNullOrEmpty(inbound.streamSettings.wsSettings.path)) { vmessItem.path = inbound.streamSettings.wsSettings.path; } if (inbound.streamSettings.wsSettings.headers != null && !Utils.IsNullOrEmpty(inbound.streamSettings.wsSettings.headers.Host)) { vmessItem.requestHost = inbound.streamSettings.wsSettings.headers.Host; } } //h2 if (inbound.streamSettings != null && inbound.streamSettings.httpSettings != null) { if (!Utils.IsNullOrEmpty(inbound.streamSettings.httpSettings.path)) { vmessItem.path = inbound.streamSettings.httpSettings.path; } if (inbound.streamSettings.httpSettings.host != null && inbound.streamSettings.httpSettings.host.Count > 0) { vmessItem.requestHost = Utils.List2String(inbound.streamSettings.httpSettings.host); } } } catch { msg = UIRes.I18N("IncorrectClientConfiguration"); return(null); } return(vmessItem); }
private void UpdateHandler(ulong totalUp, ulong totalDown, ulong up, ulong down, List <Mode.ServerStatistics> statistics) { double up_amount = 0.0, down_amount; string up_unit = "", down_unit; up /= (ulong)(config.statisticsFreshRate / 1000f); down /= (ulong)(config.statisticsFreshRate / 1000f); Utils.ToHumanReadable(up, out up_amount, out up_unit); Utils.ToHumanReadable(down, out down_amount, out down_unit); up_unit += "/s"; down_unit += "/s"; toolSslBlank4.Text = string.Format( "{4}: {0:f2} {1} | {5}: {2:f2} {3}", up_amount, up_unit, down_amount, down_unit, UIRes.I18N("uploadSpeed"), UIRes.I18N("downloadSpeed") ); List <string[]> datas = new List <string[]>(); for (int i = 0; i < config.vmess.Count; i++) { string totalUp_ = string.Empty, totalDown_ = string.Empty, todayUp_ = string.Empty, todayDown_ = string.Empty; var index = statistics.FindIndex(item_ => Utils.IsIdenticalServer(item_, new ServerStatistics(config.vmess[i].remarks, config.vmess[i].address, config.vmess[i].port, config.vmess[i].path, config.vmess[i].requestHost, 0, 0, 0, 0))); if (index != -1) { Func <ulong, string> human_fy = (amount) => { double result; string unit; Utils.ToHumanReadable(amount, out result, out unit); return($"{string.Format("{0:f2}", result)}{unit}"); }; totalUp_ = human_fy(statistics[index].totalUp); totalDown_ = human_fy(statistics[index].totalDown); todayUp_ = human_fy(statistics[index].todayUp); todayDown_ = human_fy(statistics[index].todayDown); } datas.Add(new string[] { totalUp_, totalDown_, todayUp_, todayDown_ }); } lvServers.Invoke((MethodInvoker) delegate { lvServers.SuspendLayout(); for (int i = 0; i < datas.Count; i++) { lvServers.Items[i].SubItems[7].Text = datas[i][0]; lvServers.Items[i].SubItems[8].Text = datas[i][1]; lvServers.Items[i].SubItems[9].Text = datas[i][2]; lvServers.Items[i].SubItems[10].Text = datas[i][3]; } lvServers.ResumeLayout(); }); }
private void tsbCheckUpdateN_Click(object sender, EventArgs e) { //System.Diagnostics.Process.Start(Global.UpdateUrl); DownloadHandle downloadHandle = null; if (downloadHandle == null) { downloadHandle = new DownloadHandle(); downloadHandle.AbsoluteCompleted += (sender2, args) => { if (args.Success) { AppendText(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "v2rayN")); string url = args.Msg; this.Invoke((MethodInvoker)(delegate { askToDownload(downloadHandle, url); })); } else { AppendText(false, args.Msg); } }; downloadHandle.UpdateCompleted += (sender2, args) => { if (args.Success) { AppendText(false, UIRes.I18N("MsgDownloadV2rayCoreSuccessfully")); try { string fileName = Utils.GetPath(downloadHandle.DownloadFileName); Process process = new Process { StartInfo = new ProcessStartInfo { FileName = "v2rayUpgrade.exe", Arguments = "\"" + fileName + "\"", WorkingDirectory = Utils.StartupPath() } }; process.Start(); if (process.Id > 0) { menuExit_Click(null, null); } } catch (Exception ex) { AppendText(false, ex.Message); } } else { AppendText(false, args.Msg); } }; downloadHandle.Error += (sender2, args) => { AppendText(true, args.GetException().Message); }; } AppendText(false, string.Format(UIRes.I18N("MsgStartUpdating"), "v2rayN")); downloadHandle.CheckUpdateAsync("v2rayN"); }