Example #1
0
        void Process(UMC.Net.NetContext context)
        {
            if (String.IsNullOrEmpty(context.UserAgent))
            {
                return;
            }
            context.AddHeader("Access-Control-Allow-Origin", "*");
            context.AddHeader("Access-Control-Allow-Credentials", "true");
            context.AddHeader("Access-Control-Max-Age", "18000");
            context.AddHeader("Access-Control-Allow-Methods", "*");
            context.AddHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");

            var QueryString = new NameValueCollection(context.QueryString);

            QueryString.Add(context.Form);

            var model = QueryString["_model"];
            var cmd   = QueryString["_cmd"];
            var jsonp = context.QueryString.Get("jsonp");

            if ("Upload".Equals(model) && "Command".Equals(cmd))
            {
                try
                {
                    var url  = new Uri(QueryString["src"]);
                    var wb   = new Net.HttpClient();
                    var hash = UMC.Data.JSON.Deserialize <Hashtable>(wb.GetAsync(url).Result.Content.ReadAsStringAsync().Result).GetEnumerator();

                    QueryString.Clear();
                    while (hash.MoveNext())
                    {
                        QueryString.Add(hash.Key.ToString(), hash.Value.ToString());
                    }
                    model = QueryString["_model"];
                    cmd   = QueryString["_cmd"];
                    if (String.IsNullOrEmpty(jsonp) == false)
                    {
                        QueryString.Add("jsonp", jsonp);
                    }
                }
                catch
                {
                    return;
                }
            }


            var Url = context.Url;
            var ip  = context.Headers.Get("X-Real-IP");

            if (String.IsNullOrEmpty(ip))
            {
                ip = context.UserHostAddress;;
            }
            var host = UMC.Data.WebResource.Instance().APIHost();;

            if (String.IsNullOrEmpty(host))
            {
                var cahash = context.Headers.Get("CA-Host");
                if (String.IsNullOrEmpty(cahash) == false)
                {
                    host = String.Format("https://{0}", context.Headers.Get("CA-Host"));
                }
            }

            if (String.IsNullOrEmpty(host) == false)
            {
                Url = new Uri(String.Format("{1}{0}", context.Url.PathAndQuery, host));
            }


            Process(QueryString, Url, context, model, cmd, url =>
            {
                context.Redirect(url.AbsoluteUri);
            });
        }
Example #2
0
        static void Process(UMC.Net.NetContext context, String model, string cmd)
        {
            if (String.IsNullOrEmpty(context.UserAgent))
            {
                return;
            }
            if (context.UrlReferrer != null)
            {
                context.AddHeader("Access-Control-Allow-Origin", String.Format("{0}://{1}", context.UrlReferrer.Scheme, context.UrlReferrer.Host));
            }
            else
            {
                context.AddHeader("Access-Control-Allow-Origin", "*");
            }
            context.AddHeader("Access-Control-Allow-Credentials", "true");
            context.AddHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST");
            context.AddHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");

            var QueryString = new NameValueCollection(context.QueryString);

            QueryString.Add(context.Form);
            if (string.IsNullOrEmpty(model))
            {
                model = QueryString["_model"];
                cmd   = QueryString["_cmd"];
            }
            var jsonp = context.QueryString.Get("jsonp");

            if ("Upload".Equals(model) && "Command".Equals(cmd))
            {
                try
                {
                    var url  = new Uri(QueryString["src"]);
                    var wb   = new Net.HttpClient();
                    var hash = UMC.Data.JSON.Deserialize <Hashtable>(wb.GetAsync(url).Result.Content.ReadAsStringAsync().Result).GetEnumerator();

                    QueryString.Clear();
                    while (hash.MoveNext())
                    {
                        QueryString.Add(hash.Key.ToString(), hash.Value.ToString());
                    }
                    model = QueryString["_model"];
                    cmd   = QueryString["_cmd"];
                    if (String.IsNullOrEmpty(jsonp) == false)
                    {
                        QueryString.Add("jsonp", jsonp);
                    }
                }
                catch
                {
                    return;
                }
            }
            context.ContentType = "text/javascript;charset=utf-8";

            var Url = context.Url;
            var ip  = context.Headers.Get("X-Real-IP");

            if (String.IsNullOrEmpty(ip))
            {
                ip = context.UserHostAddress;;
            }
            var cahash = context.Headers.Get("CA-Host");

            if (String.IsNullOrEmpty(cahash) == false)
            {
                Url = new Uri(String.Format("https://{1}{0}", context.Url.PathAndQuery, cahash));
            }


            Process(QueryString, context.InputStream, context.OutputStream, Url, context.UrlReferrer, ip, context.UserAgent, model, cmd, url =>
            {
                context.Redirect(url.AbsoluteUri);
            });
        }