Exemplo n.º 1
0
        private AuroraXmlDocument GetXML(string filename, OSHttpRequest httpRequest, OSHttpResponse httpResponse, Dictionary <string, object> requestParameters)
        {
            IWebInterfacePage page = GetPage(filename);

            if (page != null)
            {
                ITranslator translator = null;
                if (httpRequest.Query.ContainsKey("language"))
                {
                    translator = _translators.FirstOrDefault(t => t.LanguageName == httpRequest.Query["language"].ToString());
                }
                if (translator == null)
                {
                    translator = _defaultTranslator;
                }

                if (page.RequiresAuthentication)
                {
                    if (!Authenticator.CheckAuthentication(httpRequest))
                    {
                        return(null);
                    }
                    if (page.RequiresAdminAuthentication)
                    {
                        if (!Authenticator.CheckAdminAuthentication(httpRequest))
                        {
                            return(null);
                        }
                    }
                }
                return((AuroraXmlDocument)page.Fill(this, filename, httpRequest, httpResponse, requestParameters, translator)["xml"]);
            }
            return(null);
        }
Exemplo n.º 2
0
        protected Dictionary <string, object> AddVarsForPage(string filename, string parentFileName,
                                                             OSHttpRequest httpRequest, OSHttpResponse httpResponse,
                                                             Dictionary <string, object> requestParameters,
                                                             out string response)
        {
            response = null;
            Dictionary <string, object> vars = new Dictionary <string, object>();
            IWebInterfacePage           page = GetPage(filename);

            if (page != null)
            {
                ITranslator translator = null;
                if (httpRequest.Query.ContainsKey("language"))
                {
                    translator =
                        _translators.FirstOrDefault(t => t.LanguageName == httpRequest.Query["language"].ToString());
                    httpResponse.AddCookie(new System.Web.HttpCookie("language",
                                                                     httpRequest.Query["language"].ToString()));
                }
                else if (httpRequest.Cookies.Get("language") != null)
                {
                    var cookie = httpRequest.Cookies.Get("language");
                    translator = _translators.FirstOrDefault(t => t.LanguageName == cookie.Value);
                }
                if (translator == null)
                {
                    translator = _defaultTranslator;
                }

                if (page.RequiresAuthentication)
                {
                    if (!Authenticator.CheckAuthentication(httpRequest))
                    {
                        return(null);
                    }
                }
                if (page.RequiresAdminAuthentication)
                {
                    if (!Authenticator.CheckAdminAuthentication(httpRequest))
                    {
                        return(null);
                    }
                }
                vars = page.Fill(this, parentFileName, httpRequest, httpResponse, requestParameters, translator,
                                 out response);
                return(vars);
            }
            return(null);
        }
Exemplo n.º 3
0
        protected byte[] FindAndSendPage(string path, Stream request, OSHttpRequest httpRequest,
                                         OSHttpResponse httpResponse)
        {
            byte[] response = MainServer.BlankResponse;
            string filename = GetFileNameFromHTMLPath(path, httpRequest.Query);

            if (filename == null)
            {
                return(MainServer.BlankResponse);
            }
            if (httpRequest.HttpMethod == "POST")
            {
                httpResponse.KeepAlive = false;
            }
            MainConsole.Instance.Debug("[WebInterface]: Serving " + filename + ", keep-alive: " + httpResponse.KeepAlive);
            IWebInterfacePage page = GetPage(filename);

            if (page != null)
            {
                httpResponse.ContentType = GetContentType(filename, httpResponse);
                string text;
                if (!File.Exists(filename))
                {
                    if (!page.AttemptFindPage(filename, ref httpResponse, out text))
                    {
                        return(MainServer.BadRequest);
                    }
                }
                else
                {
                    text = File.ReadAllText(filename);
                }

                var requestParameters = request != null
                                            ? ParseQueryString(request.ReadUntilEnd())
                                            : new Dictionary <string, object>();

                if (filename.EndsWith(".xsl"))
                {
                    AuroraXmlDocument vars = GetXML(filename, httpRequest, httpResponse, requestParameters);

                    var xslt = new XslCompiledTransform();
                    if (File.Exists(path))
                    {
                        xslt.Load(GetFileNameFromHTMLPath(path, httpRequest.Query));
                    }
                    else if (text != "")
                    {
                        xslt.Load(new XmlTextReader(new StringReader(text)));
                    }
                    var stm = new MemoryStream();
                    xslt.Transform(vars, null, stm);
                    stm.Position = 1;
                    var    sr      = new StreamReader(stm);
                    string results = sr.ReadToEnd().Trim();
                    return(Encoding.UTF8.GetBytes(Regex.Replace(results, @"[^\u0000-\u007F]", string.Empty)));
                }
                else
                {
                    string respStr = null;
                    var    vars    = AddVarsForPage(filename, filename, httpRequest,
                                                    httpResponse, requestParameters, out respStr);

                    AddDefaultVarsForPage(ref vars);

                    if (!string.IsNullOrEmpty(respStr))
                    {
                        return(response = Encoding.UTF8.GetBytes(respStr));
                    }
                    if (httpResponse.StatusCode != 200)
                    {
                        return(MainServer.BlankResponse);
                    }
                    if (vars == null)
                    {
                        return(MainServer.BadRequest);
                    }
                    response = Encoding.UTF8.GetBytes(ConvertHTML(filename, text, httpRequest, httpResponse,
                                                                  requestParameters, vars));
                }
            }
            else
            {
                httpResponse.ContentType = GetContentType(filename, httpResponse);
                if (httpResponse.ContentType == null || !File.Exists(filename))
                {
                    return(MainServer.BadRequest);
                }
                response = File.ReadAllBytes(filename);
            }
            return(response);
        }