dolibarr/htdocs/admin/geoipmaxmind.php

179 lines
4.8 KiB
PHP
Raw Normal View History

2009-10-14 13:04:09 +02:00
<?php
/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.org>
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
2011-09-21 15:24:27 +02:00
*
2009-10-14 13:04:09 +02:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2009-10-14 13:04:09 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-10-14 13:04:09 +02:00
*/
/**
* \file htdocs/admin/geoipmaxmind.php
* \ingroup geoipmaxmind
* \brief Setup page for geoipmaxmind module
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
2018-11-21 15:11:57 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
2009-10-14 13:04:09 +02:00
// Security check
if (!$user->admin)
accessforbidden();
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
2018-04-25 11:50:58 +02:00
$langs->loadLangs(array("admin","errors"));
2009-10-14 13:04:09 +02:00
2017-05-16 13:27:32 +02:00
$action = GETPOST('action','aZ09');
2011-09-06 12:52:42 +02:00
2009-10-14 13:04:09 +02:00
/*
* Actions
*/
2011-09-06 12:52:42 +02:00
if ($action == 'set')
2009-10-14 13:04:09 +02:00
{
$error=0;
2011-09-21 15:24:27 +02:00
$gimcdf= GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
2011-09-06 12:52:42 +02:00
if (! $gimcdf && ! file_exists($gimcdf))
2009-10-14 13:04:09 +02:00
{
2015-10-28 19:28:18 +01:00
setEventMessages($langs->trans("ErrorFileNotFound",$gimcdf), null, 'errors');
2009-10-14 13:04:09 +02:00
$error++;
}
2011-09-21 15:24:27 +02:00
2009-10-14 13:04:09 +02:00
if (! $error)
{
2011-09-06 12:52:42 +02:00
$res = dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$gimcdf,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
2011-09-21 15:24:27 +02:00
2011-09-06 12:52:42 +02:00
if (! $error)
{
2015-10-28 19:28:18 +01:00
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
else
{
2015-10-28 19:28:18 +01:00
setEventMessages($langs->trans("Error"), null, 'errors');
}
2009-10-14 13:04:09 +02:00
}
}
/*
* View
*/
$form=new Form($db);
llxHeader();
2018-02-26 09:20:05 +01:00
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'title_setup');
2009-10-14 13:04:09 +02:00
print '<br>';
$version='';
$geoip='';
if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
{
$geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
2013-07-09 00:19:58 +02:00
//if ($geoip->error) print dol_htmloutput_errors($geoip->errorlabel,'',1);
if ($geoip->gi == 'NOGI') $geointernal=true;
else $geointernal=false;
}
else
{
2013-07-13 10:34:19 +02:00
if (function_exists('geoip_country_code_by_name')) $geointernal=true;
2009-10-14 13:04:09 +02:00
}
// Mode
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
print "</tr>\n";
print '<tr class="oddeven"><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
2009-10-14 13:04:09 +02:00
print '<td colspan="2">';
2013-07-09 00:19:58 +02:00
if ($geointernal) print 'Using geoip PHP internal functions. Value must be '.geoip_db_filename(GEOIP_COUNTRY_EDITION).' or '.geoip_db_filename(GEOIP_CITY_EDITION_REV1).'<br>';
2009-10-14 13:04:09 +02:00
print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
if ($geoip) $version=$geoip->getVersion();
if ($version)
{
print '<br>'.$langs->trans("Version").': '.$version;
}
print '</td></tr>';
print '</table>';
print "</form>\n";
print '<br>';
print $langs->trans("NoteOnPathLocation").'<br>';
2013-07-09 15:27:06 +02:00
$url1='http://www.maxmind.com/en/city?rId=awstats';
2009-10-14 13:04:09 +02:00
print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
print '<br>';
2013-07-09 15:27:06 +02:00
$url2='http://www.maxmind.com/en/city?rId=awstats';
2009-10-14 13:04:09 +02:00
print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
if ($geoip)
{
print '<br><br>';
print '<br>'.$langs->trans("TestGeoIPResult",$ip).':';
2009-10-14 13:04:09 +02:00
$ip='24.24.24.24';
print '<br>'.$ip.' -> ';
2009-10-14 13:04:09 +02:00
$result=dol_print_ip($ip,1);
if ($result) print $result;
else print $langs->trans("Error");
/* We disable this test because dol_print_ip need an ip as input
$ip='www.google.com';
print '<br>'.$ip.' -> ';
$result=dol_print_ip($ip,1);
if ($result) print $result;
else print $langs->trans("Error");
*/
2018-11-21 15:11:57 +01:00
//var_dump($_SERVER);
$ip = getUserRemoteIP();
2018-11-21 15:11:57 +01:00
//$ip='91.161.249.43';
$isip=is_ip($ip);
if ($isip == 1)
{
print '<br>'.$ip.' -> ';
$result=dol_print_ip($ip,1);
if ($result) print $result;
else print $langs->trans("Error");
}
else
2018-11-21 15:11:57 +01:00
{
print '<br>'.$ip.' -> ';
$result=dol_print_ip($ip,1);
if ($result) print $result;
else print $langs->trans("NotAPublicIp");
}
2009-10-14 13:04:09 +02:00
$geoip->close();
}
llxFooter();
$db->close();