dolibarr 21.0.0-beta
explorer_withredoc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
28require_once '../../main.inc.php';
29
38// Enable and test if module Api is enabled
39if (!isModEnabled('api')) {
40 $langs->load("admin");
41 dol_syslog("Call of Dolibarr API interfaces with module API REST are disabled");
42 print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>';
43 print $langs->trans("ToActivateModule");
44 //session_destroy();
45 exit(0);
46}
47
48// Test if explorer is not disabled
49if (getDolGlobalString('API_EXPLORER_DISABLED')) {
50 $langs->load("admin");
51 dol_syslog("Call Dolibarr API interfaces with module REST disabled");
52 print $langs->trans("WarningAPIExplorerDisabled").'.<br><br>';
53 //session_destroy();
54 exit(0);
55}
56
57// Restrict API to some IPs
58if (getDolGlobalString('API_RESTRICT_ON_IP')) {
59 $allowedip = explode(' ', getDolGlobalString('API_RESTRICT_ON_IP'));
60 $ipremote = getUserRemoteIP();
61 if (!in_array($ipremote, $allowedip)) {
62 dol_syslog('Remote ip is '.$ipremote.', not into list ' . getDolGlobalString('API_RESTRICT_ON_IP'));
63 print 'APIs are not allowed from the IP '.$ipremote;
64 header('HTTP/1.1 503 API not allowed from your IP '.$ipremote);
65 //session_destroy();
66 exit(0);
67 }
68}
69
70?>
71<!DOCTYPE html>
72<html>
73 <head>
74 <title>ReDoc</title>
75 <!-- needed for adaptive design -->
76 <meta charset="utf-8"/>
77 <meta name="viewport" content="width=device-width, initial-scale=1">
78 <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
79
80 <!--
81 ReDoc doesn't change outer page styles
82 -->
83 <style>
84 body {
85 margin: 0;
86 padding: 0;
87 }
88 </style>
89 </head>
90 <body>
91 <redoc spec-url='<?php echo DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.GETPOST('DOLAPIKEY', 'aZ09'); ?>'></redoc>
92 <!--<redoc spec-url='https://demo.dolibarr.org/api/index.php/explorer/swagger.json'></redoc>-->
93 <!--<redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>-->
94 <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
95 </body>
96</html>
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152