2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../components/loading/loading';
|
|
|
|
import globalize from '../../scripts/globalize';
|
|
|
|
import '../../elements/emby-checkbox/emby-checkbox';
|
|
|
|
import '../../elements/emby-select/emby-select';
|
2020-07-08 19:58:28 +01:00
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function onSubmit(e) {
|
2020-07-09 11:36:54 +01:00
|
|
|
const form = this;
|
|
|
|
const localAddress = form.querySelector('#txtLocalAddress').value;
|
|
|
|
const enableUpnp = form.querySelector('#chkEnableUpnp').checked;
|
2020-01-22 03:30:55 +03:00
|
|
|
confirmSelections(localAddress, enableUpnp, function () {
|
2020-07-09 11:36:54 +01:00
|
|
|
const validationResult = getValidationAlert(form);
|
2020-01-22 03:30:55 +03:00
|
|
|
|
|
|
|
if (validationResult) {
|
2020-04-26 17:17:59 -04:00
|
|
|
showAlertText(validationResult);
|
2020-01-22 18:31:01 +03:00
|
|
|
return;
|
2020-01-22 03:30:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
validateHttps(form).then(function () {
|
2019-07-30 00:56:28 -07:00
|
|
|
loading.show();
|
2020-01-22 03:30:55 +03:00
|
|
|
ApiClient.getServerConfiguration().then(function (config) {
|
2020-05-04 12:44:12 +02:00
|
|
|
config.LocalNetworkSubnets = form.querySelector('#txtLanNetworks').value.split(',').map(function (s) {
|
2020-01-22 03:30:55 +03:00
|
|
|
return s.trim();
|
|
|
|
}).filter(function (s) {
|
|
|
|
return s.length > 0;
|
2019-07-30 00:56:28 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
config.RemoteIPFilter = form.querySelector('#txtExternalAddressFilter').value.split(',').map(function (s) {
|
2020-01-22 03:30:55 +03:00
|
|
|
return s.trim();
|
|
|
|
}).filter(function (s) {
|
|
|
|
return s.length > 0;
|
2019-07-30 00:56:28 -07:00
|
|
|
});
|
2020-09-10 11:10:24 +02:00
|
|
|
config.KnownProxies = form.querySelector('#txtKnownProxies').value.split(',').map(function (s) {
|
|
|
|
return s.trim();
|
|
|
|
}).filter(function (s) {
|
|
|
|
return s.length > 0;
|
|
|
|
});
|
2020-07-30 16:07:13 +02:00
|
|
|
config.IsRemoteIPFilterBlacklist = form.querySelector('#selectExternalAddressFilterMode').value === 'blacklist';
|
2020-05-04 12:44:12 +02:00
|
|
|
config.PublicPort = form.querySelector('#txtPublicPort').value;
|
|
|
|
config.PublicHttpsPort = form.querySelector('#txtPublicHttpsPort').value;
|
|
|
|
config.HttpServerPortNumber = form.querySelector('#txtPortNumber').value;
|
2020-05-10 18:53:49 -04:00
|
|
|
config.HttpsPortNumber = form.querySelector('#txtHttpsPort').value;
|
|
|
|
config.EnableHttps = form.querySelector('#chkEnableHttps').checked;
|
|
|
|
config.RequireHttps = form.querySelector('#chkRequireHttps').checked;
|
2019-07-30 00:56:28 -07:00
|
|
|
config.EnableUPnP = enableUpnp;
|
2020-05-04 12:44:12 +02:00
|
|
|
config.BaseUrl = form.querySelector('#txtBaseUrl').value;
|
|
|
|
config.EnableRemoteAccess = form.querySelector('#chkRemoteAccess').checked;
|
|
|
|
config.CertificatePath = form.querySelector('#txtCertificatePath').value || null;
|
|
|
|
config.CertificatePassword = form.querySelector('#txtCertPassword').value || null;
|
2019-07-30 00:56:28 -07:00
|
|
|
config.LocalNetworkAddresses = localAddress ? [localAddress] : [];
|
|
|
|
ApiClient.updateServerConfiguration(config).then(Dashboard.processServerConfigurationUpdateResult, Dashboard.processErrorResponse);
|
2020-01-22 03:30:55 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function triggerChange(select) {
|
2020-07-09 11:36:54 +01:00
|
|
|
const evt = document.createEvent('HTMLEvents');
|
2020-05-04 12:44:12 +02:00
|
|
|
evt.initEvent('change', false, true);
|
2020-01-22 03:30:55 +03:00
|
|
|
select.dispatchEvent(evt);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getValidationAlert(form) {
|
2020-05-04 12:44:12 +02:00
|
|
|
if (form.querySelector('#txtPublicPort').value === form.querySelector('#txtPublicHttpsPort').value) {
|
|
|
|
return 'The public http and https ports must be different.';
|
2020-01-22 03:30:55 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
if (form.querySelector('#txtPortNumber').value === form.querySelector('#txtHttpsPort').value) {
|
|
|
|
return 'The http and https ports must be different.';
|
2020-01-22 03:30:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateHttps(form) {
|
2020-07-09 11:36:54 +01:00
|
|
|
const certPath = form.querySelector('#txtCertificatePath').value || null;
|
|
|
|
const httpsEnabled = form.querySelector('#chkEnableHttps').checked;
|
2020-01-22 03:30:55 +03:00
|
|
|
|
2020-04-26 17:17:59 -04:00
|
|
|
if (httpsEnabled && !certPath) {
|
|
|
|
return showAlertText({
|
2020-05-04 12:44:12 +02:00
|
|
|
title: globalize.translate('TitleHostingSettings'),
|
|
|
|
text: globalize.translate('HttpsRequiresCert')
|
2020-04-26 17:17:59 -04:00
|
|
|
}).then(Promise.reject);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 17:17:59 -04:00
|
|
|
function showAlertText(options) {
|
2020-01-22 03:30:55 +03:00
|
|
|
return new Promise(function (resolve, reject) {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../components/alert').then(({default: alert}) => {
|
2020-01-22 03:30:55 +03:00
|
|
|
alert(options).then(resolve, reject);
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function confirmSelections(localAddress, enableUpnp, callback) {
|
2020-01-22 03:30:55 +03:00
|
|
|
if (localAddress || !enableUpnp) {
|
2020-04-26 17:17:59 -04:00
|
|
|
showAlertText({
|
2020-05-04 12:44:12 +02:00
|
|
|
title: globalize.translate('TitleHostingSettings'),
|
|
|
|
text: globalize.translate('SettingsWarning')
|
2020-01-22 03:30:55 +03:00
|
|
|
}).then(callback);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-07-08 19:58:28 +01:00
|
|
|
export default function (view, params) {
|
2018-10-23 01:05:09 +03:00
|
|
|
function loadPage(page, config) {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#txtPortNumber').value = config.HttpServerPortNumber;
|
|
|
|
page.querySelector('#txtPublicPort').value = config.PublicPort;
|
|
|
|
page.querySelector('#txtPublicHttpsPort').value = config.PublicHttpsPort;
|
|
|
|
page.querySelector('#txtLocalAddress').value = config.LocalNetworkAddresses[0] || '';
|
|
|
|
page.querySelector('#txtLanNetworks').value = (config.LocalNetworkSubnets || []).join(', ');
|
2020-09-10 11:10:24 +02:00
|
|
|
page.querySelector('#txtKnownProxies').value = (config.KnownProxies || []).join(', ');
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#txtExternalAddressFilter').value = (config.RemoteIPFilter || []).join(', ');
|
|
|
|
page.querySelector('#selectExternalAddressFilterMode').value = config.IsRemoteIPFilterBlacklist ? 'blacklist' : 'whitelist';
|
2020-07-30 16:07:13 +02:00
|
|
|
page.querySelector('#chkRemoteAccess').checked = config.EnableRemoteAccess == null || config.EnableRemoteAccess;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#txtHttpsPort').value = config.HttpsPortNumber;
|
2020-05-10 18:53:49 -04:00
|
|
|
page.querySelector('#chkEnableHttps').checked = config.EnableHttps;
|
|
|
|
page.querySelector('#chkRequireHttps').checked = config.RequireHttps;
|
2020-05-04 12:44:12 +02:00
|
|
|
page.querySelector('#txtBaseUrl').value = config.BaseUrl || '';
|
2020-07-09 11:36:54 +01:00
|
|
|
const txtCertificatePath = page.querySelector('#txtCertificatePath');
|
2020-05-04 12:44:12 +02:00
|
|
|
txtCertificatePath.value = config.CertificatePath || '';
|
|
|
|
page.querySelector('#txtCertPassword').value = config.CertificatePassword || '';
|
|
|
|
page.querySelector('#chkEnableUpnp').checked = config.EnableUPnP;
|
|
|
|
triggerChange(page.querySelector('#chkRemoteAccess'));
|
2019-07-30 00:56:28 -07:00
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('#chkRemoteAccess').addEventListener('change', function () {
|
2020-01-22 03:30:55 +03:00
|
|
|
if (this.checked) {
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('.fldExternalAddressFilter').classList.remove('hide');
|
|
|
|
view.querySelector('.fldExternalAddressFilterMode').classList.remove('hide');
|
|
|
|
view.querySelector('.fldPublicPort').classList.remove('hide');
|
|
|
|
view.querySelector('.fldPublicHttpsPort').classList.remove('hide');
|
|
|
|
view.querySelector('.fldEnableUpnp').classList.remove('hide');
|
2020-01-22 03:30:55 +03:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('.fldExternalAddressFilter').classList.add('hide');
|
|
|
|
view.querySelector('.fldExternalAddressFilterMode').classList.add('hide');
|
|
|
|
view.querySelector('.fldPublicPort').classList.add('hide');
|
|
|
|
view.querySelector('.fldPublicHttpsPort').classList.add('hide');
|
|
|
|
view.querySelector('.fldEnableUpnp').classList.add('hide');
|
2020-01-22 03:30:55 +03:00
|
|
|
}
|
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('#btnSelectCertPath').addEventListener('click', function () {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../components/directorybrowser/directorybrowser').then(({default: directoryBrowser}) => {
|
2020-07-19 10:13:35 +01:00
|
|
|
const picker = new directoryBrowser();
|
2018-10-23 01:05:09 +03:00
|
|
|
picker.show({
|
2020-01-22 03:30:55 +03:00
|
|
|
includeFiles: true,
|
|
|
|
includeDirectories: true,
|
|
|
|
callback: function (path) {
|
|
|
|
if (path) {
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('#txtCertificatePath').value = path;
|
2020-01-22 03:30:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
},
|
2020-05-04 12:44:12 +02:00
|
|
|
header: globalize.translate('HeaderSelectCertificatePath')
|
2020-01-22 03:30:55 +03:00
|
|
|
});
|
|
|
|
});
|
2019-06-10 15:25:07 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('.dashboardHostingForm').addEventListener('submit', onSubmit);
|
|
|
|
view.addEventListener('viewshow', function (e) {
|
2019-06-10 15:25:07 -07:00
|
|
|
loading.show();
|
2020-01-22 03:30:55 +03:00
|
|
|
ApiClient.getServerConfiguration().then(function (config) {
|
2019-06-10 15:25:07 -07:00
|
|
|
loadPage(view, config);
|
|
|
|
});
|
|
|
|
});
|
2020-07-09 11:36:54 +01:00
|
|
|
}
|
2020-07-08 19:58:28 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|