From 1948e543bf0e42941d27c746b0bb670262cdb60b Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 00:58:03 +0100 Subject: [PATCH 01/18] initial --- composer.json | 4 +- composer.lock | 367 +++++++++++++++++- config/bundles.php | 1 + config/packages/gpslab_geoip.yaml | 4 + dockerfiles/usr/local/bin/containerstartup.sh | 1 + src/Twig/Domain2Ip.php | 61 +++ src/Twig/Email2Domain.php | 25 ++ src/Twig/GeoIp.php | 65 ++++ symfony.lock | 3 + templates/base/index.html.twig | 4 +- templates/dmarc_reports/report.html.twig | 18 +- templates/smtptls_reports/report.html.twig | 131 +++---- 12 files changed, 602 insertions(+), 82 deletions(-) create mode 100644 config/packages/gpslab_geoip.yaml create mode 100644 src/Twig/Domain2Ip.php create mode 100644 src/Twig/Email2Domain.php create mode 100644 src/Twig/GeoIp.php diff --git a/composer.json b/composer.json index 1338d33..4f522e8 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "ext-ctype": "*", "ext-iconv": "*", "antedebaas/dns-parser": "^1.2.2", + "antedebaas/geoip2": "2.1.1", "buzzingpixel/twig-switch": "^1.0", "doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-migrations-bundle": "^3.2", @@ -70,7 +71,8 @@ "scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", - "assets:install %PUBLIC_DIR%": "symfony-cmd" + "assets:install %PUBLIC_DIR%": "symfony-cmd", + "geoip2:update": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" diff --git a/composer.lock b/composer.lock index 7c8f5df..40c524c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d25431624d3c6d3bcbfde60ac031042", + "content-hash": "79787970b5d49c55c32c79e2e984a325", "packages": [ { "name": "antedebaas/dns-parser", @@ -78,6 +78,57 @@ }, "time": "2024-08-22T17:35:56+00:00" }, + { + "name": "antedebaas/geoip2", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/antedebaas/geoip2.git", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antedebaas/geoip2/zipball/c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "shasum": "" + }, + "require": { + "ext-phar": "*", + "ext-zlib": "*", + "geoip2/geoip2": "~2.0", + "php": ">=7.2.0", + "symfony/config": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/console": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/expression-language": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/filesystem": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "~7.0|~8.0|~9.0" + }, + "suggest": { + "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "GpsLab\\Bundle\\GeoIP2Bundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A Symfony Bundle for the Maxmind GeoIP2 API", + "homepage": "https://github.com/antedebaas/geoip2", + "support": { + "source": "https://github.com/antedebaas/geoip2/tree/v2.1.1" + }, + "time": "2024-10-30T20:39:51+00:00" + }, { "name": "buzzingpixel/twig-switch", "version": "1.0.2", @@ -127,6 +178,82 @@ }, "time": "2020-06-21T00:42:23+00:00" }, + { + "name": "composer/ca-bundle", + "version": "1.5.3", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8 || ^9", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/ca-bundle/issues", + "source": "https://github.com/composer/ca-bundle/tree/1.5.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-11-04T10:15:26+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -1415,6 +1542,180 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "geoip2/geoip2", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "shasum": "" + }, + "require": { + "ext-json": "*", + "maxmind-db/reader": "~1.8", + "maxmind/web-service-common": "~0.8", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/GeoIP2-php/issues", + "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.13.0" + }, + "time": "2022-08-05T20:32:58+00:00" + }, + { + "name": "maxmind-db/reader", + "version": "v1.11.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.11.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "php-coveralls/php-coveralls": "^2.1", + "phpstan/phpstan": "*", + "phpunit/phpcov": ">=6.0.0", + "phpunit/phpunit": ">=8.0.0,<10.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.1" + }, + "time": "2023-12-02T00:09:23+00:00" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.9.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Exception\\": "src/Exception", + "MaxMind\\WebService\\": "src/WebService" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/web-service-common-php", + "support": { + "issues": "https://github.com/maxmind/web-service-common-php/issues", + "source": "https://github.com/maxmind/web-service-common-php/tree/v0.9.0" + }, + "time": "2022-03-28T17:43:20+00:00" + }, { "name": "php-imap/php-imap", "version": "5.0.1", @@ -2904,6 +3205,70 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/expression-language", + "version": "v7.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/expression-language.git", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/expression-language/zipball/c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/cache": "^6.4|^7.0", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/service-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\ExpressionLanguage\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an engine that can compile and evaluate expressions", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/expression-language/tree/v7.1.6" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-09T08:46:59+00:00" + }, { "name": "symfony/filesystem", "version": "v7.1.6", diff --git a/config/bundles.php b/config/bundles.php index bd86778..4e31f68 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -11,4 +11,5 @@ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], SecIT\ImapBundle\ImapBundle::class => ['all' => true], SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], + GpsLab\Bundle\GeoIP2Bundle\GpsLabGeoIP2Bundle::class => ['all' => true], ]; diff --git a/config/packages/gpslab_geoip.yaml b/config/packages/gpslab_geoip.yaml new file mode 100644 index 0000000..cd4d184 --- /dev/null +++ b/config/packages/gpslab_geoip.yaml @@ -0,0 +1,4 @@ +gpslab_geoip: + license: '%env(MAXMIND_LICENCE)%' + edition: 'GeoLite2-Country' + path: '%kernel.project_dir%/var/data/GeoLite2-Country.mmdb' \ No newline at end of file diff --git a/dockerfiles/usr/local/bin/containerstartup.sh b/dockerfiles/usr/local/bin/containerstartup.sh index 7055a88..100354e 100755 --- a/dockerfiles/usr/local/bin/containerstartup.sh +++ b/dockerfiles/usr/local/bin/containerstartup.sh @@ -14,6 +14,7 @@ if [ ! -f "/var/www/html/.env.local" ]; then echo "ENABLE_REGISTRATION=\"$ENABLE_REGISTRATION\"" >> /var/www/html/.env.local echo "PUSHOVER_API_KEY=\"$PUSHOVER_API_KEY\"" >> /var/www/html/.env.local echo "PUSHOVER_USER_KEY=\"$PUSHOVER_USER_KEY\"" >> /var/www/html/.env.local + echo "MAXMIND_LICENCE=\"$MAXMIND_LICENCE\"" >> /var/www/html/.env.local fi echo "Check if attachments directory exists" diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php new file mode 100644 index 0000000..5f47388 --- /dev/null +++ b/src/Twig/Domain2Ip.php @@ -0,0 +1,61 @@ +reader = $reader; + } + + public function getFilters(): array + { + return [ + new TwigFilter('domain2ip', [$this, 'domain2ipFilter']), + ]; + } + + public function domain2ipFilter($domain) + { + if (empty($domain)) { + return ''; + } + $email = null; + if (is_array($domain)) { + $email = $domain[1]; + $domain = $domain[0]; + } + + $dns = new Dns(); + try { + $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + } catch (\Exception $e) { + $ipv4 = ''; + } + try { + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + } catch (\Exception $e) { + $ipv6 = ''; + } + + if(!empty($ipv6)) { + $ip = $ipv6; + } else { + $ip = $ipv4; + } + + if (!is_null($email)) { + return array($ip, $email); + } else { + return array($ip, $domain); + } + } +} \ No newline at end of file diff --git a/src/Twig/Email2Domain.php b/src/Twig/Email2Domain.php new file mode 100644 index 0000000..1c6a0d2 --- /dev/null +++ b/src/Twig/Email2Domain.php @@ -0,0 +1,25 @@ +reader = $reader; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('geoip', [$this, 'geoipFunction'], ['is_safe' => ['html']]), + ]; + } + + public function geoipFunction($type, $ip) + { + + if (empty($ip)) { + return ''; + } + $domain = null; + if (is_array($ip)) { + $domain = $ip[1]; + $ip = $ip[0]; + } + + try { + $iso = strtolower($this->reader->country($ip)->country->isoCode); + } catch (\Exception $e) { + $iso = ''; + } + try { + switch ($type) { + case 'country' || 'default': + $response = ''; + + if (!is_null($domain)) { + return $domain.' '.$response; + } else { + return $ip.' '.$response; + } + + default: + return $ip; + } + } + catch (\Exception $e) { + return $ip; + } + } +} \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index 696c730..c8b95d0 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,7 @@ { + "antedebaas/geoip2": { + "version": "v2.1.1" + }, "antedebaas/imap-bundle": { "version": "2.0.1" }, diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 67d3e05..17f09e2 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -9,8 +9,8 @@ Viesti Reports - {{ page.title }} - {# - + + {# #} {% block stylesheets %}{% endblock %} diff --git a/templates/dmarc_reports/report.html.twig b/templates/dmarc_reports/report.html.twig index 7289504..4ba1464 100644 --- a/templates/dmarc_reports/report.html.twig +++ b/templates/dmarc_reports/report.html.twig @@ -11,19 +11,19 @@
  • Reporting for: - {{ report.domain.fqdn }} + {{ geoip('country',report.domain.fqdn|domain2ip) }}
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • E-Mail: - {{ report.email }} + {{ geoip('country',report.email|email2domain|domain2ip) }}
  • @@ -45,13 +45,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -170,25 +170,25 @@
  • Envelope to: - {{ record.envelopeto }} + {{ geoip('country',record.envelopeto|domain2ip) }}
  • Envelope from: - {{ record.envelopefrom }} + {{ geoip('country',record.envelopefrom|domain2ip) }}
  • Header from: - {{ record.headerfrom }} + {{ geoip('country',record.headerfrom|domain2ip) }}
  • IP Address: - {{ record.sourceip }} + {{ geoip('country',record.sourceip) }}
  • diff --git a/templates/smtptls_reports/report.html.twig b/templates/smtptls_reports/report.html.twig index 15e5078..b5509d9 100644 --- a/templates/smtptls_reports/report.html.twig +++ b/templates/smtptls_reports/report.html.twig @@ -11,7 +11,7 @@
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • @@ -34,13 +34,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -61,16 +61,14 @@
  • Domain: - - {{ policy.policydomain.fqdn }} - + {{ geoip('country',policy.policydomain.fqdn|domain2ip) }}
  • {% for mxrecord in policy.smtptls_mxrecords|sort((a, b) => a.priority <=> b.priority) %}
  • MX: - {{ mxrecord.mxrecord.name }} + {{ geoip('country',mxrecord.mxrecord.name|domain2ip) }}
  • {% endfor %} @@ -78,68 +76,63 @@
  • String max age: - {{ policy.policystringmaxage }} sec + {{ policy.policystringmaxage }} sec
  • {% endif %}

    - + TLSA resource record: + + + {% endfor %}
    @@ -223,13 +216,13 @@
  • Sending MTA IP: - {{ failuredetail.sendingmtaip }} + {{ geoip('country',failuredetail.sendingmtaip) }}
  • Receiving IP: - {{ failuredetail.receivingip }} + {{ geoip('country',failuredetail.receivingip) }}
  • From acc7acce4c2163e45515281141dfc4db2ff29760 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:06:47 +0100 Subject: [PATCH 02/18] update view all button on dashboard --- templates/dashboard/index.html.twig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/templates/dashboard/index.html.twig b/templates/dashboard/index.html.twig index 6271273..e53a5fa 100644 --- a/templates/dashboard/index.html.twig +++ b/templates/dashboard/index.html.twig @@ -65,7 +65,10 @@
    - View all +

    +
    + View all +
    @@ -154,7 +157,10 @@ - View all +

    +
    + View all +
    @@ -212,7 +218,10 @@ - View all +

    +
    + View all +
    From 926ccc6e82ed3baf72b1fdbc28ffac26f08ed807 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:16:26 +0100 Subject: [PATCH 03/18] ip on null --- src/Twig/Domain2Ip.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index 5f47388..e7d7220 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -36,12 +36,22 @@ public function domain2ipFilter($domain) $dns = new Dns(); try { - $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + $ipv4 = $dns->getRecords($domain, 'A')[0]; + if(!is_null($ipv4)) { + $ipv4 = $ipv4->toArray()["ip"]; + } else { + $ipv4 = ''; + } } catch (\Exception $e) { $ipv4 = ''; } try { - $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; + if(!is_null($ipv4)) { + $ipv6 = $ipv6->toArray()["ipv6"]; + } else { + $ipv6 = ''; + } } catch (\Exception $e) { $ipv6 = ''; } From 11403b6668d667e6f3b63d5ba30b27e3f3080858 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:23:55 +0100 Subject: [PATCH 04/18] ipv6 --- src/Twig/Domain2Ip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index e7d7220..2d8af08 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -47,7 +47,7 @@ public function domain2ipFilter($domain) } try { $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; - if(!is_null($ipv4)) { + if(!is_null($ipv6)) { $ipv6 = $ipv6->toArray()["ipv6"]; } else { $ipv6 = ''; From 05968d5a4886170a633e3dfd1cc620e508a7d581 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 00:58:03 +0100 Subject: [PATCH 05/18] initial --- composer.json | 4 +- composer.lock | 367 +++++++++++++++++- config/bundles.php | 1 + config/packages/gpslab_geoip.yaml | 4 + dockerfiles/usr/local/bin/containerstartup.sh | 1 + src/Twig/Domain2Ip.php | 61 +++ src/Twig/Email2Domain.php | 25 ++ src/Twig/GeoIp.php | 65 ++++ symfony.lock | 3 + templates/base/index.html.twig | 4 +- templates/dmarc_reports/report.html.twig | 18 +- templates/smtptls_reports/report.html.twig | 131 +++---- 12 files changed, 602 insertions(+), 82 deletions(-) create mode 100644 config/packages/gpslab_geoip.yaml create mode 100644 src/Twig/Domain2Ip.php create mode 100644 src/Twig/Email2Domain.php create mode 100644 src/Twig/GeoIp.php diff --git a/composer.json b/composer.json index 1338d33..4f522e8 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "ext-ctype": "*", "ext-iconv": "*", "antedebaas/dns-parser": "^1.2.2", + "antedebaas/geoip2": "2.1.1", "buzzingpixel/twig-switch": "^1.0", "doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-migrations-bundle": "^3.2", @@ -70,7 +71,8 @@ "scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", - "assets:install %PUBLIC_DIR%": "symfony-cmd" + "assets:install %PUBLIC_DIR%": "symfony-cmd", + "geoip2:update": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" diff --git a/composer.lock b/composer.lock index 7c8f5df..40c524c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d25431624d3c6d3bcbfde60ac031042", + "content-hash": "79787970b5d49c55c32c79e2e984a325", "packages": [ { "name": "antedebaas/dns-parser", @@ -78,6 +78,57 @@ }, "time": "2024-08-22T17:35:56+00:00" }, + { + "name": "antedebaas/geoip2", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/antedebaas/geoip2.git", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antedebaas/geoip2/zipball/c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "shasum": "" + }, + "require": { + "ext-phar": "*", + "ext-zlib": "*", + "geoip2/geoip2": "~2.0", + "php": ">=7.2.0", + "symfony/config": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/console": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/expression-language": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/filesystem": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "~7.0|~8.0|~9.0" + }, + "suggest": { + "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "GpsLab\\Bundle\\GeoIP2Bundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A Symfony Bundle for the Maxmind GeoIP2 API", + "homepage": "https://github.com/antedebaas/geoip2", + "support": { + "source": "https://github.com/antedebaas/geoip2/tree/v2.1.1" + }, + "time": "2024-10-30T20:39:51+00:00" + }, { "name": "buzzingpixel/twig-switch", "version": "1.0.2", @@ -127,6 +178,82 @@ }, "time": "2020-06-21T00:42:23+00:00" }, + { + "name": "composer/ca-bundle", + "version": "1.5.3", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8 || ^9", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/ca-bundle/issues", + "source": "https://github.com/composer/ca-bundle/tree/1.5.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-11-04T10:15:26+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -1415,6 +1542,180 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "geoip2/geoip2", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "shasum": "" + }, + "require": { + "ext-json": "*", + "maxmind-db/reader": "~1.8", + "maxmind/web-service-common": "~0.8", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/GeoIP2-php/issues", + "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.13.0" + }, + "time": "2022-08-05T20:32:58+00:00" + }, + { + "name": "maxmind-db/reader", + "version": "v1.11.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.11.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "php-coveralls/php-coveralls": "^2.1", + "phpstan/phpstan": "*", + "phpunit/phpcov": ">=6.0.0", + "phpunit/phpunit": ">=8.0.0,<10.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.1" + }, + "time": "2023-12-02T00:09:23+00:00" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.9.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Exception\\": "src/Exception", + "MaxMind\\WebService\\": "src/WebService" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/web-service-common-php", + "support": { + "issues": "https://github.com/maxmind/web-service-common-php/issues", + "source": "https://github.com/maxmind/web-service-common-php/tree/v0.9.0" + }, + "time": "2022-03-28T17:43:20+00:00" + }, { "name": "php-imap/php-imap", "version": "5.0.1", @@ -2904,6 +3205,70 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/expression-language", + "version": "v7.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/expression-language.git", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/expression-language/zipball/c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/cache": "^6.4|^7.0", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/service-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\ExpressionLanguage\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an engine that can compile and evaluate expressions", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/expression-language/tree/v7.1.6" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-09T08:46:59+00:00" + }, { "name": "symfony/filesystem", "version": "v7.1.6", diff --git a/config/bundles.php b/config/bundles.php index bd86778..4e31f68 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -11,4 +11,5 @@ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], SecIT\ImapBundle\ImapBundle::class => ['all' => true], SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], + GpsLab\Bundle\GeoIP2Bundle\GpsLabGeoIP2Bundle::class => ['all' => true], ]; diff --git a/config/packages/gpslab_geoip.yaml b/config/packages/gpslab_geoip.yaml new file mode 100644 index 0000000..cd4d184 --- /dev/null +++ b/config/packages/gpslab_geoip.yaml @@ -0,0 +1,4 @@ +gpslab_geoip: + license: '%env(MAXMIND_LICENCE)%' + edition: 'GeoLite2-Country' + path: '%kernel.project_dir%/var/data/GeoLite2-Country.mmdb' \ No newline at end of file diff --git a/dockerfiles/usr/local/bin/containerstartup.sh b/dockerfiles/usr/local/bin/containerstartup.sh index 7055a88..100354e 100755 --- a/dockerfiles/usr/local/bin/containerstartup.sh +++ b/dockerfiles/usr/local/bin/containerstartup.sh @@ -14,6 +14,7 @@ if [ ! -f "/var/www/html/.env.local" ]; then echo "ENABLE_REGISTRATION=\"$ENABLE_REGISTRATION\"" >> /var/www/html/.env.local echo "PUSHOVER_API_KEY=\"$PUSHOVER_API_KEY\"" >> /var/www/html/.env.local echo "PUSHOVER_USER_KEY=\"$PUSHOVER_USER_KEY\"" >> /var/www/html/.env.local + echo "MAXMIND_LICENCE=\"$MAXMIND_LICENCE\"" >> /var/www/html/.env.local fi echo "Check if attachments directory exists" diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php new file mode 100644 index 0000000..5f47388 --- /dev/null +++ b/src/Twig/Domain2Ip.php @@ -0,0 +1,61 @@ +reader = $reader; + } + + public function getFilters(): array + { + return [ + new TwigFilter('domain2ip', [$this, 'domain2ipFilter']), + ]; + } + + public function domain2ipFilter($domain) + { + if (empty($domain)) { + return ''; + } + $email = null; + if (is_array($domain)) { + $email = $domain[1]; + $domain = $domain[0]; + } + + $dns = new Dns(); + try { + $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + } catch (\Exception $e) { + $ipv4 = ''; + } + try { + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + } catch (\Exception $e) { + $ipv6 = ''; + } + + if(!empty($ipv6)) { + $ip = $ipv6; + } else { + $ip = $ipv4; + } + + if (!is_null($email)) { + return array($ip, $email); + } else { + return array($ip, $domain); + } + } +} \ No newline at end of file diff --git a/src/Twig/Email2Domain.php b/src/Twig/Email2Domain.php new file mode 100644 index 0000000..1c6a0d2 --- /dev/null +++ b/src/Twig/Email2Domain.php @@ -0,0 +1,25 @@ +reader = $reader; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('geoip', [$this, 'geoipFunction'], ['is_safe' => ['html']]), + ]; + } + + public function geoipFunction($type, $ip) + { + + if (empty($ip)) { + return ''; + } + $domain = null; + if (is_array($ip)) { + $domain = $ip[1]; + $ip = $ip[0]; + } + + try { + $iso = strtolower($this->reader->country($ip)->country->isoCode); + } catch (\Exception $e) { + $iso = ''; + } + try { + switch ($type) { + case 'country' || 'default': + $response = ''; + + if (!is_null($domain)) { + return $domain.' '.$response; + } else { + return $ip.' '.$response; + } + + default: + return $ip; + } + } + catch (\Exception $e) { + return $ip; + } + } +} \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index 696c730..c8b95d0 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,7 @@ { + "antedebaas/geoip2": { + "version": "v2.1.1" + }, "antedebaas/imap-bundle": { "version": "2.0.1" }, diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 67d3e05..17f09e2 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -9,8 +9,8 @@ Viesti Reports - {{ page.title }} - {# - + + {# #} {% block stylesheets %}{% endblock %} diff --git a/templates/dmarc_reports/report.html.twig b/templates/dmarc_reports/report.html.twig index 7289504..4ba1464 100644 --- a/templates/dmarc_reports/report.html.twig +++ b/templates/dmarc_reports/report.html.twig @@ -11,19 +11,19 @@
  • Reporting for: - {{ report.domain.fqdn }} + {{ geoip('country',report.domain.fqdn|domain2ip) }}
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • E-Mail: - {{ report.email }} + {{ geoip('country',report.email|email2domain|domain2ip) }}
  • @@ -45,13 +45,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -170,25 +170,25 @@
  • Envelope to: - {{ record.envelopeto }} + {{ geoip('country',record.envelopeto|domain2ip) }}
  • Envelope from: - {{ record.envelopefrom }} + {{ geoip('country',record.envelopefrom|domain2ip) }}
  • Header from: - {{ record.headerfrom }} + {{ geoip('country',record.headerfrom|domain2ip) }}
  • IP Address: - {{ record.sourceip }} + {{ geoip('country',record.sourceip) }}
  • diff --git a/templates/smtptls_reports/report.html.twig b/templates/smtptls_reports/report.html.twig index 15e5078..b5509d9 100644 --- a/templates/smtptls_reports/report.html.twig +++ b/templates/smtptls_reports/report.html.twig @@ -11,7 +11,7 @@
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • @@ -34,13 +34,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -61,16 +61,14 @@
  • Domain: - - {{ policy.policydomain.fqdn }} - + {{ geoip('country',policy.policydomain.fqdn|domain2ip) }}
  • {% for mxrecord in policy.smtptls_mxrecords|sort((a, b) => a.priority <=> b.priority) %}
  • MX: - {{ mxrecord.mxrecord.name }} + {{ geoip('country',mxrecord.mxrecord.name|domain2ip) }}
  • {% endfor %} @@ -78,68 +76,63 @@
  • String max age: - {{ policy.policystringmaxage }} sec + {{ policy.policystringmaxage }} sec
  • {% endif %}

    -
      {% for rdata in policy.smtptls_rdatarecords %} -
    • -
      - TLSA resource record: -
        -
      • -
        - Usage: - - PKIX-TA - {% elseif rdata.usagetype == 1 %}data-bs-title="Service Certificate Constraint">PKIX-EE - {% elseif rdata.usagetype == 2 %}data-bs-title="Trust Anchor Assertion">DANE-TA - {% elseif rdata.usagetype == 3 %}data-bs-title="Domain Issued Certificate">DANE-EE - {% endif %} - - - - -
        -
      • -
      • -
        - Selector: - - Cert - {% elseif rdata.selectortype == 1 %}data-bs-title="Use subject public key">SPKI - {% endif %} - - - - -
        -
      • -
      • -
        - Matching-Type: - - Full - {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-256 hash">SHA-256 - {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-512 hash">SHA-512 - {% endif %} - - - - -
        -
      • -
      - -
    • - {% endfor %} -
    + TLSA resource record: +
      +
    • +
      + Usage: + + PKIX-TA + {% elseif rdata.usagetype == 1 %}data-bs-title="Service Certificate Constraint">PKIX-EE + {% elseif rdata.usagetype == 2 %}data-bs-title="Trust Anchor Assertion">DANE-TA + {% elseif rdata.usagetype == 3 %}data-bs-title="Domain Issued Certificate">DANE-EE + {% endif %} + + + + +
      +
    • +
    • +
      + Selector: + + Cert + {% elseif rdata.selectortype == 1 %}data-bs-title="Use subject public key">SPKI + {% endif %} + + + + +
      +
    • +
    • +
      + Matching-Type: + + Full + {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-256 hash">SHA-256 + {% elseif rdata.matchingtype == 2 %}data-bs-title="SHA-512 hash">SHA-512 + {% endif %} + + + + +
      +
    • +
    + + {% endfor %}
      @@ -176,7 +169,7 @@
    • Summary successful count: - {{ policy.summarysuccessfulcount }} + {{ policy.summarysuccessfulcount }}
    • @@ -201,19 +194,19 @@
    • Receiving MX Hostname: - {{ failuredetail.receivingmxhostname.name }} + {{ geoip('country',failuredetail.receivingmxhostname.name|domain2ip) }}
    • Result: - {{ failuredetail.resulttype }} + {{ failuredetail.resulttype }}
    • Failed Session Count: - {{ failuredetail.failedsessioncount }} + {{ failuredetail.failedsessioncount }}
    @@ -223,13 +216,13 @@
  • Sending MTA IP: - {{ failuredetail.sendingmtaip }} + {{ geoip('country',failuredetail.sendingmtaip) }}
  • Receiving IP: - {{ failuredetail.receivingip }} + {{ geoip('country',failuredetail.receivingip) }}
  • From d3ab725bb4629bb59c5312307974212aa02cf58f Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:06:47 +0100 Subject: [PATCH 06/18] update view all button on dashboard --- templates/dashboard/index.html.twig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/templates/dashboard/index.html.twig b/templates/dashboard/index.html.twig index 6271273..e53a5fa 100644 --- a/templates/dashboard/index.html.twig +++ b/templates/dashboard/index.html.twig @@ -65,7 +65,10 @@
    - View all +

    +
    + View all +
    @@ -154,7 +157,10 @@ - View all +

    +
    + View all +
    @@ -212,7 +218,10 @@ - View all +

    +
    + View all +
    From 2a89aa59287d57644b331e86aedc91d66ef9de8d Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:16:26 +0100 Subject: [PATCH 07/18] ip on null --- src/Twig/Domain2Ip.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index 5f47388..e7d7220 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -36,12 +36,22 @@ public function domain2ipFilter($domain) $dns = new Dns(); try { - $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + $ipv4 = $dns->getRecords($domain, 'A')[0]; + if(!is_null($ipv4)) { + $ipv4 = $ipv4->toArray()["ip"]; + } else { + $ipv4 = ''; + } } catch (\Exception $e) { $ipv4 = ''; } try { - $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; + if(!is_null($ipv4)) { + $ipv6 = $ipv6->toArray()["ipv6"]; + } else { + $ipv6 = ''; + } } catch (\Exception $e) { $ipv6 = ''; } From d428cff8d4fc7ca1f476d195420906aebf304687 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:23:55 +0100 Subject: [PATCH 08/18] ipv6 --- src/Twig/Domain2Ip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index e7d7220..2d8af08 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -47,7 +47,7 @@ public function domain2ipFilter($domain) } try { $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; - if(!is_null($ipv4)) { + if(!is_null($ipv6)) { $ipv6 = $ipv6->toArray()["ipv6"]; } else { $ipv6 = ''; From 31dfb725659e9964b5fd47d496723ac6dd12b729 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 17:50:28 +0100 Subject: [PATCH 09/18] icon stuff --- templates/base/index.html.twig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 17f09e2..17c46a4 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -4,9 +4,10 @@ - - - + + + + Viesti Reports - {{ page.title }} From 7b3f0da80f9267deadd64bfac05a2dd9996fd56f Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 18:19:47 +0100 Subject: [PATCH 10/18] add tabler-vendors --- templates/base/index.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 17c46a4..1e9dbcf 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -11,8 +11,8 @@ Viesti Reports - {{ page.title }} - {# - #} + {# #} + {% block stylesheets %}{% endblock %} {% block javascripts_header %}{% endblock %} From 9740c4ef09b283d11eb5d0287d5f498b7748f4e0 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 19:43:18 +0100 Subject: [PATCH 11/18] add version question --- .github/ISSUE_TEMPLATE.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 772098f..af621cc 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -15,6 +15,9 @@ Please check the open and closed issues if any relevant issues exist **Describe the bug** A clear and concise description of what the bug is. +**What version are you running?** +- v1.xx.x + **Are you using the Docker image?** - Yes - No From 1c8afc1b8b8a13328e9a68389ceb30f0c802ef2b Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 00:58:03 +0100 Subject: [PATCH 12/18] initial --- composer.json | 4 +- composer.lock | 367 +++++++++++++++++- config/bundles.php | 1 + config/packages/gpslab_geoip.yaml | 4 + dockerfiles/usr/local/bin/containerstartup.sh | 1 + src/Twig/Domain2Ip.php | 61 +++ src/Twig/Email2Domain.php | 25 ++ src/Twig/GeoIp.php | 65 ++++ symfony.lock | 3 + templates/base/index.html.twig | 4 +- templates/dmarc_reports/report.html.twig | 18 +- templates/smtptls_reports/report.html.twig | 131 +++---- 12 files changed, 602 insertions(+), 82 deletions(-) create mode 100644 config/packages/gpslab_geoip.yaml create mode 100644 src/Twig/Domain2Ip.php create mode 100644 src/Twig/Email2Domain.php create mode 100644 src/Twig/GeoIp.php diff --git a/composer.json b/composer.json index 1338d33..4f522e8 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "ext-ctype": "*", "ext-iconv": "*", "antedebaas/dns-parser": "^1.2.2", + "antedebaas/geoip2": "2.1.1", "buzzingpixel/twig-switch": "^1.0", "doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-migrations-bundle": "^3.2", @@ -70,7 +71,8 @@ "scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", - "assets:install %PUBLIC_DIR%": "symfony-cmd" + "assets:install %PUBLIC_DIR%": "symfony-cmd", + "geoip2:update": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" diff --git a/composer.lock b/composer.lock index 7c8f5df..40c524c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d25431624d3c6d3bcbfde60ac031042", + "content-hash": "79787970b5d49c55c32c79e2e984a325", "packages": [ { "name": "antedebaas/dns-parser", @@ -78,6 +78,57 @@ }, "time": "2024-08-22T17:35:56+00:00" }, + { + "name": "antedebaas/geoip2", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/antedebaas/geoip2.git", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antedebaas/geoip2/zipball/c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "reference": "c0f9b7f3bcb1fcc9e97439ae168d28aa2791e519", + "shasum": "" + }, + "require": { + "ext-phar": "*", + "ext-zlib": "*", + "geoip2/geoip2": "~2.0", + "php": ">=7.2.0", + "symfony/config": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/console": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/expression-language": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/filesystem": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0", + "symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "~7.0|~8.0|~9.0" + }, + "suggest": { + "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "GpsLab\\Bundle\\GeoIP2Bundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A Symfony Bundle for the Maxmind GeoIP2 API", + "homepage": "https://github.com/antedebaas/geoip2", + "support": { + "source": "https://github.com/antedebaas/geoip2/tree/v2.1.1" + }, + "time": "2024-10-30T20:39:51+00:00" + }, { "name": "buzzingpixel/twig-switch", "version": "1.0.2", @@ -127,6 +178,82 @@ }, "time": "2020-06-21T00:42:23+00:00" }, + { + "name": "composer/ca-bundle", + "version": "1.5.3", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "reference": "3b1fc3f0be055baa7c6258b1467849c3e8204eb2", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8 || ^9", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "symfony/process": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/ca-bundle/issues", + "source": "https://github.com/composer/ca-bundle/tree/1.5.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-11-04T10:15:26+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -1415,6 +1542,180 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "geoip2/geoip2", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/GeoIP2-php.git", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "reference": "6a41d8fbd6b90052bc34dff3b4252d0f88067b23", + "shasum": "" + }, + "require": { + "ext-json": "*", + "maxmind-db/reader": "~1.8", + "maxmind/web-service-common": "~0.8", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeoIp2\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind GeoIP2 PHP API", + "homepage": "https://github.com/maxmind/GeoIP2-php", + "keywords": [ + "IP", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/GeoIP2-php/issues", + "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.13.0" + }, + "time": "2022-08-05T20:32:58+00:00" + }, + { + "name": "maxmind-db/reader", + "version": "v1.11.1", + "source": { + "type": "git", + "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "reference": "1e66f73ffcf25e17c7a910a1317e9720a95497c7", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "ext-maxminddb": "<1.11.1,>=2.0.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "php-coveralls/php-coveralls": "^2.1", + "phpstan/phpstan": "*", + "phpunit/phpcov": ">=6.0.0", + "phpunit/phpunit": ">=8.0.0,<10.0.0", + "squizlabs/php_codesniffer": "3.*" + }, + "suggest": { + "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder", + "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Db\\": "src/MaxMind/Db" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory J. Oschwald", + "email": "goschwald@maxmind.com", + "homepage": "https://www.maxmind.com/" + } + ], + "description": "MaxMind DB Reader API", + "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php", + "keywords": [ + "database", + "geoip", + "geoip2", + "geolocation", + "maxmind" + ], + "support": { + "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.1" + }, + "time": "2023-12-02T00:09:23+00:00" + }, + { + "name": "maxmind/web-service-common", + "version": "v0.9.0", + "source": { + "type": "git", + "url": "https://github.com/maxmind/web-service-common-php.git", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "reference": "4dc5a3e8df38aea4ca3b1096cee3a038094e9b53", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0.3", + "ext-curl": "*", + "ext-json": "*", + "php": ">=7.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", + "phpunit/phpunit": "^8.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "MaxMind\\Exception\\": "src/Exception", + "MaxMind\\WebService\\": "src/WebService" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Gregory Oschwald", + "email": "goschwald@maxmind.com" + } + ], + "description": "Internal MaxMind Web Service API", + "homepage": "https://github.com/maxmind/web-service-common-php", + "support": { + "issues": "https://github.com/maxmind/web-service-common-php/issues", + "source": "https://github.com/maxmind/web-service-common-php/tree/v0.9.0" + }, + "time": "2022-03-28T17:43:20+00:00" + }, { "name": "php-imap/php-imap", "version": "5.0.1", @@ -2904,6 +3205,70 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/expression-language", + "version": "v7.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/expression-language.git", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/expression-language/zipball/c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "reference": "c3a1224bc144b36cd79149b42c1aecd5f81395a5", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/cache": "^6.4|^7.0", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/service-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\ExpressionLanguage\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an engine that can compile and evaluate expressions", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/expression-language/tree/v7.1.6" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-10-09T08:46:59+00:00" + }, { "name": "symfony/filesystem", "version": "v7.1.6", diff --git a/config/bundles.php b/config/bundles.php index bd86778..4e31f68 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -11,4 +11,5 @@ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], SecIT\ImapBundle\ImapBundle::class => ['all' => true], SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true], + GpsLab\Bundle\GeoIP2Bundle\GpsLabGeoIP2Bundle::class => ['all' => true], ]; diff --git a/config/packages/gpslab_geoip.yaml b/config/packages/gpslab_geoip.yaml new file mode 100644 index 0000000..cd4d184 --- /dev/null +++ b/config/packages/gpslab_geoip.yaml @@ -0,0 +1,4 @@ +gpslab_geoip: + license: '%env(MAXMIND_LICENCE)%' + edition: 'GeoLite2-Country' + path: '%kernel.project_dir%/var/data/GeoLite2-Country.mmdb' \ No newline at end of file diff --git a/dockerfiles/usr/local/bin/containerstartup.sh b/dockerfiles/usr/local/bin/containerstartup.sh index 7055a88..100354e 100755 --- a/dockerfiles/usr/local/bin/containerstartup.sh +++ b/dockerfiles/usr/local/bin/containerstartup.sh @@ -14,6 +14,7 @@ if [ ! -f "/var/www/html/.env.local" ]; then echo "ENABLE_REGISTRATION=\"$ENABLE_REGISTRATION\"" >> /var/www/html/.env.local echo "PUSHOVER_API_KEY=\"$PUSHOVER_API_KEY\"" >> /var/www/html/.env.local echo "PUSHOVER_USER_KEY=\"$PUSHOVER_USER_KEY\"" >> /var/www/html/.env.local + echo "MAXMIND_LICENCE=\"$MAXMIND_LICENCE\"" >> /var/www/html/.env.local fi echo "Check if attachments directory exists" diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php new file mode 100644 index 0000000..5f47388 --- /dev/null +++ b/src/Twig/Domain2Ip.php @@ -0,0 +1,61 @@ +reader = $reader; + } + + public function getFilters(): array + { + return [ + new TwigFilter('domain2ip', [$this, 'domain2ipFilter']), + ]; + } + + public function domain2ipFilter($domain) + { + if (empty($domain)) { + return ''; + } + $email = null; + if (is_array($domain)) { + $email = $domain[1]; + $domain = $domain[0]; + } + + $dns = new Dns(); + try { + $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + } catch (\Exception $e) { + $ipv4 = ''; + } + try { + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + } catch (\Exception $e) { + $ipv6 = ''; + } + + if(!empty($ipv6)) { + $ip = $ipv6; + } else { + $ip = $ipv4; + } + + if (!is_null($email)) { + return array($ip, $email); + } else { + return array($ip, $domain); + } + } +} \ No newline at end of file diff --git a/src/Twig/Email2Domain.php b/src/Twig/Email2Domain.php new file mode 100644 index 0000000..1c6a0d2 --- /dev/null +++ b/src/Twig/Email2Domain.php @@ -0,0 +1,25 @@ +reader = $reader; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('geoip', [$this, 'geoipFunction'], ['is_safe' => ['html']]), + ]; + } + + public function geoipFunction($type, $ip) + { + + if (empty($ip)) { + return ''; + } + $domain = null; + if (is_array($ip)) { + $domain = $ip[1]; + $ip = $ip[0]; + } + + try { + $iso = strtolower($this->reader->country($ip)->country->isoCode); + } catch (\Exception $e) { + $iso = ''; + } + try { + switch ($type) { + case 'country' || 'default': + $response = ''; + + if (!is_null($domain)) { + return $domain.' '.$response; + } else { + return $ip.' '.$response; + } + + default: + return $ip; + } + } + catch (\Exception $e) { + return $ip; + } + } +} \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index 696c730..c8b95d0 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,7 @@ { + "antedebaas/geoip2": { + "version": "v2.1.1" + }, "antedebaas/imap-bundle": { "version": "2.0.1" }, diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 67d3e05..17f09e2 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -9,8 +9,8 @@ Viesti Reports - {{ page.title }} - {# - + + {# #} {% block stylesheets %}{% endblock %} diff --git a/templates/dmarc_reports/report.html.twig b/templates/dmarc_reports/report.html.twig index 7289504..4ba1464 100644 --- a/templates/dmarc_reports/report.html.twig +++ b/templates/dmarc_reports/report.html.twig @@ -11,19 +11,19 @@
  • Reporting for: - {{ report.domain.fqdn }} + {{ geoip('country',report.domain.fqdn|domain2ip) }}
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • E-Mail: - {{ report.email }} + {{ geoip('country',report.email|email2domain|domain2ip) }}
  • @@ -45,13 +45,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -170,25 +170,25 @@
  • Envelope to: - {{ record.envelopeto }} + {{ geoip('country',record.envelopeto|domain2ip) }}
  • Envelope from: - {{ record.envelopefrom }} + {{ geoip('country',record.envelopefrom|domain2ip) }}
  • Header from: - {{ record.headerfrom }} + {{ geoip('country',record.headerfrom|domain2ip) }}
  • IP Address: - {{ record.sourceip }} + {{ geoip('country',record.sourceip) }}
  • diff --git a/templates/smtptls_reports/report.html.twig b/templates/smtptls_reports/report.html.twig index 15e5078..b5509d9 100644 --- a/templates/smtptls_reports/report.html.twig +++ b/templates/smtptls_reports/report.html.twig @@ -11,7 +11,7 @@
  • Report ID: - {{ report.externalid }} + {{ report.externalid }}
  • @@ -34,13 +34,13 @@
  • Begin time: - {{ report.begintime|date("d-M-Y H:i:s") }} + {{ report.begintime|date("d-M-Y H:i:s") }}
  • End time: - {{ report.endtime|date("d-M-Y H:i:s") }} + {{ report.endtime|date("d-M-Y H:i:s") }}
  • @@ -61,16 +61,14 @@
  • Domain: - - {{ policy.policydomain.fqdn }} - + {{ geoip('country',policy.policydomain.fqdn|domain2ip) }}
  • {% for mxrecord in policy.smtptls_mxrecords|sort((a, b) => a.priority <=> b.priority) %}
  • MX: - {{ mxrecord.mxrecord.name }} + {{ geoip('country',mxrecord.mxrecord.name|domain2ip) }}
  • {% endfor %} @@ -78,68 +76,63 @@
  • String max age: - {{ policy.policystringmaxage }} sec + {{ policy.policystringmaxage }} sec
  • {% endif %}

    -
      {% for rdata in policy.smtptls_rdatarecords %} -
    • -
      - TLSA resource record: -
        -
      • -
        - Usage: - - PKIX-TA - {% elseif rdata.usagetype == 1 %}data-bs-title="Service Certificate Constraint">PKIX-EE - {% elseif rdata.usagetype == 2 %}data-bs-title="Trust Anchor Assertion">DANE-TA - {% elseif rdata.usagetype == 3 %}data-bs-title="Domain Issued Certificate">DANE-EE - {% endif %} - - - - -
        -
      • -
      • -
        - Selector: - - Cert - {% elseif rdata.selectortype == 1 %}data-bs-title="Use subject public key">SPKI - {% endif %} - - - - -
        -
      • -
      • -
        - Matching-Type: - - Full - {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-256 hash">SHA-256 - {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-512 hash">SHA-512 - {% endif %} - - - - -
        -
      • -
      - -
    • - {% endfor %} -
    + TLSA resource record: +
      +
    • +
      + Usage: + + PKIX-TA + {% elseif rdata.usagetype == 1 %}data-bs-title="Service Certificate Constraint">PKIX-EE + {% elseif rdata.usagetype == 2 %}data-bs-title="Trust Anchor Assertion">DANE-TA + {% elseif rdata.usagetype == 3 %}data-bs-title="Domain Issued Certificate">DANE-EE + {% endif %} + + + + +
      +
    • +
    • +
      + Selector: + + Cert + {% elseif rdata.selectortype == 1 %}data-bs-title="Use subject public key">SPKI + {% endif %} + + + + +
      +
    • +
    • +
      + Matching-Type: + + Full + {% elseif rdata.matchingtype == 1 %}data-bs-title="SHA-256 hash">SHA-256 + {% elseif rdata.matchingtype == 2 %}data-bs-title="SHA-512 hash">SHA-512 + {% endif %} + + + + +
      +
    • +
    + + {% endfor %}
      @@ -176,7 +169,7 @@
    • Summary successful count: - {{ policy.summarysuccessfulcount }} + {{ policy.summarysuccessfulcount }}
    • @@ -201,19 +194,19 @@
    • Receiving MX Hostname: - {{ failuredetail.receivingmxhostname.name }} + {{ geoip('country',failuredetail.receivingmxhostname.name|domain2ip) }}
    • Result: - {{ failuredetail.resulttype }} + {{ failuredetail.resulttype }}
    • Failed Session Count: - {{ failuredetail.failedsessioncount }} + {{ failuredetail.failedsessioncount }}
    @@ -223,13 +216,13 @@
  • Sending MTA IP: - {{ failuredetail.sendingmtaip }} + {{ geoip('country',failuredetail.sendingmtaip) }}
  • Receiving IP: - {{ failuredetail.receivingip }} + {{ geoip('country',failuredetail.receivingip) }}
  • From fbac516c2b92f346a3b17c77126660ce97c23f49 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:06:47 +0100 Subject: [PATCH 13/18] update view all button on dashboard --- templates/dashboard/index.html.twig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/templates/dashboard/index.html.twig b/templates/dashboard/index.html.twig index 6271273..e53a5fa 100644 --- a/templates/dashboard/index.html.twig +++ b/templates/dashboard/index.html.twig @@ -65,7 +65,10 @@
    - View all +

    +
    + View all +
    @@ -154,7 +157,10 @@ - View all +

    +
    + View all +
    @@ -212,7 +218,10 @@ - View all +

    +
    + View all +
    From 70e4c0cd79def654a8c18c943db8986485869b78 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:16:26 +0100 Subject: [PATCH 14/18] ip on null --- src/Twig/Domain2Ip.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index 5f47388..e7d7220 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -36,12 +36,22 @@ public function domain2ipFilter($domain) $dns = new Dns(); try { - $ipv4 = $dns->getRecords($domain, 'A')[0]->toArray()["ip"]; + $ipv4 = $dns->getRecords($domain, 'A')[0]; + if(!is_null($ipv4)) { + $ipv4 = $ipv4->toArray()["ip"]; + } else { + $ipv4 = ''; + } } catch (\Exception $e) { $ipv4 = ''; } try { - $ipv6 = $dns->getRecords($domain, 'AAAA')[0]->toArray()["ipv6"]; + $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; + if(!is_null($ipv4)) { + $ipv6 = $ipv6->toArray()["ipv6"]; + } else { + $ipv6 = ''; + } } catch (\Exception $e) { $ipv6 = ''; } From dfe438826000f4c7460e129acbe934c572d5ba27 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 01:23:55 +0100 Subject: [PATCH 15/18] ipv6 --- src/Twig/Domain2Ip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twig/Domain2Ip.php b/src/Twig/Domain2Ip.php index e7d7220..2d8af08 100644 --- a/src/Twig/Domain2Ip.php +++ b/src/Twig/Domain2Ip.php @@ -47,7 +47,7 @@ public function domain2ipFilter($domain) } try { $ipv6 = $dns->getRecords($domain, 'AAAA')[0]; - if(!is_null($ipv4)) { + if(!is_null($ipv6)) { $ipv6 = $ipv6->toArray()["ipv6"]; } else { $ipv6 = ''; From 1f4e0f51185d21aefca6ecc4400b4e9ab2bf3816 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 17:50:28 +0100 Subject: [PATCH 16/18] icon stuff --- templates/base/index.html.twig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 17f09e2..17c46a4 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -4,9 +4,10 @@ - - - + + + + Viesti Reports - {{ page.title }} From 34da928b7e55e0f3684e92e3f475d23756ce5df8 Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 18:19:47 +0100 Subject: [PATCH 17/18] add tabler-vendors --- templates/base/index.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/base/index.html.twig b/templates/base/index.html.twig index 17c46a4..1e9dbcf 100644 --- a/templates/base/index.html.twig +++ b/templates/base/index.html.twig @@ -11,8 +11,8 @@ Viesti Reports - {{ page.title }} - {# - #} + {# #} + {% block stylesheets %}{% endblock %} {% block javascripts_header %}{% endblock %} From a878454e9131b526d1de1f697f0015547f66abea Mon Sep 17 00:00:00 2001 From: Ante de Baas Date: Sun, 10 Nov 2024 19:43:18 +0100 Subject: [PATCH 18/18] add version question --- .github/ISSUE_TEMPLATE.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 772098f..af621cc 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -15,6 +15,9 @@ Please check the open and closed issues if any relevant issues exist **Describe the bug** A clear and concise description of what the bug is. +**What version are you running?** +- v1.xx.x + **Are you using the Docker image?** - Yes - No