feat: over wall 初步

pull/67/head
xiaojunnuo 2020-12-01 00:19:24 +08:00
parent 78116101a0
commit 315bb7ef5a
12 changed files with 8233 additions and 107 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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'
]
}
}

View File

@ -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
}

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@ const serverApi = {
return this.close() return this.close()
} }
}, },
async start ({ mitmproxyPath }) { async start ({ mitmproxyPath, plugins }) {
const allConfig = config.get() const allConfig = config.get()
const serverConfig = lodash.cloneDeep(allConfig.server) const serverConfig = lodash.cloneDeep(allConfig.server)
@ -37,6 +37,9 @@ const serverApi = {
if (allConfig.plugin) { if (allConfig.plugin) {
lodash.each(allConfig.plugin, (value) => { lodash.each(allConfig.plugin, (value) => {
const plugin = value const plugin = value
if (!plugin.enabled) {
return
}
if (plugin.intercepts) { if (plugin.intercepts) {
lodash.merge(intercepts, 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') // 启动中 // fireStatus('ing') // 启动中
const basePath = serverConfig.setting.userBasePath const basePath = serverConfig.setting.userBasePath
const runningConfig = basePath + '/running.json' const runningConfig = basePath + '/running.json'

View File

@ -36,6 +36,8 @@ module.exports = {
const regexp = new RegExp(interceptOpt.replace) const regexp = new RegExp(interceptOpt.replace)
proxyTarget = req.url.replace(regexp, proxyConf) 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 backup = interceptOpt.backup
const proxy = proxyTarget.indexOf('http') === 0 ? proxyTarget : rOptions.protocol + '//' + proxyTarget const proxy = proxyTarget.indexOf('http') === 0 ? proxyTarget : rOptions.protocol + '//' + proxyTarget
// eslint-disable-next-line node/no-deprecated-api // eslint-disable-next-line node/no-deprecated-api

View File

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