snappymail/dev/Settings/Admin/Security.js

123 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-03-16 17:46:22 +08:00
import { Capa } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
2022-02-17 16:36:29 +08:00
import { addObservablesTo, addSubscribablesTo } from 'External/ko';
import Remote from 'Remote/Admin/Fetch';
2016-07-16 05:29:42 +08:00
import { decorateKoCommands } from 'Knoin/Knoin';
2016-09-10 06:38:16 +08:00
export class SecurityAdminSettings /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
2021-03-16 21:15:05 +08:00
this.weakPassword = rl.app.weakPassword;
2014-08-21 23:08:34 +08:00
addObservablesTo(this, {
2021-03-10 18:44:48 +08:00
useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'),
2020-10-27 18:09:24 +08:00
2021-03-10 18:44:48 +08:00
verifySslCertificate: !!SettingsGet('VerifySslCertificate'),
allowSelfSigned: !!SettingsGet('AllowSelfSigned'),
2020-10-27 18:09:24 +08:00
2021-03-10 18:44:48 +08:00
adminLogin: SettingsGet('AdminLogin'),
2020-10-27 18:09:24 +08:00
adminLoginError: false,
adminPassword: '',
adminPasswordNew: '',
adminPasswordNew2: '',
adminPasswordNewError: false,
adminTOTP: SettingsGet('AdminTOTP'),
2020-10-27 18:09:24 +08:00
adminPasswordUpdateError: false,
2021-03-16 17:46:22 +08:00
adminPasswordUpdateSuccess: false,
2021-04-13 01:15:33 +08:00
capaOpenPGP: Settings.capa(Capa.OpenPGP)
2016-07-16 05:29:42 +08:00
});
2016-07-01 06:50:11 +08:00
addSubscribablesTo(this, {
2021-03-16 17:46:22 +08:00
adminPassword: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
},
adminLogin: () => this.adminLoginError(false),
adminPasswordNew: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
adminPasswordNew2: () => {
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
capaOpenPGP: value =>
Remote.saveConfig({
CapaOpenPGP: value ? 1 : 0
2021-03-16 17:46:22 +08:00
}),
useLocalProxyForExternalImages: value =>
Remote.saveConfig({
UseLocalProxyForExternalImages: value ? 1 : 0
2021-03-16 17:46:22 +08:00
}),
verifySslCertificate: value => {
value || this.allowSelfSigned(true);
Remote.saveConfig({
VerifySslCertificate: value ? 1 : 0
2021-03-16 17:46:22 +08:00
});
},
allowSelfSigned: value =>
Remote.saveConfig({
AllowSelfSigned: value ? 1 : 0
2021-03-16 17:46:22 +08:00
})
2016-07-16 05:29:42 +08:00
});
2014-08-21 23:08:34 +08:00
decorateKoCommands(this, {
saveNewAdminPasswordCommand: self => self.adminLogin().trim() && self.adminPassword()
});
2016-09-10 06:38:16 +08:00
}
2016-07-16 05:29:42 +08:00
2016-09-10 06:38:16 +08:00
saveNewAdminPasswordCommand() {
if (!this.adminLogin().trim()) {
2016-09-10 06:38:16 +08:00
this.adminLoginError(true);
return false;
}
2014-08-21 23:08:34 +08:00
2019-07-05 03:19:24 +08:00
if (this.adminPasswordNew() !== this.adminPasswordNew2()) {
2016-09-10 06:38:16 +08:00
this.adminPasswordNewError(true);
return false;
}
2016-06-30 08:02:45 +08:00
2016-09-10 06:38:16 +08:00
this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false);
2016-07-16 05:29:42 +08:00
Remote.request('AdminPasswordUpdate', (iError, data) => {
2021-04-23 03:56:01 +08:00
if (iError) {
this.adminPasswordUpdateError(true);
} else {
this.adminPassword('');
this.adminPasswordNew('');
this.adminPasswordNew2('');
this.adminPasswordUpdateSuccess(true);
this.weakPassword(!!data.Result.Weak);
}
}, {
2016-09-10 06:38:16 +08:00
'Login': this.adminLogin(),
'Password': this.adminPassword(),
'NewPassword': this.adminPasswordNew(),
'TOTP': this.adminTOTP()
2016-09-10 06:38:16 +08:00
});
2016-07-16 05:29:42 +08:00
2016-09-10 06:38:16 +08:00
return true;
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
onHide() {
this.adminPassword('');
this.adminPasswordNew('');
this.adminPasswordNew2('');
}
}