mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-08-17 05:53:50 +02:00
Change user templating and split domain name
This commit is contained in:
parent
6358eb1fa5
commit
c66a2c9dd3
2 changed files with 30 additions and 14 deletions
|
@ -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
|
||||||
|
|
39
api/web.go
39
api/web.go
|
@ -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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user = strings.Replace(user,"{{ token }}", userToken, 1)
|
||||||
|
|
||||||
// authenticated
|
// authenticated
|
||||||
seed := make([]byte, 16)
|
seed := make([]byte, 16)
|
||||||
rand.Read(seed)
|
rand.Read(seed)
|
||||||
|
@ -187,16 +198,18 @@ 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"+
|
"gatewayprofileusagemethod:i:1\r\n"+
|
||||||
"gatewayprofileusagemethod:i:1\r\n"+
|
"gatewayaccesstoken:s:"+token+"\r\n"+
|
||||||
"gatewayaccesstoken:s:"+token+"\r\n"+
|
"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:"+user+"\r\n"+
|
||||||
"username:s:"+userToken+"\r\n"+
|
"domain:s:"+domain+"\r\n"+
|
||||||
"bitmapcachesize:i:32000\r\n"))
|
"bitmapcachesize:i:32000\r\n"
|
||||||
|
|
||||||
|
http.ServeContent(w, r, fn, time.Now(), strings.NewReader(data))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue