routingrule.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "net/http"
  4. "strings"
  5. "imuslab.com/zoraxy/mod/dynamicproxy"
  6. )
  7. /*
  8. Routing Rule
  9. This script handle special routing rules for some utilities functions
  10. */
  11. // Register the system build-in routing rules into the core
  12. func registerBuildInRoutingRules() {
  13. //Cloudflare email decoder
  14. //It decode the email address if you are proxying a cloudflare protected site
  15. //[email-protected] -> [email protected]
  16. dynamicProxyRouter.AddRoutingRules(&dynamicproxy.RoutingRule{
  17. ID: "cloudflare-decoder",
  18. MatchRule: func(r *http.Request) bool {
  19. return strings.HasSuffix(r.RequestURI, "cloudflare-static/email-decode.min.js")
  20. },
  21. RoutingHandler: func(w http.ResponseWriter, r *http.Request) {
  22. decoder := "function fixObfuscatedEmails(){let t=document.getElementsByClassName(\"__cf_email__\");for(let e=0;e<t.length;e++){let r=t[e],l=r.getAttribute(\"data-cfemail\");if(l){let a=decrypt(l);r.setAttribute(\"href\",\"mailto:\"+a),r.innerHTML=a}}}function decrypt(t){let e=\"\",r=parseInt(t.substr(0,2),16);for(let l=2;l<t.length;l+=2){let a=parseInt(t.substr(l,2),16)^r;e+=String.fromCharCode(a)}try{e=decodeURIComponent(escape(e))}catch(f){console.error(f)}return e}fixObfuscatedEmails();"
  23. w.Header().Set("Content-type", "text/javascript")
  24. w.Write([]byte(decoder))
  25. },
  26. Enabled: false,
  27. UseSystemAccessControl: false,
  28. })
  29. }