explorer_withredoc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  3. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <https://www.gnu.org/licenses/>.
  17. *
  18. * @deprecated Old explorer. Not using Swagger. See instead explorer in htdocs/api/index.php.
  19. */
  20. /**
  21. * \defgroup api Module DolibarrApi
  22. * \brief API explorer using the swagger.json file
  23. * \file htdocs/api/admin/explorer_withredoc.php
  24. */
  25. require_once '../../main.inc.php';
  26. // Enable and test if module Api is enabled
  27. if (empty($conf->global->MAIN_MODULE_API)) {
  28. $langs->load("admin");
  29. dol_syslog("Call of Dolibarr API interfaces with module API REST are disabled");
  30. print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>';
  31. print $langs->trans("ToActivateModule");
  32. //session_destroy();
  33. exit(0);
  34. }
  35. // Test if explorer is not disabled
  36. if (!empty($conf->global->API_EXPLORER_DISABLED)) {
  37. $langs->load("admin");
  38. dol_syslog("Call Dolibarr API interfaces with module REST disabled");
  39. print $langs->trans("WarningAPIExplorerDisabled").'.<br><br>';
  40. //session_destroy();
  41. exit(0);
  42. }
  43. // Restrict API to some IPs
  44. if (!empty($conf->global->API_RESTRICT_ON_IP)) {
  45. $allowedip = explode(' ', $conf->global->API_RESTRICT_ON_IP);
  46. $ipremote = getUserRemoteIP();
  47. if (!in_array($ipremote, $allowedip)) {
  48. dol_syslog('Remote ip is '.$ipremote.', not into list '.$conf->global->API_RESTRICT_ON_IP);
  49. print 'APIs are not allowed from the IP '.$ipremote;
  50. header('HTTP/1.1 503 API not allowed from your IP '.$ipremote);
  51. //session_destroy();
  52. exit(0);
  53. }
  54. }
  55. ?>
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59. <title>ReDoc</title>
  60. <!-- needed for adaptive design -->
  61. <meta charset="utf-8"/>
  62. <meta name="viewport" content="width=device-width, initial-scale=1">
  63. <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
  64. <!--
  65. ReDoc doesn't change outer page styles
  66. -->
  67. <style>
  68. body {
  69. margin: 0;
  70. padding: 0;
  71. }
  72. </style>
  73. </head>
  74. <body>
  75. <redoc spec-url='<?php echo DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.GETPOST('DOLAPIKEY', 'aZ09'); ?>'></redoc>
  76. <!--<redoc spec-url='https://demo.dolibarr.org/api/index.php/explorer/swagger.json'></redoc>-->
  77. <!--<redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>-->
  78. <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
  79. </body>
  80. </html>