dolibarr  13.0.2
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 $action = GETPOST('action', 'aZ09');
39 
40 //Activate ProfId
41 if ($action == 'setproductionmode')
42 {
43  $status = GETPOST('status', 'alpha');
44 
45  if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
46  {
47  $error = 0;
48 
49  if ($status == 1)
50  {
51  $result = dol_mkdir($conf->api->dir_temp);
52  if ($result < 0)
53  {
54  setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
55  $error++;
56  }
57  } else {
58  // Delete the cache file otherwise it does not update
59  $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
60  if ($result < 0)
61  {
62  setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
63  $error++;
64  }
65  }
66 
67  if (!$error)
68  {
69  header("Location: ".$_SERVER["PHP_SELF"]);
70  exit;
71  }
72  } else {
73  dol_print_error($db);
74  }
75 }
76 
77 if ($action == 'save')
78 {
79  dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha'));
80 }
81 
82 
83 dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
84 
85 
86 /*
87  * View
88  */
89 
90 llxHeader();
91 
92 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
93 print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
94 
95 print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
96 print "<br>\n";
97 
98 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
99 print '<input type="hidden" name="token" value="'.newToken().'">';
100 print '<input type="hidden" name="action" value="save">';
101 
102 print '<table class="noborder centpercent">';
103 
104 print '<tr class="liste_titre">';
105 print "<td>".$langs->trans("Parameter")."</td>";
106 print '<td>'.$langs->trans("Value")."</td>";
107 print "<td>&nbsp;</td>";
108 print "</tr>";
109 
110 print '<tr class="oddeven">';
111 print '<td>'.$langs->trans("ApiProductionMode").'</td>';
112 $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true);
113 if ($production_mode)
114 {
115  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&value='.($i + 1).'&status=0">';
116  print img_picto($langs->trans("Activated"), 'switch_on');
117  print '</a></td>';
118 } else {
119  print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&token='.newToken().'&value='.($i + 1).'&status=1">';
120  print img_picto($langs->trans("Disabled"), 'switch_off');
121  print '</a></td>';
122 }
123 print '<td>&nbsp;</td>';
124 print '</tr>';
125 
126 print '<tr class="oddeven">';
127 print '<td>'.$langs->trans("RESTRICT_ON_IP");
128 print ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
129 print '</td>';
130 print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag($conf->global->API_RESTRICT_ON_IP).'"></td>';
131 print '<td>';
132 print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
133 print '</td>';
134 print '</tr>';
135 
136 print '</table>';
137 print '<br><br>';
138 
139 print '</form>';
140 
141 
142 // Define $urlwithroot
143 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
144 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
145 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
146 
147 // Show message
148 $message = '';
149 $url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
150 $message .= '<span class="opacitymedium">'.$langs->trans("UrlToGetKeyToUseAPIs").':</span><br>';
151 $message .= img_picto('', 'globe').' '.$url;
152 print $message;
153 print '<br>';
154 print '<br>';
155 
156 // Explorer
157 print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
158 if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer'))
159 {
160  $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
161  print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
162 } else {
163  $langs->load("errors");
164  print info_admin($langs->trans("ErrorNotAvailableWithThisDistribution"), 0, 0, 'error');
165 }
166 
167 llxFooter();
168 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:432
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1144
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)