From 8ae4cde1c43ed67971088e5326a75256d71e329c Mon Sep 17 00:00:00 2001 From: Sebastian Cohnen Date: Tue, 30 Mar 2021 20:39:30 +0200 Subject: [PATCH] defaults --domain and --tls-port via --host --- README.md | 6 +++--- main.go | 23 ++++++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ebc35f3..c420ece 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ General options are: Let's Encrypt specific (`--auto-cert`) options are: -* `--domain` the domain you want to have your certificate generated for +* `--domain` the domain you want to have your certificate generated for (if `--host` is not `fritz.box` it will default to the host name in `--host`) * `--email` your mail address you want to have registered with Let’s Encrypt * `--save` (optional) to save generated private key and acquired certificate * `--dns-provider` (default `manual`) to specify one of [lego's](https://github.com/xenolf/lego/tree/master/providers/dns) supported DNS providers. Note that you might have to set environment variables to configure your provider, e.g. `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` and `AWS_HOSTED_ZONE_ID`. I use name servers by AWS/Route53 and [inwx](https://github.com/xenolf/lego/blob/master/providers/dns/inwx/inwx.go), so I have to provide `INWX_USERNAME`, `INWX_PASSWORD`. I'm not sure if there is a overview, so for now you have to consult the [source](https://github.com/xenolf/lego/tree/master/providers/dns). @@ -67,9 +67,9 @@ Options for non `--auto-cert` mode: These are some things I'd like to to in the future: -* if `--tls-port` is not given, we should try to use `--host` before failing * add validation for private keys and certificate before uploading (avoid trying to upload garbage) * allow password protected private keys (when not provisioned by LE) +* ~~if `--tls-port` is not given, we should try to use `--host` before failing~~ * ~~add homebrew as a release target for goreleaser~~ * ~~ask for `--user` if not provided (may be empty then) and/or add `--pw-only` flag~~ * ~~allow other then DNS-01 Let's Encrypt challenges and make [legos](https://github.com/xenolf/lego) DNS providers available to make things even more automated!~~ @@ -88,4 +88,4 @@ Releases are done via Github Actions on push of a git tag. To make a release, ru ```terminal git tag va.b.c git push --tags -``` \ No newline at end of file +``` diff --git a/main.go b/main.go index b6c1074..db7f8cb 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "net/url" "os" + "strconv" "github.com/tisba/fritz-tls/fritzbox" ) @@ -130,6 +131,11 @@ func setupConfiguration() configOptions { flag.Parse() + url, err := url.Parse(config.host) + if err != nil { + log.Fatal(err) + } + if config.version { log.Printf("fritz-tls %s (%s, %s)", version, date, commit) os.Exit(0) @@ -141,7 +147,11 @@ func setupConfiguration() configOptions { } if config.domain == "" { - log.Fatal("--domain is required with --auto-cert!") + if url.Hostname() != "fritz.box" { + config.domain = url.Hostname() + } else { + log.Fatal("--domain is required with --auto-cert!") + } } if config.email == "" { @@ -163,14 +173,17 @@ func setupConfiguration() configOptions { } } - url, err := url.Parse(config.host) - if err != nil { - log.Fatal(err) - } config.user = url.User.Username() url.User = nil config.host = url.String() + if config.tlsPort == 0 && url.Port() != "" { + config.tlsPort, err = strconv.Atoi(url.Port()) + if err != nil { + log.Fatal(err) + } + } + if config.adminPassword == "" { config.adminPassword = os.Getenv("FRITZTLS_ADMIN_PASS") }