From b1332afd73aa2bec75c2f51e5f3e5a13a0e23bd0 Mon Sep 17 00:00:00 2001 From: OttoMao Date: Sat, 22 Aug 2015 14:57:07 +0800 Subject: [PATCH] add Eng. version --- .gitignore | 21 +++ cn/index.html | 248 +++++++++++++++++++++++++++++++++ github.css => dest/github.css | 0 index.css => dest/index.css | 19 ++- lib.js => dest/lib.js | 0 en/index.html | 243 +++++++++++++++++++++++++++++++++ gulpfile.js | 35 +++++ index.html | 88 ++++++------ package.json | 43 ++++++ src/i18n.json | 71 ++++++++++ src/index.html | 250 ++++++++++++++++++++++++++++++++++ index.js => src/index.js | 0 index.less => src/index.less | 27 ++-- 13 files changed, 988 insertions(+), 57 deletions(-) create mode 100644 .gitignore create mode 100644 cn/index.html rename github.css => dest/github.css (100%) rename index.css => dest/index.css (89%) rename lib.js => dest/lib.js (100%) create mode 100644 en/index.html create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/i18n.json create mode 100644 src/index.html rename index.js => src/index.js (100%) rename index.less => src/index.less (89%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f76f798 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +.*.swp +._* +.DS_Store +.git +.hg +.lock-wscript +.svn +.wafpickle-* +CVS +npm-debug.log +logs +*.log +pids +*.pid +*.seed +lib-cov +coverage +.grunt +build/Release +node_modules +.lock-wscript \ No newline at end of file diff --git a/cn/index.html b/cn/index.html new file mode 100644 index 0000000..88a0bb0 --- /dev/null +++ b/cn/index.html @@ -0,0 +1,248 @@ + + + AnyProxy + + + + + + + + + + + +
+ + +
+ +

AnyProxy是一个开放式的HTTP/HTTPS代理,你可以灵活控制各种网络数据

+
+     + +
+
+ +
+
+
+ + + +

基于Node.js

+
全程JavaScript,学习无压力
+
+
+ + + +

支持Https

+
明文解析Https请求数据
如何配置 >>
+
+
+ + + +

Web界面

+
多终端共享,可视化观察每个请求
+
+
+ + + +

规则逻辑(Rule)

+
个性化处理规则,定制专属调试工具
+
+
+
+
+ +
+
+

安装

+
    +
  • 安装 Node.js >= v0.12
  • +
  • npm install -g anyproxy, 可能需要sudo
  • +
  • More>>
  • +
+

使用

+
    +
  • 运行  anyproxy
  • +
  • 把浏览器http代理指向 127.0.0.1:8001
  • +
  • 访问界面:http://127.0.0.1:8002
  • +
  • 更多用法 >>
  • +
+ +
+
+ +
+ +
+

规则文件(rule)样例

+ +
+
在HTML响应末尾加上"hello world"
+
+
+//append "hello world" to all web pages
+//file : rule_replace_response_data.js
+//run  : anyproxy --rule rule_replace_response_data.js
+module.exports = {
+    replaceServerResDataAsync: function(req,res,serverRes,cb){
+
+        if(/html/i.test(res.headers['content-type'])){
+            var newDataStr = serverRes.toString();
+            newDataStr += "hello world!";
+            cb(newDataStr);
+        }
+    }
+};
+
+                    
+ + + +
+
+
+
去除请求头的if-modified-since字段
+
+
+//remove cache related header
+//file : rule_remove_cache_header.js
+//run  : anyproxy --rule rule_remove_cache_header.js
+module.exports = {
+    replaceRequestOption : function(req,option){
+        var newOption = option;
+        delete newOption.headers['if-modified-since'];
+
+        return newOption;
+    }
+};
+
+                    
+ + + +
+
+ +
+
为某个请求指定目标IP地址
+
+
+//assign a specific IP adress for some request
+//file : rule_reverse_proxy.js
+//run  : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
+module.exports = {
+    replaceRequestOption : function(req,option){
+        var newOption = option;
+        if(newOption.headers.host == "www.taobao.com"){
+            newOption.hostname = "192.168.1.3";
+            newOption.port     = "80";
+        }
+
+        return newOption;
+    }
+};
+
+                    
+ + + +
+
+ +
+
把所有图片响应替换成本地图片
+
+
+//replace all the images with local one
+//file : rule_use_local_data.js
+//run  : anyproxy --rule anyproxy --rule rule_use_local_data.js
+var fs  = require("fs"),
+    img = fs.readFileSync("sample.jpg");
+
+module.exports = {
+    shouldUseLocalResponse : function(req,reqBody){
+        if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
+            req.replaceLocalFile = true;
+            return true;
+        }else{
+            return false;
+        }
+    },
+
+    dealLocalResponse : function(req,reqBody,callback){
+        if(req.replaceLocalFile){
+            callback(200, {"content-type":"image/png"},img );
+        }
+    }
+};
+
+                    
+ + + +
+ + + +
+
+ +
+
+

