dav.php 7.4 KB

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