Skip to content
Snippets Groups Projects
Commit c66a2c9d authored by Bolke de Bruin's avatar Bolke de Bruin
Browse files

Change user templating and split domain name

parent 6358eb1f
Loading
...@@ -76,7 +76,10 @@ caps: ...@@ -76,7 +76,10 @@ caps:
enableDrive: true enableDrive: true
enableClipboard: true enableClipboard: true
client: client:
usernameTemplate: "{{ username }}@bla.com" # this is a go string templated with {{ username }} and {{ token }}
# the example below uses the ASCII field separator to distinguish
# between user and token
usernameTemplate: "{{ username }}@bla.com\x1f{{ token }}"
# rdp file settings see: # rdp file settings see:
# https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/rdp-files # https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/rdp-files
networkAutoDetect: 0 networkAutoDetect: 0
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"github.com/coreos/go-oidc/v3/oidc" "github.com/coreos/go-oidc/v3/oidc"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/patrickmn/go-cache" "github.com/patrickmn/go-cache"
...@@ -155,8 +156,16 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) { ...@@ -155,8 +156,16 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) {
host := c.Hosts[rand.Intn(len(c.Hosts))] host := c.Hosts[rand.Intn(len(c.Hosts))]
host = strings.Replace(host, "{{ preferred_username }}", userName, 1) host = strings.Replace(host, "{{ preferred_username }}", userName, 1)
user := userName // split the username into user and domain
creds := strings.SplitN(userName, "@", 2)
user := creds[0]
var domain string
if len(creds) > 1 {
domain = creds[1]
}
if c.UsernameTemplate != "" { if c.UsernameTemplate != "" {
c.UsernameTemplate = fmt.Sprintf(c.UsernameTemplate)
user = strings.Replace(c.UsernameTemplate, "{{ username }}", user, 1) user = strings.Replace(c.UsernameTemplate, "{{ username }}", user, 1)
if c.UsernameTemplate == user { if c.UsernameTemplate == user {
log.Printf("Invalid username template. %s == %s", c.UsernameTemplate, user) log.Printf("Invalid username template. %s == %s", c.UsernameTemplate, user)
...@@ -180,6 +189,8 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) { ...@@ -180,6 +189,8 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) {
} }
} }
user = strings.Replace(user,"{{ token }}", userToken, 1)
// authenticated // authenticated
seed := make([]byte, 16) seed := make([]byte, 16)
rand.Read(seed) rand.Read(seed)
...@@ -187,8 +198,7 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) { ...@@ -187,8 +198,7 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename="+fn) w.Header().Set("Content-Disposition", "attachment; filename="+fn)
w.Header().Set("Content-Type", "application/x-rdp") w.Header().Set("Content-Type", "application/x-rdp")
http.ServeContent(w, r, fn, time.Now(), strings.NewReader( data := "full address:s:"+host+"\r\n"+
"full address:s:"+host+"\r\n"+
"gatewayhostname:s:"+c.GatewayAddress+"\r\n"+ "gatewayhostname:s:"+c.GatewayAddress+"\r\n"+
"gatewaycredentialssource:i:5\r\n"+ "gatewaycredentialssource:i:5\r\n"+
"gatewayusagemethod:i:1\r\n"+ "gatewayusagemethod:i:1\r\n"+
...@@ -197,6 +207,9 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) { ...@@ -197,6 +207,9 @@ func (c *Config) HandleDownload(w http.ResponseWriter, r *http.Request) {
"networkautodetect:i:"+strconv.Itoa(c.NetworkAutoDetect)+"\r\n"+ "networkautodetect:i:"+strconv.Itoa(c.NetworkAutoDetect)+"\r\n"+
"bandwidthautodetect:i:"+strconv.Itoa(c.BandwidthAutoDetect)+"\r\n"+ "bandwidthautodetect:i:"+strconv.Itoa(c.BandwidthAutoDetect)+"\r\n"+
"connection type:i:"+strconv.Itoa(c.ConnectionType)+"\r\n"+ "connection type:i:"+strconv.Itoa(c.ConnectionType)+"\r\n"+
"username:s:"+userToken+"\r\n"+ "username:s:"+user+"\r\n"+
"bitmapcachesize:i:32000\r\n")) "domain:s:"+domain+"\r\n"+
"bitmapcachesize:i:32000\r\n"
http.ServeContent(w, r, fn, time.Now(), strings.NewReader(data))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment