Browse Source

feat: over wall 初步

pull/67/head
xiaojunnuo 4 years ago
parent
commit
315bb7ef5a
  1. 5
      README.md
  2. 13
      packages/core/src/config/index.js
  3. 26
      packages/core/src/expose.js
  4. 3
      packages/core/src/modules/plugin/index.js
  5. 6
      packages/core/src/modules/plugin/node/config.js
  6. 19
      packages/core/src/modules/plugin/overwall/config.js
  7. 60
      packages/core/src/modules/plugin/overwall/index.js
  8. 8023
      packages/core/src/modules/plugin/overwall/pac
  9. 12
      packages/core/src/modules/server/index.js
  10. 0
      packages/mitmproxy/src/lib/interceptor/impl/overwall.js
  11. 2
      packages/mitmproxy/src/lib/interceptor/impl/proxy.js
  12. 5
      packages/mitmproxy/src/options.js

5
README.md

@ -169,11 +169,10 @@ const intercepts = {
![](./doc/proxy.png)
#### 2. 360软件会严重拖慢设置代理命令的执行时间
如果开启了360,那么软件开启windows代理的时间会特别长,需要耐心等待。
#### 2. 尝试将代理设置关闭再重新打开
#### 3.如果还是不行,请在下方加作者好友,将服务日志发送给作者进行分析
日志打开方式:加速服务->右边日志按钮->另存为
日志打开方式:加速服务->右边日志按钮->打开日志文件夹
![](./doc/log.png)

13
packages/core/src/config/index.js

@ -121,13 +121,12 @@ module.exports = {
redirect: 'npm.taobao.org/mirrors'
}
},
'registry-1.docker.io': { '.*': { proxy: 'docker.mirrors.ustc.edu.cn' } },
'packages.elastic.co': { '.*': { proxy: 'elastic.proxy.ustclug.org' } },
'ppa.launchpad.net': { '.*': { proxy: 'launchpad.proxy.ustclug.org' } },
'archive.cloudera.com': { '.*': { regexp: '/cdh5/.*', proxy: 'cloudera.proxy.ustclug.org' } },
'downloads.lede-project.org': { '.*': { proxy: 'lede.proxy.ustclug.org' } },
'downloads.openwrt.org': { '.*': { proxy: 'openwrt.proxy.ustclug.org' } },
'secure.gravatar.com': { '.*': { proxy: 'gravatar.proxy.ustclug.org' } },
// 'packages.elastic.co': { '.*': { proxy: 'elastic.proxy.ustclug.org' } },
// 'ppa.launchpad.net': { '.*': { proxy: 'launchpad.proxy.ustclug.org' } },
// 'archive.cloudera.com': { '.*': { regexp: '/cdh5/.*', proxy: 'cloudera.proxy.ustclug.org' } },
// 'downloads.lede-project.org': { '.*': { proxy: 'lede.proxy.ustclug.org' } },
// 'downloads.openwrt.org': { '.*': { proxy: 'openwrt.proxy.ustclug.org' } },
// 'secure.gravatar.com': { '.*': { proxy: 'gravatar.proxy.ustclug.org' } },
'*.carbonads.com': {
'/carbon.*': {
abort: true,

26
packages/core/src/expose.js

@ -23,7 +23,6 @@ function setupPlugin (key, plugin, context, config) {
return api
}
const server = modules.server
const proxy = setupPlugin('proxy', modules.proxy, context, config)
const plugin = {}
for (const key in modules.plugin) {
@ -32,11 +31,14 @@ for (const key in modules.plugin) {
plugin[key] = api
}
config.resetDefault()
const server = modules.server
const serverStart = server.start
module.exports = {
status,
api: {
startup: async ({ mitmproxyPath }) => {
const newServerStart = ({ mitmproxyPath }) => {
return serverStart({ mitmproxyPath, plugins: plugin })
}
server.start = newServerStart
async function startup ({ mitmproxyPath }) {
const conf = config.get()
if (conf.server.enabled) {
try {
@ -73,8 +75,9 @@ module.exports = {
} catch (err) {
log.error('开启插件失败:', err)
}
},
shutdown: async () => {
}
async function shutdown () {
try {
const plugins = []
for (const key in plugin) {
@ -113,7 +116,11 @@ module.exports = {
log.error('代理服务关闭失败', err)
}
}
},
}
const api = {
startup,
shutdown,
status: {
get () {
return status
@ -127,4 +134,7 @@ module.exports = {
plugin,
log
}
module.exports = {
status,
api
}

3
packages/core/src/modules/plugin/index.js

@ -1,4 +1,5 @@
const node = require('./node')
const overwall = require('./overwall')
module.exports = {
node
node, overwall
}

6
packages/core/src/modules/plugin/node/config.js

@ -11,9 +11,9 @@ module.exports = {
NODE_TLS_REJECT_UNAUTHORIZED: false,
registry: 'https://registry.npmjs.org'// 可以选择切换官方或者淘宝镜像
},
intercepts: {
'cdn.cypress.io': [{ regexp: '/desktop/.*', proxy: 'http://npm.taobao.org/mirrors/cypress/' }]
},
// intercepts: {
// 'cdn.cypress.io': [{ regexp: '/desktop/.*', proxy: 'http://npm.taobao.org/mirrors/cypress/' }]
// },
variables: {
SASS_BINARY_SITE: 'https://npm.taobao.org/mirrors/node-sass/',
PHANTOMJS_CDNURL: 'https://npm.taobao.org/mirrors/phantomjs/',

19
packages/core/src/modules/plugin/overwall/config.js

@ -0,0 +1,19 @@
module.exports = {
name: 'OverWall',
enabled: true,
server: {
'ow.docmirror.top/_go_over_wall_': true
},
targets: {
'*facebook.com': true,
'*.fbcdn.net': true,
'*twitter.com': true,
'*youtube.com': true
},
pac: {
enabled: true,
update: [
'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt'
]
}
}

60
packages/core/src/modules/plugin/overwall/index.js

@ -0,0 +1,60 @@
const pluginConfig = require('./config')
const Plugin = function (context) {
const { config, shell, event, log } = context
const api = {
async start () {
event.fire('status', { key: 'plugin.overwall.enabled', value: true })
},
async close () {
event.fire('status', { key: 'plugin.overwall.enabled', value: false })
},
async restart () {
await api.close()
await api.start()
},
async overrideRunningConfig (serverConfig) {
const conf = config.get().plugin.overwall
if (!conf?.enabled) {
return
}
if (!conf.targets) {
return
}
const server = conf.server
let i = 0
let main
const backup = []
for (const key in server) {
if (i === 0) {
main = key
} else {
backup.push(key)
}
i++
}
for (const key in conf.targets) {
serverConfig.intercepts[key] = {
'.*': {
// eslint-disable-next-line no-template-curly-in-string
proxy: main + '/${host}',
backup
}
}
}
}
}
return api
}
module.exports = {
key: 'overwall',
config: pluginConfig,
status: {
enabled: false
},
plugin: Plugin
}

8023
packages/core/src/modules/plugin/overwall/pac

File diff suppressed because it is too large Load Diff

12
packages/core/src/modules/server/index.js

@ -27,7 +27,7 @@ const serverApi = {
return this.close()
}
},
async start ({ mitmproxyPath }) {
async start ({ mitmproxyPath, plugins }) {
const allConfig = config.get()
const serverConfig = lodash.cloneDeep(allConfig.server)
@ -37,6 +37,9 @@ const serverApi = {
if (allConfig.plugin) {
lodash.each(allConfig.plugin, (value) => {
const plugin = value
if (!plugin.enabled) {
return
}
if (plugin.intercepts) {
lodash.merge(intercepts, plugin.intercepts)
}
@ -45,6 +48,13 @@ const serverApi = {
}
})
}
log.error('plugins', plugins)
for (const key in plugins) {
const plugin = plugins[key]
if (plugin.overrideRunningConfig) {
plugin.overrideRunningConfig(serverConfig)
}
}
// fireStatus('ing') // 启动中
const basePath = serverConfig.setting.userBasePath
const runningConfig = basePath + '/running.json'

0
packages/mitmproxy/src/lib/interceptor/impl/overwall.js

2
packages/mitmproxy/src/lib/interceptor/impl/proxy.js

@ -36,6 +36,8 @@ module.exports = {
const regexp = new RegExp(interceptOpt.replace)
proxyTarget = req.url.replace(regexp, proxyConf)
}
// eslint-disable-next-line no-template-curly-in-string
proxyTarget = proxyTarget.replace('${host}', rOptions.hostname)
// const backup = interceptOpt.backup
const proxy = proxyTarget.indexOf('http') === 0 ? proxyTarget : rOptions.protocol + '//' + proxyTarget
// eslint-disable-next-line node/no-deprecated-api

5
packages/mitmproxy/src/options.js

@ -63,7 +63,10 @@ module.exports = (config) => {
log.info('白名单域名,不拦截', hostname)
return false
}
return !!matchHostname(intercepts, hostname) // 配置了拦截的域名,将会被代理
const ret = !!matchHostname(intercepts, hostname) // 配置了拦截的域名,将会被代理
if (ret) {
return true
}
},
createIntercepts: (context) => {
const rOptions = context.rOptions

Loading…
Cancel
Save