index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 Regis Houssin <regis.houssin@capnetworks.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 <http://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. $langs->load("admin");
  30. if (! $user->admin)
  31. accessforbidden();
  32. $action=GETPOST('action','aZ09');
  33. //Activate ProfId
  34. if ($action == 'setproductionmode')
  35. {
  36. $status = GETPOST('status','alpha');
  37. if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', $conf->entity) > 0)
  38. {
  39. $error=0;
  40. if ($status == 1)
  41. {
  42. $result = dol_mkdir($conf->api->dir_temp);
  43. if ($result < 0)
  44. {
  45. setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
  46. $error++;
  47. }
  48. }
  49. else
  50. {
  51. // Delete the cache file otherwise it does not update
  52. $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
  53. if ($result < 0)
  54. {
  55. setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
  56. $error++;
  57. }
  58. }
  59. if (!$error)
  60. {
  61. header("Location: ".$_SERVER["PHP_SELF"]);
  62. exit;
  63. }
  64. }
  65. else
  66. {
  67. dol_print_error($db);
  68. }
  69. }
  70. /*
  71. * View
  72. */
  73. llxHeader();
  74. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  75. print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup');
  76. print $langs->trans("ApiDesc")."<br>\n";
  77. print "<br>\n";
  78. //print '<form name="apisetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  79. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  80. print '<table class="noborder" width="100%">';
  81. print '<tr class="liste_titre">';
  82. print "<td>".$langs->trans("Parameter")."</td>";
  83. print '<td align="center">'.$langs->trans("Value")."</td>";
  84. print "<td>&nbsp;</td>";
  85. print "</tr>";
  86. print '<tr class="impair">';
  87. print '<td>'.$langs->trans("ApiProductionMode").'</td>';
  88. $production_mode=(empty($conf->global->API_PRODUCTION_MODE)?false:true);
  89. if ($production_mode)
  90. {
  91. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">';
  92. print img_picto($langs->trans("Activated"),'switch_on');
  93. print '</a></td>';
  94. }
  95. else
  96. {
  97. print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">';
  98. print img_picto($langs->trans("Disabled"),'switch_off');
  99. print '</a></td>';
  100. }
  101. print '<td>&nbsp;</td>';
  102. print '</tr>';
  103. print '</table>';
  104. print '<br><br>';
  105. // Define $urlwithroot
  106. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  107. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  108. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  109. // Show message
  110. $message='';
  111. $url=$urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&userpassword=<strong>thepassword</strong>[&reset=1]';
  112. $message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>';
  113. $message.=img_picto('','object_globe.png').' '.$url;
  114. print $message;
  115. print '<br>';
  116. print '<br>';
  117. // Explorer
  118. print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
  119. if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer'))
  120. {
  121. $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
  122. print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
  123. }
  124. else
  125. {
  126. print $langs->trans("NotAvailableWithThisDistribution");
  127. }
  128. llxFooter();
  129. $db->close();