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); }
private string GetMonitoredBoardsTableHtml() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Program.active_dumpers.Count; i++) { try { BoardWatcher bw = Program.active_dumpers.ElementAt(i).Value; sb.Append("<tr>"); if (bw.IsMonitoring) //is running { sb.AppendFormat("<td><a class=\"btn btn-warning\" href=\"/cancel/bw/{0}\">Stop</a></td>", bw.Board); } else { //sb.AppendFormat("<td><a class=\"btn btn-info\" href=\"/cancel/bwr/{0}\">Start (Full Mode)</a></td>", bw.Board); sb.Append("<td>-</td>"); } sb.AppendFormat("<td>/{0}/</td>", bw.Board); sb.AppendFormat("<td>{0}</td>", bw.Mode.ToString()); sb.AppendFormat("<td>{0}</td>", bw.ActiveThreadWorkers); sb.AppendFormat("<td><a class=\"btn btn-default\" href=\"{0}\">Stop all manually added threads</a></td>", StopAllManuallyAddedThreadsHandler.GetLinkToThisPage(bw.Board)); sb.AppendFormat("<td><a href='/boards/{0}' class='label label-danger'>*click*</a></td>", bw.Board); sb.AppendFormat("<td> <a href='/logs/{0}/{1}' class='label label-primary'>Logs</a> </td>", "boardwatcher", bw.Board); sb.Append("</tr>"); } catch (Exception) { if (i >= Program.active_dumpers.Count()) { break; } } } return(sb.ToString()); }
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); }
private string GetWatchedThreadsTableHtml() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Program.active_dumpers.Count; i++) { try { BoardWatcher bw = Program.active_dumpers.ElementAt(i).Value; for (int index = 0; index < bw.watched_threads.Count; index++) { try { ThreadWorker tw = bw.watched_threads.ElementAt(index).Value; // Don't pollute the list with unactive thread workers (because no filter match) in monitor modes if (tw.AddedAutomatically && (!tw.IsActive) && (bw.Mode == BoardWatcher.BoardMode.Whitelist || bw.Mode == BoardWatcher.BoardMode.Blacklist)) { continue; } sb.Append("<tr>"); sb.AppendFormat("<td><a class=\"btn btn-default\" href='/action/removethreadworker/?board={0}&id={1}' title='Remove'><i class=\"fa fa-trash-o\"></i></a></td>", tw.Board.Board, tw.ID); if (tw.IsStatic) { sb.Append("<td><a class=\"btn btn-primary\" href='#'>Static</a></td>"); } else { if (tw.IsActive) { sb.AppendFormat("<td><a class=\"btn btn-warning\" href=\"/cancel/tw/{0}/{1}\">Stop</a></td>", bw.Board, tw.ID); } else { sb.AppendFormat("<td><a class=\"btn btn-info\" href=\"/cancel/twr/{0}/{1}\">Start</a></td>", bw.Board, tw.ID); } } sb.AppendFormat("<td>{0}</td>", string.Format("/{0}/", bw.Board)); sb.AppendFormat("<td>{0}</td>", tw.ID); sb.AppendFormat("<td>{0}</td>", tw.AddedAutomatically ? "<span class=\"label label-primary\">Yes</span>" : "<span class=\"label label-default\">No</span>"); sb.AppendFormat("<td>{0}</td>", tw.ThumbOnly ? "<span class=\"label label-primary\">Yes</span>" : "<span class=\"label label-default\">No</span>"); sb.AppendFormat("<td><a href='/boards/{0}/{1}' class='label label-danger'>*click*</a></td>", bw.Board, tw.ID); sb.AppendFormat("<td><pre>{0}</pre></td>", tw.ThreadTitle); sb.AppendFormat("<td>{0} ago</td>", HMSFormatter.GetReadableTimespan(DateTime.Now - tw.LastUpdated).ToLower()); sb.AppendFormat("<td>{0}</td>", tw.AutoSage ? "<span class=\"label label-primary\">Yes</span>" : "<span class=\"label label-default\">No</span>"); sb.AppendFormat("<td>{0}</td>", tw.ImageLimitReached ? "<span class=\"label label-primary\">Yes</span>" : "<span class=\"label label-default\">No</span>"); sb.AppendFormat("<td> <a href='/threadinfo?board={0}&id={1}' class='label label-primary'>Info</a> </td>", bw.Board, tw.ID); sb.Append("</tr>"); } catch (Exception) { if (index >= bw.watched_threads.Count) { break; } } } } catch (Exception) { if (i >= Program.active_dumpers.Count) { break; } } } return(sb.ToString()); }
protected string GetThreadFiltersTableHtml() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Program.active_dumpers.Count; i++) { try { BoardWatcher bw = Program.active_dumpers.ElementAt(i).Value; ChanArchiver.Filters.IFilter[] Filters = GetFilterType() == ChanArchiver.Filters.FilterType.WhiteList ? bw.WhitelistFilters : bw.BlacklistFilters; for (int index = 0; index < Filters.Length; index++) { ChanArchiver.Filters.IFilter f = Filters[index]; sb.Append("<tr>"); sb.AppendFormat("<td>/{0}/</td>", bw.Board); sb.AppendFormat("<td>{0}</td>", f.GetType().FullName.Split('.').Last()); sb.AppendFormat("<td><code>{0}</code></td>", HttpUtility.HtmlEncode(f.FilterText)); { StringBuilder notes_form = new StringBuilder(); notes_form.Append("<div class=\"input-group\">"); notes_form.Append("<form action='/filters/'>"); notes_form.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", "mode", "editnotes"); notes_form.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", "b", bw.Board); notes_form.AppendFormat("<input type='hidden' name='{0}' value='{1}' />", "filterindex", index); notes_form.Append("<textarea class='form-control' cols='6' rows='3' name='notestext'>"); notes_form.Append(HttpUtility.HtmlEncode(f.Notes)); notes_form.Append("</textarea>"); //notes_form.Append("<br/>"); notes_form.Append("<span class=\"input-group-btn\"><button type='submit' class='btn btn-default'>Save</button></span>"); notes_form.Append("</form></div>"); sb.AppendFormat("<td>{0}</td>", notes_form.ToString()); } //sb.AppendFormat("<td><a class='label label-warning' href='/filters/?mode=edit&b={0}&i={1}'>Edit</a></td>", bw.Board, index); sb.AppendFormat("<td><a class=\"btn btn-default\" title='Delete' href='/filters/?mode=delete&b={0}&i={1}'><i class=\"fa fa-trash-o\"></i></a></td>", bw.Board, index); sb.Append("</tr>"); } } catch (Exception) { if (i >= Program.active_dumpers.Count) { break; } } } return(sb.ToString()); }
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); }
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session) { string command = request.UriPath.ToString(); if (command.StartsWith("/logs/")) { string[] a = command.Split('/'); if (a.Length >= 3) { string mode = a[2]; string id = a[3]; LogEntry[] data = null; switch (mode) { case "file": FileQueueStateInfo st = Program.get_file_state(id); if (st != null) { data = st.Logs; } break; case "threadworker": // /logs/threadworker/board/tid if (Program.active_dumpers.ContainsKey(id)) { BoardWatcher bw = Program.active_dumpers[id]; if (bw.watched_threads.ContainsKey(Convert.ToInt32(a[4]))) { data = bw.watched_threads[Convert.ToInt32(a[4])].Logs; } } break; case "boardwatcher": if (Program.active_dumpers.ContainsKey(id)) { BoardWatcher bw = Program.active_dumpers[id]; data = bw.Logs; } break; default: break; } if (data != null) { StringBuilder items = new StringBuilder(); for (int index = 0; index < data.Length; index++) { try { LogEntry e = data[index]; items.Append("<tr>"); switch (e.Level) { case LogEntry.LogLevel.Fail: items.Append("<td><span class=\"label label-danger\">Fail</span></td>"); break; case LogEntry.LogLevel.Info: items.Append("<td><span class=\"label label-info\">Info</span></td>"); break; case LogEntry.LogLevel.Success: items.Append("<td><span class=\"label label-success\">Success</span></td>"); break; case LogEntry.LogLevel.Warning: items.Append("<td><span class=\"label label-warning\">Warning</span></td>"); break; default: items.Append("<td><span class=\"label label-default\">Unknown</span></td>"); break; } items.AppendFormat("<td>{0}</td>", e.Time); items.AppendFormat("<td>{0}</td>", e.Title); items.AppendFormat("<td>{0}</td>", e.Sender); items.AppendFormat("<td>{0}</td>", e.Message); items.Append("</tr>"); } catch (Exception) { continue; } } //write everything response.Status = System.Net.HttpStatusCode.OK; response.ContentType = "text/html"; byte[] fdata = Encoding.UTF8.GetBytes(Properties.Resources.logs_page.Replace("{Logs}", items.ToString())); response.ContentLength = fdata.Length; response.SendHeaders(); response.SendBody(fdata); return(true); } else { //404 return(false); } } } 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.ThreadFiltersPageTemplate); IncludeCommonHtml(sb); 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("/filters/")) { 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("/filters"); 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.Filters.Length - 1) { bw.RemoveFilter(inde); bw.SaveFilters(); response.Redirect(ThreadFiltersPageHandler.Url); 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(ThreadFiltersPageHandler.Url); 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.Filters.Length) { Filters.IFilter fil = bw.Filters[index]; fil.Notes = notes_text; bw.SaveFilters(); response.Redirect(ThreadFiltersPageHandler.Url); return true; } } } } return false; default: return false; } } return false; }