Exemplo n.º 1
0
        private void GetBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
        {
            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
            var bk = Program.DataConnection.GetBackup(input["id"].Value);

            if (bk == null)
            {
                ReportError(response, bw, "Invalid or missing backup id");
            }
            else
            {
                var scheduleId  = Program.DataConnection.GetScheduleIDsFromTags(new string[] { "ID=" + bk.ID });
                var schedule    = scheduleId.Any() ? Program.DataConnection.GetSchedule(scheduleId.First()) : null;
                var sourcenames = SpecialFolders.GetSourceNames(bk);

                //TODO: Filter out the password in both settings and the target url

                bw.OutputOK(new
                {
                    success = true,
                    data    = new {
                        Schedule     = schedule,
                        Backup       = bk,
                        DisplayNames = sourcenames
                    }
                });
            }
        }
Exemplo n.º 2
0
        public void Execute(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (!request.Param.Contains("call_id"))
            {
                return;
            }

            var call = _plugin.PluginManager.Core.CallManager[Int32.Parse(request.Param["call_id"].Value)];

            var content = TemplateTools.ProcessTemplate(
                "CallState.html",
                new Dictionary <string, string>()
            {
                { "number", call.Number },
                { "state", ConvertState(call.State) }
            });

            response.Connection    = HttpServer.ConnectionType.Close;
            response.ContentType   = "text/html";
            response.ContentLength = content.Length;
            response.AddHeader("Content-type", "text/html");
            response.SendHeaders();

            response.SendBody(content);
        }
