public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            var path = this.GetPath(request.Uri);
            var html = System.IO.Path.Combine(path, "index.html");
            var htm  = System.IO.Path.Combine(path, "index.htm");

            if (System.IO.Directory.Exists(path) && (System.IO.File.Exists(html) || System.IO.File.Exists(htm)))
            {
                if (!request.Uri.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    response.Redirect(request.Uri.AbsolutePath + "/");
                    return(true);
                }

                response.Status      = System.Net.HttpStatusCode.OK;
                response.Reason      = "OK";
                response.ContentType = "text/html; charset=utf-8";
                response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0");

                using (var fs = System.IO.File.OpenRead(System.IO.File.Exists(html) ? html : htm))
                {
                    response.ContentLength = fs.Length;
                    response.Body          = fs;
                    response.Send();
                }

                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if ((request.Uri.AbsolutePath == "/" || request.Uri.AbsolutePath == "/index.html" || request.Uri.AbsolutePath == "/index.htm") && System.IO.File.Exists(m_defaultdoc))
            {
                response.Status      = System.Net.HttpStatusCode.OK;
                response.Reason      = "OK";
                response.ContentType = "text/html";

                using (var fs = System.IO.File.OpenRead(m_defaultdoc))
                {
                    response.ContentLength = fs.Length;
                    response.Body          = fs;
                    response.Send();
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public bool Process(HttpServer.IHttpRequest aRequest, HttpServer.IHttpResponse aResponse, HttpServer.Sessions.IHttpSession aSession)
        {
            if (!aRequest.Uri.AbsolutePath.StartsWith("/logout"))
            {
                return(false);
            }
            foreach (RequestCookie cookie in aRequest.Cookies)
            {
                Host.Logger.WriteLine("Cookie({0}) = {1}", cookie.Name, cookie.Value);
            }

            Host.Logger.WriteLine("Logout PlugIn: {0}", aRequest.Uri.AbsolutePath);
            StreamWriter writer = new StreamWriter(aResponse.Body);

            writer.WriteLine("Goodbye {0}!", aSession["Username"]);
            writer.Flush();
            aResponse.Send();

            //clear the session
            aSession.Clear();


            return(true);
        }
Esempio n. 4
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            //We use the fake entry point /control.cgi to listen for requests
            //This ensures that the rest of the webserver can just serve plain files
            if (!request.Uri.AbsolutePath.Equals(CONTROL_HANDLER_URI, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;

            string action = input["action"].Value ?? "";

            //Lookup the actual handler method
            ProcessSub method;

            SUPPORTED_METHODS.TryGetValue(action, out method);

            if (method == null)
            {
                response.Status = System.Net.HttpStatusCode.NotImplemented;
                response.Reason = "Unsupported action: " + (action == null ? "<null>" : "");
                response.Send();
            }
            else
            {
                //Default setup
                response.Status = System.Net.HttpStatusCode.OK;
                response.Reason = "OK";
                #if DEBUG
                response.ContentType = "text/plain";
                #else
                response.ContentType = "text/json";
                #endif
                using (BodyWriter bw = new BodyWriter(response, request))
                {
                    try
                    {
                        method(request, response, session, bw);
                    }
                    catch (Exception ex)
                    {
                        Program.DataConnection.LogError("", string.Format("Request for {0} gave error", action), ex);
                        Console.WriteLine(ex.ToString());

                        try
                        {
                            if (!response.HeadersSent)
                            {
                                response.Status      = System.Net.HttpStatusCode.InternalServerError;
                                response.Reason      = "Error";
                                response.ContentType = "text/plain";

                                bw.WriteJsonObject(new
                                {
                                    Message = ex.Message,
                                    Type    = ex.GetType().Name,
                                    #if DEBUG
                                    Stacktrace = ex.ToString()
                                    #endif
                                });
                                bw.Flush();
                            }
                        }
                        catch (Exception flex)
                        {
                            Program.DataConnection.LogError("", "Reporting error gave error", flex);
                        }
                    }
                }
            }

            return(true);
        }