Skip to content

Commit

Permalink
Merge pull request #11 from userjack6880/dev
Browse files Browse the repository at this point in the history
Alpha 6 Update
  • Loading branch information
userjack6880 authored Feb 21, 2020
2 parents 10cc412 + d0e0469 commit d266a61
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 56 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog

## 0-α6
- Sort index by DMARC policy added.
- Link to domain page from senders page.
- Fixed policy listed on index.
- Added Organization Output

## 0-α5
- Fixed behavior of the control that changes the start of the display period to take in account the default date range configured in `config.php`.
- Created the beginnings of the org reports page. It's kinda basic right now.
- Added a bit of color to the DKIM and SPF result columns.
- Added optional GeoIP2 Information on `hosts.php`.
- Fixed a bunch of little things here and there, and added a few comments in areas that needed it.
- Many thanks to Timo N. for making excellent suggestions on improving this project, pointing out things I would've overlooked long into it.

## 0-α4
- Added a control to change the start of the display period in 1 week steps.
- Added disposition control to display a single disposition only.
- Added a sender report to show senders for a single domain or what domains a single sender sent as.
- Some code cleanup.

## 0-α3

- Fixed issue where a domain will be listed to have a non-zero volume, but on the domain page will have no reports. This page now properly shows all reports related to a single domain.
- Improved the accuracy of the DMARC compliance graph. No longer does it take the larger of the two alignments, but instead counts a message as complaint if it is either DKIM or SPF aligned.
- Moved away from mysqli to utilize PDO instead.

## 0-α2

- Code now has most useful features now.

## 0-α1

- Project started. It's absolutely terrible and nobody should use this.
40 changes: 13 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,36 @@
# Open DMARC Analyzer

