Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
outils
question2answer
Commits
82f6ef2f
Commit
82f6ef2f
authored
Jan 13, 2018
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize qa_block_ip_match
parent
b0f03e08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
limits.php
qa-include/app/limits.php
+13
-5
No files found.
qa-include/app/limits.php
View file @
82f6ef2f
...
...
@@ -185,25 +185,33 @@ function qa_block_ips_explode($blockipstring)
*/
function
qa_block_ip_match
(
$ip
,
$blockipclause
)
{
// check if the input parameters use the same IP version
if
((
strpos
(
$ip
,
"."
)
!==
false
&&
strpos
(
$blockipclause
,
"."
)
===
false
)
||
(
strpos
(
$ip
,
"."
)
===
false
&&
strpos
(
$blockipclause
,
"."
)
!==
false
)
)
{
$ipv4
=
filter_var
(
$ip
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_IPV4
)
!==
false
;
$blockipv4
=
filter_var
(
$blockipclause
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_IPV4
)
!==
false
;
// allow faster return if IP and blocked IP are plain IPv4 strings (IPv6 requires expanding)
if
(
$ipv4
&&
$blockipv4
)
{
return
$ip
===
$blockipclause
;
}
// check if same IP version
if
((
$ipv4
&&
!
$blockipv4
)
||
(
!
$ipv4
&&
$blockipv4
))
{
return
false
;
}
if
(
filter_var
(
$ip
,
FILTER_VALIDATE_IP
))
{
if
(
preg_match
(
'/^(.*)\-(.*)$/'
,
$blockipclause
,
$matches
))
{
// match IP range
if
(
filter_var
(
$matches
[
1
],
FILTER_VALIDATE_IP
)
&&
filter_var
(
$matches
[
2
],
FILTER_VALIDATE_IP
))
{
return
qa_ip_between
(
$ip
,
$matches
[
1
],
$matches
[
2
]);
}
}
elseif
(
strlen
(
$blockipclause
))
{
// normalize IPv6 addresses
if
(
filter_var
(
$ip
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_IPV6
))
{
$ip
=
qa_ipv6_expand
(
$ip
);
$blockipclause
=
qa_ipv6_expand
(
$blockipclause
);
}
// preg_quote misses hyphens but that is OK here
//
expand wildcards;
preg_quote misses hyphens but that is OK here
return
preg_match
(
'/^'
.
str_replace
(
'\\*'
,
'([0-9A-Fa-f]+)'
,
preg_quote
(
$blockipclause
,
'/'
))
.
'$/'
,
$ip
)
>
0
;
}
}
...
...
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