Rewrite of the entrypoint in Golang (#71)
- General improvements
- Parallel download of only needed files at start
- Prettier console output with all streams merged (openvpn, unbound, shadowsocks etc.)
- Simplified Docker final image
- Faster bootup
- DNS over TLS
- Finer grain blocking at DNS level: malicious, ads and surveillance
- Choose your DNS over TLS providers
- Ability to use multiple DNS over TLS providers for DNS split horizon
- Environment variables for DNS logging
- DNS block lists needed are downloaded and built automatically at start, in parallel
- PIA
- A random region is selected if the REGION parameter is left empty (thanks @rorph for your PR)
- Routing and iptables adjusted so it can work as a Kubernetes pod sidecar (thanks @rorph for your PR)
This commit is contained in:
61
internal/pia/download.go
Normal file
61
internal/pia/download.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package pia
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/models"
|
||||
)
|
||||
|
||||
func (c *configurator) DownloadOvpnConfig(encryption models.PIAEncryption,
|
||||
protocol models.NetworkProtocol, region models.PIARegion) (lines []string, err error) {
|
||||
c.logger.Info("%s: downloading openvpn configuration files", logPrefix)
|
||||
URL := buildZipURL(encryption, protocol)
|
||||
content, status, err := c.client.GetContent(URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if status != 200 {
|
||||
return nil, fmt.Errorf("HTTP Get %s resulted in HTTP status code %d", URL, status)
|
||||
}
|
||||
filename := fmt.Sprintf("%s.ovpn", region)
|
||||
fileContent, err := getFileInZip(content, filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", URL, err)
|
||||
}
|
||||
lines = strings.Split(string(fileContent), "\n")
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func buildZipURL(encryption models.PIAEncryption, protocol models.NetworkProtocol) (URL string) {
|
||||
URL = string(constants.PIAOpenVPNURL) + "/openvpn"
|
||||
if encryption == constants.PIAEncryptionStrong {
|
||||
URL += "-strong"
|
||||
}
|
||||
if protocol == constants.TCP {
|
||||
URL += "-tcp"
|
||||
}
|
||||
return URL + ".zip"
|
||||
}
|
||||
|
||||
func getFileInZip(zipContent []byte, filename string) (fileContent []byte, err error) {
|
||||
contentLength := int64(len(zipContent))
|
||||
r, err := zip.NewReader(bytes.NewReader(zipContent), contentLength)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, f := range r.File {
|
||||
if f.Name == filename {
|
||||
readCloser, err := f.Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer readCloser.Close()
|
||||
return ioutil.ReadAll(readCloser)
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("%s not found in zip archive file", filename)
|
||||
}
|
||||
Reference in New Issue
Block a user