diff --git a/CHANGELOG.md b/CHANGELOG.md index bbe82806..2dc88ee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ **Merged pull requests:** - Release v2.1.5-2023.06 🎉 +- IP detect subsystem replace [\#204](https://github.com/torrentpier/torrentpier-lts/pull/204) ([belomaxorka](https://github.com/belomaxorka)) - Fixed broken skype widget in user profile [\#203](https://github.com/torrentpier/torrentpier-lts/pull/203) ([belomaxorka](https://github.com/belomaxorka)) - Redirect to viewprofile.php if profile.php hasn't arguments [\#202](https://github.com/torrentpier/torrentpier-lts/pull/202) ([belomaxorka](https://github.com/belomaxorka)) - Show smilies in post for guests [\#196](https://github.com/torrentpier/torrentpier-lts/pull/196) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/admin/admin_log.php b/admin/admin_log.php index 2e53c409..b9915c3a 100644 --- a/admin/admin_log.php +++ b/admin/admin_log.php @@ -304,7 +304,7 @@ if ($log_rowset) 'USER_ID' => $row['log_user_id'], 'USERNAME' => $row['log_username'], 'USER_HREF_S' => url_arg($url, $user_key, $row['log_user_id']), - 'USER_IP' => decode_ip($row['log_user_ip']), + 'USER_IP' => verify_ip($row['log_user_ip']) ? decode_ip($row['log_user_ip']) : '127.0.0.1', 'FORUM_ID' => $row['log_forum_id'], 'FORUM_HREF' => BB_ROOT . FORUM_URL . $row['log_forum_id'], @@ -410,4 +410,4 @@ $template->assign_vars(array( 'TOPIC_CSV' => $topic_csv, )); -print_page('admin_log.tpl', 'admin'); \ No newline at end of file +print_page('admin_log.tpl', 'admin'); diff --git a/common.php b/common.php index d43e41b6..a1745ca1 100644 --- a/common.php +++ b/common.php @@ -266,13 +266,17 @@ function clean_filename ($fname) function encode_ip ($ip) { - $d = explode('.', $ip); - return sprintf('%02x%02x%02x%02x', $d[0], $d[1], $d[2], $d[3]); + $long = -1; + if (verify_ip($ip)) + { + $long = ip2long($ip); + } + return $long; } function decode_ip ($ip) { - return long2ip("0x{$ip}"); + return long2ip($ip); } function ip2int ($ip) @@ -300,7 +304,7 @@ function hexhex ($value) function verify_ip ($ip) { - return preg_match('#^(\d{1,3}\.){3}\d{1,3}$#', $ip); + return (bool)filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } function str_compact ($str) diff --git a/library/includes/functions.php b/library/includes/functions.php index 46063e8d..e56713e4 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -997,8 +997,7 @@ function bt_show_port ($port) function decode_ip_xx ($ip) { - $h = explode('.', chunk_split($ip, 2, '.')); - return hexdec($h[0]) .'.'. hexdec($h[1]) .'.'. hexdec($h[2]) .'.xx'; + return inet_ntop(inet_pton($ip) & inet_pton("255.255.255.0")); } function checkbox_get_val (&$key, &$val, $default = 1, $on = 1, $off = 0)