Fix template rendering bug
This commit is contained in:
parent
409377d014
commit
30bdc3243f
3 changed files with 10 additions and 7 deletions
|
@ -8,7 +8,6 @@ services:
|
||||||
image: openvpn:local
|
image: openvpn:local
|
||||||
command: /etc/openvpn/setup/configure.sh
|
command: /etc/openvpn/setup/configure.sh
|
||||||
environment:
|
environment:
|
||||||
- OPVN_PASSWD_AUTH=true
|
|
||||||
- OPVN_ROLE=slave
|
- OPVN_ROLE=slave
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
|
@ -22,7 +21,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
image: openvpn-admin:local
|
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:
|
environment:
|
||||||
- OPVN_SLAVE=1
|
- OPVN_SLAVE=1
|
||||||
network_mode: service:openvpn
|
network_mode: service:openvpn
|
||||||
|
|
|
@ -7,8 +7,6 @@ services:
|
||||||
dockerfile: Dockerfile.openvpn
|
dockerfile: Dockerfile.openvpn
|
||||||
image: openvpn:local
|
image: openvpn:local
|
||||||
command: /etc/openvpn/setup/configure.sh
|
command: /etc/openvpn/setup/configure.sh
|
||||||
environment:
|
|
||||||
- OPVN_PASSWD_AUTH=true
|
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
ports:
|
ports:
|
||||||
|
@ -21,7 +19,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
image: openvpn-admin:local
|
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
|
network_mode: service:openvpn
|
||||||
volumes:
|
volumes:
|
||||||
- ./easyrsa_master:/mnt/easyrsa
|
- ./easyrsa_master:/mnt/easyrsa
|
||||||
|
|
10
main.go
10
main.go
|
@ -532,6 +532,9 @@ func (oAdmin *OpenvpnAdmin) renderClientConfig(username string) string {
|
||||||
parts := strings.SplitN(server, ":",3)
|
parts := strings.SplitN(server, ":",3)
|
||||||
hosts = append(hosts, OpenvpnServer{Host: parts[0], Port: parts[1], Protocol: parts[2]})
|
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 := openvpnClientConfig{}
|
||||||
conf.Hosts = hosts
|
conf.Hosts = hosts
|
||||||
|
@ -546,11 +549,14 @@ func (oAdmin *OpenvpnAdmin) renderClientConfig(username string) string {
|
||||||
log.Println("ERROR: clientConfigTpl not found in templates box")
|
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
|
var tmp bytes.Buffer
|
||||||
err := t.Execute(&tmp, conf)
|
err := t.Execute(&tmp, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("WARNING: something goes wrong during rendering config for %s", username )
|
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
|
hosts = nil
|
||||||
|
@ -602,7 +608,7 @@ func (oAdmin *OpenvpnAdmin) modifyCcd(ccd Ccd) (bool, string) {
|
||||||
return false, ccdErr
|
return false, ccdErr
|
||||||
}
|
}
|
||||||
|
|
||||||
t := template.New(ccdTpl)
|
t := template.Must(template.New("ccd").Parse(ccdTpl))
|
||||||
var tmp bytes.Buffer
|
var tmp bytes.Buffer
|
||||||
tplErr := t.Execute(&tmp, ccd)
|
tplErr := t.Execute(&tmp, ccd)
|
||||||
if tplErr != nil {
|
if tplErr != nil {
|
||||||
|
|
Loading…
Reference in a new issue