Skip to content

Commit

Permalink
Store user_webdavauth users in DB + code cleanup
Browse files Browse the repository at this point in the history
This commit introduces the storing of user_webdavauth users in the database which is a pre-requisite of #12620.

Furthermore, I refactored the code and removed deprecated code, as a little gimmick I added unit tests for the backend.

Conflicts:
	lib/private/server.php
  • Loading branch information
LukasReschke committed Dec 19, 2014
1 parent 6b3600d commit 50deaab
Show file tree
Hide file tree
Showing 12 changed files with 867 additions and 115 deletions.
55 changes: 22 additions & 33 deletions apps/user_webdavauth/appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
<?php

/**
* ownCloud - user_webdavauth
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

require_once OC_App::getAppPath('user_webdavauth').'/user_webdavauth.php';
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
* @copyright 2014 Lukas Reschke lukas@owncloud.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

OC_APP::registerAdmin('user_webdavauth', 'settings');
namespace OCA\user_webdavauth\AppInfo;

OC_User::registerBackend("WEBDAVAUTH");
OC_User::useBackend( "WEBDAVAUTH" );
use OCA\user_webdavauth\USER_WEBDAVAUTH;
use OCP\Util;

OCP\Util::addTranslations('user_webdavauth');

// add settings page to navigation
$entry = array(
'id' => "user_webdavauth_settings",
'order'=>1,
'href' => OC_Helper::linkTo( "user_webdavauth", "settings.php" ),
'name' => 'WEBDAVAUTH'
$userBackend = new USER_WEBDAVAUTH(
\OC::$server->getConfig(),
\OC::$server->getDb(),
\OC::$server->getHTTPHelper(),
\OC::$server->getLogger(),
\OC::$server->getUserManager(),
\OC::$server->getServerRoot()
);
\OC_User::useBackend($userBackend);

Util::addTranslations('user_webdavauth');
\OC_APP::registerAdmin('user_webdavauth', 'settings');
41 changes: 41 additions & 0 deletions apps/user_webdavauth/appinfo/database.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>

<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>utf8</charset>

<table>

<name>*dbprefix*webdav_user_mapping</name>

<declaration>

<field>
<name>uid</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>

<field>
<name>displayname</name>
<type>text</type>
<notnull>false</notnull>
<length>255</length>
</field>

<index>
<name>webdav_uid</name>
<unique>true</unique>
<field>
<name>uid</name>
</field>
</index>

</declaration>

</table>

</database>
6 changes: 3 additions & 3 deletions apps/user_webdavauth/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<info>
<id>user_webdavauth</id>
<name>WebDAV user backend</name>
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other webserver to authenticate. It should return http 200 for right credentials and http 401 for wrong ones.
<description>Authenticate users by a WebDAV call. You can use any WebDAV server, ownCloud server or other web server to authenticate. It should return a HTTP 2xx status code for correct credentials and a 4xx or 5xx for invalid ones.

Attention: This app is not compatible with the LDAP user and group backend. This app is not the webdav interface of ownCloud, if you don't understand what it does then do not enable it.</description>
Attention: This app is not the WebDAV interface of ownCloud, if you don't understand what it does then do not enable it.</description>
<licence>AGPL</licence>
<author>Frank Karlitschek</author>
<requiremin>4.93</requiremin>
<requiremin>7.0</requiremin>
<shipped>true</shipped>
<types>
<authentication/>
Expand Down
2 changes: 1 addition & 1 deletion apps/user_webdavauth/appinfo/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0.1
1.2.0.0
23 changes: 6 additions & 17 deletions apps/user_webdavauth/settings.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
<?php

/**
* ownCloud - user_webdavauth
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/

OC_Util::checkAdminUser();
Expand All @@ -28,12 +17,12 @@
OCP\JSON::callCheck();

if(isset($_POST['webdav_url'])) {
OC_CONFIG::setValue('user_webdavauth_url', strip_tags($_POST['webdav_url']));
\OC::$server->getConfig()->setSystemValue('user_webdavauth_url', $_POST['webdav_url']);
}
}

// fill template
$tmpl = new OC_Template( 'user_webdavauth', 'settings');
$tmpl->assign( 'webdav_url', OC_Config::getValue( "user_webdavauth_url" ));
$tmpl = new OC_Template('user_webdavauth', 'settings');
$tmpl->assign('webdav_url', \OC::$server->getConfig()->getSystemValue('user_webdavauth_url'));

return $tmpl->fetchPage();
16 changes: 12 additions & 4 deletions apps/user_webdavauth/templates/settings.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?php
/** @var array $_ */
?>
<form id="webdavauth" class="section" action="#" method="post">
<h2><?php p($l->t('WebDAV Authentication'));?></h2>
<p><label for="webdav_url"><?php p($l->t('Address:').' ');?><input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>"></label>
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
<input type="submit" value="<?php p($l->t('Save')); ?>" />
<br /><?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP statuscodes 401 and 403 as invalid credentials, and all other responses as valid credentials.')); ?>
<p>
<label for="webdav_url"><?php p($l->t('Address:').' ');?>
<input type="url" placeholder="https://example.com/webdav" id="webdav_url" name="webdav_url" value="<?php p($_['webdav_url']); ?>">
</label>
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" id="requesttoken">
<input type="submit" value="<?php p($l->t('Save')); ?>" />
<br />
<?php p($l->t('The user credentials will be sent to this address. This plugin checks the response and will interpret the HTTP status codes 2xx and 403 as valid credentials, and all other responses as invalid credentials.')); ?>
</p>
</form>
Loading

0 comments on commit 50deaab

Please sign in to comment.