ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/BBClone/trunk/lib/plugin/ext_lookup_geoip.php
Revision: 417
Committed: Wed Dec 21 11:27:14 2022 UTC (23 months ago) by joku
File size: 2155 byte(s)
Log Message:
update Copyright 

File Contents

# Content
1 <?php
2 /* This file is part of BBClone (A PHP based Web Counter on Steroids)
3 *
4 * SVN FILE $Id$
5 *
6 * Copyright (C) 2001-2023, the BBClone Team (see doc/authors.txt for details)
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * See doc/copying.txt for details
19 */
20
21 /////////////////////////////////////////
22 // Plug-in: Extension look-up by GeoIP //
23 /////////////////////////////////////////
24
25 function bbc_extension_plugin($host, $addr) {
26 global $BBC_GEOIP_PATH, $gi;
27
28 if ( function_exists("geoip_country_code_by_name") ){
29 $addr = geoip_country_code_by_name($addr);
30 } else {
31 // First of all let's check if the include file exists
32 if ( !@file_exists( $BBC_GEOIP_PATH.'geoip.inc' ) ) {
33 bbc_msg('Missing geoip installation');
34 }
35 @include_once ( $BBC_GEOIP_PATH.'geoip.inc' );
36
37 // Bail out if the file exists but does not seem to be geoip
38 if ( !function_exists('geoip_open') ) {
39 return "";
40 }
41
42 if (filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
43 $gi = geoip_open($BBC_GEOIP_PATH ."GeoIPv6.dat",GEOIP_STANDARD);
44 $addr = geoip_country_code_by_addr_v6($gi, $addr);
45 } elseif (filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
46 $gi = geoip_open($BBC_GEOIP_PATH ."GeoIP.dat",GEOIP_STANDARD);
47 $addr = geoip_country_code_by_addr($gi, $addr);
48 } else {
49 if((strpos($addr, ":") === false)) {
50 //ipv4
51 $gi = geoip_open($BBC_GEOIP_PATH ."GeoIP.dat",GEOIP_STANDARD);
52 $addr = geoip_country_code_by_addr($gi, $addr);
53 } else {
54 //ipv6
55 $gi = geoip_open($BBC_GEOIP_PATH ."GeoIPv6.dat",GEOIP_STANDARD);
56 $addr = geoip_country_code_by_addr_v6($gi, $addr);
57 }
58 }
59 geoip_close($gi);
60 }
61
62 return strtolower($addr);
63 }
64
65 ?>

Properties

Name Value
svn:keywords Id