feat: over wall 初步
parent
78116101a0
commit
315bb7ef5a
|
@ -169,11 +169,10 @@ const intercepts = {
|
||||||

|

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

|

|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,99 +31,110 @@ 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
|
||||||
const conf = config.get()
|
async function startup ({ mitmproxyPath }) {
|
||||||
if (conf.server.enabled) {
|
const conf = config.get()
|
||||||
try {
|
if (conf.server.enabled) {
|
||||||
await server.start({ mitmproxyPath })
|
try {
|
||||||
} catch (err) {
|
await server.start({ mitmproxyPath })
|
||||||
log.error('代理服务启动失败:', err)
|
} catch (err) {
|
||||||
}
|
log.error('代理服务启动失败:', err)
|
||||||
}
|
}
|
||||||
if (conf.proxy.enabled) {
|
}
|
||||||
try {
|
if (conf.proxy.enabled) {
|
||||||
await proxy.start()
|
try {
|
||||||
} catch (err) {
|
await proxy.start()
|
||||||
log.error('开启系统代理失败:', err)
|
} catch (err) {
|
||||||
}
|
log.error('开启系统代理失败:', err)
|
||||||
}
|
}
|
||||||
try {
|
}
|
||||||
const plugins = []
|
try {
|
||||||
for (const key in plugin) {
|
const plugins = []
|
||||||
if (conf.plugin[key].enabled) {
|
for (const key in plugin) {
|
||||||
const start = async () => {
|
if (conf.plugin[key].enabled) {
|
||||||
try {
|
const start = async () => {
|
||||||
await plugin[key].start()
|
try {
|
||||||
log.info(`插件【${key}】已启动`)
|
await plugin[key].start()
|
||||||
} catch (err) {
|
log.info(`插件【${key}】已启动`)
|
||||||
log.error(`插件【${key}】启动失败`, err)
|
} catch (err) {
|
||||||
}
|
log.error(`插件【${key}】启动失败`, err)
|
||||||
}
|
|
||||||
plugins.push(start())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugins && plugins.length > 0) {
|
plugins.push(start())
|
||||||
await Promise.all(plugins)
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
log.error('开启插件失败:', err)
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
shutdown: async () => {
|
if (plugins && plugins.length > 0) {
|
||||||
try {
|
await Promise.all(plugins)
|
||||||
const plugins = []
|
}
|
||||||
for (const key in plugin) {
|
} catch (err) {
|
||||||
if (status.plugin[key].enabled && plugin[key].close) {
|
log.error('开启插件失败:', err)
|
||||||
const close = async () => {
|
|
||||||
try {
|
|
||||||
await plugin[key].close()
|
|
||||||
log.info(`插件【${key}】已关闭`)
|
|
||||||
} catch (err) {
|
|
||||||
log.info(`插件【${key}】关闭失败`, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plugins.push(close())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (plugins.length > 0) {
|
|
||||||
await Promise.all(plugins)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log.error('插件关闭失败'.error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status.proxy.enabled) {
|
|
||||||
try {
|
|
||||||
await proxy.close()
|
|
||||||
log.info('系统代理已关闭')
|
|
||||||
} catch (err) {
|
|
||||||
log.error('系统代理关闭失败', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (status.server.enabled) {
|
|
||||||
try {
|
|
||||||
await server.close()
|
|
||||||
log.info('代理服务已关闭')
|
|
||||||
} catch (err) {
|
|
||||||
log.error('代理服务关闭失败', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
status: {
|
|
||||||
get () {
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
},
|
|
||||||
config,
|
|
||||||
event,
|
|
||||||
shell,
|
|
||||||
server,
|
|
||||||
proxy,
|
|
||||||
plugin,
|
|
||||||
log
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function shutdown () {
|
||||||
|
try {
|
||||||
|
const plugins = []
|
||||||
|
for (const key in plugin) {
|
||||||
|
if (status.plugin[key].enabled && plugin[key].close) {
|
||||||
|
const close = async () => {
|
||||||
|
try {
|
||||||
|
await plugin[key].close()
|
||||||
|
log.info(`插件【${key}】已关闭`)
|
||||||
|
} catch (err) {
|
||||||
|
log.info(`插件【${key}】关闭失败`, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugins.push(close())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plugins.length > 0) {
|
||||||
|
await Promise.all(plugins)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log.error('插件关闭失败'.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.proxy.enabled) {
|
||||||
|
try {
|
||||||
|
await proxy.close()
|
||||||
|
log.info('系统代理已关闭')
|
||||||
|
} catch (err) {
|
||||||
|
log.error('系统代理关闭失败', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status.server.enabled) {
|
||||||
|
try {
|
||||||
|
await server.close()
|
||||||
|
log.info('代理服务已关闭')
|
||||||
|
} catch (err) {
|
||||||
|
log.error('代理服务关闭失败', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const api = {
|
||||||
|
startup,
|
||||||
|
shutdown,
|
||||||
|
status: {
|
||||||
|
get () {
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
},
|
||||||
|
config,
|
||||||
|
event,
|
||||||
|
shell,
|
||||||
|
server,
|
||||||
|
proxy,
|
||||||
|
plugin,
|
||||||
|
log
|
||||||
|
}
|
||||||
|
module.exports = {
|
||||||
|
status,
|
||||||
|
api
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const node = require('./node')
|
const node = require('./node')
|
||||||
|
const overwall = require('./overwall')
|
||||||
module.exports = {
|
module.exports = {
|
||||||
node
|
node, overwall
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/',
|
||||||
|
|
|
@ -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'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
@ -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'
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue