dolibarr 25.0.0-alpha
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-2025 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';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/api.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
48
49// Load translation files required by the page
50$langs->load("admin");
51
52if (!$user->admin) {
54}
55
56$action = GETPOST('action', 'aZ09');
57
58// Activate Production mode
59if ($action == 'setproductionmode') {
60 $status = GETPOST('status', 'alpha');
61
62 if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) {
63 $error = 0;
64
65 if ($status == 1) {
66 $result = dol_mkdir($conf->api->dir_temp);
67 if ($result < 0) {
68 setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
69 $error++;
70 }
71 } else {
72 // Delete the cache file otherwise it does not update
73 $result = dol_delete_file($conf->api->dir_temp.'/routes.php', 1);
74 if ($result < 0) {
75 setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
76 $error++;
77 }
78 }
79
80 if (!$error) {
81 header("Location: ".$_SERVER["PHP_SELF"]);
82 exit;
83 }
84 } else {
86 }
87}
88
89// Disable compression mode
90if ($action == 'setdisablecompression') {
91 if (dolibarr_set_const($db, 'API_DISABLE_COMPRESSION', GETPOSTINT('status'), 'chaine', 0, '', 0) <= 0) {
93 }
94}
95
96// Disable compression mode
97if ($action == 'setenablecount' && !empty($dolibarr_api_count_always_enabled)) {
98 if (dolibarr_set_const($db, 'API_ENABLE_COUNT_CALLS', GETPOSTINT('status'), 'chaine', 0, '', 0) <= 0) {
100 }
101}
102
103if ($action == 'save') {
104 if (dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha')) <= 0) {
106 }
107}
108
109
110dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
111
112
113/*
114 * View
115 */
116
117llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-api page-admin-index');
118
119$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
120
121print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
122
123$head = api_admin_prepare_head();
124
125print dol_get_fiche_head($head, 'parameter', '', -1);
126
127print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
128print "<br>\n";
129
130print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
131print '<input type="hidden" name="token" value="'.newToken().'">';
132print '<input type="hidden" name="action" value="save">';
133
134print '<table class="noborder centpercent">';
135
136print '<tr class="liste_titre">';
137print "<td>".$langs->trans("Parameter")."</td>";
138print '<td></td>';
139print "<td>&nbsp;</td>";
140print "</tr>";
141
142print '<tr class="oddeven">';
143print '<td>'.$langs->trans("ApiProductionMode").'</td>';
144$production_mode = getDolGlobalBool('API_PRODUCTION_MODE');
145if ($production_mode) {
146 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=0">';
147 print img_picto($langs->trans("Activated"), 'switch_on');
148 print '</a></td>';
149} else {
150 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=1">';
151 print img_picto($langs->trans("Disabled"), 'switch_off');
152 print '</a></td>';
153}
154print '<td>&nbsp;</td>';
155print '</tr>';
156
157print '<tr class="oddeven">';
158print '<td>'.$langs->trans("API_DISABLE_COMPRESSION").'</td>';
159$disable_compression = getDolGlobalBool('API_DISABLE_COMPRESSION');
160if ($disable_compression) {
161 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=0">';
162 print img_picto($langs->trans("Activated"), 'switch_on');
163 print '</a></td>';
164} else {
165 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=1">';
166 print img_picto($langs->trans("Disabled"), 'switch_off');
167 print '</a></td>';
168}
169print '<td>&nbsp;</td>';
170print '</tr>';
171
172print '<tr class="oddeven">';
173print '<td>'.$langs->trans("API_ENABLE_COUNT_CALLS").'</td>';
174$enable_count = getDolGlobalBool('API_ENABLE_COUNT_CALLS');
175if (!empty($dolibarr_api_count_always_enabled)) {
176 print '<td>';
177 print img_picto($langs->trans("AlwaysEnabled"), 'switch_on', 'class="opacitymedium"');
178 print '</td>';
179} else {
180 if ($enable_count) {
181 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenablecount&token='.newToken().'&status=0">';
182 print img_picto($langs->trans("Activated"), 'switch_on');
183 print '</a></td>';
184 } else {
185 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenablecount&token='.newToken().'&status=1">';
186 print img_picto($langs->trans("Disabled"), 'switch_off');
187 print '</a></td>';
188 }
189}
190print '<td>&nbsp;</td>';
191print '</tr>';
192
193print '<tr class="oddeven">';
194print '<td>'.$form->textwithpicto($langs->trans("RESTRICT_ON_IP"), $langs->trans("RESTRICT_ON_IPHelp").'<br>'.$langs->trans("Example").': '.$langs->trans("IPListExample"));
195print '</td>';
196print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag(getDolGlobalString('API_RESTRICT_ON_IP')).'" spellcheck="false"></td>';
197print '<td>';
198print '<input type="submit" class="button button-save smallpaddingimp" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
199print '</td>';
200print '</tr>';
201
202print '</table>';
203print '<br><br>';
204
205print '</form>';
206
207
208// Define $urlwithroot
209$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
210$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
211//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
212
213// Show message
214$message = '';
215//$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
216$url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]';
217$message .= '<span class="opacitymedium">'.$langs->trans("UrlToGetKeyToUseAPIs").':</span><br>';
218$message .= '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogettoken" value="'.$url.'" spellcheck="false"></div>';
219print $message;
220print ajax_autoselect("urltogettoken");
221print '<br>';
222print '<br>';
223
224// Explorer
225print '<span class="opacitymedium">'.$langs->trans("ApiExporerIs").':</span><br>';
226if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) {
227 $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
228 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a></div><br>\n";
229
230 print '<div class="opacitymediumxxx"><br><span class="opacitymedium">'.$langs->trans("SwaggerDescriptionFile").':</span><br>';
231 $urlswagger = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY=youruserapikey';
232 //$urlswaggerreal = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.$user->api_key;
233 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogetapidesc" value="'.$urlswagger.'" spellcheck="false"></div>';
234 print '</div>';
235 print ajax_autoselect("urltogetapidesc");
236} else {
237 $langs->load("errors");
238 print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error');
239}
240
241llxFooter();
242$db->close();
global $dolibarr_main_url_root
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).
api_admin_prepare_head()
Return array head with list of tabs to view object information.
Definition api.lib.php:32
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.