This project is used to generate the proxy auto-configuration `proxy.pac` file, which can be used for configuring browser or system-level proxy settings.
Supports routing traffic through proxies: You can customize rules to route traffic to different proxy servers based on domain names or IP networks specified in the configuration files.
For high-performance matching: Uses a hash table for domain rules, and an IP prefix tree for fast matching of network rules. If there is no domain match, the IP address will be resolved and then matched against network rules.
- **Auto-Proxy Rules**: Add rules to `auto-proxy.txt` to control how websites are accessed.
All files starting with `auto-proxy` and ending with `.txt` will be parsed as Auto-Proxy rules. If you have multiple Auto-Proxy rules, you can save them as multiple files, like `auto-proxy-1.txt`, `auto-proxy-2.txt`, etc.
**Note**: Currently, the URL matching rules in Auto-Proxy are ignored, and only domain rules are handled.
Add your domains or IP networks to the appropriate file, one per line. Subdomains will inherit the proxy behavior of their parent domain. You can also add country-level top domains to simplify the configuration. Lines starting with `#` are treated as comments.
IPv4 Networks added to `ipv4-rules-direct.txt` will bypass the proxy and connect directly:
```
# Direct connect IPv4 networks
192.168.0.0/16
114.114.114.114/32 # To add a specific IP address, append /32 to the IP address
```
You can also create your own custom rule files, following the format `<domain|ipv4|ipv6>-rules-<rule_name>.txt`. For example, `domain-rules-companyProxy.txt` will make all domains in this file use the `companyProxy` setting defined in `proxy.pac`. `ipv4-rules-block.txt` will block all networks listed in the file.
- **Domain Regular Expressions**: `domain-regexp.txt` is used to define domain rules based on regular expressions, which allows for flexible matching of similar domains.
File structure:
```
[direct]
# host regex ...
[blocked]
# ...
[proxy]
# ...
```
Each section represents a different proxy behavior, which can be `direct`, `blocked`, `proxy`, or a custom behavior (e.g., `[companyProxy]`).
- **[direct]**: Domains matched by regular expressions in this section will bypass the proxy and connect directly.
- **[blocked]**: Domains matched by regular expressions in this section will be blocked.
- **[proxy]**: Domains matched by regular expressions in this section will use the default proxy.
- **Custom Behavior**: You can add your own section name, such as `[companyProxy]`, to indicate that domains matching those patterns will use a custom proxy configuration.
Each line is a regular expression for matching specific domains or their subdomains. Lines starting with `#` are treated as comments. For example:
```
[direct]
# Direct connection domains
^img-[0-9][0-9].*\.example\.com$
[blocked]
# Blocked domains
^ad-[a-z0-9]\.cdn[0-9]\.example\.com$
```
Ensure that the regular expressions are valid to avoid affecting normal network access.
The generated `proxy.pac` file uses the following default proxy configurations (note that the default proxy server is `SOCKS5 127.0.0.1:1080`):
```javascript
var proxyBehaviors = {
proxy: "SOCKS5 127.0.0.1:1080", // Default proxy
direct: DIRECT,
blocked: "PROXY 0.0.0.0:0",
"http_proxy": "PROXY 127.0.0.1:3128",
"companyProxy": "PROXY 192.168.1.1:8080", // Domains in `domain-rules-companyProxy.txt` will use this proxy setting
};
```
You can modify these values after generating `proxy.pac`, or customize them directly in the original script `proxy.js` to use different default settings. Please adjust these settings according to your environment and requirements.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the [GNU General Public License](./LICENSE) along with this program. If not, see <https://www.gnu.org/licenses/>.