oauth.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  3. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. /**
  20. * \file htdocs/admin/oauth.php
  21. * \ingroup oauth
  22. * \brief Setup page to configure oauth access api
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
  27. // Define $urlwithroot
  28. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  29. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  30. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  31. $langs->load("admin");
  32. $langs->load("oauth");
  33. // Security check
  34. if (!$user->admin)
  35. accessforbidden();
  36. $action = GETPOST('action', 'alpha');
  37. /*
  38. * Actions
  39. */
  40. if ($action == 'update')
  41. {
  42. $error = 0;
  43. foreach ($list as $constname) {
  44. $constvalue = GETPOST($constname[1], 'alpha');
  45. if (!dolibarr_set_const($db, $constname[1], $constvalue, 'chaine', 0, '', $conf->entity))
  46. $error++;
  47. $constvalue = GETPOST($constname[2], 'alpha');
  48. if (!dolibarr_set_const($db, $constname[2], $constvalue, 'chaine', 0, '', $conf->entity))
  49. $error++;
  50. }
  51. if (! $error)
  52. {
  53. setEventMessages($langs->trans("SetupSaved"), null);
  54. } else {
  55. setEventMessages($langs->trans("Error"), null, 'errors');
  56. }
  57. }
  58. /*
  59. * View
  60. */
  61. llxHeader();
  62. $form = new Form($db);
  63. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  64. print load_fiche_titre($langs->trans('ConfigOAuth'),$linkback,'title_setup');
  65. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  66. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  67. print '<input type="hidden" name="action" value="update">';
  68. $head = oauthadmin_prepare_head();
  69. dol_fiche_head($head, 'services', '', 0, 'technic');
  70. print $langs->trans("ListOfSupportedOauthProviders").'<br><br>';
  71. print '<table class="noborder" width="100%">';
  72. $i=0;
  73. foreach ($list as $key)
  74. {
  75. $supported=0;
  76. if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1;
  77. if (! $supported) continue; // show only supported
  78. $i++;
  79. print '<tr class="liste_titre'.($i > 1 ?' liste_titre_add':'').'">';
  80. // Api Name
  81. $label = $langs->trans($key[0]);
  82. print '<td>'.$label.'</td>';
  83. print '<td>';
  84. if (! empty($key[3])) print $langs->trans($key[3]);
  85. print '</td>';
  86. print '</tr>';
  87. if ($supported)
  88. {
  89. $redirect_uri=$urlwithroot.'/core/modules/oauth/'.$supportedoauth2array[$key[0]].'_oauthcallback.php';
  90. print '<tr class="oddeven value">';
  91. print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
  92. print '<td><input style="width: 80%" type"text" name="uri'.$key[0].'" value="'.$redirect_uri.'">';
  93. print '</td></tr>';
  94. }
  95. else
  96. {
  97. print '<tr class="oddeven value">';
  98. print '<td>'.$langs->trans("UseTheFollowingUrlAsRedirectURI").'</td>';
  99. print '<td>'.$langs->trans("FeatureNotYetSupported").'</td>';
  100. print '</td></tr>';
  101. }
  102. // Api Id
  103. print '<tr class="oddeven value">';
  104. print '<td><label for="'.$key[1].'">'.$langs->trans($key[1]).'</label></td>';
  105. print '<td><input type="text" size="100" id="'.$key[1].'" name="'.$key[1].'" value="'.$conf->global->{$key[1]}.'">';
  106. print '</td></tr>';
  107. // Api Secret
  108. print '<tr class="oddeven value">';
  109. print '<td><label for="'.$key[2].'">'.$langs->trans($key[2]).'</label></td>';
  110. print '<td><input type="password" size="100" id="'.$key[2].'" name="'.$key[2].'" value="'.$conf->global->{$key[2]}.'">';
  111. print '</td></tr>';
  112. }
  113. print '</table>'."\n";
  114. dol_fiche_end();
  115. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
  116. print '</form>';
  117. llxFooter();
  118. $db->close();