Skip to content

Commit

Permalink
feat: add support set http-proxy-redir-domain
Browse files Browse the repository at this point in the history
Used for set cookie via nginx proxy.

Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Dec 16, 2024
1 parent 47d3fa4 commit a272ad4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
67 changes: 35 additions & 32 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import (

// Config struct
type Config struct {
AddrDev string
AddrUser string
AddrHttpProxy string
DisableSignUp bool
HttpProxyRedirURL string
HttpProxyPort int
SslCert string
SslKey string
SslCacert string // mTLS for device
WebUISslCert string
WebUISslKey string
Token string
DevAuthUrl string
WhiteList map[string]bool
DB string
LocalAuth bool
SeparateSslConfig bool
AddrDev string
AddrUser string
AddrHttpProxy string
DisableSignUp bool
HttpProxyRedirURL string
HttpProxyRedirDomain string
HttpProxyPort int
SslCert string
SslKey string
SslCacert string // mTLS for device
WebUISslCert string
WebUISslKey string
Token string
DevAuthUrl string
WhiteList map[string]bool
DB string
LocalAuth bool
SeparateSslConfig bool
}

func getConfigOpt(yamlCfg *yaml.File, name string, opt interface{}) {
Expand All @@ -50,21 +51,22 @@ func getConfigOpt(yamlCfg *yaml.File, name string, opt interface{}) {
// Parse config
func Parse(c *cli.Context) *Config {
cfg := &Config{
AddrDev: c.String("addr-dev"),
AddrUser: c.String("addr-user"),
AddrHttpProxy: c.String("addr-http-proxy"),
DisableSignUp: c.Bool("disable-sign-up"),
HttpProxyRedirURL: c.String("http-proxy-redir-url"),
SslCert: c.String("ssl-cert"),
SslKey: c.String("ssl-key"),
SslCacert: c.String("ssl-cacert"),
SeparateSslConfig: c.Bool("separate-ssl-config"),
WebUISslCert: c.String("webui-ssl-cert"),
WebUISslKey: c.String("webui-ssl-key"),
Token: c.String("token"),
DevAuthUrl: c.String("dev-auth-url"),
DB: c.String("db"),
LocalAuth: c.Bool("local-auth"),
AddrDev: c.String("addr-dev"),
AddrUser: c.String("addr-user"),
AddrHttpProxy: c.String("addr-http-proxy"),
DisableSignUp: c.Bool("disable-sign-up"),
HttpProxyRedirURL: c.String("http-proxy-redir-url"),
HttpProxyRedirDomain: c.String("http-proxy-redir-domain"),
SslCert: c.String("ssl-cert"),
SslKey: c.String("ssl-key"),
SslCacert: c.String("ssl-cacert"),
SeparateSslConfig: c.Bool("separate-ssl-config"),
WebUISslCert: c.String("webui-ssl-cert"),
WebUISslKey: c.String("webui-ssl-key"),
Token: c.String("token"),
DevAuthUrl: c.String("dev-auth-url"),
DB: c.String("db"),
LocalAuth: c.Bool("local-auth"),
}

cfg.WhiteList = make(map[string]bool)
Expand All @@ -86,6 +88,7 @@ func Parse(c *cli.Context) *Config {
getConfigOpt(yamlCfg, "addr-http-proxy", &cfg.AddrHttpProxy)
getConfigOpt(yamlCfg, "disable-sign-up", &cfg.DisableSignUp)
getConfigOpt(yamlCfg, "http-proxy-redir-url", &cfg.HttpProxyRedirURL)
getConfigOpt(yamlCfg, "http-proxy-redir-domain", &cfg.HttpProxyRedirDomain)
getConfigOpt(yamlCfg, "ssl-cert", &cfg.SslCert)
getConfigOpt(yamlCfg, "ssl-key", &cfg.SslKey)
getConfigOpt(yamlCfg, "ssl-cacert", &cfg.SslCacert)
Expand Down
10 changes: 6 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,12 @@ func httpProxyRedirect(br *broker, c *gin.Context) {

httpProxySessions.Store(sid, make(chan struct{}))

c.SetCookie("rtty-http-sid", sid, 0, "", "", false, true)
c.SetCookie("rtty-http-devid", devid, 0, "", "", false, true)
c.SetCookie("rtty-http-proto", proto, 0, "", "", false, true)
c.SetCookie("rtty-http-destaddr", addr, 0, "", "", false, true)
domain := cfg.HttpProxyRedirDomain

c.SetCookie("rtty-http-sid", sid, 0, "", domain, false, true)
c.SetCookie("rtty-http-devid", devid, 0, "", domain, false, true)
c.SetCookie("rtty-http-proto", proto, 0, "", domain, false, true)
c.SetCookie("rtty-http-destaddr", addr, 0, "", domain, false, true)

c.Redirect(http.StatusFound, location)
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func main() {
Value: "",
Usage: "url to redirect for HTTP proxy",
},
&cli.StringFlag{
Name: "http-proxy-redir-domain",
Value: "",
Usage: "domain for HTTP proxy set cookie",
},
&cli.StringFlag{
Name: "ssl-cert",
Value: "",
Expand Down
3 changes: 3 additions & 0 deletions rttys.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#http-proxy-redir-url:

# Used for set cookie
#http-proxy-redir-domain:

#ssl-cacert: /etc/rttys/rttys.ca
#ssl-cert: /etc/rttys/rttys.crt
#ssl-key: /etc/rttys/rttys.key
Expand Down

0 comments on commit a272ad4

Please sign in to comment.