changement d'API, site plus joli, plus de tests
parent
83157fb1ab
commit
bbc4801c3f
|
@ -148,10 +148,16 @@ prefix '/domain' => sub {
|
|||
, get_request( qw/address referer/ );
|
||||
};
|
||||
|
||||
get '/cliup/:login/:pass/:domain/:name/:type/:rdata' => sub {
|
||||
what_is_next rt_dom_cli_autoupdate
|
||||
get_session( qw// )
|
||||
, get_param( qw/login pass domain name type rdata/ );
|
||||
};
|
||||
|
||||
get '/cli/:login/:pass/:domain/:name/:type/:rdata/:ttl/:ip' => sub {
|
||||
what_is_next rt_dom_cli_mod_entry
|
||||
get_session( qw/login/ )
|
||||
, get_param( qw/passwd domain name type rdata ttl ip/ );
|
||||
get_session( qw// )
|
||||
, get_param( qw/login pass domain name type rdata ttl ip/ );
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ use Exporter 'import';
|
|||
# what we want to export eventually
|
||||
our @EXPORT_OK = qw/
|
||||
rt_dom_cli_mod_entry
|
||||
rt_dom_cli_autoupdate
|
||||
rt_dom_mod_entry
|
||||
rt_dom_del_entry
|
||||
rt_dom_del
|
||||
|
@ -26,6 +27,7 @@ rt_dom_updateraw
|
|||
# bundle of exports (tags)
|
||||
our %EXPORT_TAGS = ( all => [qw/
|
||||
rt_dom_cli_mod_entry
|
||||
rt_dom_cli_autoupdate
|
||||
rt_dom_mod_entry
|
||||
rt_dom_del_entry
|
||||
rt_dom_del
|
||||
|
@ -35,6 +37,86 @@ rt_dom_add_entry
|
|||
rt_dom_updateraw
|
||||
/] );
|
||||
|
||||
sub rt_dom_cli_autoupdate {
|
||||
my ($session, $param, $request) = @_;
|
||||
my $res;
|
||||
|
||||
my @missingitems;
|
||||
my @items = qw/login pass domain name type rdata/;
|
||||
|
||||
for(@items) {
|
||||
push @missingitems, $_ unless($$param{$_});
|
||||
}
|
||||
|
||||
if(@missingitems != 0) {
|
||||
say "Il manque : " . join ', ', @missingitems;
|
||||
return $res;
|
||||
}
|
||||
|
||||
for(@items) {
|
||||
say "::::::::: $_ : $$param{$_}" if $$param{$_};
|
||||
}
|
||||
|
||||
if(! is_ipv4($$param{rdata}) && ! is_ipv6($$param{rdata})) {
|
||||
say "Attention, ceci n'est pas une adresse IP : $$param{rdata}.";
|
||||
return $res;
|
||||
}
|
||||
|
||||
eval {
|
||||
my $pass = encrypt($$param{pass});
|
||||
my $app = app->new(get_cfg());
|
||||
|
||||
my $user = $app->auth($$param{login}, $pass);
|
||||
|
||||
unless ( $user && ( $$user{admin} ||
|
||||
$app->is_owning_domain($$user{login}, $$param{domain}))) {
|
||||
$app->disconnect();
|
||||
say q{Donnée privée, petit coquin. ;) };
|
||||
return $res;
|
||||
}
|
||||
|
||||
my $zone = $app->get_zone( $$param{domain} );
|
||||
my $zf = $zone->get_zonefile();
|
||||
|
||||
my $name = $$param{name};
|
||||
|
||||
if($name =~ /$$param{domain}$/) {
|
||||
$name .= '.';
|
||||
}
|
||||
|
||||
if($name !~ /\.$/) {
|
||||
$name .= ".$$param{domain}."
|
||||
}
|
||||
|
||||
my $rr_list = $zf->rr_search($name, $$param{type});
|
||||
my $rr;
|
||||
if(@$rr_list) {
|
||||
$rr = pop @$rr_list;
|
||||
}
|
||||
else {
|
||||
say "Pas d'entrée au nom $name de type $$param{type} trouvée.";
|
||||
return $res;
|
||||
}
|
||||
|
||||
my $str_old = "$$rr{name} $$rr{ttl} $$rr{type} $$rr{rdata}";
|
||||
my $str_new = "$$rr{name} $$rr{ttl} $$rr{type} $$param{rdata}";
|
||||
|
||||
say "old : $str_old";
|
||||
say "new : $str_new";
|
||||
|
||||
$zf->rr_mod($str_old, $str_new);
|
||||
$zone->update( $zf );
|
||||
|
||||
$app->disconnect();
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
say "Problème : $@";
|
||||
}
|
||||
|
||||
$res
|
||||
}
|
||||
|
||||
sub rt_dom_cli_mod_entry {
|
||||
my ($session, $param, $request) = @_;
|
||||
my $res;
|
||||
|
@ -138,8 +220,8 @@ sub rt_dom_mod_entry {
|
|||
&& ! is_domain_name ($rdata))
|
||||
{
|
||||
$$res{deferred}{errmsg} =
|
||||
"Une entrée CNAME doit avoir un nom de domaine "
|
||||
. "(pas une URL, pas de http://) : $rdata n'est pas correct.";
|
||||
"Une entrée $$param{type} doit avoir un nom de domaine "
|
||||
. "(pas une URL, pas de http://) : '$rdata' n'est pas correct.";
|
||||
$$res{route} = ($$request{referer}) ? $$request{referer} : '/';
|
||||
return $res;
|
||||
}
|
||||
|
@ -488,12 +570,12 @@ sub rt_dom_add_entry {
|
|||
my $str_new = "$name $$param{ttl} $$param{type} ";
|
||||
my $rdata = $$param{rdata};
|
||||
|
||||
if ($$param{type} =~ /^(CNAME|MX|NS|PTR)$/i
|
||||
if ($$param{type} =~ /^(CNAME|MX|NS|PTR|SRV)$/i
|
||||
&& ! is_domain_name ($rdata))
|
||||
{
|
||||
$$res{deferred}{errmsg} =
|
||||
"Une entrée CNAME doit avoir un nom de domaine "
|
||||
. "(pas une URL, pas de http://) : $rdata n'est pas correct.";
|
||||
"Une entrée $$param{type} doit avoir un nom de domaine "
|
||||
. "(pas une URL, pas de http://) : '$rdata' n'est pas correct.";
|
||||
$$res{route} = ($$request{referer}) ? $$request{referer} : '/';
|
||||
return $res;
|
||||
}
|
||||
|
|
|
@ -143,6 +143,12 @@ sub rr_mod {
|
|||
$self->rr_add_raw($rrline_new);
|
||||
}
|
||||
|
||||
sub rr_search {
|
||||
my ($self, $name, $type) = @_;
|
||||
my $rrlisttmp = $self->rr_array_to_array();
|
||||
[ grep { $$_{name} eq $name && $$_{type} eq $type } @$rrlisttmp ]
|
||||
}
|
||||
|
||||
sub rr_array_to_array {
|
||||
my ($self) = shift;
|
||||
my $rr_list;
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<td><% rr.type %></td>
|
||||
<td><input type='number' name='newttl' class="form-control" value='<% rr.ttl %>' size='4' /></td>
|
||||
<td><input type='text' name='newrdata' class="form-control" value='<% rr.rdata %>'/>
|
||||
<input type='number' name='newpriority' class="form-control" value='<% rr.priority %>' size='4' /></td>
|
||||
Priorité <input type='number' name='newpriority' class="form-control" value='<% rr.priority %>' size='4' /></td>
|
||||
<td><input type='submit' id='submit' class="btn btn-success btn-xs" value='✔' /></td>
|
||||
|
||||
<td>
|
||||
|
@ -244,7 +244,6 @@
|
|||
<input type="text" id="mxname" name="name" class="form-control" placeholder="www">
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<input type="hidden" name="type" value='MX'/>
|
||||
|
||||
|
@ -254,7 +253,6 @@
|
|||
<input type="number" id="mxinput_ttl" name="ttl" class="form-control" value="3600" placeholder="3600" >
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="mxpriority" class="col-sm-6 control-label">Priorité</label>
|
||||
|
@ -262,7 +260,6 @@
|
|||
<input type="text" id="mxpriority" name="priority" class="form-control" value="10" >
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="mxrdata" class="col-sm-6 control-label">Cible</label>
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
</td>
|
||||
|
||||
<td>
|
||||
<a href="/domain/del/<% domain.domain %>" ><button type="button" class="btn btn-danger">Supprimer</button></a>
|
||||
<a href="/domain/del/<% domain.domain %>" >
|
||||
<button type="button" class="btn btn-danger">
|
||||
Supprimer
|
||||
</button>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<% END %>
|
||||
|
@ -29,6 +33,8 @@
|
|||
<p>Réservez-en un ! \o/</p>
|
||||
<% END %>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-4 col-sm-offset-1">
|
||||
<h3>Ajouter un nouveau domaine :</h3>
|
||||
|
||||
<form class="form" action='/domain/add/' method="post" >
|
||||
|
@ -37,15 +43,19 @@
|
|||
<% ELSE %>
|
||||
<input type='text' name='domain' />
|
||||
<% END %>
|
||||
<select name='tld' >
|
||||
<select name='tld' class='form-control' >
|
||||
<% FOREACH dom in provideddomains %>
|
||||
<option><% dom %></option>
|
||||
<% END %>
|
||||
</select>
|
||||
<input type='submit' name='submit' value="Créer mon domaine!" />
|
||||
<input type='submit' name='submit' value="Créer mon domaine!"
|
||||
class='btn btn-primary' />
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div> <!-- fin de colonne -->
|
||||
</div> <!-- fin de ligne -->
|
||||
|
|
Reference in New Issue