. // //#################################################################### //### configuration ################################################## //#################################################################### // Copy dmarcts-report-viewer-config.php.sample to // dmarcts-report-viewer-config.php and edit with the appropriate info // for your database authentication and location. // // Edit the configuration variables in dmarcts-report-viewer.js with your preferences. // //#################################################################### //### functions ###################################################### //#################################################################### function html ($host_lookup = 1, $cssfile, $domains = array(), $orgs = array(), $periods = array() ) { $html = array(); $html[] = ""; $html[] = ""; $html[] = " "; $html[] = " DMARC Report Viewer"; $html[] = " "; $html[] = " "; $html[] = " "; $html[] = " "; // $html[] = " "; // Optionblock form // -------------------------------------------------------------------------- $html[] = "
"; // Host lookup option // -------------------------------------------------------------------------- $html[] = "
Hostname(s): on off
"; // DMARC select // -------------------------------------------------------------------------- $html[] = "
DMARC Result:"; $html[] = ""; $html[] = "
"; // Period select // -------------------------------------------------------------------------- if ( count( $periods ) > 0 ) { $html[] = "
Month:"; $html[] = ""; $html[] = "
"; } // Domains select // -------------------------------------------------------------------------- if ( count( $domains ) > 1 ) { $html[] = "
Domain(s):"; $html[] = ""; $html[] = "
"; } // Organizations select // -------------------------------------------------------------------------- if ( count( $orgs ) > 0 ) { $html[] = "
Reporter(s):"; $html[] = ""; $html[] = "
"; } // Refresh button // -------------------------------------------------------------------------- $html[] = "
"; $html[] = ""; $html[] = "
"; // Reset button // -------------------------------------------------------------------------- $html[] = "
"; $html[] = ""; $html[] = "
"; // End optionblock // -------------------------------------------------------------------------- $html[] = "
"; // Report divs // -------------------------------------------------------------------------- $html[] = ""; $html[] = "
DMARC Reports
"; $html[] = "
"; $html[] = "
"; $html[] = ""; $html[] = ""; $html[] = "
"; $html[] = "
"; $html[] = ""; // Page Footer // -------------------------------------------------------------------------- $html[] = " "; $html[] = " "; $html[] = ""; return implode("\n",$html); } //#################################################################### //### main ########################################################### //#################################################################### // These files must exist, in the same folder as this script. include "dmarcts-report-viewer-config.php"; include "dmarcts-report-viewer-common.php"; // Make a MySQL Connection using mysqli // -------------------------------------------------------------------------- $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport); if ($mysqli->connect_errno) { echo "Error: Failed to make a MySQL connection
"; echo "Errno: " . $mysqli->connect_errno . " "; echo "Error: " . $mysqli->connect_error . " "; // Debug ONLY. This will expose database credentials when database connection fails // echo "Database connection information:
dbhost: " . $dbhost . "
dbuser: " . $dbuser . "
dbpass: " . $dbpass . "
dbname: " . $dbname . "
dbport: " . $dbport . "
"; exit; } // Get all domains reported // -------------------------------------------------------------------------- $sql="SELECT DISTINCT domain FROM `report` ORDER BY domain"; $query = $mysqli->query($sql) or die("Query failed: ".$mysqli->error." (Error #" .$mysqli->errno.")"); while($row = $query->fetch_assoc()) { $domains[] = $row['domain']; } // Get all organisations // -------------------------------------------------------------------------- $sql="SELECT DISTINCT org FROM `report` ORDER BY org"; $query = $mysqli->query($sql) or die("Query failed: ".$mysqli->error." (Error #" .$mysqli->errno.")"); while($row = $query->fetch_assoc()) { $orgs[] = $row['org']; } // Get all periods // -------------------------------------------------------------------------- $sql="SELECT DISTINCT DISTINCT year(mindate) as year, month(mindate) as month FROM `report` ORDER BY year desc, month desc"; $query = $mysqli->query($sql) or die("Query failed: ".$mysqli->error." (Error #" .$mysqli->errno.")"); while($row = $query->fetch_assoc()) { $periods[] = sprintf( "%'.04d-%'.02d", $row['year'], $row['month'] ); } // Generate Page with report list and report data (if a report is selected). // -------------------------------------------------------------------------- echo html( $hostlookup, $cssfile, $domains, $orgs, $periods ); ?>