Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
restrict_ip
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
restrict_ip
Commits
7e63fec6
Commit
7e63fec6
authored
8 years ago
by
git
Committed by
Jay Friendly
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2854768
by oinuma: Use a wildcard path
parent
63ebd735
Branches
Branches containing commit
Tags
2.0.12
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
restrict_ip.services.yml
+1
-0
1 addition, 0 deletions
restrict_ip.services.yml
src/Service/RestrictIpService.php
+40
-3
40 additions, 3 deletions
src/Service/RestrictIpService.php
with
41 additions
and
3 deletions
restrict_ip.services.yml
+
1
−
0
View file @
7e63fec6
...
...
@@ -17,6 +17,7 @@ services:
-
@
config.factory
-
@
request_stack
-
@
restrict_ip.mapper
-
@
path.matcher
restrict_ip.event_subscriber
:
class
:
'
%restrict_ip.event_subscriber.class%'
...
...
This diff is collapsed.
Click to expand it.
src/Service/RestrictIpService.php
+
40
−
3
View file @
7e63fec6
...
...
@@ -4,6 +4,7 @@ namespace Drupal\restrict_ip\Service;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Path\CurrentPathStack
;
use
Drupal\Core\Path\PathMatcherInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Drupal\restrict_ip
\Mapper\RestrictIpMapperInterface
;
use
Symfony\Component\HttpFoundation\RequestStack
;
...
...
@@ -52,6 +53,13 @@ class RestrictIpService implements RestrictIpServiceInterface
*/
protected
$mapper
;
/**
* The Path Matcher service
*
* @var \Drupal\Core\Path\PathMatcherInterface
*/
protected
$pathMatcher
;
/**
* Constructs a RestrictIpService object
*
...
...
@@ -65,11 +73,14 @@ class RestrictIpService implements RestrictIpServiceInterface
* The current HTTP request
* @param \Drupal\restrict_ip\Mapper\RestrictIpMapperInterface $restrictIpMapper
* The Restrict IP data mapper object
* @param \Drupal\Core\Path\PathMatcherInterface $pathMatcher
* The Path Matcher service
*/
public
function
__construct
(
AccountProxyInterface
$currentUser
,
CurrentPathStack
$currentPathStack
,
ConfigFactoryInterface
$configFactory
,
RequestStack
$requestStack
,
RestrictIpMapperInterface
$restrictIpMapper
)
public
function
__construct
(
AccountProxyInterface
$currentUser
,
CurrentPathStack
$currentPathStack
,
ConfigFactoryInterface
$configFactory
,
RequestStack
$requestStack
,
RestrictIpMapperInterface
$restrictIpMapper
,
PathMatcherInterface
$pathMatcher
)
{
$this
->
currentUser
=
$currentUser
;
$this
->
mapper
=
$restrictIpMapper
;
$this
->
pathMatcher
=
$pathMatcher
;
$this
->
currentPath
=
strtolower
(
$currentPathStack
->
getPath
());
$this
->
config
=
$configFactory
->
get
(
'restrict_ip.settings'
);
...
...
@@ -266,7 +277,20 @@ class RestrictIpService implements RestrictIpServiceInterface
if
(
$this
->
config
->
get
(
'white_black_list'
)
==
1
)
{
$whitelisted_pages
=
$this
->
getWhitelistedPagePaths
();
if
(
count
(
$whitelisted_pages
)
&&
in_array
(
$this
->
currentPath
,
$whitelisted_pages
))
$current_whitelist
=
FALSE
;
if
(
count
(
$whitelisted_pages
))
{
foreach
(
$whitelisted_pages
as
$whitelisted_page
)
{
if
(
$this
->
pathMatcher
->
matchPath
(
$this
->
currentPath
,
$whitelisted_page
))
{
$current_whitelist
=
TRUE
;
}
}
}
if
(
$current_whitelist
)
{
$allow_access
=
TRUE
;
}
...
...
@@ -284,7 +308,20 @@ class RestrictIpService implements RestrictIpServiceInterface
if
(
$this
->
config
->
get
(
'white_black_list'
)
==
2
)
{
$blacklisted_pages
=
$this
->
getBlacklistedPagePaths
();
if
(
count
(
$blacklisted_pages
)
&&
!
in_array
(
$this
->
currentPath
,
$blacklisted_pages
))
$current_blacklist
=
FALSE
;
if
(
count
(
$blacklisted_pages
))
{
foreach
(
$blacklisted_pages
as
$blacklisted_page
)
{
if
(
$this
->
pathMatcher
->
matchPath
(
$this
->
currentPath
,
$blacklisted_page
))
{
$current_blacklist
=
TRUE
;
}
}
}
if
(
!
$current_blacklist
)
{
$allow_access
=
TRUE
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment