Skip to content

Commit

Permalink
defaults --domain and --tls-port via --host
Browse files Browse the repository at this point in the history
  • Loading branch information
tisba committed Mar 30, 2021
1 parent ab8819f commit 8ae4cde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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!~~
Expand All @@ -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
```
```
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"net/url"
"os"
"strconv"

"github.com/tisba/fritz-tls/fritzbox"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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 == "" {
Expand All @@ -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")
}
Expand Down

0 comments on commit 8ae4cde

Please sign in to comment.