summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-01-24 14:11:53 +0100
committerArthur Schiwon <blizzz@owncloud.com>2013-01-24 14:11:53 +0100
commit5b9e181198a61f5c123f5e8d5acec4c30cc8908a (patch)
treeb908cd8d837eb49185f636a3e989ddc4c62eabab /apps/user_ldap
parent3bf38c7a8469d1a1eac579378fc6336db86d0218 (diff)
downloadnextcloud-server-5b9e181198a61f5c123f5e8d5acec4c30cc8908a.tar.gz
nextcloud-server-5b9e181198a61f5c123f5e8d5acec4c30cc8908a.zip
LDAP: implement deleteConfiguration feature
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/js/settings.js33
-rw-r--r--apps/user_ldap/lib/helper.php47
-rw-r--r--apps/user_ldap/templates/settings.php4
3 files changed, 73 insertions, 11 deletions
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index c3484da5ac6..49bbc60d81c 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -45,12 +45,32 @@ var LdapConfiguration = {
$(this).removeAttr('checked');
}
});
+ },
+
+ deleteConfiguration: function() {
+ $.post(
+ OC.filePath('user_ldap','ajax','deleteConfiguration.php'),
+ $('#ldap_serverconfig_chooser').serialize(),
+ function (result) {
+ if(result.status == 'success') {
+ $('#ldap_serverconfig_chooser option:selected').remove();
+ $('#ldap_serverconfig_chooser option:first').select();
+ LdapConfiguration.refreshConfig();
+ } else {
+ OC.dialogs.alert(
+ result.message,
+ 'Deletion failed'
+ );
+ }
+ }
+ );
}
}
$(document).ready(function() {
$('#ldapSettings').tabs();
$('#ldap_action_test_connection').button();
+ $('#ldap_action_delete_configuration').button();
LdapConfiguration.refreshConfig();
$('#ldap_action_test_connection').click(function(event){
event.preventDefault();
@@ -73,6 +93,19 @@ $(document).ready(function() {
);
});
+ $('#ldap_action_delete_configuration').click(function(event) {
+ event.preventDefault();
+ OC.dialogs.confirm(
+ 'Do you really want to delete the current Server Configuration?',
+ 'Confirm Deletion',
+ function(deleteConfiguration) {
+ if(deleteConfiguration) {
+ LdapConfiguration.deleteConfiguration();
+ }
+ }
+ );
+ });
+
$('#ldap_submit').click(function(event) {
event.preventDefault();
$.post(
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 1751f57f503..5f6e2a1d037 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -24,13 +24,13 @@
namespace OCA\user_ldap\lib;
class Helper {
-
+
/**
* @brief returns prefixes for each saved LDAP/AD server configuration.
* @return array with a list of the available prefixes
- *
+ *
* Configuration prefixes are used to set up configurations for n LDAP or
- * AD servers. Since configuration is stored in the database, table
+ * AD servers. Since configuration is stored in the database, table
* appconfig under appid user_ldap, the common identifiers in column
* 'configkey' have a prefix. The prefix for the very first server
* configuration is empty.
@@ -38,29 +38,56 @@ class Helper {
* Server 1: ldap_login_filtter
* Server 2: s1_ldap_login_filter
* Server 3: s2_ldap_login_filter
- *
- * The prefix needs to be passed to the constructor of Connection class,
+ *
+ * The prefix needs to be passed to the constructor of Connection class,
* except the default (first) server shall be connected to.
- *
+ *
*/
static public function getServerConfigurationPrefixes() {
$referenceConfigkey = 'ldap_login_filter';
-
+
$query = \OCP\DB::prepare('
SELECT DISTINCT `configkey`
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
');
-
+
$serverConfigs = $query->execute(array('%'.$referenceConfigkey))->fetchAll();
$prefixes = array();
-
+
foreach($serverConfigs as $serverConfig) {
$len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey);
$prefixes[] = substr($serverConfig['configkey'], 0, $len);
}
-
+
return $prefixes;
}
+
+ static public function deleteServerConfiguration($prefix) {
+ //just to be on the safe side
+ \OCP\User::checkAdminUser();
+
+ if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
+ return false;
+ }
+
+ $query = \OCP\DB::prepare('
+ DELETE
+ FROM `*PREFIX*appconfig`
+ WHERE `configkey` LIKE ?
+ AND appid = "user_ldap"
+ ');
+ $res = $query->execute(array($prefix.'%'));
+
+ if(\OCP\DB::isError($res)) {
+ return false;
+ }
+
+ if($res->numRows() == 0) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 20297c02d39..513c59653e6 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -15,7 +15,9 @@
<p><label for="ldap_serverconfig_chooser"><?php echo $l->t('Server configuration');?></label><select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
<?php echo $_['serverConfigurationOptions']; ?>
<option value="NEW"><?php echo $l->t('Add Server Configuration');?></option>
- </select></p>
+ </select>
+ <button id="ldap_action_delete_configuration" name="ldap_action_delete_configuration">Delete Configuration</button>
+ </p>
<p><label for="ldap_host"><?php echo $l->t('Host');?></label><input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>" data-default="<?php echo $_['ldap_host_default']; ?>" title="<?php echo $l->t('You can omit the protocol, except you require SSL. Then start with ldaps://');?>"></p>
<p><label for="ldap_base"><?php echo $l->t('Base DN');?></label><textarea id="ldap_base" name="ldap_base" placeholder="<?php echo $l->t('One Base DN per line');?>" title="<?php echo $l->t('You can specify Base DN for users and groups in the Advanced tab');?>" data-default="<?php echo $_['ldap_base_default']; ?>" ><?php echo $_['ldap_base']; ?></textarea></p>
<p><label for="ldap_dn"><?php echo $l->t('User DN');?></label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" data-default="<?php echo $_['ldap_dn_default']; ?>" title="<?php echo $l->t('The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.');?>" /></p>