the MacAuth e-mail reporting feature of mactrack is not working, because it is not (fully) implemented !
Here is my implementation:
Find "function mactrack_process_mac_auth_report(" in poller_mactrack.php and replace
Code: Select all
function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time) {
if ($mac_auth_frequency == 0) {
$ports = db_fetch_assoc("SELECT mac_track_temp_ports.*, mac_track_sites.site_name
FROM mac_track_temp_ports
LEFT JOIN mac_track_sites
ON mac_track_sites.site_id=mac_track_temp_ports.site_id
WHERE authorized=0");
}else{
$ports = db_fetch_assoc("SELECT mac_track_ports.*, mac_track_sites.site_name
FROM mac_track_ports
LEFT JOIN mac_track_sites
ON mac_track_sites.site_id=mac_track_temp_ports.site_id
WHERE authorized=0");
}
if (sizeof($ports)) {
foreach($ports as $port) {
/* create the report */
}
/* email the report */
}else{
if ($mac_auth_frequency > 0) {
/* send out an empty report */
}
}
}
Code: Select all
function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time) {
/* ############## Patch ############# */
if ($mac_auth_frequency == 0) {
$ports = db_fetch_assoc("SELECT mac_track_temp_ports.*, mac_track_sites.site_name
FROM mac_track_temp_ports
LEFT JOIN mac_track_sites
ON mac_track_sites.site_id=mac_track_temp_ports.site_id
WHERE authorized=0
ORDER BY mac_track_temp_ports.device_name,mac_track_temp_ports.port_number,mac_track_temp_ports.scan_date,mac_track_temp_ports.mac_address");
}else{
$ports = db_fetch_assoc("SELECT mac_track_ports.*, mac_track_sites.site_name
FROM mac_track_ports
LEFT JOIN mac_track_sites
ON mac_track_sites.site_id=mac_track_ports.site_id
WHERE authorized=0
ORDER BY mac_track_ports.device_name,mac_track_ports.port_number,mac_track_ports.scan_date,mac_track_ports.mac_address");
}
/* ################################ */
if (sizeof($ports)) {
/* ############## Patch ############# */
$message = "<table><tr><td>Switch Name</td><td>Switch Hostname</td><td>ED IP Address</td><td>ED MAC Address</td><td>Port Number</td><td>Port Name</td><td>Scan Date</td></tr>";
foreach($ports as $port) {
/* create the report */
$message .= "<tr>";
$message .= "<td>" . $port["device_name"] . "</td>";
$message .= "<td>" . $port["hostname"] . "</td>";
$message .= "<td>" . $port["ip_address"] . "</td>";
$message .= "<td>" . $port["mac_address"] . "</td>";
$message .= "<td>" . $port["port_number"] . "</td>";
$message .= "<td>" . $port["port_name"] . "</td>";
$message .= "<td>" . $port["scan_date"] . "</td>";
$message .= "</tr>";
}
$message .= "</table>";
$message = "Not authorized devices:<br><br>" . $message;
/* set the subject */
$subject = "MACAUTH Report " . date("Y-m-d H:i:s") ;
$from = read_config_option("mt_from_email");
$fromname = read_config_option("mt_from_name");
$to = read_config_option("mt_macauth_emails");
/* email the report */
mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');
mactrack_debug("MACAUTH Report eMail sent.");
/* ############################## */
}else{
if ($mac_auth_frequency > 0) {
/* send out an empty report */
/* ############## Patch ############# */
$message = "No not authorized devices found.";
/* set the subject */
$subject = "MACAUTH Report OK " . date("Y-m-d H:i:s") ;
$from = read_config_option("mt_from_email");
$fromname = read_config_option("mt_from_name");
$to = read_config_option("mt_macauth_emails");
/* email the report */
mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');
mactrack_debug("MACAUTH Report empty eMail sent.");
/* ############################## */
}
}
}
Code: Select all
/* if it's time to e-mail */
if (($last_macauth_time + ($mac_auth_frequency*60) > time()) ||
($mac_auth_frequency == 0)) {
mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time);
}
Code: Select all
/* if it's time to e-mail */
/* ############## Patch ############# */
/*
if (($last_macauth_time + ($mac_auth_frequency*60) > time()) ||
($mac_auth_frequency == 0)) {
mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time);
}
*/
mactrack_debug("MACAUTH Time to mail report? " . $last_macauth_time . " + " . ($mac_auth_frequency*60) ." <= " . time());
if (($last_macauth_time + ($mac_auth_frequency*60) <= time()) ||
($mac_auth_frequency == 0)) {
mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time);
set_config_option("mt_last_macauth_time",time());
}
/* ############################### */