user_webdavauth.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Felix Moeller <mail@felixmoeller.de>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Georg Ehrke <georg@ownCloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author opensaucesystems <ashley@opensaucesystems.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. class OC_USER_WEBDAVAUTH extends OC_User_Backend implements \OCP\IUserBackend {
  28. protected $webdavauth_url;
  29. public function __construct() {
  30. $this->webdavauth_url = OC_Config::getValue( "user_webdavauth_url" );
  31. }
  32. public function deleteUser($uid) {
  33. // Can't delete user
  34. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to delete users from web frontend using WebDAV user backend', 3);
  35. return false;
  36. }
  37. public function setPassword ( $uid, $password ) {
  38. // We can't change user password
  39. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to change password for users from web frontend using WebDAV user backend', 3);
  40. return false;
  41. }
  42. public function checkPassword( $uid, $password ) {
  43. $arr = explode('://', $this->webdavauth_url, 2);
  44. if( ! isset($arr) OR count($arr) !== 2) {
  45. OC_Log::write('OC_USER_WEBDAVAUTH', 'Invalid Url: "'.$this->webdavauth_url.'" ', 3);
  46. return false;
  47. }
  48. list($webdavauth_protocol, $webdavauth_url_path) = $arr;
  49. $url= $webdavauth_protocol.'://'.urlencode($uid).':'.urlencode($password).'@'.$webdavauth_url_path;
  50. $headers = get_headers($url);
  51. if($headers==false) {
  52. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to connect to WebDAV Url: "'.$webdavauth_protocol.'://'.$webdavauth_url_path.'" ', 3);
  53. return false;
  54. }
  55. $returncode= substr($headers[0], 9, 3);
  56. if(substr($returncode, 0, 1) === '2') {
  57. return $uid;
  58. } else {
  59. return false;
  60. }
  61. }
  62. /*
  63. * we don´t know if a user exists without the password. so we have to return true all the time
  64. */
  65. public function userExists( $uid ){
  66. return true;
  67. }
  68. /**
  69. * @return bool
  70. */
  71. public function hasUserListings() {
  72. return false;
  73. }
  74. /*
  75. * we don´t know the users so all we can do it return an empty array here
  76. */
  77. public function getUsers($search = '', $limit = 10, $offset = 0) {
  78. $returnArray = array();
  79. return $returnArray;
  80. }
  81. /**
  82. * Backend name to be shown in user management
  83. * @return string the name of the backend to be shown
  84. */
  85. public function getBackendName(){
  86. return 'WebDAV';
  87. }
  88. }