token-validator: update to handle custom domains
This commit is contained in:
parent
efab34d551
commit
5a4650f70e
|
@ -18,18 +18,27 @@ func (student Student) MyDelegatedDomain() string {
|
|||
}
|
||||
}
|
||||
|
||||
func (student Student) DefaultAssociatedDomain() string {
|
||||
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), AssociatedDomainSuffix)
|
||||
}
|
||||
|
||||
func (student Student) MyAssociatedDomain() string {
|
||||
if student.AssociatedDomain != nil {
|
||||
return *student.AssociatedDomain
|
||||
} else {
|
||||
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), AssociatedDomainSuffix)
|
||||
return student.DefaultAssociatedDomain()
|
||||
}
|
||||
}
|
||||
|
||||
func (student Student) GetAssociatedDomains() (ds []string) {
|
||||
defdn := student.DefaultAssociatedDomain()
|
||||
ds = append(ds, defdn)
|
||||
|
||||
studentDomain := student.MyAssociatedDomain()
|
||||
|
||||
ds = append(ds, studentDomain)
|
||||
if defdn != studentDomain {
|
||||
ds = append(ds, studentDomain)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -30,18 +30,38 @@ func init() {
|
|||
Domain string `json:"domain"`
|
||||
A string `json:"a"`
|
||||
AAAA string `json:"aaaa"`
|
||||
CNAME string `json:"cname,omitempty"`
|
||||
}{}
|
||||
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var aaaa net.IP
|
||||
if ue != nil && len(ue.AAAA) > 0 {
|
||||
aaaa = net.ParseIP(ue.AAAA)
|
||||
}
|
||||
if ue.Domain != "" && ue.A == "" && ue.AAAA == "" && ue.CNAME == "" {
|
||||
student.AssociatedDomain = nil
|
||||
|
||||
return true, AddAssociatedDomains(student, aaaa)
|
||||
if _, err := student.Update(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
} else if ue.CNAME != "" {
|
||||
cname := dns.Fqdn(ue.CNAME)
|
||||
student.AssociatedDomain = &cname
|
||||
|
||||
if _, err := student.Update(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
} else {
|
||||
var aaaa net.IP
|
||||
if ue != nil && len(ue.AAAA) > 0 {
|
||||
aaaa = net.ParseIP(ue.AAAA)
|
||||
}
|
||||
|
||||
return true, AddAssociatedDomains(student, aaaa)
|
||||
}
|
||||
}))
|
||||
router.GET("/api/adomains/:dn", apiAuthHandler(func(student adlin.Student, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return GetAssociatedDomain(student, ps.ByName("dn"))
|
||||
|
@ -50,6 +70,34 @@ func init() {
|
|||
router.GET("/api/ddomains/", apiAuthHandler(func(student adlin.Student, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return []string{student.MyDelegatedDomain()}, nil
|
||||
}))
|
||||
router.POST("/api/ddomains/", apiAuthHandler(func(student adlin.Student, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
ue := &struct {
|
||||
NS string `json:"ns"`
|
||||
}{}
|
||||
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ue.NS == "" {
|
||||
student.DelegatedDomain = nil
|
||||
|
||||
if _, err := student.Update(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
} else {
|
||||
ns := dns.Fqdn(ue.NS)
|
||||
student.DelegatedDomain = &ns
|
||||
|
||||
if _, err := student.Update(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
}))
|
||||
router.GET("/api/ddomains/:dn/", apiAuthHandler(func(student adlin.Student, ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return getRRDelegatedDomain(student, ps.ByName("dn"), "")
|
||||
}))
|
||||
|
@ -239,7 +287,7 @@ func delAssociatedDomains(student adlin.Student, dn string) (err error) {
|
|||
}
|
||||
|
||||
func AddAssociatedDomains(student adlin.Student, aaaa net.IP) (err error) {
|
||||
err = delAssociatedDomains(student, student.MyAssociatedDomain())
|
||||
err = delAssociatedDomains(student, student.DefaultAssociatedDomain())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -257,12 +305,12 @@ func AddAssociatedDomains(student adlin.Student, aaaa net.IP) (err error) {
|
|||
m2.Question[0] = dns.Question{adlin.AssociatedDomainSuffix, dns.TypeSOA, dns.ClassINET}
|
||||
|
||||
rrA := new(dns.A)
|
||||
rrA.Hdr = dns.RR_Header{Name: student.MyAssociatedDomain(), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}
|
||||
rrA.Hdr = dns.RR_Header{Name: student.DefaultAssociatedDomain(), Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 3600}
|
||||
rrA.A = net.IPv4(82, 64, 31, 248)
|
||||
m2.Insert([]dns.RR{rrA})
|
||||
|
||||
rrAAAA := new(dns.AAAA)
|
||||
rrAAAA.Hdr = dns.RR_Header{Name: student.MyAssociatedDomain(), Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 3600}
|
||||
rrAAAA.Hdr = dns.RR_Header{Name: student.DefaultAssociatedDomain(), Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 3600}
|
||||
rrAAAA.AAAA = aaaa
|
||||
m2.Insert([]dns.RR{rrAAAA})
|
||||
|
||||
|
|
|
@ -381,6 +381,123 @@ angular.module("AdLinApp")
|
|||
});
|
||||
}
|
||||
|
||||
$scope.useMyAssociationD = function() {
|
||||
$scope.assoc = {
|
||||
"domain": $scope.adomains[0].domain,
|
||||
"cname": $scope.student.associated_domain?$scope.student.associated_domain:"",
|
||||
}
|
||||
$('#AssocMyDomainModal').modal('show');
|
||||
}
|
||||
|
||||
$scope.newMyDomainAssociationD = function(assoc) {
|
||||
$('#AssocMyDomainModal').modal('hide');
|
||||
$scope.pleaseWaitNewAssociation = true;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "api/adomains/",
|
||||
data: assoc,
|
||||
}).then(function(response) {
|
||||
$scope.updateAssociationD();
|
||||
$scope.checkLoginState();
|
||||
$scope.pleaseWaitNewAssociation = false;
|
||||
$scope.addToast({
|
||||
variant: "success",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Votre domaine a bien été associé !",
|
||||
});
|
||||
}, function(response) {
|
||||
$scope.pleaseWaitNewAssociation = false;
|
||||
$scope.addToast({
|
||||
variant: "danger",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Erreur durant l'association du domaine : " + response.data.errmsg,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$scope.delMyDomainAssociationD = function(assoc) {
|
||||
$('#AssocMyDomainModal').modal('hide');
|
||||
$scope.pleaseWaitNewAssociation = true;
|
||||
assoc.cname = ''
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "api/adomains/",
|
||||
data: assoc,
|
||||
}).then(function(response) {
|
||||
$scope.updateAssociationD();
|
||||
$scope.checkLoginState();
|
||||
$scope.pleaseWaitNewAssociation = false;
|
||||
$scope.addToast({
|
||||
variant: "success",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Votre domaine n'est plus pris en compte. Vous devez utiliser l'association qui vous a été attribuée sous adlin20xx.p0m.fr.",
|
||||
});
|
||||
}, function(response) {
|
||||
$scope.pleaseWaitNewAssociation = false;
|
||||
$scope.addToast({
|
||||
variant: "danger",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Erreur durant l'association du domaine : " + response.data.errmsg,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$scope.useMyDelegationD = function() {
|
||||
$scope.assoc = {
|
||||
"ns": $scope.student.delegated_domain?$scope.student.delegated_domain:"",
|
||||
}
|
||||
$('#DelegateMyDomainModal').modal('show');
|
||||
}
|
||||
|
||||
$scope.newMyDomainDelegationD = function(assoc) {
|
||||
$('#DelegateMyDomainModal').modal('hide');
|
||||
$scope.pleaseWaitNewDelegation = true;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "api/ddomains/",
|
||||
data: assoc,
|
||||
}).then(function(response) {
|
||||
$scope.checkLoginState();
|
||||
$scope.pleaseWaitNewDelegation = false;
|
||||
$scope.addToast({
|
||||
variant: "success",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Votre sous-domaine de délégation a bien été enregistré !",
|
||||
});
|
||||
}, function(response) {
|
||||
$scope.pleaseWaitNewDelegation = false;
|
||||
$scope.addToast({
|
||||
variant: "danger",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Erreur durant la délégation du domaine : " + response.data.errmsg,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$scope.delMyDomainDelegatedD = function() {
|
||||
$scope.pleaseWaitNewDelegation = true;
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: "api/ddomains/",
|
||||
data: {},
|
||||
}).then(function(response) {
|
||||
$scope.checkLoginState();
|
||||
$scope.pleaseWaitNewDelegation = false;
|
||||
$scope.addToast({
|
||||
variant: "success",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Votre domaine n'est plus pris en compte. Vous devez utiliser la délégation qui vous a été attribuée sous srs.p0m.fr.",
|
||||
});
|
||||
}, function(response) {
|
||||
$scope.pleaseWaitNewDelegation = false;
|
||||
$scope.addToast({
|
||||
variant: "danger",
|
||||
title: "Maatma Domain Names",
|
||||
msg: "Erreur durant la délégation du domaine : " + response.data.errmsg,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$scope.addNS = function(domain) {
|
||||
$scope.nsrr = {
|
||||
"domain": domain,
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
Noms de domaine
|
||||
</h2>
|
||||
|
||||
<h3>Association simple</h3>
|
||||
<h3>
|
||||
Association simple
|
||||
<span class="badge badge-pill badge-dark" title="Une association simple est un sous-domaine qui va vous être attribué, sans que vous ayez à gérer de serveur DNS. Ce domaine sera associé à une IP que vous pourrez changer par la suite. C'est la première étape, plus facile que la délégation.">?</span>
|
||||
</h3>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
|
@ -28,6 +31,9 @@
|
|||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" ng-show="pleaseWaitNewAssociation"></span>
|
||||
Demander une nouvelle association
|
||||
</button>
|
||||
<button class="btn ml-2" ng-class="{'btn-secondary': !adomains || !adomains.length, 'btn-success': adomains && adomains.length}" ng-disabled="!adomains || !adomains.length" ng-click="useMyAssociationD()">
|
||||
Utiliser mon domaine
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
@ -35,7 +41,10 @@
|
|||
|
||||
<hr class="my-4">
|
||||
|
||||
<h3>Délégation</h3>
|
||||
<h3>
|
||||
Délégation
|
||||
<span class="badge badge-pill badge-dark" title="Une délégation va vous permettre de gérer vous-même votre domaine sur Internet. Nous vous offrons login.srs.p0m.fr, mais vous pouvez aussi choisir de créer la délégation sur votre domaine, si vous en possédez un. Rendez-vous ensuite sur votre serveur pour y installer un serveur de noms de domaine autoritaire tel que nsd, bind, knot ou encore powerDNS...">?</span>
|
||||
</h3>
|
||||
|
||||
<ul class="nav nav-tabs" id="ddomainTabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
|
@ -48,11 +57,17 @@
|
|||
<a class="nav-link" data-toggle="tab" data-target="#DNSSEC" role="tab" aria-controls="dnssec" aria-selected="false">DNSSEC</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<div ng-if="!student.delegated_domain" class="tab-content" id="myTabContent">
|
||||
<div class="tab-pane fade show active" id="NS" role="tabpanel" aria-labelledby="ns-tab">
|
||||
|
||||
<div ng-repeat="domain in ddomains">
|
||||
<h4 class="text-muted">{{ domain }}</h4>
|
||||
<h4 class="text-muted">
|
||||
{{ domain }}
|
||||
<button class="btn btn-sm btn-info ml-2" ng-if="$first" ng-click="useMyDelegationD()">
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" ng-show="pleaseWaitNewDelegation"></span>
|
||||
Utiliser mon domaine
|
||||
</button>
|
||||
</h4>
|
||||
|
||||
<table class="table table-striped table-hover" ng-controller="NSDomainsController">
|
||||
<thead>
|
||||
|
@ -65,7 +80,7 @@
|
|||
<tr ng-repeat="rr in domainNS">
|
||||
<td><span ng-repeat="val in rr.values">{{ val }} </span></td>
|
||||
<td>
|
||||
<span class="badge badge-pill badge-secondary">Not implemented yet</span>
|
||||
<!--span class="badge badge-pill badge-secondary">Not implemented yet</span-->
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-warning" ng-click="updateNS(domain, rr)">Modifier</button>
|
||||
|
@ -180,7 +195,31 @@
|
|||
|
||||
</div>
|
||||
</div>
|
||||
<div ng-if="student.delegated_domain">
|
||||
<h4 class="text-muted">
|
||||
{{ student.delegated_domain }}
|
||||
<button class="btn btn-sm btn-danger ml-2" ng-if="student.delegated_domain" ng-click="delMyDomainDelegatedD()">
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" ng-show="pleaseWaitNewDelegation"></span>
|
||||
Ne plus utiliser mon domaine
|
||||
</button>
|
||||
</h4>
|
||||
<p>
|
||||
Vous avez choisi d'utiliser votre propre domaine pour réaliser la délégation.
|
||||
</p>
|
||||
<p>
|
||||
L'interface de maatma ne vous est plus utile, car pour réaliser la délégation, vous devez passer par l'interface de votre bureau d'enregistrement.
|
||||
</p>
|
||||
<p>
|
||||
Pour rappel, voici les enregistrements à rajouter :
|
||||
</p>
|
||||
<pre>
|
||||
;; Delegation {{ student.delegated_domain }} to the given name server
|
||||
{{ student.delegated_domain }} 300 IN NS ns.{{ student.delegated_domain }}
|
||||
|
||||
;; GLUE record to serve along with the previous record
|
||||
ns.{{ student.delegated_domain }} 300 IN AAAA [your NS ip]
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="AssocModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
|
@ -224,6 +263,85 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="AssocMyDomainModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Utiliser mon domaine</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Si tu possèdes ton propre domaine, tu peux l'utiliser à la place du domaine qui t'es proposé ici !
|
||||
</p>
|
||||
<p>
|
||||
Pour cela, rien de plus simple. Choisis un sous-domaine de ton choix, dans ton domaine (par exemple <code>adlin.nemunai.re</code>) :
|
||||
</p>
|
||||
<form class="ml-2 mr-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="mysubdomain">Ton sous-domaine :</label>
|
||||
<input class="form-control" id="mysubdomain" ng-model="assoc.cname" autofocus>
|
||||
</div>
|
||||
</form>
|
||||
<p>
|
||||
Ensuite, dans ta zone DNS, ajoute un alias pointant vers le domaine sous <code>adlin20xx.p0m.fr</code> qui t'es proposé :
|
||||
</p>
|
||||
<pre>
|
||||
{{ assoc.cname }} 300 IN CNAME {{ assoc.domain }}
|
||||
</pre>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
|
||||
<button type="button" class="btn btn-primary" ng-disabled="!assoc.cname" ng-click="newMyDomainAssociationD(assoc)">Ok, c'est fait</button>
|
||||
<button type="button" class="btn btn-danger" ng-show="student.associated_domain" ng-click="delMyDomainAssociationD(assoc)">Supprimer l'association enregistrée</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="DelegateMyDomainModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Utiliser mon domaine comme délégation</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>
|
||||
Tu peux utiliser ton propre domaine à la place du domaine qui t'es proposé ici !
|
||||
</p>
|
||||
<p>
|
||||
Commence par choisir un sous-domaine de ton choix (différent de l'association ci-dessus), dans ton domaine (par exemple <code>adlin.nemunai.re</code>) :
|
||||
</p>
|
||||
<form class="ml-2 mr-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="mysubdomaind">Ton sous-domaine :</label>
|
||||
<input class="form-control" id="mysubdomaind" ng-model="assoc.ns" autofocus>
|
||||
</div>
|
||||
</form>
|
||||
<p>
|
||||
Ensuite, configure ta zone DNS, pour réaliser la délégation. L'interface
|
||||
</p>
|
||||
<pre>
|
||||
;; Delegation {{ assoc.ns }} to the given name server
|
||||
{{ assoc.ns }} 300 IN NS ns.{{ assoc.ns }}
|
||||
|
||||
;; GLUE record to serve along with the previous record
|
||||
ns.{{ assoc.ns }} 300 IN AAAA [your NS ip]
|
||||
</pre>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
|
||||
<button type="button" class="btn btn-primary" ng-disabled="!assoc.ns" ng-click="newMyDomainDelegationD(assoc)">Ok, c'est fait</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="NSModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
|
|
Reference in New Issue