2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
|
|
|
Links = require('Common/Links'),
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AppAdminStore = require('Stores/Admin/App'),
|
|
|
|
CapaAdminStore = require('Stores/Admin/Capa'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
|
|
|
Remote = require('Remote/Admin/Ajax');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function SecurityAdminSettings()
|
|
|
|
{
|
|
|
|
this.useLocalProxyForExternalImages = AppAdminStore.useLocalProxyForExternalImages;
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.weakPassword = AppAdminStore.weakPassword;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.capaOpenPGP = CapaAdminStore.openPGP;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth;
|
|
|
|
this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.capaTwoFactorAuth.subscribe(function(bValue) {
|
|
|
|
if (!bValue)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.capaTwoFactorAuthForce(false);
|
|
|
|
}
|
|
|
|
}, this);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.verifySslCertificate = ko.observable(!!Settings.settingsGet('VerifySslCertificate'));
|
|
|
|
this.allowSelfSigned = ko.observable(!!Settings.settingsGet('AllowSelfSigned'));
|
2014-10-18 23:19:37 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.verifySslCertificate.subscribe(function(bValue) {
|
|
|
|
if (!bValue)
|
|
|
|
{
|
|
|
|
this.allowSelfSigned(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminLogin = ko.observable(Settings.settingsGet('AdminLogin'));
|
|
|
|
this.adminLoginError = ko.observable(false);
|
|
|
|
this.adminPassword = ko.observable('');
|
|
|
|
this.adminPasswordNew = ko.observable('');
|
|
|
|
this.adminPasswordNew2 = ko.observable('');
|
|
|
|
this.adminPasswordNewError = ko.observable(false);
|
|
|
|
|
|
|
|
this.adminPasswordUpdateError = ko.observable(false);
|
|
|
|
this.adminPasswordUpdateSuccess = ko.observable(false);
|
|
|
|
|
|
|
|
this.adminPassword.subscribe(function() {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminLogin.subscribe(function() {
|
|
|
|
this.adminLoginError(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminPasswordNew.subscribe(function() {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.adminPasswordNew2.subscribe(function() {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.saveNewAdminPasswordCommand = Utils.createCommand(this, function() {
|
|
|
|
|
|
|
|
if ('' === Utils.trim(this.adminLogin()))
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.adminLoginError(true);
|
|
|
|
return false;
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
if (this.adminPasswordNew() !== this.adminPasswordNew2())
|
|
|
|
{
|
|
|
|
this.adminPasswordNewError(true);
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
2015-04-08 00:39:43 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
|
|
|
'Login': this.adminLogin(),
|
|
|
|
'Password': this.adminPassword(),
|
|
|
|
'NewPassword': this.adminPasswordNew()
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
2014-10-18 23:29:09 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
}, function() {
|
|
|
|
return '' !== Utils.trim(this.adminLogin()) && '' !== this.adminPassword();
|
|
|
|
});
|
2015-01-06 05:41:22 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
SecurityAdminSettings.prototype.onNewAdminPasswordResponse = function(sResult, oData)
|
|
|
|
{
|
|
|
|
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.adminPasswordUpdateSuccess(true);
|
|
|
|
|
|
|
|
this.weakPassword(!!oData.Result.Weak);
|
|
|
|
}
|
|
|
|
else
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.adminPasswordUpdateError(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SecurityAdminSettings.prototype.onBuild = function()
|
|
|
|
{
|
|
|
|
this.capaOpenPGP.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.noop, {
|
|
|
|
'CapaOpenPGP': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.capaTwoFactorAuth.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.noop, {
|
|
|
|
'CapaTwoFactorAuth': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.capaTwoFactorAuthForce.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(Utils.noop, {
|
|
|
|
'CapaTwoFactorAuthForce': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.useLocalProxyForExternalImages.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'UseLocalProxyForExternalImages': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
this.verifySslCertificate.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'VerifySslCertificate': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.allowSelfSigned.subscribe(function(bValue) {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'AllowSelfSigned': bValue ? '1' : '0'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
SecurityAdminSettings.prototype.onHide = function()
|
|
|
|
{
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
SecurityAdminSettings.prototype.phpInfoLink = function()
|
|
|
|
{
|
|
|
|
return Links.phpInfo();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SecurityAdminSettings;
|