Merge pull request #5568 from nextcloud/ldap-agent-credentials-safe
Ldap agent credentials save
This commit is contained in:
commit
2bfa1ce5c3
|
@ -209,11 +209,6 @@ select[multiple=multiple] + button {
|
||||||
color: #777;
|
color: #777;
|
||||||
}
|
}
|
||||||
|
|
||||||
.outoftheway {
|
|
||||||
position: absolute;
|
|
||||||
left: -2000px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ldapSettings {
|
#ldapSettings {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
|
@ -43,11 +43,15 @@ OCA = OCA || {};
|
||||||
},
|
},
|
||||||
ldap_dn: {
|
ldap_dn: {
|
||||||
$element: $('#ldap_dn'),
|
$element: $('#ldap_dn'),
|
||||||
setMethod: 'setAgentDN'
|
setMethod: 'setAgentDN',
|
||||||
|
preventAutoSave: true,
|
||||||
|
$saveButton: $('.ldapSaveAgentCredentials')
|
||||||
},
|
},
|
||||||
ldap_agent_password: {
|
ldap_agent_password: {
|
||||||
$element: $('#ldap_agent_password'),
|
$element: $('#ldap_agent_password'),
|
||||||
setMethod: 'setAgentPwd'
|
setMethod: 'setAgentPwd',
|
||||||
|
preventAutoSave: true,
|
||||||
|
$saveButton: $('.ldapSaveAgentCredentials')
|
||||||
},
|
},
|
||||||
ldap_base: {
|
ldap_base: {
|
||||||
$element: $('#ldap_base'),
|
$element: $('#ldap_base'),
|
||||||
|
@ -65,7 +69,11 @@ OCA = OCA || {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.setManagedItems(items);
|
this.setManagedItems(items);
|
||||||
_.bindAll(this, 'onPortButtonClick', 'onBaseDNButtonClick', 'onBaseDNTestButtonClick');
|
_.bindAll(this,
|
||||||
|
'onPortButtonClick',
|
||||||
|
'onBaseDNButtonClick',
|
||||||
|
'onBaseDNTestButtonClick'
|
||||||
|
);
|
||||||
this.managedItems.ldap_port.$relatedElements.click(this.onPortButtonClick);
|
this.managedItems.ldap_port.$relatedElements.click(this.onPortButtonClick);
|
||||||
this.managedItems.ldap_base.$detectButton.click(this.onBaseDNButtonClick);
|
this.managedItems.ldap_base.$detectButton.click(this.onBaseDNButtonClick);
|
||||||
this.managedItems.ldap_base.$testButton.click(this.onBaseDNTestButtonClick);
|
this.managedItems.ldap_base.$testButton.click(this.onBaseDNTestButtonClick);
|
||||||
|
|
|
@ -53,6 +53,7 @@ OCA = OCA || {};
|
||||||
setManagedItems: function(managedItems) {
|
setManagedItems: function(managedItems) {
|
||||||
this.managedItems = managedItems;
|
this.managedItems = managedItems;
|
||||||
this._enableAutoSave();
|
this._enableAutoSave();
|
||||||
|
this._enableSaveButton();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,7 +320,10 @@ OCA = OCA || {};
|
||||||
|
|
||||||
for(var id in this.managedItems) {
|
for(var id in this.managedItems) {
|
||||||
if(_.isUndefined(this.managedItems[id].$element)
|
if(_.isUndefined(this.managedItems[id].$element)
|
||||||
|| _.isUndefined(this.managedItems[id].setMethod)) {
|
|| _.isUndefined(this.managedItems[id].setMethod)
|
||||||
|
|| (!_.isUndefined(this.managedItems[id].preventAutoSave)
|
||||||
|
&& this.managedItems[id].preventAutoSave === true)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var $element = this.managedItems[id].$element;
|
var $element = this.managedItems[id].$element;
|
||||||
|
@ -331,6 +335,35 @@ OCA = OCA || {};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set's up save-button behavior (essentially used for agent dn and pwd)
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_enableSaveButton: function() {
|
||||||
|
var view = this;
|
||||||
|
|
||||||
|
// TODO: this is not nice, because it fires one request per change
|
||||||
|
// in the scenario this happens twice, causes detectors to run
|
||||||
|
// duplicated etc. To have this work properly, the wizard endpoint
|
||||||
|
// must accept setting multiple changes. Instead of messing around
|
||||||
|
// with old ajax/wizard.php use this opportunity and create a
|
||||||
|
// Controller
|
||||||
|
for(var id in this.managedItems) {
|
||||||
|
if(_.isUndefined(this.managedItems[id].$element)
|
||||||
|
|| _.isUndefined(this.managedItems[id].$saveButton)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
(function (item) {
|
||||||
|
item.$saveButton.click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
view._requestSave(item.$element);
|
||||||
|
});
|
||||||
|
})(this.managedItems[id]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initializes a multiSelect element
|
* initializes a multiSelect element
|
||||||
*
|
*
|
||||||
|
|
|
@ -37,9 +37,13 @@ namespace OCA\User_LDAP;
|
||||||
* @property int ldapPagingSize holds an integer
|
* @property int ldapPagingSize holds an integer
|
||||||
*/
|
*/
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
|
||||||
protected $configPrefix = null;
|
protected $configPrefix = null;
|
||||||
protected $configRead = false;
|
protected $configRead = false;
|
||||||
|
/**
|
||||||
|
* @var string[] pre-filled with one reference key so that at least one entry is written on save request and
|
||||||
|
* the config ID is registered
|
||||||
|
*/
|
||||||
|
protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive'];
|
||||||
|
|
||||||
//settings
|
//settings
|
||||||
protected $config = array(
|
protected $config = array(
|
||||||
|
@ -187,7 +191,9 @@ class Configuration {
|
||||||
$this->$setMethod($key, $val);
|
$this->$setMethod($key, $val);
|
||||||
if(is_array($applied)) {
|
if(is_array($applied)) {
|
||||||
$applied[] = $inputKey;
|
$applied[] = $inputKey;
|
||||||
|
// storing key as index avoids duplication, and as value for simplicity
|
||||||
}
|
}
|
||||||
|
$this->unsavedChanges[$key] = $key;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -240,11 +246,12 @@ class Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saves the current Configuration in the database
|
* saves the current config changes in the database
|
||||||
*/
|
*/
|
||||||
public function saveConfiguration() {
|
public function saveConfiguration() {
|
||||||
$cta = array_flip($this->getConfigTranslationArray());
|
$cta = array_flip($this->getConfigTranslationArray());
|
||||||
foreach($this->config as $key => $value) {
|
foreach($this->unsavedChanges as $key) {
|
||||||
|
$value = $this->config[$key];
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'ldapAgentPassword':
|
case 'ldapAgentPassword':
|
||||||
$value = base64_encode($value);
|
$value = base64_encode($value);
|
||||||
|
@ -275,6 +282,7 @@ class Configuration {
|
||||||
}
|
}
|
||||||
$this->saveValue($cta[$key], $value);
|
$this->saveValue($cta[$key], $value);
|
||||||
}
|
}
|
||||||
|
$this->unsavedChanges = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -150,7 +150,7 @@ class Connection extends LDAPUtility {
|
||||||
$this->configuration->$name = $value;
|
$this->configuration->$name = $value;
|
||||||
$after = $this->configuration->$name;
|
$after = $this->configuration->$name;
|
||||||
if($before !== $after) {
|
if($before !== $after) {
|
||||||
if ($this->configID !== '') {
|
if ($this->configID !== '' && $this->configID !== null) {
|
||||||
$this->configuration->saveConfiguration();
|
$this->configuration->saveConfiguration();
|
||||||
}
|
}
|
||||||
$this->validateConfiguration();
|
$this->validateConfiguration();
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
<div class="outoftheway">
|
|
||||||
<!-- Hack for Safari and Chromium/Chrome which ignore autocomplete="off" -->
|
|
||||||
<input type="text" id="fake_user" name="fake_user" autocomplete="off" />
|
|
||||||
<input type="password" id="fake_password" name="fake_password"
|
|
||||||
autocomplete="off" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<fieldset id="ldapWizard1">
|
<fieldset id="ldapWizard1">
|
||||||
<p>
|
<p>
|
||||||
<select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
|
<select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
|
||||||
|
@ -54,6 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tablerow"> </div>
|
||||||
<div class="tablerow">
|
<div class="tablerow">
|
||||||
<input type="text" id="ldap_dn" name="ldap_dn"
|
<input type="text" id="ldap_dn" name="ldap_dn"
|
||||||
class="tablecell"
|
class="tablecell"
|
||||||
|
@ -68,7 +62,11 @@
|
||||||
placeholder="<?php p($l->t('Password'));?>" autocomplete="off"
|
placeholder="<?php p($l->t('Password'));?>" autocomplete="off"
|
||||||
title="<?php p($l->t('For anonymous access, leave DN and Password empty.'));?>"
|
title="<?php p($l->t('For anonymous access, leave DN and Password empty.'));?>"
|
||||||
/>
|
/>
|
||||||
|
<button class="ldapSaveAgentCredentials" name="ldapSaveAgentCredentials" type="button">
|
||||||
|
<?php p($l->t('Save Credentials'));?>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tablerow"> </div>
|
||||||
|
|
||||||
<div class="tablerow">
|
<div class="tablerow">
|
||||||
<textarea id="ldap_base" name="ldap_base"
|
<textarea id="ldap_base" name="ldap_base"
|
||||||
|
|
Loading…
Reference in New Issue