示例#1
0
        public override Response Status(NameValueCollection httpGet, Request request)
        {
            Html html = new Html ();

            if (httpGet ["delete"] != null) {
                int item = int.Parse (httpGet ["delete"]);
                using (listLock.Write) {
                    foreach (RefererPair rp in watchlist.ToArray ()) {
                        if (rp.GetHashCode () == item)
                            watchlist.Remove (rp);
                    }
                }

                SaveFilters ();
            }

            if (httpGet ["clear"] != null) {
                using (listLock.Write) {
                    blocked.Clear ();
                }
            }

            if (httpGet ["action"] != null || httpGet ["flags"] != null) {
                RefererPair p = new RefererPair (httpGet ["from"], httpGet ["to"]);

                p.Flags.Set (httpGet ["flags"]);
                if (httpGet ["action"].Contains (" ") == false)
                    p.Flags.Set (httpGet ["action"]);

                using (listLock.Write) {
                    watchlist.Add (p);

                    foreach (RefererPair bp in blocked.ToArray ()) {
                        if (p.Match (bp))
                            blocked.Remove (bp);
                    }
                }
                SaveFilters ();
            }

            if (httpGet ["return"] != null) {
                Response resp = new Response (HttpStatusCode.Redirect, new Html ());
                resp.ReplaceHeader ("Location", httpGet ["return"]);
                return resp;
            }

            html += Html.Format (@"<h2>Blocked <a href=""?clear=yes"">clear</a></h2>");
            html += Html.Format ("<table><tr><th>From Domain</th><th>To Domain</th><th>Flags</th></tr>");
            html += Form ("", "");
            using (listLock.Read) {
                foreach (RefererPair pair in blocked) {
                    html += Form (pair);
                }
                html += Html.Format ("</table>");

                html += Html.Format ("<h2>Watchlist</h2>");

                html += Html.Format ("<table><tr><th>From Domain</th><th>To Domain</th><th>Flags</th><th>Delete</th></tr>");
                foreach (RefererPair pair in watchlist) {
                    html += Html.Format ("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td><a href=\"?delete={3}\">delete</a></td></tr>", pair.FromHost, pair.ToHost, pair.Flags, pair.GetHashCode ());
                }
                html += Html.Format ("</table>");
            }

            html += Html.Format (@"
            <div>
                <ul>
                    <li><strong>Pass</strong> Allow request to pass through unmodified</li>
                    <li><strong>Fake</strong> Change referer to the root of the target host</li>
                    <li><strong>Clean</strong> Change referer to the root of the source host</li>
                    <li><strong>Remove</strong> Remove the referer header</li>
                    <li><strong>Slow</strong> Do not modify the request but slow down the transfer speed</li>
                    <li><strong>Block</strong> Block the entire request</li>
                </ul>
                <p>From/To: Wildcard(*) allowed in start of domains, applies to subdomains only</p>
                <p>Example: *example.com matches xyz.example.com and example.com but not badexample.com</p>
            </div>");

            return WebUI.ResponseTemplate (ToString (), html);
        }