mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-27 12:05:26 +00:00
Merge pull request #48 from juanfont/better-profile-info
Improving namespace/user support
This commit is contained in:
commit
31556e1ac0
15
api.go
15
api.go
@ -76,7 +76,7 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var m Machine
|
var m Machine
|
||||||
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
log.Println("New Machine!")
|
log.Println("New Machine!")
|
||||||
m = Machine{
|
m = Machine{
|
||||||
Expiry: &req.Expiry,
|
Expiry: &req.Expiry,
|
||||||
@ -200,7 +200,7 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var m Machine
|
var m Machine
|
||||||
if result := h.db.First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if result := h.db.Preload("Namespace").First(&m, "machine_key = ?", mKey.HexString()); errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
|
log.Printf("Ignoring request, cannot find machine with key %s", mKey.HexString())
|
||||||
c.String(http.StatusUnauthorized, "")
|
c.String(http.StatusUnauthorized, "")
|
||||||
return
|
return
|
||||||
@ -357,16 +357,23 @@ func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Mac
|
|||||||
log.Printf("Cannot fetch peers: %s", err)
|
log.Printf("Cannot fetch peers: %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profile := tailcfg.UserProfile{
|
||||||
|
ID: tailcfg.UserID(m.NamespaceID),
|
||||||
|
LoginName: m.Namespace.Name,
|
||||||
|
DisplayName: m.Namespace.Name,
|
||||||
|
}
|
||||||
|
|
||||||
resp := tailcfg.MapResponse{
|
resp := tailcfg.MapResponse{
|
||||||
KeepAlive: false,
|
KeepAlive: false,
|
||||||
Node: node,
|
Node: node,
|
||||||
Peers: *peers,
|
Peers: *peers,
|
||||||
DNS: []netaddr.IP{},
|
DNS: []netaddr.IP{},
|
||||||
SearchPaths: []string{},
|
SearchPaths: []string{},
|
||||||
Domain: "foobar@example.com",
|
Domain: "headscale.net",
|
||||||
PacketFilter: *h.aclRules,
|
PacketFilter: *h.aclRules,
|
||||||
DERPMap: h.cfg.DerpMap,
|
DERPMap: h.cfg.DerpMap,
|
||||||
UserProfiles: []tailcfg.UserProfile{},
|
UserProfiles: []tailcfg.UserProfile{profile},
|
||||||
}
|
}
|
||||||
|
|
||||||
var respBody []byte
|
var respBody []byte
|
||||||
|
2
app.go
2
app.go
@ -175,7 +175,7 @@ func (h *Headscale) Serve() error {
|
|||||||
}()
|
}()
|
||||||
err = s.ListenAndServeTLS("", "")
|
err = s.ListenAndServeTLS("", "")
|
||||||
} else {
|
} else {
|
||||||
return errors.New("Unknown value for TLSLetsEncryptChallengeType")
|
return errors.New("unknown value for TLSLetsEncryptChallengeType")
|
||||||
}
|
}
|
||||||
} else if h.cfg.TLSCertPath == "" {
|
} else if h.cfg.TLSCertPath == "" {
|
||||||
if !strings.HasPrefix(h.cfg.ServerURL, "http://") {
|
if !strings.HasPrefix(h.cfg.ServerURL, "http://") {
|
||||||
|
@ -154,7 +154,6 @@ func (m Machine) toNode() (*tailcfg.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) {
|
func (h *Headscale) getPeers(m Machine) (*[]*tailcfg.Node, error) {
|
||||||
|
|
||||||
machines := []Machine{}
|
machines := []Machine{}
|
||||||
if err := h.db.Where("namespace_id = ? AND machine_key <> ? AND registered",
|
if err := h.db.Where("namespace_id = ? AND machine_key <> ? AND registered",
|
||||||
m.NamespaceID, m.MachineKey).Find(&machines).Error; err != nil {
|
m.NamespaceID, m.MachineKey).Find(&machines).Error; err != nil {
|
||||||
|
@ -106,10 +106,10 @@ func (h *Headscale) SetMachineNamespace(m *Machine, namespaceName string) error
|
|||||||
func (n *Namespace) toUser() *tailcfg.User {
|
func (n *Namespace) toUser() *tailcfg.User {
|
||||||
u := tailcfg.User{
|
u := tailcfg.User{
|
||||||
ID: tailcfg.UserID(n.ID),
|
ID: tailcfg.UserID(n.ID),
|
||||||
LoginName: "",
|
LoginName: n.Name,
|
||||||
DisplayName: n.Name,
|
DisplayName: n.Name,
|
||||||
ProfilePicURL: "",
|
ProfilePicURL: "",
|
||||||
Domain: "",
|
Domain: "headscale.net",
|
||||||
Logins: []tailcfg.LoginID{},
|
Logins: []tailcfg.LoginID{},
|
||||||
Created: time.Time{},
|
Created: time.Time{},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user