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); }); }
void TransmitFile(UMC.Net.NetContext context, String name) { var lastIndex = name.LastIndexOf('.'); var extName = "html"; if (lastIndex > -1) { extName = name.Substring(lastIndex + 1); } switch (extName.ToLower()) { case "pdf": context.ContentType = "application/pdf"; break; case "txt": context.ContentType = "text/plain"; break; case "htm": case "html": context.ContentType = "text/html"; break; case "json": context.ContentType = "text/json"; break; case "js": context.ContentType = "text/javascript"; break; case "css": context.ContentType = "text/css"; break; case "bmp": context.ContentType = "image/bmp"; break; case "gif": context.ContentType = "image/gif"; break; case "jpeg": case "jpg": context.ContentType = "image/jpeg"; break; case "png": context.ContentType = "image/png"; break; case "svg": context.ContentType = "image/svg+xml"; break; case "mp3": context.ContentType = "audio/mpeg"; break; case "mp4": context.ContentType = "video/mpeg4"; break; case "xml": context.ContentType = "text/xml"; break; default: context.ContentType = "application/octet-stream"; break; } var file = new System.IO.FileInfo(name); context.AddHeader("Last-Modified", file.LastWriteTimeUtc.ToString("r")); var Since = context.Headers["If-Modified-Since"]; if (String.IsNullOrEmpty(Since) == false) { var time = Convert.ToDateTime(Since); if (time >= file.LastWriteTimeUtc) { context.StatusCode = 304; return; } } using (System.IO.FileStream stream = System.IO.File.OpenRead(name)) { Utility.Copy(stream, context.OutputStream); } }
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); }); }