Console: configurer le système destinataire

On peut désormais activer ou désactiver le contrôle SPF, DKIM et DMARC
sur le système destinataire.
This commit is contained in:
Marc van der Wal 2023-10-25 15:50:29 +02:00
parent 2ac52d0578
commit 23409b4d6f
3 changed files with 85 additions and 0 deletions

View File

@ -6,6 +6,37 @@ use REST::Client;
our $VERSION = '0.1'; our $VERSION = '0.1';
sub call_api {
my ($method, $target, $url, $body_parameters) = @_;
my $host = config->{'api'}{$target};
die "Invalid target: $target" unless defined $host;
my $client = REST::Client->new();
$client->setHost($host);
$client->setTimeout(5);
$client->addHeader('Accept' => 'application/json');
$client->addHeader('Content-Type' => 'application/json');
my $body_data;
$body_data = encode_json($body_parameters) if defined $body_parameters;
$client->request($method, $url, $body_data);
my $status = $client->responseCode();
if ($status =~ /^2\d\d$/) {
my $response;
if ($client->responseContent() ne '') {
$response = decode_json($client->responseContent());
}
return ($response, $status);
}
else {
warn "API request returned $status";
return ($client->responseContent(), $status);
}
}
get '/' => sub { get '/' => sub {
template 'index' => { 'title' => 'Accueil' }; template 'index' => { 'title' => 'Accueil' };
}; };
@ -59,6 +90,26 @@ post '/dns/zone-edit/:zone' => sub {
} }
redirect "/dns/zone-edit/$zone?success=$success", 303; redirect "/dns/zone-edit/$zone?success=$success", 303;
get '/recipient/settings' => sub {
my ($system_status, $http_code) = call_api(GET => 'recipient', '/status');
die if $http_code ne '200';
template 'recipient/settings' => {
title => 'Paramètres du système destinataire',
system_status => $system_status
};
};
post '/recipient/settings' => sub {
my %api_params = map {
$_ => body_parameters->{"$_-status"} ? 'enabled' : 'disabled'
} qw(spf dkim dmarc);
my (undef, $status) = call_api(PUT => 'recipient', '/status', \%api_params);
my $success = ($status eq 200) ? 'success' : 'failure';
redirect "/recipient/settings?success=$success", 303;
};
}; };
get '/recipient/webmail' => sub { get '/recipient/webmail' => sub {

View File

@ -30,6 +30,7 @@
<li class="nav-item dropdown"> <li class="nav-item dropdown">
[% PROCESS role id="recipient" label="Destinataire" %] [% PROCESS role id="recipient" label="Destinataire" %]
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="[% request.uri_base %]/recipient/settings">Paramétrer le système</a></li>
<li><a class="dropdown-item" href="[% request.uri_base %]/dns/zone-edit/destinataire.example">Éditer la zone DNS</a></li> <li><a class="dropdown-item" href="[% request.uri_base %]/dns/zone-edit/destinataire.example">Éditer la zone DNS</a></li>
<li><a class="dropdown-item" href="[% request.uri_base %]/recipient/webmail">Relever les courriels</a></li> <li><a class="dropdown-item" href="[% request.uri_base %]/recipient/webmail">Relever les courriels</a></li>
</ul> </ul>

View File

@ -0,0 +1,33 @@
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>Paramètres du système destinataire</h1>
<h2>Vérifications SPF, DKIM et DMARC</h2>
<form method="POST" class="mt-3 container">
[% FOR item IN ['spf', 'dkim', 'dmarc'] %]
<div class="row mb-2 border-bottom">
<div class="col-sm-7 form-check form-switch">
<label class="form-check-label" for="[% item %]-status">Activer le contrôle [% item.upper %]</label>
<input class="form-check-input" type="checkbox" role="switch" id="[% item %]-status"
name="[% item %]-status"
[%- IF system_status.item(item) == 'enabled' %] checked[% END -%]>
</div>
<div class="col-sm-5" for="[% item %]-status">
État actuel:
[% IF system_status.item(item) == 'enabled' %]
<span class="text-success">activé</span>
[% ELSE %]
<span class="text-danger">inactif</span>
[% END %]
</div>
</div>
[% END %]
<div class="row mt-3">
<div class="col">
<button class="btn btn-primary" type="submit">Valider</button>
</div>
</div>
</form>
</div>
</div>
</div>