Skip to content

Commit

Permalink
Extended DNS checking - 1st pass (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
antedebaas authored Aug 19, 2024
1 parent 7f74c46 commit f21b3dc
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 47 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"antedebaas/dns-parser": "^1.2.0",
"antedebaas/dns-parser": "^1.2.1",
"buzzingpixel/twig-switch": "^1.0",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^3.1",
Expand Down
63 changes: 56 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ services:
- '../src/Entity/'
- '../src/Kernel.php'

buzzingpixel\twigswitch\SwitchTwigExtension:
tags: ['twig.extension']

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventListener\KernelExceptionListener:
Expand Down
31 changes: 31 additions & 0 deletions migrations/mysql/Version20240819175623.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240819175623 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE domains ADD bimiselector VARCHAR(255) DEFAULT NULL, ADD dkimselector VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE domains DROP bimiselector, DROP dkimselector');
}
}
34 changes: 34 additions & 0 deletions migrations/postgresql/Version20240819175040.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240819175040 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE domains ADD bimiselector VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE domains ADD dkimselector VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE domains DROP bimiselector');
$this->addSql('ALTER TABLE domains DROP dkimselector');
}
}
37 changes: 37 additions & 0 deletions migrations/sqlite/Version20240819145909.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240819145909 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE domains ADD COLUMN bimiselector VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE domains ADD COLUMN dkimselector VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__domains AS SELECT id, fqdn, sts_version, sts_mode, sts_maxage, mailhost, bimisvgfile, bimivmcfile FROM domains');
$this->addSql('DROP TABLE domains');
$this->addSql('CREATE TABLE domains (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, fqdn VARCHAR(255) NOT NULL, sts_version VARCHAR(255) DEFAULT \'STSv1\' NOT NULL, sts_mode VARCHAR(255) DEFAULT \'enforce\' NOT NULL, sts_maxage INTEGER DEFAULT 86400 NOT NULL, mailhost VARCHAR(255) NOT NULL, bimisvgfile CLOB DEFAULT NULL, bimivmcfile CLOB DEFAULT NULL)');
$this->addSql('INSERT INTO domains (id, fqdn, sts_version, sts_mode, sts_maxage, mailhost, bimisvgfile, bimivmcfile) SELECT id, fqdn, sts_version, sts_mode, sts_maxage, mailhost, bimisvgfile, bimivmcfile FROM __temp__domains');
$this->addSql('DROP TABLE __temp__domains');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8C7BBF9DC1A19758 ON domains (fqdn)');
}
}
36 changes: 22 additions & 14 deletions src/Controller/DomainsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Repository\DomainsRepository;

use Ante\DnsParser\Dns;
use Ante\DnsParser\TXTRecords;
use App\Enums\TXTRecordStates;

class DomainsController extends AbstractController
Expand Down Expand Up @@ -108,12 +109,21 @@ public function check(Domains $domain, Request $request): Response
return $this->render('not_found.html.twig', []);
}

$dnsrecords = array();
$dkimselector = $domain->getDkimselector();
if($dkimselector == null || $dkimselector == '') { $dkimselector = 'default'; }
$bimiselector = $domain->getBimiselector();
if($bimiselector == null || $bimiselector == '') { $bimiselector = 'default'; }
$selectors = array(
'dkim' => $dkimselector,
'bimi' => $bimiselector,
);

$dnsrecords = array();

$dns = new Dns();
$dnsrecords = array_merge($dnsrecords,$dns->getRecords($domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords('default._domainkey.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords('default._bimi.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords($dkimselector.'._domainkey.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords($bimiselector.'._bimi.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords('_mta-sts.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords('_dmarc.'.$domain->getFqdn(), 'TXT'));
$dnsrecords = array_merge($dnsrecords,$dns->getRecords('_smtp._tls.'.$domain->getFqdn(), 'TXT'));
Expand All @@ -126,6 +136,7 @@ public function check(Domains $domain, Request $request): Response
return $this->render('domains/check.html.twig', [
'domain' => $domain,
'validation' => $validation,
'selectors' => $selectors,
'menuactive' => 'domains',
'breadcrumbs' => array(
array('name' => $this->translator->trans("Domains"), 'url' => $this->router->generate('app_domains')),
Expand All @@ -136,23 +147,20 @@ public function check(Domains $domain, Request $request): Response

private function findvalidtxtrecords(array $records): array {
$result = array(
'SPF'=> TXTRecordStates::FAIL,
'DKIM'=> TXTRecordStates::FAIL,
'BIMI'=> TXTRecordStates::FAIL,
'STS'=> TXTRecordStates::FAIL,
'DMARC'=> TXTRecordStates::FAIL,
'TLSRPT'=> TXTRecordStates::FAIL,
'SPF'=> array(new TXTRecords\SPF1(""),TXTRecordStates::FAIL),
'DKIM'=> array(new TXTRecords\DKIM1(""),TXTRecordStates::FAIL),
'BIMI'=> array(new TXTRecords\BIMI1(""),TXTRecordStates::FAIL),
'STS'=> array(new TXTRecords\STSV1(""),TXTRecordStates::FAIL),
'DMARC'=> array(new TXTRecords\DMARC1(""),TXTRecordStates::FAIL),
'TLSRPT'=> array(new TXTRecords\TLSRPTV1(""),TXTRecordStates::FAIL),
);

foreach($records as $record) {
if($record->v()->version() == 1) {
$result[$record->v()->type()] = TXTRecordStates::GOOD;
$result[$record->v()->type()] = array($record->v(),TXTRecordStates::GOOD);
}
}
if($result['BIMI'] == TXTRecordStates::FAIL) {
$result['BIMI'] = TXTRecordStates::WARNING;
}


return $result;
}

Expand Down
30 changes: 30 additions & 0 deletions src/Entity/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class Domains
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $bimivmcfile = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $bimiselector = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $dkimselector = null;

public function __construct()
{
$this->DMARC_Reports = new ArrayCollection();
Expand Down Expand Up @@ -296,4 +302,28 @@ public function setBimiVMCFile(?string $bimivmcfile): static

return $this;
}

public function getBimiselector(): ?string
{
return $this->bimiselector;
}

public function setBimiselector(?string $bimiselector): static
{
$this->bimiselector = $bimiselector;

return $this;
}

public function getDkimselector(): ?string
{
return $this->dkimselector;
}

public function setDkimselector(?string $dkimselector): static
{
$this->dkimselector = $dkimselector;

return $this;
}
}
10 changes: 10 additions & 0 deletions src/Form/DomainFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'by_reference' => false,
])

->add('dkimselector', TextType::class, [
'label' => 'DKIM selector name',
'data' => 'default',
])

->add('bimiselector', TextType::class, [
'label' => 'BIMI selector name',
'data' => 'default',
])

->add('bimisvgfile', FileType::class, [
'label' => 'BIMI Logo SVG file',

Expand Down
2 changes: 1 addition & 1 deletion src/Twig/PrintAExtention.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getFilters(): array
];
}

public function printa(array $data): string
public function printa(object|array $data): string
{
return print_r($data);
}
Expand Down
Loading

0 comments on commit f21b3dc

Please sign in to comment.