feat: 你懂的

pull/67/head
xiaojunnuo 2020-12-02 12:21:49 +08:00
parent 315bb7ef5a
commit 5fd89d66f6
26 changed files with 24747 additions and 90 deletions

3
packages/core/.babelrc Normal file
View File

@ -0,0 +1,3 @@
{
"presets": ["es2020","stage-4"]
}

View File

@ -18,6 +18,7 @@
"dependencies": {
"@docmirror/mitmproxy": "^1.2.2",
"agentkeepalive": "^2.1.1",
"babel-preset-es2020": "^1.0.2",
"charset": "^1.0.0",
"child_process": "^1.0.2",
"colors": "^1.1.2",

View File

@ -78,11 +78,11 @@ module.exports = {
},
// google cdn
'www.google.com': {
'/recaptcha/.*': { proxy: 'www.recaptcha.net' },
'.*': {
proxy: 'gg.docmirror.top/_yxorp',
desc: '呀,被你发现了,偷偷的用,别声张'
}
'/recaptcha/.*': { proxy: 'www.recaptcha.net' }
// '.*': {
// proxy: 'gg.docmirror.top/_yxorp',
// desc: '呀,被你发现了,偷偷的用,别声张'
// }
},
'ajax.googleapis.com': {
'.*': {

View File

@ -19,7 +19,10 @@ function setupPlugin (key, plugin, context, config) {
const pluginStatus = plugin.status
const api = PluginClass(context)
config.addDefault(key, pluginConfig)
lodash.set(status, key, pluginStatus)
if (pluginStatus) {
lodash.set(status, key, pluginStatus)
}
return api
}

View File

@ -1,13 +1,14 @@
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 })
// event.fire('status', { key: 'plugin.overwall.enabled', value: true })
},
async close () {
event.fire('status', { key: 'plugin.overwall.enabled', value: false })
// event.fire('status', { key: 'plugin.overwall.enabled', value: false })
},
async restart () {
@ -15,12 +16,9 @@ const Plugin = function (context) {
await api.start()
},
async overrideRunningConfig (serverConfig) {
async overrideRunningConfig_bak (serverConfig) {
const conf = config.get().plugin.overwall
if (!conf?.enabled) {
return
}
if (!conf.targets) {
if (!conf || !conf.enabled || !conf.targets) {
return
}
const server = conf.server
@ -53,8 +51,5 @@ const Plugin = function (context) {
module.exports = {
key: 'overwall',
config: pluginConfig,
status: {
enabled: false
},
plugin: Plugin
}

File diff suppressed because it is too large Load Diff

View File

@ -48,13 +48,14 @@ const serverApi = {
}
})
}
log.error('plugins', plugins)
for (const key in plugins) {
const plugin = plugins[key]
if (plugin.overrideRunningConfig) {
plugin.overrideRunningConfig(serverConfig)
}
}
serverConfig.plugin = allConfig.plugin
// fireStatus('ing') // 启动中
const basePath = serverConfig.setting.userBasePath
const runningConfig = basePath + '/running.json'

View File

@ -1,6 +1,10 @@
// eslint-disable-next-line no-unused-vars
const server = require('@docmirror/mitmproxy')
const configPath = process.argv[2]
let configPath = 'C:/Users/Administrator/.dev-sidecar/running.json'
if (process.argv && process.argv.length > 3) {
configPath = process.argv[2]
}
const fs = require('fs')
const path = require('path')
const configJson = fs.readFileSync(configPath)

2
packages/core/start2.js Normal file
View File

@ -0,0 +1,2 @@
// eslint-disable-next-line no-unused-vars
const mitmproxy = require('./start/mitmproxy.js')

View File

@ -93,10 +93,10 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@docmirror/mitmproxy@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e"
integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg==
"@docmirror/mitmproxy@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.2.tgz#a4d0020e073eaa68adb7902b5634ab2a1a3bc058"
integrity sha512-xW1xyqUfpGAZZTzqSjoQM0Mmq8VVEyvS8AiTUBvgpxUAYG2sqNCacLETwYfNBP1MStUBtGXKklcISpIY6+R+DA==
dependencies:
agentkeepalive "^2.1.1"
child_process "^1.0.2"
@ -442,6 +442,11 @@ ansi-escapes@^4.2.1:
dependencies:
type-fest "^0.11.0"
ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8=
ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.npm.taobao.org/ansi-regex/download/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
@ -452,6 +457,11 @@ ansi-regex@^5.0.0:
resolved "https://registry.npm.taobao.org/ansi-regex/download/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
integrity sha1-OIU59VF5vzkznIGvMKZU1p+Hy3U=
ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=
ansi-styles@^3.2.0, ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.npm.taobao.org/ansi-styles/download/ansi-styles-3.2.1.tgz?cache=0&sync_timestamp=1601839122515&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fansi-styles%2Fdownload%2Fansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
@ -625,6 +635,15 @@ aws4@^1.8.0:
resolved "https://registry.npm.taobao.org/aws4/download/aws4-1.10.1.tgz?cache=0&sync_timestamp=1597236947743&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Faws4%2Fdownload%2Faws4-1.10.1.tgz#e1e82e4f3e999e2cfd61b161280d16a111f86428"
integrity sha1-4eguTz6Zniz9YbFhKA0WoRH4ZCg=
babel-code-frame@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
integrity sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=
dependencies:
chalk "^1.1.3"
esutils "^2.0.2"
js-tokens "^3.0.2"
babel-eslint@^10.1.0:
version "10.1.0"
resolved "https://registry.npm.taobao.org/babel-eslint/download/babel-eslint-10.1.0.tgz?cache=0&sync_timestamp=1599054223324&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-eslint%2Fdownload%2Fbabel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
@ -637,6 +656,104 @@ babel-eslint@^10.1.0:
eslint-visitor-keys "^1.0.0"
resolve "^1.12.0"
babel-messages@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
integrity sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=
dependencies:
babel-runtime "^6.22.0"
babel-plugin-check-es2015-constants@^6.8.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a"
integrity sha1-NRV7EBQm/S/9PaP3XH0ekYNbv4o=
dependencies:
babel-runtime "^6.22.0"
babel-plugin-transform-es2015-arrow-functions@^6.8.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221"
integrity sha1-RSaSy3EdX3ncf4XkQM5BufJE0iE=
dependencies:
babel-runtime "^6.22.0"
babel-plugin-transform-es2015-block-scoping@^6.9.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f"
integrity sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=
dependencies:
babel-runtime "^6.26.0"
babel-template "^6.26.0"
babel-traverse "^6.26.0"
babel-types "^6.26.0"
lodash "^4.17.4"
babel-plugin-transform-es2015-template-literals@^6.8.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d"
integrity sha1-qEs0UPfp+PH2g51taH2oS7EjbY0=
dependencies:
babel-runtime "^6.22.0"
babel-preset-es2020@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/babel-preset-es2020/-/babel-preset-es2020-1.0.2.tgz#489272ca9c8b1fca59b2cfc4b2a2fab02eedeb79"
integrity sha1-SJJyypyLH8pZss/EsqL6sC7t63k=
dependencies:
babel-plugin-check-es2015-constants "^6.8.0"
babel-plugin-transform-es2015-arrow-functions "^6.8.0"
babel-plugin-transform-es2015-block-scoping "^6.9.0"
babel-plugin-transform-es2015-template-literals "^6.8.0"
babel-runtime@^6.22.0, babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4=
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.11.0"
babel-template@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02"
integrity sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=
dependencies:
babel-runtime "^6.26.0"
babel-traverse "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
lodash "^4.17.4"
babel-traverse@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=
dependencies:
babel-code-frame "^6.26.0"
babel-messages "^6.23.0"
babel-runtime "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
debug "^2.6.8"
globals "^9.18.0"
invariant "^2.2.2"
lodash "^4.17.4"
babel-types@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
integrity sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=
dependencies:
babel-runtime "^6.26.0"
esutils "^2.0.2"
lodash "^4.17.4"
to-fast-properties "^1.0.3"
babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"
integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@ -883,6 +1000,17 @@ caseless@~0.12.0:
resolved "https://registry.npm.taobao.org/caseless/download/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
integrity sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=
dependencies:
ansi-styles "^2.2.1"
escape-string-regexp "^1.0.2"
has-ansi "^2.0.0"
strip-ansi "^3.0.0"
supports-color "^2.0.0"
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.npm.taobao.org/chalk/download/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@ -1119,6 +1247,11 @@ copy-descriptor@^0.1.0:
resolved "https://registry.npm.taobao.org/copy-descriptor/download/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
core-js@^2.4.0:
version "2.6.12"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.12.tgz#d9333dfa7b065e347cc5682219d6f690859cc2ec"
integrity sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==
core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -1227,7 +1360,7 @@ date-format@^3.0.0:
resolved "https://registry.yarnpkg.com/date-format/-/date-format-3.0.0.tgz#eb8780365c7d2b1511078fb491e6479780f3ad95"
integrity sha512-eyTcpKOcamdhWJXj56DpQMo1ylSQpcGtGKXcU0Tb97+K56/CF5amAqqqNj0+KvA0iw2ynxtHWFsPDSClCxe48w==
debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
@ -1538,7 +1671,7 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"
escape-string-regexp@^1.0.5:
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
@ -2169,6 +2302,11 @@ globals@^12.1.0:
dependencies:
type-fest "^0.8.1"
globals@^9.18.0:
version "9.18.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==
globby@^9.2.0:
version "9.2.0"
resolved "https://registry.npm.taobao.org/globby/download/globby-9.2.0.tgz?cache=0&sync_timestamp=1591083812416&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglobby%2Fdownload%2Fglobby-9.2.0.tgz#fd029a706c703d29bdd170f4b6db3a3f7a7cb63d"
@ -2201,6 +2339,13 @@ har-validator@~5.1.3:
ajv "^6.12.3"
har-schema "^2.0.0"
has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
integrity sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=
dependencies:
ansi-regex "^2.0.0"
has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.npm.taobao.org/has-flag/download/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
@ -2396,6 +2541,13 @@ interpret@^1.2.0:
resolved "https://registry.npm.taobao.org/interpret/download/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha1-Zlq4vE2iendKQFhOgS4+D6RbGh4=
invariant@^2.2.2:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"
ip@^1.1.5:
version "1.1.5"
resolved "https://registry.npm.taobao.org/ip/download/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a"
@ -2656,11 +2808,16 @@ js-queue@2.0.0:
dependencies:
easy-stack "^1.0.0"
js-tokens@^4.0.0:
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls=
js-yaml@^3.13.1:
version "3.14.0"
resolved "https://registry.npm.taobao.org/js-yaml/download/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
@ -2838,7 +2995,7 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.7.0:
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.7.0:
version "4.17.20"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
@ -2861,6 +3018,13 @@ log4js@^6.3.0:
rfdc "^1.1.4"
streamroller "^2.2.4"
loose-envify@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
lru-cache@^4.0.1, lru-cache@^4.1.2:
version "4.1.5"
resolved "https://registry.npm.taobao.org/lru-cache/download/lru-cache-4.1.5.tgz?cache=0&sync_timestamp=1594427582110&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flru-cache%2Fdownload%2Flru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
@ -3755,6 +3919,11 @@ readdirp@~3.5.0:
dependencies:
picomatch "^2.2.1"
regenerator-runtime@^0.11.0:
version "0.11.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==
regex-not@^1.0.0, regex-not@^1.0.2:
version "1.0.2"
resolved "https://registry.npm.taobao.org/regex-not/download/regex-not-1.0.2.tgz#1f4ece27e00b0b65e0247a6810e6a85d83a5752c"
@ -4245,6 +4414,13 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"
strip-ansi@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
integrity sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=
dependencies:
ansi-regex "^2.0.0"
strip-ansi@^5.1.0, strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.npm.taobao.org/strip-ansi/download/strip-ansi-5.2.0.tgz?cache=0&sync_timestamp=1589682795383&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fstrip-ansi%2Fdownload%2Fstrip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
@ -4279,6 +4455,11 @@ strip-json-comments@^3.0.1:
resolved "https://registry.npm.taobao.org/strip-json-comments/download/strip-json-comments-3.1.1.tgz?cache=0&sync_timestamp=1594567532500&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fstrip-json-comments%2Fdownload%2Fstrip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha1-MfEoGzgyYwQ0gxwxDAHMzajL4AY=
supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=
supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.npm.taobao.org/supports-color/download/supports-color-5.5.0.tgz?cache=0&sync_timestamp=1598611709087&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
@ -4374,6 +4555,11 @@ to-arraybuffer@^1.0.0:
resolved "https://registry.npm.taobao.org/to-arraybuffer/download/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43"
integrity sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=
to-fast-properties@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
integrity sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=
to-fast-properties@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/to-fast-properties/download/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"

View File

@ -15,7 +15,7 @@
<a-sub-menu v-if="item.children && item.children.length>0" :key="item.path" @titleClick="titleClick(item)">
<span slot="title"><a-icon :type="item.icon?item.icon:'file'" /><span>{{item.title}}</span></span>
<a-menu-item v-for="(sub) of item.children" :key="sub.path" @click="menuClick(sub)" >
{{ sub.title }}
<a-icon :type="sub.icon?sub.icon:'file'"/> {{ sub.title }}
</a-menu-item>
</a-sub-menu>
<a-menu-item v-else :key="item.path" @click="menuClick(item)">
@ -60,7 +60,8 @@ export default {
path: '/plugin',
icon: 'api',
children: [
{ title: 'NPM加速', path: '/plugin/node', icon: 'like' }
{ title: 'NPM加速', path: '/plugin/node', icon: 'like' },
{ title: '', path: '/plugin/overwall', icon: 'global' }
]
}
]

View File

@ -0,0 +1,108 @@
<template>
<ds-container>
<template slot="header">
梯子
<span>
</span>
</template>
<div v-if="config">
<a-form layout="horizontal">
<a-form-item label="梯子" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.overwall.enabled">
启用
</a-checkbox>
<div>这是什么功能你懂的偷偷的用别声张可以分享给信得过的朋友</div>
<div>还有不要看视频流量挺小的</div>
</a-form-item>
<a-form-item label="PAC" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.overwall.pac.enabled">
启用PAC
</a-checkbox>
</a-form-item>
<a-form-item label="自定义域名" :label-col="labelCol" :wrapper-col="wrapperCol">
<div>
<a-row :gutter="10" style="">
<a-col :span="14">
<span>PAC没有拦截到的域名可以在此处定义</span>
</a-col>
<a-col :span="3">
<a-button type="primary" icon="plus" @click="addTarget()" />
</a-col>
</a-row>
<a-row :gutter="10" v-for="(item,index) of targets" :key = 'index'>
<a-col :span="14">
<a-input v-model="item.key"></a-input>
</a-col>
<a-col :span="3">
<a-button type="danger" icon="minus" @click="deleteTarget(item,index)" />
</a-col>
</a-row>
</div>
</a-form-item>
</a-form>
</div>
<template slot="footer">
<div class="footer-bar">
<a-button class="md-mr-10" icon="sync" @click="resetDefault()"></a-button>
<a-button :loading="applyLoading" icon="check" type="primary" @click="apply()"></a-button>
</div>
</template>
</ds-container>
</template>
<script>
import Plugin from '../../mixins/plugin'
export default {
name: 'Overwall',
mixins: [Plugin],
data () {
return {
key: 'plugin.overwall',
targets: undefined
}
},
created () {
console.log('status:', this.status)
},
mounted () {
},
methods: {
async applyAfter () {
if (this.status.server.enabled) {
return this.$api.server.restart()
}
},
ready () {
this.targets = []
const targetsMap = this.config.plugin.overwall.targets
for (const key in targetsMap) {
const value = targetsMap[key]
this.targets.push({
key, value
})
}
},
deleteTarget (item, index) {
this.targets.splice(index, 1)
},
addTarget () {
this.targets.unshift({ key: '', value: true })
},
async applyBefore () {
const map = {}
for (const item of this.targets) {
if (item.key) {
map[item.key] = item.value
}
}
this.config.plugin.overwall.targets = map
}
}
}
</script>
<style lang="sass">
</style>

View File

@ -2,13 +2,15 @@ import Index from '../pages/index'
import Server from '../pages/server'
import Proxy from '../pages/proxy'
import Node from '../pages/plugin/node'
import Overwall from '../pages/plugin/overwall'
const routes = [
{ path: '/', redirect: '/index' },
{ path: '/index', component: Index },
{ path: '/server', component: Server },
{ path: '/proxy', component: Proxy },
{ path: '/plugin/node', component: Node }
{ path: '/plugin/node', component: Node },
{ path: '/plugin/overwall', component: Overwall }
]

View File

@ -4,13 +4,11 @@ module.exports = {
const { rOptions, log, RequestCounter } = context
let proxyConf = interceptOpt.proxy
if (RequestCounter && interceptOpt.backup) {
if (RequestCounter && interceptOpt.backup && interceptOpt.backup.length > 0) {
// 优选逻辑
const backup = [proxyConf]
if (interceptOpt.backup) {
for (const bk of interceptOpt.backup) {
backup.push(bk)
}
for (const bk of interceptOpt.backup) {
backup.push(bk)
}
const key = interceptOpt.key
@ -38,6 +36,7 @@ module.exports = {
}
// 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

View File

@ -0,0 +1,79 @@
const url = require('url')
const pac = require('./source/pac')
const matchUtil = require('../../../utils/util.match')
const lodash = require('lodash')
function matched (hostname, regexpMap) {
const ret1 = matchUtil.matchHostname(regexpMap, hostname)
if (ret1) {
return true
}
const ret = pac.FindProxyForURL('https://' + hostname, hostname)
if (ret && ret.indexOf('PROXY ') === 0) {
return true
}
return false
}
module.exports = function createOverWallIntercept (overWallConfig) {
if (!overWallConfig || overWallConfig.enabled !== true || !overWallConfig.server || Object.keys(overWallConfig.server).length === 0) {
return null
}
const keys = Object.keys(overWallConfig.server)
const regexpMap = matchUtil.domainMapRegexply(overWallConfig.intercepts)
return {
sslConnectInterceptor: (req, cltSocket, head) => {
const hostname = req.url.split(':')[0]
return matched(hostname, regexpMap)
},
requestIntercept (context, req, res, ssl, next) {
const { rOptions, log, RequestCounter } = context
if (rOptions.protocol === 'http:') {
return
}
const hostname = rOptions.hostname
if (!matched(hostname, regexpMap)) {
return
}
const key = '__over_wall_proxy__'
let proxyServer = keys[0]
if (RequestCounter && keys.length > 1) {
const count = RequestCounter.getOrCreate(key, keys)
if (count.value == null) {
count.doRank()
}
if (count.value == null) {
log.error('count value is null', count)
} else {
count.doCount(count.value)
proxyServer = count.value
context.requestCount = {
key,
value: count.value,
count
}
}
}
const proxyTarget = proxyServer + '/' + hostname + req.url
// const backup = interceptOpt.backup
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
rOptions.path = URL.path
if (URL.port == null) {
rOptions.port = rOptions.protocol === 'https:' ? 443 : 80
}
log.info('OverWall:', rOptions.hostname, proxyTarget)
if (context.requestCount) {
log.debug('OverWall choice:', JSON.stringify(context.requestCount))
}
return true
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,14 +5,32 @@ const log = require('../../../utils/util.log')
const DnsUtil = require('../../dns/index')
const localIP = '127.0.0.1'
const defaultDns = require('dns')
function isSslConnect (sslConnectInterceptors, req, cltSocket, head) {
for (const intercept of sslConnectInterceptors) {
const ret = intercept(req, cltSocket, head)
if (ret) {
return true
}
}
return false
}
// create connectHandler function
module.exports = function createConnectHandler (sslConnectInterceptor, fakeServerCenter, dnsConfig) {
module.exports = function createConnectHandler (sslConnectInterceptor, middlewares, fakeServerCenter, dnsConfig) {
// return
const sslConnectInterceptors = []
sslConnectInterceptors.push(sslConnectInterceptor)
for (const middleware of middlewares) {
if (middleware.sslConnectInterceptor) {
sslConnectInterceptors.push(middleware.sslConnectInterceptor)
}
}
return function connectHandler (req, cltSocket, head) {
// eslint-disable-next-line node/no-deprecated-api
const srvUrl = url.parse(`https://${req.url}`)
const hostname = srvUrl.hostname
if (typeof sslConnectInterceptor === 'function' && sslConnectInterceptor(req, cltSocket, head)) {
if (isSslConnect(sslConnectInterceptors, req, cltSocket, head)) {
fakeServerCenter.getServerPromise(hostname, srvUrl.port).then((serverObj) => {
connect(req, cltSocket, head, localIP, serverObj.port)
}, (e) => {

View File

@ -6,10 +6,12 @@ const DnsUtil = require('../../dns/index')
const log = require('../../../utils/util.log')
const RequestCounter = require('../../choice/RequestCounter')
const InsertScriptMiddleware = require('../middleware/InsertScriptMiddleware')
const OverWallMiddleware = require('../middleware/overwall')
const defaultDns = require('dns')
const MAX_SLOW_TIME = 8000 // 超过此时间 则认为太慢了
// create requestHandler function
module.exports = function createRequestHandler (createIntercepts, externalProxy, dnsConfig, setting) {
module.exports = function createRequestHandler (createIntercepts, middlewares, externalProxy, dnsConfig, setting) {
// return
return function requestHandler (req, res, ssl) {
let proxyReq
@ -44,8 +46,14 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
if (setting.script.enabled) {
reqIncpts.unshift(InsertScriptMiddleware)
}
for (const middleware of middlewares) {
reqIncpts.unshift(middleware)
}
if (reqIncpts && reqIncpts.length > 0) {
for (const reqIncpt of reqIncpts) {
if (!reqIncpt.requestIntercept) {
continue
}
const goNext = reqIncpt.requestIntercept(context, req, res, ssl, next)
if (goNext) {
next()
@ -200,6 +208,11 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
const next = () => {
resolve()
}
for (const middleware of middlewares) {
if (middleware.responseInterceptor) {
middleware.responseInterceptor(req, res, proxyReq, proxyRes, ssl, next)
}
}
if (!setting.script.enabled) {
next()
return
@ -217,7 +230,6 @@ module.exports = function createRequestHandler (createIntercepts, externalProxy,
body += append.body
}
}
InsertScriptMiddleware.responseInterceptor(req, res, proxyReq, proxyRes, ssl, next, { head, body })
} else {
next()

View File

@ -38,6 +38,7 @@ module.exports = {
port = ~~port
const requestHandler = createRequestHandler(
createIntercepts,
middlewares,
externalProxy,
dnsConfig,
setting
@ -55,6 +56,7 @@ module.exports = {
const connectHandler = createConnectHandler(
sslConnectInterceptor,
middlewares,
fakeServersCenter,
dnsConfig
)

View File

@ -1,54 +1,22 @@
const interceptors = require('./lib/interceptor')
const dnsUtil = require('./lib/dns')
const lodash = require('lodash')
const log = require('./utils/util.log')
const path = require('path')
function matchHostname (hostMap, hostname) {
const value = hostMap[hostname]
if (value) {
return value
}
if (!value) {
for (const target in hostMap) {
if (target.indexOf('*') < 0) {
continue
}
// 正则表达式匹配
if (hostname.match(target)) {
return hostMap[target]
}
}
}
}
function isMatched (url, regexp) {
return url.match(regexp)
}
function domainRegexply (target) {
return target.replace(/\./g, '\\.').replace(/\*/g, '.*')
}
function domainMapRegexply (hostMap) {
const regexpMap = {}
lodash.each(hostMap, (value, domain) => {
if (domain.indexOf('*') >= 0) {
const regDomain = domainRegexply(domain)
regexpMap[regDomain] = value
} else {
regexpMap[domain] = value
}
})
return regexpMap
}
const matchUtil = require('./utils/util.match')
const createOverwallMiddleware = require('./lib/proxy/middleware/overwall')
module.exports = (config) => {
const intercepts = domainMapRegexply(config.intercepts)
const whiteList = domainMapRegexply(config.whiteList)
const intercepts = matchUtil.domainMapRegexply(config.intercepts)
const whiteList = matchUtil.domainMapRegexply(config.whiteList)
const dnsMapping = config.dns.mapping
const serverConfig = config
const setting = serverConfig.setting
const overwallMiddleware = createOverwallMiddleware(serverConfig.plugin.overwall)
const middlewares = []
if (overwallMiddleware) {
middlewares.push(overwallMiddleware)
}
const options = {
port: serverConfig.port,
dnsConfig: {
@ -56,22 +24,21 @@ module.exports = (config) => {
mapping: dnsMapping
},
setting,
middlewares,
sslConnectInterceptor: (req, cltSocket, head) => {
const hostname = req.url.split(':')[0]
const inWhiteList = matchHostname(whiteList, hostname) != null
const inWhiteList = matchUtil.matchHostname(whiteList, hostname) != null
if (inWhiteList) {
log.info('白名单域名,不拦截', hostname)
return false
}
const ret = !!matchHostname(intercepts, hostname) // 配置了拦截的域名,将会被代理
if (ret) {
return true
}
// 配置了拦截的域名,将会被代理
return !!matchUtil.matchHostname(intercepts, hostname)
},
createIntercepts: (context) => {
const rOptions = context.rOptions
const hostname = rOptions.hostname
const interceptOpts = matchHostname(intercepts, hostname)
const interceptOpts = matchUtil.matchHostname(intercepts, hostname)
if (!interceptOpts) { // 该域名没有配置拦截器,直接过
return
}
@ -81,13 +48,13 @@ module.exports = (config) => {
const interceptOpt = interceptOpts[regexp]
interceptOpt.key = regexp
if (regexp !== true) {
if (!isMatched(rOptions.path, regexp)) {
if (!matchUtil.isMatched(rOptions.path, regexp)) {
continue
}
}
for (const impl of interceptors) {
// 根据拦截配置挑选合适的拦截器来处理
if (impl.is(interceptOpt)) {
if (impl.is && impl.is(interceptOpt)) {
const interceptor = {}
if (impl.requestIntercept) {
// req拦截器

View File

@ -0,0 +1,48 @@
const lodash = require('lodash')
function isMatched (url, regexp) {
return url.match(regexp)
}
function domainRegexply (target) {
return target.replace(/\./g, '\\.').replace(/\*/g, '.*')
}
function domainMapRegexply (hostMap) {
const regexpMap = {}
if (hostMap == null) {
return regexpMap
}
lodash.each(hostMap, (value, domain) => {
if (domain.indexOf('*') >= 0) {
const regDomain = domainRegexply(domain)
regexpMap[regDomain] = value
} else {
regexpMap[domain] = value
}
})
return regexpMap
}
function matchHostname (hostMap, hostname) {
const value = hostMap[hostname]
if (value) {
return value
}
if (!value) {
for (const target in hostMap) {
if (target.indexOf('*') < 0) {
continue
}
// 正则表达式匹配
if (hostname.match(target)) {
return hostMap[target]
}
}
}
}
module.exports = {
isMatched,
domainRegexply,
domainMapRegexply,
matchHostname
}

View File

@ -1,8 +1,12 @@
module.exports = {
fireError (e) {
process.send({ type: 'error', event: e })
if (process.send) {
process.send({ type: 'error', event: e })
}
},
fireStatus (status) {
process.send({ type: 'status', event: status })
if (process.send) {
process.send({ type: 'status', event: status })
}
}
}

View File

@ -30,3 +30,5 @@ const hostname4 = 'gh.docmirror.top'
dnsProviders.usa.lookup(hostname4)
const hostname5 = 'gh2.docmirror.top'
dnsProviders.usa.lookup(hostname5)

View File

@ -15,3 +15,6 @@ chunk.copy(chunkNew, 0, 0, index)
scriptBuf.copy(chunkNew, index, 0)
chunk.copy(chunkNew, index + scriptBuf.length, index)
console.log(chunkNew.toString())
const reg2 = '/aaaa/i'
console.log(new RegExp(reg2).test('aaaa'))

View File

@ -0,0 +1,3 @@
const pac = require('../src/lib/interceptor/impl/source/pac')
const string = pac.FindProxyForURL('https://www.facebook.com', 'www.facebook.com')
console.log(string)