summaryrefslogtreecommitdiff
path: root/post.php
diff options
context:
space:
mode:
Diffstat (limited to 'post.php')
-rw-r--r--post.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/post.php b/post.php
index 742a95b0..99b1110b 100644
--- a/post.php
+++ b/post.php
@@ -447,13 +447,25 @@ if (isset($_POST['delete'])) {
}
if ($config['country_flags']) {
- if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
- error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION));
+ require 'inc/lib/geoip/geoip.inc';
+ $gi=geoip\geoip_open('inc/lib/geoip/GeoIPv6.dat', GEOIP_STANDARD);
+
+ function ipv4to6($ip) {
+ if (strpos($ip, ':') !== false) {
+ if (strpos($ip, '.') > 0)
+ $ip = substr($ip, strrpos($ip, ':')+1);
+ else return $ip; //native ipv6
+ }
+ $iparr = array_pad(explode('.', $ip), 4, 0);
+ $part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
+ $part8 = base_convert(($iparr[2] * 256) + $iparr[3], 10, 16);
+ return '::ffff:'.$part7.':'.$part8;
}
- if ($country_code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])) {
+
+ if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2')))
- $post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . "</tinyboard>" .
- "\n<tinyboard flag alt>" . @geoip_country_name_by_name($_SERVER['REMOTE_ADDR']) . "</tinyboard>";
+ $post['body'] .= "\n<tinyboard flag>".strtolower($country_code)."</tinyboard>".
+ "\n<tinyboard flag alt>".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))."</tinyboard>";
}
}