geoipmaxmind.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/geoipmaxmind.php
  19. * \ingroup geoipmaxmind
  20. * \brief Setup page for geoipmaxmind module
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  24. require_once(DOL_DOCUMENT_ROOT."/lib/dolgeoip.class.php");
  25. // Security check
  26. if (!$user->admin)
  27. accessforbidden();
  28. $langs->load("admin");
  29. $langs->load("errors");
  30. /*
  31. * Actions
  32. */
  33. if ($_POST["action"] == 'set')
  34. {
  35. $error=0;
  36. if (! empty($_POST["GEOIPMAXMIND_COUNTRY_DATAFILE"]) && ! file_exists($_POST["GEOIPMAXMIND_COUNTRY_DATAFILE"]))
  37. {
  38. $mesg='<div class="error">'.$langs->trans("ErrorFileNotFound",$_POST["GEOIPMAXMIND_COUNTRY_DATAFILE"]).'</div>';
  39. $error++;
  40. }
  41. if (! $error)
  42. {
  43. dolibarr_set_const($db,"GEOIPMAXMIND_COUNTRY_DATAFILE",$_POST["GEOIPMAXMIND_COUNTRY_DATAFILE"],'chaine',0,'',$conf->entity);
  44. }
  45. }
  46. /*
  47. * View
  48. */
  49. $form=new Form($db);
  50. llxHeader();
  51. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  52. print_fiche_titre($langs->trans("GeoIPMaxmindSetup"),$linkback,'setup');
  53. print '<br>';
  54. if ($mesg) print $mesg;
  55. $version='';
  56. $geoip='';
  57. if (! empty($conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE))
  58. {
  59. $geoip=new DolGeoIP('country',$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE);
  60. }
  61. // Mode
  62. $var=true;
  63. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  64. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  65. print '<input type="hidden" name="action" value="set">';
  66. print '<table class="noborder" width="100%">';
  67. print '<tr class="liste_titre">';
  68. print '<td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td>';
  69. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  70. print "</tr>\n";
  71. $var=!$var;
  72. print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("PathToGeoIPMaxmindCountryDataFile").'</td>';
  73. print '<td colspan="2">';
  74. print '<input size="50" type="text" name="GEOIPMAXMIND_COUNTRY_DATAFILE" value="'.$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE.'">';
  75. if ($geoip) $version=$geoip->getVersion();
  76. if ($version)
  77. {
  78. print '<br>'.$langs->trans("Version").': '.$version;
  79. }
  80. print '</td></tr>';
  81. print '</table>';
  82. print "</form>\n";
  83. print '<br>';
  84. print $langs->trans("NoteOnPathLocation").'<br>';
  85. $url1='http://www.maxmind.com/app/perl?rId=awstats';
  86. print $langs->trans("YouCanDownloadFreeDatFileTo",'<a href="'.$url1.'" target="_blank">'.$url1.'</a>');
  87. print '<br>';
  88. $url2='http://www.maxmind.com/app/perl?rId=awstats';
  89. print $langs->trans("YouCanDownloadAdvancedDatFileTo",'<a href="'.$url2.'" target="_blank">'.$url2.'</a>');
  90. if ($geoip)
  91. {
  92. print '<br><br>';
  93. print '<br>';
  94. $ip='24.24.24.24';
  95. print $langs->trans("TestGeoIPResult",$ip).':<br>';
  96. print $ip.' -> ';
  97. $result=dol_print_ip($ip,1);
  98. if ($result) print $result;
  99. else print $langs->trans("Error");
  100. $geoip->close();
  101. }
  102. llxFooter();
  103. ?>