在家的时候, 需要使用代理, 同时要使用图书馆的数据库, 两个代理有点冲突, 自己研究了一下
ssr 的规则, 发现比较简单.
可以页面后贴出的代码进行研究 pac.txt
pac 的内部完全就是 js 的语法逻辑, 不是十分熟悉, 写的有点硬, 可以自己考虑优化
执行从 FindProxyForURL
开始执行, 然后根据具体内容进行代理访问
按照学校代理的判断方式, 判断一个 url 是否符合图书馆给出的pac 地址,
将访问数据库的链接,执行 PROXY proxy2.lib.whu.edu.cn:81
代理链接, 第一次建立链接的时候, 需要使用图书馆 帐号密码进行验证,
剩余的链接进行 ssr 验证, 进行正常的代理 执行过程.
代码demo
// 默认使用的是 js 的语法
// 判断网站, 然后选择 代理位置
var direct = "DIRECT;";
var wall_proxy = function(){
return "__PROXY__"; };
var wall_v6_proxy = function(){
return "__PROXY__"; };
var ip_proxy = function(){
return wall_proxy(); };
var ipv6_proxy = function(){
return wall_v6_proxy(); };
var nowall_proxy = function(){
return direct; };
/*
* Copyright (C) 2014 breakwa11
* https://github.com/breakwa11/gfw_whitelist
*/
var subnetIpRangeList = [
0,1,
167772160,184549376, //10.0.0.0/8
2886729728,2887778304, //172.16.0.0/12
3232235520,3232301056, //192.168.0.0/16
2130706432,2130706688 //127.0.0.0/24
];
var hasOwnProperty = Object.hasOwnProperty;
function check_ipv4(host) {
var re_ipv4 = /^\d+\.\d+\.\d+\.\d+$/g;
if (re_ipv4.test(host)) {
return true;
}
}
function check_ipv6(host) {
var re_ipv6 = /^\[?([a-fA-F0-9]{0,4}\:){1,7}[a-fA-F0-9]{0,4}\]?$/g;
if (re_ipv6.test(host)) {
return true;
}
}
function check_ipv6_dns(dnsstr) {
var re_ipv6 = /([a-fA-F0-9]{0,4}\:){1,7}[a-fA-F0-9]{0,4}(%[0-9]+)?/g;
if (re_ipv6.test(dnsstr)) {
return true;
}
}
function convertAddress(ipchars) {
var bytes = ipchars.split('.');
var result = (bytes[0] << 24) |
(bytes[1] << 16) |
(bytes[2] << 8) |
(bytes[3]);
return result >>> 0;
}
function isInSubnetRange(ipRange, intIp) {
for ( var i = 0; i < 10; i += 2 ) {
if ( ipRange[i] <= intIp && intIp < ipRange[i+1] )
return true;
}
}
function getProxyFromIP(strIp) {
var intIp = convertAddress(strIp);
if ( isInSubnetRange(subnetIpRangeList, intIp) ) {
return direct;
}
return wall_proxy();
}
// 默认执行此函数 // 需要在这里 校内网
function FindProxyForURL(url, host) {
// 如果在校内网链接 数据库, 则直接连接
var whu_lib_proxy = "PROXY proxy2.lib.whu.edu.cn:81";
if(!WHU_lib_proxy(url,host))
{
return whu_lib_proxy;
}
if ( isPlainHostName(host) === true ) {
return direct;
}
if ( check_ipv4(host) === true ) {
return getProxyFromIP(host);
}
if ( check_ipv6(host) === true ) {
return ipv6_proxy();
}
var strIp = dnsResolve(host);
if ( !strIp ) {
return wall_proxy();
}
return getProxyFromIP(strIp);
}
function FindProxyForURLEx(url, host) {
if ( isPlainHostName(host) === true ) {
return direct;
}
if ( check_ipv4(host) === true ) {
return getProxyFromIP(host);
}
if ( check_ipv6(host) === true ) {
return ipv6_proxy();
}
var strIp = dnsResolveEx(host);
if ( !strIp ) {
return wall_proxy();
}
if ( check_ipv6_dns(strIp) === true ) {
return ipv6_proxy();
}
var dnsIps = strIp.split(";");
if (check_ipv4(dnsIps[0]) === true) {
return getProxyFromIP(dnsIps[0]);
} else if (check_ipv6_dns(dnsIps[0]) === true) {
return ipv6_proxy();
}
return wall_proxy();
}
//pac for whu lib
//Version: 20200117-14:14
//
function WHU_lib_proxy(url, host) {
// 根据规则判定是否在 武汉大学 net 中
var in_whu_net = true;
var not_in_whu_net = false;
var whu_lib_proxy = "PROXY proxy2.lib.whu.edu.cn:81";
// 在校内网络的情况
/*
if
(
//begin of direct client ip
isInNet(myIpAddress(), "202.114.64.0", "255.255.255.0") ||
isInNet(myIpAddress(), "202.114.66.0", "255.255.254.0") ||
isInNet(myIpAddress(), "202.114.68.0", "255.255.252.0") ||
isInNet(myIpAddress(), "202.114.72.0", "255.255.248.0") ||
isInNet(myIpAddress(), "202.114.96.0", "255.255.240.0") ||
isInNet(myIpAddress(), "218.197.144.0", "255.255.255.0") ||
isInNet(myIpAddress(), "218.197.146.0", "255.255.254.0") ||
isInNet(myIpAddress(), "218.197.148.0", "255.255.252.0") ||
isInNet(myIpAddress(), "218.197.152.0", "255.255.248.0") ||
isInNet(myIpAddress(), "222.20.192.0", "255.255.192.0") ||
isInNet(myIpAddress(), "125.220.128.0", "255.255.224.0") ||
isInNet(myIpAddress(), "192.168.254.0", "255.255.255.255"))
return in_whu_net;
//end of direct client ip;
else if (
//begin of direct name acl
dnsDomainIs(host, "2shusheng.lib.whu.edu.cn") ||
dnsDomainIs(host, "apps.lib.whu.edu.cn") ||
dnsDomainIs(host, "counter.lib.whu.edu.cn") ||
dnsDomainIs(host, "iras.lib.whu.edu.cn") ||
dnsDomainIs(host, "metalib.lib.whu.edu.cn") ||
dnsDomainIs(host, "opac.lib.whu.edu.cn") ||
dnsDomainIs(host, "proxy2.lib.whu.edu.cn") ||
dnsDomainIs(host, "proxy.lib.whu.edu.cn") ||
dnsDomainIs(host, "seat.lib.whu.edu.cn") ||
dnsDomainIs(host, "svpn.lib.whu.edu.cn") ||
dnsDomainIs(host, "www.lib.whu.edu.cn") ||
dnsDomainIs(host, "xenapp.lib.whu.edu.cn") ||
dnsDomainIs(host, "ztcb.lib.whu.edu.cn") ||
dnsDomainIs(host, ".dummy-domain1.domain"))
return in_whu_net;
//end of direct name acl;
else if (
//begin of ip name acl
isInNet(host,"102.114.65.149","255.255.255.255") ||
isInNet(host,"102.114.65.55","255.255.255.255") ||
isInNet(host,"202.114.65.106","255.255.255.255") ||
isInNet(host,"202.114.65.215","255.255.255.255") ||
isInNet(host,"202.114.65.63","255.255.255.255") ||
isInNet(host,"202.114.65.9","255.255.255.255") ||
isInNet(host,"192.168.253.252","255.255.255.252"))
return in_whu_net;
//end of direct ip acl;
*/
// 不在校园网的情况
if (
//begin of domain name acl
dnsDomainIs(host, ".51cto.com") || host == "51cto.com" ||
dnsDomainIs(host, ".51sjsj.com") || host == "51sjsj.com" ||
dnsDomainIs(host, ".5cy.com") || host == "5cy.com" ||
dnsDomainIs(host, ".5read.com") || host == "5read.com" ||
dnsDomainIs(host, ".aacnjournals.org") || host == "aacnjournals.org" ||
dnsDomainIs(host, ".aacrjournals.org") || host == "aacrjournals.org" ||
dnsDomainIs(host, ".aacr.org") || host == "aacr.org" ||
dnsDomainIs(host, ".aappublications.org") || host == "aappublications.org" ||
dnsDomainIs(host, ".accessmedicine.com") || host == "accessmedicine.com" ||
dnsDomainIs(host, ".accesspharmacy.com") || host == "accesspharmacy.com" ||
dnsDomainIs(host, ".accesssurgery.com") || host == "accesssurgery.com" ||
dnsDomainIs(host, ".acgpublishing.com") || host == "acgpublishing.com" ||
dnsDomainIs(host, ".acm.org") || host == "acm.org" ||
dnsDomainIs(host, ".acpjc.org") || host == "acpjc.org" ||
dnsDomainIs(host, ".acponline.org") || host == "acponline.org" ||
dnsDomainIs(host, ".acs.org") || host == "acs.org" ||
dnsDomainIs(host, ".acs.org.ccindex.cn") || host == "acs.org.ccindex.cn" ||
dnsDomainIs(host, ".a.ebscohost.com") || host == "a.ebscohost.com" ||
dnsDomainIs(host, "a.example.com") || host == "a.example.com" ||
dnsDomainIs(host, ".agu.org") || host == "agu.org" ||
dnsDomainIs(host, ".aiaa.org") || host == "aiaa.org" ||
dnsDomainIs(host, ".aidsonline.com") || host == "aidsonline.com" ||
dnsDomainIs(host, ".aip.org") || host == "aip.org" ||
dnsDomainIs(host, ".airiti.com.cn") || host == "airiti.com.cn" ||
dnsDomainIs(host, ".airitilibrary.cn") || host == "airitilibrary.cn" ||
dnsDomainIs(host, ".airitinpm.com") || host == "airitinpm.com" ||
dnsDomainIs(host, ".ajax.googleapis.com") || host == "ajax.googleapis.com" ||
dnsDomainIs(host, "ajax..googleapis.com") || host == "ajax..googleapis.com" ||
dnsDomainIs(host, ".ajcn.org") || host == "ajcn.org" ||
dnsDomainIs(host, ".ajhp.org") || host == "ajhp.org" ||
dnsDomainIs(host, ".ajnr.org") || host == "ajnr.org" ||
dnsDomainIs(host, ".ajtmh.org") || host == "ajtmh.org" ||
dnsDomainIs(host, ".akademiai.com") || host == "akademiai.com" ||
dnsDomainIs(host, ".alexanderstreet.com") || host == "alexanderstreet.com" ||
dnsDomainIs(host, ".allenpress.com") || host == "allenpress.com" ||
dnsDomainIs(host, ".alphamedpress.org") || host == "alphamedpress.org" ||
dnsDomainIs(host, ".ama-assn.org") || host == "ama-assn.org" ||
dnsDomainIs(host, ".amdigital.co.uk") || host == "amdigital.co.uk" ||
dnsDomainIs(host, ".amjbot.org") || host == "amjbot.org" ||
dnsDomainIs(host, ".amjmedsci.com") || host == "amjmedsci.com" ||
dnsDomainIs(host, ".amjpathol.org") || host == "amjpathol.org" ||
dnsDomainIs(host, ".ams.org") || host == "ams.org" ||
dnsDomainIs(host, ".anatomy.tv") || host == "anatomy.tv" ||
dnsDomainIs(host, ".anb.org") || host == "anb.org" ||
dnsDomainIs(host, ".angle.com.tw") || host == "angle.com.tw" ||
dnsDomainIs(host, ".annals.org") || host == "annals.org" ||
dnsDomainIs(host, ".annualreviews.org") || host == "annualreviews.org" ||
dnsDomainIs(host, ".apabi.com") || host == "apabi.com" ||
dnsDomainIs(host, ".aps.org") || host == "aps.org" ||
dnsDomainIs(host, ".archive.nstl.gov.cn") || host == "archive.nstl.gov.cn" ||
dnsDomainIs(host, ".artlib.cn") || host == "artlib.cn" ||
dnsDomainIs(host, ".asahi.com") || host == "asahi.com" ||
dnsDomainIs(host, ".ascelibrary.org") || host == "ascelibrary.org" ||
dnsDomainIs(host, ".asce.org") || host == "asce.org" ||
dnsDomainIs(host, ".asme.org") || host == "asme.org" ||
dnsDomainIs(host, ".asm.org") || host == "asm.org" ||
dnsDomainIs(host, ".aspbjournals.org") || host == "aspbjournals.org" ||
dnsDomainIs(host, ".aspetjournals.org") || host == "aspetjournals.org" ||
dnsDomainIs(host, ".astm.org") || host == "astm.org" ||
dnsDomainIs(host, ".atypon-link.com?") || host == "atypon-link.com?" ||
dnsDomainIs(host, ".awlonline.com") || host == "awlonline.com" ||
dnsDomainIs(host, ".basicedu.chaoxing.com") || host == "basicedu.chaoxing.com"