geoipmaxmind.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /**
  19. * \file htdocs/admin/geoipmaxmind.php
  20. * \ingroup geoipmaxmind
  21. * \brief Setup page for geoipmaxmind module
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
  26. // Security check
  27. if (!$user->admin)
  28. accessforbidden();
  29. $langs->load("admin");
  30. $langs->load("errors");
  31. $action = GETPOST('action','aZ09');
  32. /*
  33. * Actions
  34. */
  35. if ($action == 'set')
  36. {
  37. $error=0;
  38. $gimcdf= GETPOST("GEOIPMAXMIND_COUNTRY_DATAFILE");
  39. if (! $gimcdf && ! file_exists($gimcdf))
  40. {
  41. setEventMessages($langs->trans("ErrorFileNotFound",$gimcdf), null, 'errors');
  42. $error++;
  43. }
  44. if (! $error)
  45. {
  46. $res = dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$gimcdf,'chaine',0,'',$conf->entity);
  47. if (! $res > 0) $error++;
  48. if (! $error)
  49. {
  50. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  51. }
  52. else
  53. {
  54. setEventMessages($langs->trans("Error"), null, 'errors');
  55. }
  56. }
  57. }
  58. /*
  59. * View
  60. */
  61. $form=new Form($db);
  62. llxHeader();
  63. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  64. print load_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'title_setup');
  65. print '<br>';
  66. $version='';
  67. $geoip='';
  68. if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
  69. {
  70. $geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
  71. //if ($geoip->error) print dol_htmloutput_errors($geoip->errorlabel,'',1);
  72. if ($geoip->gi == 'NOGI') $geointernal=true;
  73. else $geointernal=false;
  74. }
  75. else
  76. {
  77. if (function_exists('geoip_country_code_by_name')) $geointernal=true;
  78. }
  79. // Mode
  80. $var=true;
  81. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  82. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  83. print '<input type="hidden" name="action" value="set">';
  84. print '<table class="noborder" width="100%">';
  85. print '<tr class="liste_titre">';
  86. print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
  87. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  88. print "</tr>\n";
  89. print '<tr class="oddeven"><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
  90. print '<td colspan="2">';
  91. 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>';
  92. print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
  93. if ($geoip) $version=$geoip->getVersion();
  94. if ($version)
  95. {
  96. print '<br>'.$langs->trans("Version").': '.$version;
  97. }
  98. print '</td></tr>';
  99. print '</table>';
  100. print "</form>\n";
  101. print '<br>';
  102. print $langs->trans("NoteOnPathLocation").'<br>';
  103. $url1='http://www.maxmind.com/en/city?rId=awstats';
  104. print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
  105. print '<br>';
  106. $url2='http://www.maxmind.com/en/city?rId=awstats';
  107. print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
  108. if ($geoip)
  109. {
  110. print '<br><br>';
  111. print '<br>'.$langs->trans("TestGeoIPResult",$ip).':';
  112. $ip='24.24.24.24';
  113. print '<br>'.$ip.' -> ';
  114. $result=dol_print_ip($ip,1);
  115. if ($result) print $result;
  116. else print $langs->trans("Error");
  117. /* We disable this test because dol_print_ip need an ip as input
  118. $ip='www.google.com';
  119. print '<br>'.$ip.' -> ';
  120. $result=dol_print_ip($ip,1);
  121. if ($result) print $result;
  122. else print $langs->trans("Error");
  123. */
  124. $geoip->close();
  125. }
  126. llxFooter();
  127. $db->close();