dolibarr 21.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.org>
4 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2012-2018 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34
46// Load translation files required by the page
47$langs->load("admin");
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54
55// Activate Production mode
56if ($action == 'setproductionmode') {
57 $status = GETPOST('status', 'alpha');
58
59 if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) {
60 $error = 0;
61
62 if ($status == 1) {
63 $result = dol_mkdir($conf->api->dir_temp);
64 if ($result < 0) {
65 setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
66 $error++;
67 }
68 } else {
69 // Delete the cache file otherwise it does not update
70 $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
71 if ($result < 0) {
72 setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
73 $error++;
74 }
75 }
76
77 if (!$error) {
78 header("Location: ".$_SERVER["PHP_SELF"]);
79 exit;
80 }
81 } else {
82 dol_print_error($db);
83 }
84}
85
86// Disable compression mode
87if ($action == 'setdisablecompression') {
88 $status = GETPOST('status', 'alpha');
89
90 if (dolibarr_set_const($db, 'API_DISABLE_COMPRESSION', $status, 'chaine', 0, '', 0) > 0) {
91 header("Location: ".$_SERVER["PHP_SELF"]);
92 exit;
93 } else {
94 dol_print_error($db);
95 }
96}
97
98if ($action == 'save') {
99 dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha'));
100}
101
102
103dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
104
105
106/*
107 * View
108 */
109
110llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-api page-admin-index');
111
112$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
113print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
114
115print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
116print "<br>\n";
117
118print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
119print '<input type="hidden" name="token" value="'.newToken().'">';
120print '<input type="hidden" name="action" value="save">';
121
122print '<table class="noborder centpercent">';
123
124print '<tr class="liste_titre">';
125print "<td>".$langs->trans("Parameter")."</td>";
126print '<td>'.$langs->trans("Value")."</td>";
127print "<td>&nbsp;</td>";
128print "</tr>";
129
130print '<tr class="oddeven">';
131print '<td>'.$langs->trans("ApiProductionMode").'</td>';
132$production_mode = getDolGlobalBool('API_PRODUCTION_MODE');
133if ($production_mode) {
134 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=0">';
135 print img_picto($langs->trans("Activated"), 'switch_on');
136 print '</a></td>';
137} else {
138 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=1">';
139 print img_picto($langs->trans("Disabled"), 'switch_off');
140 print '</a></td>';
141}
142print '<td>&nbsp;</td>';
143print '</tr>';
144
145print '<tr class="oddeven">';
146print '<td>'.$langs->trans("API_DISABLE_COMPRESSION").'</td>';
147$disable_compression = getDolGlobalBool('API_DISABLE_COMPRESSION');
148if ($disable_compression) {
149 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=0">';
150 print img_picto($langs->trans("Activated"), 'switch_on');
151 print '</a></td>';
152} else {
153 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=1">';
154 print img_picto($langs->trans("Disabled"), 'switch_off');
155 print '</a></td>';
156}
157print '<td>&nbsp;</td>';
158print '</tr>';
159
160print '<tr class="oddeven">';
161print '<td>'.$form->textwithpicto($langs->trans("RESTRICT_ON_IP"), $langs->trans("Example").': '.$langs->trans("IPListExample"));
162print '</td>';
163print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag(getDolGlobalString('API_RESTRICT_ON_IP')).'"></td>';
164print '<td>';
165print '<input type="submit" class="button button-save smallpaddingimp" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
166print '</td>';
167print '</tr>';
168
169print '</table>';
170print '<br><br>';
171
172print '</form>';
173
174
175// Define $urlwithroot
176$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
177$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
178//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
179
180// Show message
181$message = '';
182//$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
183$url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]';
184$message .= '<span class="opacitymedium">'.$langs->trans("UrlToGetKeyToUseAPIs").':</span><br>';
185$message .= '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogettoken" value="'.$url.'"></div>';
186print $message;
187print ajax_autoselect("urltogettoken");
188print '<br>';
189print '<br>';
190
191// Explorer
192print '<span class="opacitymedium">'.$langs->trans("ApiExporerIs").':</span><br>';
193if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) {
194 $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
195 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a></div><br>\n";
196
197 print '<div class="opacitymediumxxx"><br><span class="opacitymedium">'.$langs->trans("SwaggerDescriptionFile").':</span><br>';
198 $urlswagger = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY=youruserapikey';
199 //$urlswaggerreal = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.$user->api_key;
200 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogetapidesc" value="'.$urlswagger.'"></div>';
201 print '</div>';
202 print ajax_autoselect("urltogetapidesc");
203} else {
204 $langs->load("errors");
205 print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error');
206}
207
208llxFooter();
209$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
llxFooter()
Footer empty.
Definition document.php:107
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_dir($folder)
Test if filename is a directory.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.