refactor: pac转移配置

pull/88/head
xiaojunnuo 2021-08-11 11:21:53 +08:00
parent 09b2e65adb
commit 8b0f2d0f5d
8 changed files with 3391 additions and 23161 deletions

View File

@ -39,23 +39,23 @@ module.exports = {
'/.*/.*/releases/download/': { '/.*/.*/releases/download/': {
redirect: 'download.fastgit.org', redirect: 'download.fastgit.org',
desc: 'release文件加速下载跳转地址', desc: 'release文件加速下载跳转地址',
sni: 'no.sni' sni: 'baidu.com'
}, },
'/.*/.*/archive/': { '/.*/.*/archive/': {
redirect: 'download.fastgit.org', redirect: 'download.fastgit.org',
sni: 'no.sni' sni: 'baidu.com'
}, },
'/.*/.*/blame/': { '/.*/.*/blame/': {
redirect: 'hub.fastgit.org', redirect: 'hub.fastgit.org',
sni: 'no.sni' sni: 'baidu.com'
}, },
'^/[^/]+/[^/]+(/releases(/.*)?)?$': { '^/[^/]+/[^/]+(/releases(/.*)?)?$': {
script: [ script: [
'github' 'github'
], ],
desc: 'clone加速复制链接脚本', desc: 'clone加速复制链接脚本',
sni: 'no.sni' sni: 'baidu.com'
}, },
'/.*': { '/.*': {
proxy: 'github.com', proxy: 'github.com',

View File

@ -16,8 +16,9 @@ module.exports = {
}, },
pac: { pac: {
enabled: true, enabled: true,
update: [ // update: [
'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt' // 'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt'
] // ],
customPacFilePath: './extra/pac/pac.txt'
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
const url = require('url') const url = require('url')
const pac = require('./source/pac') const pac = require('./source/pac')
const matchUtil = require('../../../utils/util.match') const matchUtil = require('../../../utils/util.match')
let pacClient = null
function matched (hostname, regexpMap) { function matched (hostname, regexpMap) {
const ret1 = matchUtil.matchHostname(regexpMap, hostname) const ret1 = matchUtil.matchHostname(regexpMap, hostname)
if (ret1) { if (ret1) {
return true return true
} }
const ret = pac.FindProxyForURL('https://' + hostname, hostname) const ret = pacClient.FindProxyForURL('https://' + hostname, hostname)
if (ret && ret.indexOf('PROXY ') === 0) { if (ret && ret.indexOf('PROXY ') === 0) {
return true return true
} }
@ -18,6 +19,11 @@ module.exports = function createOverWallIntercept (overWallConfig) {
if (!overWallConfig || overWallConfig.enabled !== true) { if (!overWallConfig || overWallConfig.enabled !== true) {
return null return null
} }
if (overWallConfig.pac) {
// 初始化pac
pacClient = pac.createPacClient(overWallConfig.pac.customPacFilePath)
}
let server = overWallConfig.server let server = overWallConfig.server
let keys = Object.keys(server) let keys = Object.keys(server)
if (keys.length === 0) { if (keys.length === 0) {

View File

@ -1,8 +1,27 @@
const fs = require('fs')
const path = require('path')
const log = require('../../../../utils/util.log')
function createPacClient (pacFilePath) {
var __PROXY__ = 'PROXY 127.0.0.1:1080;' var __PROXY__ = 'PROXY 127.0.0.1:1080;'
var __USERRULES__ = [] var __USERRULES__ = []
const getRules = function () {
let text = require('./pac.txt.js') function readFile (location) {
try {
const filePath = path.resolve(location)
log.debug('read pac path:', filePath)
return fs.readFileSync(location).toString()
} catch (e) {
log.error('读取pac失败')
return ''
}
}
const getRules = function (pacFilePath) {
let text = readFile(pacFilePath)
if (text.indexOf('!---------------------EOF') === -1) {
text = Buffer.from(text, 'base64').toString() text = Buffer.from(text, 'base64').toString()
}
const rules = [] const rules = []
const arr = text.split('\n') const arr = text.split('\n')
for (const line of arr) { for (const line of arr) {
@ -14,7 +33,8 @@ const getRules = function () {
} }
return rules return rules
} }
var __RULES__ = getRules() var __RULES__ = getRules(pacFilePath)
/* eslint-disable */ /* eslint-disable */
// Was generated by gfwlist2pac in precise mode // Was generated by gfwlist2pac in precise mode
// https://github.com/clowwindy/gfwlist2pac // https://github.com/clowwindy/gfwlist2pac
@ -660,6 +680,12 @@ function FindProxyForURL(url, host) {
return direct; return direct;
} }
module.exports = {
FindProxyForURL return {
FindProxyForURL,
}
}
module.exports = {
createPacClient
} }

File diff suppressed because one or more lines are too long