{"id":147118,"date":"2020-08-25T08:13:16","date_gmt":"2020-08-25T00:13:16","guid":{"rendered":"http:\/\/4563.org\/?p=147118"},"modified":"2020-08-25T08:13:16","modified_gmt":"2020-08-25T00:13:16","slug":"%e6%b1%82%e5%8a%a9%ef%bc%8ccf-workers%e5%8f%aa%e5%8f%8d%e4%bb%a3%e6%9f%90%e4%b8%aa%e7%bd%91%e7%ab%99%e7%9a%84%e6%9f%90%e4%b8%aa%e8%b7%af%e5%be%84%e8%af%a5%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=147118","title":{"rendered":"\u6c42\u52a9\uff0cCF workers\u53ea\u53cd\u4ee3\u67d0\u4e2a\u7f51\u7ad9\u7684\u67d0\u4e2a\u8def\u5f84\u8be5\u600e\u4e48\u5199"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>xshell<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-7-26 22:26:27\t<\/p>\n<h3>\u6c42\u52a9\uff0cCF workers\u53ea\u53cd\u4ee3\u67d0\u4e2a\u7f51\u7ad9\u7684\u67d0\u4e2a\u8def\u5f84\u8be5\u600e\u4e48\u5199<\/h3>\n<p>  \t\t\u6c42\u52a9\uff0cCF workers\u53ea\u53cd\u4ee3\u67d0\u4e2a\u7f51\u7ad9\u7684\u67d0\u4e2a\u8def\u5f84\u8be5\u600e\u4e48\u5199<br \/>  \u7f51\u4e0a\u53ea\u627e\u5230\u53cd\u4ee3\u6574\u4e2a\u57df\u7684\uff0c\u6c42\u52a9\u5927\u4f6c\uff0c\u4f8b\u5982\u6211\u53ea\u60f3\u53cd\u4ee3 XXX.com\/img\/\u8def\u5f84\u600e\u4e48\u5199\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>xshell<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-7-26 22:45:02\t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5df2\u89e3\u51b3\uff0c\u8c37\u6b4c\u5230\u7b54\u6848\u4e86\uff0c\u987a\u4fbf\u8d34\u51fa\u4ee3\u7801\u7ed9\u9700\u8981\u7684MJJ<br \/>  \/\/ \u4f60\u8981\u955c\u50cf\u7684\u7f51\u7ad9.<br \/>  const upstream = &#8216;content.warframe.com&#8217;<\/p>\n<p>  \/\/ \u955c\u50cf\u7f51\u7ad9\u7684\u76ee\u5f55\uff0c\u6bd4\u5982\u4f60\u60f3\u955c\u50cf\u67d0\u4e2a\u7f51\u7ad9\u7684\u4e8c\u7ea7\u76ee\u5f55\u5219\u586b\u5199\u4e8c\u7ea7\u76ee\u5f55\u7684\u76ee\u5f55\u540d\uff0c\u955c\u50cf google \u7528\u4e0d\u5230\uff0c\u9ed8\u8ba4\u5373\u53ef.<br \/>  const upstream_path = &#8216;\/&#8217;<\/p>\n<p>  \/\/ \u955c\u50cf\u7ad9\u662f\u5426\u6709\u624b\u673a\u8bbf\u95ee\u4e13\u7528\u7f51\u5740\uff0c\u6ca1\u6709\u5219\u586b\u4e00\u6837\u7684.<br \/>  const upstream_mobile = &#8216;content.warframe.com&#8217;<\/p>\n<p>  \/\/ \u5c4f\u853d\u56fd\u5bb6\u548c\u5730\u533a.<br \/>  const blocked_region = [&#8216;KP&#8217;, &#8216;SY&#8217;, &#8216;PK&#8217;, &#8216;CU&#8217;]<\/p>\n<p>  \/\/ \u5c4f\u853d IP \u5730\u5740.<br \/>  const blocked_ip_address = [&#8216;0.0.0.0&#8217;, &#8216;127.0.0.1&#8217;]<\/p>\n<p>  \/\/ \u955c\u50cf\u7ad9\u662f\u5426\u5f00\u542f HTTPS.<br \/>  const https = true<\/p>\n<p>  \/\/ \u6587\u672c\u66ff\u6362.<br \/>  const replace_dict = {<br \/>  &nbsp; &nbsp; &#8216;$upstream&#8217;: &#8216;$custom_domain&#8217;,<br \/>  &nbsp; &nbsp; &#8216;\/\/content.warframe.com&#8217;: &#8221;<br \/>  }<\/p>\n<p>  \/\/ \u4ee5\u4e0b\u4fdd\u6301\u9ed8\u8ba4\uff0c\u4e0d\u8981\u52a8<br \/>  addEventListener(&#8216;fetch&#8217;, event =&gt; {<br \/>  &nbsp; &nbsp; event.respondWith(fetchAndApply(event.request));<br \/>  })<\/p>\n<p>  async function fetchAndApply(request) {<\/p>\n<p>  &nbsp; &nbsp; const region = request.headers.get(&#8216;cf-ipcountry&#8217;).toUpperCase();<br \/>  &nbsp; &nbsp; const ip_address = request.headers.get(&#8216;cf-connecting-ip&#8217;);<br \/>  &nbsp; &nbsp; const user_agent = &quot;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/80.0.3987.149 Safari\/537.36&quot;<\/p>\n<p>  &nbsp; &nbsp; let response = null;<br \/>  &nbsp; &nbsp; let url = new URL(request.url);<br \/>  &nbsp; &nbsp; let url_hostname = url.hostname;<\/p>\n<p>  &nbsp; &nbsp; if (https == true) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;url.protocol = &#8216;https:&#8217;;<br \/>  &nbsp; &nbsp; } else {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;url.protocol = &#8216;http:&#8217;;<br \/>  &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; if (await device_status(user_agent)) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;var upstream_domain = upstream;<br \/>  &nbsp; &nbsp; } else {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;var upstream_domain = upstream_mobile;<br \/>  &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; url.host = upstream_domain;<br \/>  &nbsp; &nbsp; if (url.pathname == &#8216;\/&#8217;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;url.pathname = upstream_path;<br \/>  &nbsp; &nbsp; } else {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;url.pathname = upstream_path + url.pathname;<br \/>  &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; if (blocked_region.includes(region)) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;response = new Response(&#8216;Access denied: WorkersProxy is not available in your region yet.&#8217;, {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;status: 403<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;});<br \/>  &nbsp; &nbsp; } else if (blocked_ip_address.includes(ip_address)) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;response = new Response(&#8216;Access denied: Your IP address is blocked by WorkersProxy.&#8217;, {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;status: 403<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;});<br \/>  &nbsp; &nbsp; } else {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let method = request.method;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let request_headers = request.headers;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let new_request_headers = new Headers(request_headers);<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;new_request_headers.set(&#8216;Host&#8217;, url.hostname);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;new_request_headers.set(&#8216;Referer&#8217;, url.hostname);<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;let original_response = await fetch(url.href, {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;method: method,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;headers: new_request_headers<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;})<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;let original_response_clone = original_response.clone();<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let original_text = null;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let response_headers = original_response.headers;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let new_response_headers = new Headers(response_headers);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;let status = original_response.status;<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;new_response_headers.set(&#8216;access-control-allow-origin&#8217;, &#8216;*&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;new_response_headers.set(&#8216;access-control-allow-credentials&#8217;, true);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;new_response_headers.delete(&#8216;content-security-policy&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;new_response_headers.delete(&#8216;content-security-policy-report-only&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;new_response_headers.delete(&#8216;clear-site-data&#8217;);<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;const content_type = new_response_headers.get(&#8216;content-type&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if (content_type.includes(&#8216;text\/html&#8217;) &amp;&amp; content_type.includes(&#8216;UTF-8&#8217;)) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;original_text = await replace_response_text(original_response_clone, upstream_domain, url_hostname);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;} else {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;original_text = original_response_clone.body<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;response = new Response(original_text, {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;status,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;headers: new_response_headers<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;})<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; return response;<br \/>  }<\/p>\n<p>  async function replace_response_text(response, upstream_domain, host_name) {<br \/>  &nbsp; &nbsp; let text = await response.text()<\/p>\n<p>  &nbsp; &nbsp; var i, j;<br \/>  &nbsp; &nbsp; for (i in replace_dict) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;j = replace_dict<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if (i == &#8216;$upstream&#8217;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;i = upstream_domain<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;} else if (i == &#8216;$custom_domain&#8217;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;i = host_name<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;if (j == &#8216;$upstream&#8217;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;j = upstream_domain<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;} else if (j == &#8216;$custom_domain&#8217;) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;j = host_name<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;let re = new RegExp(i, &#8216;g&#8217;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;text = text.replace(re, j);<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; return text;<br \/>  }<\/p>\n<p>  async function device_status(user_agent_info) {<br \/>  &nbsp; &nbsp; var agents = [&quot;Android&quot;, &quot;iPhone&quot;, &quot;SymbianOS&quot;, &quot;Windows Phone&quot;, &quot;iPad&quot;, &quot;iPod&quot;];<br \/>  &nbsp; &nbsp; var flag = true;<br \/>  &nbsp; &nbsp; for (var v = 0; v &lt; agents.length; v++) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if (user_agent_info.indexOf(agents) &gt; 0) {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;flag = false;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;break;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; return flag;<br \/>  }\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>kko654852<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \u534a\u5c0f\u65f6\u524d\t<\/p>\n<h3><\/h3>\n<p>  \t\txshell \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-7-26 22:45<br \/>  \u5df2\u89e3\u51b3\uff0c\u8c37\u6b4c\u5230\u7b54\u6848\u4e86\uff0c\u987a\u4fbf\u8d34\u51fa\u4ee3\u7801\u7ed9\u9700\u8981\u7684MJJ<\/p>\n<p> \u4ed8\u8d39\u5e2e\u5fd9\u53cd\u4ee3\u4e00\u4e2a\u7ad9 \u53ef\u4ee5\uff1f\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>xshell \u5927\u4f6c\u6709\u8bdd\u8bf4 : 20&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/147118"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147118"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/147118\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}