Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
b8b1895
Fixing Haproxy and start preparing for sniproxy
matthias1232 Jul 22, 2022
45cb640
config json
matthias1232 Jul 22, 2022
9566580
sniproxy
matthias1232 Jul 22, 2022
325292e
Update config-sample.json
matthias1232 Jul 22, 2022
ced42ab
test
matthias1232 Jul 22, 2022
b517aca
Update __init__.py
matthias1232 Jul 22, 2022
54a722a
Update dnsproxy.py
matthias1232 Jul 22, 2022
d5b7e53
Update sniproxy.py
matthias1232 Jul 22, 2022
112579c
Update sniproxy.py
matthias1232 Jul 22, 2022
8d20283
Update sniproxy.py
matthias1232 Jul 22, 2022
45e1c49
Update sniproxy.py
matthias1232 Jul 22, 2022
a2a0190
Update sniproxy.py
matthias1232 Jul 22, 2022
3cfab01
Update sniproxy.py
matthias1232 Jul 22, 2022
6fe36c5
Update sniproxy.py
matthias1232 Jul 22, 2022
bd65ef2
Update sniproxy.py
matthias1232 Jul 22, 2022
e8464a6
Update sniproxy.py
matthias1232 Jul 22, 2022
6ae4767
Update sniproxy.py
matthias1232 Jul 22, 2022
26afe76
Update sniproxy.py
matthias1232 Jul 22, 2022
283d883
Update sniproxy.py
matthias1232 Jul 22, 2022
0ea6e81
Update sniproxy.py
matthias1232 Jul 22, 2022
1975b46
Update sniproxy.py
matthias1232 Jul 22, 2022
ae3510a
Update sniproxy.py
matthias1232 Jul 22, 2022
b2e6820
Update sniproxy.py
matthias1232 Jul 22, 2022
4025cd9
Update README.md
matthias1232 Jul 22, 2022
d05c1cb
Update sniproxy.py
matthias1232 Jul 24, 2022
b5f16d1
Update sniproxy.py
matthias1232 Jul 24, 2022
e9b724b
Update sniproxy.py
matthias1232 Jul 24, 2022
775ab19
Update sniproxy.py
matthias1232 Jul 24, 2022
cd6253a
Update sniproxy.py
matthias1232 Jul 24, 2022
e1f0ca4
Update sniproxy.py
matthias1232 Jul 24, 2022
c2f4c59
Update sniproxy.py
matthias1232 Jul 24, 2022
27bdb83
Update sniproxy.py
matthias1232 Jul 24, 2022
79b597b
Update sniproxy.py
matthias1232 Jul 24, 2022
5f5e6a0
Update sniproxy.py
matthias1232 Jul 24, 2022
2fb98b5
Update sniproxy.py
matthias1232 Jul 24, 2022
17a6963
Update sniproxy.py
matthias1232 Jul 24, 2022
e557d59
Update sniproxy.py
matthias1232 Jul 24, 2022
afea531
Update sniproxy.py
matthias1232 Jul 24, 2022
587077a
Update sniproxy.py
matthias1232 Jul 24, 2022
c97d8fe
Update sniproxy.py
matthias1232 Jul 24, 2022
ae88498
Update sniproxy.py
matthias1232 Jul 24, 2022
16221b1
Update sniproxy.py
matthias1232 Jul 24, 2022
456d57a
Update sniproxy.py
matthias1232 Jul 24, 2022
48fa2aa
Update sniproxy.py
matthias1232 Jul 24, 2022
ad73d6e
Update sniproxy.py
matthias1232 Jul 24, 2022
1af14d6
Update sniproxy.py
matthias1232 Jul 24, 2022
1d5f118
Update sniproxy.py
matthias1232 Jul 24, 2022
73a2ef6
Update sniproxy.py
matthias1232 Jul 24, 2022
789eec3
Update sniproxy.py
matthias1232 Jul 24, 2022
a5ce5dd
Update sniproxy.py
matthias1232 Jul 24, 2022
86adc8e
Update sniproxy.py
matthias1232 Jul 24, 2022
7462353
Update sniproxy.py
matthias1232 Jul 24, 2022
f898e9e
Update sniproxy.py
matthias1232 Jul 24, 2022
dc6aed0
Update sniproxy.py
matthias1232 Jul 24, 2022
2be9847
Update sniproxy.py
matthias1232 Jul 24, 2022
788d1d9
Update sniproxy.py
matthias1232 Jul 24, 2022
690d30e
Update sniproxy.py
matthias1232 Jul 24, 2022
d23f5e2
Update sniproxy.py
matthias1232 Jul 24, 2022
4ceb4f3
Update hosts.py
matthias1232 Jul 24, 2022
ce6bed3
o
matthias1232 Jul 24, 2022
150ca82
Update sniproxy.py
matthias1232 Jul 24, 2022
07e9d6e
Update sniproxy.py
matthias1232 Jul 24, 2022
a147271
Update sniproxy.py
matthias1232 Jul 24, 2022
04ba070
Update sniproxy.py
matthias1232 Jul 24, 2022
3f52120
Update sniproxy.py
matthias1232 Jul 24, 2022
4e82527
Update sniproxy.py
matthias1232 Jul 24, 2022
b3958fa
Update sniproxy.py
matthias1232 Jul 24, 2022
41c7f8f
Update sniproxy.py
matthias1232 Jul 24, 2022
b181878
Update sniproxy.py
matthias1232 Jul 24, 2022
df61852
Update sniproxy.py
matthias1232 Jul 24, 2022
55ff24a
Update sniproxy.py
matthias1232 Jul 24, 2022
723bf4d
Update sniproxy.py
matthias1232 Jul 24, 2022
4f6b9ef
Update sniproxy.py
matthias1232 Jul 24, 2022
b53c9d6
Update sniproxy.py
matthias1232 Jul 24, 2022
9dbf1fa
Update sniproxy.py
matthias1232 Jul 24, 2022
d1ed095
Update sniproxy.py
matthias1232 Jul 24, 2022
7217e05
Update sniproxy.py
matthias1232 Jul 24, 2022
6b1c656
Update sniproxy.py
matthias1232 Jul 24, 2022
262a8f1
Update sniproxy.py
matthias1232 Jul 24, 2022
af38540
Update sniproxy.py
matthias1232 Jul 24, 2022
474af64
Update sniproxy.py
matthias1232 Jul 24, 2022
3245b46
Update sniproxy.py
matthias1232 Jul 24, 2022
24fb5b7
Update sniproxy.py
matthias1232 Jul 24, 2022
cbba560
Update sniproxy.py
matthias1232 Jul 24, 2022
4acb3d5
Update sniproxy.py
matthias1232 Jul 24, 2022
420616a
Update sniproxy.py
matthias1232 Jul 24, 2022
f408c6c
Update sniproxy.py
matthias1232 Jul 24, 2022
ee0e3b1
Update sniproxy.py
matthias1232 Jul 24, 2022
06ed75e
Update sniproxy.py
matthias1232 Jul 24, 2022
6b0803e
Update sniproxy.py
matthias1232 Jul 24, 2022
50d382b
Update sniproxy.py
matthias1232 Jul 24, 2022
1e6bdaf
Update sniproxy.py
matthias1232 Jul 24, 2022
5467416
Update sniproxy.py
matthias1232 Jul 24, 2022
9cf8a8c
Update sniproxy.py
matthias1232 Jul 24, 2022
eb851e6
Update sniproxy.py
matthias1232 Jul 24, 2022
bd9995c
Update sniproxy.py
matthias1232 Jul 24, 2022
4829841
Update sniproxy.py
matthias1232 Jul 24, 2022
0e5ea50
Update sniproxy.py
matthias1232 Jul 24, 2022
b6f495f
Update sniproxy.py
matthias1232 Jul 24, 2022
2179c0e
Update sniproxy.py
matthias1232 Jul 24, 2022
822cdc5
Update sniproxy.py
matthias1232 Jul 24, 2022
4575c2c
Update sniproxy.py
matthias1232 Jul 24, 2022
3a9837f
Update sniproxy.py
matthias1232 Jul 24, 2022
ba870c9
Update sniproxy.py
matthias1232 Jul 24, 2022
311bc06
Update sniproxy.py
matthias1232 Jul 24, 2022
8132b86
Update sniproxy.py
matthias1232 Jul 24, 2022
aae54e4
Update sniproxy.py
matthias1232 Jul 24, 2022
397ac00
Update sniproxy.py
matthias1232 Jul 24, 2022
1b1b6ff
Update sniproxy.py
matthias1232 Jul 24, 2022
5f5a6d2
Update sniproxy.py
matthias1232 Jul 24, 2022
e5ec6c2
Update dnsmasq.py
matthias1232 Jul 24, 2022
82e4eaa
Update dnsmasq.py
matthias1232 Jul 24, 2022
3794f13
Update dnsmasq.py
matthias1232 Jul 24, 2022
54f8018
Update dnsmasq.py
matthias1232 Jul 24, 2022
8dab078
Update sniproxy.py
matthias1232 Jul 24, 2022
d0a316f
dns list
matthias1232 Jul 24, 2022
c4be88d
Domain List to Json generator
matthias1232 Jul 25, 2022
22162d1
Update domains.lst
matthias1232 Jul 25, 2022
4f71895
Update domains.lst
matthias1232 Jul 25, 2022
661cc22
Change Country CH
matthias1232 Jul 25, 2022
48b4dd7
Create proxies-ch.json
matthias1232 Jul 25, 2022
fbba989
Update README.md
matthias1232 Jul 25, 2022
d24d0d6
Update README.md
matthias1232 Jul 25, 2022
6e9b39f
Update README.md
matthias1232 Jul 25, 2022
59869bb
Update README.md
matthias1232 Jul 25, 2022
3909630
Update README.md
matthias1232 Jul 25, 2022
609860a
Update README.md
matthias1232 Jul 25, 2022
165ccd7
Update README.md
matthias1232 Jul 25, 2022
dab1824
Update README.md
matthias1232 Jul 25, 2022
c003196
Update README.md
matthias1232 Jul 25, 2022
75d67b8
Update README.md
matthias1232 Jul 25, 2022
f613d99
Update README.md
matthias1232 Jul 25, 2022
b9be2cc
Update README.md
matthias1232 Jul 25, 2022
fe206d6
Update README.md
matthias1232 Jul 25, 2022
b85b4a9
Update README.md
matthias1232 Jul 25, 2022
cf2352e
Update domains.lst
matthias1232 Oct 11, 2022
ee546b4
Update domains.lst
matthias1232 Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ docs/_build/
# PyBuilder
target/

