Exemplo n.º 1
0
        public override bool Apply(Request request)
        {
            int headers = request.Count;

            string connection = request.GetHeader ("Proxy-Connection");
            request.RemoveHeader ("Proxy-Connection");
            if (connection == null)
                request.ReplaceHeader ("Connection", "close");
            else
                request.ReplaceHeader ("Connection", connection);

            if (headers != request.Count)
                return true;
            else
                return false;
        }
Exemplo n.º 2
0
        public override bool Apply(Request request)
        {
            if (request.Response != null) {
                request.Response.Add ("X-PP-User-Agent: " + request.GetHeader ("User-Agent"));
                return false;
            }

            try {
                listLock.EnterReadLock ();

                if (staticAgent.ContainsKey (request.Uri.Host)) {
                    UserAgentRule r = staticAgent[request.Uri.Host];

                    if (r.UserAgent == "") {
                        request.RemoveHeader ("User-Agent");
                    } else if (r.UserAgent.ToLowerInvariant () == "random") {
                        request.ReplaceHeader ("User-Agent", RandomUserAgent ());
                    } else if (r.UserAgent.ToLowerInvariant () != "pass") {
                        request.ReplaceHeader ("User-Agent", r.UserAgent);
                    }

                    if (r.Lang == "") {
                        request.RemoveHeader ("Accept-Language");
                    } else if (r.Lang.ToLowerInvariant () == "random") {
                        request.ReplaceHeader ("Accept-Language", GetRandom (lang));
                    } else if (r.Lang.ToLowerInvariant () != "pass") {
                        request.ReplaceHeader ("Accept-Language", r.Lang);
                    }

                } else {
                    //Default
                    request.ReplaceHeader ("User-Agent", RandomUserAgent ());
                    request.RemoveHeader ("Accept-Language");
                }
            } finally {
                listLock.TryExitReadLock ();
            }
            return true;
        }
Exemplo n.º 3
0
        public override Response Status(NameValueCollection httpGet, Request request)
        {
            Html html = Html.Format ("<p>Replaces the User-Agent and Accept-Language headers with random ones</p>");
            html += Html.Format ("<p><strong>Your: </strong> {0}</p>", request.GetHeader ("User-Agent"));
            html += Html.Format ("<p><strong>Random: </strong> {0}</p>", RandomUserAgent ());

            if (httpGet["delete"] != null) {
                try {
                    listLock.EnterWriteLock ();
                    staticAgent.Remove (httpGet["delete"]);
                } finally {
                    listLock.TryExitWriteLock ();
                }

                saveSettings ();
            }

            if (httpGet["action"] != null) {
                UserAgentRule r = new UserAgentRule ();
                r.Domain = httpGet["domain"];
                r.Lang = httpGet["lang"];
                if (httpGet["action"] == "Permanent")
                    r.Permanent = true;
                r.UserAgent = httpGet["agent"];
                if (r.UserAgent.ToLowerInvariant () == "random") {
                    r.UserAgent = RandomUserAgent ();
                    r.Random = true;
                }

                try {
                    listLock.EnterWriteLock ();
                    staticAgent.Add (r.Domain, r);
                } finally {
                    listLock.TryExitWriteLock ();
                }

                if (r.Permanent)
                    saveSettings ();
            }

            html += Html.Format (@"<form action=""?"" method=""get"">
                                <p><label for=""domain"">Domain</label>: <input type=""text"" name=""domain"" value="""" /></p>
                                <p><label for=""lang"">Language</label>: <input type=""text"" name=""lang"" value="""" /></p>
                                <p><label for=""agent"">User-Agent</label>: <input type=""text"" name=""agent"" value="""" />
                                    ""random"" = change every session.
                                    ""pass"" = pass through unmodified</p>
                                <input type=""submit"" name=""action"" value=""Permanent"" />
                                <input type=""submit"" name=""action"" value=""Temporary"" />
                            </form>");
            try {
                listLock.EnterReadLock ();

                foreach (UserAgentRule rule in staticAgent.Values) {
                    html += Html.Format ("<p>{0} <a href=\"?delete={1}\">delete</a></p>", rule, rule.Domain);
                }
            } finally {
                listLock.ExitReadLock ();
            }

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