public override void Execute(ref string codes, string pageUrl, string pageUrlNoQuery, string pagePath, string rootUrl) { try { // 1- executing plugins if (Plugins.IsPluginAvailable(PluginHosts.IPluginJSProcessor)) { Plugins.CallPluginMethod(PluginHosts.IPluginJSProcessor, PluginMethods.IPluginJSProcessor.BeforeExecute, this, (object)codes, pageUrl, pageUrlNoQuery, pagePath, rootUrl); } // BugFix: setting document.domain will cause error in javascript // Also checking the value of document.domain may cause bad behaviours // so both are going ot be disabled here JSReplacer.ReplacePropertyUsages(ref codes, "document.domain", Consts.ClientContent.JSEncoder_ASProxyLocationXDomain); // New location should be encoded! JSReplacer.AddEncoderMethodToPropertySet(ref codes, new string[] { "location.href", "window.location", "document.location", "top.location", "self.location", "parent.location" }, Consts.ClientContent.JSEncoder_ASProxyEncoderMethodName); // Cookie set JSReplacer.AddEncoderMethodToPropertySet(ref codes, "document.cookie", Consts.ClientContent.JSEncoder_ASProxySetCookieMethodName); // Cookie get, Since v5.0 JSReplacer.AddEncoderMethodToPropertyGet(ref codes, "document.cookie", Consts.ClientContent.JSEncoder_ASProxyGetCookieMethodName, true); // Replaces these properties by __XUrl // top.location , parent.location and self.location JSReplacer.AddEncoderMethodToPropertyGet(ref codes, new string[] { "top", "parent", "self" }, new string[] { "location" }, Consts.ClientContent.JSEncoder_ASProxyWindowLocOverrider, false); // document.URL is only getter and its string JSReplacer.AddEncoderMethodToPropertyGet(ref codes, new string[] { "document" }, new string[] { "URL" }, Consts.ClientContent.JSEncoder_ASProxyWindowLocHref, false); // fisrt test location with base objects JSReplacer.AddEncoderMethodToPropertyGet(ref codes, new string[] { "window", "document", "location" }, new string[] { "location" }, Consts.ClientContent.JSEncoder_ASProxyWindowLocOverrider, false); // then location attributes test JSReplacer.AddEncoderMethodToPropertyGetFirstPart(ref codes, new string[] { "location" }, new string[] { "href", "search", "hash", "host", "hostname", "pathname", "port", "protocol", "replace", "assign" }, Consts.ClientContent.JSEncoder_ASProxyWindowLocOverrider, false); JSReplacer.AddEncoderMethodToMethodFirstParameter(ref codes, "location.replace", Consts.ClientContent.JSEncoder_ASProxyEncoderMethodName); // It is not common to use "open" method directly. // So i ignore to handle it here //JSReplacer.AddEncoderMethodToMethodFirstParameter(ref html, "open", Consts.JSEncoder_ASProxyEncoderMethodName); // Don't proccess these // The "open" method will proccess in JavaScript encoder in "asproxyencoder.js" file. // Since v4.8 //JSReplacer.AddEncoderMethodToMethodFirstParameter(ref html, "window.open", Consts.JSEncoder_ASProxyEncoderMethodName); //JSReplacer.AddEncoderMethodToMethodFirstParameter(ref html, "location.open", Consts.JSEncoder_ASProxyEncoderMethodName); // 2- executing plugins if (Plugins.IsPluginAvailable(PluginHosts.IPluginJSProcessor)) { Plugins.CallPluginMethod(PluginHosts.IPluginJSProcessor, PluginMethods.IPluginJSProcessor.AfterExecute, this, (object)codes, pageUrl, pageUrlNoQuery, pagePath, rootUrl); } } catch (Exception ex) { // error logs if (Systems.LogSystem.ErrorLogEnabled) { Systems.LogSystem.LogError(ex, pageUrl); } LastStatus = LastStatus.ContinueWithError; LastException = ex; LastErrorMessage = "ASProxy has some errors!"; codes = "/* ASProxy has some errors! \n" + ex.Message + " */" + codes; } }
/// <summary> /// Processes the html codes /// </summary> /// <param name="codes">Html codes</param> /// <param name="pageUrl">Page url. E.G. http://Site.com/users/profile.aspx?uid=90</param> /// <param name="rootUrl">Root path. E.G. http://Site.com/</param> public override void Execute(ref string codes, string pageUrl, string pageUrlNoQuery, string pagePath, string rootUrl) { try { // 1- executing plugins if (Plugins.IsPluginAvailable(PluginHosts.IPluginHtmlProcessor)) { Plugins.CallPluginMethod(PluginHosts.IPluginHtmlProcessor, PluginMethods.IPluginHtmlProcessor.BeforeExecute, this, (object)codes, pageUrl, pageUrlNoQuery, pagePath, rootUrl); } // ASProxy pages url formats generator ASProxyPagesFormat pages = new ASProxyPagesFormat(_UserOptions.EncodeUrl); // Original urls addistional codes option bool orginalUrlRequired = false; // Renames ASPDotNET standard ViewState name to a temporary name // This name will reset to default when the page posted back HtmlReplacer.ReplaceAspDotNETViewState(ref codes); // If remove scripts chosen, remove all the scripts. if (_UserOptions.RemoveScripts) { HtmlReplacer.RemoveScripts(ref codes); } // If remove embeded objects is requested if (_UserOptions.RemoveObjects) { // Removing <object> tag HtmlParser.RemoveTagContent(ref codes, "object", true); // Removing <embed> tag HtmlParser.RemoveTagContent(ref codes, "embed", true); } // Applying the BASE tag to the URLs. string baseHref; if (HtmlReplacer.ReplaceBaseSources(ref codes, true, out baseHref)) { // changing page base path to specified Base in the document pagePath = UrlProvider.AddSlashToEnd(baseHref); // BUGFIX v4.6.1:: site root url should change also rootUrl = UrlProvider.GetRootPath(rootUrl); } // processing style sheet links if (_UserOptions.Images) { HtmlReplacer.ReplaceCssLinks(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl); // TODO: CSSReplacer // This function replaces "Import" rule and background images! // So, this breaches to background option role. Since v4.0 CSSReplacer.ReplaceStyleTagStyleUrl(ref codes, pageUrlNoQuery, pages.PageAnyType, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl); } // It seems with javascript encoding these methods are useless!! // The javascript may be disabled in browser so we have to this anyway if (_UserOptions.Links) { string extraAttib = ""; // Add displaying orginal url address code if (_UserOptions.OrginalUrl) { orginalUrlRequired = true; extraAttib = Resources.STR_OrginalUrl_TagAttributeFormat; } // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttib += Consts.ClientContent.attrAlreadyEncodedAttributeWithValue; HtmlReplacer.ReplaceAnchors(ref codes, pageUrlNoQuery, pages.PageDefault, pagePath, rootUrl, _UserOptions.EncodeUrl, extraAttib); HtmlReplacer.ReplaceHttpRefresh(ref codes, pageUrlNoQuery, pages.PageDefault, pagePath, rootUrl, _UserOptions.EncodeUrl); } else { string extraAttib; // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttib = Consts.ClientContent.attrAlreadyEncodedAttributeWithValue; HtmlReplacer.ReplaceAnchors(ref codes, pageUrlNoQuery, "{0}", pagePath, rootUrl, false, extraAttib); HtmlReplacer.ReplaceHttpRefresh(ref codes, pageUrlNoQuery, "{0}", pagePath, rootUrl, _UserOptions.EncodeUrl); } if (_UserOptions.Frames) { string extraAttrib = Resources.STR_IFrame_ExtraAttribute; // Encode <iframe> tags HtmlReplacer.ReplaceIFrames(ref codes, pageUrlNoQuery, pages.PageHtml, pagePath, rootUrl, _UserOptions.EncodeUrl, extraAttrib); // Encode <framset> tags HtmlReplacer.ReplaceFrameSets(ref codes, pageUrlNoQuery, pages.PageHtml, pagePath, rootUrl, _UserOptions.EncodeUrl); } // Encode <img> tags if (_UserOptions.Images) { string extraAttrib = ""; // Add code to display orginal url address if (_UserOptions.OrginalUrl) { orginalUrlRequired = true; extraAttrib = Resources.STR_OrginalUrl_TagAttributeFormat; } // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttrib += Consts.ClientContent.attrAlreadyEncodedAttributeWithValue; HtmlReplacer.ReplaceImages(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl, extraAttrib); // Encode background image of <body> , <table> and <td> tags HtmlReplacer.ReplaceBackgrounds(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl); } else { string extraAttrib; // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttrib = Consts.ClientContent.attrAlreadyEncodedAttributeWithValue; HtmlReplacer.ReplaceImages(ref codes, pageUrlNoQuery, "{0}", pagePath, rootUrl, false, extraAttrib); } // Encodes script tags if RemoveScripts option is disabled if (_UserOptions.RemoveScripts == false) { HtmlReplacer.ReplaceScripts(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl); // TODO: JSReplacer JSReplacer.ReplaceScriptTagCodes(ref codes); // V5.2: Replaces tags events using RegEx HtmlReplacer.ReplaceTagsEvents(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, pageUrl, rootUrl, _UserOptions.EncodeUrl); } // Encode <embed> tags HtmlReplacer.ReplaceEmbeds(ref codes, pageUrlNoQuery, pages.PageAnyType, pagePath, rootUrl, _UserOptions.EncodeUrl); // Encode <form> tags if (_UserOptions.SubmitForms) { string extraAttrib; // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttrib = Consts.ClientContent.attrAlreadyEncodedAttributeWithValue + Resources.STR_SubmitForms_ExtraAttribute; HtmlReplacer.ReplaceFormsSources(ref codes, pageUrlNoQuery, pages.PageDefault, pagePath, rootUrl, _UserOptions.EncodeUrl, _UserOptions.SubmitForms, extraAttrib); } else { string extraAttib; // Add an attribute to determine that this tag already encoded and javascript encoder shouldn't encode it again. extraAttib = Consts.ClientContent.attrAlreadyEncodedAttributeWithValue + Resources.STR_SubmitForms_ExtraAttribute; HtmlReplacer.ReplaceFormsSources(ref codes, pageUrlNoQuery, "{0}", pagePath, pagePath, false, _UserOptions.SubmitForms, extraAttib); } // Add dynamic encoding javascript codes string jsEncoderCodes = GenerateJsEncoderCodes(pageUrl, pageUrlNoQuery, pagePath, rootUrl); // Add jsEncoder codes to page ExtraCodesForPage = jsEncoderCodes + ExtraCodesForPage; // OrginalUrl additional injection html codes if (orginalUrlRequired) { // TODO: Check necessary ExtraCodesForPage = Resources.STR_OrginalUrl_FloatBar + ExtraCodesForPage; // Inject to html, right after the body element ExtraCodesForBody = Resources.STR_OrginalUrl_Functions + ExtraCodesForBody; } // 2- executing plugins if (Plugins.IsPluginAvailable(PluginHosts.IPluginHtmlProcessor)) { Plugins.CallPluginMethod(PluginHosts.IPluginHtmlProcessor, PluginMethods.IPluginHtmlProcessor.AfterExecute, this, (object)codes, pageUrl, pageUrlNoQuery, pagePath, rootUrl); } } catch (Exception ex) { // error logs if (Systems.LogSystem.ErrorLogEnabled) { Systems.LogSystem.LogError(ex, pageUrl); } codes = "<center><b>ASProxy has some errors! The delivered content may not work properly.</b></center>" + ex.Message + "<br />" + codes; } }