summaryrefslogtreecommitdiff
path: root/post.php
diff options
context:
space:
mode:
authorJano Slota <jano@alokal.eu>2014-02-11 14:40:22 +0100
committerczaks <marcin@6irc.net>2014-02-18 23:49:07 +0100
commitada45312a4b1ddc4f975dcd9c1d272a73a701ffd (patch)
treece61fc8f1dabdd06fc2ace427110ac58272cffd9 /post.php
parentcbf44d4d75db5c12fdc694aa321c12a3f9eec403 (diff)
Use the added GeoIPv6 instead of the PHP plugin. Quite messy.
Diffstat (limited to 'post.php')
-rw-r--r--post.php25
1 files changed, 19 insertions, 6 deletions
diff --git a/post.php b/post.php
index 742a95b0..2f2d3ff4 100644
--- a/post.php
+++ b/post.php
@@ -447,13 +447,26 @@ 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 'geoip.inc';
+ $gi=geoip_open('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 (!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>";
+
+ if ($country_code = 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_addr_v6($gi, IPv4To6($_SERVER['REMOTE_ADDR'])) . "</tinyboard>";
}
}