diff --git a/packages/core/src/modules/plugin/overwall/config.js b/packages/core/src/modules/plugin/overwall/config.js index d26d970..9a68a15 100644 --- a/packages/core/src/modules/plugin/overwall/config.js +++ b/packages/core/src/modules/plugin/overwall/config.js @@ -2,7 +2,12 @@ module.exports = { name: '梯子', enabled: false, server: { - 'ow.docmirror.top/_go_over_wall_': true + }, + serverDefault: { + 'ow-prod.docmirror.top': { + path: 'X2dvX292ZXJfd2FsbF8', + password: 'dev_sidecar_is_666' + } }, targets: { '*facebook.com': true diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js index 04f458a..9ff6092 100644 --- a/packages/gui/src/bridge/api/backend.js +++ b/packages/gui/src/bridge/api/backend.js @@ -41,20 +41,23 @@ const localApi = { setting: { load () { const settingPath = _getSettingsPath() - if (!fs.existsSync(settingPath)) { - this.save({}) + let setting = {} + if (fs.existsSync(settingPath)) { + const file = fs.readFileSync(settingPath) + setting = JSON5.parse(file.toString()) + if (setting == null) { + setting = {} + } } - const file = fs.readFileSync(settingPath) - const setting = JSON5.parse(file.toString()) - if (setting && setting.installTime == null) { - setting.installTime = new Date().getTime() - this.save(setting) - } - if (setting && setting.overwall == null) { + if (setting.overwall == null) { setting.overwall = true - this.save(setting) } - return setting || {} + + if (setting.installTime == null) { + setting.installTime = new Date().getTime() + localApi.setting.save(setting) + } + return setting }, save (setting = {}) { const settingPath = _getSettingsPath() diff --git a/packages/gui/src/view/pages/plugin/overwall.vue b/packages/gui/src/view/pages/plugin/overwall.vue index 1ad3ff2..7c15d9c 100644 --- a/packages/gui/src/view/pages/plugin/overwall.vue +++ b/packages/gui/src/view/pages/plugin/overwall.vue @@ -24,18 +24,18 @@
- + PAC没有拦截到的域名,可以在此处定义 - + - + - + @@ -44,22 +44,28 @@
- + Nginx二层代理服务端配置 - + - - + + + + + + + + - + - +
您可以在此处配置你自己的服务器地址
@@ -144,12 +150,15 @@ export default { key, value }) } + if (this.servers.length === 0) { + this.addServer() + } }, deleteServer (item, index) { this.servers.splice(index, 1) }, addServer () { - this.servers.unshift({ key: '', value: true }) + this.servers.unshift({ key: '', value: { type: 'path' } }) }, saveServer () { const map = {} diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js index 051e93a..c696684 100644 --- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js +++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js @@ -15,10 +15,18 @@ function matched (hostname, regexpMap) { } module.exports = function createOverWallIntercept (overWallConfig) { - if (!overWallConfig || overWallConfig.enabled !== true || !overWallConfig.server || Object.keys(overWallConfig.server).length === 0) { + if (!overWallConfig || overWallConfig.enabled !== true) { + return null + } + let server = overWallConfig.server + let keys = Object.keys(server) + if (keys.length === 0) { + server = overWallConfig.serverDefault + keys = Object.keys(server) + } + if (keys.length === 0) { return null } - const keys = Object.keys(overWallConfig.server) const regexpMap = matchUtil.domainMapRegexply(overWallConfig.intercepts) return { sslConnectInterceptor: (req, cltSocket, head) => { @@ -34,10 +42,10 @@ module.exports = function createOverWallIntercept (overWallConfig) { if (!matched(hostname, regexpMap)) { return } - const key = '__over_wall_proxy__' + const cacheKey = '__over_wall_proxy__' let proxyServer = keys[0] if (RequestCounter && keys.length > 1) { - const count = RequestCounter.getOrCreate(key, keys) + const count = RequestCounter.getOrCreate(cacheKey, keys) if (count.value == null) { count.doRank() } @@ -47,23 +55,29 @@ module.exports = function createOverWallIntercept (overWallConfig) { count.doCount(count.value) proxyServer = count.value context.requestCount = { - key, + key: cacheKey, value: count.value, count } } } - const proxyTarget = proxyServer + '/' + hostname + req.url + const domain = proxyServer + const path = server[domain].path + const password = server[domain].password + const proxyTarget = domain + '/' + path + '/' + hostname + req.url // 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 const URL = url.parse(proxy) rOptions.protocol = URL.protocol rOptions.hostname = URL.host rOptions.host = URL.host rOptions.headers.host = URL.host + if (password) { + rOptions.headers.dspassword = password + } rOptions.path = URL.path if (URL.port == null) { rOptions.port = rOptions.protocol === 'https:' ? 443 : 80 diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js index a0e1162..9555832 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js @@ -47,7 +47,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e reqIncpts.unshift(InsertScriptMiddleware) } for (const middleware of middlewares) { - reqIncpts.unshift(middleware) + reqIncpts.push(middleware) } if (reqIncpts && reqIncpts.length > 0) { for (const reqIncpt of reqIncpts) {