Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
a7033f22
Commit
a7033f22
authored
Sep 30, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) add X-Forwarded-For to access controller
parent
89c05ee2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
10 deletions
+22
-10
AccessController.php
...ntrollers/OPNsense/CaptivePortal/Api/AccessController.php
+22
-10
No files found.
src/opnsense/mvc/app/controllers/OPNsense/CaptivePortal/Api/AccessController.php
View file @
a7033f22
...
@@ -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
());
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment