|
|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"crypto/tls" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"log" |
|
|
|
"net/http" |
|
|
|
@ -19,9 +20,9 @@ import ( |
|
|
|
|
|
|
|
func writeDomains() error { |
|
|
|
b := new(bytes.Buffer) |
|
|
|
err := json.NewEncoder(b).Encode(domains) |
|
|
|
err := json.NewEncoder(b).Encode(certgroups) |
|
|
|
if err != nil { |
|
|
|
return errors.New("Couldn't encode domains list into JSON: " + err.Error()) |
|
|
|
return errors.New("Couldn't encode certgroups struct into JSON: " + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
err = ioutil.WriteFile(configDir+"/domains.json", b.Bytes(), 0644) |
|
|
|
@ -136,14 +137,16 @@ func sendFileToServer(filePath, server string) error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func renew() error { |
|
|
|
func renew(cert_idx int) error { |
|
|
|
log.Println("Renew operation initiated...") |
|
|
|
//BUILD/SET GETSSL ENVIRONMENT VARIABLES THEN EXECUTE GETSSL
|
|
|
|
|
|
|
|
//domain list
|
|
|
|
var domainlist string |
|
|
|
cg := certgroups[cert_idx] |
|
|
|
domains := cg.Domains |
|
|
|
for _, d := range domains { |
|
|
|
if d == appconf.PrimaryDomain { //ignore primary domain
|
|
|
|
if d == cg.PrimaryDomain { //ignore primary domain
|
|
|
|
continue |
|
|
|
} |
|
|
|
domainlist = domainlist + "," + d |
|
|
|
@ -165,7 +168,6 @@ func renew() error { |
|
|
|
continue |
|
|
|
} |
|
|
|
aclstring += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.LetsEncryptValidationPath |
|
|
|
//aclstring += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
aclstring += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync" |
|
|
|
@ -182,68 +184,68 @@ func renew() error { |
|
|
|
} |
|
|
|
|
|
|
|
//Cert and key locations
|
|
|
|
domain_cert_location := appconf.TLSCertFile |
|
|
|
domain_cert_location := appconf.TLSCertPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
domain_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCertFile |
|
|
|
domain_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCertPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
//domain_cert_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/cert"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
domain_cert_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/cert" |
|
|
|
domain_cert_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/cert/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
} |
|
|
|
err = os.Setenv("DOMAIN_CERT_LOCATION", domain_cert_location) |
|
|
|
if err != nil { |
|
|
|
return errors.New("RENEW: error setting DOMAIN_CERT_LOCATION environment variable: " + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
domain_key_location := appconf.TLSKeyFile |
|
|
|
domain_key_location := appconf.TLSKeyPath + fmt.Sprintf("%02d", cert_idx) + ".key" |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
domain_key_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSKeyFile |
|
|
|
domain_key_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSKeyPath + fmt.Sprintf("%02d", cert_idx) + ".key" |
|
|
|
//domain_key_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/key"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
domain_key_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/key" |
|
|
|
domain_key_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/key/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
} |
|
|
|
err = os.Setenv("DOMAIN_KEY_LOCATION", domain_key_location) |
|
|
|
if err != nil { |
|
|
|
return errors.New("RENEW: error setting DOMAIN_KEY_LOCATION environment variable: " + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
domain_chain_location := appconf.TLSChainFile |
|
|
|
domain_chain_location := appconf.TLSChainPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//domain_chain_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSChainFile
|
|
|
|
domain_chain_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/chain" |
|
|
|
domain_chain_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSChainPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
//domain_chain_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/chain"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
domain_chain_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/chain" |
|
|
|
domain_chain_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/chain/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
} |
|
|
|
err = os.Setenv("DOMAIN_CHAIN_LOCATION", domain_chain_location) |
|
|
|
if err != nil { |
|
|
|
return errors.New("RENEW: error setting DOMAIN_CHAIN_LOCATION environment variable: " + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
domain_pem_location := appconf.TLSPEMFile |
|
|
|
domain_pem_location := appconf.TLSPEMPath |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
domain_pem_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSPEMFile |
|
|
|
domain_pem_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".pem" |
|
|
|
//domain_pem_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/pem"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
domain_pem_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/pem" |
|
|
|
domain_pem_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/pem/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
} |
|
|
|
err = os.Setenv("DOMAIN_PEM_LOCATION", domain_pem_location) |
|
|
|
if err != nil { |
|
|
|
@ -251,17 +253,17 @@ func renew() error { |
|
|
|
} |
|
|
|
|
|
|
|
//these parameters don't seem to be respected by gettssl from environment variables, so write them to config file:
|
|
|
|
ca_cert_location := appconf.TLSCAFile |
|
|
|
ca_cert_location := appconf.TLSCAPath |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
ca_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCAFile |
|
|
|
ca_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCAPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
//ca_cert_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/ca"
|
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
ca_cert_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/ca" |
|
|
|
ca_cert_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/ca/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
} |
|
|
|
|
|
|
|
reload_command := appconf.ReloadCommand |
|
|
|
@ -285,7 +287,7 @@ func renew() error { |
|
|
|
|
|
|
|
configFile = "CA=\"" + ca_server + "\"\n" |
|
|
|
configFile += "USE_SINGLE_ACL=\"true\"\n" |
|
|
|
configFile += "CA_CERT_LOCATION=\"" + appconf.TLSCAFile + "\"\n" |
|
|
|
configFile += "CA_CERT_LOCATION=\"" + appconf.TLSCAPath + "\"\n" |
|
|
|
configFile += "RELOAD_CMD=\"" + reload_command + "\"\n" |
|
|
|
configFile += "RENEW_ALLOW=\"" + appconf.RenewAllow + "\"\n" |
|
|
|
configFile += "CHECK_REMOTE=\"true\"\n" |
|
|
|
@ -293,9 +295,9 @@ func renew() error { |
|
|
|
configFile += "CHECK_REMOTE_WAIT=\"5\"\n" |
|
|
|
|
|
|
|
//write config file
|
|
|
|
err = ioutil.WriteFile(configDir+"/"+appconf.PrimaryDomain+"/getssl.cfg", []byte(configFile), 0644) |
|
|
|
err = ioutil.WriteFile(configDir+"/"+cg.PrimaryDomain+"/getssl.cfg", []byte(configFile), 0644) |
|
|
|
if err != nil { |
|
|
|
return errors.New("Couldn't write getssl config file: " + configDir + "/" + appconf.PrimaryDomain + "/getssl.cfg") |
|
|
|
return errors.New("Couldn't write getssl config file: " + configDir + "/" + cg.PrimaryDomain + "/getssl.cfg") |
|
|
|
} |
|
|
|
|
|
|
|
if appconf.Debug { |
|
|
|
@ -316,9 +318,9 @@ func renew() error { |
|
|
|
//RUN getssl on primary domain to renew
|
|
|
|
//cmd = exec.Command(appconf.SrvDir+"/getssl", "-u", "-w", appconf.SrvDir, appconf.PrimaryDomain)
|
|
|
|
if appconf.Debug { |
|
|
|
cmd = exec.Command(appconf.SrvDir+"/getssl", "-d", "-w", appconf.SrvDir, appconf.PrimaryDomain) |
|
|
|
cmd = exec.Command(appconf.SrvDir+"/getssl", "-d", "-w", appconf.SrvDir, cg.PrimaryDomain) |
|
|
|
} else { |
|
|
|
cmd = exec.Command(appconf.SrvDir+"/getssl", "-w", appconf.SrvDir, appconf.PrimaryDomain) |
|
|
|
cmd = exec.Command(appconf.SrvDir+"/getssl", "-w", appconf.SrvDir, cg.PrimaryDomain) |
|
|
|
} |
|
|
|
output, err = cmd.CombinedOutput() |
|
|
|
if err != nil { |
|
|
|
|