From 6427a0d16d32220bd216f7d39ae1466e43b68e52 Mon Sep 17 00:00:00 2001 From: negbie Date: Thu, 15 Jul 2021 09:45:09 +0200 Subject: [PATCH] Allow custom ctrl address --- config.go | 5 ++++- go.mod | 3 ++- go.sum | 7 ++++--- main.go | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 51ce166..a2ff2c1 100644 --- a/config.go +++ b/config.go @@ -14,7 +14,10 @@ import ( //go:embed zip/sounds.tar.gz var baresipSounds []byte -func createConfig(maxCalls uint, rtpNet, rtpPorts string, rtpTimeout uint, sipAddr string) { +func createConfig(maxCalls uint, rtpNet, rtpPorts string, rtpTimeout uint, ctrlAddr, sipAddr string) { + ctrlAddrNorm := strings.Replace(ctrlAddr, "localhost", "127.0.0.1", 1) + config = strings.Replace(config, "127.0.0.1:4444", ctrlAddrNorm, 1) + if sipAddr != "" { config = strings.Replace( config, diff --git a/go.mod b/go.mod index 1111fae..11b1ede 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,6 @@ go 1.16 require ( github.com/coocood/freecache v1.1.1 - github.com/negbie/go-baresip v0.1.0 + github.com/goccy/go-json v0.7.4 // indirect + github.com/negbie/go-baresip v0.1.1 ) diff --git a/go.sum b/go.sum index 6fbab0d..65837d2 100644 --- a/go.sum +++ b/go.sum @@ -4,11 +4,12 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/coocood/freecache v1.1.1 h1:uukNF7QKCZEdZ9gAV7WQzvh0SbjwdMF6m3x3rxEkaPc= github.com/coocood/freecache v1.1.1/go.mod h1:OKrEjkGVoxZhyWAJoeFi5BMLUJm2Tit0kpGkIr7NGYY= -github.com/goccy/go-json v0.6.1 h1:O7xC9WR7B09imThbRIEMIWK4MVcxOsLzWtGe16cv5SU= github.com/goccy/go-json v0.6.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.7.4 h1:B44qRUFwz/vxPKPISQ1KhvzRi9kZ28RAf6YtjriBZ5k= +github.com/goccy/go-json v0.7.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/negbie/go-baresip v0.1.0 h1:e0xuvvRmgZGqimZMIqGp5hZyp6LQeWfud9d2JW/wbs4= -github.com/negbie/go-baresip v0.1.0/go.mod h1:rZ1+ZBEwbYxNOsm4KHZSnutgWMcA1qtpj9TBcSyOzPo= +github.com/negbie/go-baresip v0.1.1 h1:OS3oGmkdKLc6G0fMf5U6Ck2yYRk1gw0vQTFxVb1GnKU= +github.com/negbie/go-baresip v0.1.1/go.mod h1:rZ1+ZBEwbYxNOsm4KHZSnutgWMcA1qtpj9TBcSyOzPo= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= diff --git a/main.go b/main.go index 6862798..6d04ea5 100644 --- a/main.go +++ b/main.go @@ -10,10 +10,11 @@ import ( gobaresip "github.com/negbie/go-baresip" ) -const v = "v0.1.0" +const v = "v0.1.1" func main() { debug := flag.Bool("debug", false, "Set debug mode") + ctrlAddr := flag.String("ctrl_address", "127.0.0.1:4444", "Local control listen address") guiAddr := flag.String("gui_address", "0.0.0.0:8080", "Local GUI listen address") logStd := flag.Bool("log_stderr", true, "Log to stderr") lokiURL := flag.String("loki_url", "", "URL to remote Loki server like http://localhost:3100") @@ -32,7 +33,7 @@ func main() { os.Exit(0) } - createConfig(*maxCalls, *rtpNet, *rtpPorts, *rtpTimeout, *sipAddr) + createConfig(*maxCalls, *rtpNet, *rtpPorts, *rtpTimeout, *ctrlAddr, *sipAddr) if *webhookDelay == 0 { *webhookDelay = 1 @@ -64,6 +65,7 @@ func main() { gobaresip.SetConfigPath("."), gobaresip.SetDebug(*debug), gobaresip.SetUserAgent("telefonist"), + gobaresip.SetCtrlTCPAddr(*ctrlAddr), gobaresip.SetWsAddr(*guiAddr), ) if err != nil {