You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 20KB

5 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
9 years ago
9 years ago
8 years ago
7 years ago
7 years ago
6 years ago
6 years ago
5 years ago
9 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
9 years ago
8 years ago
6 years ago
5 years ago
8 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. # OpenVPN and Deluge with Deluge Web
  2. This container contains OpenVPN and Deluge with a configuration
  3. where Deluge is running only when OpenVPN has an active tunnel.
  4. It bundles configuration files for many popular VPN providers to make the setup easier.
  5. Based wholy on the work of transmission with openvpn by haugene at https://github.com/haugene/docker-transmission-openvpn
  6. Note also this is partially complete so your mileage may vary
  7. You will need to specify your provider and credentials with environment variables,
  8. as well as mounting volumes where the data should be stored.
  9. An example run command to get you going is provided below.
  10. Also worth mentioning.
  11. If you want to route web traffic through the same tunnel that Deluge is using there
  12. is a pre-installed Tinyproxy which will expose a proxy on port 8888 when enabled.
  13. And if you're using PIA as provider it will update Deluge hourly with assigned open port - TBC
  14. GL HF! And if you run into problems, please check the README twice and maybe try the gitter chat before opening an issue :)
  15. ### about:maintenance
  16. This image was created for my own use, but sharing is caring so it had to be open source.
  17. The number of users, issues and pull-requests have gone up quite drastically since that
  18. and that's great! It's been a lot of fun watching the activity level go up
  19. and my pet project improve with it.
  20. Maintaining this takes time, so like donating, please donate to the originating author, here's a button:
  21. [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=73XHRSK65KQYC)
  22. You can also help out by submitting pull-requests or helping others with
  23. open issues or in the gitter chat. A big thanks to everyone who has contributed so far!
  24. And if you could be interested in joining as collaborator, let me know.
  25. ## Run container from Github
  26. To run the container use this command:
  27. ```
  28. $ docker build --cap-add=NET_ADMIN --device=/dev/net/tun -d \
  29. -v /your/storage/path/:/data \
  30. -v /etc/localtime:/etc/localtime:ro \
  31. -e OPENVPN_PROVIDER=PIA \
  32. -e OPENVPN_CONFIG=Netherlands \
  33. -e OPENVPN_USERNAME=user \
  34. -e OPENVPN_PASSWORD=pass \
  35. -e WEBPROXY_ENABLED=false \
  36. -e LOCAL_NETWORK=192.168.0.0/16 \
  37. --log-driver json-file \
  38. --log-opt max-size=10m \
  39. -p 9091:9091 \
  40. uri:https://github.com/sscraggles/docker-deluge-openvpn/
  41. ```
  42. You must set the environment variables `OPENVPN_PROVIDER`, `OPENVPN_USERNAME` and `OPENVPN_PASSWORD` to provide basic connection details.
  43. The `OPENVPN_CONFIG` is an optional variable. If no config is given, a default config will be selected for the provider you have chosen.
  44. Find available OpenVPN configurations by looking in the openvpn folder of the GitHub repository. The value that you should use here is the filename of your chosen openvpn configuration *without* the .ovpn file extension. For example:
  45. ```
  46. -e "OPENVPN_CONFIG=ipvanish-AT-Vienna-vie-c02"
  47. ```
  48. You can also provide a comma separated list of openvpn configuration filenames.
  49. If you provide a list, a file will be randomly chosen in the list, this is useful for redundancy setups. For example:
  50. ```
  51. -e "OPENVPN_CONFIG=ipvanish-AT-Vienna-vie-c02,ipvanish-FR-Paris-par-a01,ipvanish-DE-Frankfurt-fra-a01"
  52. ```
  53. If you provide a list and the selected server goes down, after the value of ping-timeout the container will be restarted and a server will be randomly chosen, note that the faulty server can be chosen again, if this should occur, the container will be restarted again until a working server is selected.
  54. To make sure this work in all cases, you should add ```--pull-filter ignore ping``` to your OPENVPN_OPTS variable.
  55. As you can see, the container also expects a data volume to be mounted.
  56. This is where Transmission will store your downloads, incomplete downloads and look for a watch directory for new .torrent files.
  57. By default a folder named transmission-home will also be created under /data, this is where Transmission stores its state.
  58. ### Supported providers
  59. This is a list of providers that are bundled within the image. Feel free to create an issue if your provider is not on the list, but keep in mind that some providers generate config files per user. This means that your login credentials are part of the config an can therefore not be bundled. In this case you can use the custom provider setup described later in this readme. The custom provider setting can be used with any provider.
  60. | Provider Name | Config Value (`OPENVPN_PROVIDER`) |
  61. |:-----------------------------|:-------------|
  62. | Anonine | `ANONINE` |
  63. | AnonVPN | `ANONVPN` |
  64. | BlackVPN | `BLACKVPN` |
  65. | BTGuard | `BTGUARD` |
  66. | Cryptostorm | `CRYPTOSTORM` |
  67. | Cypherpunk | `CYPHERPUNK` |
  68. | FrootVPN | `FROOT` |
  69. | FrostVPN | `FROSTVPN` |
  70. | Giganews | `GIGANEWS` |
  71. | HideMe | `HIDEME` |
  72. | HideMyAss | `HIDEMYASS` |
  73. | IntegrityVPN | `INTEGRITYVPN` |
  74. | IPredator | `IPREDATOR` |
  75. | IPVanish | `IPVANISH` |
  76. | Ivacy | `IVACY` |
  77. | IVPN | `IVPN` |
  78. | Mullvad | `MULLVAD` |
  79. | Newshosting | `NEWSHOSTING` |
  80. | NordVPN | `NORDVPN` |
  81. | OVPN | `OVPN` |
  82. | Perfect Privacy | `PERFECTPRIVACY` |
  83. | Private Internet Access | `PIA` |
  84. | PrivateVPN | `PRIVATEVPN` |
  85. | proXPN | `PROXPN` |
  86. | PureVPN | `PUREVPN` |
  87. | RA4W VPN | `RA4W` |
  88. | SaferVPN | `SAFERVPN` |
  89. | SlickVPN | `SLICKVPN` |
  90. | Smart DNS Proxy | `SMARTDNSPROXY` |
  91. | SmartVPN | `SMARTVPN` |
  92. | TigerVPN | `TIGER` |
  93. | TorGuard | `TORGUARD` |
  94. | TunnelBear | `TUNNELBEAR`|
  95. | UsenetServerVPN | `USENETSERVER` |
  96. | Windscribe | `WINDSCRIBE` |
  97. | VPNArea.com | `VPNAREA` |
  98. | VPN.AC | `VPNAC` |
  99. | VPN.ht | `VPNHT` |
  100. | VPNBook.com | `VPNBOOK` |
  101. | VPNTunnel | `VPNTUNNEL` |
  102. | VyprVpn | `VYPRVPN` |
  103. ### Required environment options
  104. | Variable | Function | Example |
  105. |----------|----------|-------|
  106. |`OPENVPN_PROVIDER` | Sets the OpenVPN provider to use. | `OPENVPN_PROVIDER=provider`. Supported providers and their config values are listed in the table above. |
  107. |`OPENVPN_USERNAME`|Your OpenVPN username |`OPENVPN_USERNAME=asdf`|
  108. |`OPENVPN_PASSWORD`|Your OpenVPN password |`OPENVPN_PASSWORD=asdf`|
  109. ### Network configuration options
  110. | Variable | Function | Example |
  111. |----------|----------|-------|
  112. |`OPENVPN_CONFIG` | Sets the OpenVPN endpoint to connect to. | `OPENVPN_CONFIG=UK Southampton`|
  113. |`OPENVPN_OPTS` | Will be passed to OpenVPN on startup | See [OpenVPN doc](https://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html) |
  114. |`LOCAL_NETWORK` | Sets the local network that should have access. Accepts comma separated list. | `LOCAL_NETWORK=192.168.0.0/24`|
  115. ### Firewall configuration options
  116. When enabled, the firewall blocks everything except traffic to the peer port and traffic to the rpc port from the LOCAL_NETWORK and the internal docker gateway.
  117. If TRANSMISSION_PEER_PORT_RANDOM_ON_START is enabled then it allows traffic to the range of peer ports defined by TRANSMISSION_PEER_PORT_RANDOM_HIGH and TRANSMISSION_PEER_PORT_RANDOM_LOW.
  118. | Variable | Function | Example |
  119. |----------|----------|-------|
  120. |`ENABLE_UFW` | Enables the firewall | `ENABLE_UFW=true`|
  121. |`UFW_ALLOW_GW_NET` | Allows the gateway network through the firewall. Off defaults to only allowing the gateway. | `UFW_ALLOW_GW_NET=true`|
  122. |`UFW_EXTRA_PORTS` | Allows the comma separated list of ports through the firewall. Respsects UFW_ALLOW_GW_NET. | `UFW_EXTRA_PORTS=9910,23561,443`|
  123. ### Web proxy configuration options
  124. This container also contains a web-proxy server to allow you to tunnel your web-browser traffic through the same OpenVPN tunnel.
  125. This is useful if you are using a private tracker that needs to see you login from the same IP address you are torrenting from.
  126. The default listening port is 8888. Note that only ports above 1024 can be specified as all ports below 1024 are privileged
  127. and would otherwise require root permissions to run.
  128. | Variable | Function | Example |
  129. |----------|----------|-------|
  130. |`WEBPROXY_ENABLED` | Enables the web proxy | `WEBPROXY_ENABLED=true`|
  131. |`WEBPROXY_PORT` | Sets the listening port | `WEBPROXY_PORT=8888` |
  132. ### User configuration options
  133. By default everything will run as the root user. However, it is possible to change who runs the transmission process.
  134. You may set the following parameters to customize the user id that runs transmission.
  135. | Variable | Function | Example |
  136. |----------|----------|-------|
  137. |`PUID` | Sets the user id who will run transmission | `PUID=1003`|
  138. |`PGID` | Sets the group id for the transmission user | `PGID=1003` |
  139. ### Dropping default route from iptables (advanced)
  140. Some VPNs do not override the default route, but rather set other routes with a lower metric.
  141. This might lead to te default route (your untunneled connection) to be used.
  142. To drop the default route set the environment variable `DROP_DEFAULT_ROUTE` to `true`.
  143. *Note*: This is not compatible with all VPNs. You can check your iptables routing with the `ip r` command in a running container.
  144. ### Custom pre/post scripts
  145. If you ever need to run custom code before or after transmission is executed or stopped, you can use the custom scripts feature.
  146. Custom scripts are located in the /scripts directory which is empty by default.
  147. To enable this feature, you'll need to mount the /scripts directory.
  148. Once /scripts is mounted you'll need to write your custom code in the following bash shell scripts:
  149. | Script | Function |
  150. |----------|----------|
  151. |/scripts/transmission-pre-start.sh | This shell script will be executed before transmission start |
  152. |/scripts/transmission-post-start.sh | This shell script will be executed after transmission start |
  153. |/scripts/transmission-pre-stop.sh | This shell script will be executed before transmission stop |
  154. |/scripts/transmission-post-stop.sh | This shell script will be executed after transmission stop |
  155. Don't forget to include the #!/bin/bash shebang and to make the scripts executable using chmod a+x
  156. #### Use docker env file
  157. Another way is to use a docker env file where you can easily store all your env variables and maintain multiple configurations for different providers.
  158. In the GitHub repository there is a provided DockerEnv file with all the current transmission and openvpn environment variables. You can use this to create local configurations
  159. by filling in the details and removing the # of the ones you want to use.
  160. Please note that if you pass in env. variables on the command line these will override the ones in the env file.
  161. See explanation of variables above.
  162. To use this env file, use the following to run the docker image:
  163. ```
  164. $ docker run --cap-add=NET_ADMIN --device=/dev/net/tun -d \
  165. -v /your/storage/path/:/data \
  166. -v /etc/localtime:/etc/localtime:ro \
  167. --env-file /your/docker/env/file \
  168. -p 9091:9091 \
  169. uri:https://github.com/sscraggles/docker-deluge-openvpn/
  170. ```
  171. ## Known issues, tips and tricks
  172. #### Use Google DNS servers
  173. Some have encountered problems with DNS resolving inside the docker container.
  174. This causes trouble because OpenVPN will not be able to resolve the host to connect to.
  175. If you have this problem use dockers --dns flag to override the resolv.conf of the container.
  176. For example use googles dns servers by adding --dns 8.8.8.8 --dns 8.8.4.4 as parameters to the usual run command.
  177. #### Restart container if connection is lost
  178. If the VPN connection fails or the container for any other reason loses connectivity, you want it to recover from it. One way of doing this is to set environment variable `OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60` and use the --restart=always flag when starting the container. This way OpenVPN will exit if ping fails over a period of time which will stop the container and then the Docker deamon will restart it.
  179. #### Running it on a NAS
  180. Several popular NAS platforms supports Docker containers. You should be able to set up and configure this container using their web interfaces. Remember that you need a TUN/TAP device to run the container. To set up the device it's probably simplest to install a OpenVPN package for the NAS. This should set up the device. If not, there are some more detailed instructions below.
  181. #### Questions?
  182. If you are having issues with this container please submit an issue on GitHub.
  183. Please provide logs, docker version and other information that can simplify reproducing the issue.
  184. Using the latest stable verison of Docker is always recommended. Support for older version is on a best-effort basis.
  185. ## Adding new providers
  186. If your VPN provider is not in the list of supported providers you could always create an issue on GitHub and see if someone could add it for you. But if you're feeling up for doing it yourself, here's a couple of pointers.
  187. You clone this repository and create a new folder under "openvpn" where you put the .ovpn files your provider gives you. Depending on the structure of these files you need to make some adjustments. For example if they come with a ca.crt file that is referenced in the config you need to update this reference to the path it will have inside the container (which is /etc/openvpn/...). You also have to set where to look for your username/password.
  188. There is a script called adjustConfigs.sh that could help you. After putting your .ovpn files in a folder, run that script with your folder name as parameter and it will try to do the changes descibed above. If you use it or not, reading it might give you some help in what you're looking to change in the .ovpn files.
  189. Once you've finished modifying configs, you build the container and run it with OPENVPN_PROVIDER set to the name of the folder of configs you just created (it will be lowercased to match the folder names). And that should be it!
  190. So, you've just added your own provider and you're feeling pretty good about it! Why don't you fork this repository, commit and push your changes and submit a pull request? Share your provider with the rest of us! :) Please submit your PR to the dev branch in that case.
  191. ### Using a custom provider
  192. If you want to run the image with your own provider without building a new image, that is also possible. For some providers, like AirVPN, the .ovpn files are generated per user and contains credentials. They should not be added to a public image. This is what you do:
  193. Add a new volume mount to your `docker run` command that mounts your config file:
  194. `-v /path/to/your/config.ovpn:/etc/openvpn/custom/default.ovpn`
  195. Then you can set `OPENVPN_PROVIDER=CUSTOM`and the container will use the config you provided. If you are using AirVPN or other provider with credentials in the config file, you still need to set `OPENVPN_USERNAME` and `OPENVPN_PASSWORD` as this is required by the startup script. They will not be read by the .ovpn file, so you can set them to whatever.
  196. Note that you still need to modify your .ovpn file as described in the previous section. If you have an separate ca.crt file your volume mount should be a folder containing both the ca.crt and the .ovpn config.
  197. ## Controlling Transmission remotely
  198. The container exposes /config as a volume. This is the directory where the supplied transmission and OpenVPN credentials will be stored.
  199. If you have transmission authentication enabled and want scripts in another container to access and
  200. control the transmission-daemon, this can be a handy way to access the credentials.
  201. For example, another container may pause or restrict transmission speeds while the server is streaming video.
  202. ## Running on ARM (Raspberry PI)
  203. Since the Raspberry PI runs on an ARM architecture instead of x64, the existing x64 images will not
  204. work properly. To support users that wish to run this container on a Raspberry Pi, there are 2 additional
  205. Dockerfiles created. The Dockerfiles supported by the Raspberry PI are Dockerfile.armhf -- there is
  206. also an example docker-compose-armhf file that shows how you might use Transmission/OpenVPN and the
  207. corresponding nginx reverse proxy on an RPI machine.
  208. ## Make it work on Synology NAS
  209. Here are the steps to run it on a Synology NAS (Tested on DSM 6) :
  210. - Connect as _admin_ to your Synology SSH
  211. - Switch to root with command `sudo su -`
  212. - Enter your _admin_ password when prompted
  213. - Create a TUN.sh file anywhere in your synology file system by typing `vim /volume1/foldername/TUN.sh`
  214. replacing _foldername_ with any folder you created on your Synology
  215. - Paste @timkelty 's script :
  216. ```
  217. #!/bin/sh
  218. # Create the necessary file structure for /dev/net/tun
  219. if ( [ ! -c /dev/net/tun ] ); then
  220. if ( [ ! -d /dev/net ] ); then
  221. mkdir -m 755 /dev/net
  222. fi
  223. mknod /dev/net/tun c 10 200
  224. fi
  225. # Load the tun module if not already loaded
  226. if ( !(lsmod | grep -q "^tun\s") ); then
  227. insmod /lib/modules/tun.ko
  228. fi
  229. ```
  230. - Save the file with [escape] + `:wq!`
  231. - Go in the folder containing your script : `cd /volume1/foldername/`
  232. - Check permission with `chmod 0755 TUN.sh`
  233. - Run it with `./TUN.sh`
  234. - Return to initial directory typing `cd`
  235. - Create the DNS config file by typing `vim /volume1/foldername/resolv.conf`
  236. - Paste the following lines :
  237. ```
  238. nameserver 8.8.8.8
  239. nameserver 8.8.4.4
  240. ```
  241. - Save the file with [escape] + `:wq!`
  242. - Create your docker container with a the following command line:
  243. # Tested on DSM 6.1.4-15217 Update 1, Docker Package 17.05.0-0349
  244. docker run \
  245. --cap-add=NET_ADMIN \
  246. --device=/dev/net/tun \
  247. -d \
  248. -v /volume1/foldername/resolv.conf:/etc/resolv.conf \
  249. -v /volume1/yourpath/:/data \
  250. -e "OPENVPN_PROVIDER=PIA" \
  251. -e "OPENVPN_CONFIG=Netherlands" \
  252. -e "OPENVPN_USERNAME=XXXXX" \
  253. -e "OPENVPN_PASSWORD=XXXXX" \
  254. -e "LOCAL_NETWORK=192.168.0.0/24" \
  255. -e "OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60" \
  256. -e "PGID=100" \
  257. -e "PUID=1234" \
  258. -p 9091:9091 \
  259. --sysctl net.ipv6.conf.all.disable_ipv6=0 \
  260. --name "deluge-openvpn-syno" \
  261. uri:https://github.com/sscraggles/docker-deluge-openvpn/
  262. - To make it work after a nas restart, create an automated task in your synology web interface : go to **Settings Panel > Task Scheduler ** create a new task that run `/volume1/foldername/TUN.sh` as root (select '_root_' in 'user' selectbox). This task will start module that permit the container to run, you can make a task that run on startup. These kind of task doesn't work on my nas so I just made a task that run every minute.
  263. - Enjoy
  264. ## systemd Integration
  265. On many modern linux systems, including Ubuntu, systemd can be used to start the transmission-openvpn at boot time, and restart it after any failure.
  266. Save the following as `/etc/systemd/system/transmission-openvpn.service`, and replace the OpenVPN PROVIDER/USERNAME/PASSWORD directives with your settings, and add any other directives that you're using.
  267. This service is assuming that there is a `bittorrent` user set up with a home directory at `/home/bittorrent/`. The data directory will be mounted at `/home/bittorrent/data/`. This can be changed to whichever user and location you're using.
  268. OpenVPN is set to exit if there is a connection failure. OpenVPN exiting triggers the container to also exit, then the `Restart=always` definition in the `transmission-openvpn.service` file tells systems to restart things again.
  269. ```
  270. [Unit]
  271. Description=haugene/transmission-openvpn docker container
  272. After=docker.service
  273. Requires=docker.service
  274. [Service]
  275. User=bittorrent
  276. TimeoutStartSec=0
  277. ExecStartPre=-/usr/bin/docker kill transmission-openvpn
  278. ExecStartPre=-/usr/bin/docker rm transmission-openvpn
  279. ExecStartPre=/usr/bin/docker pull haugene/transmission-openvpn
  280. ExecStart=/usr/bin/docker run \
  281. --name transmission-openvpn \
  282. --cap-add=NET_ADMIN \
  283. --device=/dev/net/tun \
  284. -v /home/bittorrent/data/:/data \
  285. -e "OPENVPN_PROVIDER=TORGUARD" \
  286. -e "OPENVPN_USERNAME=bittorrent@example.com" \
  287. -e "OPENVPN_PASSWORD=hunter2" \
  288. -e "OPENVPN_CONFIG=Netherlands" \
  289. -e "OPENVPN_OPTS=--inactive 3600 --ping 10 --ping-exit 60" \
  290. -e "TRANSMISSION_UMASK=0" \
  291. -p 9091:9091 \
  292. --dns 8.8.8.8 \
  293. --dns 8.8.4.4 \
  294. uri:https://github.com/sscraggles/docker-deluge-openvpn/
  295. Restart=always
  296. RestartSec=5
  297. [Install]
  298. WantedBy=multi-user.target
  299. ```
  300. Then enable and start the new service with:
  301. ```
  302. $ sudo systemctl enable /etc/systemd/system/transmission-openvpn.service
  303. $ sudo systemctl restart transmission-openvpn.service
  304. ```
  305. If it is stopped or killed in any fashion, systemd will restart the container. If you do want to shut it down, then run the following command and it will stay down until you restart it.
  306. ```
  307. $ sudo systemctl stop transmission-openvpn.service
  308. # Later ...
  309. $ sudo systemctl start transmission-openvpn.service
  310. ```