2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import _ from '_';
|
|
|
|
import ko from 'ko';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import {createCommand, trim, boolToAjax} from 'Common/Utils';
|
|
|
|
import {phpInfo} from 'Common/Links';
|
|
|
|
import {StorageResultType} from 'Common/Enums';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import {settingsGet} from 'Storage/Settings';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import AppAdminStore from 'Stores/Admin/App';
|
|
|
|
import CapaAdminStore from 'Stores/Admin/Capa';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
import Remote from 'Remote/Admin/Ajax';
|
|
|
|
|
|
|
|
class SecurityAdminSettings
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
this.useLocalProxyForExternalImages = AppAdminStore.useLocalProxyForExternalImages;
|
2015-01-27 05:06:00 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.weakPassword = AppAdminStore.weakPassword;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaOpenPGP = CapaAdminStore.openPGP;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth;
|
|
|
|
this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaTwoFactorAuth.subscribe((value) => {
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
this.capaTwoFactorAuthForce(false);
|
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.verifySslCertificate = ko.observable(!!settingsGet('VerifySslCertificate'));
|
|
|
|
this.allowSelfSigned = ko.observable(!!settingsGet('AllowSelfSigned'));
|
2014-10-18 23:19:37 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.verifySslCertificate.subscribe((value) => {
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
this.allowSelfSigned(true);
|
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminLogin = ko.observable(settingsGet('AdminLogin'));
|
|
|
|
this.adminLoginError = ko.observable(false);
|
|
|
|
this.adminPassword = ko.observable('');
|
|
|
|
this.adminPasswordNew = ko.observable('');
|
|
|
|
this.adminPasswordNew2 = ko.observable('');
|
|
|
|
this.adminPasswordNewError = ko.observable(false);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPasswordUpdateError = ko.observable(false);
|
|
|
|
this.adminPasswordUpdateSuccess = ko.observable(false);
|
2015-04-08 00:39:43 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPassword.subscribe(() => {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
2014-10-18 23:29:09 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminLogin.subscribe(() => {
|
|
|
|
this.adminLoginError(false);
|
|
|
|
});
|
2016-07-01 06:50:11 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPasswordNew.subscribe(() => {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
});
|
2015-01-06 05:41:22 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPasswordNew2.subscribe(() => {
|
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
|
|
|
this.adminPasswordNewError(false);
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.saveNewAdminPasswordCommand = createCommand(this, () => {
|
|
|
|
|
|
|
|
if ('' === trim(this.adminLogin()))
|
|
|
|
{
|
|
|
|
this.adminLoginError(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.adminPasswordNew() !== this.adminPasswordNew2())
|
|
|
|
{
|
|
|
|
this.adminPasswordNewError(true);
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPasswordUpdateError(false);
|
|
|
|
this.adminPasswordUpdateSuccess(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
|
|
|
'Login': this.adminLogin(),
|
|
|
|
'Password': this.adminPassword(),
|
|
|
|
'NewPassword': this.adminPasswordNew()
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, () => '' !== trim(this.adminLogin()) && '' !== this.adminPassword());
|
|
|
|
|
|
|
|
this.onNewAdminPasswordResponse = _.bind(this.onNewAdminPasswordResponse, this);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-07-16 05:29:42 +08:00
|
|
|
|
|
|
|
onNewAdminPasswordResponse(result, data) {
|
|
|
|
if (StorageResultType.Success === result && data && data.Result)
|
|
|
|
{
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
|
|
|
|
this.adminPasswordUpdateSuccess(true);
|
|
|
|
|
|
|
|
this.weakPassword(!!data.Result.Weak);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.adminPasswordUpdateError(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onBuild() {
|
|
|
|
this.capaOpenPGP.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'CapaOpenPGP': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaTwoFactorAuth.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'CapaTwoFactorAuth': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaTwoFactorAuthForce.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'CapaTwoFactorAuthForce': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.useLocalProxyForExternalImages.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'UseLocalProxyForExternalImages': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.verifySslCertificate.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'VerifySslCertificate': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.allowSelfSigned.subscribe((value) => {
|
|
|
|
Remote.saveAdminConfig(null, {
|
|
|
|
'AllowSelfSigned': boolToAjax(value)
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onHide() {
|
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
phpInfoLink() {
|
|
|
|
return phpInfo();
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-07-16 03:54:37 +08:00
|
|
|
export {SecurityAdminSettings, SecurityAdminSettings as default};
|