dolibarr 18.0.6
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32
33// Load translation files required by the page
34$langs->load("admin");
35
36if (!$user->admin) {
38}
39
40$action = GETPOST('action', 'aZ09');
41
42// Activate Production mode
43if ($action == 'setproductionmode') {
44 $status = GETPOST('status', 'alpha');
45
46 if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) {
47 $error = 0;
48
49 if ($status == 1) {
50 $result = dol_mkdir($conf->api->dir_temp);
51 if ($result < 0) {
52 setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
53 $error++;
54 }
55 } else {
56 // Delete the cache file otherwise it does not update
57 $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
58 if ($result < 0) {
59 setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
60 $error++;
61 }
62 }
63
64 if (!$error) {
65 header("Location: ".$_SERVER["PHP_SELF"]);
66 exit;
67 }
68 } else {
69 dol_print_error($db);
70 }
71}
72
73// Disable compression mode
74if ($action == 'setdisablecompression') {
75 $status = GETPOST('status', 'alpha');
76
77 if (dolibarr_set_const($db, 'API_DISABLE_COMPRESSION', $status, 'chaine', 0, '', 0) > 0) {
78 header("Location: ".$_SERVER["PHP_SELF"]);
79 exit;
80 } else {
81 dol_print_error($db);
82 }
83}
84
85if ($action == 'save') {
86 dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha'));
87}
88
89
90dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
91
92
93/*
94 * View
95 */
96
97llxHeader();
98
99$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
100print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
101
102print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
103print "<br>\n";
104
105print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
106print '<input type="hidden" name="token" value="'.newToken().'">';
107print '<input type="hidden" name="action" value="save">';
108
109print '<table class="noborder centpercent">';
110
111print '<tr class="liste_titre">';
112print "<td>".$langs->trans("Parameter")."</td>";
113print '<td>'.$langs->trans("Value")."</td>";
114print "<td>&nbsp;</td>";
115print "</tr>";
116
117print '<tr class="oddeven">';
118print '<td>'.$langs->trans("ApiProductionMode").'</td>';
119$production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true);
120if ($production_mode) {
121 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=0">';
122 print img_picto($langs->trans("Activated"), 'switch_on');
123 print '</a></td>';
124} else {
125 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&status=1">';
126 print img_picto($langs->trans("Disabled"), 'switch_off');
127 print '</a></td>';
128}
129print '<td>&nbsp;</td>';
130print '</tr>';
131
132print '<tr class="oddeven">';
133print '<td>'.$langs->trans("API_DISABLE_COMPRESSION").'</td>';
134$disable_compression = (empty($conf->global->API_DISABLE_COMPRESSION) ?false:true);
135if ($disable_compression) {
136 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=0">';
137 print img_picto($langs->trans("Activated"), 'switch_on');
138 print '</a></td>';
139} else {
140 print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecompression&token='.newToken().'&status=1">';
141 print img_picto($langs->trans("Disabled"), 'switch_off');
142 print '</a></td>';
143}
144print '<td>&nbsp;</td>';
145print '</tr>';
146
147print '<tr class="oddeven">';
148print '<td>'.$langs->trans("RESTRICT_ON_IP");
149print ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
150print '</td>';
151print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag(getDolGlobalString('API_RESTRICT_ON_IP')).'"></td>';
152print '<td>';
153print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
154print '</td>';
155print '</tr>';
156
157print '</table>';
158print '<br><br>';
159
160print '</form>';
161
162
163// Define $urlwithroot
164$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
165$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
166//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
167
168// Show message
169$message = '';
170//$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
171$url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]';
172$message .= '<span class="opacitymedium">'.$langs->trans("UrlToGetKeyToUseAPIs").':</span><br>';
173$message .= '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogettoken" value="'.$url.'"></div>';
174print $message;
175print ajax_autoselect("urltogettoken");
176print '<br>';
177print '<br>';
178
179// Explorer
180print '<span class="opacitymedium">'.$langs->trans("ApiExporerIs").':</span><br>';
181if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) {
182 $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
183 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a></div><br>\n";
184 print '<div class="opacitymediumxxx"><br><span class="opacitymedium">'.$langs->trans("SwaggerDescriptionFile").':</span><br>';
185 $urlswagger = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY=youruserapikey';
186 //$urlswaggerreal = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.$user->api_key;
187 print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$urlswagger.'" target="_blank" rel="noopener noreferrer">'.$urlswagger."</a></div><br>\n";
188 print '</div>';
189} else {
190 $langs->load("errors");
191 print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error');
192}
193
194llxFooter();
195$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()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.