refactor: pac转移配置
parent
09b2e65adb
commit
8b0f2d0f5d
|
@ -39,23 +39,23 @@ module.exports = {
|
|||
'/.*/.*/releases/download/': {
|
||||
redirect: 'download.fastgit.org',
|
||||
desc: 'release文件加速下载跳转地址',
|
||||
sni: 'no.sni'
|
||||
sni: 'baidu.com'
|
||||
},
|
||||
'/.*/.*/archive/': {
|
||||
redirect: 'download.fastgit.org',
|
||||
sni: 'no.sni'
|
||||
sni: 'baidu.com'
|
||||
},
|
||||
|
||||
'/.*/.*/blame/': {
|
||||
redirect: 'hub.fastgit.org',
|
||||
sni: 'no.sni'
|
||||
sni: 'baidu.com'
|
||||
},
|
||||
'^/[^/]+/[^/]+(/releases(/.*)?)?$': {
|
||||
script: [
|
||||
'github'
|
||||
],
|
||||
desc: 'clone加速复制链接脚本',
|
||||
sni: 'no.sni'
|
||||
sni: 'baidu.com'
|
||||
},
|
||||
'/.*': {
|
||||
proxy: 'github.com',
|
||||
|
|
|
@ -16,8 +16,9 @@ module.exports = {
|
|||
},
|
||||
pac: {
|
||||
enabled: true,
|
||||
update: [
|
||||
'https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt'
|
||||
]
|
||||
// update: [
|
||||
// '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
|
@ -1,13 +1,14 @@
|
|||
const url = require('url')
|
||||
const pac = require('./source/pac')
|
||||
const matchUtil = require('../../../utils/util.match')
|
||||
let pacClient = null
|
||||
|
||||
function matched (hostname, regexpMap) {
|
||||
const ret1 = matchUtil.matchHostname(regexpMap, hostname)
|
||||
if (ret1) {
|
||||
return true
|
||||
}
|
||||
const ret = pac.FindProxyForURL('https://' + hostname, hostname)
|
||||
const ret = pacClient.FindProxyForURL('https://' + hostname, hostname)
|
||||
if (ret && ret.indexOf('PROXY ') === 0) {
|
||||
return true
|
||||
}
|
||||
|
@ -18,6 +19,11 @@ module.exports = function createOverWallIntercept (overWallConfig) {
|
|||
if (!overWallConfig || overWallConfig.enabled !== true) {
|
||||
return null
|
||||
}
|
||||
if (overWallConfig.pac) {
|
||||
// 初始化pac
|
||||
pacClient = pac.createPacClient(overWallConfig.pac.customPacFilePath)
|
||||
}
|
||||
|
||||
let server = overWallConfig.server
|
||||
let keys = Object.keys(server)
|
||||
if (keys.length === 0) {
|
||||
|
|
|
@ -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 __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()
|
||||
}
|
||||
const rules = []
|
||||
const arr = text.split('\n')
|
||||
for (const line of arr) {
|
||||
|
@ -14,7 +33,8 @@ const getRules = function () {
|
|||
}
|
||||
return rules
|
||||
}
|
||||
var __RULES__ = getRules()
|
||||
var __RULES__ = getRules(pacFilePath)
|
||||
|
||||
/* eslint-disable */
|
||||
// Was generated by gfwlist2pac in precise mode
|
||||
// https://github.com/clowwindy/gfwlist2pac
|
||||
|
@ -660,6 +680,12 @@ function FindProxyForURL(url, host) {
|
|||
return direct;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
FindProxyForURL
|
||||
|
||||
return {
|
||||
FindProxyForURL,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createPacClient
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue