dav.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /* Copyright (C) 2008-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/dav.php
  19. * \ingroup dav
  20. * \brief Page to setup DAV server
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/dav/dav.lib.php';
  26. // Load translation files required by the page
  27. $langs->loadLangs(array("admin", "other", "agenda"));
  28. if (!$user->admin) {
  29. accessforbidden();
  30. }
  31. // Parameters
  32. $action = GETPOST('action', 'aZ09');
  33. $backtopage = GETPOST('backtopage', 'alpha');
  34. if (empty($action)) {
  35. $action = 'edit';
  36. }
  37. $arrayofparameters = array(
  38. 'DAV_RESTICT_ON_IP'=>array('css'=>'minwidth200', 'enabled'=>1),
  39. 'DAV_ALLOW_PRIVATE_DIR'=>array('css'=>'minwidth200', 'enabled'=>2),
  40. 'DAV_ALLOW_PUBLIC_DIR'=>array('css'=>'minwidth200', 'enabled'=>1),
  41. 'DAV_ALLOW_ECM_DIR'=>array('css'=>'minwidth200', 'enabled'=>isModEnabled('ecm'))
  42. );
  43. // To fix when dire does not exists
  44. dol_mkdir($conf->dav->dir_output.'/temp');
  45. dol_mkdir($conf->dav->dir_output.'/public');
  46. dol_mkdir($conf->dav->dir_output.'/private');
  47. /*
  48. * Actions
  49. */
  50. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  51. if ($action == 'update') {
  52. $action = 'edit';
  53. }
  54. /*
  55. * View
  56. */
  57. $help_url = 'EN:Module_DAV';
  58. llxHeader('', $langs->trans("DAVSetup"), $help_url);
  59. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  60. print load_fiche_titre($langs->trans("DAVSetup"), $linkback, 'title_setup');
  61. print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  62. print '<input type="hidden" name="token" value="'.newToken().'">';
  63. $head = dav_admin_prepare_head();
  64. print dol_get_fiche_head($head, 'webdav', '', -1, '');
  65. if ($action == 'edit') {
  66. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  67. print '<input type="hidden" name="token" value="'.newToken().'">';
  68. print '<input type="hidden" name="action" value="update">';
  69. print '<table class="noborder centpercent nomarginbottom">';
  70. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  71. foreach ($arrayofparameters as $key => $val) {
  72. if (isset($val['enabled']) && empty($val['enabled'])) {
  73. continue;
  74. }
  75. print '<tr class="oddeven"><td>';
  76. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  77. $label = $langs->trans($key);
  78. if ($key == 'DAV_RESTICT_ON_IP') {
  79. $label = $langs->trans("RESTRICT_ON_IP");
  80. $tooltiphelp .= ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
  81. }
  82. print $form->textwithpicto($label, $tooltiphelp);
  83. print '</td><td>';
  84. if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
  85. print $langs->trans("AlwaysActive");
  86. } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
  87. print $form->selectyesno($key, getDolGlobalString($key), 1);
  88. } else {
  89. print '<input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'">';
  90. }
  91. print '</td></tr>';
  92. }
  93. print '</table>';
  94. print '<br><div class="center">';
  95. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  96. print '</div>';
  97. print '</form>';
  98. print '<br>';
  99. } else {
  100. print '<table class="noborder centpercent nomarginbottom">';
  101. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  102. foreach ($arrayofparameters as $key => $val) {
  103. if (isset($val['enabled']) && empty($val['enabled'])) {
  104. continue;
  105. }
  106. print '<tr class="oddeven"><td>';
  107. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  108. $label = $langs->trans($key);
  109. if ($key == 'DAV_RESTICT_ON_IP') {
  110. $label = $langs->trans("RESTRICT_ON_IP");
  111. $tooltiphelp .= ' <span class="opacitymedium">'.$langs->trans("Example").': '.$langs->trans("IPListExample").'</span>';
  112. }
  113. print $form->textwithpicto($label, $tooltiphelp);
  114. print '</td><td class="minwidth200">';
  115. if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
  116. print $langs->trans("AlwaysActive");
  117. } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
  118. print yn(getDolGlobalString($key));
  119. } else {
  120. print getDolGlobalString($key);
  121. }
  122. print '</td></tr>';
  123. }
  124. print '</table>';
  125. print '<div class="tabsAction">';
  126. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  127. print '</div>';
  128. }
  129. print dol_get_fiche_end();
  130. /*print '<div class="center">';
  131. print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
  132. print "</div>";
  133. */
  134. print "</form>\n";
  135. clearstatcache();
  136. print '<span class="opacitymedium">'.$langs->trans("WebDAVSetupDesc")."</span><br>\n";
  137. print "<br>";
  138. // Define $urlwithroot
  139. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  140. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  141. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  142. // Show message
  143. $message = '';
  144. $url = '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">'.$urlwithroot.'/dav/fileserver.php</a>';
  145. $message .= img_picto('', 'globe').' '.str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV', ''));
  146. $message .= '<div class="urllink"><input type="text" id="webdavpublicurl" class="quatrevingtpercent" value="'.$urlwithroot.'/dav/fileserver.php">';
  147. $message .= '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">';
  148. $message .= ' '.img_picto('', 'globe');
  149. $message .= '</a>';
  150. $message .= '</div>';
  151. $message .= ajax_autoselect('webdavpublicurl');
  152. $message .= '<br>';
  153. if (getDolGlobalString('DAV_ALLOW_PUBLIC_DIR')) {
  154. $urlEntity = (isModEnabled('multicompany') ? '?entity=' . $conf->entity : '');
  155. $url = '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '</a>';
  156. $message .= img_picto('', 'globe') . ' ' . str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV public', ''));
  157. $message .= '<div class="urllink"><input type="text" id="webdavurl" class="quatrevingtpercent" value="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '">';
  158. $message .= '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">';
  159. $message .= ' ' . img_picto('', 'globe');
  160. $message .= '</a>';
  161. $message .= '</div>';
  162. $message .= ajax_autoselect('webdavurl');
  163. $message .= '<br>';
  164. }
  165. print $message;
  166. print '<br>';
  167. require_once DOL_DOCUMENT_ROOT.'/includes/sabre/autoload.php';
  168. $version = Sabre\DAV\Version::VERSION;
  169. print '<span class="opacitymedium">'.$langs->trans("BaseOnSabeDavVersion").' : '.$version.'</span>';
  170. // End of page
  171. llxFooter();
  172. $db->close();