From 5e2790dea250c851502cbcd043d6c2d3d1696ff9 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 12 Jul 2021 14:34:55 -0700 Subject: [PATCH] README stub and minor app usability features --- README.md | 21 +++++++++++++++++++++ app/main.go | 23 +++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc6ec0b --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Cwtch Server + +## Running + +- cd app +- go build +- ./app + +The app takes the following arguments +- -debug: enabled debug logging + +The app takes the following environment variables +- CWTCH_HOME: sets the config dir for the app + +## Using the Server + +When run the app will output standard log lines, one of which will contain the `tofubundle` in purple. This is the part you need to capture and import into a Cwtch client app so you can use the server for hosting groups + +## Docker + +Currently, the dockerfile is out of date and is not usable. Check back for updates. \ No newline at end of file diff --git a/app/main.go b/app/main.go index bbbf2ef..945672f 100644 --- a/app/main.go +++ b/app/main.go @@ -4,10 +4,13 @@ import ( "crypto/rand" "cwtch.im/cwtch/model" "encoding/base64" + "flag" + "fmt" cwtchserver "git.openprivacy.ca/cwtch.im/server" "git.openprivacy.ca/cwtch.im/tapir/primitives" "git.openprivacy.ca/openprivacy/connectivity/tor" "git.openprivacy.ca/openprivacy/log" + "io/ioutil" mrand "math/rand" "os" "os/signal" @@ -20,11 +23,19 @@ const ( ) func main() { + flagDebug := flag.Bool("debug", false, "Enable debug logging") + flagExportTofu := flag.Bool("exportTofuBundle", false, "Export the tofubundle to a file called `tofubundle`") + flag.Parse() + log.AddEverythingFromPattern("server/app/main") log.AddEverythingFromPattern("server/server") log.ExcludeFromPattern("service.go") - log.SetLevel(log.LevelDebug) - configDir := os.Getenv("CWTCH_CONFIG_DIR") + log.SetLevel(log.LevelInfo) + if *flagDebug { + log.Infoln("enableing Debug logging") + log.SetLevel(log.LevelDebug) + } + configDir := os.Getenv("CWTCH_HOME") if len(os.Args) == 2 && os.Args[1] == "gen1" { config := new(cwtchserver.Config) @@ -80,9 +91,13 @@ func main() { } bundle := server.KeyBundle().Serialize() - log.Infof("Server Config: server:%s", base64.StdEncoding.EncodeToString(bundle)) + tofubundle := fmt.Sprintf("tofubundle:server:%s||%s", base64.StdEncoding.EncodeToString(bundle), invite) + log.Infof("Server Tofu Bundle (import into client to use server): %s", log.Magenta(tofubundle)) + log.Infof("Server Config: server address:%s", base64.StdEncoding.EncodeToString(bundle)) - log.Infof("Server Tofu Bundle: tofubundle:server:%s||%s", base64.StdEncoding.EncodeToString(bundle), invite) + if *flagExportTofu { + ioutil.WriteFile("tofubundle", []byte(tofubundle), 0600) + } // Graceful Shutdown c := make(chan os.Signal, 1)