index.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /**
  22. * \file htdocs/api/admin/index.php
  23. * \ingroup api
  24. * \brief Page to setup Webservices REST module
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. // Load translation files required by the page
  30. $langs->load("admin");
  31. if (!$user->admin)
  32. accessforbidden();
  33. $action = GETPOST('action', 'aZ09');
  34. //Activate ProfId
  35. if ($action == 'setproductionmode')
  36. {
  37. $status = GETPOST('status', 'alpha');
  38. if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
  39. {
  40. $error = 0;
  41. if ($status == 1)
  42. {
  43. $result = dol_mkdir($conf->api->dir_temp);
  44. if ($result < 0)
  45. {
  46. setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
  47. $error++;
  48. }
  49. }
  50. else
  51. {
  52. // Delete the cache file otherwise it does not update
  53. $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
  54. if ($result < 0)
  55. {
  56. setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
  57. $error++;
  58. }
  59. }
  60. if (!$error)
  61. {
  62. header("Location: ".$_SERVER["PHP_SELF"]);
  63. exit;
  64. }
  65. }
  66. else
  67. {
  68. dol_print_error($db);
  69. }
  70. }
  71. if ($action == 'save')
  72. {
  73. dolibarr_set_const($db, 'API_RESTRICT_ON_IP', GETPOST('API_RESTRICT_ON_IP', 'alpha'));
  74. }
  75. dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
  76. /*
  77. * View
  78. */
  79. llxHeader();
  80. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  81. print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
  82. print '<span class="opacitymedium">'.$langs->trans("ApiDesc")."</span><br>\n";
  83. print "<br>\n";
  84. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  85. print '<input type="hidden" name="token" value="'.newToken().'">';
  86. print '<input type="hidden" name="action" value="save">';
  87. print '<table class="noborder centpercent">';
  88. print '<tr class="liste_titre">';
  89. print "<td>".$langs->trans("Parameter")."</td>";
  90. print '<td>'.$langs->trans("Value")."</td>";
  91. print "<td>&nbsp;</td>";
  92. print "</tr>";
  93. print '<tr class="oddeven">';
  94. print '<td>'.$langs->trans("ApiProductionMode").'</td>';
  95. $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true);
  96. if ($production_mode)
  97. {
  98. print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=0">';
  99. print img_picto($langs->trans("Activated"), 'switch_on');
  100. print '</a></td>';
  101. }
  102. else
  103. {
  104. print '<td><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=1">';
  105. print img_picto($langs->trans("Disabled"), 'switch_off');
  106. print '</a></td>';
  107. }
  108. print '<td>&nbsp;</td>';
  109. print '</tr>';
  110. print '<tr class="oddeven">';
  111. print '<td>'.$langs->trans("RESTRICT_ON_IP");
  112. print ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
  113. print '</td>';
  114. print '<td><input type="text" name="API_RESTRICT_ON_IP" value="'.dol_escape_htmltag($conf->global->API_RESTRICT_ON_IP).'"></td>';
  115. print '<td>';
  116. print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'"></td>';
  117. print '</td>';
  118. print '</tr>';
  119. print '</table>';
  120. print '<br><br>';
  121. print '</form>';
  122. // Define $urlwithroot
  123. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  124. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  125. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  126. // Show message
  127. $message = '';
  128. $url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
  129. $message .= $langs->trans("UrlToGetKeyToUseAPIs").':<br>';
  130. $message .= img_picto('', 'globe').' '.$url;
  131. print $message;
  132. print '<br>';
  133. print '<br>';
  134. // Explorer
  135. print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
  136. if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer'))
  137. {
  138. $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
  139. print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
  140. }
  141. else
  142. {
  143. print $langs->trans("NotAvailableWithThisDistribution");
  144. }
  145. llxFooter();
  146. $db->close();