From 535a06a6eecaf0aeb1699fed9df1703876de4e93 Mon Sep 17 00:00:00 2001 From: daiwentao Date: Thu, 12 Feb 2026 13:00:55 +0800 Subject: [PATCH] Add pac file --- mi.pac | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 mi.pac diff --git a/mi.pac b/mi.pac new file mode 100644 index 000000000..086212b81 --- /dev/null +++ b/mi.pac @@ -0,0 +1,100 @@ +// Helper function to check if a string is an IP address +function isIP(host) { + var parts = host.split("."); + if (parts.length !== 4) { + return false; + } + for (var i = 0; i < 4; i++) { + var num = parseInt(parts[i], 10); + if (isNaN(num) || num < 0 || num > 255) { + return false; + } + } + return true; +} + +// Helper function to check if IP is in private network range +function isPrivateIP(host) { + if (!isIP(host)) { + return false; + } + var parts = host.split("."); + var first = parseInt(parts[0], 10); + var second = parseInt(parts[1], 10); + + // 10.0.0.0/8 + if (first === 10) { + return true; + } + // 172.16.0.0/12 + if (first === 172 && second >= 16 && second <= 31) { + return true; + } + // 192.168.0.0/16 + if (first === 192 && second === 168) { + return true; + } + // 127.0.0.0/8 (localhost) + if (first === 127) { + return true; + } + return false; +} + +function FindProxyForURL(url, host) { + // Enable logging (set to false to disable) + var enableLog = true; + + // Log function for debugging using alert + function log(message) { + if (enableLog) { + alert("PAC: " + message); + } + } + + log("Checking URL: " + url + ", Host: " + host); + + // Direct connect addresses and domains (whitelist) + var direct_list = [ + "localhost", + "*.cn", // All .cn domains direct connect (use with caution) + "*.baidu.com", + "*.qq.com", + "*.taobao.com" + ]; + + // Proxy addresses and domains (proxy list) + var proxy_list = [ + "google.com", + "*.google.com", + "*.youtube.com", + "*.facebook.com", + "*.twitter.com" + ]; + + // 1. Check if host is localhost or private IP, then direct connect + if (host === "localhost" || host === "127.0.0.1" || isPrivateIP(host)) { + log("Matched private/localhost IP: " + host + " -> DIRECT"); + return "DIRECT"; + } + + // 2. Check if host is in direct list (whitelist), then direct connect + for (var i = 0; i < direct_list.length; i++) { + if (shExpMatch(host, direct_list[i])) { + log("Matched direct list pattern: " + direct_list[i] + " for " + host + " -> DIRECT"); + return "DIRECT"; + } + } + + // 3. Check if host is in proxy list, then use proxy + for (var i = 0; i < proxy_list.length; i++) { + if (shExpMatch(host, proxy_list[i])) { + log("Matched proxy list pattern: " + proxy_list[i] + " for " + host + " -> PROXY"); + return "SOCKS5 127.0.0.1:1088"; // This port should match your sslocal listening port + } + } + + // 4. Default rule: all other traffic direct connect + log("No match found for " + host + " -> DIRECT (default)"); + return "DIRECT"; +} \ No newline at end of file