예제 #1
0
        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)
        {
            // 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);

            resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars);
            //m_log.DebugFormat("[Wifi]: resource {0}", resource);

            Request     request = RequestFactory.CreateRequest(resource, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language")));
            Environment env     = new 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  = WebApp.GetPath(resource);
                string[] resourcePaths = WebApp.GetPaths(resource);

                string type = WebAppUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                //m_log.DebugFormat("[XXX]: path {0}", resourcePath);
                if (type.StartsWith("image"))
                {
                    return(WebAppUtils.ReadBinaryResource(resourcePaths));
                }

                if (type.StartsWith("application"))
                {
                    string res = WebAppUtils.ReadTextResource(resourcePaths, WebApp.MissingPage, 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(resourcePaths, WebApp.MissingPage));
                    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));
        }