Commit a7033f22 authored by Ad Schellevis's avatar Ad Schellevis

(captiveportal, new) add X-Forwarded-For to access controller

parent 89c05ee2
...@@ -55,7 +55,7 @@ class AccessController extends ApiControllerBase ...@@ -55,7 +55,7 @@ class AccessController extends ApiControllerBase
if ($allClients != null) { if ($allClients != null) {
// search for client by ip address // search for client by ip address
foreach ($allClients as $connectedClient) { foreach ($allClients as $connectedClient) {
if ($connectedClient['ipAddress'] == $this->request->getClientAddress()) { if ($connectedClient['ipAddress'] == $this->getClientIp()) {
// client is authorized in this zone according to our administration // client is authorized in this zone according to our administration
$connectedClient['clientState'] = 'AUTHORIZED'; $connectedClient['clientState'] = 'AUTHORIZED';
return $connectedClient; return $connectedClient;
...@@ -64,7 +64,22 @@ class AccessController extends ApiControllerBase ...@@ -64,7 +64,22 @@ class AccessController extends ApiControllerBase
} }
// return Unauthorized // return Unauthorized
return array('clientState' => "NOT_AUTHORIZED", "ipAddress" => $this->request->getClientAddress()); return array('clientState' => "NOT_AUTHORIZED", "ipAddress" => $this->getClientIp());
}
/**
* determine clients ip address
*/
private function getClientIp()
{
// determine orginal sender of this request
if ($this->request->getHeader('X-Forwarded-For') != "") {
// use X-Forwarded-For header to determine real client
return $this->request->getHeader('X-Forwarded-For');
} else {
// client accesses the Api directly
return $this->request->getClientAddress();
}
} }
/** /**
...@@ -87,6 +102,7 @@ class AccessController extends ApiControllerBase ...@@ -87,6 +102,7 @@ class AccessController extends ApiControllerBase
*/ */
public function logonAction($zoneid = 0) public function logonAction($zoneid = 0)
{ {
$clientIp = $this->getClientIp();
if ($this->request->isOptions()) { if ($this->request->isOptions()) {
// return empty result on CORS preflight // return empty result on CORS preflight
return array(); return array();
...@@ -131,7 +147,7 @@ class AccessController extends ApiControllerBase ...@@ -131,7 +147,7 @@ class AccessController extends ApiControllerBase
"captiveportal allow", "captiveportal allow",
array((string)$cpZone->zoneid, array((string)$cpZone->zoneid,
$userName, $userName,
$this->request->getClientAddress(), $clientIp,
$authServerName, $authServerName,
'json') 'json')
); );
...@@ -143,16 +159,12 @@ class AccessController extends ApiControllerBase ...@@ -143,16 +159,12 @@ class AccessController extends ApiControllerBase
} }
} }
} else { } else {
return array("clientState" => 'NOT_AUTHORIZED', return array("clientState" => 'NOT_AUTHORIZED',"ipAddress" => $clientIp);
"ipAddress" => $this->request->getClientAddress()
);
} }
} }
} }
return array("clientState" => 'UNKNOWN', return array("clientState" => 'UNKNOWN',"ipAddress" => $clientIp);
"ipAddress" => $this->request->getClientAddress()
);
} }
...@@ -182,7 +194,7 @@ class AccessController extends ApiControllerBase ...@@ -182,7 +194,7 @@ class AccessController extends ApiControllerBase
} }
} }
} }
return array("clientState" => "UNKNOWN", "ipAddress" => $this->request->getClientAddress()); return array("clientState" => "UNKNOWN", "ipAddress" => $this->getClientIp());
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment