28require
'../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
48$langs->loadLangs(array(
"admin",
"errors"));
50$action =
GETPOST(
'action',
'aZ09');
52if (!isset($conf->global->GEOIP_VERSION)) {
53 $conf->global->GEOIP_VERSION =
'2';
61if ($action ==
'set') {
70 $gimcdf =
GETPOST(
"GEOIPMAXMIND_COUNTRY_DATAFILE");
72 if (!preg_match(
'/\.(dat|mmdb)$/', $gimcdf)) {
73 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat",
'.dat|.mmdb'),
null,
'errors');
78 $res2 =
dolibarr_set_const($db,
"GEOIPMAXMIND_COUNTRY_DATAFILE", $gimcdf,
'chaine', 0,
'', $conf->entity);
85 $gimcdf =
GETPOST(
"GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED");
86 if ($gimcdf && !preg_match(
'/\.(dat|mmdb)$/', $gimcdf)) {
87 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat",
'.dat|.mmdb'),
null,
'errors');
92 $varname =
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED';
93 if (isset($_FILES[$varname]) && $_FILES[$varname][
"name"]) {
96 $dirforterms = $diroffile.
'/';
97 $original_file = $_FILES[$varname][
"name"];
99 $result =
dol_move_uploaded_file($_FILES[$varname][
"tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES[$varname][
'error']);
100 if ((
int) $result > 0) {
104 setEventMessages($langs->trans(
"Error").
' '.$langs->transnoentitiesnoconv((
string) $result),
null,
'errors');
118$documenturl =
getDolGlobalString(
'DOL_URL_ROOT_DOCUMENT_PHP', DOL_URL_ROOT.
'/document.php');
125$form =
new Form($db);
128llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-geoipmaxmind');
130$linkback =
'<a href="'.dolBuildUrl(DOL_URL_ROOT.
'/admin/modules.php', [
'restore_lastsearch_values' => 1]).
'">'.
img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
132print
load_fiche_titre($langs->trans(
"GeoIPMaxmindSetup"), $linkback,
'title_setup');
141 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
144 $geoip =
new DolGeoIP(
'country', $datafile);
148print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post">';
149print
'<input type="hidden" name="token" value="'.newToken().
'">';
150print
'<input type="hidden" name="action" value="set">';
152print
'<div class="div-table-responsive-no-min">';
153print
'<table class="noborder centpercent">';
154print
'<tr class="liste_titre">';
155print
'<td>'.$langs->trans(
"Parameter").
'</td><td></td>';
156print
'<td class="right"></td>';
160print
'<tr class="oddeven"><td>'.$langs->trans(
"GeoIPLibVersion").
'</td>';
162$arrayofvalues = array(
'php' =>
'Native PHP functions',
'1' =>
'Embedded GeoIP v1',
'2' =>
'Embedded GeoIP v2');
163print $form->selectarray(
'geoipversion', $arrayofvalues,
getDolGlobalString(
'GEOIP_VERSION',
'2'));
166 $version = $geoip->getVersion();
169 print
'<br>'.$langs->trans(
"Version").
': '.$version;
177print
'<tr class="oddeven"><td>'.$langs->trans(
"PathToGeoIPMaxmindCountryDataFile").
'</td>';
182 if (function_exists(
'geoip_db_filename')) {
183 print
'Using geoip PHP internal functions. Value must be '.geoip_db_filename(GEOIP_COUNTRY_EDITION).
' or '.geoip_db_filename(GEOIP_CITY_EDITION_REV1).
' or /pathtodatafile/GeoLite2-Country.mmdb<br>';
185 print
'<input type="text" class="minwidth200" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.dol_escape_htmltag(
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE')).
'">';
186 if (!file_exists(str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $gimcdf))) {
187 print
'<div class="error">'.$langs->trans(
"ErrorFileNotFound", $gimcdf).
'</div>';
190 $modulepart =
'geoipmaxmind';
191 print
'<div class="inline-block nobordernopadding valignmiddle "><div class="inline-block marginrightonly">';
193 $maxmin = $maxfilesizearray[
'maxmin'];
195 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
197 print
'<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED" id="GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED">';
203 $maxphp = @ini_get(
'upload_max_filesize');
204 if (preg_match(
'/k$/i', $maxphp)) {
205 $maxphp = preg_replace(
'/k$/i',
'', $maxphp);
206 $maxphp = (int) $maxphp * 1;
208 if (preg_match(
'/m$/i', $maxphp)) {
209 $maxphp = preg_replace(
'/m$/i',
'', $maxphp);
210 $maxphp = (int) $maxphp * 1024;
212 if (preg_match(
'/g$/i', $maxphp)) {
213 $maxphp = preg_replace(
'/g$/i',
'', $maxphp);
214 $maxphp = (int) $maxphp * 1024 * 1024;
216 if (preg_match(
'/t$/i', $maxphp)) {
217 $maxphp = preg_replace(
'/t$/i',
'', $maxphp);
218 $maxphp = (int) $maxphp * 1024 * 1024 * 1024;
220 $maxphp2 = @ini_get(
'post_max_size');
221 if (preg_match(
'/k$/i', $maxphp2)) {
222 $maxphp2 = preg_replace(
'/k$/i',
'', $maxphp2);
223 $maxphp2 = (int) $maxphp2 * 1;
225 if (preg_match(
'/m$/i', $maxphp2)) {
226 $maxphp2 = preg_replace(
'/m$/i',
'', $maxphp2);
227 $maxphp2 = (int) $maxphp2 * 1024;
229 if (preg_match(
'/g$/i', $maxphp2)) {
230 $maxphp2 = preg_replace(
'/g$/i',
'', $maxphp2);
231 $maxphp2 = (int) $maxphp2 * 1024 * 1024;
233 if (preg_match(
'/t$/i', $maxphp2)) {
234 $maxphp2 = preg_replace(
'/t$/i',
'', $maxphp2);
235 $maxphp2 = (int) $maxphp2 * 1024 * 1024 * 1024;
239 $maxphptoshow = $maxphptoshowparam =
'';
241 $maxmin = min($max, $maxphp);
242 $maxphptoshow = $maxphp;
243 $maxphptoshowparam =
'upload_max_filesize';
246 $maxmin = min($max, $maxphp2);
247 if ($maxphp2 < $maxphp) {
248 $maxphptoshow = $maxphp2;
249 $maxphptoshowparam =
'post_max_size';
253 $langs->load(
'other');
255 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
257 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
266 if (file_exists($diroffile.
'/'.$geoipfile)) {
267 $file =
dol_dir_list($diroffile,
'files', 0, $geoipfile);
269 print
'<div class="inline-block valignmiddle marginrightonly"><a href="'.$documenturl.
'?modulepart='.$modulepart.
'&file='.urlencode($geoipfile).
'">'.$geoipfile.
'</a>'.$formfile->showPreview($file[0], $modulepart, $geoipfile, 0,
'');
270 print
'<div class="inline-block valignmiddle marginrightonly"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?action=removetermsofsale&modulepart='.$modulepart.
'&token='.
newToken().
'">'.
img_delete($langs->trans(
"Delete"),
'',
'marginleftonly').
'</a></div>';
279 print
'<span class="opacitymedium">';
280 print $langs->trans(
"Example").
'<br>';
281 print
'/usr/local/share/GeoIP/GeoIP.dat<br>
282/usr/share/GeoIP/GeoIP.dat<br>
283/usr/share/GeoIP/GeoLite2-Country.mmdb';
292print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
"Save").
'">';
299print
'<div class="hideonsmartphone info">';
301 print $langs->trans(
"NoteOnPathLocation").
'<br>';
304$url1 =
'http://www.maxmind.com/en/city?rId=awstats';
305$textoshow = $langs->trans(
"YouCanDownloadFreeDatFileTo",
'{s1}');
306$textoshow = str_replace(
'{s1}',
'<a href="'.$url1.
'" target="_blank" rel="noopener noreferrer external">'.$url1.
'</a>', $textoshow);
311$url2 =
'http://www.maxmind.com/en/city?rId=awstats';
312$textoshow = $langs->trans(
"YouCanDownloadAdvancedDatFileTo",
'{s1}');
313$textoshow = str_replace(
'{s1}',
'<a href="'.$url2.
'" target="_blank" rel="noopener noreferrer external">'.$url2.
'</a>', $textoshow);
321 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
322 print
'<input type="hidden" name="token" value="'.newToken().
'">';
333 print $langs->trans(
"Error");
336 $ip =
'2a01:e0a:7e:4a60:429a:23ff:f7b8:dc8a';
337 print
'<br>'.$ip.
' -> ';
342 print $langs->trans(
"Error");
358 print
'<br>'.$langs->trans(
"CurrentIP").
': '.$ip.
' -> ';
363 print $langs->trans(
"Error");
366 print
'<br>'.($isip == 2 ? $langs->trans(
"CurrentIP").
': ' :
'').$ip.
' -> ';
371 print $langs->trans(
"NotAPublicIp");
376 print
'<br><input type="text class="width100" name="iptotest" id="iptotest" placeholder="'.dol_escape_htmltag($langs->trans(
"EnterAnIP")).
'" value="'.$ip.
'">';
377 print
'<input type="submit" class="width40 button small smallpaddingimp" value=" -> ">';
383 print $langs->trans(
"Error");
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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeF...
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254....
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.