Exemple #1
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.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);
        }
        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);
        }
Exemple #4
0
        public sealed override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath == GetPageUrl())
            {
                StringBuilder sb = new StringBuilder(HtmlTemplates.ThreadFiltersPageTemplate);

                IncludeCommonHtml(sb);

                sb.Replace("{{inline-title}}", GetPageTitle());
                sb.Replace("{{boards-list-html}}", ThreadServerModule.get_board_list(UrlParameters.Board));
                sb.Replace("{{available-filters-list}}", get_available_filters());
                sb.Replace("{{filters-list}}", GetThreadFiltersTableHtml());

                WriteFinalHtmlResponse(response, sb.ToString());

                return(true);
            }

            if (request.UriPath.StartsWith(GetPageUrl() + "/"))
            {
                string mode  = request.QueryString["mode"].Value;
                string board = request.QueryString[UrlParameters.Board].Value;

                BoardWatcher bw;

                switch (mode)
                {
                case "add":
                {
                    if (Program.active_dumpers.ContainsKey(board))
                    {
                        bw = Program.active_dumpers[board];
                    }
                    else
                    {
                        bw = new BoardWatcher(board);
                        Program.active_dumpers.Add(board, bw);
                    }

                    string filter_type = request.QueryString["type"].Value;
                    string filter_exp  = request.QueryString["exp"].Value;

                    if (string.IsNullOrEmpty(filter_exp) || string.IsNullOrEmpty(filter_type))
                    {
                        return(false);
                    }
                    else
                    {
                        ChanArchiver.Filters.IFilter f = get_filter(filter_type, filter_exp);
                        if (f != null)
                        {
                            bw.AddFilter(f);
                            bw.SaveFilters();
                            response.Redirect(GetPageUrl());
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                case "edit":
                    return(false);

                case "delete":
                {
                    if (Program.active_dumpers.ContainsKey(board))
                    {
                        string index = request.QueryString["i"].Value;

                        bw = Program.active_dumpers[board];

                        int inde = -1;
                        Int32.TryParse(index, out inde);

                        if (inde >= 0 && inde <= bw.WhitelistFilters.Length - 1)
                        {
                            bw.RemoveFilter(inde);
                            bw.SaveFilters();
                            response.Redirect(GetPageUrl());
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "editnotes":
                {
                    string fID        = request.QueryString["filterindex"].Value;
                    string notes_text = request.QueryString["notestext"].Value;

                    if (string.IsNullOrEmpty(fID) || string.IsNullOrEmpty(board))
                    {
                        response.Redirect(GetPageUrl());
                        return(true);
                    }
                    else
                    {
                        if (Program.active_dumpers.ContainsKey(board))
                        {
                            bw = Program.active_dumpers[board];

                            int index = -1;

                            Int32.TryParse(fID, out index);

                            if (index >= 0 && index < bw.WhitelistFilters.Length)
                            {
                                Filters.IFilter fil = bw.WhitelistFilters[index];

                                fil.Notes = notes_text;
                                bw.SaveFilters();
                                response.Redirect(GetPageUrl());
                                return(true);
                            }
                        }
                    }
                }
                    return(false);

                default:
                    return(false);
                }
            }

            return(false);
        }
Exemple #5
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);
                }

                PostFormatter[] thread_data = ThreadStore.GetStorageEngine().GetThread(board, threadIdStr);

                MemoryStream memIO = new MemoryStream();

                ZipOutputStream zipStream = new ZipOutputStream(memIO);
                zipStream.SetLevel(0); // no compression is needed since most of the files are media files, and they are already compressed anyway

                write_file_to_zip(zipStream, "res/blue.css", Encoding.UTF8.GetBytes(Properties.Resources.css_blue));
                write_file_to_zip(zipStream, "res/sticky.png", Properties.Resources.sticky);
                write_file_to_zip(zipStream, "res/locked.png", Properties.Resources.locked);

                foreach (PostFormatter pf in thread_data)
                {
                    if (pf.MyFile != null)
                    {
                        string full_path;
                        if (FileOperations.ResolveFullFilePath(pf.MyFile.Hash, pf.MyFile.Extension, out full_path))
                        {
                            string ext = Path.GetExtension(full_path);

                            if (!string.IsNullOrEmpty(ext))
                            {
                                ext = ext.Substring(1);
                            }

                            if (ext != pf.MyFile.Extension)
                            {
                                pf.MyFile.ChangeExtension(ext);
                            }

                            string zip_file_name = string.Format("file/{0}.{1}", pf.MyFile.Hash, ext);

                            byte[] data = File.ReadAllBytes(full_path);

                            pf.MyFile.Size = data.Length;

                            write_file_to_zip(zipStream, zip_file_name, data);
                        }

                        string thumb_path;

                        if (FileOperations.CheckThumbFileExist(pf.MyFile.Hash, out thumb_path))
                        {
                            string zip_file_name = string.Format("thumb/{0}.jpg", pf.MyFile.Hash);
                            write_file_to_zip(zipStream, zip_file_name, File.ReadAllBytes(thumb_path));
                        }
                    }
                }

                string notes = ThreadStore.GetStorageEngine().GetThreadNotes(board, threadId);

                string pageHtml = build_page_html(board, threadIdStr, thread_data, notes);

                write_file_to_zip(zipStream, "index.html", Encoding.UTF8.GetBytes(pageHtml));

                zipStream.Close();
                memIO.Close();

                byte[] result = memIO.ToArray();

                response.Status        = System.Net.HttpStatusCode.OK;
                response.ContentType   = ServerConstants.ZipContentType;
                response.ContentLength = result.Length;
                response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}.zip\"", threadId));
                response.SendHeaders();
                response.SendBody(result);

                return(true);
            }
            return(false);
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            string command = request.UriPath.ToString();

            if (command == "/favicon.ico")
            {
                response.Status        = System.Net.HttpStatusCode.OK;
                response.ContentLength = Properties.Resources.favicon_ico.Length;
                response.ContentType   = "image/x-icon";
                response.SendHeaders();
                response.SendBody(Properties.Resources.favicon_ico);
                return(true);
            }

            if (command.StartsWith("/res/"))
            {
                byte[] data = null;
                switch (command.Split('/')[2].ToLower())
                {
                case "bgwhite.png":
                    data = Properties.Resources.bgwhite;
                    response.ContentType = "image/png";
                    break;

                case "hr.png":
                    data = Properties.Resources.hr;
                    response.ContentType = "image/png";
                    break;

                case "locked.png":
                    data = Properties.Resources.locked;
                    response.ContentType = "image/png";
                    break;

                case "sticky.png":
                    data = Properties.Resources.sticky;
                    response.ContentType = "image/png";
                    break;

                case "bootstrap.css":
                    //data = Encoding.UTF8.GetBytes(Properties.Resources.bootstrap_css);
                    data = Properties.Resources.paper_theme_min;
                    response.ContentType = "text/css";
                    break;

                case "dashboard.css":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.dashboard_css);
                    response.ContentType = "text/css";
                    break;

                case "bootstrap.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.bootstrap_js);
                    response.ContentType = "application/javascript";
                    break;

                case "jquery.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_js);
                    response.ContentType = "application/javascript";
                    break;

                case "docs.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.docs_js);
                    response.ContentType = "application/javascript";
                    break;

                case "css.css":
                    data = Encoding.UTF8.GetBytes(ChanArchiver.Properties.Resources.layout);
                    response.ContentType = "text/css";
                    break;

                case "blue.css":
                    data = Encoding.UTF8.GetBytes(ChanArchiver.Properties.Resources.css_blue);
                    response.ContentType = "text/css";
                    break;

                case "favicon.ico":
                    data = Properties.Resources.favicon_ico;
                    response.ContentType = "image/x-icon";
                    break;

                case "jquery.flot.min.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_flot_min);
                    response.ContentType = "application/javascript";
                    break;

                case "jquery.flot.categories.min.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_flot_categories_min);
                    response.ContentType = "application/javascript";
                    break;

                case "jquery.flot.pie.min.js":
                    data = Properties.Resources.jquery_flot_pie_min;
                    response.ContentType = "application/javascript";
                    break;

                case "sorttable.js":
                    data = Properties.Resources.sorttable_js;
                    response.ContentType = "application/javascript";
                    break;
                //webfonts

                case "font-awesome.min.css":
                    data = Properties.Resources.font_awesome_min;
                    response.ContentType = "text/css";
                    break;

                case "fontawesome-webfont.eot":
                    data = Properties.Resources.fontawesome_webfont_eot;
                    response.ContentType = "application/vnd.ms-fontobject";
                    break;

                case "fontawesome-webfont.svg":
                    data = Properties.Resources.fontawesome_webfont_svg;
                    response.ContentType = "image/svg+xml";
                    break;

                case "fontawesome-webfont.ttf":
                case "fontawesome-webfont.ttf?v=4.1.0":
                    data = Properties.Resources.fontawesome_webfont_ttf;
                    response.ContentType = "application/font-sfnt";
                    break;

                case "fontawesome-webfont.woff":
                case "fontawesome-webfont.woff?v=4.1.0":
                    data = Properties.Resources.fontawesome_webfont_woff;
                    response.ContentType = "application/font-woff";
                    break;

                case "FontAwesome.otf":
                    data = Properties.Resources.FontAwesome_otf;
                    response.ContentType = "application/font-sfnt";
                    break;

                case "verify.js":
                    data = Encoding.UTF8.GetBytes(Properties.Resources.verify_notify_min);
                    response.ContentType = "application/javascript";
                    break;

                default:
                    break;
                }

                if (data == null)
                {
                    ThreadServerModule._404(response);
                }
                else
                {
                    response.Status        = System.Net.HttpStatusCode.OK;
                    response.ContentLength = data.Length;
                    response.SendHeaders();
                    response.SendBody(data);
                }
            }

            return(false);
        }