/// <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; } }