dolibarr 20.0.2
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 *
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
27require_once '../../main.inc.php';
28
29// Enable and test if module Api is enabled
30if (!isModEnabled('api')) {
31 $langs->load("admin");
32 dol_syslog("Call of Dolibarr API interfaces with module API REST are disabled");
33 print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>';
34 print $langs->trans("ToActivateModule");
35 //session_destroy();
36 exit(0);
37}
38
39// Test if explorer is not disabled
40if (getDolGlobalString('API_EXPLORER_DISABLED')) {
41 $langs->load("admin");
42 dol_syslog("Call Dolibarr API interfaces with module REST disabled");
43 print $langs->trans("WarningAPIExplorerDisabled").'.<br><br>';
44 //session_destroy();
45 exit(0);
46}
47
48// Restrict API to some IPs
49if (getDolGlobalString('API_RESTRICT_ON_IP')) {
50 $allowedip = explode(' ', getDolGlobalString('API_RESTRICT_ON_IP'));
51 $ipremote = getUserRemoteIP();
52 if (!in_array($ipremote, $allowedip)) {
53 dol_syslog('Remote ip is '.$ipremote.', not into list ' . getDolGlobalString('API_RESTRICT_ON_IP'));
54 print 'APIs are not allowed from the IP '.$ipremote;
55 header('HTTP/1.1 503 API not allowed from your IP '.$ipremote);
56 //session_destroy();
57 exit(0);
58 }
59}
60
61?>
62<!DOCTYPE html>
63<html>
64 <head>
65 <title>ReDoc</title>
66 <!-- needed for adaptive design -->
67 <meta charset="utf-8"/>
68 <meta name="viewport" content="width=device-width, initial-scale=1">
69 <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
70
71 <!--
72 ReDoc doesn't change outer page styles
73 -->
74 <style>
75 body {
76 margin: 0;
77 padding: 0;
78 }
79 </style>
80 </head>
81 <body>
82 <redoc spec-url='<?php echo DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.GETPOST('DOLAPIKEY', 'aZ09'); ?>'></redoc>
83 <!--<redoc spec-url='https://demo.dolibarr.org/api/index.php/explorer/swagger.json'></redoc>-->
84 <!--<redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>-->
85 <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
86 </body>
87</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 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:140