其他特性

+ +

相关阅读

+ +
+
+ + + + + +
+ + + + + + \ No newline at end of file diff --git a/github.css b/dest/github.css similarity index 100% rename from github.css rename to dest/github.css diff --git a/index.css b/dest/index.css similarity index 89% rename from index.css rename to dest/index.css index beb1597..9db1135 100644 --- a/index.css +++ b/dest/index.css @@ -1,9 +1,8 @@ @font-face { font-family: 'iconfont'; - src: url('//at.alicdn.com/t/font_1438330832_106274.eot'); - src: url('//at.alicdn.com/t/font_1438330832_106274.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('//at.alicdn.com/t/font_1438330832_106274.woff') format('woff'), /* chrome、firefox */ url('//at.alicdn.com/t/font_1438330832_106274.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ url('//at.alicdn.com/t/font_1438330832_106274.svg#iconfont') format('svg'); - + src: url('//at.alicdn.com/t/font_1440130445_6601267.eot'); /* IE9*/ + src: url('//at.alicdn.com/t/font_1440130445_6601267.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('//at.alicdn.com/t/font_1440130445_6601267.woff') format('woff'), /* chrome、firefox */ url('//at.alicdn.com/t/font_1440130445_6601267.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ url('//at.alicdn.com/t/font_1440130445_6601267.svg#iconfont') format('svg'); /* iOS 4.1- */ } i.iconfont { @@ -17,11 +16,19 @@ body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } -.wrapper .cornerBtn { +.wrapper .cornerBtnWrapper { position: absolute; right: 10px; top: 10px; z-index: 1; + width: 100%; + text-align: right; + color: #5a5a5a; +} +.wrapper .cornerBtnWrapper a { + display: inline-block; + margin-right: 10px; + margin-left: 10px; } .wrapper a, .wrapper a:hover { @@ -65,7 +72,7 @@ body { } @media only screen and (min-device-width: 320px) and (max-device-width: 600px) and (-webkit-min-device-pixel-ratio: 2) { .wrapper .actionBtn { - font-size: 20px; + font-size: 16px; padding: 10px 20px; } } @@ -135,7 +142,7 @@ body { } .feature .featureContent h4 { color: #5a5a5a; - margin: 12px auto 8px; + margin: 12px auto 2px; font-size: 20px; } .feature .featureContent h5 { diff --git a/lib.js b/dest/lib.js similarity index 100% rename from lib.js rename to dest/lib.js diff --git a/en/index.html b/en/index.html new file mode 100644 index 0000000..fe3abe4 --- /dev/null +++ b/en/index.html @@ -0,0 +1,243 @@ + + + AnyProxy + + + + + + + + + + + +
+ + +
+ +

AnyProxy is a fully configurable http/https proxy in NodeJS, which offers you the ablity to handle http traffic as you wish.

+
+     + +
+
+ +
+
+
+ + + +

Based on Node.js

+
It's all javascript and easy to learn.
+
+
+ + + +

HTTPS supported

+
help to decrypted HTTPS data
How to config >>
+
+
+ + + +

Web UI

+
Web based interface to view requests
+
+
+ + + +

Customed Rule File

+
Make your own debugging tool by writing rule files
+
+
+
+
+ +
+
+

Installation

+
    +
  • install Node.js >= v0.12
  • +
  • npm install -g anyproxy, may requiresudo
  • +
  • More>>
  • +
+

Quick Start

+
    +
  • run  anyproxy
  • +
  • set proxy to 127.0.0.1:8001 on your browser or device
  • +
  • view web interface at http://127.0.0.1:8002
  • +
  • More Usage >>
  • +
+ +
+
+ +
+ +
+

Sample of Rule Files

+ +
+
Append "hello world" on HTML response
+
+
+//append "hello world" to all web pages
+//file : rule_replace_response_data.js
+//run  : anyproxy --rule rule_replace_response_data.js
+module.exports = {
+    replaceServerResDataAsync: function(req,res,serverRes,cb){
+
+        if(/html/i.test(res.headers['content-type'])){
+            var newDataStr = serverRes.toString();
+            newDataStr += "hello world!";
+            cb(newDataStr);
+        }
+    }
+};
+
+                    
+ + + +
+
+
+
remove if-modified-since from http request header
+
+
+//remove cache related header
+//file : rule_remove_cache_header.js
+//run  : anyproxy --rule rule_remove_cache_header.js
+module.exports = {
+    replaceRequestOption : function(req,option){
+        var newOption = option;
+        delete newOption.headers['if-modified-since'];
+
+        return newOption;
+    }
+};
+
+                    
+ + + +
+
+ +
+
assign a specified ip address for some requests
+
+
+//assign a specific IP adress for some request
+//file : rule_reverse_proxy.js
+//run  : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
+module.exports = {
+    replaceRequestOption : function(req,option){
+        var newOption = option;
+        if(newOption.headers.host == "www.taobao.com"){
+            newOption.hostname = "192.168.1.3";
+            newOption.port     = "80";
+        }
+
+        return newOption;
+    }
+};
+
+                    
+ + + +
+
+ +
+
replace all image response by local one
+
+
+//replace all the images with local one
+//file : rule_use_local_data.js
+//run  : anyproxy --rule anyproxy --rule rule_use_local_data.js
+var fs  = require("fs"),
+    img = fs.readFileSync("sample.jpg");
+
+module.exports = {
+    shouldUseLocalResponse : function(req,reqBody){
+        if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
+            req.replaceLocalFile = true;
+            return true;
+        }else{
+            return false;
+        }
+    },
+
+    dealLocalResponse : function(req,reqBody,callback){
+        if(req.replaceLocalFile){
+            callback(200, {"content-type":"image/png"},img );
+        }
+    }
+};
+
+                    
+ + + +
+ + + +
+
+ +
+
+

Other Features

+ +
+
+ + + + + +
+ + + + + + \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..407ea12 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,35 @@ +var fs = require("fs"), + Juicer = require("juicer"), + gulp = require("gulp"), + less = require("gulp-less"), + path = require('path'); + +Juicer.set('strip',false); + +gulp.task('less', function(){ + return gulp.src('./src/*.less') + .pipe(less()) + .pipe(gulp.dest('./dest/')); +}); + +gulp.task("page",function(){ + var i18nConfig = JSON.parse(fs.readFileSync("./src/i18n.json",{encoding :"utf8"})), + pageTpl = Juicer(fs.readFileSync("./src/index.html",{encoding : "utf8"}) ); + + // console.log(pageTpl); + var pageCN = pageTpl.render(i18nConfig.cn), + pageEN = pageTpl.render(i18nConfig.en); + + fs.writeFileSync("./cn/index.html",pageCN); + fs.writeFileSync("./en/index.html",pageEN); + + fs.writeFileSync("./index.html",pageEN); +}); + +gulp.task("watch",function(){ + gulp.watch('./src/*', ['less','page']); +}); + +gulp.task("default",["less","page"],function(){ + +}); \ No newline at end of file diff --git a/index.html b/index.html index 296eb81..fe3abe4 100644 --- a/index.html +++ b/index.html @@ -1,27 +1,36 @@ AnyProxy - + -
- View on Github
+
-

AnyProxy是一个开放式的HTTP/HTTPS代理,你可以灵活控制各种网络数据

+

AnyProxy is a fully configurable http/https proxy in NodeJS, which offers you the ablity to handle http traffic as you wish.

    @@ -32,31 +41,31 @@
- + -

基于Node.js

-
全程JavaScript,学习无压力
+

Based on Node.js

+
It's all javascript and easy to learn.
-

支持Https

-
明文解析Https请求数据
如何配置>>
+

HTTPS supported

+
help to decrypted HTTPS data
How to config >>
-

Web界面

-
多终端共享,可视化观察每个请求
+

Web UI

+
Web based interface to view requests
-

规则逻辑(Rule)

-
编写个性化处理规则,定制专属调试工具
+

Customed Rule File

+
Make your own debugging tool by writing rule files
@@ -64,18 +73,18 @@
-

安装

+

Installation

    -
  • 安装 Node.js >= v0.12
  • -
  • npm install -g anyproxy, 可能需要sudo
  • +
  • install Node.js >= v0.12
  • +
  • npm install -g anyproxy, may requiresudo
  • More>>
-

使用

+

Quick Start

    -
  • 运行  anyproxy
  • -
  • 把浏览器http代理指向 127.0.0.1:8001
  • -
  • 访问界面:http://127.0.0.1:8002
  • -
  • 更多用法>>
  • +
  • run  anyproxy
  • +
  • set proxy to 127.0.0.1:8001 on your browser or device
  • +
  • view web interface at http://127.0.0.1:8002
  • +
  • More Usage >>
@@ -84,10 +93,10 @@
-

规则文件(rule)样例

+

Sample of Rule Files

-
在HTML响应末尾加上"hello world"
+
Append "hello world" on HTML response
 
 //append "hello world" to all web pages
@@ -111,7 +120,7 @@ module.exports = {
                     
-
去除请求头的if-modified-since字段
+
remove if-modified-since from http request header
 
 //remove cache related header
@@ -134,7 +143,7 @@ module.exports = {
                 
-
为某个请求指定目标IP地址
+
assign a specified ip address for some requests
 
 //assign a specific IP adress for some request
@@ -160,7 +169,7 @@ module.exports = {
                 
-
把所有图片响应替换成本地图片
+
replace all image response by local one
 
 //replace all the images with local one
@@ -193,7 +202,7 @@ module.exports = {
                 
@@ -201,17 +210,12 @@ module.exports = {
-

其他特性

+

Other Features

-

相关阅读

- +
  • Map file to local , filter your logs
  • +
  • Simulate a low-speed network , help to test the performance of your app on poor network
  • +
  • Using AnyProxy as an npm module , to deploy your own debugging tools
  • +
    @@ -226,11 +230,11 @@ module.exports = {
    - - + + + + + + +
    + + +
    + +

    ${summary}

    +
    +     + +
    +
    + +
    +
    +
    + + + +

    ${featureA}

    +
    ${featureADesc}
    +
    +
    + + + +

    ${featureB}

    +
    ${featureBDesc}
    ${featureBHowTo} >>
    +
    +
    + + + +

    ${featureC}

    +
    ${featureCDesc}
    +
    +
    + + + +

    ${featureD}

    +
    ${featureDDesc}
    +
    +
    +
    +
    + +
    +
    +

    ${installationTitle}

    +
      +
    • ${installationStepA} Node.js >= v0.12
    • +
    • npm install -g anyproxy, ${installationStepB}sudo
    • +
    • More>>
    • +
    +

    ${quickStartTitle}

    + + +
    +
    + +
    + +
    +

    ${sampleRuleTitle}

    + +
    +
    ${sampleATitle}
    +
    +
    +//append "hello world" to all web pages
    +//file : rule_replace_response_data.js
    +//run  : anyproxy --rule rule_replace_response_data.js
    +module.exports = {
    +    replaceServerResDataAsync: function(req,res,serverRes,cb){
    +
    +        if(/html/i.test(res.headers['content-type'])){
    +            var newDataStr = serverRes.toString();
    +            newDataStr += "hello world!";
    +            cb(newDataStr);
    +        }
    +    }
    +};
    +
    +                    
    + + + +
    +
    +
    +
    ${sampleBTitle}
    +
    +
    +//remove cache related header
    +//file : rule_remove_cache_header.js
    +//run  : anyproxy --rule rule_remove_cache_header.js
    +module.exports = {
    +    replaceRequestOption : function(req,option){
    +        var newOption = option;
    +        delete newOption.headers['if-modified-since'];
    +
    +        return newOption;
    +    }
    +};
    +
    +                    
    + + + +
    +
    + +
    +
    ${sampleCTitle}
    +
    +
    +//assign a specific IP adress for some request
    +//file : rule_reverse_proxy.js
    +//run  : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
    +module.exports = {
    +    replaceRequestOption : function(req,option){
    +        var newOption = option;
    +        if(newOption.headers.host == "www.taobao.com"){
    +            newOption.hostname = "192.168.1.3";
    +            newOption.port     = "80";
    +        }
    +
    +        return newOption;
    +    }
    +};
    +
    +                    
    + + + +
    +
    + +
    +
    ${sampleDTitle}
    +
    +
    +//replace all the images with local one
    +//file : rule_use_local_data.js
    +//run  : anyproxy --rule anyproxy --rule rule_use_local_data.js
    +var fs  = require("fs"),
    +    img = fs.readFileSync("sample.jpg");
    +
    +module.exports = {
    +    shouldUseLocalResponse : function(req,reqBody){
    +        if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
    +            req.replaceLocalFile = true;
    +            return true;
    +        }else{
    +            return false;
    +        }
    +    },
    +
    +    dealLocalResponse : function(req,reqBody,callback){
    +        if(req.replaceLocalFile){
    +            callback(200, {"content-type":"image/png"},img );
    +        }
    +    }
    +};
    +
    +                    
    + + + +
    + + + +
    +
    + +
    +
    +

    ${otherFeaturesTitle}

    + + {@if language == "cn"} +

    相关阅读

    + + {@/if} +
    +
    + + + + + +
    + + + + + + \ No newline at end of file diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js diff --git a/index.less b/src/index.less similarity index 89% rename from index.less rename to src/index.less index 53d0b5f..ca46ea2 100644 --- a/index.less +++ b/src/index.less @@ -13,11 +13,11 @@ @font-face { font-family: 'iconfont'; - src: url('//at.alicdn.com/t/font_1438330832_106274.eot'); /* IE9*/ - src: url('//at.alicdn.com/t/font_1438330832_106274.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ - url('//at.alicdn.com/t/font_1438330832_106274.woff') format('woff'), /* chrome、firefox */ - url('//at.alicdn.com/t/font_1438330832_106274.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ - url('//at.alicdn.com/t/font_1438330832_106274.svg#iconfont') format('svg'); /* iOS 4.1- */ + src: url('//at.alicdn.com/t/font_1440130445_6601267.eot'); /* IE9*/ + src: url('//at.alicdn.com/t/font_1440130445_6601267.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ + url('//at.alicdn.com/t/font_1440130445_6601267.woff') format('woff'), /* chrome、firefox */ + url('//at.alicdn.com/t/font_1440130445_6601267.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ + url('//at.alicdn.com/t/font_1440130445_6601267.svg#iconfont') format('svg'); /* iOS 4.1- */ } i.iconfont{ @@ -34,11 +34,20 @@ body{ } .wrapper{ - .cornerBtn{ + .cornerBtnWrapper{ position : absolute; right : 10px; top : 10px; - z-index : 1; + z-index : 1; + width: 100%; + text-align: right; + color: @textDark; + } + + .cornerBtnWrapper a{ + display: inline-block; + margin-right: 10px; + margin-left : 10px; } a, @@ -93,7 +102,7 @@ body{ and (min-device-width: 320px) and (max-device-width: 600px) and (-webkit-min-device-pixel-ratio: 2){ - font-size:20px; + font-size:16px; padding: 10px 20px; } } @@ -180,7 +189,7 @@ body{ h4{ color: @textDark; - margin: 12px auto 8px; + margin: 12px auto 2px; font-size: 20px; }