Ajaxifiy Settings Save
This commit is contained in:
parent
229a25f41a
commit
6d84aa93d3
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - user_ldap
|
||||
*
|
||||
* @author Arthur Schiwon
|
||||
* @copyright 2013 Arthur Schiwon blizzz@owncloud.com
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// 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();
|
|
@ -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') {
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<p><label for="ldap_cache_ttl">Cache Time-To-Live</label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" value="<?php echo $_['ldap_cache_ttl']; ?>" title="<?php echo $l->t('in seconds. A change empties the cache.');?>" data-default="<?php echo $_['ldap_cache_ttl_default']; ?>" /></p>
|
||||
<p><label for="home_folder_naming_rule">User Home Folder Naming Rule</label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" value="<?php echo $_['home_folder_naming_rule']; ?>" title="<?php echo $l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.');?>" data-default="<?php echo $_['home_folder_naming_rule_default']; ?>" /></p>
|
||||
</fieldset>
|
||||
<input type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection">Test Configuration</button> <a href="http://owncloud.org/support/ldap-backend/" target="_blank"><img src="<?php echo OCP\Util::imagePath('', 'actions/info.png'); ?>" style="height:1.75ex" /> <?php echo $l->t('Help');?></a>
|
||||
<input id="ldap_submit" type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection">Test Configuration</button> <a href="http://owncloud.org/support/ldap-backend/" target="_blank"><img src="<?php echo OCP\Util::imagePath('', 'actions/info.png'); ?>" style="height:1.75ex" /> <?php echo $l->t('Help');?></a>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue