1
0
Fork 0
mirror of synced 2024-11-21 16:25:35 -05:00

Fix template rendering bug

This commit is contained in:
Ilya Sosnovsky 2021-03-10 17:54:27 +03:00
parent 409377d014
commit 30bdc3243f
3 changed files with 10 additions and 7 deletions

View file

@ -8,7 +8,6 @@ services:
image: openvpn:local
command: /etc/openvpn/setup/configure.sh
environment:
- OPVN_PASSWD_AUTH=true
- OPVN_ROLE=slave
cap_add:
- NET_ADMIN
@ -22,7 +21,7 @@ services:
build:
context: .
image: openvpn-admin:local
command: /app/openvpn-admin --debug --ovpn.network="172.16.100.0/22" --master.sync-token="TOKEN" --master.host="http://172.20.0.1:8080" --role="slave" --ovpn.server="127.0.0.1:7777:tcp" --ovpn.server="127.0.0.1:7778:tcp" --auth.password
command: /app/openvpn-admin --debug --ovpn.network="172.16.100.0/22" --master.sync-token="TOKEN" --master.host="http://172.20.0.1:8080" --role="slave" --ovpn.server="127.0.0.1:7777:tcp" --ovpn.server="127.0.0.1:7778:tcp" --easyrsa.path="/mnt/easyrsa" --easyrsa.index-path="/mnt/easyrsa/pki/index.txt"
environment:
- OPVN_SLAVE=1
network_mode: service:openvpn

View file

@ -7,8 +7,6 @@ services:
dockerfile: Dockerfile.openvpn
image: openvpn:local
command: /etc/openvpn/setup/configure.sh
environment:
- OPVN_PASSWD_AUTH=true
cap_add:
- NET_ADMIN
ports:
@ -21,7 +19,7 @@ services:
build:
context: .
image: openvpn-admin:local
command: /app/openvpn-admin --debug --ovpn.network="172.16.100.0/22" --master.sync-token="TOKEN" --auth.password --ovpn.server="127.0.0.1:7777:tcp"
command: /app/openvpn-admin --debug --ovpn.network="172.16.100.0/22" --master.sync-token="TOKEN" --easyrsa.path="/mnt/easyrsa" --easyrsa.index-path="/mnt/easyrsa/pki/index.txt" --ovpn.server="127.0.0.1:7777:tcp"
network_mode: service:openvpn
volumes:
- ./easyrsa_master:/mnt/easyrsa

10
main.go
View file

@ -532,6 +532,9 @@ func (oAdmin *OpenvpnAdmin) renderClientConfig(username string) string {
parts := strings.SplitN(server, ":",3)
hosts = append(hosts, OpenvpnServer{Host: parts[0], Port: parts[1], Protocol: parts[2]})
}
if *debug {
log.Printf("WARNING: hosts for %s\n %v", username, hosts )
}
conf := openvpnClientConfig{}
conf.Hosts = hosts
@ -546,11 +549,14 @@ func (oAdmin *OpenvpnAdmin) renderClientConfig(username string) string {
log.Println("ERROR: clientConfigTpl not found in templates box")
}
t := template.New(clientConfigTpl)
t := template.Must(template.New("client-config").Parse(clientConfigTpl))
var tmp bytes.Buffer
err := t.Execute(&tmp, conf)
if err != nil {
log.Printf("WARNING: something goes wrong during rendering config for %s", username )
if *debug {
log.Printf("ERROR: rendering config for %s failed \n %v", username, err )
}
}
hosts = nil
@ -602,7 +608,7 @@ func (oAdmin *OpenvpnAdmin) modifyCcd(ccd Ccd) (bool, string) {
return false, ccdErr
}
t := template.New(ccdTpl)
t := template.Must(template.New("ccd").Parse(ccdTpl))
var tmp bytes.Buffer
tplErr := t.Execute(&tmp, ccd)
if tplErr != nil {