From a53addf8250ea47a36837463f15122339123aeff Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 18 Jan 2013 01:23:15 +0100 Subject: LDAP: first basics for multiserver config ui --- apps/user_ldap/js/settings.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 7063eead96a..8cd31301f2e 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -21,4 +21,37 @@ $(document).ready(function() { } ); }); + + $('#ldap_serverconfig_chooser').change(function(event) { + value = $('#ldap_serverconfig_chooser option:selected:first').attr('value'); + if(value == 'NEW') { + $.post( + OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'), + function (result) { + if(result.status == 'success') { + OC.dialogs.confirm( + 'Take over settings from recent server configuration?', + 'Keep settings?', + function(keep) { + if(!keep) { + $('#ldap').find('input[type=text], input[type=password], textarea, select').val(''); + $('#ldap').find('input[type=checkbox]').removeAttr('checked'); + } + } + ); + $('#ldap_serverconfig_chooser option:selected:first').removeAttr('selected'); + var html = ''; + $('#ldap_serverconfig_chooser option:last').before(html); + } else { + OC.dialogs.alert( + result.message, + 'Cannot add server configuration' + ); + } + } + ); + } else { + alert(value); + } + }); }); \ No newline at end of file -- cgit v1.2.3 From 805f900b1980ae1f5d69395fd646a9a4605b7c68 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 18 Jan 2013 13:45:39 +0100 Subject: LDAP: pass defaults to settings form, and restore them on creating a new configuration if wanted --- apps/user_ldap/js/settings.js | 12 +++++++-- apps/user_ldap/settings.php | 13 +++++++++- apps/user_ldap/templates/settings.php | 48 +++++++++++++++++------------------ 3 files changed, 46 insertions(+), 27 deletions(-) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 8cd31301f2e..0b8f141dfa2 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -34,8 +34,16 @@ $(document).ready(function() { 'Keep settings?', function(keep) { if(!keep) { - $('#ldap').find('input[type=text], input[type=password], textarea, select').val(''); - $('#ldap').find('input[type=checkbox]').removeAttr('checked'); + $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() { + $(this).val($(this).attr('data-default')); + }); + $('#ldap').find('input[type=checkbox]').each(function() { + if($(this).attr('data-default') == 1) { + $(this).attr('checked', 'checked'); + } else { + $(this).removeAttr('checked'); + } + }); } } ); diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 73e4f0b6f4b..f3f0826739f 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -64,7 +64,7 @@ if($_POST) { } } if($clearCache) { - $ldap = new \OCA\user_ldap\lib\Connection('user_ldap'); + $ldap = new \OCA\user_ldap\lib\Connection(); $ldap->clearCache(); } } @@ -88,4 +88,15 @@ $hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:')); $tmpl->assign('home_folder_naming_rule', $hfnr, ''); $tmpl->assign('serverConfigurationOptions', '', false); +// assign default values +if(!isset($ldap)) { + $ldap = new \OCA\user_ldap\lib\Connection(); +} +$defaults = $ldap->getDefaults(); +foreach($defaults as $key => $default) { + $tmpl->assign($key.'_default', $default); +} + +// $tmpl->assign(); + return $tmpl->fetchPage(); diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index c3ec20fc847..90a46a1733a 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -17,32 +17,32 @@

-

-

-

-

-


t('use %%uid placeholder, e.g. "uid=%%uid"');?>

-


t('without any placeholder, e.g. "objectClass=person".');?>

-


t('without any placeholder, e.g. "objectClass=posixGroup".');?>

+

+

+

+

+


t('use %%uid placeholder, e.g. "uid=%%uid"');?>

+


t('without any placeholder, e.g. "objectClass=person".');?>

+


t('without any placeholder, e.g. "objectClass=posixGroup".');?>

-

-

-

-

title="t('When switched on, ownCloud will only connect to the replica server.');?>" />

-

-

-

-

title="t('Do not use it for SSL connections, it will fail.');?>" />

-

>

-

>
t('Not recommended, use for testing only.');?>

-

-

-

-

-

-

-

+

+

+

+

data-default="" title="t('When switched on, ownCloud will only connect to the replica server.');?>" />

+

+

+

+

data-default="" title="t('Do not use it for SSL connections, it will fail.');?>" />

+

>

+

>
t('Not recommended, use for testing only.');?>

+

+

+

+

+

+

+

t('Help');?> -- cgit v1.2.3 From 6d84aa93d3ddf4f7d3c8599cba17bb02fd6df9e9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sun, 20 Jan 2013 18:02:44 +0100 Subject: Ajaxifiy Settings Save --- apps/user_ldap/ajax/setConfiguration.php | 33 +++++++++++++++++++++ apps/user_ldap/js/settings.js | 14 +++++++++ apps/user_ldap/lib/connection.php | 51 +++++++++++++++++++++++++++++--- apps/user_ldap/templates/settings.php | 2 +- 4 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 apps/user_ldap/ajax/setConfiguration.php (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php new file mode 100644 index 00000000000..206487c7e0a --- /dev/null +++ b/apps/user_ldap/ajax/setConfiguration.php @@ -0,0 +1,33 @@ +. + * + */ + +// Check user and app status +OCP\JSON::checkAdminUser(); +OCP\JSON::checkAppEnabled('user_ldap'); +OCP\JSON::callCheck(); + +$prefix = $_POST['ldap_serverconfig_chooser']; +$connection = new \OCA\user_ldap\lib\Connection($prefix); +$connection->setConfiguration($_POST); +$connection->saveConfiguration(); +OCP\JSON::success(); \ No newline at end of file diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 0b8f141dfa2..a07d140cf86 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -22,6 +22,20 @@ $(document).ready(function() { ); }); + $('#ldap_submit').click(function(event) { + event.preventDefault(); + $.post( + OC.filePath('user_ldap','ajax','setConfiguration.php'), + $('#ldap').serialize(), + function (result) { + if (result.status == 'success') { + $('#notification').text(t('user_ldap', 'LDAP Configuration Saved')); + $('#notification').fadeIn(); + } + } + ); + }); + $('#ldap_serverconfig_chooser').change(function(event) { value = $('#ldap_serverconfig_chooser option:selected:first').attr('value'); if(value == 'NEW') { diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index 926691c2d91..ebc46bf3b94 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -195,6 +195,12 @@ class Connection { $defaults[$varname]); } + private function setValue($varname, $value) { + \OCP\Config::setAppValue($this->configID, + $this->configPrefix.$varname, + $value); + } + /** * Caches the general LDAP configuration. */ @@ -205,7 +211,7 @@ class Connection { $this->config['ldapHost'] = $this->$v('ldap_host'); $this->config['ldapBackupHost'] = $this->$v('ldap_backup_host'); $this->config['ldapPort'] = $this->$v('ldap_port'); - $this->config['ldapBackupPort'] = $this->$v('ldapPort'); + $this->config['ldapBackupPort'] = $this->$v('ldap_backup_port'); $this->config['ldapOverrideMainServer'] = $this->$v('ldap_override_main_server'); $this->config['ldapAgentName'] = $this->$v('ldap_dn'); @@ -253,6 +259,13 @@ class Connection { } } + private function getConfigTranslationArray() { + static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName', + + 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'turn_off_cert_check' => 'turnOffCertCheck'); + return $array; + } + /** * @brief set LDAP configuration with values delivered by an array, not read from configuration * @param $config array that holds the config parameters in an associated array @@ -264,9 +277,7 @@ class Connection { return false; } - $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName', - - 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule'); + $params = $this->getConfigTranslationArray(); foreach($config as $parameter => $value) { if(isset($this->config[$parameter])) { @@ -287,11 +298,42 @@ class Connection { return $this->configured; } + public function saveConfiguration() { + $trans = array_flip($this->getConfigTranslationArray()); + foreach($this->config as $key => $value) { + \OCP\Util::writeLog('user_ldap', 'LDAP: storing key '.$key.' value '.$value, \OCP\Util::DEBUG); + switch ($key) { + case 'ldap_agent_password': + $value = base64_encode($value); + break; + case 'home_folder_naming_rule': + $value = empty($value) ? 'opt:username' : 'attr:'.$value; + break; + case 'ldapIgnoreNamingRules': + case 'ldapOverrideUuidAttribute': + case 'hasPagedResultSupport': + continue; + default: + if(is_null($value)) { + $value = 0; + } + } + + $this->setValue($trans[$key], $value); + } + } + /** * @brief get the current LDAP configuration * @return array */ public function getConfiguration() { + $trans = $this->getConfigTranslationArray(); + $config = array(); + foreach($trans as $classKey => $dbKey) { + $config[$dbKey] = $this->config[$classKey]; + } + return $this->config; } @@ -394,6 +436,7 @@ class Connection { 'ldap_uuid_attribute' => 'auto', 'ldap_override_uuid_attribute' => 0, 'home_folder_naming_rule' => '', + 'ldap_turn_off_cert_check' => 0, ); } diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 90a46a1733a..6b95f8660eb 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -44,7 +44,7 @@

- t('Help');?> + t('Help');?> -- cgit v1.2.3 From 06c284f6cc6256b22f645d2d35f966c0bc98f4df Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 23 Jan 2013 23:41:35 +0100 Subject: LDAP settings: read configuration when another server config is chosen --- apps/user_ldap/ajax/getConfiguration.php | 31 ++++++++++++++++++++++++++ apps/user_ldap/js/settings.js | 37 +++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 apps/user_ldap/ajax/getConfiguration.php (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/ajax/getConfiguration.php b/apps/user_ldap/ajax/getConfiguration.php new file mode 100644 index 00000000000..dfae68d2dc9 --- /dev/null +++ b/apps/user_ldap/ajax/getConfiguration.php @@ -0,0 +1,31 @@ +. + * + */ + +// Check user and app status +OCP\JSON::checkAdminUser(); +OCP\JSON::checkAppEnabled('user_ldap'); +OCP\JSON::callCheck(); + +$prefix = $_POST['ldap_serverconfig_chooser']; +$connection = new \OCA\user_ldap\lib\Connection($prefix); +OCP\JSON::success(array('configuration' => $connection->getConfiguration())); \ No newline at end of file diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index a07d140cf86..66876cadaf7 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -49,6 +49,9 @@ $(document).ready(function() { function(keep) { if(!keep) { $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() { + if($(this).attr('id') == 'ldap_serverconfig_chooser') { + return; + } $(this).val($(this).attr('data-default')); }); $('#ldap').find('input[type=checkbox]').each(function() { @@ -61,8 +64,8 @@ $(document).ready(function() { } } ); - $('#ldap_serverconfig_chooser option:selected:first').removeAttr('selected'); - var html = ''; + $('#ldap_serverconfig_chooser option:selected').removeAttr('selected'); + var html = ''; $('#ldap_serverconfig_chooser option:last').before(html); } else { OC.dialogs.alert( @@ -73,7 +76,35 @@ $(document).ready(function() { } ); } else { - alert(value); + $.post( + OC.filePath('user_ldap','ajax','getConfiguration.php'), + $('#ldap_serverconfig_chooser').serialize(), + function (result) { + if(result.status == 'success') { + $.each(result.configuration, function(configkey, configvalue) { + elementID = '#'+configkey; + + //deal with Checkboxes + if($(elementID).is('input[type=checkbox]')) { + if(configvalue == 1) { + $(elementID).attr('checked', 'checked'); + } else { + $(elementID).removeAttr('checked'); + } + return; + } + + //On Textareas, Multi-Line Settings come as array + if($(elementID).is('textarea') && $.isArray(configvalue)) { + configvalue = configvalue.join("\n"); + } + + // assign the value + $('#'+configkey).val(configvalue); + }); + } + } + ); } }); }); \ No newline at end of file -- cgit v1.2.3 From b2ea78c00d203d7a70952dc7dab095cbeafb0b95 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 24 Jan 2013 13:00:40 +0100 Subject: LDAP: improve and cleanup settings JS --- apps/user_ldap/js/settings.js | 95 ++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 42 deletions(-) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 66876cadaf7..c3484da5ac6 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -1,6 +1,57 @@ +var LdapConfiguration = { + refreshConfig: function() { + $.post( + OC.filePath('user_ldap','ajax','getConfiguration.php'), + $('#ldap_serverconfig_chooser').serialize(), + function (result) { + if(result.status == 'success') { + $.each(result.configuration, function(configkey, configvalue) { + elementID = '#'+configkey; + + //deal with Checkboxes + if($(elementID).is('input[type=checkbox]')) { + if(configvalue == 1) { + $(elementID).attr('checked', 'checked'); + } else { + $(elementID).removeAttr('checked'); + } + return; + } + + //On Textareas, Multi-Line Settings come as array + if($(elementID).is('textarea') && $.isArray(configvalue)) { + configvalue = configvalue.join("\n"); + } + + // assign the value + $('#'+configkey).val(configvalue); + }); + } + } + ); + }, + + resetDefaults: function() { + $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() { + if($(this).attr('id') == 'ldap_serverconfig_chooser') { + return; + } + $(this).val($(this).attr('data-default')); + }); + $('#ldap').find('input[type=checkbox]').each(function() { + if($(this).attr('data-default') == 1) { + $(this).attr('checked', 'checked'); + } else { + $(this).removeAttr('checked'); + } + }); + } +} + $(document).ready(function() { $('#ldapSettings').tabs(); $('#ldap_action_test_connection').button(); + LdapConfiguration.refreshConfig(); $('#ldap_action_test_connection').click(function(event){ event.preventDefault(); $.post( @@ -48,19 +99,7 @@ $(document).ready(function() { 'Keep settings?', function(keep) { if(!keep) { - $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() { - if($(this).attr('id') == 'ldap_serverconfig_chooser') { - return; - } - $(this).val($(this).attr('data-default')); - }); - $('#ldap').find('input[type=checkbox]').each(function() { - if($(this).attr('data-default') == 1) { - $(this).attr('checked', 'checked'); - } else { - $(this).removeAttr('checked'); - } - }); + LdapConfiguration.resetDefaults(); } } ); @@ -76,35 +115,7 @@ $(document).ready(function() { } ); } else { - $.post( - OC.filePath('user_ldap','ajax','getConfiguration.php'), - $('#ldap_serverconfig_chooser').serialize(), - function (result) { - if(result.status == 'success') { - $.each(result.configuration, function(configkey, configvalue) { - elementID = '#'+configkey; - - //deal with Checkboxes - if($(elementID).is('input[type=checkbox]')) { - if(configvalue == 1) { - $(elementID).attr('checked', 'checked'); - } else { - $(elementID).removeAttr('checked'); - } - return; - } - - //On Textareas, Multi-Line Settings come as array - if($(elementID).is('textarea') && $.isArray(configvalue)) { - configvalue = configvalue.join("\n"); - } - - // assign the value - $('#'+configkey).val(configvalue); - }); - } - } - ); + LdapConfiguration.refreshConfig(); } }); }); \ No newline at end of file -- cgit v1.2.3 From 5b9e181198a61f5c123f5e8d5acec4c30cc8908a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 24 Jan 2013 14:11:53 +0100 Subject: LDAP: implement deleteConfiguration feature --- apps/user_ldap/js/settings.js | 33 ++++++++++++++++++++++++ apps/user_ldap/lib/helper.php | 47 +++++++++++++++++++++++++++-------- apps/user_ldap/templates/settings.php | 4 ++- 3 files changed, 73 insertions(+), 11 deletions(-) (limited to 'apps/user_ldap/js/settings.js') 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 @@

+ + +

-- cgit v1.2.3 From 3e99f12120dde810e3976b270666751b52c98959 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 24 Jan 2013 22:47:25 +0100 Subject: LDAP: make settings strings in JS translatable --- apps/user_ldap/js/settings.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 49bbc60d81c..7d0a85248f3 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -59,7 +59,7 @@ var LdapConfiguration = { } else { OC.dialogs.alert( result.message, - 'Deletion failed' + t('user_ldap', 'Deletion failed') ); } } @@ -81,12 +81,12 @@ $(document).ready(function() { if (result.status == 'success') { OC.dialogs.alert( result.message, - 'Connection test succeeded' + t('user_ldap', 'Connection test succeeded') ); } else { OC.dialogs.alert( result.message, - 'Connection test failed' + t('user_ldap', 'Connection test failed') ); } } @@ -96,8 +96,8 @@ $(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', + t('user_ldap', 'Do you really want to delete the current Server Configuration?'), + t('user_ldap', 'Confirm Deletion'), function(deleteConfiguration) { if(deleteConfiguration) { LdapConfiguration.deleteConfiguration(); @@ -128,8 +128,8 @@ $(document).ready(function() { function (result) { if(result.status == 'success') { OC.dialogs.confirm( - 'Take over settings from recent server configuration?', - 'Keep settings?', + t('user_ldap', 'Take over settings from recent server configuration?'), + t('user_ldap', 'Keep settings?'), function(keep) { if(!keep) { LdapConfiguration.resetDefaults(); @@ -142,7 +142,7 @@ $(document).ready(function() { } else { OC.dialogs.alert( result.message, - 'Cannot add server configuration' + t('user_ldap', 'Cannot add server configuration') ); } } -- cgit v1.2.3 From a8ac4bdf79b65239c6aeef4e6d0d642bedefc9c3 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 30 Jan 2013 02:30:24 +0100 Subject: LDAP: Always preset configuration prefix when no configuratin is stored or all remaining ones are deleted --- apps/user_ldap/js/settings.js | 60 ++++++++++++++++++++++++++----------------- apps/user_ldap/settings.php | 3 +++ 2 files changed, 39 insertions(+), 24 deletions(-) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index 7d0a85248f3..d1b1b715a57 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -1,5 +1,9 @@ var LdapConfiguration = { refreshConfig: function() { + if($('#ldap_serverconfig_chooser option').length < 2) { + LdapConfiguration.addConfiguration(true); + return; + } $.post( OC.filePath('user_ldap','ajax','getConfiguration.php'), $('#ldap_serverconfig_chooser').serialize(), @@ -64,6 +68,37 @@ var LdapConfiguration = { } } ); + }, + + addConfiguration: function(doNotAsk) { + $.post( + OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'), + function (result) { + if(result.status == 'success') { + if(doNotAsk) { + LdapConfiguration.resetDefaults(); + } else { + OC.dialogs.confirm( + t('user_ldap', 'Take over settings from recent server configuration?'), + t('user_ldap', 'Keep settings?'), + function(keep) { + if(!keep) { + LdapConfiguration.resetDefaults(); + } + } + ); + } + $('#ldap_serverconfig_chooser option:selected').removeAttr('selected'); + var html = ''; + $('#ldap_serverconfig_chooser option:last').before(html); + } else { + OC.dialogs.alert( + result.message, + t('user_ldap', 'Cannot add server configuration') + ); + } + } + ); } } @@ -123,30 +158,7 @@ $(document).ready(function() { $('#ldap_serverconfig_chooser').change(function(event) { value = $('#ldap_serverconfig_chooser option:selected:first').attr('value'); if(value == 'NEW') { - $.post( - OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'), - function (result) { - if(result.status == 'success') { - OC.dialogs.confirm( - t('user_ldap', 'Take over settings from recent server configuration?'), - t('user_ldap', 'Keep settings?'), - function(keep) { - if(!keep) { - LdapConfiguration.resetDefaults(); - } - } - ); - $('#ldap_serverconfig_chooser option:selected').removeAttr('selected'); - var html = ''; - $('#ldap_serverconfig_chooser option:last').before(html); - } else { - OC.dialogs.alert( - result.message, - t('user_ldap', 'Cannot add server configuration') - ); - } - } - ); + LdapConfiguration.addConfiguration(false); } else { LdapConfiguration.refreshConfig(); } diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 5b679683f27..d5d2f648b38 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -49,6 +49,9 @@ foreach($prefixes as $prefix) { $scoHtml .= ''; $sel = ''; } +if(count($prefixes) == 0) { + $scoHtml .= ''; +} $tmpl->assign('serverConfigurationOptions', $scoHtml, false); // assign default values -- cgit v1.2.3 From 14bc6f8c6c87bbb16529d2e52208ddab9c56fde6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 30 Jan 2013 03:34:51 +0100 Subject: LDAP: working visual feedback on save. Save button will be highlighted green or red. --- apps/user_ldap/js/settings.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'apps/user_ldap/js/settings.js') diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index d1b1b715a57..166761bc1ff 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -104,6 +104,7 @@ var LdapConfiguration = { $(document).ready(function() { $('#ldapSettings').tabs(); + $('#ldap_submit').button(); $('#ldap_action_test_connection').button(); $('#ldap_action_delete_configuration').button(); LdapConfiguration.refreshConfig(); @@ -147,9 +148,18 @@ $(document).ready(function() { OC.filePath('user_ldap','ajax','setConfiguration.php'), $('#ldap').serialize(), function (result) { + bgcolor = $('#ldap_submit').css('background'); if (result.status == 'success') { - $('#notification').text(t('user_ldap', 'LDAP Configuration Saved')); - $('#notification').fadeIn(); + //the dealing with colors is a but ugly, but the jQuery version in use has issues with rgba colors + $('#ldap_submit').css('background', '#fff'); + $('#ldap_submit').effect('highlight', {'color':'#A8FA87'}, 5000, function() { + $('#ldap_submit').css('background', bgcolor); + }); + } else { + $('#ldap_submit').css('background', '#fff'); + $('#ldap_submit').effect('highlight', {'color':'#E97'}, 5000, function() { + $('#ldap_submit').css('background', bgcolor); + }); } } ); -- cgit v1.2.3