static void AddUrl(UrlInfo urlinfo) { if (!MonitorLog.RegexUrl(urlinfo.PsnUrl)) { return; } lock (_outputLock) { Console.ForegroundColor = string.IsNullOrEmpty(urlinfo.ReplacePath) ? ConsoleColor.DarkMagenta : ConsoleColor.Blue; Console.WriteLine(TrimUrlQuery(urlinfo.PsnUrl)); Console.ResetColor(); } }
public void AddUrl(UrlInfo urlinfo) { if (flp_log.InvokeRequired) { AddUrldelegate d = AddUrl; flp_log.Invoke(d, urlinfo); } else { if (AppConfig.Instance().Rule.Length <= 0) { MessageBox.Show(_rm.GetString("rulealert")); return; } if (!MonitorLog.RegexUrl(urlinfo.PsnUrl)) { return; } bool iscdn = urlinfo.IsCdn; if (_ctrls.Contains(urlinfo.PsnUrl)) { if (flp_log.Controls.ContainsKey((string)_ctrls[urlinfo.PsnUrl])) { urlinfo.MarkTxt = ((UrlReplace) flp_log.Controls.Find((string)_ctrls[urlinfo.PsnUrl], true).FirstOrDefault()).MarkTxt; flp_log.Controls.RemoveByKey((string)_ctrls[urlinfo.PsnUrl]); _ctrls.Remove(urlinfo.PsnUrl); } if (flp_lixian.Controls.ContainsKey((string)_ctrls[urlinfo.PsnUrl])) { urlinfo.MarkTxt = ((UrlReplace) flp_lixian.Controls.Find((string)_ctrls[urlinfo.PsnUrl], true).FirstOrDefault()) .MarkTxt; flp_lixian.Controls.RemoveByKey((string)_ctrls[urlinfo.PsnUrl]); _ctrls.Remove(urlinfo.PsnUrl); } } UrlInfo temp = DataHistoryOperate.GetInfo(urlinfo.PsnUrl); if (temp != null) { if (!string.IsNullOrEmpty(temp.ReplacePath) && !File.Exists(temp.ReplacePath)) { temp.ReplacePath = ""; } urlinfo = temp; } var u = new UrlReplace { Name = "url_replace" + (_lognum++).ToString(), PsnUrl = urlinfo.PsnUrl, LocalPath = String.IsNullOrEmpty(urlinfo.ReplacePath) ? _rm.GetString("replacetip") : urlinfo.ReplacePath, LogTime = DateTime.Now, MarkTxt = urlinfo.MarkTxt, IsLixian = urlinfo.IsLixian, LixianUrl = urlinfo.LixianUrl, IsCdn = iscdn, Host = urlinfo.Host }; u.ClickReplaceEvent += u_ClickReplaceEvent; u.NameTextChanged += u_NameTextChanged; u.EnableLixian += u_EnableLixian; u.DragDropFileto += u_DragDropFileto; u.PingClick += u_PingClick; u.SetLixian(AppConfig.Instance().EnableLixian); if (u.IsLixian) { flp_lixian.Controls.Add(u); var scrollp = new Point(0, flp_lixian.Height - flp_lixian.AutoScrollPosition.Y); flp_lixian.AutoScrollPosition = scrollp; } else { flp_log.Controls.Add(u); var scrollp = new Point(0, flp_log.Height - flp_log.AutoScrollPosition.Y); flp_log.AutoScrollPosition = scrollp; } tab_lixian.Text = _rm.GetString("tab_lixian.Text") + "(" + flp_lixian.Controls.Count.ToString() + ")"; tabPage_log.Text = _rm.GetString("tabPage_log.Text") + "(" + flp_log.Controls.Count.ToString() + ")"; if (!_ctrls.ContainsKey(urlinfo.PsnUrl)) { _ctrls.Add(urlinfo.PsnUrl, u.Name); } } }
private void QueryHandle(string query) { HeaderFields = ParseQuery(query); if ((HeaderFields == null) || !HeaderFields.ContainsKey("Host")) { SendBadRequest(); } else { int num; string requestedPath; int index; if (HttpRequestType.ToUpper().Equals("CONNECT")) { index = RequestedPath.IndexOf(":"); if (index >= 0) { requestedPath = RequestedPath.Substring(0, index); num = RequestedPath.Length > (index + 1) ? int.Parse(RequestedPath.Substring(index + 1)) : 443; } else { requestedPath = RequestedPath; num = 80; } } else { index = HeaderFields["Host"].IndexOf(":"); if (index > 0) { requestedPath = HeaderFields["Host"].Substring(0, index); num = int.Parse(HeaderFields["Host"].Substring(index + 1)); } else { requestedPath = HeaderFields["Host"]; num = 80; } if (HttpRequestType.ToUpper().Equals("POST")) { int tempnum = query.IndexOf("\r\n\r\n"); _mHttpPost = query.Substring(tempnum + 4); } } var localFile = String.Empty; if (MonitorLog.RegexUrl(RequestedUrl)) { localFile = UrlOperate.MatchFile(RequestedUrl); } _uinfo.PsnUrl = string.IsNullOrEmpty(_uinfo.PsnUrl) ? RequestedUrl : _uinfo.PsnUrl; if (!HttpRequestType.ToUpper().Equals("CONNECT") && localFile != string.Empty && File.Exists(localFile)) { _uinfo.ReplacePath = localFile; _updataUrlLog(_uinfo); SendLocalFile(localFile, HeaderFields.ContainsKey("Range") ? HeaderFields["Range"] : null, HeaderFields.ContainsKey("Proxy-Connection") ? HeaderFields["Proxy-Connection"] : null); } else { try { bool iscdn; IPAddress hostIp = CdnOperate.GetCdnAddress(requestedPath, out iscdn); var remoteEp = new IPEndPoint(hostIp, num); DestinationSocket = new Socket(remoteEp.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (HeaderFields.ContainsKey("Proxy-Connection") && HeaderFields["Proxy-Connection"].ToLower().Equals("keep-alive")) { DestinationSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1); } DestinationSocket.BeginConnect(remoteEp, OnConnected, DestinationSocket); _uinfo.Host = hostIp.ToString(); _uinfo.IsCdn = iscdn; _uinfo.ReplacePath = string.Empty; _updataUrlLog(_uinfo); } catch { SendBadRequest(); } } } }