Page MenuHomeIn-Portal Phabricator

D528.id1352.diff
No OneTemporary

File Metadata

Created
Sat, Jul 19, 12:55 PM

D528.id1352.diff

Index: core/admin_templates/logs/session_logs/session_log_list.tpl
===================================================================
--- core/admin_templates/logs/session_logs/session_log_list.tpl
+++ core/admin_templates/logs/session_logs/session_log_list.tpl
@@ -58,7 +58,7 @@
color: #555;
}
- tr.grid-data-row td.SessionKey {
+ tr.grid-data-row td.SessionKey, tr.grid-data-row td.IP {
text-overflow: ellipsis;
}
</style>
Index: core/admin_templates/logs/system_logs/system_log_list.tpl
===================================================================
--- core/admin_templates/logs/system_logs/system_log_list.tpl
+++ core/admin_templates/logs/system_logs/system_log_list.tpl
@@ -77,7 +77,7 @@
font-size: 11px;
}
- tr.grid-data-row td.LogSessionKey {
+ tr.grid-data-row td.LogSessionKey, tr.grid-data-row td.IpAddress {
text-overflow: ellipsis;
}
</style>
Index: core/admin_templates/logs/visits/visits_list.tpl
===================================================================
--- core/admin_templates/logs/visits/visits_list.tpl
+++ core/admin_templates/logs/visits/visits_list.tpl
@@ -46,6 +46,12 @@
</tbody>
</table>
+<style type="text/css">
+ tr.grid-data-row td.IPAddress {
+ text-overflow: ellipsis;
+ }
+</style>
+
<inp2:m_DefineElement name="grid_userlink_td">
<inp2:m_if check="UserFound" user_field="$user_field">
<a href="<inp2:UserLink edit_template='users/users_edit' user_field="$user_field"/>" onclick="return direct_edit('<inp2:m_Param name="PrefixSpecial"/>', this.href);" title="<inp2:m_phrase name="la_Edit_User"/>"><inp2:Field field="$field" grid="$grid"/></a>
@@ -68,4 +74,4 @@
<script type="text/javascript">
Grids['visits'].SetDependantToolbarButtons( new Array('delete') );
</script>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: core/admin_templates/submissions/submissions_list.tpl
===================================================================
--- core/admin_templates/submissions/submissions_list.tpl
+++ core/admin_templates/submissions/submissions_list.tpl
@@ -48,6 +48,11 @@
</tbody>
</table>
+<style type="text/css">
+ tr.grid-data-row td.IPAddress {
+ text-overflow: ellipsis;
+ }
+</style>
<inp2:m_DefineElement name="grid_email_td">
<a href="mailto:<inp2:Field field="$field" />"><inp2:Field field="$field"/></a>
Index: core/admin_templates/users/users_list.tpl
===================================================================
--- core/admin_templates/users/users_list.tpl
+++ core/admin_templates/users/users_list.tpl
@@ -107,8 +107,14 @@
</tbody>
</table>
+<style type="text/css">
+ tr.grid-data-row td.IPAddress {
+ text-overflow: ellipsis;
+ }
+</style>
+
<inp2:m_RenderElement name="grid" PrefixSpecial="u.regular" IdField="PortalUserId" grid="RegularUsers"/>
<script type="text/javascript">
Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary', 'frontend_mail', 'e-mail', 'approve', 'decline') );
</script>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: core/install/english.lang
===================================================================
--- core/install/english.lang
+++ core/install/english.lang
@@ -404,7 +404,7 @@
<PHRASE Label="la_fld_DisplayName" Module="Core" Type="1">RmllbGQgTGFiZWw=</PHRASE>
<PHRASE Label="la_fld_DisplaySiteNameInHeader" Module="Core" Type="1">RGlzcGxheSBzaXRlIG5hbWUgaW4gSGVhZGVy</PHRASE>
<PHRASE Label="la_fld_DisplayToPublic" Module="Core" Type="1">RGlzcGxheSBUbyBQdWJsaWM=</PHRASE>
- <PHRASE Label="la_fld_DomainIPRange" Module="Core" Type="1" Hint="U2luZ2xlIElQLCBJUCByYW5nZSwgU3VibmV0IG9yIGhvc3RuYW1lIHJlY29yZCBwZXIgbGluZSAoZm9ybWF0czogMS4yLjMuNCBvciAxLjIuMy4zMi0xLjIuMy41NCBvciAxLjIuMy4zMi8yNyBvciAxLjIuMy4zMi8yNTUuMjU1LjI1NS4yMjQgb3Igd3d3LmluLXBvcnRhbC5jb20p">UmFuZ2Ugb2YgSVBz</PHRASE>
+ <PHRASE Label="la_fld_DomainIPRange" Module="Core" Type="1" Hint="U2luZ2xlIElQLCBJUCByYW5nZSwgU3VibmV0IG9yIGhvc3RuYW1lIHJlY29yZCBwZXIgbGluZSwgZS5nLjoNCg0KLSAxLjIuMy40DQotIDEuMi4zLjMyLTEuMi4zLjU0DQotIDEuMi4zLjMyLzI3DQotIDEuMi4zLjMyLzI1NS4yNTUuMjU1LjIyNA0KLSA5NzFhOjZmZjQ6M2ZlODpjZTI3OjcwODU6ZjQ5ODpmYzVhOjk4OTMNCi0gOTcxYTo2ZmY0OjNmZTg6Y2UyNzo3MDg1OmY0OTg6ZmM1YTo5ODkzLTk3MWE6NmZmNDozZmU4OmNlMjc6NzA4NTpmNDk4OmZjNWE6OTg5NQ0KLSA5NzFhOjZmZjQ6M2ZlODpjZTI3OjcwODU6ZjQ5ODpmYzVhOjk4OTMvNjQNCi0gd3d3LmluLXBvcnRhbC5jb20=">UmFuZ2Ugb2YgSVBz</PHRASE>
<PHRASE Label="la_fld_DomainName" Module="Core" Type="1" Column="RG9tYWluIE5hbWU=">RG9tYWluIE5hbWU=</PHRASE>
<PHRASE Label="la_fld_DoNotEncode" Module="Core" Type="1">QXMgUGxhaW4gVGV4dA==</PHRASE>
<PHRASE Label="la_fld_Duration" Module="Core" Type="1" Column="RHVyYXRpb24=">RHVyYXRpb24=</PHRASE>
Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql
+++ core/install/install_schema.sql
@@ -239,7 +239,7 @@
l5_ColumnTranslation text,
PhraseType int(11) NOT NULL DEFAULT '0',
LastChanged int(10) unsigned DEFAULT NULL,
- LastChangeIP varchar(15) NOT NULL DEFAULT '',
+ LastChangeIP varchar(50) NOT NULL DEFAULT '',
Module varchar(30) NOT NULL DEFAULT 'In-Portal',
PRIMARY KEY (PhraseId),
KEY Phrase_Index (Phrase),
@@ -304,7 +304,7 @@
Modified int(11) DEFAULT NULL,
dob int(11) DEFAULT NULL,
TimeZone varchar(255) NOT NULL DEFAULT '',
- IPAddress varchar(15) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
IsBanned tinyint(1) NOT NULL DEFAULT '0',
PwResetConfirm varchar(255) NOT NULL DEFAULT '',
PwRequestTime int(11) unsigned DEFAULT NULL,
@@ -398,7 +398,7 @@
`Language` int(11) NOT NULL DEFAULT '1',
Theme int(11) NOT NULL DEFAULT '1',
GroupId int(11) NOT NULL DEFAULT '0',
- IpAddress varchar(20) NOT NULL DEFAULT '0.0.0.0',
+ IpAddress varchar(50) NOT NULL DEFAULT '0.0.0.0',
`Status` int(11) NOT NULL DEFAULT '1',
GroupList varchar(255) DEFAULT NULL,
TimeZone varchar(255) NOT NULL DEFAULT '',
@@ -443,7 +443,7 @@
LogRequestData longtext,
LogUserId int(11) DEFAULT NULL,
LogInterface tinyint(4) DEFAULT NULL,
- IpAddress varchar(15) NOT NULL DEFAULT '',
+ IpAddress varchar(50) NOT NULL DEFAULT '',
LogSessionKey char(64) NOT NULL DEFAULT '',
LogSessionData longtext,
LogBacktrace longtext,
@@ -874,7 +874,7 @@
CREATE TABLE CatalogRatings (
RatingId int(11) NOT NULL auto_increment,
- IPAddress varchar(255) NOT NULL default '',
+ IPAddress varchar(50) NOT NULL default '',
CreatedOn INT UNSIGNED NULL DEFAULT NULL,
RatingValue int(11) NOT NULL default '0',
ItemId int(11) NOT NULL default '0',
@@ -889,7 +889,7 @@
CreatedOn int(10) unsigned DEFAULT NULL,
ReviewText longtext,
Rating tinyint(3) unsigned NOT NULL DEFAULT '0',
- IPAddress varchar(255) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
ItemId int(11) NOT NULL DEFAULT '0',
CreatedById int(11) DEFAULT NULL,
ItemType tinyint(4) NOT NULL DEFAULT '0',
@@ -1025,7 +1025,7 @@
CREATE TABLE SpamControl (
ItemResourceId int(11) NOT NULL default '0',
- IPaddress varchar(20) NOT NULL default '',
+ IPaddress varchar(50) NOT NULL default '',
Expire INT UNSIGNED NULL DEFAULT NULL,
PortalUserId int(11) NOT NULL default '0',
DataType varchar(20) default NULL,
@@ -1066,7 +1066,7 @@
VisitId int(11) NOT NULL AUTO_INCREMENT,
VisitDate int(10) unsigned DEFAULT NULL,
Referer varchar(255) NOT NULL DEFAULT '',
- IPAddress varchar(15) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
AffiliateId int(10) unsigned NOT NULL DEFAULT '0',
PortalUserId int(11) NOT NULL DEFAULT '-2',
PRIMARY KEY (VisitId),
@@ -1197,7 +1197,7 @@
FormSubmissionId int(11) NOT NULL AUTO_INCREMENT,
FormId int(11) NOT NULL DEFAULT '0',
SubmissionTime int(11) DEFAULT NULL,
- IPAddress varchar(15) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
ReferrerURL text NULL,
LogStatus tinyint(3) unsigned NOT NULL DEFAULT '2',
LastUpdatedOn int(10) unsigned DEFAULT NULL,
@@ -1291,7 +1291,7 @@
`MainPrefix` varchar(255) NOT NULL DEFAULT '',
`MainIDs` text,
`UserId` int(11) DEFAULT NULL,
- `IpAddress` varchar(15) NOT NULL DEFAULT '',
+ `IpAddress` varchar(50) NOT NULL DEFAULT '',
`Hostname` varchar(255) NOT NULL DEFAULT '',
`RequestURI` varchar(255) NOT NULL DEFAULT '',
`Backtrace` longtext,
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql
+++ core/install/upgrades.sql
@@ -2986,3 +2986,19 @@
UPDATE UserSessionLogs SET SessionKey = SessionId;
ALTER TABLE CurlLog CHANGE `SessionKey` `SessionKey` char(64) NOT NULL DEFAULT '';
ALTER TABLE SystemLog CHANGE `LogSessionKey` `LogSessionKey` char(64) NOT NULL DEFAULT '';
+
+ALTER TABLE SystemLog CHANGE `IpAddress` `IpAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE UserSessions CHANGE `IpAddress` `IpAddress` varchar(50) NOT NULL DEFAULT '0.0.0.0';
+ALTER TABLE Semaphores CHANGE `IpAddress` `IpAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE FormSubmissions CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE LanguageLabels CHANGE `LastChangeIP` `LastChangeIP` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE CatalogRatings CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE SpamControl CHANGE `IPaddress` `IPaddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE UserSessionLogs CHANGE `IP` `IP` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE CatalogReviews CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE Users CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE UserVisits CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+
+UPDATE LanguageLabels
+SET l1_HintTranslation = 'Single IP, IP range, Subnet or hostname record per line, e.g.:\r\n\r\n- 1.2.3.4\r\n- 1.2.3.32-1.2.3.54\r\n- 1.2.3.32/27\r\n- 1.2.3.32/255.255.255.224\r\n- 971a:6ff4:3fe8:ce27:7085:f498:fc5a:9893\r\n- 971a:6ff4:3fe8:ce27:7085:f498:fc5a:9893-971a:6ff4:3fe8:ce27:7085:f498:fc5a:9895\r\n- 971a:6ff4:3fe8:ce27:7085:f498:fc5a:9893/64\r\n- www.in-portal.com'
+WHERE PhraseKey = 'LA_FLD_DOMAINIPRANGE';
Index: core/kernel/globals.php
===================================================================
--- core/kernel/globals.php
+++ core/kernel/globals.php
@@ -527,39 +527,78 @@
$network = trim($network);
$ip = trim($ip);
- if ( preg_replace('/[\d\.\/-]/', '', $network) != '' ) {
+ if ( preg_replace('#[\da-f.:\-/]#i', '', $network) != '' ) {
$network = gethostbyname($network);
}
- if ($network == $ip) {
- // comparing two ip addresses directly
+ // Comparing two ip addresses directly.
+ if ( $network === $ip ) {
return true;
}
- $d = strpos($network, '-');
- if ($d !== false) {
- // ip address range specified
- $from = ip2long(trim(substr($network, 0, $d)));
- $to = ip2long(trim(substr($network, $d + 1)));
+ // Compare only with networks of the same IP specification.
+ if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
+ $filter_option = FILTER_FLAG_IPV4;
+ }
+ else {
+ $filter_option = FILTER_FLAG_IPV6;
+ }
+
+ // IP address range specified.
+ $delimiter_pos = strpos($network, '-');
+
+ if ( $delimiter_pos !== false ) {
+ $from = trim(substr($network, 0, $delimiter_pos));
+ $to = trim(substr($network, $delimiter_pos + 1));
+
+ if ( !filter_var($from, FILTER_VALIDATE_IP, $filter_option)
+ || !filter_var($to, FILTER_VALIDATE_IP, $filter_option)
+ ) {
+ return false;
+ }
+
+ if ( $filter_option === FILTER_FLAG_IPV4 ) {
+ $ip = ip2long($ip);
+
+ return $ip >= ip2long($from) && $ip <= ip2long($to);
+ }
+
+ $ip = inet_pton($ip);
- $ip = ip2long($ip);
- return ($ip >= $from && $ip <= $to);
+ return $ip >= inet_pton($from) && $ip <= inet_pton($to);
}
- elseif (strpos($network, '/') !== false) {
- // single subnet specified
+
+ // Single subnet specified (CIDR).
+ if ( strpos($network, '/') !== false ) {
$ip_arr = explode('/', $network);
- if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
- $ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
+ // Alternate form of the "194.1.4/24".
+ if ( ($filter_option === FILTER_FLAG_IPV4) && !preg_match('@\d*\.\d*\.\d*\.\d*@', $ip_arr[0]) ) {
+ $ip_arr[0] .= '.0';
+ }
+
+ if ( !filter_var($ip_arr[0], FILTER_VALIDATE_IP, $filter_option) ) {
+ return false;
+ }
+
+ if ( $filter_option === FILTER_FLAG_IPV4 ) {
+ $network_long = ip2long($ip_arr[0]);
+ $x = ip2long($ip_arr[1]);
+
+ $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
+ $ip_long = ip2long($ip);
+
+ return ($ip_long & $mask) == ($network_long & $mask);
}
- $network_long = ip2long($ip_arr[0]);
- $x = ip2long($ip_arr[1]);
+ $subnet_hex = unpack('H*', inet_pton($ip_arr[0]))[1]; // 32 bytes, but 16 hex symbols.
+ $ip_hex = unpack('H*', inet_pton($ip))[1]; // 32 bytes, but 16 hex symbols.
- $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
- $ip_long = ip2long($ip);
+ $mask = $ip_arr[1] / 4; // The "4" is the size of each hex symbol in bits.
+ $subnet_hex = hex2bin(str_pad(substr($subnet_hex, 0, $mask), 32, '0'));
+ $ip_hex = hex2bin(str_pad(substr($ip_hex, 0, $mask), 32, '0'));
- return ($ip_long & $mask) == ($network_long & $mask);
+ return $subnet_hex === $ip_hex;
}
return false;
Index: core/kernel/utility/debugger.php
===================================================================
--- core/kernel/utility/debugger.php
+++ core/kernel/utility/debugger.php
@@ -151,44 +151,83 @@
* @return bool
* @access public
*/
- public static function netMatch($network, $ip) {
-
+ public static function netMatch($network, $ip)
+ {
$network = trim($network);
$ip = trim($ip);
- if ( preg_replace('/[\d\.\/-]/', '', $network) != '' ) {
+ if ( preg_replace('#[\da-f.:\-/]#i', '', $network) != '' ) {
$network = gethostbyname($network);
}
- if ($network == $ip) {
- // comparing two ip addresses directly
+ // Comparing two ip addresses directly.
+ if ( $network === $ip ) {
return true;
}
- $d = strpos($network, '-');
- if ($d !== false) {
- // ip address range specified
- $from = ip2long(trim(substr($network, 0, $d)));
- $to = ip2long(trim(substr($network, $d + 1)));
+ // Compare only with networks of the same IP specification.
+ if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
+ $filter_option = FILTER_FLAG_IPV4;
+ }
+ else {
+ $filter_option = FILTER_FLAG_IPV6;
+ }
+
+ // IP address range specified.
+ $delimiter_pos = strpos($network, '-');
+
+ if ( $delimiter_pos !== false ) {
+ $from = trim(substr($network, 0, $delimiter_pos));
+ $to = trim(substr($network, $delimiter_pos + 1));
+
+ if ( !filter_var($from, FILTER_VALIDATE_IP, $filter_option)
+ || !filter_var($to, FILTER_VALIDATE_IP, $filter_option)
+ ) {
+ return false;
+ }
+
+ if ( $filter_option === FILTER_FLAG_IPV4 ) {
+ $ip = ip2long($ip);
- $ip = ip2long($ip);
- return ($ip >= $from && $ip <= $to);
+ return $ip >= ip2long($from) && $ip <= ip2long($to);
+ }
+
+ $ip = inet_pton($ip);
+
+ return $ip >= inet_pton($from) && $ip <= inet_pton($to);
}
- elseif (strpos($network, '/') !== false) {
- // single subnet specified
+
+ // Single subnet specified (CIDR).
+ if ( strpos($network, '/') !== false ) {
$ip_arr = explode('/', $network);
- if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
- $ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
+ // Alternate form of the "194.1.4/24".
+ if ( ($filter_option === FILTER_FLAG_IPV4) && !preg_match('@\d*\.\d*\.\d*\.\d*@', $ip_arr[0]) ) {
+ $ip_arr[0] .= '.0';
+ }
+
+ if ( !filter_var($ip_arr[0], FILTER_VALIDATE_IP, $filter_option) ) {
+ return false;
+ }
+
+ if ( $filter_option === FILTER_FLAG_IPV4 ) {
+ $network_long = ip2long($ip_arr[0]);
+ $x = ip2long($ip_arr[1]);
+
+ $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
+ $ip_long = ip2long($ip);
+
+ return ($ip_long & $mask) == ($network_long & $mask);
}
- $network_long = ip2long($ip_arr[0]);
- $x = ip2long($ip_arr[1]);
+ $subnet_hex = unpack('H*', inet_pton($ip_arr[0]))[1]; // 32 bytes, but 16 hex symbols.
+ $ip_hex = unpack('H*', inet_pton($ip))[1]; // 32 bytes, but 16 hex symbols.
- $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
- $ip_long = ip2long($ip);
+ $mask = $ip_arr[1] / 4; // The "4" is the size of each hex symbol in bits.
+ $subnet_hex = hex2bin(str_pad(substr($subnet_hex, 0, $mask), 32, '0'));
+ $ip_hex = hex2bin(str_pad(substr($ip_hex, 0, $mask), 32, '0'));
- return ($ip_long & $mask) == ($network_long & $mask);
+ return $subnet_hex === $ip_hex;
}
return false;
Index: core/tests/Unit/kernel/kUtilTest.php
===================================================================
--- /dev/null
+++ core/tests/Unit/kernel/kUtilTest.php
@@ -0,0 +1,59 @@
+<?php
+
+
+class kUtilTest extends AbstractTestCase
+{
+
+ /**
+ * @dataProvider netMatchDataProvider
+ */
+ public function testNetMatch($network, $ip, $expected)
+ {
+ $this->assertSame($expected, kUtil::netMatch($network, $ip));
+ }
+
+ public static function netMatchDataProvider()
+ {
+ $ip_from_host = gethostbyname('www.in-portal.org');
+
+ return array(
+ // Hosts.
+ array('www.in-portal.org', $ip_from_host, true),
+ array('www.yahoo.com', $ip_from_host, false),
+
+ // IPv4 address vs IPv4 network.
+ array('1.2.3.4', '1.2.3.4', true),
+ array('1.2.3.4', '1.2.3.5', false),
+ array('1.2.3.32-1.2.3.54', '1.2.3.40', true),
+ array('1.2.3.32-1.2.3.54', '1.2.3.64', false),
+ array('1.2.3.32/27', '1.2.3.35', true),
+ array('1.2.3.32/27', '1.2.3.64', false),
+ array('1.2.3/27', '1.2.3.5', true),
+ array('1.2.3/27', '1.2.3.33', false),
+ array('1.2.3.32/255.255.255.224', '1.2.3.35', true),
+ array('1.2.3.32/255.255.255.224', '1.2.3.64', false),
+ array('1.2.3.32/27', '1.2.3.4.6', false),
+
+ // IPv6 address vs IPv6 network.
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9893', true),
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9895', false),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9894', true),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9896', false),
+ array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe8::9895', true),
+ array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe9::9895', false),
+
+ // IPv6 address vs IPv4 network.
+ array('1.2.3.4', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32-1.2.3.54', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32/255.255.255.224', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+
+ // IPv4 address vs IPv6 network.
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '1.2.3.4', false),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '1.2.3.4', false),
+ array('971a:6ff4:3fe8::9893/64', '1.2.3.4', false),
+ );
+ }
+
+}
Index: core/tests/Unit/kernel/utility/DebuggerUtilTest.php
===================================================================
--- /dev/null
+++ core/tests/Unit/kernel/utility/DebuggerUtilTest.php
@@ -0,0 +1,59 @@
+<?php
+
+
+class DebuggerUtilTest extends AbstractTestCase
+{
+
+ /**
+ * @dataProvider netMatchDataProvider
+ */
+ public function testNetMatch($network, $ip, $expected)
+ {
+ $this->assertSame($expected, DebuggerUtil::netMatch($network, $ip));
+ }
+
+ public static function netMatchDataProvider()
+ {
+ $ip_from_host = gethostbyname('www.in-portal.org');
+
+ return array(
+ // Hosts.
+ array('www.in-portal.org', $ip_from_host, true),
+ array('www.yahoo.com', $ip_from_host, false),
+
+ // IPv4 address vs IPv4 network.
+ array('1.2.3.4', '1.2.3.4', true),
+ array('1.2.3.4', '1.2.3.5', false),
+ array('1.2.3.32-1.2.3.54', '1.2.3.40', true),
+ array('1.2.3.32-1.2.3.54', '1.2.3.64', false),
+ array('1.2.3.32/27', '1.2.3.35', true),
+ array('1.2.3.32/27', '1.2.3.64', false),
+ array('1.2.3/27', '1.2.3.5', true),
+ array('1.2.3/27', '1.2.3.33', false),
+ array('1.2.3.32/255.255.255.224', '1.2.3.35', true),
+ array('1.2.3.32/255.255.255.224', '1.2.3.64', false),
+ array('1.2.3.32/27', '1.2.3.4.6', false),
+
+ // IPv6 address vs IPv6 network.
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9893', true),
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '971a:6ff4:3fe8::7085:f498:fc5a:9895', false),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9894', true),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '971a:6ff4:3fe8::9896', false),
+ array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe8::9895', true),
+ array('971a:6ff4:3fe8::9893/64', '971a:6ff4:3fe9::9895', false),
+
+ // IPv6 address vs IPv4 network.
+ array('1.2.3.4', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32-1.2.3.54', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3/27', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+ array('1.2.3.32/255.255.255.224', '971a:6ff4:3fe8::7085:f498:fc5a:9893', false),
+
+ // IPv4 address vs IPv6 network.
+ array('971a:6ff4:3fe8::7085:f498:fc5a:9893', '1.2.3.4', false),
+ array('971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895', '1.2.3.4', false),
+ array('971a:6ff4:3fe8::9893/64', '1.2.3.4', false),
+ );
+ }
+
+}
Index: core/units/forms/form_submissions/form_submissions_config.php
===================================================================
--- core/units/forms/form_submissions/form_submissions_config.php
+++ core/units/forms/form_submissions/form_submissions_config.php
@@ -123,7 +123,7 @@
'FormSubmissionId' => Array ('type' => 'int', 'not_null' => 1,'default' => 0),
'FormId' => Array ('type' => 'int', 'not_null' => '1', 'default' => 0),
'SubmissionTime' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'),
- 'IPAddress' => Array ('type' => 'string', 'max_len' => 15, 'not_null' => 1, 'default' => ''),
+ 'IPAddress' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'ReferrerURL' => Array ('type' => 'string', 'default' => NULL),
'LogStatus' => Array (
Index: core/units/logs/session_logs/session_logs_config.php
===================================================================
--- core/units/logs/session_logs/session_logs_config.php
+++ core/units/logs/session_logs/session_logs_config.php
@@ -120,7 +120,7 @@
),
'SessionStart' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'time_format' => 'H:i:s', 'default' => NULL),
'SessionEnd' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'time_format' => 'H:i:s', 'default' => NULL),
- 'IP' => Array ('type' => 'string', 'max_len' => 15, 'not_null' => 1, 'default' => ''),
+ 'IP' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'AffectedItems' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
),
Index: core/units/logs/system_logs/system_logs_config.php
===================================================================
--- core/units/logs/system_logs/system_logs_config.php
+++ core/units/logs/system_logs/system_logs_config.php
@@ -151,7 +151,7 @@
),
'not_null' => 1, 'default' => 0
),
- 'IpAddress' => Array ('type' => 'string', 'max_len' => 15, 'not_null' => 1, 'default' => ''),
+ 'IpAddress' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'LogSessionKey' => Array ('type' => 'string', 'max_len' => 64, 'not_null' => 1, 'default' => ''),
'LogSessionData' => Array ('type' => 'string', 'default' => NULL),
'LogBacktrace' => Array ('type' => 'string', 'default' => NULL),
Index: core/units/phrases/phrases_config.php
===================================================================
--- core/units/phrases/phrases_config.php
+++ core/units/phrases/phrases_config.php
@@ -125,7 +125,7 @@
'not_null' => 1, 'required' => 1, 'default' => Language::PHRASE_TYPE_COMMON,
),
'LastChanged' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
- 'LastChangeIP' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'LastChangeIP' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'Module' => Array (
'type' => 'string',
'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Modules WHERE (Loaded = 1) AND (Name <> "In-Portal") ORDER BY LoadOrder', 'option_key_field' => 'Name', 'option_title_field' => 'Name',
Index: core/units/reviews/reviews_config.php
===================================================================
--- core/units/reviews/reviews_config.php
+++ core/units/reviews/reviews_config.php
@@ -120,10 +120,7 @@
'use_phrases' => 1,
'min_value_inc' => 0, 'max_value_inc' => 5, 'not_null' => 1, 'default' => 0,
),
- 'IPAddress' => Array (
- 'type' => 'string',
- 'max_value_inc' => 15, 'not_null' =>1, 'default' => '',
- ),
+ 'IPAddress' => array('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'ItemId' => Array (
'type' => 'int',
'not_null' => 1, 'default' => 0
Index: core/units/users/users_config.php
===================================================================
--- core/units/users/users_config.php
+++ core/units/users/users_config.php
@@ -396,7 +396,7 @@
'Modified' => Array ('formatter' => 'kDateFormatter', 'default' => NULL),
'dob' => Array ('formatter' => 'kDateFormatter', 'default' => NULL),
'TimeZone' => Array ('default' => ''),
- 'IPAddress' => Array ('default' => ''),
+ 'IPAddress' => Array ('max_len' => 50, 'default' => ''),
'IsBanned' => Array ('default' => 0),
'PwResetConfirm' => Array ('default' => ''),
'PwRequestTime' => Array ('formatter' => 'kDateFormatter', 'default' => NULL),
Index: core/units/visits/visits_config.php
===================================================================
--- core/units/visits/visits_config.php
+++ core/units/visits/visits_config.php
@@ -122,7 +122,7 @@
'VisitId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'VisitDate' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'custom_filter' => 'date_range', 'default' => NULL),
'Referer' => Array ('type' => 'string', 'not_null' => '1', 'default' => ''),
- 'IPAddress' => Array ('type' => 'string', 'not_null' => '1', 'default' => ''),
+ 'IPAddress' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => '1', 'default' => ''),
'AffiliateId' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (0 => 'lu_None'), 'left_sql' => 'SELECT %s FROM '.TABLE_PREFIX.'Affiliates af LEFT JOIN '.TABLE_PREFIX.'Users u ON u.PortalUserId = af.PortalUserId WHERE %s', 'left_key_field' => 'AffiliateId', 'left_title_field' => 'IF(u.Email = "", u.Username, u.Email)', 'not_null'=>1,'default'=>0),
'PortalUserId' => Array ('type' => 'int', 'not_null' => '1', 'default' => USER_GUEST),
),
Index: modules/in-bulletin/install/install_schema.sql
===================================================================
--- modules/in-bulletin/install/install_schema.sql
+++ modules/in-bulletin/install/install_schema.sql
@@ -1,6 +1,6 @@
CREATE TABLE Posting (
PostingId int(11) NOT NULL AUTO_INCREMENT,
- IPAddress varchar(255) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
PosterAlias varchar(255) NOT NULL DEFAULT '',
Pending tinyint(4) NOT NULL DEFAULT '0',
`Subject` varchar(255) DEFAULT NULL,
@@ -172,7 +172,7 @@
GuestEmail varchar(255) NOT NULL DEFAULT '',
CommentBody text,
CreatedOn int(11) DEFAULT NULL,
- UserIP varchar(255) NOT NULL DEFAULT '',
+ UserIP varchar(50) NOT NULL DEFAULT '',
Priority int(11) NOT NULL DEFAULT '0',
`Status` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (CommentId),
@@ -189,10 +189,10 @@
PollId int(11) NOT NULL DEFAULT '0',
AnswerId int(11) NOT NULL DEFAULT '0',
CreatedById int(11) NOT NULL DEFAULT '-2',
- UserIP varchar(255) NOT NULL DEFAULT '',
+ UserIP varchar(50) NOT NULL DEFAULT '',
AnswerDate int(10) unsigned DEFAULT NULL,
PRIMARY KEY (StatisticsId),
KEY AnswerId (AnswerId,PollId),
KEY CreatedById (CreatedById),
KEY UserIP (UserIP)
-);
\ No newline at end of file
+);
Index: modules/in-bulletin/install/upgrades.sql
===================================================================
--- modules/in-bulletin/install/upgrades.sql
+++ modules/in-bulletin/install/upgrades.sql
@@ -282,3 +282,8 @@
UPDATE Modules
SET ClassNamespace = 'InPortal\\Modules\\InBulletin'
WHERE `Name` = 'In-Bulletin';
+
+# ===== v 5.2.2-B3 =====
+ALTER TABLE PollsComments CHANGE `UserIP` `UserIP` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE PollsStatistics CHANGE `UserIP` `UserIP` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE Posting CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
Index: modules/in-bulletin/units/poll_comments/poll_comments_config.php
===================================================================
--- modules/in-bulletin/units/poll_comments/poll_comments_config.php
+++ modules/in-bulletin/units/poll_comments/poll_comments_config.php
@@ -73,7 +73,7 @@
'GuestEmail' => Array('type' => 'string', 'max_len' => 255, 'formatter' => 'kFormatter', 'regexp' => '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', 'sample_value' => 'email@domain.com', 'not_null' => '1', 'default' => '', 'error_msgs' => Array ('invalid_format' => '!la_invalid_email!', 'unique' => '!lu_email_already_exist!'), 'required' => 0),
'CommentBody' => Array ('type' => 'string', 'required' => 1, 'default' => NULL),
'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#'),
- 'UserIP' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
+ 'UserIP' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'Priority' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Status' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_opt_Active', 0 => 'la_opt_Disabled', 2 => 'la_opt_Pending'), 'use_phrases' => 1, 'required' => 1, 'not_null' => 1, 'default' => 1),
),
Index: modules/in-bulletin/units/posts/posts_config.php
===================================================================
--- modules/in-bulletin/units/posts/posts_config.php
+++ modules/in-bulletin/units/posts/posts_config.php
@@ -73,7 +73,7 @@
'Fields' => Array (
'PostingId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- 'IPAddress' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
+ 'IPAddress' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'PosterAlias' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
'Pending' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Subject' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL),
Index: modules/in-commerce/admin_templates/downloads/downloads_list.tpl
===================================================================
--- modules/in-commerce/admin_templates/downloads/downloads_list.tpl
+++ modules/in-commerce/admin_templates/downloads/downloads_list.tpl
@@ -41,10 +41,16 @@
</tbody>
</table>
+<style type="text/css">
+ tr.grid-data-row td.IPAddress {
+ text-overflow: ellipsis;
+ }
+</style>
+
<inp2:m_RenderElement name="grid" PrefixSpecial="down" IdField="DownloadId" grid="Default"/>
<script type="text/javascript">
Grids['down'].SetDependantToolbarButtons( new Array('reset') );
</script>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: modules/in-commerce/admin_templates/visits/visits_list_incommerce.tpl
===================================================================
--- modules/in-commerce/admin_templates/visits/visits_list_incommerce.tpl
+++ modules/in-commerce/admin_templates/visits/visits_list_incommerce.tpl
@@ -46,6 +46,12 @@
</tbody>
</table>
+<style type="text/css">
+ tr.grid-data-row td.IPAddress {
+ text-overflow: ellipsis;
+ }
+</style>
+
<inp2:m_DefineElement name="grid_userlink_td">
<inp2:m_if check="UserFound" user_field="$user_field">
<a href="<inp2:UserLink edit_template='users/users_edit' user_field="$user_field"/>" onclick="return direct_edit('<inp2:m_Param name="PrefixSpecial"/>', this.href);" title="<inp2:m_phrase name="la_Edit_User"/>"><inp2:Field field="$field" grid="$grid"/></a>
@@ -68,4 +74,4 @@
<script type="text/javascript">
Grids['visits.incommerce'].SetDependantToolbarButtons( new Array('delete') );
</script>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: modules/in-commerce/install/install_schema.sql
===================================================================
--- modules/in-commerce/install/install_schema.sql
+++ modules/in-commerce/install/install_schema.sql
@@ -129,7 +129,7 @@
OnHold tinyint(3) unsigned NOT NULL DEFAULT '0',
OrderDate int(10) unsigned DEFAULT NULL,
PortalUserId int(11) NOT NULL DEFAULT '-1',
- OrderIP varchar(30) NOT NULL DEFAULT '',
+ OrderIP varchar(50) NOT NULL DEFAULT '',
UserComment text,
AdminComment text,
BillingTo varchar(255) NOT NULL DEFAULT '',
@@ -490,7 +490,7 @@
ProductName varchar(255) NOT NULL DEFAULT '',
FileId int(11) NOT NULL DEFAULT '0',
Filename varchar(255) NOT NULL DEFAULT '',
- IPAddress varchar(100) NOT NULL DEFAULT '',
+ IPAddress varchar(50) NOT NULL DEFAULT '',
StartedOn int(11) DEFAULT NULL,
EndedOn int(11) DEFAULT NULL,
PRIMARY KEY (DownloadId),
Index: modules/in-commerce/install/upgrades.sql
===================================================================
--- modules/in-commerce/install/upgrades.sql
+++ modules/in-commerce/install/upgrades.sql
@@ -302,3 +302,7 @@
UPDATE Modules
SET ClassNamespace = 'InPortal\\Modules\\InCommerce'
WHERE `Name` = 'In-Commerce';
+
+# ===== v 5.2.2-B3 =====
+ALTER TABLE UserDownloads CHANGE `IPAddress` `IPAddress` varchar(50) NOT NULL DEFAULT '';
+ALTER TABLE Orders CHANGE `OrderIP` `OrderIP` varchar(50) NOT NULL DEFAULT '';
Index: modules/in-commerce/units/downloads/downloads_config.php
===================================================================
--- modules/in-commerce/units/downloads/downloads_config.php
+++ modules/in-commerce/units/downloads/downloads_config.php
@@ -90,7 +90,7 @@
'ProductName' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
'FileId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Filename' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
- 'IPAddress' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'IPAddress' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => ''),
'StartedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
'EndedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
),
@@ -113,4 +113,4 @@
),
),
),
-);
\ No newline at end of file
+);
Index: modules/in-commerce/units/orders/orders_config.php
===================================================================
--- modules/in-commerce/units/orders/orders_config.php
+++ modules/in-commerce/units/orders/orders_config.php
@@ -326,7 +326,7 @@
),
'OrderDate' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'required' => 1, 'default' => '#NOW#'),
'PortalUserId' =>Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' =>Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'required' =>1, 'not_null' =>1, 'default' =>-1),
- 'OrderIP' => Array ('type' => 'string', 'not_null' => 1, 'default' => '', 'filter_type' => 'like'),
+ 'OrderIP' => Array ('type' => 'string', 'max_len' => 50, 'not_null' => 1, 'default' => '', 'filter_type' => 'like'),
'UserComment' => Array ('type' => 'string', 'default' => NULL),
'AdminComment' => Array ('type' => 'string', 'default' => NULL),
'BillingTo' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),

Event Timeline