-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a little something to the readme
- Loading branch information
heikoschmidt
committed
Mar 9, 2024
1 parent
ee61378
commit ea04f8b
Showing
4 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,89 @@ | ||
# pypacer | ||
|
||
Generate auto proxy config files (PAC) from a declaration. | ||
# Generate auto proxy config files (PAC) from a declaration. | ||
|
||
[![Tests](https://github.com/73h/pypacer/actions/workflows/tests.yml/badge.svg)](https://github.com/73h/pypacer/actions/workflows/tests.yml) | ||
|
||
*-- Still at work --* | ||
--- | ||
|
||
This package aims to make it possible to create simple proxy scripts declaratively. It will never cover all the | ||
subtleties. If you have unusual requirements, it is better to write the proxy script directly in JavaScript | ||
|
||
## Usage | ||
|
||
ToDo: Build package and publish on pypi | ||
|
||
### Example | ||
|
||
example.yaml: | ||
|
||
```yaml | ||
description: A normal proxy script | ||
version: 1.0 | ||
default: PROXY_DEFAULT | ||
proxies: | ||
DIRECT: | ||
description: take the direct route | ||
route: "DIRECT" | ||
targets: | ||
- ".example.com" | ||
PROXY_NET_MASKS: | ||
description: take the proxy A route | ||
route: "PROXY netmask.example.com" | ||
targets: | ||
- "93.184.0.0/16" | ||
- "example.net" | ||
- "192.0.0.170" | ||
- "127.0.0.1" | ||
PROXY_COMPANY: | ||
description: take the proxy B route | ||
route: "PROXY company.example.com" | ||
targets: | ||
- "example.com" | ||
- "foo.example.com" | ||
- "bar.example.com" | ||
PROXY_DEFAULT: | ||
description: take the default proxy route | ||
route: "PROXY default.example.com" | ||
targets: [] | ||
|
||
``` | ||
|
||
run this in python: | ||
|
||
```python | ||
import os | ||
from pypacer import PyPacer | ||
|
||
p = PyPacer() | ||
with open(os.path.join("examples.yaml"), "r") as f: | ||
p.load_from_yaml(f.read()) | ||
print(p.output()) | ||
``` | ||
|
||
and you get this: | ||
|
||
```javascript | ||
function FindProxyForURL(url, host) { | ||
host = host.toLowerCase(); | ||
if ( | ||
localHostOrDomainIs(host, "example.com") | ||
|| localHostOrDomainIs(host, "foo.example.com") | ||
|| localHostOrDomainIs(host, "bar.example.com") | ||
) { | ||
return "PROXY company.example.com"; | ||
} | ||
if ( | ||
dnsDomainIs(host, ".example.com") | ||
) { | ||
return "DIRECT"; | ||
} | ||
if ( | ||
isInNet(host, "93.184.0.0", "255.255.0.0") | ||
|| localHostOrDomainIs(host, "example.net") | ||
|| isInNet(host, "192.0.0.170", "255.255.255.255") | ||
|| isInNet(host, "127.0.0.1", "255.255.255.255") | ||
) { | ||
return "PROXY netmask.example.com"; | ||
} | ||
return "PROXY default.example.com"; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters