user_webdavauth.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  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. class OC_USER_WEBDAVAUTH extends OC_User_Backend {
  23. protected $webdavauth_url;
  24. public function __construct() {
  25. $this->webdavauth_url = OC_Config::getValue( "user_webdavauth_url" );
  26. }
  27. public function deleteUser($uid) {
  28. // Can't delete user
  29. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to delete users from web frontend using WebDAV user backend', 3);
  30. return false;
  31. }
  32. public function setPassword ( $uid, $password ) {
  33. // We can't change user password
  34. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to change password for users from web frontend using WebDAV user backend', 3);
  35. return false;
  36. }
  37. public function checkPassword( $uid, $password ) {
  38. $arr = explode('://', $this->webdavauth_url, 2);
  39. if( ! isset($arr) OR count($arr) !== 2) {
  40. OC_Log::write('OC_USER_WEBDAVAUTH', 'Invalid Url: "'.$this->webdavauth_url.'" ', 3);
  41. return false;
  42. }
  43. list($webdavauth_protocol, $webdavauth_url_path) = $arr;
  44. $url= $webdavauth_protocol.'://'.urlencode($uid).':'.urlencode($password).'@'.$webdavauth_url_path;
  45. $headers = get_headers($url);
  46. if($headers==false) {
  47. OC_Log::write('OC_USER_WEBDAVAUTH', 'Not possible to connect to WebDAV Url: "'.$webdavauth_protocol.'://'.$webdavauth_url_path.'" ', 3);
  48. return false;
  49. }
  50. $returncode= substr($headers[0], 9, 3);
  51. if(substr($returncode, 0, 1) === '2') {
  52. return $uid;
  53. } else {
  54. return false;
  55. }
  56. }
  57. /*
  58. * we don´t know if a user exists without the password. so we have to return true all the time
  59. */
  60. public function userExists( $uid ){
  61. return true;
  62. }
  63. /**
  64. * @return bool
  65. */
  66. public function hasUserListings() {
  67. return false;
  68. }
  69. /*
  70. * we don´t know the users so all we can do it return an empty array here
  71. */
  72. public function getUsers($search = '', $limit = 10, $offset = 0) {
  73. $returnArray = array();
  74. return $returnArray;
  75. }
  76. }