MacAuth Report E-Mail not working [solved]

Support questions about the MAC Track plugin

Moderators: Developers, Moderators

Post Reply
mf2hd
Posts: 4
Joined: Wed May 21, 2014 8:00 am

MacAuth Report E-Mail not working [solved]

Post by mf2hd »

Hello,

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 */
		}
	}
}
with

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.");
		
		/* ############################## */

		}
	}
}
Also find "function collect_mactrack_data(" in poller_mactrack.php and replace

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);
			}
with

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());
			}
			/* ############################### */
This patch is for MACTrack 2.9.
asterixlinux
Posts: 19
Joined: Wed Jul 13, 2011 6:41 am

Re: MacAuth Report E-Mail not working [solved]

Post by asterixlinux »

Hi . Could you aid me ??
I have mactrack 2.9 ; installed this patch and receive emails.
my problem that I always get emails with "Not authorized devices".
How can I set the devices allowed to 1 and receive email with ONLY the devices UNAUTHORIZED ??
Thanks for the help that you can give me
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests