Updated acmedns tool

Add support for automatically generating acmedns module for Windows 7 using older version of lego
This commit is contained in:
Toby Chui 2024-05-18 14:48:55 +08:00
parent ec973eb3bc
commit fe48a9a0c3
4 changed files with 73 additions and 11 deletions

4
.gitignore vendored
View File

@ -31,4 +31,6 @@ src/rules/*
src/README.md src/README.md
docker/ContainerTester.sh docker/ContainerTester.sh
docker/ImagePublisher.sh docker/ImagePublisher.sh
src/mod/acme/test/stackoverflow.pem src/mod/acme/test/stackoverflow.pem
/tools/dns_challenge_update/code-gen/acmedns
/tools/dns_challenge_update/code-gen/lego

View File

@ -12,7 +12,22 @@ To update the module, simply run update.sh
The updated files will be written into the `acmedns` folder. Then, you can copy it to the ACME module folder (or later-on a CICD pipeline will be made to do this automatically, but for now you have to manually copy it into the module under `src/mod/acme/`) The updated files will be written into the `acmedns` folder. Then, you can copy it to the ACME module folder (or later-on a CICD pipeline will be made to do this automatically, but for now you have to manually copy it into the module under `src/mod/acme/`)
### Build for Windows 7 (NT6.1)
If you want to build Zoraxy with NT6.1, the lego version must be kept on or below 4.15.0. To build acmedns module for win7, add -- "win7" as go run paramter as follows.
```bash
go run ./extract.go -- "win7"
```
After moving the generated modules into the acmedns folder, you will also need to force override the version of the lego in the go.mod file under `src/`. by adding this line at the bottom of the go.mod file
```
replace github.com/go-acme/lego/v4 v4.16.1 => github.com/go-acme/lego/v4 v4.15.0
```
Make sure your Go version is on or below `1.20` for Windows 7 support.
### Module Usage ### Module Usage
@ -25,14 +40,9 @@ func GetDNSProviderByJsonConfig(name string, js string)(challenge.Provider, erro
providersdef.GetDNSProviderByJsonConfig("gandi", "{\"Username\":\"far\",\"Password\":\"boo\"}") providersdef.GetDNSProviderByJsonConfig("gandi", "{\"Username\":\"far\",\"Password\":\"boo\"}")
``` ```
This should be able to replace the default lego v4 build in one (the one attached below) that requires the use of environment variables This should be able to replace the default lego v4 build in one (the one attached below) that requires the use of environment variables
```go ```go
// NewDNSChallengeProviderByName Factory for DNS providers. // NewDNSChallengeProviderByName Factory for DNS providers.
func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) func NewDNSChallengeProviderByName(name string) (challenge.Provider, error)
``` ```

View File

@ -9,6 +9,15 @@ import (
"strings" "strings"
) )
/*
Usage
git clone {repo_link_for_lego}
go run extract.go
//go run extract.go -- "win7"
*/
var legoProvidersSourceFolder string = "./lego/providers/dns/" var legoProvidersSourceFolder string = "./lego/providers/dns/"
var outputDir string = "./acmedns" var outputDir string = "./acmedns"
var defTemplate string = `package acmedns var defTemplate string = `package acmedns
@ -72,6 +81,26 @@ func getExcludedDNSProviders() []string {
} }
} }
// Exclude list for Windows build, due to limitations for lego versions
func getExcludedDNSProvidersNT61() []string {
return []string{
"edgedns", //Too complex data structure
"exec", //Not a DNS provider
"httpreq", //Not a DNS provider
"hurricane", //Multi-credentials arch
"oraclecloud", //Evil company
"acmedns", //Not a DNS provider
"selectelv2", //Not sure why not working with our code generator
"designate", //OpenStack, if you are using this you shd not be using zoraxy
"mythicbeasts", //Module require url.URL, which cannot be automatically parsed
//The following suppliers was not in lego v1.15 (Windows 7 last supported version of lego)
"cpanel",
"mailinabox",
"shellrent",
}
}
func isInSlice(str string, slice []string) bool { func isInSlice(str string, slice []string) bool {
for _, s := range slice { for _, s := range slice {
if s == str { if s == str {
@ -85,6 +114,10 @@ func isExcludedDNSProvider(providerName string) bool {
return isInSlice(providerName, getExcludedDNSProviders()) return isInSlice(providerName, getExcludedDNSProviders())
} }
func isExcludedDNSProviderNT61(providerName string) bool {
return isInSlice(providerName, getExcludedDNSProvidersNT61())
}
// extractConfigStruct extracts the name of the config struct and its content as plain text from a given source code. // extractConfigStruct extracts the name of the config struct and its content as plain text from a given source code.
func extractConfigStruct(sourceCode string) (string, string) { func extractConfigStruct(sourceCode string) (string, string) {
// Regular expression to match the struct declaration. // Regular expression to match the struct declaration.
@ -106,6 +139,7 @@ func extractConfigStruct(sourceCode string) (string, string) {
func main() { func main() {
// A map of provider name to information on what can be filled // A map of provider name to information on what can be filled
extractedProviderList := map[string]*ProviderInfo{} extractedProviderList := map[string]*ProviderInfo{}
buildForWindowsSeven := (len(os.Args) > 2 && os.Args[2] == "win7")
//Search all providers //Search all providers
providers, err := filepath.Glob(filepath.Join(legoProvidersSourceFolder, "/*")) providers, err := filepath.Glob(filepath.Join(legoProvidersSourceFolder, "/*"))
@ -123,10 +157,19 @@ func main() {
importList := "" importList := ""
for _, provider := range providers { for _, provider := range providers {
providerName := filepath.Base(provider) providerName := filepath.Base(provider)
if isExcludedDNSProvider(providerName) {
//Ignore this provider if buildForWindowsSeven {
continue if isExcludedDNSProviderNT61(providerName) {
//Ignore this provider
continue
}
} else {
if isExcludedDNSProvider(providerName) {
//Ignore this provider
continue
}
} }
//Check if {provider_name}.go exists //Check if {provider_name}.go exists
providerDef := filepath.Join(provider, providerName+".go") providerDef := filepath.Join(provider, providerName+".go")
if !fileExists(providerDef) { if !fileExists(providerDef) {
@ -230,11 +273,17 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
os.WriteFile(filepath.Join(outputDir, "providers.json"), js, 0775)
fullCodeSnippet := strings.ReplaceAll(defTemplate, "{{magic}}", generatedConvertcode) fullCodeSnippet := strings.ReplaceAll(defTemplate, "{{magic}}", generatedConvertcode)
fullCodeSnippet = strings.ReplaceAll(fullCodeSnippet, "{{imports}}", importList) fullCodeSnippet = strings.ReplaceAll(fullCodeSnippet, "{{imports}}", importList)
os.WriteFile(filepath.Join(outputDir, "acmedns.go"), []byte(fullCodeSnippet), 0775) outJsonFilename := "providers.json"
outGoFilename := "acmedns.go"
if buildForWindowsSeven {
outJsonFilename = "providers_nt61.json"
outGoFilename = "acmedns_nt61.go"
}
os.WriteFile(filepath.Join(outputDir, outJsonFilename), js, 0775)
os.WriteFile(filepath.Join(outputDir, outGoFilename), []byte(fullCodeSnippet), 0775)
fmt.Println("Output written to file") fmt.Println("Output written to file")
} }

View File

@ -18,6 +18,7 @@ fi
# Run the extract.go to get all the config from lego source code # Run the extract.go to get all the config from lego source code
echo "Generating code" echo "Generating code"
go run ./extract.go go run ./extract.go
go run ./extract.go -- "win7"
echo "Cleaning up lego" echo "Cleaning up lego"
# Comment the line below if you dont want to pull everytime update # Comment the line below if you dont want to pull everytime update