LDAP: implement deleteConfiguration feature

This commit is contained in:
Arthur Schiwon 2013-01-24 14:11:53 +01:00
parent 3bf38c7a84
commit 5b9e181198
3 changed files with 73 additions and 11 deletions

View File

@ -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(

View File

@ -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;
}
}

View File

@ -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>