81 lines
2.0 KiB
Perl
81 lines
2.0 KiB
Perl
#
|
|
# SPDX-FileCopyrightText: 2023 Afnic
|
|
#
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
#
|
|
|
|
package Email::SpoofingDemo::API::Sender;
|
|
|
|
use Dancer2;
|
|
|
|
use Email::SpoofingDemo::DKIM qw(read_signing_table read_key_table
|
|
write_signing_table write_key_table
|
|
generate_dkim_key);
|
|
|
|
our $VERSION = '0.1';
|
|
|
|
my $signing_table = "/etc/opendkim/signing_table";
|
|
my $key_table = "/etc/opendkim/key_table";
|
|
my $key_dir = "/etc/opendkim/keys";
|
|
|
|
get '/' => sub { return "Welcome"; };
|
|
|
|
get '/installed-keys' => sub {
|
|
my $signing_table = read_signing_table($signing_table);
|
|
my $key_table = read_key_table($key_table);
|
|
|
|
my @result;
|
|
|
|
for my $domain (sort keys %$key_table) {
|
|
push @result, {
|
|
domain => $domain,
|
|
available_keys => $key_table->{$domain},
|
|
current_key => $signing_table->{$domain}
|
|
};
|
|
}
|
|
|
|
return \@result;
|
|
};
|
|
|
|
post '/generate-dkim-key' => sub {
|
|
my $domain = body_parameters->get('domain');
|
|
my $selector = body_parameters->get('selector');
|
|
my $key_size = body_parameters->get('key_size');
|
|
|
|
# Generate key
|
|
my $txt_data = generate_dkim_key($domain, $selector, $key_size,
|
|
$key_table, $key_dir, $signing_table);
|
|
|
|
my $txt_record = sprintf("%-30s. TXT %s",
|
|
qq{$selector._domainkey.$domain},
|
|
$txt_data);
|
|
|
|
return {
|
|
txt_record => $txt_record
|
|
};
|
|
};
|
|
|
|
post '/send-email/confirmation_email' => sub {
|
|
system("/home/expediteur/scripts/send_confirmation_email.sh");
|
|
my $status = ($? >> 8);
|
|
if ($status != 0) {
|
|
status(500);
|
|
return "E-mail script exited with status $status";
|
|
}
|
|
};
|
|
|
|
post '/send-email/newsletter' => sub {
|
|
system("/home/expediteur/scripts/send_newsletter.sh");
|
|
my $status = ($? >> 8);
|
|
if ($status != 0) {
|
|
status(500);
|
|
return "E-mail script exited with status $status";
|
|
}
|
|
};
|
|
|
|
any qr{.*} => sub { status 'not_found'; return "Invalid route" };
|
|
|
|
dance;
|
|
|
|
true;
|