dav.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. $arrayofparameters = array(
  35. 'DAV_RESTICT_ON_IP'=>array('css'=>'minwidth200', 'enabled'=>1),
  36. 'DAV_ALLOW_PRIVATE_DIR'=>array('css'=>'minwidth200', 'enabled'=>2),
  37. 'DAV_ALLOW_PUBLIC_DIR'=>array('css'=>'minwidth200', 'enabled'=>1),
  38. 'DAV_ALLOW_ECM_DIR'=>array('css'=>'minwidth200', 'enabled'=>isModEnabled('ecm'))
  39. );
  40. // To fix when dire does not exists
  41. dol_mkdir($conf->dav->dir_output.'/temp');
  42. dol_mkdir($conf->dav->dir_output.'/public');
  43. dol_mkdir($conf->dav->dir_output.'/private');
  44. /*
  45. * Actions
  46. */
  47. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  48. /*
  49. * View
  50. */
  51. $help_url = 'EN:Module_DAV';
  52. llxHeader('', $langs->trans("DAVSetup"), $help_url);
  53. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  54. print load_fiche_titre($langs->trans("DAVSetup"), $linkback, 'title_setup');
  55. print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  56. print '<input type="hidden" name="token" value="'.newToken().'">';
  57. $head = dav_admin_prepare_head();
  58. print dol_get_fiche_head($head, 'webdav', '', -1, '');
  59. if ($action == 'edit') {
  60. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  61. print '<input type="hidden" name="token" value="'.newToken().'">';
  62. print '<input type="hidden" name="action" value="update">';
  63. print '<table class="noborder centpercent nomarginbottom">';
  64. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  65. foreach ($arrayofparameters as $key => $val) {
  66. if (isset($val['enabled']) && empty($val['enabled'])) {
  67. continue;
  68. }
  69. print '<tr class="oddeven"><td>';
  70. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  71. $label = $langs->trans($key);
  72. if ($key == 'DAV_RESTICT_ON_IP') {
  73. $label = $langs->trans("RESTRICT_ON_IP");
  74. $tooltiphelp .= ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
  75. }
  76. print $form->textwithpicto($label, $tooltiphelp);
  77. print '</td><td>';
  78. if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
  79. print $langs->trans("AlwaysActive");
  80. } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
  81. print $form->selectyesno($key, getDolGlobalString($key), 1);
  82. } else {
  83. print '<input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'">';
  84. }
  85. print '</td></tr>';
  86. }
  87. print '</table>';
  88. print '<br><div class="center">';
  89. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  90. print '</div>';
  91. print '</form>';
  92. print '<br>';
  93. } else {
  94. print '<table class="noborder centpercent nomarginbottom">';
  95. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  96. foreach ($arrayofparameters as $key => $val) {
  97. if (isset($val['enabled']) && empty($val['enabled'])) {
  98. continue;
  99. }
  100. print '<tr class="oddeven"><td>';
  101. $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
  102. $label = $langs->trans($key);
  103. if ($key == 'DAV_RESTICT_ON_IP') {
  104. $label = $langs->trans("RESTRICT_ON_IP");
  105. $tooltiphelp .= ' <span class="opacitymedium">'.$langs->trans("Example").': '.$langs->trans("IPListExample").'</span>';
  106. }
  107. print $form->textwithpicto($label, $tooltiphelp);
  108. print '</td><td class="minwidth200">';
  109. if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
  110. print $langs->trans("AlwaysActive");
  111. } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
  112. print yn(getDolGlobalString($key));
  113. } else {
  114. print getDolGlobalString($key);
  115. }
  116. print '</td></tr>';
  117. }
  118. print '</table>';
  119. print '<div class="tabsAction">';
  120. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  121. print '</div>';
  122. }
  123. print dol_get_fiche_end();
  124. /*print '<div class="center">';
  125. print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
  126. print "</div>";
  127. */
  128. print "</form>\n";
  129. clearstatcache();
  130. print '<span class="opacitymedium">'.$langs->trans("WebDAVSetupDesc")."</span><br>\n";
  131. print "<br>";
  132. // Define $urlwithroot
  133. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  134. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  135. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  136. // Show message
  137. $message = '';
  138. $url = '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">'.$urlwithroot.'/dav/fileserver.php</a>';
  139. $message .= img_picto('', 'globe').' '.str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV', ''));
  140. $message .= '<div class="urllink"><input type="text" id="webdavpublicurl" class="quatrevingtpercent" value="'.$urlwithroot.'/dav/fileserver.php">';
  141. $message .= '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">';
  142. $message .= ' '.img_picto('', 'globe');
  143. $message .= '</a>';
  144. $message .= '</div>';
  145. $message .= ajax_autoselect('webdavpublicurl');
  146. $message .= '<br>';
  147. if (!empty(getDolGlobalString('DAV_ALLOW_PUBLIC_DIR'))) {
  148. $urlEntity = (isModEnabled('multicompany') ? '?entity=' . $conf->entity : '');
  149. $url = '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '</a>';
  150. $message .= img_picto('', 'globe') . ' ' . str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV public', ''));
  151. $message .= '<div class="urllink"><input type="text" id="webdavurl" class="quatrevingtpercent" value="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '">';
  152. $message .= '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">';
  153. $message .= ' ' . img_picto('', 'globe');
  154. $message .= '</a>';
  155. $message .= '</div>';
  156. $message .= ajax_autoselect('webdavurl');
  157. $message .= '<br>';
  158. }
  159. print $message;
  160. print '<br>';
  161. require_once DOL_DOCUMENT_ROOT.'/includes/sabre/autoload.php';
  162. $version = Sabre\DAV\Version::VERSION;
  163. print '<span class="opacitymedium">'.$langs->trans("BaseOnSabeDavVersion").' : '.$version.'</span>';
  164. // End of page
  165. llxFooter();
  166. $db->close();