61 $datfile = str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $datfile);
69 if ($type ==
'country') {
71 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
72 if (function_exists(
'stream_wrapper_restore')) {
73 stream_wrapper_restore(
'phar');
75 include_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
77 } elseif ($type ==
'city') {
79 if ($geoipversion ==
'2' || ($geoipversion !=
'php' && !function_exists(
'geoip_country_code_by_name'))) {
80 if (function_exists(
'stream_wrapper_restore')) {
81 stream_wrapper_restore(
'phar');
83 include_once DOL_DOCUMENT_ROOT.
'/includes/geoip2/geoip2.phar';
86 print
'ErrorBadParameterInConstructor';
90 $this->error = $e->getMessage();
91 $this->errorlabel =
'Exception '.$this->error;
92 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
97 if (empty($type) || empty($datfile)) {
98 $this->errorlabel =
'Constructor was called with no datafile parameter';
99 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
102 if (!file_exists($datfile) || !is_readable($datfile)) {
103 $this->error =
'ErrorGeoIPClassNotInitialized';
104 $this->errorlabel =
"Datafile ".$datfile.
" not found";
105 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
109 if ($geoipversion ==
'2') {
112 $this->gi =
new GeoIp2\Database\Reader($datfile);
114 $this->error = $e->getMessage();
115 dol_syslog(
'DolGeoIP '.$this->errorlabel, LOG_ERR);
118 } elseif (function_exists(
'geoip_open') && defined(
'GEOIP_STANDARD')) {
119 $this->gi = geoip_open($datfile, constant(
'GEOIP_STANDARD'));
120 } elseif (function_exists(
'geoip_country_code_by_name')) {
142 if (is_object($this->gi) && method_exists($this->gi,
'metadata')) {
144 $databasetype = (
string) $this->gi->metadata()->databaseType;
146 if (strpos($databasetype,
'Country') ===
false && strpos($databasetype,
'City') !==
false) {
147 $record = $this->gi->city($ipOrName);
149 $record = $this->gi->country($ipOrName);
151 return (
string) $record->country->isoCode;
171 if (empty($this->gi)) {
174 if ($this->gi ==
'NOGI') {
176 return strtolower(geoip_country_code_by_name($ip));
178 if (preg_match(
'/^[0-9]+.[0-9]+\.[0-9]+\.[0-9]+/', $ip)) {
179 if ($geoipversion ==
'2') {
182 if (!function_exists(
'geoip_country_code_by_addr')) {
183 return strtolower(geoip_country_code_by_name($ip));
185 return strtolower(geoip_country_code_by_addr($this->gi, $ip));
188 if ($geoipversion ==
'2') {
191 if (function_exists(
'geoip_country_code_by_addr_v6')) {
192 return strtolower(geoip_country_code_by_addr_v6($this->gi, $ip));
193 } elseif (function_exists(
'geoip_country_code_by_name_v6')) {
194 return strtolower(geoip_country_code_by_name_v6($this->gi, $ip));
215 if (empty($this->gi)) {
219 if ($geoipversion ==
'2') {
222 return strtolower(geoip_country_code_by_name($name));
238 if ($geoipversion ==
'php') {
239 if ($this->gi ==
'NOGI') {
240 return geoip_database_info();
242 return 'geoip_database_info() function not available';
246 return 'Not available (not using PHP internal geo functions - We are using embedded Geoip v'.$geoipversion.
')';
256 if (function_exists(
'geoip_close')) {
258 geoip_close($this->gi);
Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeF...
getCountryCodeFromIP($ip)
Return in lower case the country code from an ip.
__construct($type, $datfile)
Constructor.
getVersion()
Return version of data file.
getGeoIp2IsoCode($ipOrName)
Return the ISO country code for an IP or a host name using the embedded GeoIP2 reader.
close()
Close geoip object.
getCountryCodeFromName($name)
Return in lower case the country code from a host name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php