# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /var/www/freenetis-1.1
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: application/controllers/connection_requests.php
--- application/controllers/connection_requests.php Base (BASE)
+++ application/controllers/connection_requests.php Locally Modified (Based On LOCAL)
@@ -536,16 +536,31 @@
 			
 			if ($gateway && $gateway->id)
 			{
-				// first try SNMP
-				if (module::e('snmp'))
+				$mac_address = '';
+				
+				// first try CGI scripts
+				if (module::e('cgi'))
 				{
+					$vars = arr::to_object(array
+					(
+						'GATEWAY_IP_ADDRESS'	=> $gateway->ip_address,
+						'IP_ADDRESS'			=> $ip_address
+					));
+
+					$url = text::object_format($vars, Settings::get('cgi_arp_url'));
+
+					$mac_address = @file_get_contents($url);
+				}
+				
+				// now try SNMP
+				if (!valid::mac_address($mac_address) && module::e('snmp'))
+				{
 					try
 					{
 						$snmp = Snmp_Factory::factoryForDevice($gateway->ip_address);
 
 						// try find MAC address in DHCP
 						$mac_address = $snmp->getDHCPMacAddressOf($ip_address);
-						$this->session->set('connection_request_mac', $mac_address);
 					}
 					catch (DHCPMacAddressException $e)
 					{
@@ -553,7 +568,6 @@
 						{
 							// try find MAC address in ARP table
 							$mac_address = $snmp->getARPMacAddressOf($ip_address);
-							$this->session->set('connection_request_mac', $mac_address);
 						}
 						catch(Exception $e)
 						{
@@ -567,26 +581,10 @@
 						status::mwarning($e->getMessage());
 					}
 				}
-				// now try CGI scripts
-				else if (module::e('cgi'))
-				{
-					$vars = arr::to_object(array
-					(
-						'GATEWAY_IP_ADDRESS'	=> $gateway->ip_address,
-						'IP_ADDRESS'			=> $ip_address
-					));
 
-					$url = text::object_format($vars, Settings::get('cgi_arp_url'));
-
-					$mac_address = @file_get_contents($url);
-
-					if ($mac_address !== FALSE)
-					{
 						$this->session->set('connection_request_mac', $mac_address);
 					}
 				}
-			}
-		}
 		
 		// form
 		$form = new Forge();
Index: application/controllers/json.php
--- application/controllers/json.php Base (BASE)
+++ application/controllers/json.php Locally Modified (Based On LOCAL)
@@ -216,21 +216,31 @@
 
 		if ($gateway && $gateway->id && valid::ip($ip_address))
 		{
-			// first try SNMP
-			if (module::e('snmp'))
+			$mac_address = '';
+			
+			// first try CGI scripts
+			if (module::e('cgi'))
 			{
+				$vars = arr::to_object(array
+				(
+					'GATEWAY_IP_ADDRESS'	=> $gateway->ip_address,
+					'IP_ADDRESS'			=> $ip_address
+				));
+				
+				$url = text::object_format($vars, Settings::get('cgi_arp_url'));
+				
+				$mac_address = trim(@file_get_contents($url));
+			}
+			
+			// now try SNMP
+			if (!valid::mac_address($mac_address) && module::e('snmp'))
+			{
 				try
 				{
 					$snmp = Snmp_Factory::factoryForDevice($gateway->ip_address);
 
 					// try find MAC address in DHCP
 					$mac_address = $snmp->getDHCPMacAddressOf($ip_address);
-
-					die(json_encode(array
-					(
-						'state' => 1,
-						'mac' => $mac_address
-					)));
 				}
 				// MAC table is not in DHCP
 				catch (DHCPMacAddressException $e)
@@ -239,47 +249,19 @@
 					{
 						// try find MAC address in ARP table
 						$mac_address = $snmp->getARPMacAddressOf($ip_address);
-
-						die(json_encode(array
-						(
-							'state' => 1,
-							'mac' => $mac_address
-						)));
 					}
 					catch(Exception $e)
 					{
 						Log::add_exception($e);
-						die(json_encode(array
-						(
-							'state' => 0,
-							'message' => $e->getMessage()
-						)));
 					}
 				}
 				catch (Exception $e)
 				{
 					Log::add_exception($e);
-					die(json_encode(array
-					(
-						'state' => 0,
-						'message' => $e->getMessage()
-					)));
 				}
 			}
-			// now try CGI scripts
-			else if (module::e('cgi'))
-			{	
-				$vars = arr::to_object(array
-				(
-					'GATEWAY_IP_ADDRESS'	=> $gateway->ip_address,
-					'IP_ADDRESS'			=> $ip_address
-				));
 				
-				$url = text::object_format($vars, Settings::get('cgi_arp_url'));
-				
-				$mac_address = @file_get_contents($url);
-				
-				if ($mac_address !== FALSE)
+			if (valid::mac_address($mac_address))
 				{
 					die(json_encode(array
 					(
@@ -292,7 +274,7 @@
 					die(json_encode(array
 					(
 						'state' => 0,
-						'message' => __('Invalid output data')
+					'message' => __('MAC not found')
 					)));
 				}
 			}
@@ -301,15 +283,6 @@
 				die(json_encode(array
 				(
 					'state' => 0,
-					'message' => __('SNMP or CGI scripts not enabled')
-				)));
-			}
-		}
-		else
-		{
-			die(json_encode(array
-			(
-				'state' => 0,
\ No newline at end of file
 				'message' => __('Invalid input data')
 			)));
 		}
