Allow override of automatically assigned delegated domain
This commit is contained in:
parent
54a3fe9192
commit
c4da666a1e
@ -11,15 +11,23 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (student *Student) MyDelegatedDomainSuffix() string {
|
func (student *Student) MyDelegatedDomainSuffix() string {
|
||||||
|
if student.DelegatedDomain != nil {
|
||||||
|
for _, ddomain := range DelegatedDomainSuffixes {
|
||||||
|
if strings.HasSuffix(*student.DelegatedDomain, ddomain) {
|
||||||
|
return ddomain
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return DelegatedDomainSuffixes[int(student.Id)%len(DelegatedDomainSuffixes)]
|
return DelegatedDomainSuffixes[int(student.Id)%len(DelegatedDomainSuffixes)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (student *Student) MyDelegatedDomain() string {
|
func (student *Student) MyDelegatedDomain() string {
|
||||||
if student.DelegatedDomain != nil {
|
if student.DelegatedDomain != nil {
|
||||||
return *student.DelegatedDomain
|
return *student.DelegatedDomain
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyDelegatedDomainSuffix())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyDelegatedDomainSuffix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (student *Student) MyAssociatedDomainSuffix() string {
|
func (student *Student) MyAssociatedDomainSuffix() string {
|
||||||
@ -33,9 +41,9 @@ func (student *Student) DefaultAssociatedDomain() string {
|
|||||||
func (student *Student) MyAssociatedDomain() string {
|
func (student *Student) MyAssociatedDomain() string {
|
||||||
if student.AssociatedDomain != nil {
|
if student.AssociatedDomain != nil {
|
||||||
return *student.AssociatedDomain
|
return *student.AssociatedDomain
|
||||||
} else {
|
|
||||||
return student.DefaultAssociatedDomain()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return student.DefaultAssociatedDomain()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (student *Student) GetAssociatedDomains() (ds []string) {
|
func (student *Student) GetAssociatedDomains() (ds []string) {
|
||||||
|
@ -30,6 +30,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateAuthToken(s *adlin.Student, _ httprouter.Params, _ []byte) (interface{}, error) {
|
func validateAuthToken(s *adlin.Student, _ httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
|
if s.DelegatedDomain != nil {
|
||||||
|
for _, ddomain := range adlin.DelegatedDomainSuffixes {
|
||||||
|
if strings.HasSuffix(*s.DelegatedDomain, ddomain) {
|
||||||
|
s.DelegatedDomain = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,14 @@ func init() {
|
|||||||
return true, nil
|
return true, nil
|
||||||
} else {
|
} else {
|
||||||
ns := dns.Fqdn(ue.NS)
|
ns := dns.Fqdn(ue.NS)
|
||||||
|
|
||||||
|
// Ensure ns doesn't belong to one of our domain
|
||||||
|
for _, ddomain := range adlin.DelegatedDomainSuffixes {
|
||||||
|
if strings.HasSuffix(ns, ddomain) {
|
||||||
|
return nil, fmt.Errorf("Vous ne pouvez pas vous créer une délégation vers ce sous-domaine: interdit par l'administrateur.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
student.DelegatedDomain = &ns
|
student.DelegatedDomain = &ns
|
||||||
|
|
||||||
if _, err := student.Update(); err != nil {
|
if _, err := student.Update(); err != nil {
|
||||||
|
Reference in New Issue
Block a user