Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Generate auto proxy config files (PAC) from a declaration

License

NotificationsYou must be signed in to change notification settings

73h/paccreator

Repository files navigation

Tests


This package aims to make it possible to create simple proxy scripts declaratively. It will never cover all thesubtleties. If you have unusual requirements, it is better to write the proxy script directly in JavaScript

Usage

You can install the package with pip.

pip install paccreator

You can also load the script directly from github with pip.

pip install git+https://github.com/73h/paccreator.git@main#egg=paccreator

Create a file called myproxy.yaml and define your proxy rules in it like this.

description:A description of proxy script# (optional, default=pac file for my company)version:The version of proxy script# (optional, default=0.1)proxies:  -route:DIRECTdescription:A description of proxy# (optional, default=use this proxy)tags:# (optional) Here you can add any comments you like, which you can use to filter later. However, there are also standard annotations.      -default# (optional) This marks the proxy as default if no other condition applies. if no default proxy is available, the first one is used.      -catch-plain-hostnames# (optional) This proxy applies if there is no domain name in the hostname (no dots). You should not annotate this on several proxies.targets:      -example.com      -foo.example.com      -.example.net# You can also use a network mask, ip-addresses, hosts or strings  -route:PROXY proxy1.example.com:80; DIRECTtargets:      -10.0.0.0/8

Run this in python.

importosfrompaccreatorimportPacCreatorp=PacCreator()withopen(os.path.join("myproxy.yaml"),"r")asf:p.load_from_yaml(f.read())print(p.output())

You can also use with contextmanager.

importosfrompaccreatorimportload_from_yamlwithopen(os.path.join("myproxy.yaml"),"r")asf:withload_from_yaml(f.read())asp:print(p.output())

Examples

A simple Example for a random company

yaml file

description:Simple proxyproxies:  -description:use direct connectionroute:DIRECTtargets:      -10.0.0.0/8      -.my-company.com  -description:use my proxyroute:PROXY proxy.my-company.com:80tags:      -defaulttargets:      -www.my-company.com      -contact.my-company.com  -description:use the special proxyroute:PROXY proxy.my-company.com:8080targets:      -datacenter.my-company.com

As a result, you can see that it has resolved the overlap between.my-company.com and,for example,contact.my-company.com by first evaluating the exact subdomains.The network mask10.0.0.0/8 was placed at the end to avoid DNS queries when they are not necessary.

functionFindProxyForURL(url,host){/*        Description: Simple proxy        Version: 0.1    */host=host.toLowerCase();if(localHostOrDomainIs(host,"www.my-company.com")||localHostOrDomainIs(host,"contact.my-company.com")){/* use my proxy */return"PROXY proxy.my-company.com:80";}if(localHostOrDomainIs(host,"datacenter.my-company.com")){/* use the special proxy */return"PROXY proxy.my-company.com:8080";}if(dnsDomainIs(host,".my-company.com")){/* use direct connection */return"DIRECT";}if(isInNet(host,"10.0.0.0","255.0.0.0")){/* use direct connection */return"DIRECT";}/* Default: use my proxy */return"PROXY proxy.my-company.com:80";}

Unit Tests Example

You can see all the options supported so far in the test examples.

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp