liuch / dmarc-srg

A php parser, viewer and summary report generator for incoming DMARC reports.
GNU General Public License v3.0
218 stars 32 forks source link

Subdomain reports generate: Failed to add an incoming report: unknown domain #10

Closed reingit closed 2 years ago

reingit commented 2 years ago

When subdomains have different policies, or at least generate their own reports. Things stop working. Any (easy) fix for this? Can I manually add the subdomains in the DB?

    try {
        $fqdn = $this->data['domain'];
        $domain = new Domain($fqdn);
        if (!$domain->exists()) {
            // The domain is not found.
            // It will automatically added a new domain if there are no domains in the table
            // or will throw an error otherwise.
            if (DomainList::count() !== 0) {
                throw new Exception('Failed to add an incoming report: unknown domain', -1);
            }

Is what errors out.

liuch commented 2 years ago

Hi, reingit! The DB has a table named domains, that stores the allowed domains, so you can add new records to it. You can also add any domain to the DB via the web interface (Main menu --> Settings --> Domains). I hope this helps you.

liuch commented 2 years ago

I would like to clarify: only the first domain from the first processed report will be automatically added to the database. The rest of the domains must be added explicitly.

reingit commented 2 years ago

I assume you filter out these domains since you don't want spammers to fill up the DB with sending rua support for other domains? Since I'm in the situation where I have 100+ subdomains with (possible) different dmarc policies that come and go I'm not sure if adding by hand will work.

What if I do something like this: (untested), you think that could work: ` $fqdn = $this->data['domain']; $domain = new Domain($fqdn); if (!$domain->exists()) { // The domain is not found. // It will automatically added a new domain if there are no domains in the table // or will throw an error otherwise. if (DomainList::count() !== 0) { // Check if this is for a subdomain and the "main" domain exists in the DB. if (preg_match('/[a-z0-9][a-z0-9-]{0,63}.[a-z]{2,6}(.[a-z]{1,2})?$/i', $fqdn, $match)) { if ($match[0]->exists()) { // Allow creation of subdomains automagically when root/main domain already exists... } else { throw new Exception('Failed to add an incoming report: unknown subdomain', -1); } } else { throw new Exception('Failed to add an incoming report: unknown domain', -1); } }

$domain = new Domain([
    'fqdn'        => $fqdn,
    'active'      => true,
    'description' => 'The domain was added automatically.'
]);
$domain->save();

} elseif (!$domain->active()) { throw new Exception('Failed to add an incoming report: the domain is inactive', -1); } `

reingit commented 2 years ago

obviously I can't make codeblocks on github. sorry for that. also the regex is just something i grabbed from google for now .. It's more that i'm wondering if you see a problem with hacking something in there at ./classes/Report/Report.php or that you see it breaking other stuff.

Thanks so far!

liuch commented 2 years ago

I assume you filter out these domains since you don't want spammers to fill up the DB with sending rua support for other domains?

Yes, you are right. This is exactly what my idea is. Moreover it is necessary for a quick selection of reports for the specified domain from the DB.

What if I do something like this: (untested), you think that could work:

This will definitely not work out, because the table where reports are stored has a field domain_id and each report must match a record in the domains table.

I wrote this for my own little mail server which has fewer requirements than yours. I see the only way out in the form of support for wildcard domain in my project, something like *.yourdomain.net. But then you will only get one summary report for such a wildcard domain, no subdomain breakdown. This feature is currently not implemented. Maybe it is better to use another project according to your requirements?

liuch commented 2 years ago

One more way is to add an option for automatically adding any new domains (not only the first one) in the DB, but then there will be a problem with cleaning unused domains.

llsnndlldkm commented 2 years ago

Could you make this an option (conf + web interface) so people can decide for themselves if they would like to have domains added automatically?

liuch commented 2 years ago

@llsnndlldkm, I think that's a good idea. I will add this option soon.

reingit commented 2 years ago

Thank you! Just tested this and can confirm it works.