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);
        }
示例#2
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);
        }
        private string GetFileQueueTableHtml(stats s)
        {
            StringBuilder sb = new StringBuilder();

            var ordered = Program.queued_files.OrderByDescending(x => x.Value.Percent());

            s.files_count = ordered.Count();

            for (int index = 0; index < s.files_count; index++)
            {
                try
                {
                    KeyValuePair <string, FileQueueStateInfo> kvp = ordered.ElementAt(index);

                    FileQueueStateInfo f = kvp.Value;

                    if ((!Settings.ListThumbsInQueue) && f.Type == FileQueueStateInfo.FileType.Thumbnail)
                    {
                        continue;
                    }

                    //sb.AppendFormat("<tr id='{0}'>", kvp.Key);

                    sb.Append("<tr>");

                    sb.AppendFormat("<td>{0}</td>", get_file_status(f.Status));

                    sb.AppendFormat("<td>{0}</td>", f.RetryCount);

                    sb.AppendFormat("<td>{0}</td>", get_type(f.Type));
                    sb.AppendFormat("<td>{0}</td>", f.Hash);

                    if (f.Type == FileQueueStateInfo.FileType.FullFile)
                    {
                        sb.AppendFormat("<td>{0}</td>", Program.format_size_string(f.PostFile.size));

                        if (f.Status != FileQueueStateInfo.DownloadStatus.Complete || f.Status != FileQueueStateInfo.DownloadStatus.NotFound)
                        {
                            s.total_files_size += f.PostFile.size;
                        }
                    }
                    else
                    {
                        sb.AppendFormat("<td>{0}</td>", Program.format_size_string(f.Length));

                        //complete files are not in the queue any more
                        if (f.Status != FileQueueStateInfo.DownloadStatus.Complete || f.Status != FileQueueStateInfo.DownloadStatus.NotFound)
                        {
                            s.total_files_size += f.Length;
                        }
                    }

                    sb.AppendFormat("<td>/{0}/</td>", f.PostFile.board);

                    sb.AppendFormat("<td><code><a href='/boards/{0}/{1}'>{1}</a></code></td>", f.PostFile.board, f.PostFile.owner.OwnerThread.ID);

                    sb.AppendFormat("<td><code><a href='/boards/{0}/{1}#p{2}'>{2}</a></code></td>", f.PostFile.board, f.PostFile.owner.OwnerThread.ID, f.PostFile.owner.ID);

                    if (f.Type == FileQueueStateInfo.FileType.Thumbnail)
                    {
                        sb.Append("<td><span class=\"label label-info\">JPG</span></td>");
                        IncrementKey(s.exts_stats, "jpg");
                    }
                    else
                    {
                        sb.AppendFormat("<td>{0}</td>", get_ext(f.PostFile.ext));
                        IncrementKey(s.exts_stats, f.PostFile.ext);
                    }

                    sb.AppendFormat("<td>{0} %</td>", Math.Round(f.Percent(), 2));

                    sb.AppendFormat("<td> <a href=\"{0}\" class=\"label label-primary\">Info</a> </td>", FileInfoPageHandler.GetLinkToThisPage(kvp.Key));

                    sb.AppendFormat("<td><span class=\"label label-primary\">{0}</span></td>", f.Type == FileQueueStateInfo.FileType.FullFile ? f.Priority.ToString().Replace("Level", "") : "N/A");

                    sb.Append("</tr>");

                    IncrementKey(s.board_stats, f.PostFile.board);
                }
                catch (Exception)
                {
                    if (index >= Program.queued_files.Keys.Count)
                    {
                        break;
                    }
                }
            }
            return(sb.ToString());
        }
示例#4
0
        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);
        }
 private string get_type(FileQueueStateInfo.FileType ty)
 {
     if (ty == FileQueueStateInfo.FileType.FullFile)
     {
         return "<span class=\"label label-warning\">Full File</span>";
     }
     else
     {
         return "<span class=\"label label-danger\">Thumb</span>";
     }
 }
        private string get_file_status(FileQueueStateInfo.DownloadStatus s)
        {
            switch (s)
            {
                case FileQueueStateInfo.DownloadStatus.Downloading:
                    return "<span class=\"label label-info\">Downloading</span>";
                case FileQueueStateInfo.DownloadStatus.Connecting:
                    return ("<span class=\"label label-warning\">Connecting</span>");
                case FileQueueStateInfo.DownloadStatus.Error:
                    return ("<span class=\"label label-danger\">Error</span>");
                case FileQueueStateInfo.DownloadStatus.Complete:
                    return ("<span class=\"label label-success\">Complete</span>");
                case FileQueueStateInfo.DownloadStatus.Queued:
                    return ("<span class=\"label label-default\">Queued</span>");
                case FileQueueStateInfo.DownloadStatus.NotFound:
                    return ("<span class=\"label label-danger\">404</span>");
                case FileQueueStateInfo.DownloadStatus.Stopped:
                    return ("<span class=\"label label-primary\">Stopped</span>");

                default:
                    return string.Format("<span class=\"label label-default\">{0}</span>", s);
            }
        }
示例#7
0
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            string command = request.UriPath;

            if (command.StartsWith("/fileinfo/"))
            {
                string[] a = command.Split('/');

                if (a.Length >= 3)
                {
                    string filehash = a[2];

                    FileQueueStateInfo fqs = Program.get_file_state(filehash);

                    if (fqs != null)
                    {
                        StringBuilder page = new StringBuilder(Properties.Resources.fileinfo);

                        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}", filehash);

                        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));


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

                        byte[] data = Encoding.UTF8.GetBytes(page.ToString());
                        response.ContentLength = data.Length;
                        response.SendHeaders();
                        response.SendBody(data);

                        return(true);
                    }
                    else
                    {
                        response.Redirect("/fq");
                        return(true);
                    }
                }
            }



            return(false);
        }