From 6d84aa93d3ddf4f7d3c8599cba17bb02fd6df9e9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sun, 20 Jan 2013 18:02:44 +0100 Subject: [PATCH] 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 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');?> -- 2.39.5