This is Open DMARC Analyzer version 0 alpha-5 (0-α5) by John Bradley (john@systemanomaly.com). Open DMARC Analyzer is an Open Source DMARC Report Analyzer to be used with DMARC reports that have been parsed by [John Levine's rrdmarc script](http://www.taugh.com/rddmarc/) or [techsneeze's dmarcts-report-parser](https://github.com/techsneeze/dmarcts-report-parser).
This is Open DMARC Analyzer version 0 alpha-6 (0-α6) by John Bradley (john@systemanomaly.com). Open DMARC Analyzer is an Open Source DMARC Report Analyzer to be used with DMARC reports that have been parsed by [John Levine's rrdmarc script](http://www.taugh.com/rddmarc/) or [techsneeze's dmarcts-report-parser](https://github.com/techsneeze/dmarcts-report-parser).

Open DMARC Analyzer was written because there didn't seem to be a full-featured self-hosted report analyzer that provided enough details to make heads or tails of a large volume of DMARC reports that come into medium to large-sized organizations. While other solutions required paid subscriptions or have part of it hosted on AWS, Open DMARC Analyzer will run on any webserver that supports PHP 5.4+ and MySQL 15.1+.

# Dependencies

## Required - [jsmitty12/phpWhois](https://github.com/jsmitty12/phpWhois/)
It is highly recommended that you install this package using composer. Instructions are found on the package's git page. This is required, and will replace most GeoIP data if you disable the MaxMind DB reader package.

## Optional - [MaxMind DB Reader PHP API](https://github.com/maxmind/MaxMind-DB-Reader-php)
A note on this dependency - I've tried to write the one refrence to this external project as optional as possible, and it can almost completely be configured from config.php, due to the limitation of php namespace, I haven't come across a way that won't require you to dig deeper into the code if you happen to chose a compatible library to replace this MaxMind one. If you do wish to replace this library with another compatible one, the line in question is located in `includes\functions.php`:
```php
$reader = new MaxMind\Db\Reader(GEO_DB);
```

It is highly recommended that you install this package using composer. Instructions are found on the package's git page.

You will also need the GeoLite2 database from MaxMind (or any other compatible DB). It can be obtained from [here](https://dev.maxmind.com/geoip/geoip2/geolite2/). Open DMARC Analyzer makes use of the GeoLite2 City database.

The MaxMind library is not distributed with this project, and is ultimately an optional feature to the project as a whole.

# Changelog

## 0-α5
- Fixed behavior of the control that changes the start of the display period to take in account the default date range configured in `config.php`.
- Created the beginnings of the org reports page. It's kinda basic right now.
- Added a bit of color to the DKIM and SPF result columns.
- Added optional GeoIP2 Information on `hosts.php`.
- Fixed a bunch of little things here and there, and added a few comments in areas that needed it.
- Many thanks to Timo N. for making excellent suggestions on improving this project, pointing out things I would've overlooked long into it.

## 0-α4
- Added a control to change the start of the display period in 1 week steps.
- Added disposition control to display a single disposition only.
- Added a sender report to show senders for a single domain or what domains a single sender sent as.
- Some code cleanup.

## 0-α3

- Fixed issue where a domain will be listed to have a non-zero volume, but on the domain page will have no reports. This page now properly shows all reports related to a single domain.
- Improved the accuracy of the DMARC compliance graph. No longer does it take the larger of the two alignments, but instead counts a message as complaint if it is either DKIM or SPF aligned.
- Moved away from mysqli to utilize PDO instead.

## 0-α2
# Latest Changes

- Code now has most useful features now.
## 0-α6

## 0-α1
- Sort index by DMARC policy added.
- Link to domain page from senders page.
- Fixed policy listed on index.
- Added Organization Output.

- Project started. It's absolutely terrible and nobody should use this.
See `CHANGELOG.md` for full details of all changes.

# License

Expand Down
14 changes: 8 additions & 6 deletions config.php.pub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
config.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)

Available at: https://github.com/userjack6880/Open-DMARC-Analyzer

Expand All @@ -25,22 +25,24 @@ this program. If not, see <https://www.gnu.org/licenses/>.

define('DB_HOST', 'localhost');
define('DB_USER', 'dmarc');
define('DB_PASS', '');
define('DB_PASS', 'password');
define('DB_NAME', 'dmarc');
define('DB_PORT', '3306'); // default port 3306

// Debug Settings

define('DEBUG', 1); // 0 - disable, 1 - CLI only, 2 - CLI and web
define('DEBUG', 1);

// Template Settings

define('TEMPLATE', 'openda');

// Package Loader
define('AUTO_LOADER', 'vendor/autoload.php'); // autoloader for composer installed libraries

// GeoIP2 Settings
define('GEO_ENABLE', 0); // 0 - disable GeoIP2, 1 - enable GeoIP2
define('GEO_LOADER', ''); // autoloader for GeoIP2 library
define('GEO_DB', ''); // location of GeoIP2 database
define('GEO_ENABLE', 1); // 0 - disable GeoIP2, 1 - enable GeoIP2
define('GEO_DB', 'includes/geolite2.mmdb'); // location of GeoIP2 database

// Defaults

Expand Down
2 changes: 1 addition & 1 deletion domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
domain.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open DMARC Analyzer
Expand Down
2 changes: 1 addition & 1 deletion host.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
host.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open DMARC Analyzer
Expand Down
2 changes: 1 addition & 1 deletion includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
include.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
2 changes: 1 addition & 1 deletion includes/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
includes/db.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
39 changes: 32 additions & 7 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
includes/functions.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down Expand Up @@ -75,10 +75,14 @@ function dmarc_data($pdo, $rdata, $domain = NULL, $disp = 'none') {

$counts = [];
$serials = [];
$policy = [];

// extract the serial numbers from the array given and push into an array of just serial numbers
// additionally, pair serial numbers with their policies
foreach ($rdata as $data) {
array_push($serials, $data['serial']);
$policy[$data['serial'].'_p'] = $data['policy_p'];
$policy[$data['serial'].'_pct'] = $data['policy_pct'];
}

// parameters are different based on if the domain is set
Expand Down Expand Up @@ -106,12 +110,19 @@ function dmarc_data($pdo, $rdata, $domain = NULL, $disp = 'none') {
$counts[$id]->alignDKIM = 0;
$counts[$id]->alignSPF = 0;
$counts[$id]->compliance = 0;
$counts[$id]->policy = $data['policy_p'];
$counts[$id]->policyPct = $data['policy_pct'];
$counts[$id]->policy = $policy[$row['serial'].'_p'];
$counts[$id]->policyPct = $policy[$row['serial'].'_pct'];
$counts[$id]->reports = [];
$counts[$id]->lastSerial = $row['serial'];
}
$counts[$id]->numReport++;
$counts[$id]->rcount += $row['rcount'];
// check if current serial is bigger than what is stored
if ($row['serial'] > $counts[$id]->lastSerial) {
$counts[$id]->policy = $policy[$row['serial'].'_p'];
$counts[$id]->policyPct = $policy[$row['serial'].'_pct'];
$counts[$id]->lastSerial = $row['serial'];
}
if ($row['dkimresult'] == 'pass') { $counts[$id]->resultDKIM++; }
if ($row['spfresult'] == 'pass') { $counts[$id]->resultSPF++; }
if ($row['dkim_align'] == 'pass') { $counts[$id]->alignDKIM++; }
Expand Down Expand Up @@ -287,23 +298,37 @@ function senders_report_info($ip = null) {
// if no IP is given, don't bother with anything
if (!isset($ip)) { return; }
// if GeoIP2 is disabled, don't bother with anything
elseif(!GEO_ENABLE) { return; }
elseif(!GEO_ENABLE) {
echo "<h2>WHOIS Info for $ip</h2>\n";

require_once(AUTO_LOADER);

$whois = new phpWhois\Whois();
$result = $whois->lookup($ip,false);

echo "Organization: ".$result['regrinfo']['owner']['organization']."<br>\n";
echo "Hostname: ".gethostbyaddr($ip)."</td>\n";

}
// otherwise, let's get started with this
else {
echo "<h2>GeoIP Info for $ip</h2>\n";

require_once(GEO_LOADER);
require_once(AUTO_LOADER);

$reader = new MaxMind\Db\Reader(GEO_DB);

$data = $reader->get($ip);

$whois = new phpWhois\Whois();
$result = $whois->lookup($ip,false);

echo "Organization: ".$result['regrinfo']['owner']['organization']."<br>\n";
echo "City: ".$data['city']['names']['en']."<br>\n";
echo "Region: ".$data['subdivisions']['0']['names']['en']."<br>\n";
echo "Country: ".$data['country']['names']['en']."<br>\n";
echo "Location: ".$data['location']['latitude'].",".$data['location']['longitude']."<br>\n";
echo "Hostname: ".gethostbyaddr($ip)."</td>\n";
debug(str_replace(array('&lt;?php&nbsp;','?&gt;'), '', highlight_string( '<?php ' . var_export($data, true) . ' ?>', true ) ));

$reader->close();
}
Expand Down Expand Up @@ -332,7 +357,7 @@ function senders_report_table($pdo, $dateRange = DATE_RANGE, $domain = null, $ip
echo "\t<tr>\n";
echo "\t\t<td>".long2ip($row['ip'])."</td>\n";
echo "\t\t<td>".gethostbyaddr(long2ip($row['ip']))."</td>\n";
echo "\t\t<td>".$row['identifier_hfrom']."</td>\n";
echo "\t\t<td><a href='domain.php?domain=".$row['identifier_hfrom']."'>".$row['identifier_hfrom']."</a></td>\n";
echo "\t</tr>\n";
}

Expand Down
2 changes: 1 addition & 1 deletion includes/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
includes/template-loader.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
4 changes: 2 additions & 2 deletions includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
ncludes/template.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand All @@ -23,7 +23,7 @@

// Versioning
function oda_version() {
echo "0-&alpha;5";
echo "0-&alpha;6";
}

// General Page Templates
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
index.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open DMARC Analyzer
Expand Down Expand Up @@ -42,7 +42,7 @@
?>

<script>
var TSort_Data = new Array('compliance_table','s','i','','i','i','i');
var TSort_Data = new Array('compliance_table','s','i','s','i','i','i');
var TSort_Cookie = 'compliance_table';
var TSort_NColumns = 1;
tsRegister();
Expand Down
2 changes: 1 addition & 1 deletion org.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
org.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open DMARC Analyzer
Expand Down
2 changes: 1 addition & 1 deletion report.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
report.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open DMARC Analyzer
Expand Down
2 changes: 1 addition & 1 deletion templates/openda/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
templates/openda/footer.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
2 changes: 1 addition & 1 deletion templates/openda/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
templates/openda/header.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
2 changes: 1 addition & 1 deletion templates/openda/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
templates/openda/index.php
2019 - John Bradley (userjack6880)
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down
4 changes: 2 additions & 2 deletions templates/openda/style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Open DMARC Analyzer - Open Source DMARC Analyzer
templates/openda/index.php
2019 - John Bradley (userjack6880)
templates/openda/style.css
2020 - John Bradley (userjack6880)
Available at: https://github.com/userjack6880/Open-DMARC-Analyzer
Expand Down

0 comments on commit d266a61

Please sign in to comment.