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
e0bc958a
Commit
e0bc958a
authored
Feb 25, 2016
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ipv6 functions out of polyfill section
parent
e5040060
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
43 deletions
+55
-43
limits.php
qa-include/app/limits.php
+55
-0
qa-base.php
qa-include/qa-base.php
+0
-43
No files found.
qa-include/app/limits.php
View file @
e0bc958a
...
...
@@ -213,6 +213,61 @@
}
/**
* Convert an IPv6 address to its numeric representation. Based on http://stackoverflow.com/a/18277167/37947
* @param string $ip The IP address to convert
* @return string
*/
function
qa_ipv6_numeric
(
$ip
)
{
$binNum
=
''
;
foreach
(
unpack
(
'C*'
,
@
inet_pton
(
$ip
))
as
$byte
)
{
$binNum
.=
str_pad
(
decbin
(
$byte
),
8
,
"0"
,
STR_PAD_LEFT
);
}
return
base_convert
(
ltrim
(
$binNum
,
'0'
),
2
,
10
);
}
/**
* Expands an IPv6 address (possibly containing wildcards), e.g. ::ffff:1 to 0000:0000:0000:0000:0000:0000:ffff:0001.
* Based on http://stackoverflow.com/a/12095836/753676
* @param string $ip The IP address to expand.
* @return string
*/
function
qa_ipv6_expand
(
$ip
)
{
$ipv6_wildcard
=
false
;
$wildcards
=
''
;
$wildcards_matched
=
array
();
if
(
strpos
(
$ip
,
"*"
)
!==
false
)
{
$ipv6_wildcard
=
true
;
}
if
(
$ipv6_wildcard
)
{
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards
as
$index
=>
$value
)
{
if
(
$value
==
"*"
)
{
$wildcards_matched
[]
=
count
(
$wildcards
)
-
1
-
$index
;
$wildcards
[
$index
]
=
"0"
;
}
}
$ip
=
implode
(
$wildcards
,
":"
);
}
$hex
=
unpack
(
"H*hex"
,
@
inet_pton
(
$ip
));
$ip
=
substr
(
preg_replace
(
"/([0-9A-Fa-f]
{
4
}
)/"
,
"$1:"
,
$hex
[
'hex'
]),
0
,
-
1
);
if
(
$ipv6_wildcard
)
{
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards_matched
as
$value
)
{
$i
=
count
(
$wildcards
)
-
1
-
$value
;
$wildcards
[
$i
]
=
"*"
;
}
$ip
=
implode
(
$wildcards
,
":"
);
}
return
$ip
;
}
function
qa_report_write_action
(
$userid
,
$cookieid
,
$action
,
$questionid
,
$answerid
,
$commentid
)
/*
Called after a database write $action performed by a user identified by $userid and/or $cookieid.
...
...
qa-include/qa-base.php
View file @
e0bc958a
...
...
@@ -216,49 +216,6 @@
}
}
}
// http://stackoverflow.com/a/18277167
function
ipv6_numeric
(
$ip
)
{
$binNum
=
''
;
foreach
(
unpack
(
'C*'
,
@
inet_pton
(
$ip
))
as
$byte
)
{
$binNum
.=
str_pad
(
decbin
(
$byte
),
8
,
"0"
,
STR_PAD_LEFT
);
}
return
base_convert
(
ltrim
(
$binNum
,
'0'
),
2
,
10
);
}
// http://stackoverflow.com/a/12095836/753676
function
ipv6_expand
(
$ip
){
$ipv6_wildcard
=
false
;
$wildcards
=
''
;
$wildcards_matched
=
array
();
if
(
strpos
(
$ip
,
"*"
)
!==
false
){
$ipv6_wildcard
=
true
;
}
if
(
$ipv6_wildcard
){
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards
as
$index
=>
$value
){
if
(
$value
==
"*"
){
$wildcards_matched
[]
=
count
(
$wildcards
)
-
1
-
$index
;
$wildcards
[
$index
]
=
"0"
;
}
}
$ip
=
implode
(
$wildcards
,
":"
);
}
$hex
=
unpack
(
"H*hex"
,
@
inet_pton
(
$ip
));
$ip
=
substr
(
preg_replace
(
"/([0-9A-Fa-f]
{
4
}
)/"
,
"$1:"
,
$hex
[
'hex'
]),
0
,
-
1
);
if
(
$ipv6_wildcard
){
$wildcards
=
explode
(
":"
,
$ip
);
foreach
(
$wildcards_matched
as
$value
){
$i
=
count
(
$wildcards
)
-
1
-
$value
;
$wildcards
[
$i
]
=
"*"
;
}
$ip
=
implode
(
$wildcards
,
":"
);
}
return
$ip
;
}
}
...
...
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