├── .babelrc
├── .electron-vue
├── build.js
├── dev-client.js
├── dev-runner.js
├── webpack.main.config.js
├── webpack.renderer.config.js
└── webpack.web.config.js
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .travis.yml
├── README.md
├── appveyor.yml
├── build
└── icons
│ ├── 256x256.png
│ ├── icon.icns
│ └── icon.ico
├── dist
├── electron
│ └── .gitkeep
└── web
│ └── .gitkeep
├── package-lock.json
├── package.json
├── src
├── index.ejs
├── main
│ ├── const.js
│ ├── index.dev.js
│ └── index.js
└── renderer
│ ├── App.vue
│ ├── assets
│ ├── .gitkeep
│ ├── logo.png
│ ├── p1.jpg
│ ├── p2.jpg
│ ├── p3.jpg
│ └── style
│ │ └── common.scss
│ ├── components
│ ├── header-menu.vue
│ └── layout.vue
│ ├── lib
│ ├── bus.js
│ ├── global-proxy
│ │ ├── exec-sync.js
│ │ ├── index.js
│ │ ├── local-proxy.js
│ │ ├── mac.js
│ │ └── win.js
│ ├── proxy
│ │ ├── proxy-api.js
│ │ └── request-handler.js
│ └── rule
│ │ ├── const.js
│ │ └── rule-api.js
│ ├── main.js
│ ├── pages
│ ├── components
│ │ └── network-detail.vue
│ ├── network.vue
│ ├── rule
│ │ ├── index.vue
│ │ ├── rule-edit.vue
│ │ └── rule-list.vue
│ └── setting.vue
│ ├── router
│ └── index.js
│ └── store
│ ├── index.js
│ └── modules
│ ├── index.js
│ ├── rule.js
│ └── setting.js
└── static
├── .gitkeep
└── rule_sample
├── sample_modify_request_data.js
├── sample_modify_request_header.js
├── sample_modify_request_path.js
├── sample_modify_request_protocol.js
├── sample_modify_response_data.js
├── sample_modify_response_header.js
├── sample_modify_response_statuscode.js
└── sample_use_local_response.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "comments": false,
3 | "env": {
4 | "main": {
5 | "presets": [
6 | [
7 | "env",
8 | {
9 | "targets": {
10 | "node": 7
11 | }
12 | }
13 | ],
14 | "stage-0"
15 | ]
16 | },
17 | "renderer": {
18 | "presets": [
19 | [
20 | "env",
21 | {
22 | "modules": false
23 | }
24 | ],
25 | "stage-0"
26 | ]
27 | },
28 | "web": {
29 | "presets": [
30 | [
31 | "env",
32 | {
33 | "modules": false
34 | }
35 | ],
36 | "stage-0"
37 | ]
38 | }
39 | },
40 | "plugins": [
41 | "syntax-dynamic-import",
42 | "transform-vue-jsx",
43 | "transform-runtime",
44 | [
45 | "import",
46 | {
47 | "libraryName": "ant-design-vue",
48 | "libraryDirectory": "es",
49 | "style": "css"
50 | }
51 | ]
52 | ]
53 | }
54 |
--------------------------------------------------------------------------------
/.electron-vue/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | process.env.NODE_ENV = 'production'
4 |
5 | const { say } = require('cfonts')
6 | const chalk = require('chalk')
7 | const del = require('del')
8 | const { spawn } = require('child_process')
9 | const webpack = require('webpack')
10 | const Multispinner = require('multispinner')
11 |
12 |
13 | const mainConfig = require('./webpack.main.config')
14 | const rendererConfig = require('./webpack.renderer.config')
15 | const webConfig = require('./webpack.web.config')
16 |
17 | const doneLog = chalk.bgGreen.white(' DONE ') + ' '
18 | const errorLog = chalk.bgRed.white(' ERROR ') + ' '
19 | const okayLog = chalk.bgBlue.white(' OKAY ') + ' '
20 | const isCI = process.env.CI || false
21 |
22 | if (process.env.BUILD_TARGET === 'clean') clean()
23 | else if (process.env.BUILD_TARGET === 'web') web()
24 | else build()
25 |
26 | function clean () {
27 | del.sync(['build/*', '!build/icons', '!build/icons/icon.*'])
28 | console.log(`\n${doneLog}\n`)
29 | process.exit()
30 | }
31 |
32 | function build () {
33 | greeting()
34 |
35 | del.sync(['dist/electron/*', '!.gitkeep'])
36 |
37 | const tasks = ['main', 'renderer']
38 | const m = new Multispinner(tasks, {
39 | preText: 'building',
40 | postText: 'process'
41 | })
42 |
43 | let results = ''
44 |
45 | m.on('success', () => {
46 | process.stdout.write('\x1B[2J\x1B[0f')
47 | console.log(`\n\n${results}`)
48 | console.log(`${okayLog}take it away ${chalk.yellow('`electron-builder`')}\n`)
49 | process.exit()
50 | })
51 |
52 | pack(mainConfig).then(result => {
53 | results += result + '\n\n'
54 | m.success('main')
55 | }).catch(err => {
56 | m.error('main')
57 | console.log(`\n ${errorLog}failed to build main process`)
58 | console.error(`\n${err}\n`)
59 | process.exit(1)
60 | })
61 |
62 | pack(rendererConfig).then(result => {
63 | results += result + '\n\n'
64 | m.success('renderer')
65 | }).catch(err => {
66 | m.error('renderer')
67 | console.log(`\n ${errorLog}failed to build renderer process`)
68 | console.error(`\n${err}\n`)
69 | process.exit(1)
70 | })
71 | }
72 |
73 | function pack (config) {
74 | return new Promise((resolve, reject) => {
75 | config.mode = 'production'
76 | webpack(config, (err, stats) => {
77 | if (err) reject(err.stack || err)
78 | else if (stats.hasErrors()) {
79 | let err = ''
80 |
81 | stats.toString({
82 | chunks: false,
83 | colors: true
84 | })
85 | .split(/\r?\n/)
86 | .forEach(line => {
87 | err += ` ${line}\n`
88 | })
89 |
90 | reject(err)
91 | } else {
92 | resolve(stats.toString({
93 | chunks: false,
94 | colors: true
95 | }))
96 | }
97 | })
98 | })
99 | }
100 |
101 | function web () {
102 | del.sync(['dist/web/*', '!.gitkeep'])
103 | webConfig.mode = 'production'
104 | webpack(webConfig, (err, stats) => {
105 | if (err || stats.hasErrors()) console.log(err)
106 |
107 | console.log(stats.toString({
108 | chunks: false,
109 | colors: true
110 | }))
111 |
112 | process.exit()
113 | })
114 | }
115 |
116 | function greeting () {
117 | const cols = process.stdout.columns
118 | let text = ''
119 |
120 | if (cols > 85) text = 'lets-build'
121 | else if (cols > 60) text = 'lets-|build'
122 | else text = false
123 |
124 | if (text && !isCI) {
125 | say(text, {
126 | colors: ['yellow'],
127 | font: 'simple3d',
128 | space: false
129 | })
130 | } else console.log(chalk.yellow.bold('\n lets-build'))
131 | console.log()
132 | }
--------------------------------------------------------------------------------
/.electron-vue/dev-client.js:
--------------------------------------------------------------------------------
1 | const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
2 |
3 | hotClient.subscribe(event => {
4 | /**
5 | * Reload browser when HTMLWebpackPlugin emits a new index.html
6 | *
7 | * Currently disabled until jantimon/html-webpack-plugin#680 is resolved.
8 | * https://github.com/SimulatedGREG/electron-vue/issues/437
9 | * https://github.com/jantimon/html-webpack-plugin/issues/680
10 | */
11 | // if (event.action === 'reload') {
12 | // window.location.reload()
13 | // }
14 |
15 | /**
16 | * Notify `mainWindow` when `main` process is compiling,
17 | * giving notice for an expected reload of the `electron` process
18 | */
19 | if (event.action === 'compiling') {
20 | document.body.innerHTML += `
21 |
34 |
35 |
36 | Compiling Main Process...
37 |
38 | `
39 | }
40 | })
41 |
--------------------------------------------------------------------------------
/.electron-vue/dev-runner.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const chalk = require('chalk')
4 | const electron = require('electron')
5 | const path = require('path')
6 | const { say } = require('cfonts')
7 | const { spawn } = require('child_process')
8 | const webpack = require('webpack')
9 | const WebpackDevServer = require('webpack-dev-server')
10 | const webpackHotMiddleware = require('webpack-hot-middleware')
11 |
12 | const mainConfig = require('./webpack.main.config')
13 | const rendererConfig = require('./webpack.renderer.config')
14 |
15 | let electronProcess = null
16 | let manualRestart = false
17 | let hotMiddleware
18 |
19 | function logStats (proc, data) {
20 | let log = ''
21 |
22 | log += chalk.yellow.bold(`┏ ${proc} Process ${new Array((19 - proc.length) + 1).join('-')}`)
23 | log += '\n\n'
24 |
25 | if (typeof data === 'object') {
26 | data.toString({
27 | colors: true,
28 | chunks: false
29 | }).split(/\r?\n/).forEach(line => {
30 | log += ' ' + line + '\n'
31 | })
32 | } else {
33 | log += ` ${data}\n`
34 | }
35 |
36 | log += '\n' + chalk.yellow.bold(`┗ ${new Array(28 + 1).join('-')}`) + '\n'
37 |
38 | console.log(log)
39 | }
40 |
41 | function startRenderer () {
42 | return new Promise((resolve, reject) => {
43 | rendererConfig.entry.renderer = [path.join(__dirname, 'dev-client')].concat(rendererConfig.entry.renderer)
44 | rendererConfig.mode = 'development'
45 | const compiler = webpack(rendererConfig)
46 | hotMiddleware = webpackHotMiddleware(compiler, {
47 | log: false,
48 | heartbeat: 2500
49 | })
50 |
51 | compiler.hooks.compilation.tap('compilation', compilation => {
52 | compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('html-webpack-plugin-after-emit', (data, cb) => {
53 | hotMiddleware.publish({ action: 'reload' })
54 | cb()
55 | })
56 | })
57 |
58 | compiler.hooks.done.tap('done', stats => {
59 | logStats('Renderer', stats)
60 | })
61 |
62 | const server = new WebpackDevServer(
63 | compiler,
64 | {
65 | contentBase: path.join(__dirname, '../'),
66 | quiet: true,
67 | before (app, ctx) {
68 | app.use(hotMiddleware)
69 | ctx.middleware.waitUntilValid(() => {
70 | resolve()
71 | })
72 | }
73 | }
74 | )
75 |
76 | server.listen(9080)
77 | })
78 | }
79 |
80 | function startMain () {
81 | return new Promise((resolve, reject) => {
82 | mainConfig.entry.main = [path.join(__dirname, '../src/main/index.dev.js')].concat(mainConfig.entry.main)
83 | mainConfig.mode = 'development'
84 | const compiler = webpack(mainConfig)
85 |
86 | compiler.hooks.watchRun.tapAsync('watch-run', (compilation, done) => {
87 | logStats('Main', chalk.white.bold('compiling...'))
88 | hotMiddleware.publish({ action: 'compiling' })
89 | done()
90 | })
91 |
92 | compiler.watch({}, (err, stats) => {
93 | if (err) {
94 | console.log(err)
95 | return
96 | }
97 |
98 | logStats('Main', stats)
99 |
100 | if (electronProcess && electronProcess.kill) {
101 | manualRestart = true
102 | process.kill(electronProcess.pid)
103 | electronProcess = null
104 | startElectron()
105 |
106 | setTimeout(() => {
107 | manualRestart = false
108 | }, 5000)
109 | }
110 |
111 | resolve()
112 | })
113 | })
114 | }
115 |
116 | function startElectron () {
117 | var args = [
118 | '--inspect=9999',
119 | path.join(__dirname, '../dist/electron/main.js')
120 | ]
121 |
122 | // detect yarn or npm and process commandline args accordingly
123 | if (process.env.npm_execpath.endsWith('yarn.js')) {
124 | args = args.concat(process.argv.slice(3))
125 | } else if (process.env.npm_execpath.endsWith('npm-cli.js')) {
126 | args = args.concat(process.argv.slice(2))
127 | }
128 |
129 | electronProcess = spawn(electron, args)
130 |
131 | electronProcess.stdout.on('data', data => {
132 | electronLog(data, 'blue')
133 | })
134 | electronProcess.stderr.on('data', data => {
135 | electronLog(data, 'red')
136 | })
137 |
138 | electronProcess.on('close', () => {
139 | if (!manualRestart) process.exit()
140 | })
141 | }
142 |
143 | function electronLog (data, color) {
144 | let log = ''
145 | data = data.toString().split(/\r?\n/)
146 | data.forEach(line => {
147 | log += ` ${line}\n`
148 | })
149 | if (/[0-9A-z]+/.test(log)) {
150 | console.log(
151 | chalk[color].bold('┏ Electron -------------------') +
152 | '\n\n' +
153 | log +
154 | chalk[color].bold('┗ ----------------------------') +
155 | '\n'
156 | )
157 | }
158 | }
159 |
160 | function greeting () {
161 | const cols = process.stdout.columns
162 | let text = ''
163 |
164 | if (cols > 104) text = 'electron-vue'
165 | else if (cols > 76) text = 'electron-|vue'
166 | else text = false
167 |
168 | if (text) {
169 | say(text, {
170 | colors: ['yellow'],
171 | font: 'simple3d',
172 | space: false
173 | })
174 | } else console.log(chalk.yellow.bold('\n electron-vue'))
175 | console.log(chalk.blue(' getting ready...') + '\n')
176 | }
177 |
178 | function init () {
179 | greeting()
180 |
181 | Promise.all([startRenderer(), startMain()])
182 | .then(() => {
183 | startElectron()
184 | })
185 | .catch(err => {
186 | console.error(err)
187 | })
188 | }
189 |
190 | init()
191 |
--------------------------------------------------------------------------------
/.electron-vue/webpack.main.config.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | process.env.BABEL_ENV = 'main'
4 |
5 | const path = require('path')
6 | const { dependencies } = require('../package.json')
7 | const webpack = require('webpack')
8 |
9 | const BabiliWebpackPlugin = require('babili-webpack-plugin')
10 |
11 | let mainConfig = {
12 | entry: {
13 | main: path.join(__dirname, '../src/main/index.js')
14 | },
15 | externals: [
16 | ...Object.keys(dependencies || {})
17 | ],
18 | module: {
19 | rules: [
20 | {
21 | test: /\.(js)$/,
22 | enforce: 'pre',
23 | exclude: /node_modules/,
24 | use: {
25 | loader: 'eslint-loader',
26 | options: {
27 | formatter: require('eslint-friendly-formatter')
28 | }
29 | }
30 | },
31 | {
32 | test: /\.js$/,
33 | use: 'babel-loader',
34 | exclude: /node_modules/
35 | },
36 | {
37 | test: /\.node$/,
38 | use: 'node-loader'
39 | }
40 | ]
41 | },
42 | node: {
43 | __dirname: process.env.NODE_ENV !== 'production',
44 | __filename: process.env.NODE_ENV !== 'production'
45 | },
46 | output: {
47 | filename: '[name].js',
48 | libraryTarget: 'commonjs2',
49 | path: path.join(__dirname, '../dist/electron')
50 | },
51 | plugins: [
52 | new webpack.NoEmitOnErrorsPlugin()
53 | ],
54 | resolve: {
55 | extensions: ['.js', '.json', '.node']
56 | },
57 | target: 'electron-main'
58 | }
59 |
60 | /**
61 | * Adjust mainConfig for development settings
62 | */
63 | if (process.env.NODE_ENV !== 'production') {
64 | mainConfig.plugins.push(
65 | new webpack.DefinePlugin({
66 | '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
67 | })
68 | )
69 | }
70 |
71 | /**
72 | * Adjust mainConfig for production settings
73 | */
74 | if (process.env.NODE_ENV === 'production') {
75 | mainConfig.plugins.push(
76 | new BabiliWebpackPlugin(),
77 | new webpack.DefinePlugin({
78 | 'process.env.NODE_ENV': '"production"'
79 | })
80 | )
81 | }
82 |
83 | module.exports = mainConfig
84 |
--------------------------------------------------------------------------------
/.electron-vue/webpack.renderer.config.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | process.env.BABEL_ENV = 'renderer'
4 |
5 | const path = require('path')
6 | const { dependencies } = require('../package.json')
7 | const webpack = require('webpack')
8 |
9 | const BabiliWebpackPlugin = require('babili-webpack-plugin')
10 | const CopyWebpackPlugin = require('copy-webpack-plugin')
11 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
12 | const HtmlWebpackPlugin = require('html-webpack-plugin')
13 | const { VueLoaderPlugin } = require('vue-loader')
14 |
15 | /**
16 | * List of node_modules to include in webpack bundle
17 | *
18 | * Required for specific packages like Vue UI libraries
19 | * that provide pure *.vue files that need compiling
20 | * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
21 | */
22 | let whiteListedModules = ['vue']
23 |
24 | let rendererConfig = {
25 | devtool: '#cheap-module-eval-source-map',
26 | entry: {
27 | renderer: path.join(__dirname, '../src/renderer/main.js')
28 | },
29 | externals: [
30 | ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
31 | ],
32 | module: {
33 | rules: [
34 | {
35 | test: /\.(js|vue)$/,
36 | enforce: 'pre',
37 | exclude: /node_modules/,
38 | use: {
39 | loader: 'eslint-loader',
40 | options: {
41 | formatter: require('eslint-friendly-formatter')
42 | }
43 | }
44 | },
45 | {
46 | test: /\.scss$/,
47 | use: ['vue-style-loader', 'css-loader', 'sass-loader']
48 | },
49 | {
50 | test: /\.sass$/,
51 | use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax']
52 | },
53 | {
54 | test: /\.less$/,
55 | use: ['vue-style-loader', 'css-loader', 'less-loader']
56 | },
57 | {
58 | test: /\.css$/,
59 | use: ['vue-style-loader', 'css-loader']
60 | },
61 | {
62 | test: /\.html$/,
63 | use: 'vue-html-loader'
64 | },
65 | {
66 | test: /\.js$/,
67 | use: 'babel-loader',
68 | exclude: /node_modules/
69 | },
70 | {
71 | test: /\.node$/,
72 | use: 'node-loader'
73 | },
74 | {
75 | test: /\.vue$/,
76 | use: {
77 | loader: 'vue-loader',
78 | options: {
79 | extractCSS: process.env.NODE_ENV === 'production',
80 | loaders: {
81 | sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
82 | scss: 'vue-style-loader!css-loader!sass-loader',
83 | less: 'vue-style-loader!css-loader!less-loader'
84 | }
85 | }
86 | }
87 | },
88 | {
89 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
90 | use: {
91 | loader: 'url-loader',
92 | query: {
93 | limit: 10000,
94 | name: 'imgs/[name]--[folder].[ext]'
95 | }
96 | }
97 | },
98 | {
99 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
100 | loader: 'url-loader',
101 | options: {
102 | limit: 10000,
103 | name: 'media/[name]--[folder].[ext]'
104 | }
105 | },
106 | {
107 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
108 | use: {
109 | loader: 'url-loader',
110 | query: {
111 | limit: 10000,
112 | name: 'fonts/[name]--[folder].[ext]'
113 | }
114 | }
115 | }
116 | ]
117 | },
118 | node: {
119 | __dirname: process.env.NODE_ENV !== 'production',
120 | __filename: process.env.NODE_ENV !== 'production'
121 | },
122 | plugins: [
123 | new VueLoaderPlugin(),
124 | new MiniCssExtractPlugin({ filename: 'styles.css' }),
125 | new HtmlWebpackPlugin({
126 | filename: 'index.html',
127 | template: path.resolve(__dirname, '../src/index.ejs'),
128 | minify: {
129 | collapseWhitespace: true,
130 | removeAttributeQuotes: true,
131 | removeComments: true
132 | },
133 | nodeModules: process.env.NODE_ENV !== 'production'
134 | ? path.resolve(__dirname, '../node_modules')
135 | : false
136 | }),
137 | new webpack.HotModuleReplacementPlugin(),
138 | new webpack.NoEmitOnErrorsPlugin()
139 | ],
140 | output: {
141 | filename: '[name].js',
142 | libraryTarget: 'commonjs2',
143 | path: path.join(__dirname, '../dist/electron')
144 | },
145 | resolve: {
146 | alias: {
147 | '@': path.join(__dirname, '../src/renderer'),
148 | 'vue$': 'vue/dist/vue.esm.js'
149 | },
150 | extensions: ['.js', '.vue', '.json', '.css', '.node']
151 | },
152 | target: 'electron-renderer'
153 | }
154 |
155 | /**
156 | * Adjust rendererConfig for development settings
157 | */
158 | if (process.env.NODE_ENV !== 'production') {
159 | rendererConfig.plugins.push(
160 | new webpack.DefinePlugin({
161 | '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
162 | })
163 | )
164 | }
165 |
166 | /**
167 | * Adjust rendererConfig for production settings
168 | */
169 | if (process.env.NODE_ENV === 'production') {
170 | rendererConfig.devtool = ''
171 |
172 | rendererConfig.plugins.push(
173 | new BabiliWebpackPlugin(),
174 | new CopyWebpackPlugin([
175 | {
176 | from: path.join(__dirname, '../static'),
177 | to: path.join(__dirname, '../dist/electron/static'),
178 | ignore: ['.*']
179 | }
180 | ]),
181 | new webpack.DefinePlugin({
182 | 'process.env.NODE_ENV': '"production"'
183 | }),
184 | new webpack.LoaderOptionsPlugin({
185 | minimize: true
186 | })
187 | )
188 | }
189 |
190 | module.exports = rendererConfig
191 |
--------------------------------------------------------------------------------
/.electron-vue/webpack.web.config.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | process.env.BABEL_ENV = 'web'
4 |
5 | const path = require('path')
6 | const webpack = require('webpack')
7 |
8 | const BabiliWebpackPlugin = require('babili-webpack-plugin')
9 | const CopyWebpackPlugin = require('copy-webpack-plugin')
10 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
11 | const HtmlWebpackPlugin = require('html-webpack-plugin')
12 | const { VueLoaderPlugin } = require('vue-loader')
13 |
14 | let webConfig = {
15 | devtool: '#cheap-module-eval-source-map',
16 | entry: {
17 | web: path.join(__dirname, '../src/renderer/main.js')
18 | },
19 | module: {
20 | rules: [
21 | {
22 | test: /\.(js|vue)$/,
23 | enforce: 'pre',
24 | exclude: /node_modules/,
25 | use: {
26 | loader: 'eslint-loader',
27 | options: {
28 | formatter: require('eslint-friendly-formatter')
29 | }
30 | }
31 | },
32 | {
33 | test: /\.scss$/,
34 | use: ['vue-style-loader', 'css-loader', 'sass-loader']
35 | },
36 | {
37 | test: /\.sass$/,
38 | use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax']
39 | },
40 | {
41 | test: /\.less$/,
42 | use: ['vue-style-loader', 'css-loader', 'less-loader']
43 | },
44 | {
45 | test: /\.css$/,
46 | use: ['vue-style-loader', 'css-loader']
47 | },
48 | {
49 | test: /\.html$/,
50 | use: 'vue-html-loader'
51 | },
52 | {
53 | test: /\.js$/,
54 | use: 'babel-loader',
55 | include: [path.resolve(__dirname, '../src/renderer')],
56 | exclude: /node_modules/
57 | },
58 | {
59 | test: /\.vue$/,
60 | use: {
61 | loader: 'vue-loader',
62 | options: {
63 | extractCSS: true,
64 | loaders: {
65 | sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
66 | scss: 'vue-style-loader!css-loader!sass-loader',
67 | less: 'vue-style-loader!css-loader!less-loader'
68 | }
69 | }
70 | }
71 | },
72 | {
73 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
74 | use: {
75 | loader: 'url-loader',
76 | query: {
77 | limit: 10000,
78 | name: 'imgs/[name].[ext]'
79 | }
80 | }
81 | },
82 | {
83 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
84 | use: {
85 | loader: 'url-loader',
86 | query: {
87 | limit: 10000,
88 | name: 'fonts/[name].[ext]'
89 | }
90 | }
91 | }
92 | ]
93 | },
94 | plugins: [
95 | new VueLoaderPlugin(),
96 | new MiniCssExtractPlugin({ filename: 'styles.css' }),
97 | new HtmlWebpackPlugin({
98 | filename: 'index.html',
99 | template: path.resolve(__dirname, '../src/index.ejs'),
100 | minify: {
101 | collapseWhitespace: true,
102 | removeAttributeQuotes: true,
103 | removeComments: true
104 | },
105 | nodeModules: false
106 | }),
107 | new webpack.DefinePlugin({
108 | 'process.env.IS_WEB': 'true'
109 | }),
110 | new webpack.HotModuleReplacementPlugin(),
111 | new webpack.NoEmitOnErrorsPlugin()
112 | ],
113 | output: {
114 | filename: '[name].js',
115 | path: path.join(__dirname, '../dist/web')
116 | },
117 | resolve: {
118 | alias: {
119 | '@': path.join(__dirname, '../src/renderer'),
120 | 'vue$': 'vue/dist/vue.esm.js'
121 | },
122 | extensions: ['.js', '.vue', '.json', '.css']
123 | },
124 | target: 'web'
125 | }
126 |
127 | /**
128 | * Adjust webConfig for production settings
129 | */
130 | if (process.env.NODE_ENV === 'production') {
131 | webConfig.devtool = ''
132 |
133 | webConfig.plugins.push(
134 | new BabiliWebpackPlugin(),
135 | new CopyWebpackPlugin([
136 | {
137 | from: path.join(__dirname, '../static'),
138 | to: path.join(__dirname, '../dist/web/static'),
139 | ignore: ['.*']
140 | }
141 | ]),
142 | new webpack.DefinePlugin({
143 | 'process.env.NODE_ENV': '"production"'
144 | }),
145 | new webpack.LoaderOptionsPlugin({
146 | minimize: true
147 | })
148 | )
149 | }
150 |
151 | module.exports = webConfig
152 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/.eslintignore
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | parser: 'babel-eslint',
4 | parserOptions: {
5 | sourceType: 'module'
6 | },
7 | env: {
8 | browser: true,
9 | node: true
10 | },
11 | extends: 'standard',
12 | globals: {
13 | __static: true
14 | },
15 | plugins: [
16 | 'html'
17 | ],
18 | 'rules': {
19 | // allow paren-less arrow functions
20 | 'arrow-parens': 0,
21 | // allow async-await
22 | 'generator-star-spacing': 0,
23 | // allow debugger during development
24 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | dist/electron/*
3 | dist/web/*
4 | build/*
5 | !build/icons
6 | node_modules/
7 | npm-debug.log
8 | npm-debug.log.*
9 | thumbs.db
10 | !.gitkeep
11 | .idea
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | osx_image: xcode8.3
2 | sudo: required
3 | dist: trusty
4 | language: c
5 | matrix:
6 | include:
7 | - os: osx
8 | - os: linux
9 | env: CC=clang CXX=clang++ npm_config_clang=1
10 | compiler: clang
11 | cache:
12 | directories:
13 | - node_modules
14 | - "$HOME/.electron"
15 | - "$HOME/.cache"
16 | addons:
17 | apt:
18 | packages:
19 | - libgnome-keyring-dev
20 | - icnsutils
21 | before_install:
22 | - mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([
23 | "$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz
24 | | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull
25 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi
26 | install:
27 | - nvm install 7
28 | - curl -o- -L https://yarnpkg.com/install.sh | bash
29 | - source ~/.bashrc
30 | - npm install -g xvfb-maybe
31 | - yarn
32 | script:
33 | - yarn run build
34 | branches:
35 | only:
36 | - master
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # electron-vue-anyproxy
2 |
3 | > electron-vue-anyproxy
4 |
5 | 下载mac或windows [体验版](https://github.com/luoyang125024608/electron-vue-anyproxy/releases/tag/v1.0.3)
6 |
7 | 与charles等工具的区别在于,用js编写抓包规则,然后Node跑抓包规则,可以调起chrome开发者工具debugger或者console编写在node里的规则。
8 | 
9 |
10 | 
11 |
12 | 
13 |
14 | 这个项目用 [electron-vue](https://github.com/SimulatedGREG/electron-vue)@[8fae476](https://github.com/SimulatedGREG/electron-vue/tree/8fae4763e9d225d3691b627e83b9e09b56f6c935) 和 [vue-cli](https://github.com/vuejs/vue-cli)生成. 文档 [Document](https://simulatedgreg.gitbooks.io/electron-vue/content/index.html).
15 |
16 | 这个项目核心逻辑使用阿里巴巴 [anyproxy](https://github.com/alibaba/anyproxy)@4.0. 文档 [Document](http://anyproxy.io/cn/).
17 |
18 | ```
19 | 特点:1、支持同时启用多个抓包规则
20 |
21 | 2、可以打开控制台断点抓包规则
22 |
23 | 3、模块引入anyproxy,无修改源码,支持升级
24 | ```
25 | #### Build Setup
26 |
27 | ``` bash
28 | # 安装依赖
29 | npm install
30 |
31 | # 开发
32 | npm run dev
33 |
34 | # 打包编译生成
35 | npm run build
36 |
37 |
38 | # 语法检查
39 | npm run lint
40 |
41 | ```
42 |
43 | ---
44 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 0.1.{build}
2 |
3 | branches:
4 | only:
5 | - master
6 |
7 | image: Visual Studio 2017
8 | platform:
9 | - x64
10 |
11 | cache:
12 | - node_modules
13 | - '%APPDATA%\npm-cache'
14 | - '%USERPROFILE%\.electron'
15 | - '%USERPROFILE%\AppData\Local\Yarn\cache'
16 |
17 | init:
18 | - git config --global core.autocrlf input
19 |
20 | install:
21 | - ps: Install-Product node 8 x64
22 | - git reset --hard HEAD
23 | - yarn
24 | - node --version
25 |
26 | build_script:
27 | - yarn build
28 |
29 | test: off
30 |
--------------------------------------------------------------------------------
/build/icons/256x256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/build/icons/256x256.png
--------------------------------------------------------------------------------
/build/icons/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/build/icons/icon.icns
--------------------------------------------------------------------------------
/build/icons/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/build/icons/icon.ico
--------------------------------------------------------------------------------
/dist/electron/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/dist/electron/.gitkeep
--------------------------------------------------------------------------------
/dist/web/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/dist/web/.gitkeep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "electron-vue-anyproxy",
3 | "version": "1.0.3",
4 | "author": "luoyangyangyang007 <125024608@qq.com>",
5 | "description": "electron-vue-anyproxy",
6 | "license": "MIT",
7 | "main": "./dist/electron/main.js",
8 | "scripts": {
9 | "build": "node .electron-vue/build.js && electron-builder",
10 | "build:dir": "node .electron-vue/build.js && electron-builder --dir",
11 | "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
12 | "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
13 | "dev": "node .electron-vue/dev-runner.js",
14 | "lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
15 | "lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src",
16 | "pack": "npm run pack:main && npm run pack:renderer",
17 | "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
18 | "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
19 | "postinstall": "npm run lint:fix"
20 | },
21 | "build": {
22 | "productName": "electron-vue-anyproxy",
23 | "appId": "com.luoyangyangyang.electron-vue-anyproxy",
24 | "directories": {
25 | "output": "build"
26 | },
27 | "files": [
28 | "dist/electron/**/*"
29 | ],
30 | "dmg": {
31 | "contents": [
32 | {
33 | "x": 410,
34 | "y": 150,
35 | "type": "link",
36 | "path": "/Applications"
37 | },
38 | {
39 | "x": 130,
40 | "y": 150,
41 | "type": "file"
42 | }
43 | ]
44 | },
45 | "mac": {
46 | "icon": "build/icons/icon.icns"
47 | },
48 | "win": {
49 | "icon": "build/icons/icon.ico"
50 | },
51 | "linux": {
52 | "icon": "build/icons"
53 | }
54 | },
55 | "dependencies": {
56 | "anyproxy": "^4.0.12",
57 | "axios": "^0.18.0",
58 | "highlight.js": "^9.14.2",
59 | "less": "^3.9.0",
60 | "less-loader": "^4.1.0",
61 | "lodash": "^4.17.11",
62 | "node-require-function": "^1.2.0",
63 | "vue": "^2.5.16",
64 | "vue-codemirror": "^4.0.6",
65 | "vue-electron": "^1.0.6",
66 | "vue-json-viewer": "^2.0.6",
67 | "vue-router": "^3.0.1",
68 | "vuex": "^3.0.1",
69 | "vuex-electron": "^1.0.0"
70 | },
71 | "devDependencies": {
72 | "react": "^15.6.2",
73 | "ajv": "^6.5.0",
74 | "ant-design-vue": "^1.3.4",
75 | "babel-core": "^6.26.3",
76 | "babel-eslint": "^8.2.3",
77 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
78 | "babel-loader": "^7.1.4",
79 | "babel-plugin-import": "^1.11.0",
80 | "babel-plugin-syntax-dynamic-import": "^6.18.0",
81 | "babel-plugin-syntax-jsx": "^6.18.0",
82 | "babel-plugin-transform-runtime": "^6.23.0",
83 | "babel-plugin-transform-vue-jsx": "^3.7.0",
84 | "babel-preset-env": "^1.7.0",
85 | "babel-preset-stage-0": "^6.24.1",
86 | "babel-register": "^6.26.0",
87 | "babili-webpack-plugin": "^0.1.2",
88 | "cfonts": "^2.1.2",
89 | "chalk": "^2.4.1",
90 | "copy-webpack-plugin": "^4.5.1",
91 | "cross-env": "^5.1.6",
92 | "css-loader": "^0.28.11",
93 | "del": "^3.0.0",
94 | "devtron": "^1.4.0",
95 | "electron": "^2.0.4",
96 | "electron-builder": "^20.19.2",
97 | "electron-debug": "^1.5.0",
98 | "electron-devtools-installer": "^2.2.4",
99 | "eslint": "^4.19.1",
100 | "eslint-config-standard": "^11.0.0",
101 | "eslint-friendly-formatter": "^4.0.1",
102 | "eslint-loader": "^2.0.0",
103 | "eslint-plugin-html": "^4.0.3",
104 | "eslint-plugin-import": "^2.12.0",
105 | "eslint-plugin-node": "^6.0.1",
106 | "eslint-plugin-promise": "^3.8.0",
107 | "eslint-plugin-standard": "^3.1.0",
108 | "file-loader": "^1.1.11",
109 | "html-webpack-plugin": "^3.2.0",
110 | "mini-css-extract-plugin": "0.4.0",
111 | "multispinner": "^0.2.1",
112 | "node-loader": "^0.6.0",
113 | "node-sass": "^4.9.2",
114 | "sass-loader": "^7.0.3",
115 | "style-loader": "^0.21.0",
116 | "url-loader": "^1.0.1",
117 | "vue-html-loader": "^1.2.4",
118 | "vue-loader": "^15.2.4",
119 | "vue-style-loader": "^4.1.0",
120 | "vue-template-compiler": "^2.5.16",
121 | "webpack": "^4.15.1",
122 | "webpack-cli": "^3.0.8",
123 | "webpack-dev-server": "^3.1.4",
124 | "webpack-hot-middleware": "^2.22.2",
125 | "webpack-merge": "^4.1.3"
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Electron Vue Anyproxy
6 | <% if (htmlWebpackPlugin.options.nodeModules) { %>
7 |
8 |
11 | <% } %>
12 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
electron vue anyproxy
59 |
proxy and more...
60 |
61 |
62 |
63 |
64 | <% if (!process.browser) { %>
65 |
68 | <% } %>
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/main/const.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-07
3 | */
4 | const fs = require('fs')
5 | const os = require('os')
6 |
7 | export const mainParams = {
8 | width: 1300,
9 | height: 780,
10 | icon: '~@/assets/logo.png',
11 | // titleBarStyle: 'hidden-inset',
12 | backgroundColor: '#fff',
13 | show: true,
14 | useContentSize: true
15 | }
16 |
17 | export function clearCache () {
18 | try {
19 | deleteFolder(os.homedir() + '/.anyproxy/cache')
20 | console.log('已删除')
21 | } catch (err) {
22 | // 处理错误
23 | console.log(err)
24 | }
25 | }
26 |
27 | function deleteFolder (path) {
28 | var files = []
29 | if (fs.existsSync(path)) {
30 | files = fs.readdirSync(path)
31 | files.forEach(function (file, index) {
32 | var curPath = path + '/' + file
33 | if (fs.statSync(curPath).isDirectory()) { // recurse
34 | deleteFolder(curPath)
35 | } else { // delete file
36 | fs.unlinkSync(curPath)
37 | }
38 | })
39 | fs.rmdirSync(path)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/index.dev.js:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is used specifically and only for development. It installs
3 | * `electron-debug` & `vue-devtools`. There shouldn't be any need to
4 | * modify this file, but it can be used to extend your development
5 | * environment.
6 | */
7 |
8 | /* eslint-disable */
9 |
10 | // Install `electron-debug` with `devtron`
11 | require('electron-debug')({ showDevTools: true })
12 |
13 | // Install `vue-devtools`
14 | require('electron').app.on('ready', () => {
15 | let installExtension = require('electron-devtools-installer')
16 | installExtension.default(installExtension.VUEJS_DEVTOOLS)
17 | .then(() => {})
18 | .catch(err => {
19 | console.log('Unable to install `vue-devtools`: \n', err)
20 | })
21 | })
22 |
23 | // Require `main` process to boot app
24 | require('./index')
--------------------------------------------------------------------------------
/src/main/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | import { app, BrowserWindow, Menu } from 'electron'
4 | import { mainParams, clearCache } from './const'
5 | // import localProxy from '../renderer/lib/global-proxy/local-proxy.js'
6 | /**
7 | * Set `__static` path to static files in production
8 | * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
9 | */
10 | if (process.env.NODE_ENV !== 'development') {
11 | global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
12 | }
13 | let mainWindow
14 | const winURL = process.env.NODE_ENV === 'development'
15 | ? `http://localhost:9080`
16 | : `file://${__dirname}/index.html`
17 |
18 | function createWindow () {
19 | if (process.platform === 'darwin') {
20 | const template = [
21 | {
22 | label: 'Application',
23 | submenu: [
24 | { label: 'Quit', accelerator: 'Command+Q', click: function () { app.quit() } }
25 | ]
26 | },
27 | {
28 | label: 'Edit',
29 | submenu: [
30 | { label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
31 | { label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'Cut:' },
32 | { label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' }
33 | ]
34 | }
35 | ]
36 | Menu.setApplicationMenu(Menu.buildFromTemplate(template))
37 | } else {
38 | Menu.setApplicationMenu(null)
39 | }
40 | /**
41 | * Initial window options
42 | */
43 | mainWindow = new BrowserWindow(mainParams)
44 |
45 | mainWindow.loadURL(winURL)
46 |
47 | mainWindow.webContents.on('did-finish-load', () => {
48 | })
49 | mainWindow.on('closed', () => {
50 | mainWindow = null
51 | })
52 | }
53 |
54 | app.on('ready', () => {
55 | createWindow()
56 | })
57 |
58 | app.on('window-all-closed', () => {
59 | // localProxy.disable()
60 | clearCache()
61 | if (process.platform !== 'darwin') {
62 | app.quit()
63 | }
64 | })
65 |
66 | app.on('activate', () => {
67 | if (mainWindow === null) {
68 | createWindow()
69 | }
70 | })
71 |
72 | /**
73 | * Auto Updater
74 | *
75 | * Uncomment the following code below and install `electron-updater` to
76 | * support auto updating. Code Signing with a valid certificate is required.
77 | * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
78 | */
79 |
80 | /*
81 | import { autoUpdater } from 'electron-updater'
82 |
83 | autoUpdater.on('update-downloaded', () => {
84 | autoUpdater.quitAndInstall()
85 | })
86 |
87 | app.on('ready', () => {
88 | if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
89 | })
90 | */
91 |
--------------------------------------------------------------------------------
/src/renderer/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
19 |
20 |
23 |
--------------------------------------------------------------------------------
/src/renderer/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/src/renderer/assets/.gitkeep
--------------------------------------------------------------------------------
/src/renderer/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/src/renderer/assets/logo.png
--------------------------------------------------------------------------------
/src/renderer/assets/p1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/src/renderer/assets/p1.jpg
--------------------------------------------------------------------------------
/src/renderer/assets/p2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/src/renderer/assets/p2.jpg
--------------------------------------------------------------------------------
/src/renderer/assets/p3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/src/renderer/assets/p3.jpg
--------------------------------------------------------------------------------
/src/renderer/assets/style/common.scss:
--------------------------------------------------------------------------------
1 | body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td {
2 | margin: 0;
3 | padding: 0
4 | }
5 |
6 | body, button, input, select, textarea {
7 | font: 14px/1 "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Georgia, tahoma, arial, simsun, "宋体";
8 | color: #333;
9 | -ms-overflow-style: scrollbar;
10 | word-break: break-all
11 | }
12 |
13 | button, input, select, textarea {
14 | font-size: 100%
15 | }
16 |
17 | a {
18 | color: inherit;
19 | text-decoration: none;
20 | outline: 0;
21 | }
22 |
23 | table {
24 | border-collapse: collapse;
25 | border-spacing: 0
26 | }
27 |
28 | fieldset, img, area, a {
29 | border: 0;
30 | outline: 0
31 | }
32 |
33 | img {
34 | display: block;
35 | }
36 |
37 | address, caption, cite, code, dfn, em, th, var, i {
38 | font-style: normal;
39 | font-weight: normal
40 | }
41 |
42 | code, kbd, pre, samp {
43 | font-family: courier new, courier, monospace
44 | }
45 |
46 | ol, ul {
47 | list-style: none
48 | }
49 |
50 | body {
51 | background: #fff;
52 | -webkit-text-size-adjust: none;
53 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
54 | }
55 |
56 | small {
57 | font-size: 12px
58 | }
59 |
60 | h1, h2, h3, h4, h5, h6 {
61 | font-size: 100%
62 | }
63 |
64 | sup {
65 | vertical-align: text-top;
66 | }
67 |
68 | sub {
69 | vertical-align: text-bottom
70 | }
71 |
72 | legend {
73 | color: #000
74 | }
75 |
76 | a, input {
77 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
78 | }
79 |
80 | input, textarea, button, select {
81 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
82 | -webkit-appearance: none;
83 | -moz-appearance: none;
84 | border-radius: 0;
85 | outline: none;
86 | }
87 |
88 | div {
89 | -webkit-overflow-scrolling: touch;
90 | }
91 |
92 | /****************flexbox**************/
93 | .flex {
94 | display: flex;
95 | }
96 |
97 | .inline-flex {
98 | display: inline-flex;
99 | }
100 |
101 | .flex-center {
102 | justify-content: center;
103 | align-items: center;
104 | }
105 |
106 | /*横向或纵向*/
107 | .flex-row {
108 | flex-direction: row;
109 | }
110 |
111 | .flex-col {
112 | flex-direction: column;
113 | }
114 |
115 | .flex-row-reverse {
116 | flex-direction: row-reverse;
117 | }
118 |
119 | .flex-col-reverse {
120 | flex-direction: column-reverse;
121 | }
122 |
123 | .flex-wrap {
124 | flex-wrap: wrap;
125 | }
126 |
127 | /*主轴对齐方式*/
128 | .flex-justify-start {
129 | justify-content: flex-start;
130 | }
131 |
132 | .flex-justify-end {
133 | justify-content: flex-end;
134 | }
135 |
136 | .flex-justify-center {
137 | justify-content: center;
138 | }
139 |
140 | .flex-justify-between {
141 | justify-content: space-between;
142 | }
143 |
144 | .flex-justify-around {
145 | justify-content: space-around;
146 | }
147 |
148 | /*侧轴对齐方式*/
149 | .flex-align-start {
150 | align-items: flex-start;
151 | }
152 |
153 | .flex-align-end {
154 | align-items: flex-end;
155 | }
156 |
157 | .flex-align-center {
158 | align-items: center;
159 | }
160 |
161 | .flex-align-baseline {
162 | align-items: baseline;
163 | }
164 |
165 | .flex-align-stretch {
166 | align-items: stretch;
167 | }
168 |
169 | /*主轴换行时行在侧轴的对齐方式,必须定义flex-wrap为换行*/
170 | .flex-content-start {
171 | align-content: flex-start;
172 | }
173 |
174 | .flex-content-end {
175 | align-content: flex-end;
176 | }
177 |
178 | .flex-content-center {
179 | align-content: center;
180 | }
181 |
182 | .flex-content-between {
183 | align-content: space-between;
184 | }
185 |
186 | .flex-content-around {
187 | align-content: space-around;
188 | }
189 |
190 | .flex-content-stretch {
191 | align-content: stretch;
192 | }
193 |
194 | /*允许子元素收缩*/
195 | .flex-child-grow {
196 | flex-grow: 1;
197 | }
198 |
199 | /*允许拉伸*/
200 | .flex-child-shrink {
201 | flex-shrink: 1;
202 | }
203 |
204 | /*允许收缩*/
205 | .flex-child-noshrink {
206 | flex-shrink: 0;
207 | }
208 |
209 | /*不允许收缩*/
210 | .flex-child-average {
211 | flex: 1;
212 | }
213 |
214 | /*平均分布,兼容旧版必须给宽度*/
215 | .flex-child-first {
216 | order: 1;
217 | }
218 |
219 | /*排第一个*/
220 | /*子元素在侧轴的对齐方式*/
221 | .flex-child-align-start {
222 | align-self: flex-start;
223 | }
224 |
225 | .flex-child-align-end {
226 | align-self: flex-end;
227 | }
228 |
229 | .flex-child-align-center {
230 | align-self: center;
231 | }
232 |
233 | .flex-child-align-baseline {
234 | align-self: baseline;
235 | }
236 |
237 | .flex-child-align-stretch {
238 | align-self: stretch;
239 | }
240 |
241 | .text-ellipsis {
242 | display: inline-block;
243 | max-width: 100%;
244 | overflow: hidden;
245 | text-overflow: ellipsis;
246 | white-space: nowrap;
247 | word-wrap: normal;
248 | }
249 |
250 | .block {
251 | display: block;
252 | }
253 |
254 | .inline-block {
255 | display: inline-block;
256 | }
257 |
258 | .inline {
259 | display: inline;
260 | }
261 |
262 | .hide {
263 | display: none;
264 | }
265 |
266 | .left {
267 | float: left;
268 | }
269 |
270 | .right {
271 | float: right;
272 | }
273 |
274 | .full-height {
275 | height: 100%;
276 | }
277 |
278 | .full-width {
279 | width: 100%;
280 | }
281 |
282 | .relative {
283 | position: relative;
284 | }
285 |
286 | .absolute {
287 | position: absolute;
288 | }
289 |
290 | .fixed {
291 | position: fixed;
292 | }
293 |
294 | .clear {
295 | clear: both;
296 | }
297 |
298 | .overflow-hide {
299 | overflow: hidden;
300 | }
301 |
302 | .normal {
303 | font-weight: normal;
304 | }
305 |
306 | .bold {
307 | font-weight: bold;
308 | }
309 |
310 | .font-30 {
311 | font-size: 30px;
312 | }
313 |
314 | .font-24 {
315 | font-size: 24px;
316 | }
317 |
318 | .font-22 {
319 | font-size: 22px;
320 | }
321 |
322 | .font-20 {
323 | font-size: 20px;
324 | }
325 |
326 | .font-18 {
327 | font-size: 18px;
328 | }
329 |
330 | .font-17 {
331 | font-size: 17px;
332 | }
333 |
334 | .font-16 {
335 | font-size: 16px;
336 | }
337 |
338 | .font-15 {
339 | font-size: 15px;
340 | }
341 |
342 | .font-14 {
343 | font-size: 14px;
344 | }
345 |
346 | .font-13 {
347 | font-size: 13px;
348 | }
349 |
350 | .font-12 {
351 | font-size: 12px;
352 | }
353 |
354 | .font-10 {
355 | font-size: 10px;
356 | }
357 |
358 | .border-box {
359 | box-sizing: border-box;
360 | }
361 |
362 | .border {
363 | border: solid 1px #dfdfdf;
364 | }
365 |
366 | .border-top {
367 | border-top: 1px solid #dfdfdf;
368 | }
369 |
370 | .border-bottom {
371 | border-bottom: 1px solid #dfdfdf;
372 | }
373 |
374 | .border-left {
375 | border-left: 1px solid #dfdfdf;
376 | }
377 |
378 | .border-right {
379 | border-right: 1px solid #dfdfdf;
380 | }
381 |
382 | .margin {
383 | margin: 10px;
384 | }
385 |
386 | .margin-top {
387 | margin-top: 10px;
388 | }
389 |
390 | .margin-right {
391 | margin-right: 10px;
392 | }
393 |
394 | .margin-bottom {
395 | margin-bottom: 10px;
396 | }
397 |
398 | .margin-left {
399 | margin-left: 10px;
400 | }
401 |
402 | .mt-5 {
403 | margin-top: 5px;
404 | }
405 |
406 | .mr-5 {
407 | margin-right: 5px;
408 | }
409 |
410 | .mb-5 {
411 | margin-bottom: 5px;
412 | }
413 |
414 | .ml-5 {
415 | margin-left: 5px;
416 | }
417 |
418 | .padding {
419 | padding: 10px;
420 | }
421 |
422 | .pt-5 {
423 | padding-top: 5px;
424 | }
425 |
426 | .pr-5 {
427 | padding-right: 5px;
428 | }
429 |
430 | .pb-5 {
431 | padding-bottom: 5px;
432 | }
433 |
434 | .pl-5 {
435 | padding-left: 5px;
436 | }
437 |
438 | .padding-top {
439 | padding-top: 10px;
440 | }
441 |
442 | .padding-right {
443 | padding-right: 10px;
444 | }
445 |
446 | .padding-bottom {
447 | padding-bottom: 10px;
448 | }
449 |
450 | .padding-left {
451 | padding-left: 10px;
452 | }
453 |
454 | .text-center {
455 | text-align: center;
456 | }
457 |
458 | .pointer {
459 | cursor: pointer;
460 | }
461 |
462 | .assist-color, a.assist-color {
463 | color: #78b
464 | }
465 |
466 | /*辅助色*/
467 | .assist-bgcolor {
468 | background-color: #78b;
469 | }
470 |
471 | .black, a.black {
472 | color: #333;
473 | }
474 |
475 | .black-bg {
476 | background-color: #333;
477 | }
478 |
479 | .grey, a.grey {
480 | color: #505050;
481 | }
482 |
483 | .grey-bg {
484 | background-color: #505050;
485 | }
486 |
487 | .grey-6, a.grey-6 {
488 | color: #6b6b6b;
489 | }
490 |
491 | .grey-6-bg {
492 | background-color: #6b6b6b;
493 | }
494 |
495 | .grey-9, a.grey-9 {
496 | color: #9c9c9c;
497 | }
498 |
499 | .grey-9-bg {
500 | background-color: #9c9c9c;
501 | }
502 |
503 | .grey-d, a.grey-d {
504 | color: #dfdfdf;
505 | }
506 |
507 | .grey-d-bg {
508 | background-color: #dfdfdf;
509 | }
510 |
511 | .grey-e, a.grey-e {
512 | color: #efefef;
513 | }
514 |
515 | .grey-e-bg {
516 | background-color: #efefef;
517 | }
518 |
519 | .grey-f, a.grey-f {
520 | color: #f5f5f5;
521 | }
522 |
523 | .grey-f-bg {
524 | background-color: #f5f5f5;
525 | }
526 |
527 | .white, a.white {
528 | color: #fff;
529 | }
530 |
531 | .white-bg {
532 | background-color: #fff;
533 | }
534 |
535 | .red, a.red {
536 | color: #c80f1e;
537 | }
538 |
539 | .red-bg {
540 | background-color: #c80f1e;
541 | }
542 |
543 | .light-red, a.light-red {
544 | color: #ff5050;
545 | }
546 |
547 | .light-red-bg {
548 | background-color: #ff5050;
549 | }
550 |
551 | .orange-red, a.orange-red {
552 | color: #ff4e00;
553 | }
554 |
555 | .orange-red-bg {
556 | background-color: #ff4e00;
557 | }
558 |
559 | .orange, a.orange {
560 | color: #ff6700;
561 | }
562 |
563 | .orange-bg {
564 | background-color: #ff6700;
565 | }
566 |
567 | .orange-yellow, a.orange-yellow {
568 | color: #fd9712;
569 | }
570 |
571 | .orange-yellow-bg {
572 | background-color: #fd9712;
573 | }
574 |
575 | .yellow, a.yellow {
576 | color: #fbcb30;
577 | }
578 |
579 | .yellow-bg {
580 | background-color: #fbcb30;
581 | }
582 |
583 | .green, a.green {
584 | color: #5dc800;
585 | }
586 |
587 | .green-bg {
588 | background-color: #5dc800;
589 | }
590 |
591 | .light-green, a.light-green {
592 | color: #8fd14c;
593 | }
594 |
595 | .light-green-bg {
596 | background-color: #8fd14c;
597 | }
598 |
599 | .blue, a.blue {
600 | color: #3caaff;
601 | }
602 |
603 | .blue-bg {
604 | background-color: #3caaff;
605 | }
606 |
607 | .light-blue, a.light-blue {
608 | color: #78b;
609 | }
610 |
611 | .light-blue-bg {
612 | background-color: #78b;
613 | }
614 |
615 | .purple, a.purple {
616 | color: #a776d9;
617 | }
618 |
619 | .purple-bg {
620 | background-color: #a776d9;
621 | }
622 |
623 | .light-purple, a.light-purple {
624 | color: #b394f3;
625 | }
626 |
627 | .light-purple-bg {
628 | background-color: #b394f3;
629 | }
630 |
631 | .pink, a.pink {
632 | color: #fb5c9b;
633 | }
634 |
635 | .pink-bg {
636 | background-color: #fb5c9b;
637 | }
638 |
639 | .lines-1 { /* autoprefixer: off */
640 | text-overflow: ellipsis;
641 | -webkit-line-clamp: 1;
642 | display: -webkit-box;
643 | overflow: hidden;
644 | -webkit-box-orient: vertical;
645 | word-break: break-all;
646 | }
647 |
648 | .lines-2 { /* autoprefixer: off */
649 | text-overflow: ellipsis;
650 | -webkit-line-clamp: 2;
651 | display: block;
652 | display: -webkit-box;
653 | overflow: hidden;
654 | -webkit-box-orient: vertical;
655 | word-break: break-all;
656 | height: 3em;
657 | }
658 |
--------------------------------------------------------------------------------
/src/renderer/components/header-menu.vue:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
19 |
20 |
26 |
27 |
33 |
34 |
35 |
36 |
39 |
40 |
41 | 服务未启动
42 |
43 |
44 |
服务已启动
45 |
代理地址:{{ipAddress}}
46 |
代理端口:{{port}}
47 |
48 |
49 |
50 | 当前状态
51 |
52 |
55 | 下载证书
56 |
57 |
60 | 控制台
61 |
62 |
63 |
64 |
70 |
71 |
72 |
73 |
Scan to download rootCA.crt to your Phone
74 |
{{url}}
75 |
76 | Download
77 |
78 |
79 |
80 |
Your RootCA has not been generated yet, please click the button to generate before
81 | you download it.
82 |
生成证书
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
218 |
--------------------------------------------------------------------------------
/src/renderer/components/layout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 | E V A
9 | Electron Vue Anyproxy
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 抓包列表
27 |
28 |
29 |
30 |
31 |
32 | 拦截修改
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
84 |
85 |
92 |
171 |
--------------------------------------------------------------------------------
/src/renderer/lib/bus.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-10
3 | */
4 | import Vue from 'vue'
5 |
6 | export default new Vue()
7 |
--------------------------------------------------------------------------------
/src/renderer/lib/global-proxy/exec-sync.js:
--------------------------------------------------------------------------------
1 | import childProcess from 'child_process'
2 |
3 | function execSync (cmd) {
4 | let stdout
5 | let status = 0
6 |
7 | try {
8 | stdout = childProcess.execSync(cmd)
9 | } catch (err) {
10 | stdout = err.stdout
11 | status = err.status
12 | }
13 |
14 | return {
15 | stdout: stdout.toString(),
16 | status
17 | }
18 | }
19 |
20 | export default execSync
21 |
--------------------------------------------------------------------------------
/src/renderer/lib/global-proxy/index.js:
--------------------------------------------------------------------------------
1 | import mac from './mac'
2 | import win from './win'
3 |
4 | const agent = /^win/.test(process.platform) ? win : mac
5 |
6 | function execute (fn, ...args) {
7 | return new Promise((resolve, reject) => {
8 | let ret = agent[fn](...args)
9 |
10 | if (ret.status) {
11 | reject(ret.stdout)
12 | } else {
13 | resolve(ret.stdout)
14 | }
15 | })
16 | }
17 |
18 | function enable (hostname, port, protocol) {
19 | return execute('enable', hostname, port, protocol)
20 | }
21 |
22 | function disable (protocol) {
23 | return execute('disable', protocol)
24 | }
25 |
26 | function status () {
27 | return execute('status')
28 | }
29 |
30 | export default {
31 | status,
32 | enable,
33 | disable
34 | }
35 |
--------------------------------------------------------------------------------
/src/renderer/lib/global-proxy/local-proxy.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-13
3 | */
4 | import globalProxy from './index'
5 |
6 | export default {
7 | port: 8001,
8 | enable () {
9 | globalProxy.enable('127.0.0.1', this.port, 'http').then((stdout) => {
10 | // console.log(stdout)
11 | }).catch((error) => {
12 | console.log(error)
13 | })
14 | globalProxy.enable('127.0.0.1', this.port, 'https').then((stdout) => {
15 | // console.log(stdout)
16 | }).catch((error) => {
17 | console.log(error)
18 | })
19 | },
20 | disable () {
21 | globalProxy.disable('http').then((stdout) => {
22 | // console.log(stdout)
23 | }).catch((error) => {
24 | console.log(error)
25 | })
26 | globalProxy.disable('https').then((stdout) => {
27 | // console.log(stdout)
28 | }).catch((error) => {
29 | console.log(error)
30 | })
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/renderer/lib/global-proxy/mac.js:
--------------------------------------------------------------------------------
1 | import execSync from './exec-sync'
2 |
3 | let networkType = null
4 |
5 | function getNetworkType () {
6 | if (networkType) {
7 | return networkType
8 | }
9 |
10 | const networkTypes = [
11 | 'Ethernet',
12 | 'Thunderbolt Ethernet',
13 | 'Wi-Fi'
14 | ]
15 |
16 | for (let type of networkTypes) {
17 | const result = execSync(`networksetup -getwebproxy ${type}`)
18 |
19 | if (result.status === 0) {
20 | networkType = type
21 | return networkType
22 | }
23 | }
24 |
25 | throw new Error('Unknown network type')
26 | }
27 |
28 | function getProxyState () {
29 | const netType = getNetworkType()
30 |
31 | return execSync(`networksetup -getwebproxy ${netType}`)
32 | }
33 |
34 | function enable (hostname, port, protocol = 'http') {
35 | const netType = getNetworkType()
36 | const parameter = protocol === 'https'
37 | ? 'setsecurewebproxy'
38 | : 'setwebproxy'
39 |
40 | return execSync(`networksetup -${parameter} ${netType} ${hostname} ${port}`)
41 | }
42 |
43 | function disable (proxyType = 'http') {
44 | const netType = getNetworkType()
45 | const parameter = proxyType === 'https'
46 | ? 'setsecurewebproxystate'
47 | : 'setwebproxystate'
48 | return execSync(`networksetup -${parameter} ${netType} off`)
49 | }
50 |
51 | export default {
52 | enable,
53 | disable,
54 | status: getProxyState
55 | }
56 |
--------------------------------------------------------------------------------
/src/renderer/lib/global-proxy/win.js:
--------------------------------------------------------------------------------
1 | import execSync from './exec-sync'
2 |
3 | const REG_PATH = `reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion
4 | \\Internet Settings" /v`
5 |
6 | function enable (hostname, port) {
7 | return execSync(
8 | // set proxy
9 | `${REG_PATH} ProxyServer /t REG_SZ /d ${hostname}:${port} /f & ` +
10 | // enable proxy
11 | `${REG_PATH} ProxyEnable /t REG_DWORD /d 1 /f`)
12 | }
13 |
14 | function disable () {
15 | return execSync(`${REG_PATH} /v ProxyEnable /t REG_DWORD /d 0 /f`)
16 | }
17 |
18 | function status () {}
19 |
20 | export default {
21 | status,
22 | enable,
23 | disable
24 | }
25 |
--------------------------------------------------------------------------------
/src/renderer/lib/proxy/proxy-api.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-08
3 | */
4 |
5 | import ruleApi from '../rule/rule-api'
6 |
7 | const AnyProxy = require('anyproxy')
8 | const certMgr = require('anyproxy').utils.certMgr
9 |
10 | class ProxyApi {
11 | constructor () {
12 | this.proxyServer = null
13 | this.options = {
14 | port: 8001,
15 | // rule: require('/Users/luoyang/Library/Application Support/Electron/rule_custom/custom_1c9ec7bc-f809-438c-a045-11dd87f95cee.js'),
16 | webInterface: {
17 | enable: true,
18 | webPort: 8002
19 | },
20 | // throttle: 10000,
21 | forceProxyHttps: false,
22 | wsIntercept: false, // 不开启websocket代理
23 | silent: true
24 | }
25 | }
26 |
27 | get CAFileExists () {
28 | return certMgr.ifRootCAFileExists()
29 | }
30 |
31 | init (ruleIds) {
32 | this.options.forceProxyHttps = this.CAFileExists
33 | if (ruleIds) {
34 | this.options.rule = ruleApi.mergeRuleModule(ruleIds)
35 | }
36 | this.proxyServer = new AnyProxy.ProxyServer(this.options)
37 | }
38 |
39 | start (onUpdate) {
40 | if (onUpdate) {
41 | this.proxyServer.recorder.on('update', (data) => {
42 | onUpdate(data)
43 | })
44 | }
45 | this.proxyServer.start()
46 | }
47 |
48 | close () {
49 | // this.proxyServer.off('update')
50 | this.proxyServer.close()
51 | }
52 |
53 | fetchBody (id) {
54 | return new Promise((resolve, reject) => {
55 | this.proxyServer.recorder.getDecodedBody(id, (err, result) => {
56 | if (err || !result) {
57 | reject(err || new Error())
58 | } else if (result.type && result.type === 'image' && result.mime) {
59 | resolve({
60 | raw: true,
61 | type: result.mime,
62 | content: result.content
63 | })
64 | } else {
65 | resolve({
66 | id: id,
67 | type: result.type,
68 | content: result.content
69 | })
70 | }
71 | })
72 | })
73 | }
74 |
75 | getSingleLog (id) {
76 | return new Promise((resolve, reject) => {
77 | if (this.proxyServer.recorder) {
78 | this.proxyServer.recorder.getSingleRecord(id, (err, data) => {
79 | if (err) {
80 | reject(err.toString())
81 | } else {
82 | resolve(data[0])
83 | }
84 | })
85 | } else {
86 | reject(new Error())
87 | }
88 | })
89 | }
90 | }
91 |
92 | export default new ProxyApi()
93 |
--------------------------------------------------------------------------------
/src/renderer/lib/proxy/request-handler.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-08
3 | */
4 | class RequestHandler {
5 | }
6 |
7 | module.exports = RequestHandler
8 |
--------------------------------------------------------------------------------
/src/renderer/lib/rule/const.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-11
3 | */
4 | export const ruleOptions = [
5 | {
6 | value: 'modify_request_data',
7 | label: '修改请求数据'
8 | }, {
9 | value: 'modify_request_header',
10 | label: '修改请求头'
11 | }, {
12 | value: 'modify_request_path',
13 | label: '修改请求目标地址'
14 | }, {
15 | value: 'modify_request_protocol',
16 | label: '修改请求协议'
17 | }, {
18 | value: 'modify_response_data',
19 | label: '修改返回内容并延迟'
20 | }, {
21 | value: 'modify_response_header',
22 | label: '修改返回头'
23 | }, {
24 | value: 'modify_response_statuscode',
25 | label: '修改返回状态码'
26 | },
27 | {
28 | value: 'use_local_response',
29 | label: '使用本地数据'
30 | }
31 | ]
32 |
--------------------------------------------------------------------------------
/src/renderer/lib/rule/rule-api.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-11
3 | */
4 | const path = require('path')
5 | const fs = require('fs')
6 | const nodeRequire = require('node-require-function')()
7 | const co = require('co')
8 | const { app } = require('electron').remote
9 |
10 | class RuleApi {
11 | constructor () {
12 | this.ruleFile = this.userDataDir + '/rules.json'
13 | this.ruleCustomPath = this.userDataDir + '/rule_custom'
14 | this.ruleSamplePath = path.join(__static, '/rule_sample')
15 | }
16 |
17 | get userDataDir () {
18 | return app.getPath('userData')
19 | }
20 |
21 | fetchSampleRule (rulename) {
22 | const filename = 'sample_' + rulename + '.js'
23 | const rulePath = path.resolve(this.ruleSamplePath, filename)
24 | return new Promise((resolve, reject) => {
25 | if (fs.existsSync(rulePath)) {
26 | fs.readFile(rulePath, 'utf8', (err, data) => {
27 | if (err) {
28 | reject(err)
29 | } else {
30 | resolve(data.toString())
31 | }
32 | })
33 | } else {
34 | reject(new Error())
35 | }
36 | })
37 | }
38 |
39 | saveRulesIntoFile (rules) {
40 | fs.writeFileSync(this.ruleFile, JSON.stringify(rules), 'utf8')
41 | }
42 |
43 | saveCustomRuleToFile (id, rule) {
44 | if (!fs.existsSync(this.ruleCustomPath)) {
45 | fs.mkdirSync(this.ruleCustomPath)
46 | }
47 |
48 | const rulepath = path.resolve(this.ruleCustomPath, this.getCustomFileName(id))
49 |
50 | fs.writeFileSync(rulepath, rule, 'utf8')
51 | }
52 |
53 | readRulesFromFile () {
54 | if (fs.existsSync(this.ruleFile)) {
55 | return fs.readFileSync(this.ruleFile, 'utf8') || '[]'
56 | } else {
57 | return '[]'
58 | }
59 | }
60 |
61 | fetchCustomRule (id) {
62 | const rulepath = path.resolve(this.ruleCustomPath, this.getCustomFileName(id))
63 | return new Promise((resolve, reject) => {
64 | if (fs.existsSync(rulepath)) {
65 | fs.readFile(rulepath, (err, data) => {
66 | if (err) {
67 | reject(err)
68 | } else {
69 | resolve(data.toString())
70 | }
71 | })
72 | } else {
73 | reject(new Error())
74 | }
75 | })
76 | }
77 |
78 | deleteCustomRuleFile (id) {
79 | const rulepath = path.resolve(this.ruleCustomPath, this.getCustomFileName(id))
80 | if (fs.existsSync(rulepath)) {
81 | fs.unlink(rulepath, (err) => {
82 | if (err) throw err
83 | })
84 | }
85 | }
86 |
87 | freshRequire (modulePath) {
88 | let key = nodeRequire.resolve(modulePath)
89 | delete nodeRequire.cache[key]
90 | return nodeRequire(modulePath)
91 | }
92 |
93 | // require rule文件
94 | requireRuleModule (id) {
95 | if (!id) return {}
96 | const filepath = path.resolve(this.ruleCustomPath, this.getCustomFileName(id))
97 | if (fs.existsSync(filepath)) {
98 | return this.freshRequire(filepath)
99 | } else {
100 | return {}
101 | }
102 | }
103 |
104 | mergeRuleModule (ids) {
105 | let rules = ids.map(id => this.requireRuleModule(id))
106 | // var rule = this.requireRuleModule(ids[0])
107 | return {
108 | summary: '',
109 | beforeSendRequest: function * (requestDetail) {
110 | co(function * () {
111 | var result = yield rules.filter(rule => rule.beforeSendRequest).map(rule => rule.beforeSendRequest(requestDetail))
112 | return result.reduce(function (request, res) {
113 | return Object.assign(request, res || {})
114 | }, requestDetail)
115 | })
116 | },
117 | beforeSendResponse: function * (requestDetail, responseDetail) {
118 | co(function * () {
119 | var result = yield rules.filter(rule => rule.beforeSendResponse).map(rule => rule.beforeSendResponse(requestDetail, responseDetail))
120 | return result.reduce(function (response, res) {
121 | return Object.assign(response, res || {})
122 | }, responseDetail)
123 | })
124 | }
125 | }
126 | }
127 |
128 | getCustomFileName (id) {
129 | return 'custom_' + id + '.js'
130 | }
131 | }
132 |
133 | export default new RuleApi()
134 |
--------------------------------------------------------------------------------
/src/renderer/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 | import router from './router'
4 | import store from './store'
5 | import './assets/style/common.scss'
6 | import { Button, message, notification, Modal } from 'ant-design-vue'
7 | import bus from './lib/bus'
8 | import axios from 'axios'
9 |
10 | Vue.use(Button)
11 | Vue.prototype.$message = message
12 | Vue.prototype.$notification = notification
13 | Vue.prototype.$info = Modal.info
14 | Vue.prototype.$success = Modal.success
15 | Vue.prototype.$error = Modal.error
16 | Vue.prototype.$warning = Modal.warning
17 | Vue.prototype.$confirm = Modal.confirm
18 | Vue.prototype.$bus = bus
19 | Vue.prototype.$axios = axios.create({
20 | baseURL: 'http://127.0.0.1:8002'
21 | })
22 | if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
23 | Vue.config.productionTip = false
24 | /* eslint-disable no-new */
25 | new Vue({
26 | components: { App },
27 | router,
28 | store,
29 | template: ''
30 | }).$mount('#app')
31 |
--------------------------------------------------------------------------------
/src/renderer/pages/components/network-detail.vue:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
14 |
15 | Request URL: {{headers.url}}
16 | Request Method: {{headers.method}}
17 | Protocol: {{headers.protocol}}
18 |
19 |
20 |
21 | {{key}}: {{value}}
22 |
23 |
24 |
25 |
26 | {{headers.reqBody || ''}}
27 |
28 |
29 |
30 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | Status Code:
43 | {{headers.statusCode}}
44 |
45 |
46 |
47 |
48 | {{key}}: {{value}}
49 |
50 |
51 |
52 |
53 |
54 | {{detailContent.content}}
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
185 |
--------------------------------------------------------------------------------
/src/renderer/pages/network.vue:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 | Host
20 | Path
21 | Mime
22 |
23 |
30 |
31 |
32 | {{item.host}}
33 | {{item.path}}
34 | {{item.mime}}
35 |
36 |
37 |
38 |
46 |
50 |
51 |
52 |
53 |
126 |
--------------------------------------------------------------------------------
/src/renderer/pages/rule/index.vue:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
22 |
--------------------------------------------------------------------------------
/src/renderer/pages/rule/rule-edit.vue:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
11 |
12 | {{item.label}}
13 |
14 |
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
29 | 保存
30 | 取消
31 |
32 |
33 |
34 |
35 |
36 |
161 |
--------------------------------------------------------------------------------
/src/renderer/pages/rule/rule-list.vue:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 | 添加规则
8 |
9 |
14 |
15 | {{name}}
16 |
17 |
18 |
19 | {{enable?'停用':'启用'}}
20 |
21 | 编辑
22 | 删除
23 |
24 |
25 |
26 |
27 |
28 |
83 |
--------------------------------------------------------------------------------
/src/renderer/pages/setting.vue:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
28 |
29 | 抓包列表自动滚到底部
30 |
31 |
32 |
33 |
34 |
74 |
--------------------------------------------------------------------------------
/src/renderer/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Router from 'vue-router'
3 | import network from '@/pages/network.vue'
4 | import setting from '@/pages/setting.vue'
5 | import ruleIndex from '@/pages/rule/index.vue'
6 | import ruleEdit from '@/pages/rule/rule-edit.vue'
7 | import ruleList from '@/pages/rule/rule-list.vue'
8 |
9 | Vue.use(Router)
10 |
11 | export default new Router({
12 | routes: [
13 | {
14 | path: '/',
15 | name: 'network',
16 | component: network
17 | },
18 | {
19 | path: '/network',
20 | name: 'network',
21 | component: network
22 | },
23 | {
24 | path: '/setting',
25 | name: 'setting',
26 | component: setting
27 | },
28 | {
29 | path: '/rule',
30 | name: 'rule',
31 | component: ruleIndex,
32 | children: [
33 | {
34 | path: 'edit/:id',
35 | component: ruleEdit,
36 | name: 'rule-edit'
37 | },
38 | {
39 | path: 'add',
40 | component: ruleEdit,
41 | name: 'rule-add'
42 | },
43 | {
44 | path: 'list',
45 | component: ruleList,
46 | name: 'rule-list'
47 | }
48 | ]
49 | }
50 | ]
51 | })
52 |
--------------------------------------------------------------------------------
/src/renderer/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 |
4 | import { createPersistedState } from 'vuex-electron'
5 |
6 | import modules from './modules'
7 |
8 | Vue.use(Vuex)
9 |
10 | export default new Vuex.Store({
11 | modules,
12 | plugins: [
13 | createPersistedState()
14 | ],
15 | strict: process.env.NODE_ENV !== 'production'
16 | })
17 |
--------------------------------------------------------------------------------
/src/renderer/store/modules/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * The file enables `@/store/index.js` to import all vuex modules
3 | * in a one-shot manner. There should not be any reason to edit this file.
4 | */
5 |
6 | const files = require.context('.', false, /\.js$/)
7 | const modules = {}
8 |
9 | files.keys().forEach(key => {
10 | if (key === './index.js') return
11 | modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
12 | })
13 |
14 | export default modules
15 |
--------------------------------------------------------------------------------
/src/renderer/store/modules/rule.js:
--------------------------------------------------------------------------------
1 | import ruleApi from '../../lib/rule/rule-api'
2 |
3 | const state = {
4 | proxy_rules: [] // 代理配置规则
5 | }
6 |
7 | const mutations = {
8 | MODIFY_PROXY_RULE (state, payload) {
9 | console.log('modify')
10 | state.proxy_rules.splice(payload.index, 1)
11 | state.proxy_rules.push(payload.rule)
12 | },
13 | STORE_PROXY_RULE (state, rule) {
14 | console.log('store')
15 | state.proxy_rules.push(rule)
16 | },
17 | INIT_PROXY_RULE (state) {
18 | try {
19 | state.proxy_rules = JSON.parse(ruleApi.readRulesFromFile())
20 | } catch (e) {
21 | }
22 | },
23 | SAVE_PROXY_RULE (state, { id, ruleValue }) {
24 | try {
25 | ruleApi.saveCustomRuleToFile(id, ruleValue)
26 | ruleApi.saveRulesIntoFile(state.proxy_rules)
27 | } catch (e) {
28 | }
29 | },
30 | DELETE_RULE (state, id) {
31 | ruleApi.deleteCustomRuleFile(id)
32 | state.proxy_rules = state.proxy_rules.filter((item) => {
33 | return item.id !== id
34 | })
35 | ruleApi.saveRulesIntoFile(state.proxy_rules)
36 | },
37 | TOGGLE_ENABLE_RULE (state, id) {
38 | state.proxy_rules.forEach((item) => {
39 | if (item.id === id) {
40 | item.enable = !item.enable
41 | }
42 | })
43 | ruleApi.saveRulesIntoFile(state.proxy_rules)
44 | }
45 | }
46 |
47 | const actions = {
48 | MODIFY_PROXY_RULE ({ commit }, payload) {
49 | commit('MODIFY_PROXY_RULE', payload)
50 | },
51 | STORE_PROXY_RULE ({ commit }, rule) {
52 | commit('STORE_PROXY_RULE', rule)
53 | },
54 | INIT_PROXY_RULE ({ commit }) {
55 | commit('INIT_PROXY_RULE')
56 | },
57 | SAVE_PROXY_RULE ({ commit }, { id, ruleValue }) {
58 | commit('SAVE_PROXY_RULE', { id, ruleValue })
59 | },
60 | DELETE_RULE ({ commit }, id) {
61 | commit('DELETE_RULE', id)
62 | },
63 | TOGGLE_ENABLE_RULE ({ commit }, id) {
64 | commit('TOGGLE_ENABLE_RULE', id)
65 | }
66 | }
67 |
68 | export default {
69 | state,
70 | mutations,
71 | actions
72 | }
73 |
--------------------------------------------------------------------------------
/src/renderer/store/modules/setting.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by luoyang on 2019-02-15
3 | */
4 | const state = {
5 | autoScroll: false // 自动滚动
6 | }
7 |
8 | const mutations = {
9 | TOGGLE_AUTO_SCROLL (state, bool) {
10 | state.autoScroll = bool
11 | }
12 | }
13 |
14 | const actions = {
15 | TOGGLE_AUTO_SCROLL ({ commit }, bool) {
16 | commit('TOGGLE_AUTO_SCROLL', bool)
17 | }
18 | }
19 |
20 | export default {
21 | state,
22 | mutations,
23 | actions
24 | }
25 |
--------------------------------------------------------------------------------
/static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luoyang125024608/electron-vue-anyproxy/16a4de0450d04f1e65b76e93b2d79b2a0f4a0e1b/static/.gitkeep
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_request_data.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | modify the post data towards http://httpbin.org/post
4 | test:
5 | curl -H "Content-Type: text/plain" -X POST -d 'original post data' http://httpbin.org/post --proxy http://127.0.0.1:8001
6 | expected response:
7 | { "data": "i-am-anyproxy-modified-post-data" }
8 | */
9 | module.exports = {
10 | summary: 'Rule to modify request data',
11 | *beforeSendRequest(requestDetail) {
12 | if (requestDetail.url.indexOf('http://httpbin.org/post') === 0) {
13 | return {
14 | requestData: 'i-am-anyproxy-modified-post-data'
15 | };
16 | }
17 | },
18 | };
19 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_request_header.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | modify the user-agent in requests toward httpbin.org
4 | test:
5 | curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
6 | */
7 | module.exports = {
8 | *beforeSendRequest(requestDetail) {
9 | if (requestDetail.url.indexOf('http://httpbin.org') === 0) {
10 | const newRequestOptions = requestDetail.requestOptions;
11 | newRequestOptions.headers['User-Agent'] = 'AnyProxy/0.0.0';
12 | return {
13 | requestOptions: newRequestOptions
14 | };
15 | }
16 | },
17 | };
18 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_request_path.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | redirect all https://httpbin.org/user-agent requests to http://localhost:8008/index.html
4 | test:
5 | curl https://httpbin.org/user-agent --proxy http://127.0.0.1:8001
6 | expected response:
7 | 'hello world' from 127.0.0.1:8001/index.html
8 | */
9 | module.exports = {
10 | *beforeSendRequest(requestDetail) {
11 | if (requestDetail.url.indexOf('https://httpbin.org/user-agent') === 0) {
12 | const newRequestOptions = requestDetail.requestOptions;
13 | requestDetail.protocol = 'http';
14 | newRequestOptions.hostname = '127.0.0.1'
15 | newRequestOptions.port = '8008';
16 | newRequestOptions.path = '/index.html';
17 | newRequestOptions.method = 'GET';
18 | return requestDetail;
19 | }
20 | },
21 | // *beforeDealHttpsRequest(requestDetail) {
22 | // return true;
23 | // }
24 | };
25 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_request_protocol.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | redirect all http requests of httpbin.org to https
4 | test:
5 | curl 'http://httpbin.org/get?show_env=1' --proxy http://127.0.0.1:8001
6 | expected response:
7 | { "X-Forwarded-Protocol": "https" }
8 | */
9 | module.exports = {
10 | *beforeSendRequest(requestDetail) {
11 | if (requestDetail.url.indexOf('http://httpbin.org') === 0) {
12 | const newOption = requestDetail.requestOptions;
13 | newOption.port = 443;
14 | return {
15 | protocol: 'https',
16 | requestOptions: newOption
17 | };
18 | }
19 | }
20 | };
21 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_response_data.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | modify response data of http://httpbin.org/user-agent
4 | test:
5 | curl 'http://httpbin.org/user-agent' --proxy http://127.0.0.1:8001
6 | expected response:
7 | { "user-agent": "curl/7.43.0" } -- AnyProxy Hacked! --
8 | */
9 |
10 | module.exports = {
11 | *beforeSendResponse(requestDetail, responseDetail) {
12 | if (requestDetail.url === 'http://httpbin.org/user-agent') {
13 | const newResponse = responseDetail.response;
14 | newResponse.body += '-- AnyProxy Hacked! --';
15 | return new Promise((resolve, reject) => {
16 | setTimeout(() => { // delay the response for 5s
17 | resolve({ response: newResponse });
18 | }, 5000);
19 | });
20 | }
21 | },
22 | };
23 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_response_header.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | modify response header of http://httpbin.org/user-agent
4 | test:
5 | curl -I 'http://httpbin.org/user-agent' --proxy http://127.0.0.1:8001
6 | expected response:
7 | X-Proxy-By: AnyProxy
8 | */
9 | module.exports = {
10 | *beforeSendResponse(requestDetail, responseDetail) {
11 | if (requestDetail.url.indexOf('http://httpbin.org/user-agent') === 0) {
12 | const newResponse = responseDetail.response;
13 | newResponse.header['X-Proxy-By'] = 'AnyProxy';
14 | return {
15 | response: newResponse
16 | };
17 | }
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_modify_response_statuscode.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | modify all status code of http://httpbin.org/ to 404
4 | test:
5 | curl -I 'http://httpbin.org/user-agent' --proxy http://127.0.0.1:8001
6 | expected response:
7 | HTTP/1.1 404 Not Found
8 | */
9 | module.exports = {
10 | *beforeSendResponse(requestDetail, responseDetail) {
11 | if (requestDetail.url.indexOf('http://httpbin.org') === 0) {
12 | const newResponse = responseDetail.response;
13 | newResponse.statusCode = 404;
14 | return {
15 | response: newResponse
16 | };
17 | }
18 | }
19 | };
20 |
--------------------------------------------------------------------------------
/static/rule_sample/sample_use_local_response.js:
--------------------------------------------------------------------------------
1 | /*
2 | sample:
3 | intercept all requests toward httpbin.org, use a local response
4 | test:
5 | curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001
6 | */
7 | module.exports = {
8 | *beforeSendRequest(requestDetail) {
9 | const localResponse = {
10 | statusCode: 200,
11 | header: { 'Content-Type': 'application/json' },
12 | body: '{"hello": "this is local response"}'
13 | };
14 | if (requestDetail.url.indexOf('http://httpbin.org') === 0) {
15 | return {
16 | response: localResponse
17 | };
18 | }
19 | },
20 | };
21 |
--------------------------------------------------------------------------------