diff options
| author | czaks <marcin@6irc.net> | 2014-03-25 13:03:37 +0100 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-03-25 13:03:37 +0100 |
| commit | f0b2240b5f1e67fb9ad4770a3d5b0f298cf4c1d4 (patch) | |
| tree | 3180570731df62be98bd4737c34b5b3ae9ca828e /post.php | |
| parent | 15810c9bedb5b7d18baec0f845bb3177f867471e (diff) | |
| parent | 44db8e76d8e21b38f9be4ad9e69f6af19c116fb0 (diff) | |
Merge branch 'master' of github.com:vichan-devel/Tinyboard into br-integration
Diffstat (limited to 'post.php')
| -rw-r--r-- | post.php | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -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>"; } } |
