|
|
|
@ -1,4 +1,4 @@ |
|
|
|
//LEAPI - ACME Certificate Renewal Control API - Copyright 2022-2024 Ruel Tmeizeh All Rights Reserved
|
|
|
|
//LEAPI - ACME Certificate Renewal Control API - Copyright 2022-2025 Ruel Tmeizeh All Rights Reserved
|
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
@ -48,7 +48,7 @@ func writeServers() error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func sendFileToAllServers(filePath, cert_idx string) error { |
|
|
|
func sendFileToAllServers(filePath, cert_idx_str string) error { |
|
|
|
var theError error |
|
|
|
numservers := len(servers) |
|
|
|
c := make(chan string) |
|
|
|
@ -65,7 +65,7 @@ func sendFileToAllServers(filePath, cert_idx string) error { |
|
|
|
} |
|
|
|
|
|
|
|
log.Println("Parallel execution send file to server: " + srv + "...") |
|
|
|
err := sendFileToServer(filePath, srv, cert_idx) |
|
|
|
err := sendFileToServer(filePath, srv, cert_idx_str) |
|
|
|
if err != nil { |
|
|
|
log.Println(err.Error()) |
|
|
|
theError = err |
|
|
|
@ -92,7 +92,7 @@ func sendFileToAllServers(filePath, cert_idx string) error { |
|
|
|
return theError //if any one or more fail, return an error for it (the last one that fails)
|
|
|
|
} |
|
|
|
|
|
|
|
func sendFileToServer(filePath, server, cert_idx string) error { |
|
|
|
func sendFileToServer(filePath, server, cert_idx_str string) error { |
|
|
|
log.Println("Send file " + filePath + " to " + server + " starting...") |
|
|
|
|
|
|
|
_, fileName := path.Split(filePath) |
|
|
|
@ -103,8 +103,8 @@ func sendFileToServer(filePath, server, cert_idx string) error { |
|
|
|
} |
|
|
|
|
|
|
|
//url := syncScheme + server + ":" + syncPort + "/api/file/upload/" + fileType + "/" + fmt.Sprintf("%02d", cert_idx)
|
|
|
|
url := syncScheme + server + ":" + syncPort + "/api/file/upload/" + fileTypeOrACL + "/" + cert_idx |
|
|
|
if len(cert_idx) == 0 { // file is missing cert index number string, so is an ACL file
|
|
|
|
url := syncScheme + server + ":" + syncPort + "/api/file/upload/" + fileTypeOrACL + "/" + cert_idx_str |
|
|
|
if len(cert_idx_str) == 0 { // file is missing cert index number string, so is an ACL file
|
|
|
|
url = syncScheme + server + ":" + syncPort + "/api/file/upload/" + fileTypeOrACL |
|
|
|
} |
|
|
|
log.Println("Send file '" + filePath + "' to " + url + "...") |
|
|
|
@ -198,7 +198,6 @@ func renew(cert_idx int) error { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//domain_cert_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/cert"
|
|
|
|
domain_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCertPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
@ -216,7 +215,6 @@ func renew(cert_idx int) error { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//domain_key_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/key"
|
|
|
|
domain_key_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSKeyPath + fmt.Sprintf("%02d", cert_idx) + ".key" |
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
@ -233,7 +231,6 @@ func renew(cert_idx int) error { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//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" |
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
@ -244,16 +241,13 @@ func renew(cert_idx int) error { |
|
|
|
return errors.New("RENEW: error setting DOMAIN_CHAIN_LOCATION environment variable: " + err.Error()) |
|
|
|
} |
|
|
|
|
|
|
|
//domain_pem_location := appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".pem"
|
|
|
|
domain_fullpem_location := appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
domain_fullpem_location := appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".pem" |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//domain_pem_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/pem"
|
|
|
|
//domain_fullpem_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".pem"
|
|
|
|
domain_fullpem_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
domain_fullpem_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSPEMPath + fmt.Sprintf("%02d", cert_idx) + ".pem" |
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
domain_fullpem_location += ";davs:" + appconf.Username + ":" + appconf.SecretKey + ":" + appconf.Hostname + ":" + appconf.HTTPS_ServerPort + ":/api/file/sync/pem/" + fmt.Sprintf("%02d", cert_idx) |
|
|
|
@ -264,13 +258,12 @@ func renew(cert_idx int) error { |
|
|
|
} |
|
|
|
|
|
|
|
//these parameters don't seem to be respected by GetSSL from environment variables, so write them to config file:
|
|
|
|
ca_cert_location := appconf.TLSCAPath + ".crt" |
|
|
|
ca_cert_location := appconf.TLSCAPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
if appconf.SyncType == "ssh" { |
|
|
|
for _, server := range servers { |
|
|
|
if server == appconf.Hostname { |
|
|
|
continue |
|
|
|
} |
|
|
|
//ca_cert_location += ";davs:leapi:" + appconf.SecretKey + ":" + server + ":" + syncPort + ":/api/file/upload/ca"
|
|
|
|
ca_cert_location += ";ssh:" + appconf.Username + "@" + server + ":" + appconf.TLSCAPath + fmt.Sprintf("%02d", cert_idx) + ".crt" |
|
|
|
} |
|
|
|
} else { //file sync type is HTTPS
|
|
|
|
@ -285,7 +278,7 @@ func renew(cert_idx int) error { |
|
|
|
//old ssh method; requires ssh key
|
|
|
|
//reload_command += "; ssh " + appconf.Username + "@" + server + " '" + appconf.ReloadCommand + "'"
|
|
|
|
//new method; calls LEAPI to trigger reload
|
|
|
|
reload_command += " ; curl -s -k -X POST -H 'Authorization: Bearer " + appconf.SecretKey + "' " + syncScheme + server + "/api/reload" |
|
|
|
reload_command += " ; curl -s -k -X POST -H 'Authorization: Bearer " + appconf.SecretKey + "' " + syncScheme + server + ":" + appconf.HTTPS_ServerPort + "/api/reload" |
|
|
|
//reload_command += "; 'curl -s -X POST -H \\\"Authorization: Bearer " + appconf.SecretKey + "\\\" " + syncScheme + server + "/api/reload"
|
|
|
|
} |
|
|
|
|
|
|
|
@ -298,7 +291,7 @@ func renew(cert_idx int) error { |
|
|
|
|
|
|
|
configFile = "CA=\"" + ca_server + "\"\n" |
|
|
|
configFile += "USE_SINGLE_ACL=\"true\"\n" |
|
|
|
configFile += "CA_CERT_LOCATION=\"" + appconf.TLSCAPath + "\"\n" |
|
|
|
configFile += "CA_CERT_LOCATION=\"" + ca_cert_location + "\"\n" |
|
|
|
configFile += "RELOAD_CMD=\"" + reload_command + "\"\n" |
|
|
|
configFile += "RENEW_ALLOW=\"" + appconf.RenewAllow + "\"\n" |
|
|
|
configFile += "CHECK_REMOTE=\"false\"\n" |
|
|
|
|