* Copyright (C) 2005-2016 Laurent Destailleur * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2012-2018 Regis Houssin * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2024 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/api/admin/index.php * \ingroup api * \brief Page to setup Webservices REST module */ // Load Dolibarr environment require '../../main.inc.php'; /** * @var Conf $conf * @var DoliDB $db * @var Form $form * @var HookManager $hookmanager * @var Translate $langs * @var User $user * * @var string $dolibarr_main_url_root * @var string $dolibarr_api_count_always_enabled */ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Load translation files required by the page $langs->load("admin"); if (!$user->admin) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); // Activate Production mode if ($action == 'setproductionmode') { $status = GETPOST('status', 'alpha'); if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) { $error = 0; if ($status == 1) { $result = dol_mkdir($conf->api->dir_temp); if ($result < 0) { setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors'); $error++; } } else { // Delete the cache file otherwise it does not update $result = dol_delete_file($conf->api->dir_temp.'/routes.php'); if ($result < 0) { setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors'); $error++; } } if (!$error) { header("Location: ".$_SERVER["PHP_SELF"]); exit; } } else { dol_print_error($db); } } // Disable compression mode if ($action == 'setdisablecompression') { if (dolibarr_set_const($db, 'API_DISABLE_COMPRESSION', GETPOSTINT('status'), 'chaine', 0, '', 0) <= 0) { dol_print_error($db); } } // Disable compression mode if ($action == 'setenablecount' && !empty($dolibarr_api_count_always_enabled)) { if (dolibarr_set_const($db, 'API_ENABLE_COUNT_CALLS', GETPOSTINT('status'), 'chaine', 0, '', 0) <= 0) { dol_print_error($db); } } if ($action == 'save') { if (dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha')) <= 0) { dol_print_error($db); } } dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge /* * View */ llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-api page-admin-index'); $linkback = ''.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup'); print ''.$langs->trans("ApiDesc")."
\n"; print "
\n"; print '
'; print ''; print ''; print ''; print ''; print ""; print '"; print ""; print ""; print ''; print ''; $production_mode = getDolGlobalBool('API_PRODUCTION_MODE'); if ($production_mode) { print ''; } else { print ''; } print ''; print ''; print ''; print ''; $disable_compression = getDolGlobalBool('API_DISABLE_COMPRESSION'); if ($disable_compression) { print ''; } else { print ''; } print ''; print ''; print ''; print ''; $enable_count = getDolGlobalBool('API_ENABLE_COUNT_CALLS'); if (!empty($dolibarr_api_count_always_enabled)) { print ''; } else { if ($enable_count) { print ''; } else { print ''; } } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
".$langs->trans("Parameter")."'.$langs->trans("Value")." 
'.$langs->trans("ApiProductionMode").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ' 
'.$langs->trans("API_DISABLE_COMPRESSION").''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ' 
'.$langs->trans("API_ENABLE_COUNT_CALLS").''; print img_picto($langs->trans("AlwaysEnabled"), 'switch_on', 'class="opacitymedium"'); print ''; print img_picto($langs->trans("Activated"), 'switch_on'); print ''; print img_picto($langs->trans("Disabled"), 'switch_off'); print ' 
'.$form->textwithpicto($langs->trans("RESTRICT_ON_IP"), $langs->trans("Example").': '.$langs->trans("IPListExample")); print ''; print '
'; print '

'; print '
'; // Define $urlwithroot $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // Show message $message = ''; //$url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]'; $url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]'; $message .= ''.$langs->trans("UrlToGetKeyToUseAPIs").':
'; $message .= ''; print $message; print ajax_autoselect("urltogettoken"); print '
'; print '
'; // Explorer print ''.$langs->trans("ApiExporerIs").':
'; if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) { $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer'; print '
\n"; print '

'.$langs->trans("SwaggerDescriptionFile").':
'; $urlswagger = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY=youruserapikey'; //$urlswaggerreal = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.$user->api_key; print ''; print '
'; print ajax_autoselect("urltogetapidesc"); } else { $langs->load("errors"); print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error'); } llxFooter(); $db->close();