settings.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * ownCloud - user_ldap
  4. *
  5. * @author Dominik Schmidt
  6. * @copyright 2011 Dominik Schmidt dev@dominik-schmidt.de
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library 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 AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. $params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_agent_password', 'ldap_base', 'ldap_base_users', 'ldap_base_groups', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_group_filter', 'ldap_display_name', 'ldap_group_display_name', 'ldap_tls', 'ldap_turn_off_cert_check', 'ldap_nocase', 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr', 'ldap_group_member_assoc_attribute', 'ldap_cache_ttl', 'home_folder_naming_rule');
  23. OCP\Util::addscript('user_ldap', 'settings');
  24. OCP\Util::addstyle('user_ldap', 'settings');
  25. if ($_POST) {
  26. foreach($params as $param) {
  27. if(isset($_POST[$param])) {
  28. if('ldap_agent_password' == $param) {
  29. OCP\Config::setAppValue('user_ldap', $param, base64_encode($_POST[$param]));
  30. } elseif('ldap_cache_ttl' == $param) {
  31. if(OCP\Config::getAppValue('user_ldap', $param,'') != $_POST[$param]) {
  32. $ldap = new \OCA\user_ldap\lib\Connection('user_ldap');
  33. $ldap->clearCache();
  34. OCP\Config::setAppValue('user_ldap', $param, $_POST[$param]);
  35. }
  36. } elseif('home_folder_naming_rule' == $param) {
  37. $value = empty($_POST[$param]) ? 'opt:username' : 'attr:'.$_POST[$param];
  38. OCP\Config::setAppValue('user_ldap', $param, $value);
  39. } else {
  40. OCP\Config::setAppValue('user_ldap', $param, $_POST[$param]);
  41. }
  42. }
  43. elseif('ldap_tls' == $param) {
  44. // unchecked checkboxes are not included in the post paramters
  45. OCP\Config::setAppValue('user_ldap', $param, 0);
  46. }
  47. elseif('ldap_nocase' == $param) {
  48. OCP\Config::setAppValue('user_ldap', $param, 0);
  49. }
  50. elseif('ldap_turn_off_cert_check' == $param) {
  51. OCP\Config::setAppValue('user_ldap', $param, 0);
  52. }
  53. }
  54. }
  55. // fill template
  56. $tmpl = new OCP\Template( 'user_ldap', 'settings');
  57. foreach($params as $param) {
  58. $value = OCP\Config::getAppValue('user_ldap', $param,'');
  59. $tmpl->assign($param, $value);
  60. }
  61. // settings with default values
  62. $tmpl->assign( 'ldap_port', OCP\Config::getAppValue('user_ldap', 'ldap_port', '389'));
  63. $tmpl->assign( 'ldap_display_name', OCP\Config::getAppValue('user_ldap', 'ldap_display_name', 'uid'));
  64. $tmpl->assign( 'ldap_group_display_name', OCP\Config::getAppValue('user_ldap', 'ldap_group_display_name', 'cn'));
  65. $tmpl->assign( 'ldap_group_member_assoc_attribute', OCP\Config::getAppValue('user_ldap', 'ldap_group_member_assoc_attribute', 'uniqueMember'));
  66. $tmpl->assign( 'ldap_agent_password', base64_decode(OCP\Config::getAppValue('user_ldap', 'ldap_agent_password')));
  67. $tmpl->assign( 'ldap_cache_ttl', OCP\Config::getAppValue('user_ldap', 'ldap_cache_ttl', '600'));
  68. $hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username');
  69. $hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:'));
  70. $tmpl->assign( 'home_folder_naming_rule', $hfnr, '');
  71. return $tmpl->fetchPage();