Skip to content

Commit

Permalink
support google dns provider
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Dec 27, 2021
1 parent 7aab01f commit d6bb859
Show file tree
Hide file tree
Showing 4 changed files with 560 additions and 9 deletions.
51 changes: 49 additions & 2 deletions cli/zoro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"io/ioutil"
"log"
"net/http"
_ "net/http/pprof"
Expand All @@ -24,7 +25,10 @@ import (
"strings"
"syscall"

"github.com/bitly/go-simplejson"
"github.com/caddyserver/certmagic"
"github.com/denisbrodbeck/machineid"
"github.com/libdns/googleclouddns"
"github.com/txthinking/zoro"
"github.com/txthinking/zoro/https"
"github.com/urfave/cli/v2"
Expand All @@ -33,7 +37,7 @@ import (
func main() {
app := cli.NewApp()
app.Name = "zoro"
app.Version = "20211227"
app.Version = "20211228"
app.Usage = "Expose local TCP and UDP server to external network"
app.Commands = []*cli.Command{
&cli.Command{
Expand Down Expand Up @@ -104,6 +108,7 @@ func main() {
&cli.Int64Flag{
Name: "clientPort",
Usage: "Work with --clientDirectory",
Value: 8080,
},
&cli.Int64Flag{
Name: "tcpTimeout",
Expand Down Expand Up @@ -173,6 +178,10 @@ func main() {
Name: "certKey",
Usage: "Cert key of *.domain.com, like: ./path/to/cert_key.pem",
},
&cli.StringFlag{
Name: "googledns",
Usage: "Pointing to a service account file, this will ignore --cert and --certKey",
},
&cli.Int64Flag{
Name: "tlsPort",
Usage: "TLS Port, works with --domain",
Expand All @@ -195,14 +204,51 @@ func main() {
},
},
Action: func(c *cli.Context) error {
if c.String("listen") == "" || c.String("domain") == "" || c.String("cert") == "" || c.String("certKey") == "" || (c.String("password") == "" && len(c.StringSlice("subdomainPassword")) == 0) {
if c.String("listen") == "" || c.String("domain") == "" || (c.String("password") == "" && len(c.StringSlice("subdomainPassword")) == 0) {
cli.ShowCommandHelp(c, "httpsserver")
return nil
}
if (c.String("cert") == "" || c.String("certKey") == "") && c.String("googledns") == "" {
cli.ShowCommandHelp(c, "httpsserver")
return nil
}
s, err := https.NewHTTPSServer(c.String("listen"), c.String("password"), c.String("domain"), c.String("cert"), c.String("certKey"), c.Int64("tlsPort"), c.Int64("tlsTimeout"), c.Int64("tlsDeadline"), c.StringSlice("subdomainPassword"))
if err != nil {
return err
}
if c.String("cert") == "" || c.String("certKey") == "" {
certmagic.DefaultACME.Agreed = true
certmagic.DefaultACME.Email = "[email protected]"
certmagic.DefaultACME.CA = certmagic.LetsEncryptProductionCA
if c.String("googledns") != "" {
b, err := ioutil.ReadFile(c.String("googledns"))
if err != nil {
return err
}
j, err := simplejson.NewJson(b)
if err != nil {
return err
}
s, err := j.Get("project_id").String()
if err != nil {
return err
}
certmagic.DefaultACME.DNS01Solver = &certmagic.DNS01Solver{
DNSProvider: &googleclouddns.Provider{
Project: s,
ServiceAccountJSON: c.String("googledns"),
},
}
}
tc, err := certmagic.TLS([]string{"*." + c.String("domain")})
if err != nil {
return err
}
s.TLSConfig = tc
}
if err != nil {
return err
}
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down Expand Up @@ -242,6 +288,7 @@ func main() {
&cli.Int64Flag{
Name: "clientPort",
Usage: "Work with --clientDirectory",
Value: 8080,
},
&cli.Int64Flag{
Name: "tcpTimeout",
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ module github.com/txthinking/zoro
go 1.16

require (
github.com/bitly/go-simplejson v0.5.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/caddyserver/certmagic v0.15.2
github.com/denisbrodbeck/machineid v1.0.1
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/libdns/googleclouddns v1.0.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/txthinking/crypto v0.0.0-20210716135230-de9624a415a4
github.com/txthinking/x v0.0.0-20210326105829-476fab902fbe
Expand Down
Loading

0 comments on commit d6bb859

Please sign in to comment.