Exemplo n.º 3
0
 public RequestInfo(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
 {
     Request    = request;
     Response   = response;
     Session    = session;
     BodyWriter = new BodyWriter(response, request);
 }
Exemplo n.º 4
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string board       = request.QueryString[UrlParameters.Board].Value;
                string threadIdStr = request.QueryString[UrlParameters.ThreadId].Value;
                int    threadId    = -1;
                int.TryParse(threadIdStr, out threadId);

                if (!Program.IsBoardLetterValid(board))
                {
                    ThreadServerModule.write_text("Invalid board letter", response);
                    return(true);
                }

                if (threadId <= 0)
                {
                    ThreadServerModule.write_text("Invalid thread id", response);
                    return(true);
                }

                string notes = request.QueryString[UrlParameters.ThreadNotesText].Value;

                notes = System.Web.HttpUtility.HtmlDecode(notes);

                ThreadStore.GetStorageEngine().setThreadNotes(board, threadId, notes);

                response.Redirect(ThreadServerModule.GetThreadPageLink(board, threadId));

                return(true);
            }
            return(false);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == Url)
            {
                ThreadStore.GetStorageEngine().UpdateThreadStoreStats();
                ThreadStoreStats stats = ThreadStore.GetStorageEngine().StoreStats;

                JsonArray ja = new JsonArray();

                IEnumerable <string> boards = Program.ValidBoards.Keys;

                for (int i = 0, j = boards.Count(); i < j; i++)
                {
                    string boardName   = boards.ElementAt(i);
                    int    threadCount = stats[boardName];

                    if (threadCount > 0)
                    {
                        JsonArray inner = new JsonArray();

                        inner.Add(boardName);
                        inner.Add(threadCount);

                        ja.Add(inner);
                    }
                }

                WriteJsonResponse(response, ja.ToString());
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
        public void Execute(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (!request.Param.Contains("number"))
            {
                return;
            }

            var call = _plugin.PluginManager.Core.CallManager.MakeCall(request.Param["number"].Value);

            var content = TemplateTools.ProcessTemplate(
                "Call.html",
                new Dictionary <string, string>()
            {
                { "number", call.Number }
            });

            response.Connection    = HttpServer.ConnectionType.Close;
            response.ContentType   = "text/html";
            response.ContentLength = content.Length;
            response.AddHeader("Content-type", "text/html");
            response.SendHeaders();

            response.SendBody(content);

            //response.Connection = HttpServer.ConnectionType.Close;
            //response.Redirect(String.Format("/callstate?call_id={0}", call.SessionId));
            //response.Send();
        }
Exemplo n.º 7
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (!request.Uri.AbsolutePath.StartsWith(API_URI_PATH, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            var module = request.Uri.Segments.Skip(API_URI_SEGMENTS).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(module))
            {
                module = "help";
            }

            module = module.Trim('/');

            var key = string.Join("", request.Uri.Segments.Skip(API_URI_SEGMENTS + 1)).Trim('/');

            var method = request.Method;

            if (!string.IsNullOrWhiteSpace(request.Headers["X-HTTP-Method-Override"]))
            {
                method = request.Headers["X-HTTP-Method-Override"];
            }

            DoProcess(request, response, session, method, module, key);

            return(true);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string hash = request.QueryString["hash"].Value;

                if (string.IsNullOrEmpty(hash))
                {
                    ThreadServerModule._404(response);
                }
                else
                {
                    if (Program.queued_files.ContainsKey(hash))
                    {
                        FileQueueStateInfo f = Program.queued_files[hash];

                        JsonObject ob = new JsonObject();

                        ob.Add("p", f.Percent().ToString());
                        ob.Add("s", string.Format("{0} / {1}", Program.format_size_string(f.Downloaded), Program.format_size_string(f.Length)));
                        ob.Add("c", f.Status == FileQueueStateInfo.DownloadStatus.Complete);

                        WriteJsonResponse(response, ob.ToString());
                    }
                    else
                    {
                        ThreadServerModule._404(response);
                    }
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 9
0
        public void Execute(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            var filePath = request.Uri.LocalPath;

            // Prevent hacking
            filePath = filePath.Replace('/', '\\');
            filePath = filePath.Substring(filePath.LastIndexOf('\\'));

            if (filePath[0] == '\\')
            {
                filePath = filePath.Substring(1);
            }

            response.Connection = HttpServer.ConnectionType.Close;
            try
            {
                var content = TemplateTools.ReadResourceFile(filePath);
                response.ContentType   = GetMimeTypeByExtension(filePath);
                response.ContentLength = content.Length;
                response.SendHeaders();

                response.SendBody(content);
            }
            catch
            {
                response.Reason = "HTTP/1.1 404 Not Found";
                response.Send();
            }
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            string command = request.UriPath;

            if (command.StartsWith("/threadinfo"))
            {
                string board = request.QueryString["board"].Value;
                string id    = request.QueryString["id"].Value;

                if (string.IsNullOrEmpty(board) || string.IsNullOrEmpty(id))
                {
                    response.Redirect("/wjobs"); return(true);
                }

                if (Program.active_dumpers.ContainsKey(board))
                {
                    BoardWatcher bw = Program.active_dumpers[board];

                    int tid = 0;

                    Int32.TryParse(id, out tid);

                    if (bw.watched_threads.ContainsKey(tid))
                    {
                        ThreadWorker tw = bw.watched_threads[tid];

                        StringBuilder properties = new StringBuilder();

                        properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Thread ID", tw.ID);

                        properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Board", tw.Board.Board);

                        properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Update Interval (in min)", tw.UpdateInterval);

                        properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "BumpLimit", tw.BumpLimit);

                        properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "ImageLimit", tw.ImageLimit);

                        response.Status      = System.Net.HttpStatusCode.OK;
                        response.ContentType = "text/html";

                        byte[] data = Encoding.UTF8.GetBytes
                                          (Properties.Resources.threadinfo_page
                                          .Replace("{properties}", properties.ToString())
                                          .Replace("{Logs}", get_logs(tw.Logs)));

                        response.ContentLength = data.Length;
                        response.SendHeaders();
                        response.SendBody(data);

                        return(true);
                    }
                }

                response.Redirect("/wjobs"); return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == Url)
            {
                ThreadStore.GetStorageEngine().UpdateThreadStoreStats();

                StringBuilder sb = new StringBuilder(HtmlTemplates.OverviewPageTemplate);

                IncludeCommonHtml(sb);

                if (Settings.ThumbnailOnly)
                {
                    string url = ThumbnailOnlySettingsController.GetLinkToThisPage(true, Url);
                    sb.Replace("{thumbmode}", string.Format(ThumbnailOnlyWarningMessageHtml, url));
                }
                else
                {
                    sb.Replace("{thumbmode}", "");
                }

                if (FileSystemStats.IsSaveDirDriveLowOnDiskSpace)
                {
                    sb.Replace("{lowdiskspacenotice}", LowDiskSpaceWarningMessageHtml);
                }
                else
                {
                    sb.Replace("{lowdiskspacenotice}", "");
                }

                sb.Replace("{RunningTime}", get_running_time_info());

                if (Settings.EnableFileStats)
                {
                    sb.Replace("{DiskUsage}", string.Format(DiskUsageTableHtml, get_DiskUsageInfo()));
                }
                else
                {
                    sb.Replace("{DiskUsage}", "");
                }

                sb.Replace("{NetworkStats}", get_NetWorkStats());

                sb.Replace("{ArchivedThreads}", get_ArchivedThreadsStats());

                sb.Replace("{get-network-stats-today-api-link}",
                           GetDailyNetworkStatisticsJsonApiHandler.GetLinkToThisPage(DateTime.Now));

                sb.Replace("{get-network-stats-month-api-link}",
                           GetMonthlyNetworkStatisticsJsonApiHandler.GetLinkToThisPage(DateTime.Now));

                sb.Replace("{get-threads-stats-api-link}",
                           GetThreadsStatisticsJsonApiHandler.GetLinkToThisPage());

                WriteFinalHtmlResponse(response, sb.ToString());

                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        public static void HandleControlCGI(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw, Type module)
        {
            var method = request.Method;

            if (!string.IsNullOrWhiteSpace(request.Headers["X-HTTP-Method-Override"]))
            {
                method = request.Headers["X-HTTP-Method-Override"];
            }

            DoProcess(request, response, session, method, module.Name.ToLowerInvariant(), (String.Equals(request.Method, "POST", StringComparison.OrdinalIgnoreCase) ? request.Form : request.QueryString)["id"].Value);
        }
Exemplo n.º 13
0
        private void ReadLogData(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
        {
            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
            var backupid = input["id"].Value;

            if (string.IsNullOrWhiteSpace(backupid))
            {
                List <Dictionary <string, object> > res = null;
                Program.DataConnection.ExecuteWithCommand(x =>
                {
                    res = DumpTable(x, "ErrorLog", "Timestamp", input["offset"].Value, input["pagesize"].Value);
                });

                bw.OutputOK(res);
            }
            else
            {
                var backup = Program.DataConnection.GetBackup(backupid);
                if (backup == null)
                {
                    ReportError(response, bw, "Invalid or missing backup id");
                    return;
                }

                using (var con = (System.Data.IDbConnection)Activator.CreateInstance(Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType))
                {
                    con.ConnectionString = "Data Source=" + backup.DBPath;
                    con.Open();

                    using (var cmd = con.CreateCommand())
                    {
                        if (Duplicati.Library.Utility.Utility.ParseBool(input["remotelog"].Value, false))
                        {
                            var dt = DumpTable(cmd, "RemoteOperation", "ID", input["offset"].Value, input["pagesize"].Value);

                            // Unwrap raw data to a string
                            foreach (var n in dt)
                            {
                                try { n["Data"] = System.Text.Encoding.UTF8.GetString((byte[])n["Data"]); }
                                catch { }
                            }

                            bw.OutputOK(dt);
                        }
                        else
                        {
                            var dt = DumpTable(cmd, "LogData", "ID", input["offset"].Value, input["pagesize"].Value);
                            bw.OutputOK(dt);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            string command = request.UriPath;

            if (command.StartsWith(Url))
            {
                string file_hash = request.QueryString[UrlParameters.FileHash].Value;

                FileQueueStateInfo fqs = Program.get_file_state(file_hash);

                if (fqs != null)
                {
                    StringBuilder page = new StringBuilder(HtmlTemplates.FileInfoPageTemplate);

                    IncludeCommonHtml(page);

                    page.Replace("{fullfilelink}", string.Format("/file/{0}.{1}", fqs.Hash, fqs.Ext));

                    page.Replace("{thumbsource}", string.Format("/thumb/{0}.jpg", fqs.Hash));

                    page.Replace("{url}", fqs.Url);

                    page.Replace("{p}", fqs.Percent().ToString());
                    page.Replace("{md5}", fqs.Hash);

                    page.Replace("{name}", fqs.FileName);

                    page.Replace("{workid}", file_hash);

                    page.Replace("{jtype}", fqs.Type.ToString());
                    page.Replace("{rcount}", fqs.RetryCount.ToString());

                    page.Replace("{downloaded}", Program.format_size_string(fqs.Downloaded));
                    page.Replace("{length}", Program.format_size_string(fqs.Length));

                    page.Replace("{Logs}", get_logs(fqs.Logs));

                    WriteFinalHtmlResponse(response, page.ToString());

                    return(true);
                }
                else
                {
                    response.Redirect(FileQueuePageHandler.Url);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 15
0
        public bool Process(HttpServer.IHttpRequest aRequest, HttpServer.IHttpResponse aResponse, HttpServer.Sessions.IHttpSession aSession)
        {
            if (aRequest.Uri.AbsolutePath == "/user/bye/")
            {
                Host?.Logger.WriteLine($"Accept request for : {aRequest.Uri}");

                var writer = new StreamWriter(aResponse.Body);
                writer.WriteLine("<library><book>Eu e eu...</book></library>");
                writer.Flush();

                aResponse.Send();

                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
            public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
            {
                if (!this.CanHandle(request.Uri))
                {
                    return(false);
                }

                if (request.Uri.AbsolutePath.EndsWith("index.html", StringComparison.Ordinal) || request.Uri.AbsolutePath.EndsWith("index.htm", StringComparison.Ordinal))
                {
                    response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0");
                }
                else
                {
                    response.AddHeader("Cache-Control", "max-age=" + (60 * 60 * 24));
                }
                return(base.Process(request, response, session));
            }
Exemplo n.º 17
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string day_number = request.QueryString[UrlParameters.DayNumber].Value;

                int dayNumber = 0;

                DateTime day = DateTime.Now;

                if (Int32.TryParse(day_number, out dayNumber))
                {
                    day = new DateTime(day.Year, 1, 1);

                    dayNumber--;

                    if (!DateTime.IsLeapYear(day.Year) && dayNumber == 365)
                    {
                        dayNumber--;
                    }

                    day = day.AddDays(dayNumber);
                }

                var sdata = NetworkUsageCounter.GetDayStats(day);

                JsonArray ja = new JsonArray();

                for (int i = 0; i < sdata.Length; i++)
                {
                    double t = sdata[i].Value / 1024 / 1024;

                    JsonArray inner = new JsonArray();

                    inner.Add(sdata[i].Key);
                    inner.Add(Math.Round(t, 2, MidpointRounding.AwayFromZero));

                    ja.Add(inner);
                }

                WriteJsonResponse(response, ja.ToString());
                return(true);
            }

            return(false);
        }
Exemplo n.º 18
0
        private void SearchBackupFiles(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
        {
            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;

            var filter     = (input["filter"].Value ?? "").Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries);
            var timestring = input["time"].Value;
            var allversion = Duplicati.Library.Utility.Utility.ParseBool(input["all-versions"].Value, false);

            if (string.IsNullOrWhiteSpace(timestring) && !allversion)
            {
                ReportError(response, bw, "Invalid or missing time");
                return;
            }
            var bk = Program.DataConnection.GetBackup(input["id"].Value);

            if (bk == null)
            {
                ReportError(response, bw, "Invalid or missing backup id");
                return;
            }

            var prefixonly     = Duplicati.Library.Utility.Utility.ParseBool(input["prefix-only"].Value, false);
            var foldercontents = Duplicati.Library.Utility.Utility.ParseBool(input["folder-contents"].Value, false);
            var time           = new DateTime();

            if (!allversion)
            {
                time = Duplicati.Library.Utility.Timeparser.ParseTimeInterval(timestring, DateTime.Now);
            }

            var r = Runner.Run(Runner.CreateListTask(bk, filter, prefixonly, allversion, foldercontents, time), false) as Duplicati.Library.Interface.IListResults;

            var result = new Dictionary <string, object>();

            foreach (HttpServer.HttpInputItem n in input)
            {
                result[n.Name] = n.Value;
            }

            result["Filesets"] = r.Filesets;
            result["Files"]    = r.Files;

            bw.OutputOK(result);
        }
Exemplo n.º 19
0
        public bool Process(HttpServer.IHttpRequest aRequest, HttpServer.IHttpResponse aResponse, HttpServer.Sessions.IHttpSession aSession)
        {
            if (aRequest.Uri.AbsolutePath == "/user/hello/")
            {
                if (Host != null)
                {
                    Host.Logger.WriteLine(String.Format("Accept request for : {0}", aRequest.Uri.ToString()));
                }

                var writer = new StreamWriter(aResponse.Body);
                writer.WriteLine("Olá Malta...");
                writer.Flush();

                aResponse.Send();

                return(true);
            }
            return(false);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == Url || request.UriPath == (Url + "/"))
            {
                StringBuilder sb = new StringBuilder(HtmlTemplates.MonitoredBoardsPageTemplate);

                IncludeCommonHtml(sb);

                sb.Replace("{items}", GetMonitoredBoardsTableHtml());

                sb.Replace("{blist}", ThreadServerModule.get_board_list("boardletter"));

                WriteFinalHtmlResponse(response, sb.ToString());

                return(true);
            }

            return(false);
        }
Exemplo n.º 21
0
        void server_ProcessRequest(HttpServer.IHttpRequest request, System.IO.StreamWriter responseWriter)
        {
            var sr = new StreamReader(request.Body);

            //read json from request
            var json = sr.ReadToEnd();

            //deserialize json from request
            Request autoRemoteRequest = Communication.GetRequestFromJson(json);

            //get response from request
            Response response = autoRemoteRequest.ExecuteRequest();

            //serialize response
            String jsonResponse = JsonConvert.SerializeObject(response);

            //send response back to sender
            responseWriter.Write(jsonResponse);
        }
Exemplo n.º 22
0
        protected override void SetupRequest(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            int lcid = 1033;

            if (request.QueryString.Contains("lcid"))
            {
                if (int.TryParse(request.QueryString["lcid"].Value, out lcid))
                {
                    session["lcid"] = lcid;
                }
            }

            if (session["lcid"] != null)
            {
                lcid = (int)session["lcid"];
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo(lcid);

            base.SetupRequest(request, response, session);
        }
Exemplo n.º 23
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == Url || request.UriPath == (Url + "/"))
            {
                StringBuilder sb = new StringBuilder(HtmlTemplates.WatchJobsPageTemplate);

                IncludeCommonHtml(sb);

                sb.Replace("{{watched-threads-table}}", GetWatchedThreadsTableHtml());

                sb.Replace("//{ai_items_js}", get_ai_items());

                sb.Replace("//{board_names_js}", get_boards_names_js());

                sb.Replace("{archives}", get_archives_html());

                WriteFinalHtmlResponse(response, sb.ToString());
                return(true);
            }
            return(false);
        }
Exemplo n.º 24
0
        protected override void HandleRequest(HttpServer.IHttpClientContext context, HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            var handler = _handlerManager[request.Uri.LocalPath];

            if (handler != null)
            {
                try
                {
                    handler.Execute(context, request, response, session);
                }
                catch (Exception e)
                {
                    Logger.LogWarn(e);
                }
            }
            else
            {
                new FileHandler().Execute(context, request, response, session);
            }

            base.HandleRequest(context, request, response, session);
        }
Exemplo n.º 25
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (!request.Uri.AbsolutePath.StartsWith(path))
            {
                return(false);
            }
            HttpServerUtil.DebugPrintRequest(request);

            Socket socket = HttpServerUtil.GetNetworkSocket(response);

            //response.ContentLength = long.MaxValue;
            response.ContentType = "audio/" + fileInfo.Extension.Substring(1);
            response.AddHeader("TransferMode.DLNA.ORG", "Streaming");
            response.AddHeader("Server", "UPnP/1.0 DLNADOC/1.50 LAB/1.0");

            FileStream stream = fileInfo.OpenRead();

            // create local output buffers
            byte[] buffer = new byte[BUFFER_SIZE];

            HttpServerUtil.DebugPrintResponse(response);
            response.SendHeaders();

            int bytesRead = 1;

            while (socket.Connected && bytesRead > 0)
            {
                // file stream -> byte array buffer -> circlebuffer -> add metadata -> byte array buffer -> response stream
                bytesRead = stream.Read(buffer, 0, buffer.Length);
                response.SendBody(buffer, 0, bytesRead);
            }

            // remove local output buffer
            stream.Close();

            Console.WriteLine("request processing finished");

            return(true);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string value = request.QueryString[UrlParameters.IsEnabled].Value;
                Settings.ThumbnailOnly = value == "true";

                string redirect = request.QueryString[UrlParameters.RedirectUrl].Value;

                if (!string.IsNullOrWhiteSpace(redirect))
                {
                    response.Redirect(redirect);
                }
                else
                {
                    response.Redirect("/");
                }

                return(true);
            }

            return(false);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string board = request.QueryString[UrlParameters.Board].Value;

                if (!string.IsNullOrWhiteSpace(board))
                {
                    BoardWatcher bw = Program.GetBoardWatcher(board);

                    if (bw != null)
                    {
                        for (int i = 0; i < bw.watched_threads.Count; i++)
                        {
                            try
                            {
                                ThreadWorker tw = bw.watched_threads.ElementAt(i).Value;
                                if (!tw.AddedAutomatically)
                                {
                                    tw.Stop();
                                }
                            }
                            catch (System.IndexOutOfRangeException)
                            {
                                break;
                            }
                            catch { }
                        }
                    }
                }
                response.Redirect(MonitoredBoardsPageHandler.Url);
                return(true);
            }

            return(false);
        }
Exemplo n.º 28
0
 public static void DoProcess(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, string method, string module, string key)
 {
     using (var reqinfo = new RequestInfo(request, response, session))
         DoProcess(reqinfo, method, module, key);
 }
Exemplo n.º 29
0
 public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
 {
     System.Diagnostics.Trace.WriteLine(string.Format("Rejecting request for {0}", request.Uri));
     return(false);
 }
Exemplo n.º 30
0
 public BodyWriter(HttpServer.IHttpResponse resp, HttpServer.IHttpRequest request)
     : this(resp, request.QueryString["jsonp"].Value)
 {
 }