Esempio n. 1
0
        static void Main(string[] args)
        {
            var options = new MyOptions();

            if (!Parser.Default.ParseArguments(args, options))
            {
                Console.WriteLine(options.GetUsage());
                return;
            }

            CdnOperate.ReadCdnConfig();

            var config = AppConfig.Instance();

            config.Rule               = "*.pkg*|*.pup*|*.json*";
            config.ConnType           = 0;
            config.LocalFileDirectory = options.LocalFolder;
            config.Port               = options.Port;
            config.IsAutoFindFile     = !string.IsNullOrEmpty(options.LocalFolder);

            var address = IPAddress.Parse(options.IPAddress);
            var port    = options.Port;

            _listener = new HttpListenerHelp(address, port, AddUrl);
            _listener.Start();

            Application.Run(new MyAppContext());
        }
Esempio n. 2
0
        public void CheckCdn()
        {
            var t = new Task(() =>
            {
                try
                {
                    CdnOperate.ReadCdnConfig();
                    Thread.Sleep(2500);
                    OnCdnCheckComplete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(_rm.GetString("cdnerror") + ex.Message, "Error");
                    OnCdnCheckComplete(false);
                }
            });

            t.Start();
        }
Esempio n. 3
0
 private void Btn_ExportCdn_Click(object sender, EventArgs e)
 {
     CdnOperate.ExportHost();
     MessageBox.Show(_rm.GetString("exportsuccess"));
 }
        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();
                    }
                }
            }
        }