中国修改为国内,因为该软件可能其他国家的人也有在用。
parent
6653f7613e
commit
e2a309fb98
|
@ -57,12 +57,12 @@ module.exports = {
|
|||
proxyHttp: false, // false=只代理HTTPS请求 true=同时代理HTTP和HTTPS请求
|
||||
setEnv: false,
|
||||
|
||||
// 排除中国域名 所需配置
|
||||
excludeChinaDomainAllowList: true, // 是否排除中国域名,默认:需要排除
|
||||
autoUpdateChinaDomainAllowList: true, // 是否自动更新中国域名
|
||||
remoteChinaDomainAllowListFileUrl: 'https://raw.githubusercontent.com/pluwen/china-domain-allowlist/refs/heads/main/allow-list.sorl',
|
||||
chinaDomainAllowListFileAbsolutePath: null, // 自定义 china-domain-allowlist.txt 文件位置,可以是本地文件路径
|
||||
chinaDomainAllowListFilePath: './extra/proxy/china-domain-allowlist.txt', // 内置中国域名文件
|
||||
// 排除国内域名 所需配置
|
||||
excludeDomesticDomainAllowList: true, // 是否排除国内域名,默认:需要排除
|
||||
autoUpdateDomesticDomainAllowList: true, // 是否自动更新国内域名
|
||||
remoteDomesticDomainAllowListFileUrl: 'https://raw.githubusercontent.com/pluwen/china-domain-allowlist/refs/heads/main/allow-list.sorl',
|
||||
domesticDomainAllowListFileAbsolutePath: null, // 自定义 domestic-domain-allowlist.txt 文件位置,可以是本地文件路径
|
||||
domesticDomainAllowListFilePath: './extra/proxy/domestic-domain-allowlist.txt', // 内置国内域名文件
|
||||
|
||||
// 自定义系统代理排除列表
|
||||
excludeIpList: {
|
||||
|
|
|
@ -50,45 +50,45 @@ async function _winUnsetProxy (exec, setEnv) {
|
|||
}
|
||||
}
|
||||
|
||||
function getChinaDomainAllowListTmpFilePath () {
|
||||
return path.join(config.get().server.setting.userBasePath, '/china-domain-allowlist.txt')
|
||||
function getDomesticDomainAllowListTmpFilePath () {
|
||||
return path.join(config.get().server.setting.userBasePath, '/domestic-domain-allowlist.txt')
|
||||
}
|
||||
|
||||
async function downloadChinaDomainAllowListAsync () {
|
||||
async function downloadDomesticDomainAllowListAsync () {
|
||||
loadConfig()
|
||||
|
||||
const remoteFileUrl = config.get().proxy.remoteChinaDomainAllowListFileUrl
|
||||
log.info('开始下载远程 china-domain-allowlist.txt 文件:', remoteFileUrl)
|
||||
const remoteFileUrl = config.get().proxy.remoteDomesticDomainAllowListFileUrl
|
||||
log.info('开始下载远程 domestic-domain-allowlist.txt 文件:', remoteFileUrl)
|
||||
request(remoteFileUrl, (error, response, body) => {
|
||||
if (error) {
|
||||
log.error('下载远程 china-domain-allowlist.txt 文件失败, error:', error, ', response:', response, ', body:', body)
|
||||
log.error('下载远程 domestic-domain-allowlist.txt 文件失败, error:', error, ', response:', response, ', body:', body)
|
||||
return
|
||||
}
|
||||
if (response && response.statusCode === 200) {
|
||||
if (body == null || body.length < 100) {
|
||||
log.warn('下载远程 china-domain-allowlist.txt 文件成功,但内容为空或内容太短,判断为无效的 china-domain-allowlist.txt 文件:', remoteFileUrl, ', body:', body)
|
||||
log.warn('下载远程 domestic-domain-allowlist.txt 文件成功,但内容为空或内容太短,判断为无效的 domestic-domain-allowlist.txt 文件:', remoteFileUrl, ', body:', body)
|
||||
return
|
||||
} else {
|
||||
log.info('下载远程 china-domain-allowlist.txt 文件成功:', remoteFileUrl)
|
||||
log.info('下载远程 domestic-domain-allowlist.txt 文件成功:', remoteFileUrl)
|
||||
}
|
||||
|
||||
let fileTxt = body
|
||||
try {
|
||||
if (fileTxt.indexOf('*.') < 0) {
|
||||
fileTxt = Buffer.from(fileTxt, 'base64').toString('utf8')
|
||||
// log.debug('解析 base64 后的 china-domain-allowlist:', fileTxt)
|
||||
// log.debug('解析 base64 后的 domestic-domain-allowlist:', fileTxt)
|
||||
}
|
||||
} catch (e) {
|
||||
if (fileTxt.indexOf('*.') < 0) {
|
||||
log.error(`远程 china-domain-allowlist.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remoteFileUrl},body: ${body}`)
|
||||
log.error(`远程 domestic-domain-allowlist.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remoteFileUrl},body: ${body}`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 保存到本地
|
||||
saveChinaDomainAllowListFile(fileTxt)
|
||||
saveDomesticDomainAllowListFile(fileTxt)
|
||||
} else {
|
||||
log.error('下载远程 china-domain-allowlist.txt 文件失败, response:', response, ', body:', body)
|
||||
log.error('下载远程 domestic-domain-allowlist.txt 文件失败, response:', response, ', body:', body)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -104,25 +104,25 @@ function loadLastModifiedTimeFromTxt (fileTxt) {
|
|||
}
|
||||
}
|
||||
|
||||
// 保存 中国域名白名单 内容到 `~/china-domain-allowlist.txt.txt` 文件中
|
||||
function saveChinaDomainAllowListFile (fileTxt) {
|
||||
const filePath = getChinaDomainAllowListTmpFilePath()
|
||||
// 保存 国内域名白名单 内容到 `~/domestic-domain-allowlist.txt` 文件中
|
||||
function saveDomesticDomainAllowListFile (fileTxt) {
|
||||
const filePath = getDomesticDomainAllowListTmpFilePath()
|
||||
fs.writeFileSync(filePath, fileTxt.replaceAll(/\r\n?/g, '\n'))
|
||||
log.info('保存 china-domain-allowlist.txt 文件成功:', filePath)
|
||||
log.info('保存 domestic-domain-allowlist.txt 文件成功:', filePath)
|
||||
|
||||
// 尝试解析和修改 china-domain-allowlist.txt 文件时间
|
||||
// 尝试解析和修改 domestic-domain-allowlist.txt 文件时间
|
||||
const lastModifiedTime = loadLastModifiedTimeFromTxt(fileTxt)
|
||||
if (lastModifiedTime) {
|
||||
fs.stat(filePath, (err, stats) => {
|
||||
if (err) {
|
||||
log.error('修改 china-domain-allowlist.txt 文件时间失败:', err)
|
||||
log.error('修改 domestic-domain-allowlist.txt 文件时间失败:', err)
|
||||
return
|
||||
}
|
||||
|
||||
// 修改文件的访问时间和修改时间为当前时间
|
||||
fs.utimes(filePath, lastModifiedTime, lastModifiedTime, (utimesErr) => {
|
||||
if (utimesErr) {
|
||||
log.error('修改 china-domain-allowlist.txt 文件时间失败:', utimesErr)
|
||||
log.error('修改 domestic-domain-allowlist.txt 文件时间失败:', utimesErr)
|
||||
} else {
|
||||
log.info(`'${filePath}' 文件的修改时间已更新为其最近更新时间 '${formatDate(lastModifiedTime)}'`)
|
||||
}
|
||||
|
@ -143,40 +143,40 @@ function formatDate (date) {
|
|||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
|
||||
function getChinaDomainAllowList () {
|
||||
function getDomesticDomainAllowList () {
|
||||
loadConfig()
|
||||
|
||||
if (!config.get().proxy.excludeChinaDomainAllowList) {
|
||||
if (!config.get().proxy.excludeDomesticDomainAllowList) {
|
||||
return null
|
||||
}
|
||||
|
||||
// 判断是否需要自动更新中国域名
|
||||
let fileAbsolutePath = config.get().proxy.chinaDomainAllowListFileAbsolutePath
|
||||
if (!fileAbsolutePath && config.get().proxy.autoUpdateChinaDomainAllowList) {
|
||||
// 判断是否需要自动更新国内域名
|
||||
let fileAbsolutePath = config.get().proxy.domesticDomainAllowListFileAbsolutePath
|
||||
if (!fileAbsolutePath && config.get().proxy.autoUpdateDomesticDomainAllowList) {
|
||||
// 异步下载,下载成功后,下次系统代理生效
|
||||
downloadChinaDomainAllowListAsync().then()
|
||||
downloadDomesticDomainAllowListAsync().then()
|
||||
}
|
||||
|
||||
// 加载本地文件
|
||||
if (!fileAbsolutePath) {
|
||||
const tmpFilePath = getChinaDomainAllowListTmpFilePath()
|
||||
const tmpFilePath = getDomesticDomainAllowListTmpFilePath()
|
||||
if (fs.existsSync(tmpFilePath)) {
|
||||
// 如果临时文件已存在,则使用临时文件
|
||||
fileAbsolutePath = tmpFilePath
|
||||
log.info('读取已下载的 china-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
log.info('读取已下载的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
} else {
|
||||
// 如果临时文件不存在,则使用内置文件
|
||||
fileAbsolutePath = path.join(__dirname, '../../gui/', config.get().proxy.chinaDomainAllowListFilePath)
|
||||
log.info('读取内置的 china-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
fileAbsolutePath = path.join(__dirname, '../../gui/', config.get().proxy.domesticDomainAllowListFilePath)
|
||||
log.info('读取内置的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
}
|
||||
} else {
|
||||
log.info('读取自定义路径的 china-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
log.info('读取自定义路径的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
|
||||
}
|
||||
|
||||
try {
|
||||
return fs.readFileSync(fileAbsolutePath).toString()
|
||||
} catch (e) {
|
||||
log.error('读取 china-domain-allowlist.txt 文件失败:', fileAbsolutePath)
|
||||
log.error('读取 domestic-domain-allowlist.txt 文件失败:', fileAbsolutePath)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -192,21 +192,21 @@ async function _winSetProxy (exec, ip, port, setEnv) {
|
|||
}
|
||||
}
|
||||
|
||||
// 排除中国域名
|
||||
if (config.get().proxy.excludeChinaDomainAllowList) {
|
||||
// 排除国内域名
|
||||
if (config.get().proxy.excludeDomesticDomainAllowList) {
|
||||
try {
|
||||
let chinaDomainAllowList = getChinaDomainAllowList()
|
||||
if (chinaDomainAllowList) {
|
||||
chinaDomainAllowList = (chinaDomainAllowList + '\n').replaceAll(/[\r\n]+/g, '\n').replaceAll(/[^\n]*[^*.a-zA-Z\d-\n]+[^\n]*\r?\n/g, '').replaceAll(/\s*\n+\s*/g, ';')
|
||||
if (chinaDomainAllowList) {
|
||||
excludeIpStr += chinaDomainAllowList
|
||||
log.info('系统代理排除列表拼接中国域名')
|
||||
let domesticDomainAllowList = getDomesticDomainAllowList()
|
||||
if (domesticDomainAllowList) {
|
||||
domesticDomainAllowList = (domesticDomainAllowList + '\n').replaceAll(/[\r\n]+/g, '\n').replaceAll(/[^\n]*[^*.a-zA-Z\d-\n]+[^\n]*\r?\n/g, '').replaceAll(/\s*\n+\s*/g, ';')
|
||||
if (domesticDomainAllowList) {
|
||||
excludeIpStr += domesticDomainAllowList
|
||||
log.info('系统代理排除列表拼接国内域名')
|
||||
} else {
|
||||
log.info('中国域名为空,不进行系统代理排除列表拼接中国域名')
|
||||
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('系统代理排除列表拼接中国域名失败:', e)
|
||||
log.error('系统代理排除列表拼接国内域名失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,20 +44,24 @@
|
|||
<div class="form-help">解决<code>OneNote</code>、<code>MicrosoftStore</code>、<code>Outlook</code>等<code>UWP应用</code>开启代理后无法访问网络的问题</div>
|
||||
</a-form-item>
|
||||
<hr/>
|
||||
<a-form-item label="排除中国域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox v-model="config.proxy.excludeChinaDomainAllowList" >
|
||||
是否排除中国域名白名单
|
||||
<a-form-item label="排除国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox v-model="config.proxy.excludeDomesticDomainAllowList" >
|
||||
是否排除国内域名白名单
|
||||
</a-checkbox>
|
||||
</a-form-item>
|
||||
<a-form-item label="自动更新中国域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox v-model="config.proxy.excludeChinaDomainAllowList" >
|
||||
自动下载远程中国域名文件。未开启自动更新时,将使用内置中国域名文件
|
||||
<a-form-item label="自动更新国内域名" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-checkbox v-model="config.proxy.autoUpdateDomesticDomainAllowList" >
|
||||
是否自动更新国内域名
|
||||
</a-checkbox>
|
||||
</a-form-item>
|
||||
<a-form-item label="远程中国域名文件" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-input v-model="config.proxy.remoteChinaDomainAllowListFileUrl" :title="config.proxy.remoteChinaDomainAllowListFileUrl"></a-input>
|
||||
<div class="form-help">
|
||||
远程中国域名白名单文件内容可以是<code>base64</code>编码格式,也可以是未经过编码的
|
||||
开启自动更新后,启动代理服务时,将会异步从下面的远程地址下载PAC文件到本地。<br/>
|
||||
注:只要下载成功后,即使关闭自动更新功能,也会优先读取最近下载的PAC文件!
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="远程国内域名文件" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<a-input v-model="config.proxy.remoteDomesticDomainAllowListFileUrl" :title="config.proxy.remoteDomesticDomainAllowListFileUrl"></a-input>
|
||||
<div class="form-help">
|
||||
远程国内域名白名单文件内容可以是<code>base64</code>编码格式,也可以是未经过编码的
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="排除地址配置" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
|
|
Loading…
Reference in New Issue