2022-02-24 20:36:57 +08:00
|
|
|
import { pInt, forEachObjectEntry } from 'Common/Utils';
|
2021-03-18 19:33:13 +08:00
|
|
|
import { i18n, getNotification } from 'Common/Translator';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
2021-03-15 05:36:23 +08:00
|
|
|
import { DomainAdminStore } from 'Stores/Admin/Domain';
|
|
|
|
|
2021-12-03 07:11:19 +08:00
|
|
|
const domainToParams = oDomain => ({
|
|
|
|
Name: oDomain.name(),
|
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
IncHost: oDomain.imapHost(),
|
2021-12-03 07:11:19 +08:00
|
|
|
IncPort: oDomain.imapPort(),
|
|
|
|
IncSecure: oDomain.imapSecure(),
|
|
|
|
|
|
|
|
UseSieve: oDomain.useSieve() ? 1 : 0,
|
2022-02-24 19:43:44 +08:00
|
|
|
SieveHost: oDomain.sieveHost(),
|
2021-12-03 07:11:19 +08:00
|
|
|
SievePort: oDomain.sievePort(),
|
|
|
|
SieveSecure: oDomain.sieveSecure(),
|
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
OutHost: oDomain.smtpHost(),
|
2021-12-03 07:11:19 +08:00
|
|
|
OutPort: oDomain.smtpPort(),
|
|
|
|
OutSecure: oDomain.smtpSecure(),
|
|
|
|
OutAuth: oDomain.smtpAuth() ? 1 : 0,
|
|
|
|
OutUsePhpMail: oDomain.smtpPhpMail() ? 1 : 0
|
|
|
|
});
|
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class DomainPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('Domain');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
this.addObservables(this.getDefaults());
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
edit: false,
|
2021-08-20 21:40:07 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
saving: false,
|
|
|
|
|
|
|
|
testing: false,
|
|
|
|
testingDone: false,
|
|
|
|
testingImapError: false,
|
|
|
|
testingSieveError: false,
|
|
|
|
testingSmtpError: false,
|
|
|
|
testingImapErrorDesc: '',
|
|
|
|
testingSieveErrorDesc: '',
|
|
|
|
testingSmtpErrorDesc: '',
|
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
imapHostFocus: false,
|
|
|
|
sieveHostFocus: false,
|
|
|
|
smtpHostFocus: false,
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
|
2020-10-26 21:44:34 +08:00
|
|
|
this.addComputables({
|
|
|
|
headerText: () => {
|
|
|
|
const name = this.name(),
|
|
|
|
aliasName = this.aliasName();
|
|
|
|
|
|
|
|
let result = '';
|
|
|
|
|
|
|
|
if (this.edit()) {
|
2021-03-25 04:26:40 +08:00
|
|
|
result = i18n('POPUPS_DOMAIN/TITLE_EDIT_DOMAIN', { NAME: name });
|
2020-10-26 21:44:34 +08:00
|
|
|
if (aliasName) {
|
2022-02-24 21:01:41 +08:00
|
|
|
result += ' ⫘ ' + aliasName;
|
2020-10-26 21:44:34 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = name
|
2021-03-25 04:26:40 +08:00
|
|
|
? i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', { NAME: name })
|
2020-10-26 21:44:34 +08:00
|
|
|
: i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN');
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
domainDesc: () => {
|
|
|
|
const name = this.name();
|
2021-03-25 04:26:40 +08:00
|
|
|
return !this.edit() && name ? i18n('POPUPS_DOMAIN/NEW_DOMAIN_DESC', { NAME: '*@' + name }) : '';
|
2020-10-26 21:44:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
domainIsComputed: () => {
|
|
|
|
const usePhpMail = this.smtpPhpMail(),
|
|
|
|
useSieve = this.useSieve();
|
|
|
|
|
|
|
|
return (
|
|
|
|
this.name() &&
|
2022-02-24 19:43:44 +08:00
|
|
|
this.imapHost() &&
|
2020-10-26 21:44:34 +08:00
|
|
|
this.imapPort() &&
|
2022-02-24 19:43:44 +08:00
|
|
|
(useSieve ? this.sieveHost() && this.sievePort() : true) &&
|
|
|
|
((this.smtpHost() && this.smtpPort()) || usePhpMail)
|
2020-10-26 21:44:34 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
canBeTested: () => !this.testing() && this.domainIsComputed(),
|
|
|
|
canBeSaved: () => !this.saving() && this.domainIsComputed()
|
|
|
|
});
|
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addSubscribables({
|
|
|
|
testingImapError: value => value || this.testingImapErrorDesc(''),
|
|
|
|
testingSieveError: value => value || this.testingSieveErrorDesc(''),
|
|
|
|
testingSmtpError: value => value || this.testingSmtpErrorDesc(''),
|
|
|
|
|
|
|
|
// smart form improvements
|
2022-02-24 19:43:44 +08:00
|
|
|
imapHostFocus: value =>
|
|
|
|
value && this.name() && !this.imapHost() && this.imapHost(this.name().replace(/[.]?[*][.]?/g, '')),
|
2020-10-26 19:54:03 +08:00
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
sieveHostFocus: value =>
|
|
|
|
value && this.imapHost() && !this.sieveHost() && this.sieveHost(this.imapHost()),
|
2020-10-26 19:54:03 +08:00
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
smtpHostFocus: value => value && this.imapHost() && !this.smtpHost()
|
|
|
|
&& this.smtpHost(this.imapHost().replace(/imap/gi, 'smtp')),
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
imapSecure: value => {
|
|
|
|
if (this.enableSmartPorts()) {
|
|
|
|
const port = pInt(this.imapPort());
|
2022-02-24 20:36:57 +08:00
|
|
|
switch (pInt(value)) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
2020-10-26 19:54:03 +08:00
|
|
|
if (993 === port) {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.imapPort(143);
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
|
|
|
break;
|
2022-02-24 20:36:57 +08:00
|
|
|
case 1:
|
2020-10-26 19:54:03 +08:00
|
|
|
if (143 === port) {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.imapPort(993);
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
smtpSecure: value => {
|
|
|
|
if (this.enableSmartPorts()) {
|
|
|
|
const port = pInt(this.smtpPort());
|
2022-02-24 20:36:57 +08:00
|
|
|
switch (pInt(value)) {
|
|
|
|
case 0:
|
2020-10-26 19:54:03 +08:00
|
|
|
if (465 === port || 587 === port) {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.smtpPort(25);
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
|
|
|
break;
|
2022-02-24 20:36:57 +08:00
|
|
|
case 1:
|
2020-10-26 19:54:03 +08:00
|
|
|
if (25 === port || 587 === port) {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.smtpPort(465);
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
|
|
|
break;
|
2022-02-24 20:36:57 +08:00
|
|
|
case 2:
|
2020-10-26 19:54:03 +08:00
|
|
|
if (25 === port || 465 === port) {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.smtpPort(587);
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2021-02-19 19:09:20 +08:00
|
|
|
|
|
|
|
decorateKoCommands(this, {
|
|
|
|
createOrAddCommand: self => self.canBeSaved(),
|
2021-08-27 02:31:38 +08:00
|
|
|
testConnectionCommand: self => self.canBeTested()
|
2021-02-19 19:09:20 +08:00
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2015-01-29 00:27:23 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
createOrAddCommand() {
|
|
|
|
this.saving(true);
|
2021-12-03 07:11:19 +08:00
|
|
|
Remote.request('AdminDomainSave',
|
2020-07-20 21:47:33 +08:00
|
|
|
this.onDomainCreateOrSaveResponse.bind(this),
|
2021-12-03 07:11:19 +08:00
|
|
|
Object.assign(domainToParams(this), {
|
|
|
|
Create: this.edit() ? 0 : 1,
|
|
|
|
|
|
|
|
IncShortLogin: this.imapShortLogin() ? 1 : 0,
|
|
|
|
|
|
|
|
OutShortLogin: this.smtpShortLogin() ? 1 : 0,
|
|
|
|
OutSetSender: this.smtpSetSender() ? 1 : 0,
|
|
|
|
|
|
|
|
WhiteList: this.whiteList()
|
|
|
|
})
|
2016-09-10 06:38:16 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
testConnectionCommand() {
|
2022-02-24 20:36:57 +08:00
|
|
|
this.clearTesting(false);
|
2016-09-10 06:38:16 +08:00
|
|
|
this.testing(true);
|
|
|
|
|
2021-12-03 07:11:19 +08:00
|
|
|
Remote.request('AdminDomainTest',
|
2021-04-23 16:47:24 +08:00
|
|
|
(iError, oData) => {
|
|
|
|
this.testing(false);
|
|
|
|
if (iError) {
|
|
|
|
this.testingImapError(true);
|
|
|
|
this.testingSieveError(true);
|
|
|
|
this.testingSmtpError(true);
|
|
|
|
} else {
|
|
|
|
this.testingDone(true);
|
|
|
|
this.testingImapError(true !== oData.Result.Imap);
|
|
|
|
this.testingSieveError(true !== oData.Result.Sieve);
|
|
|
|
this.testingSmtpError(true !== oData.Result.Smtp);
|
|
|
|
|
|
|
|
if (this.testingImapError() && oData.Result.Imap) {
|
|
|
|
this.testingImapErrorDesc('');
|
|
|
|
this.testingImapErrorDesc(oData.Result.Imap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.testingSieveError() && oData.Result.Sieve) {
|
|
|
|
this.testingSieveErrorDesc('');
|
|
|
|
this.testingSieveErrorDesc(oData.Result.Sieve);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.testingSmtpError() && oData.Result.Smtp) {
|
|
|
|
this.testingSmtpErrorDesc('');
|
|
|
|
this.testingSmtpErrorDesc(oData.Result.Smtp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-12-03 07:11:19 +08:00
|
|
|
domainToParams(this)
|
2016-09-10 06:38:16 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:33:13 +08:00
|
|
|
onDomainCreateOrSaveResponse(iError) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.saving(false);
|
2021-03-18 19:33:13 +08:00
|
|
|
if (iError) {
|
|
|
|
this.savingError(getNotification(iError));
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-03-18 19:33:13 +08:00
|
|
|
DomainAdminStore.fetch();
|
|
|
|
this.closeCommand();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-01 00:24:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearTesting() {
|
|
|
|
this.testing(false);
|
|
|
|
this.testingDone(false);
|
|
|
|
this.testingImapError(false);
|
|
|
|
this.testingSieveError(false);
|
|
|
|
this.testingSmtpError(false);
|
|
|
|
}
|
2014-05-01 00:24:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(oDomain) {
|
|
|
|
this.saving(false);
|
|
|
|
this.clearTesting();
|
|
|
|
this.clearForm();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (oDomain) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.enableSmartPorts(false);
|
|
|
|
this.edit(true);
|
2022-02-24 20:36:57 +08:00
|
|
|
forEachObjectEntry(oDomain, (key, value) => this[key] && this[key](value));
|
2016-08-17 06:01:20 +08:00
|
|
|
this.enableSmartPorts(true);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
getDefaults() {
|
|
|
|
return {
|
2022-02-24 20:36:57 +08:00
|
|
|
enableSmartPorts: false,
|
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
savingError: '',
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
name: '',
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
imapHost: '',
|
2022-02-24 20:36:57 +08:00
|
|
|
imapPort: 143,
|
2021-08-20 21:40:07 +08:00
|
|
|
imapSecure: 0,
|
|
|
|
imapShortLogin: false,
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
useSieve: false,
|
2022-02-24 19:43:44 +08:00
|
|
|
sieveHost: '',
|
2022-02-24 20:36:57 +08:00
|
|
|
sievePort: 4190,
|
2021-08-20 21:40:07 +08:00
|
|
|
sieveSecure: 0,
|
2014-11-20 05:32:20 +08:00
|
|
|
|
2022-02-24 19:43:44 +08:00
|
|
|
smtpHost: '',
|
2022-02-24 20:36:57 +08:00
|
|
|
smtpPort: 25,
|
2021-08-20 21:40:07 +08:00
|
|
|
smtpSecure: 0,
|
|
|
|
smtpShortLogin: false,
|
|
|
|
smtpAuth: true,
|
|
|
|
smtpSetSender: false,
|
|
|
|
smtpPhpMail: false,
|
2014-11-20 05:32:20 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
whiteList: '',
|
2022-02-24 20:36:57 +08:00
|
|
|
aliasName: ''
|
2021-08-20 21:40:07 +08:00
|
|
|
};
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
clearForm() {
|
|
|
|
this.edit(false);
|
2021-12-01 21:23:37 +08:00
|
|
|
forEachObjectEntry(this.getDefaults(), (key, value) => this[key](value));
|
2016-08-17 06:01:20 +08:00
|
|
|
this.enableSmartPorts(true);
|
|
|
|
}
|
|
|
|
}
|