config.json


*.conf
77 changes: 47 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
dnsproxy
========

This project is still in beta! It currently works well, but some changes may be expected.
Project Based on https://github.com/jamiees2/dnsproxy

This is based on @trick77's original work on [tunlr-style-dns-unblocking](https://github.com/trick77/tunlr-style-dns-unblocking/)
Added sniproxy and domain list to route specific Domains to the proxy.

The purpose for this project is to make it easy to set up a fast smart DNS service on your own. It is possible to get a US VPS for 1$/mo which is well under the current 4$/mo for most smart DNS services. It is also potentially alot faster, as you then have a whole proxy server to yourself.
Unblock:

Another purpose is privacy. By changing your DNS servers, you allow whoever is on the other side to see almost all the websites you visit. Some providers explicitly state in their TOS that they log everything, which gives them control over your data. A better option is that you control those servers.
Zattoo

Wilmaa

Teleboy

Blue TV (Swisscom)

....and many more.

Prerequisites:
- A VPS based in the country you want, preferrably running Ubuntu 14.04. A 128MB server is enough.
- A VPS based in the country you want, preferrably running Ubuntu 20.04. A 128MB server is enough.
- python
- haproxy

For `sni` and `dnat` setup:
- sniproxy
- dnsmasq


The configuration generator (dnsproxy.py) offers three different possibilities for setup:
- [sni (Simple Setup)](https://github.com/jamiees2/dnsproxy/wiki/SNI-Setup)
- [dnat (Advanced Setup)](https://github.com/jamiees2/dnsproxy/wiki/DNAT-Setup)
- [local (Advanced Setup)](https://github.com/jamiees2/dnsproxy/wiki/Local-Setup)
- manual (Default)
The configuration generator (dnsproxy.py) offers works with sniproxy with the following Setup:
- [sni (Simple Setup)](https://github.com/jamiees2/dnsproxy/wiki/SNI-Setup) (You dont need HAProxy, as we use sniproxy in our project Fork)


You can generate each configuration file separately with `-o`. Example:

```python dnsproxy.py -o sniproxy```

```python dnsproxy.py -o dnsmasq```

You can also generate a Hosts file for your Client, then you can skip dnsmasq.

```python dnsproxy.py -o hosts```


Copy and overwrite the generated configs for sniproxy and dnsmasq.
Restart the Service and your dns Proxy should be up and running.

You can generate each configuration file separately with `-m manual`. Example:
```python dnsproxy.py -m manual -o haproxy```. `-m manual` is also default, so this can be simplified to ```python dnsproxy.py -o haproxy```.
Now just point your DNS Entries to your VPS and the traffic for the needed Domains goes through the Proxy.

It is also possible to specify which proxy list you would like to use, based on country. You can specify that by passing `-c <country>`, where `<country>` is a suffix of any file in the `proxies/` directory. For example, if you wish to generate configuration for a uk based SNI proxy, you can run `python dnsproxy.py -c uk -m sni`. The default country is `us`.
It is also possible to specify which proxy list you would like to use, based on country. You can specify that by passing `-c <country>`, where `<country>` is a suffix of any file in the `proxies/` directory. For example, if you wish to generate configuration for a uk based SNI proxy, you can run `python dnsproxy.py -c uk -m sni`. The default country is `ch`.

Check the wiki for additional information, along with these links by @trick77:
- http://trick77.com/2014/03/01/tunlr-style-dns-unblocking-pandora-netflix-hulu-et-al/
- http://trick77.com/2014/03/02/dns-unblocking-using-dnsmasq-haproxy/

*If you would like to add a service, please send a pull request.*

Output of `dnsproxy.py -h`:
```
usage: dnsproxy.py [-h] [-m {manual,sni,dnat,local}]
[-o {dnsmasq,haproxy,netsh,hosts,rinetd,iptables} [{dnsmasq,haproxy,netsh,hosts,rinetd,iptables} ...]]
[-c COUNTRY] [-d] [--no-test] [--ip IP] [--bind-ip BIND_IP]
[--base-ip BASE_IP] [--base-port BASE_PORT] [--save]
[--output-dir OUTPUT_DIR] [--only [ONLY [ONLY ...]]]
[--skip [SKIP [SKIP ...]]]
[-o {dnsmasq,haproxy,netsh,hosts,rinetd,iptables,iproute2,sniproxy}]
[-c COUNTRY [COUNTRY ...]] [-d] [--ip IP]
[--bind-ip BIND_IP] [--base-ip BASE_IP]
[--base-port BASE_PORT] [--save] [--output-dir OUTPUT_DIR]
[--only [ONLY [ONLY ...]]] [--skip [SKIP [SKIP ...]]]
[--dnsmasq-filename DNSMASQ_FILENAME]
[--haproxy-filename HAPROXY_FILENAME]
[--sniproxy-filename SNIPROXY_FILENAME]
[--iptables-filename IPTABLES_FILENAME]
[--iproute2-filename IPROUTE2_FILENAME]
[--netsh-filename NETSH_FILENAME]
[--hosts-filename HOSTS_FILENAME]
[--rinetd-filename RINETD_FILENAME]
Expand All @@ -57,16 +72,14 @@ optional arguments:
-h, --help show this help message and exit
-m {manual,sni,dnat,local}, --mode {manual,sni,dnat,local}
Presets for configuration file generation.
-o {dnsmasq,haproxy,netsh,hosts,rinetd,iptables} [{dnsmasq,haproxy,netsh,hosts,rinetd,iptables} ...], --output {dnsmasq,haproxy,netsh,hosts,rinetd,iptables} [{dnsmasq,haproxy,netsh,hosts,rinetd,iptables} ...]
-o {dnsmasq,haproxy,netsh,hosts,rinetd,iptables,iproute2,sniproxy}, --output {dnsmasq,haproxy,netsh,hosts,rinetd,iptables,iproute2,sniproxy}
Which configuration file(s) to generate. This is
ignored when not in manual mode.
-c COUNTRY, --country COUNTRY
The country to use for generating the configuration.
-c COUNTRY [COUNTRY ...], --country COUNTRY [COUNTRY ...]
The country/-ies to use for generating the
configuration (space-separated, e.g. -c us uk).
-d, --dnat Specify to use DNAT instead of SNI (Advanced). This is
ignored when not in manual mode.
--no-test Specify to skip generating test configuration. This
means that you will not be able to test your setup
with the setup tester.
--ip IP Specify the public IP to use
--bind-ip BIND_IP Specify the IP that haproxy should bind to
--base-ip BASE_IP Specify the base IP from which DNAT should start
Expand All @@ -86,8 +99,12 @@ optional arguments:
Specify the DNS configuration file name
--haproxy-filename HAPROXY_FILENAME
Specify the haproxy configuration file name
--sniproxy-filename SNIPROXY_FILENAME
Specify the sniproxy configuration file name
--iptables-filename IPTABLES_FILENAME
Specify the iptables configuration file name
--iproute2-filename IPROUTE2_FILENAME
Specify the iproute2 configuration file name
--netsh-filename NETSH_FILENAME
Specify the netsh configuration file name
--hosts-filename HOSTS_FILENAME
Expand Down
2 changes: 1 addition & 1 deletion config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"base_port": 27200, // Only required for mode "dnat"
// "local_subnet": 24, // Only required for mode "dnat"
// "local_device": "eth1", // Only required for mode "dnat"
"server_options": "check inter 10s fastinter 2s downinter 2s fall 1800", // Don't touch unless you know what you're doing
"server_options": "check init-addr none resolvers mydns", // Don't touch unless you know what you're doing
"stats": {
"enabled": true, // Set to true to enable HAProxy stats web page
"port": 27199,
Expand Down
18 changes: 18 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"iptables_location": "iptables", // Required to generate iptables rules in mode "dnat"
"bind_ip": "*", // The IP address to bind to
"public_ip": "", // IP address of your remote server, required for every mode
"base_ip": "",
// "base_ip": "x.x.x.x", // Only required for modes "dnat" and "local"
// "base_ip": "127.0.0.51", // For local
"base_port": 27200, // Only required for mode "dnat"
// "local_subnet": 24, // Only required for mode "dnat"
// "local_device": "eth1", // Only required for mode "dnat"
"server_options": "check init-addr none resolvers mydns", // Don't touch unless you know what you're doing
"stats": {
"enabled": true, // Set to true to enable HAProxy stats web page
"port": 27199,
"user": "haproxy",
"password": "123456"
}
}
15 changes: 11 additions & 4 deletions dnsproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main(args):

# Choose from the available modes
if args.mode == "sni":
files = ["haproxy", "dnsmasq", "hosts"]
files = ["haproxy", "dnsmasq", "hosts", "sniproxy"]
dnat = False
elif args.mode == "dnat":
files = ["haproxy", "dnsmasq", "hosts", "iptables", "iproute2"]
Expand Down Expand Up @@ -156,7 +156,13 @@ def main(args):
print_ips(config)

for output in set(files):
if output == "haproxy":
if output == "sniproxy":
print_firewall(config, dnat=dnat)
print ""
sniproxy_content = generators.generate_sniproxy(config, dnat=dnat)
util.put_contents(args.sniproxy_filename, sniproxy_content, base_dir=args.output_dir)
print 'File generated: ' + args.sniproxy_filename
elif output == "haproxy":
print_firewall(config, dnat=dnat)
if config["stats"]["enabled"] and not config["stats"]["password"]:
print ""
Expand Down Expand Up @@ -212,8 +218,8 @@ def main(args):
parser = argparse.ArgumentParser(description="Generate configuration files to setup a tunlr style smart DNS")

parser.add_argument("-m", "--mode", choices=["manual", "sni", "dnat", "local"], default="manual", type=str, help="Presets for configuration file generation.")
parser.add_argument("-o", "--output", choices=["dnsmasq", "haproxy", "netsh", "hosts", "rinetd", "iptables", "iproute2"], default=["haproxy"], action="append", help="Which configuration file(s) to generate. This is ignored when not in manual mode.")
parser.add_argument("-c", "--country", default="us", type=str, nargs="+", help="The country/-ies to use for generating the configuration (space-separated, e.g. -c us uk).")
parser.add_argument("-o", "--output", choices=["dnsmasq", "haproxy", "netsh", "hosts", "rinetd", "iptables", "iproute2", "sniproxy"], default=["sniproxy"], action="append", help="Which configuration file(s) to generate. This is ignored when not in manual mode.")
parser.add_argument("-c", "--country", default="ch", type=str, nargs="+", help="The country/-ies to use for generating the configuration (space-separated, e.g. -c us uk).")
parser.add_argument("-d", "--dnat", action="store_true", help="Specify to use DNAT instead of SNI (Advanced). This is ignored when not in manual mode.")

parser.add_argument("--ip", type=str, default=None, help="Specify the public IP to use")
Expand All @@ -229,6 +235,7 @@ def main(args):

parser.add_argument("--dnsmasq-filename", type=str, default="dnsmasq-haproxy.conf", help="Specify the DNS configuration file name")
parser.add_argument("--haproxy-filename", type=str, default="haproxy.conf", help="Specify the haproxy configuration file name")
parser.add_argument("--sniproxy-filename", type=str, default="sniproxy.conf", help="Specify the sniproxy configuration file name")
parser.add_argument("--iptables-filename", type=str, default="iptables-haproxy.sh", help="Specify the iptables configuration file name")
parser.add_argument("--iproute2-filename", type=str, default="iproute2-haproxy.sh", help="Specify the iproute2 configuration file name")
parser.add_argument("--netsh-filename", type=str, default="netsh-haproxy.cmd", help="Specify the netsh configuration file name")
Expand Down
1 change: 1 addition & 0 deletions generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from haproxy import generate as generate_haproxy
from sniproxy import generate as generate_sniproxy
from dnsmasq import generate as generate_dnsmasq
from iptables import generate as generate_iptables
from iproute2 import generate as generate_iproute2
Expand Down
9 changes: 6 additions & 3 deletions generators/dnsmasq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ def generate(config, dnat=False):

for chunk in c:
if not dnat:
dnsmasq_content += generate_dns(chunk, public_ip)

dnsmasq_contentwld = generate_dns(chunk, public_ip)
dnsmasq_content += dnsmasq_contentwld.replace("*", "")

else:
dnsmasq_content += generate_dns(chunk, current_ip)

dnsmasq_contentwld += generate_dns(chunk, current_ip)
dnsmasq_content = dnsmasq_contentwld.replace("*", "")
if dnat:
for group in config["groups"].values():
for proxy in group["proxies"]:
Expand Down
12 changes: 10 additions & 2 deletions generators/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def generate(config, dnat=False):
current_port = config["base_port"]
elif dnat:
return

haproxy_content = generate_global()
haproxy_content = generate_mydns()
haproxy_content += generate_global()
haproxy_content += generate_defaults()

if not dnat:
Expand Down Expand Up @@ -85,6 +85,14 @@ def generate_backend_catchall_entry(domain, mode, port, server_options, override
return result


def generate_mydns():
result = fmt('resolvers mydns', indent=None)
result += fmt('nameserver dns1 8.8.8.8:53')
result += fmt('nameserver dns2 8.8.4.4:53')
result += os.linesep
return result


def generate_global():
result = fmt('global', indent=None)
result += fmt('daemon')
Expand Down
103 changes: 103 additions & 0 deletions generators/sniproxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from util import fmt, port, chunks
import os

def generate_startconfig01():
result = fmt('# sniproxy example configuration file', indent=None)
result += fmt('# lines that start with # are comments', indent=None)
result += fmt('# lines with only white space are ignored', indent=None)
result += fmt('', indent=None)
result += fmt('user daemon', indent=None)
result += fmt('', indent=None)
result += fmt('# PID file', indent=None)
result += fmt('pidfile /var/run/sniproxy.pid', indent=None)
result += os.linesep
return result

def generate_mydns():
result = fmt('resolver {', indent=None)
result += fmt('nameserver 8.8.8.8')
result += fmt('nameserver 8.8.4.4')
result += fmt('mode ipv4_only')
result += fmt('}', indent=None)
result += os.linesep
return result

def generate_error():
result = fmt('error_log {', indent=None)
result += fmt('# Log to the daemon syslog facility')
result += fmt('syslog daemon')
result += fmt('', indent=None)
result += fmt('# Alternatively we could log to file')
result += fmt('#filename /var/log/sniproxy/sniproxy.log')
result += fmt('', indent=None)
result += fmt('# Control the verbosity of the log')
result += fmt('priority notice')
result += fmt('}', indent=None)
result += os.linesep
return result

def generate_listenhttp():
result = fmt('# blocks are delimited with {...}', indent=None)
result += fmt('listen 80 {', indent=None)
result += fmt('proto http')
result += fmt('table hosts')
result += fmt('# Fallback backend server to use if we can not parse the client request')
result += fmt('fallback localhost:8080')
result += fmt('', indent=None)
result += fmt('access_log {')
result += fmt('filename /var/log/sniproxy/http_access.log')
result += fmt('priority notice')
result += fmt('}')
result += fmt('}', indent=None)
result += os.linesep
return result

def generate_listentls():
result = fmt('# blocks are delimited with {...}', indent=None)
result += fmt('listen 443 {', indent=None)
result += fmt('proto tls')
result += fmt('table hosts')
result += fmt('', indent=None)
result += fmt('access_log {')
result += fmt('filename /var/log/sniproxy/https_access.log')
result += fmt('priority notice')
result += fmt('}')
result += fmt('}', indent=None)
result += os.linesep
return result


def generate_hosts01():
result = fmt('table hosts{', indent=None)
return result

def generate_hosts02():
result = fmt('# .* *')
result += fmt('}', indent=None)
result += os.linesep
return result

def generate(config, dnat=False):
sniproxy_content = ""
sniproxy_content += generate_startconfig01()
sniproxy_content += generate_mydns()
sniproxy_content += generate_error()
sniproxy_content += generate_listenhttp()
sniproxy_content += generate_listentls()
sniproxy_content += generate_hosts01()

for group in config["groups"].values():
for proxy in group["proxies"]:
proxy["domain2"] = proxy["domain"].replace('.','\.')
if (proxy["domain"].startswith('*')):
sniproxy_content += ' .' + proxy["domain2"] + '$ ' + '*' + '\n'
else:
sniproxy_content += ' ^' + proxy["domain2"] + ' ' + proxy["domain"] + '\n'




sniproxy_content += generate_hosts02()


return sniproxy_content
Loading