dolibarr  9.0.0
geoipmaxmind.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.org>
3  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
29 
30 // Security check
31 if (!$user->admin)
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("admin","errors"));
36 
37 $action = GETPOST('action','aZ09');
38 
39 /*
40  * Actions
41  */
42 if ($action == 'set')
43 {
44  $error=0;
45 
46  $gimcdf= GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
47 
48  if (! $gimcdf && ! file_exists($gimcdf))
49  {
50  setEventMessages($langs->trans("ErrorFileNotFound",$gimcdf), null, 'errors');
51  $error++;
52  }
53 
54  if (! $error)
55  {
56  $res = dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$gimcdf,'chaine',0,'',$conf->entity);
57  if (! $res > 0) $error++;
58 
59  if (! $error)
60  {
61  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
62  }
63  else
64  {
65  setEventMessages($langs->trans("Error"), null, 'errors');
66  }
67  }
68 }
69 
70 
71 /*
72  * View
73  */
74 
75 $form=new Form($db);
76 
77 llxHeader();
78 
79 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
80 print load_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'title_setup');
81 print '<br>';
82 
83 $version='';
84 $geoip='';
85 if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
86 {
87  $geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
88  //if ($geoip->error) print dol_htmloutput_errors($geoip->errorlabel,'',1);
89  if ($geoip->gi == 'NOGI') $geointernal=true;
90  else $geointernal=false;
91 }
92 else
93 {
94  if (function_exists('geoip_country_code_by_name')) $geointernal=true;
95 }
96 
97 // Mode
98 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
99 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
100 print '<input type="hidden" name="action" value="set">';
101 
102 print '<table class="noborder" width="100%">';
103 print '<tr class="liste_titre">';
104 print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
105 print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
106 print "</tr>\n";
107 
108 print '<tr class="oddeven"><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
109 print '<td colspan="2">';
110 
111 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>';
112 print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
113 if ($geoip) $version=$geoip->getVersion();
114 if ($version)
115 {
116  print '<br>'.$langs->trans("Version").': '.$version;
117 }
118 print '</td></tr>';
119 
120 print '</table>';
121 
122 print "</form>\n";
123 
124 print '<br>';
125 
126 print $langs->trans("NoteOnPathLocation").'<br>';
127 
128 $url1='http://www.maxmind.com/en/city?rId=awstats';
129 print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
130 
131 print '<br>';
132 
133 $url2='http://www.maxmind.com/en/city?rId=awstats';
134 print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
135 
136 if ($geoip)
137 {
138  print '<br><br>';
139  print '<br>'.$langs->trans("TestGeoIPResult",$ip).':';
140 
141  $ip='24.24.24.24';
142  print '<br>'.$ip.' -> ';
143  $result=dol_print_ip($ip,1);
144  if ($result) print $result;
145  else print $langs->trans("Error");
146 
147  /* We disable this test because dol_print_ip need an ip as input
148  $ip='www.google.com';
149  print '<br>'.$ip.' -> ';
150  $result=dol_print_ip($ip,1);
151  if ($result) print $result;
152  else print $langs->trans("Error");
153  */
154  //var_dump($_SERVER);
155  $ip = getUserRemoteIP();
156  //$ip='91.161.249.43';
157  $isip=is_ip($ip);
158  if ($isip == 1)
159  {
160  print '<br>'.$ip.' -> ';
161  $result=dol_print_ip($ip,1);
162  if ($result) print $result;
163  else print $langs->trans("Error");
164  }
165  else
166  {
167  print '<br>'.$ip.' -> ';
168  $result=dol_print_ip($ip,1);
169  if ($result) print $result;
170  else print $langs->trans("NotAPublicIp");
171  }
172 
173  $geoip->close();
174 }
175 
176 // End of page
177 llxFooter();
178 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
getUserRemoteIP()
Return the IP of remote user.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Empty header.
Definition: wrapper.php:44
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25).
Classe to manage GeoIP Usage: $geoip=new GeoIP(&#39;country&#39;,$datfile); $geoip->getCountryCodeFromIP($ip)...