public string DefaultRequest(Environment env) { MainConsole.Instance.DebugFormat("[AuroraWeb]: DefaultRequest"); SessionInfo sinfo; if (TryGetSessionInfo(env.Request, out sinfo)) { env.Session = sinfo; env.Flags = Flags.IsLoggedIn; env.State = State.Default; return PadURLs(env, sinfo.Sid, m_WebApp.ReadFile(env, "splash.html")); } string resourcePath = Localization.LocalizePath(env, "splash.html"); Processor p = new Processor(m_WebApp.WifiScriptFace, env); return p.Process(WebAppUtils.ReadTextResource(resourcePath)); }
public byte[] Handle(string path, Stream requestData, RequestFactory.IOSHttpRequest httpRequest, WifiConsoleHandler.IOSHttpResponse httpResponse) { // path = /wifi/... //m_log.DebugFormat("[AuroraWeb]: path = {0}", path); //m_log.DebugFormat("[AuroraWeb]: ip address = {0}", httpRequest.RemoteIPEndPoint); //foreach (object o in httpRequest.Query.Keys) // m_log.DebugFormat(" >> {0}={1}", o, httpRequest.Query[o]); string resource = GetParam(path); //m_log.DebugFormat("[AuroraWeb]: resource {0}", resource); resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars); Request request = RequestFactory.CreateRequest(resource, httpRequest); AuroraWeb.Environment env = new AuroraWeb.Environment(request); if (resource == string.Empty || resource.StartsWith("index.")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) m_WebApp.Services.ComputeStatistics(); httpResponse.ContentType = "text/html"; return WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env)); } else { string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource); string type = WebAppUtils.GetContentType(resource); httpResponse.ContentType = type; //m_log.DebugFormat("[AuroraWeb]: ContentType {0}", type); if (type.StartsWith("image")) return WebAppUtils.ReadBinaryResource(resourcePath); if (type.StartsWith("application")) { string res = WebAppUtils.ReadTextResource(resourcePath, true); return WebAppUtils.StringToBytes(res); } if (type.StartsWith("text")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) m_WebApp.Services.ComputeStatistics(); resourcePath = Localization.LocalizePath(env, resource); Processor p = new Processor(m_WebApp.WifiScriptFace, env); string res = p.Process(WebAppUtils.ReadTextResource(resourcePath)); if (res == string.Empty) res = m_WebApp.Services.DefaultRequest(env); return WebAppUtils.StringToBytes(res); } } httpResponse.ContentType = "text/plain"; string result = "Boo!"; return WebAppUtils.StringToBytes(result); }
public string ReadFile(Environment env, string path, List<object> lot) { string file = Localization.LocalizePath(env, path); try { using (StreamReader sr = new StreamReader(file)) { string content = sr.ReadToEnd(); Processor p = new Processor(WifiScriptFace, m_ExtensionMethods, env, lot); return p.Process(content); } } catch (Exception e) { m_log.DebugFormat("[AuroraWeb]: Exception on ReadFile {0}: {1}", path, e); return string.Empty; } }
private string Include(string argStr) { Match match = args.Match(argStr); //m_log.DebugFormat("Match {0} args? {1} {2}", args.ToString(), match.Success, match.Groups.Count); if (match.Groups.Count == 3) { string name = match.Groups[1].Value; string value = match.Groups[2].Value; // ignore the name which should be file string file = m_WebApp.LocalizePath(m_Env, value); //m_log.DebugFormat("[WebScript]: Including file {0} with index = {1} (previous file is {2})", file, m_Index, m_FileName); using (StreamReader sr = new StreamReader(file)) { if (file == m_FileName) { m_Index++; if (m_ListOfObjects != null) { if (m_Index >= m_ListOfObjects.Count) { return string.Empty; } } // recurse! return Process(sr.ReadToEnd()); } else { m_FileName = file; Processor p = new Processor(m_WebApp, m_ExtensionMethods, m_Env, m_ListOfObjects); return p.Process(sr.ReadToEnd()); } } } return string.Empty; }