2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-08-14 04:58:41 +08:00
|
|
|
import { StorageResultType } from 'Common/Enums';
|
2014-09-02 08:15:31 +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
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { command } from 'Knoin/Knoin';
|
2016-09-10 06:38:16 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
const settingsGet = rl.settings.get;
|
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class SecurityAdminSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
|
|
|
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
|
|
|
|
2020-10-27 18:09:24 +08:00
|
|
|
ko.addObservablesTo(this, {
|
|
|
|
useLocalProxyForExternalImages: !!rl.settings.get('UseLocalProxyForExternalImages'),
|
|
|
|
|
|
|
|
verifySslCertificate: !!settingsGet('VerifySslCertificate'),
|
|
|
|
allowSelfSigned: !!settingsGet('AllowSelfSigned'),
|
|
|
|
|
|
|
|
isTwoFactorDropperShown: false,
|
|
|
|
twoFactorDropperUser: '',
|
|
|
|
twoFactorDropperUserFocused: false,
|
|
|
|
|
|
|
|
adminLogin: settingsGet('AdminLogin'),
|
|
|
|
adminLoginError: false,
|
|
|
|
adminPassword: '',
|
|
|
|
adminPasswordNew: '',
|
|
|
|
adminPasswordNew2: '',
|
|
|
|
adminPasswordNewError: false,
|
|
|
|
|
|
|
|
adminPasswordUpdateError: false,
|
|
|
|
adminPasswordUpdateSuccess: false
|
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaTwoFactorAuth.subscribe(value => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!value) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.capaTwoFactorAuthForce(false);
|
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.verifySslCertificate.subscribe(value => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!value) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.allowSelfSigned(true);
|
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:08:34 +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
|
|
|
|
2020-07-20 21:47:33 +08:00
|
|
|
this.onNewAdminPasswordResponse = this.onNewAdminPasswordResponse.bind(this);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2020-08-07 00:24:46 +08:00
|
|
|
@command((self) => self.adminLogin().trim() && self.adminPassword())
|
2016-09-10 06:38:16 +08:00
|
|
|
saveNewAdminPasswordCommand() {
|
2020-08-07 00:24:46 +08:00
|
|
|
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
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
Remote.saveNewAdminPassword(this.onNewAdminPasswordResponse, {
|
|
|
|
'Login': this.adminLogin(),
|
|
|
|
'Password': this.adminPassword(),
|
|
|
|
'NewPassword': this.adminPasswordNew()
|
|
|
|
});
|
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
|
|
|
|
2016-07-17 23:03:38 +08:00
|
|
|
showTwoFactorDropper() {
|
|
|
|
this.twoFactorDropperUser('');
|
|
|
|
this.isTwoFactorDropperShown(true);
|
|
|
|
|
2020-07-23 02:28:25 +08:00
|
|
|
setTimeout(() => {
|
2020-10-27 18:09:24 +08:00
|
|
|
this.twoFactorDropperUserFocused(true);
|
2020-08-14 04:58:41 +08:00
|
|
|
}, 50);
|
2016-07-17 23:03:38 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onNewAdminPasswordResponse(result, data) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPassword('');
|
|
|
|
this.adminPasswordNew('');
|
|
|
|
this.adminPasswordNew2('');
|
|
|
|
|
|
|
|
this.adminPasswordUpdateSuccess(true);
|
|
|
|
|
|
|
|
this.weakPassword(!!data.Result.Weak);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.adminPasswordUpdateError(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onBuild() {
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaOpenPGP.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaOpenPGP': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaTwoFactorAuth.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaTwoFactorAuth': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.capaTwoFactorAuthForce.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'CapaTwoFactorAuthForce': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.useLocalProxyForExternalImages.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'UseLocalProxyForExternalImages': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.verifySslCertificate.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'VerifySslCertificate': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
});
|
|
|
|
|
2020-10-13 01:46:41 +08:00
|
|
|
this.allowSelfSigned.subscribe(value => {
|
2016-07-16 05:29:42 +08:00
|
|
|
Remote.saveAdminConfig(null, {
|
2020-07-30 03:49:41 +08:00
|
|
|
'AllowSelfSigned': value ? '1' : '0'
|
2016-07-16 05:29:42 +08:00
|
|
|
});
|
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('');
|
2016-07-17 23:03:38 +08:00
|
|
|
|
|
|
|
this.isTwoFactorDropperShown(false);
|
|
|
|
this.twoFactorDropperUser('');
|
2020-10-27 18:09:24 +08:00
|
|
|
this.twoFactorDropperUserFocused(false);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|