dolibarr  16.0.5
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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 
32 // Load translation files required by the page
33 $langs->load("admin");
34 
35 if (!$user->admin) {
37 }
38 
39 $action = GETPOST('action', 'aZ09');
40 
41 // Activate Production mode
42 if ($action == 'setproductionmode') {
43  $status = GETPOST('status', 'alpha');
44 
45  if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) {
46  $error = 0;
47 
48  if ($status == 1) {
49  $result = dol_mkdir($conf->api->dir_temp);
50  if ($result < 0) {
51  setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
52  $error++;
53  }
54  } else {
55  // Delete the cache file otherwise it does not update
56  $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
57  if ($result < 0) {
58  setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
59  $error++;
60  }
61  }
62 
63  if (!$error) {
64  header("Location: ".$_SERVER["PHP_SELF"]);
65  exit;
66  }
67  } else {
68  dol_print_error($db);
69  }
70 }
71 
72 // Disable compression mode
73 if ($action == 'setdisablecomprssion') {
74  $status = GETPOST('status', 'alpha');
75 
76  if (dolibarr_set_const($db, 'API_DISABLE_COMPRESSION', $status, 'chaine', 0, '', 0) > 0) {
77  header("Location: ".$_SERVER["PHP_SELF"]);
78  exit;
79  } else {
80  dol_print_error($db);
81  }
82 }
83 
84 if ($action == 'save') {
85  dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha'));
86 }
87 
88 
89 dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
90 
91 
92 /*
93  * View
94  */
95 
96 llxHeader();
97 
98 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
99 print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
100 
101 print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
102 print "<br>\n";
103 
104 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
105 print '<input type="hidden" name="token" value="'.newToken().'">';
106 print '<input type="hidden" name="action" value="save">';
107 
108 print '<table class="noborder centpercent">';
109 
110 print '<tr class="liste_titre">';
111 print "<td>".$langs->trans("Parameter")."</td>";
112 print '<td>'.$langs->trans("Value")."</td>";
113 print "<td>&nbsp;</td>";
114 print "</tr>";
115 
116 print '<tr class="oddeven">';
117 print '<td>'.$langs->trans("ApiProductionMode").'</td>';
118 $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true);
119 if ($production_mode) {
120  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&value='.($i + 1).'&status=0">';
121  print img_picto($langs->trans("Activated"), 'switch_on');
122  print '</a></td>';
123 } else {
124  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&value='.($i + 1).'&status=1">';
125  print img_picto($langs->trans("Disabled"), 'switch_off');
126  print '</a></td>';
127 }
128 print '<td>&nbsp;</td>';
129 print '</tr>';
130 
131 print '<tr class="oddeven">';
132 print '<td>'.$langs->trans("API_DISABLE_COMPRESSION").'</td>';
133 $disable_compression = (empty($conf->global->API_DISABLE_COMPRESSION) ?false:true);
134 if ($disable_compression) {
135  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecomprssion&token='.newToken().'&value='.($i + 1).'&status=0">';
136  print img_picto($langs->trans("Activated"), 'switch_on');
137  print '</a></td>';
138 } else {
139  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablecomprssion&token='.newToken().'&value='.($i + 1).'&status=1">';
140  print img_picto($langs->trans("Disabled"), 'switch_off');
141  print '</a></td>';
142 }
143 print '<td>&nbsp;</td>';
144 print '</tr>';
145 
146 print '<tr class="oddeven">';
147 print '<td>'.$langs->trans("RESTRICT_ON_IP");
148 print ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
149 print '</td>';
150 print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag($conf->global->API_RESTRICT_ON_IP).'"></td>';
151 print '<td>';
152 print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
153 print '</td>';
154 print '</tr>';
155 
156 print '</table>';
157 print '<br><br>';
158 
159 print '</form>';
160 
161 
162 // Define $urlwithroot
163 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
164 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
165 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
166 
167 // Show message
168 $message = '';
169 //$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
170 $url = $urlwithroot.'/api/index.php/login?login=auserlogin&password=thepassword[&reset=1]';
171 $message .= '<span class="opacitymedium">'.$langs->trans("UrlToGetKeyToUseAPIs").':</span><br>';
172 $message .= '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <input type="text" class="quatrevingtpercent" id="urltogettoken" value="'.$url.'"></div>';
173 print $message;
174 print ajax_autoselect("urltogettoken");
175 print '<br>';
176 print '<br>';
177 
178 // Explorer
179 print '<span class="opacitymedium">'.$langs->trans("ApiExporerIs").':</span><br>';
180 if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) {
181  $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
182  print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.$url."</a></div><br>\n";
183  print '<div class="opacitymediumxxx"><br><span class="opacitymedium">'.$langs->trans("SwaggerDescriptionFile").':</span><br>';
184  $urlswagger = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY=youruserapikey';
185  //$urlswaggerreal = DOL_MAIN_URL_ROOT.'/api/index.php/explorer/swagger.json?DOLAPIKEY='.$user->api_key;
186  print '<div class="urllink soixantepercent">'.img_picto('', 'globe').' <a href="'.$urlswagger.'" target="_blank" rel="noopener noreferrer">'.$urlswagger."</a></div><br>\n";
187  print '</div>';
188 } else {
189  $langs->load("errors");
190  print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error');
191 }
192 
193 llxFooter();
194 $db->close();
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5190
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4830
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3866
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_delete_file
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.
Definition: files.lib.php:1231
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4786
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10864
dolibarr_set_const
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).
Definition: admin.lib.php:627
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8123
dol_is_dir
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:447
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
ajax_autoselect
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
Definition: functions.lib.php:9667
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6589