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"));
50$action =
GETPOST(
'action',
'aZ09');
53 $conf->global->GEOIP_VERSION =
'2';
61if ($action ==
'set') {
70 $gimcdf =
GETPOST(
"GEOIPMAXMIND_COUNTRY_DATAFILE");
72 if (!preg_match(
'/\.(dat|mmdb)$/', $gimcdf)) {
73 $langs->load(
'errors');
74 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat",
'.dat|.mmdb'),
null,
'errors');
86 $gimcdf =
GETPOST(
"GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED");
87 if ($gimcdf && !preg_match(
'/\.(dat|mmdb)$/', $gimcdf)) {
88 $langs->load(
'errors');
89 setEventMessages($langs->trans(
"ErrorFileMustHaveFormat",
'.dat|.mmdb'),
null,
'errors');
94 $varname =
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED';
95 if (isset($_FILES[$varname]) && $_FILES[$varname][
"name"]) {
98 $dirforterms = $diroffile.
'/';
99 $original_file = $_FILES[$varname][
"name"];
101 $result =
dol_move_uploaded_file($_FILES[$varname][
"tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES[$varname][
'error']);
102 if ((
int) $result > 0) {
106 setEventMessages($langs->trans(
"Error").
' '.$langs->transnoentitiesnoconv((
string) $result),
null,
'errors');
114 setEventMessages($langs->trans(
"SetupSaved"),
null,
'mesgs');
120$documenturl =
getDolGlobalString(
'DOL_URL_ROOT_DOCUMENT_PHP', DOL_URL_ROOT.
'/document.php');
127$form =
new Form($db);
130llxHeader(
'',
'',
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-geoipmaxmind');
132$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>';
134print
load_fiche_titre($langs->trans(
"GeoIPMaxmindSetup"), $linkback,
'title_setup');
143 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
146 $geoip =
new DolGeoIP(
'country', $datafile);
150print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" spellcheck="false">';
151print
'<input type="hidden" name="token" value="'.newToken().
'">';
152print
'<input type="hidden" name="action" value="set">';
154print
'<div class="div-table-responsive-no-min">';
155print
'<table class="noborder centpercent">';
156print
'<tr class="liste_titre">';
157print
'<td>'.$langs->trans(
"Parameter").
'</td><td></td>';
158print
'<td class="right"></td>';
162print
'<tr class="oddeven"><td>'.$langs->trans(
"GeoIPLibVersion").
'</td>';
164$arrayofvalues = array(
'php' =>
'Native PHP functions',
'1' =>
'Embedded GeoIP v1',
'2' =>
'Embedded GeoIP v2');
165print $form->selectarray(
'geoipversion', $arrayofvalues,
getDolGlobalString(
'GEOIP_VERSION',
'2'));
168 $version = $geoip->getVersion();
171 print
'<br>'.$langs->trans(
"Version").
': '.$version;
179print
'<tr class="oddeven"><td>'.$langs->trans(
"PathToGeoIPMaxmindCountryDataFile").
'</td>';
184 if (function_exists(
'geoip_db_filename')) {
185 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>';
187 print
'<input type="text" class="minwidth200" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.dol_escape_htmltag(
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE')).
'">';
188 if (!file_exists(str_replace(
'DOL_DATA_ROOT', DOL_DATA_ROOT, $gimcdf))) {
189 $langs->load(
'errors');
190 print
'<div class="error">'.$langs->trans(
"ErrorFileNotFound", $gimcdf).
'</div>';
193 $modulepart =
'geoipmaxmind';
194 print
'<div class="inline-block nobordernopadding valignmiddle "><div class="inline-block marginrightonly">';
196 $maxmin = $maxfilesizearray[
'maxmin'];
198 print
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
200 print
'<input type="file" class="flat minwidth100 maxwidthinputfileonsmartphone" name="GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED" id="GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED">';
206 $maxphp = @ini_get(
'upload_max_filesize');
207 if (preg_match(
'/k$/i', $maxphp)) {
208 $maxphp = preg_replace(
'/k$/i',
'', $maxphp);
209 $maxphp = (int) $maxphp * 1;
211 if (preg_match(
'/m$/i', $maxphp)) {
212 $maxphp = preg_replace(
'/m$/i',
'', $maxphp);
213 $maxphp = (int) $maxphp * 1024;
215 if (preg_match(
'/g$/i', $maxphp)) {
216 $maxphp = preg_replace(
'/g$/i',
'', $maxphp);
217 $maxphp = (int) $maxphp * 1024 * 1024;
219 if (preg_match(
'/t$/i', $maxphp)) {
220 $maxphp = preg_replace(
'/t$/i',
'', $maxphp);
221 $maxphp = (int) $maxphp * 1024 * 1024 * 1024;
223 $maxphp2 = @ini_get(
'post_max_size');
224 if (preg_match(
'/k$/i', $maxphp2)) {
225 $maxphp2 = preg_replace(
'/k$/i',
'', $maxphp2);
226 $maxphp2 = (int) $maxphp2 * 1;
228 if (preg_match(
'/m$/i', $maxphp2)) {
229 $maxphp2 = preg_replace(
'/m$/i',
'', $maxphp2);
230 $maxphp2 = (int) $maxphp2 * 1024;
232 if (preg_match(
'/g$/i', $maxphp2)) {
233 $maxphp2 = preg_replace(
'/g$/i',
'', $maxphp2);
234 $maxphp2 = (int) $maxphp2 * 1024 * 1024;
236 if (preg_match(
'/t$/i', $maxphp2)) {
237 $maxphp2 = preg_replace(
'/t$/i',
'', $maxphp2);
238 $maxphp2 = (int) $maxphp2 * 1024 * 1024 * 1024;
242 $maxphptoshow = $maxphptoshowparam =
'';
244 $maxmin = min($max, $maxphp);
245 $maxphptoshow = $maxphp;
246 $maxphptoshowparam =
'upload_max_filesize';
249 $maxmin = min($max, $maxphp2);
250 if ($maxphp2 < $maxphp) {
251 $maxphptoshow = $maxphp2;
252 $maxphptoshowparam =
'post_max_size';
256 $langs->load(
'other');
258 $out .=
info_admin($langs->trans(
"ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
260 $out .=
' ('.$langs->trans(
"UploadDisabled").
')';
269 if (file_exists($diroffile.
'/'.$geoipfile)) {
270 $file =
dol_dir_list($diroffile,
'files', 0, $geoipfile);
272 print
'<div class="inline-block valignmiddle marginrightonly"><a href="'.$documenturl.
'?modulepart='.$modulepart.
'&file='.urlencode($geoipfile).
'">'.$geoipfile.
'</a>'.$formfile->showPreview($file[0], $modulepart, $geoipfile, 0,
'');
273 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>';
282 print
'<span class="opacitymedium">';
283 print $langs->trans(
"Example").
'<br>';
284 print
'/usr/local/share/GeoIP/GeoIP.dat<br>
285/usr/share/GeoIP/GeoIP.dat<br>
286/usr/share/GeoIP/GeoLite2-Country.mmdb';
295print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
"Save").
'">';
302print
'<div class="hideonsmartphone info">';
304 print $langs->trans(
"NoteOnPathLocation").
'<br>';
307$url1 =
'http://www.maxmind.com/en/city?rId=awstats';
308$textoshow = $langs->trans(
"YouCanDownloadFreeDatFileTo",
'{s1}');
309$textoshow = str_replace(
'{s1}',
'<a href="'.$url1.
'" target="_blank" rel="noopener noreferrer external">'.$url1.
'</a>', $textoshow);
314$url2 =
'http://www.maxmind.com/en/city?rId=awstats';
315$textoshow = $langs->trans(
"YouCanDownloadAdvancedDatFileTo",
'{s1}');
316$textoshow = str_replace(
'{s1}',
'<a href="'.$url2.
'" target="_blank" rel="noopener noreferrer external">'.$url2.
'</a>', $textoshow);
324 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" spellcheck="false">';
325 print
'<input type="hidden" name="token" value="'.newToken().
'">';
336 print $langs->trans(
"Error");
339 $ip =
'2a01:e0a:7e:4a60:429a:23ff:f7b8:dc8a';
340 print
'<br>'.$ip.
' -> ';
345 print $langs->trans(
"Error");
361 print
'<br>'.$langs->trans(
"CurrentIP").
': '.$ip.
' -> ';
366 print $langs->trans(
"Error");
369 print
'<br>'.($isip == 2 ? $langs->trans(
"CurrentIP").
': ' :
'').$ip.
' -> ';
374 print $langs->trans(
"NotAPublicIp");
379 print
'<br><input type="text class="width100" name="iptotest" id="iptotest" placeholder="'.dol_escape_htmltag($langs->trans(
"EnterAnIP")).
'" value="'.$ip.
'">';
380 print
'<input type="submit" class="width40 button small smallpaddingimp" value=" -> ">';
386 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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....
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
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.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
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.