public string GetMainMenu(Environment env) { if (!m_WebApp.IsInstalled) { return(m_WebApp.ReadFile(env, "main-menu-install.html")); } SessionInfo sinfo = env.Session; if (sinfo.Account != null) { if (sinfo.Account.UserLevel >= m_WebApp.AdminUserLevel) // Admin { return(m_WebApp.ReadFile(env, "main-menu-admin.html")); } else if (sinfo.Account.UserLevel >= m_WebApp.HyperlinksUserLevel) // Privileged user { return(m_WebApp.ReadFile(env, "main-menu-privileged.html")); } return(m_WebApp.ReadFile(env, "main-menu-users.html", env.Data)); } // At the request of Ai Austin, I'm exposing this to users. But just this. string[] resources = WebApp.GetPaths("main-menu.html"); return(WebAppUtils.ReadTextResource(resources, WebApp.MissingPage)); }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { string resource = GetParam(path); resource = resource.Trim(WebAppUtils.DirectorySeparatorChars); string resourcePath = System.IO.Path.Combine(m_LocalPath, resource); resourcePath = Uri.UnescapeDataString(resourcePath); m_log.DebugFormat("[Wifi]: resourcePath {0}", resourcePath); string type = WebAppUtils.GetContentType(resource); httpResponse.ContentType = type; //m_log.DebugFormat("[Wifi]: ContentType {0}", type); if (type.StartsWith("image")) { return(WebAppUtils.ReadBinaryResource(new string[] { resourcePath })); } if (type.StartsWith("application") || type.StartsWith("text")) { string res = WebAppUtils.ReadTextResource(new string[] { resourcePath }, WebApp.MissingPage, true); return(WebAppUtils.StringToBytes(res)); } m_log.WarnFormat("[Wifi]: Could not find resource {0} in local path {1}", resource, m_LocalPath); httpResponse.ContentType = "text/plain"; string result = "Boo!"; return(WebAppUtils.StringToBytes(result)); }
public string DefaultRequest(Environment env) { m_log.DebugFormat("[Wifi]: DefaultRequest"); SessionInfo sinfo; if (TryGetSessionInfo(env.TheRequest, out sinfo)) { env.Session = sinfo; env.Flags = Flags.IsLoggedIn; env.State = State.Default; return(WebAppUtils.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 string ReadFile(IEnvironment env, string path, List <object> lot) { string file = Localization.LocalizePath(env, path); try { string content = string.Empty; using (StreamReader sr = new StreamReader(file)) { content = sr.ReadToEnd(); } Processor p = new Processor(WifiScriptFace, m_ExtensionMethods, env, lot); return(p.Process(content)); } catch (Exception e) { m_log.DebugFormat("[Wifi]: Exception on ReadFile {0}: {1}", path, e); return(WebAppUtils.ReadTextResource(new string[] { WebApp.MissingPage }, "")); } }
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // path = /wifi/... //m_log.DebugFormat("[Wifi]: path = {0}", path); //m_log.DebugFormat("[Wifi]: 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("[Wifi]: resource {0}", resource); resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars); Request request = RequestFactory.CreateRequest(resource, httpRequest); Diva.Wifi.Environment env = new Diva.Wifi.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("[Wifi]: 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)); }