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';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
2016-09-10 06:38:16 +08:00
|
|
|
|
2021-09-23 02:17:44 +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
|
|
|
|
2021-03-16 17:59:47 +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,
|
2021-11-18 21:14:14 +08:00
|
|
|
adminTOTP: SettingsGet('AdminTOTP'),
|
2020-10-27 18:09:24 +08:00
|
|
|
|
|
|
|
adminPasswordUpdateError: false,
|
2021-03-16 17:46:22 +08:00
|
|
|
adminPasswordUpdateSuccess: false,
|
2014-10-18 23:29:09 +08:00
|
|
|
|
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
|
|
|
|
2021-03-16 17:59:47 +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 =>
|
2021-12-03 19:32:21 +08:00
|
|
|
Remote.saveConfig({
|
2021-03-25 04:26:40 +08:00
|
|
|
CapaOpenPGP: value ? 1 : 0
|
2021-03-16 17:46:22 +08:00
|
|
|
}),
|
|
|
|
|
|
|
|
useLocalProxyForExternalImages: value =>
|
2021-12-03 19:32:21 +08:00
|
|
|
Remote.saveConfig({
|
2021-03-25 04:26:40 +08:00
|
|
|
UseLocalProxyForExternalImages: value ? 1 : 0
|
2021-03-16 17:46:22 +08:00
|
|
|
}),
|
|
|
|
|
|
|
|
verifySslCertificate: value => {
|
2021-12-03 19:32:21 +08:00
|
|
|
value || this.allowSelfSigned(true);
|
|
|
|
Remote.saveConfig({
|
2021-03-25 04:26:40 +08:00
|
|
|
VerifySslCertificate: value ? 1 : 0
|
2021-03-16 17:46:22 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
allowSelfSigned: value =>
|
2021-12-03 19:32:21 +08:00
|
|
|
Remote.saveConfig({
|
2021-03-25 04:26:40 +08:00
|
|
|
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
|
|
|
|
2021-02-19 19:09:20 +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() {
|
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
|
|
|
|
2021-12-03 06:15:24 +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);
|
|
|
|
}
|
2021-12-03 06:15:24 +08:00
|
|
|
}, {
|
2016-09-10 06:38:16 +08:00
|
|
|
'Login': this.adminLogin(),
|
|
|
|
'Password': this.adminPassword(),
|
2021-11-18 21:14:14 +08:00
|
|
|
'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('');
|
|
|
|
}
|
|
|
|
}
|