package Email::SpoofingDemo::Web; use Dancer2; use JSON; use REST::Client; our $VERSION = '0.1'; get '/' => sub { template 'index' => { 'title' => 'Accueil' }; }; get '/dns/zone-edit/:zone' => sub { my $zone = route_parameters->get('zone'); if (defined $zone and not (grep { $_ eq $zone } @{config->{'editable_zones'}})) { pass; } my $zone_contents; if (defined $zone) { my $client = REST::Client->new(); $client->setHost(config->{'api'}{'dns'}); $client->GET("/zone/${zone}/file"); my $response = from_json($client->responseContent()); $zone_contents = $response->{'contents'}; } template 'dns/zone-edit' => { 'title' => 'Éditeur de zone DNS', 'zone_to_edit' => $zone // '', 'zone_contents' => $zone_contents // '', }; }; post '/dns/zone-edit/:zone' => sub { my $zone = route_parameters->{'zone'}; unless (grep { $_ eq $zone } @{config->{'editable_zones'}}) { pass; } my $contents = body_parameters->{'zone-contents'}; my $client = REST::Client->new(); $client->setHost(config->{'api'}{'dns'}); $client->PUT("/zone/${zone}/file", encode_json({ contents => $contents }), { "Content-Type" => "application/json", "Accept" => "application/json" }); my $success; if ($client->responseCode() eq '200') { $success = 'success'; } else { warn "Got " . $client->responseCode() . " from upstream: " . $client->responseContent(); $success = 'failure' } redirect "/dns/zone-edit/$zone?success=$success", 303; }; get '/recipient/webmail' => sub { template 'recipient/webmail' => { title => 'Courriels' }; }; any qr{.*} => sub { template '404'; }; dance; true;