2020-01-22 03:30:55 +03:00
|
|
|
define(["loading", "libraryMenu", "globalize", "emby-checkbox", "emby-select"], function (loading, libraryMenu, globalize) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function onSubmit(e) {
|
2019-07-30 00:56:28 -07:00
|
|
|
var form = this;
|
|
|
|
var localAddress = form.querySelector("#txtLocalAddress").value;
|
|
|
|
var enableUpnp = form.querySelector("#chkEnableUpnp").checked;
|
2020-01-22 03:30:55 +03:00
|
|
|
confirmSelections(localAddress, enableUpnp, function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var 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) {
|
|
|
|
config.LocalNetworkSubnets = form.querySelector("#txtLanNetworks").value.split(",").map(function (s) {
|
|
|
|
return s.trim();
|
|
|
|
}).filter(function (s) {
|
|
|
|
return s.length > 0;
|
2019-07-30 00:56:28 -07:00
|
|
|
});
|
2020-01-22 03:30:55 +03:00
|
|
|
config.RemoteIPFilter = form.querySelector("#txtExternalAddressFilter").value.split(",").map(function (s) {
|
|
|
|
return s.trim();
|
|
|
|
}).filter(function (s) {
|
|
|
|
return s.length > 0;
|
2019-07-30 00:56:28 -07:00
|
|
|
});
|
|
|
|
config.IsRemoteIPFilterBlacklist = "blacklist" === form.querySelector("#selectExternalAddressFilterMode").value;
|
|
|
|
config.PublicPort = form.querySelector("#txtPublicPort").value;
|
|
|
|
config.PublicHttpsPort = form.querySelector("#txtPublicHttpsPort").value;
|
|
|
|
config.HttpServerPortNumber = form.querySelector("#txtPortNumber").value;
|
2020-04-26 17:17:59 -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;
|
2019-07-30 23:26:42 -07:00
|
|
|
config.BaseUrl = form.querySelector("#txtBaseUrl").value;
|
2019-07-30 00:56:28 -07:00
|
|
|
config.EnableRemoteAccess = form.querySelector("#chkRemoteAccess").checked;
|
|
|
|
config.CertificatePath = form.querySelector("#txtCertificatePath").value || null;
|
|
|
|
config.CertificatePassword = form.querySelector("#txtCertPassword").value || null;
|
|
|
|
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) {
|
|
|
|
var evt = document.createEvent("HTMLEvents");
|
2020-01-22 03:30:55 +03:00
|
|
|
evt.initEvent("change", false, true);
|
|
|
|
select.dispatchEvent(evt);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getValidationAlert(form) {
|
2020-01-22 03:30:55 +03:00
|
|
|
if (form.querySelector("#txtPublicPort").value === form.querySelector("#txtPublicHttpsPort").value) {
|
|
|
|
return "The public http and https ports must be different.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (form.querySelector("#txtPortNumber").value === form.querySelector("#txtHttpsPort").value) {
|
|
|
|
return "The http and https ports must be different.";
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateHttps(form) {
|
2019-11-23 00:29:38 +09:00
|
|
|
var certPath = form.querySelector("#txtCertificatePath").value || null;
|
2020-04-26 17:17:59 -04:00
|
|
|
var 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({
|
2018-10-23 01:05:09 +03: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) {
|
|
|
|
require(["alert"], function (alert) {
|
|
|
|
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-01-22 03:30:55 +03:00
|
|
|
title: globalize.translate("TitleHostingSettings"),
|
|
|
|
text: globalize.translate("SettingsWarning")
|
|
|
|
}).then(callback);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 03:30:55 +03:00
|
|
|
return function (view, params) {
|
2018-10-23 01:05:09 +03:00
|
|
|
function loadPage(page, config) {
|
2019-07-30 00:56:28 -07: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(", ");
|
|
|
|
page.querySelector("#txtExternalAddressFilter").value = (config.RemoteIPFilter || []).join(", ");
|
|
|
|
page.querySelector("#selectExternalAddressFilterMode").value = config.IsRemoteIPFilterBlacklist ? "blacklist" : "whitelist";
|
|
|
|
page.querySelector("#chkRemoteAccess").checked = null == config.EnableRemoteAccess || config.EnableRemoteAccess;
|
|
|
|
page.querySelector("#txtHttpsPort").value = config.HttpsPortNumber;
|
2020-04-26 17:17:59 -04:00
|
|
|
page.querySelector("#chkEnableHttps").checked = config.EnableHttps;
|
|
|
|
page.querySelector("#chkRequireHttps").checked = config.RequireHttps;
|
2019-07-30 23:26:42 -07:00
|
|
|
page.querySelector("#txtBaseUrl").value = config.BaseUrl || "";
|
2018-10-23 01:05:09 +03:00
|
|
|
var txtCertificatePath = page.querySelector("#txtCertificatePath");
|
2019-07-30 00:56:28 -07:00
|
|
|
txtCertificatePath.value = config.CertificatePath || "";
|
|
|
|
page.querySelector("#txtCertPassword").value = config.CertificatePassword || "";
|
|
|
|
page.querySelector("#chkEnableUpnp").checked = config.EnableUPnP;
|
|
|
|
triggerChange(page.querySelector("#chkRemoteAccess"));
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 03:30:55 +03:00
|
|
|
view.querySelector("#chkRemoteAccess").addEventListener("change", function () {
|
|
|
|
if (this.checked) {
|
|
|
|
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");
|
|
|
|
} else {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
view.querySelector("#btnSelectCertPath").addEventListener("click", function () {
|
|
|
|
require(["directorybrowser"], function (directoryBrowser) {
|
|
|
|
var 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) {
|
|
|
|
view.querySelector("#txtCertificatePath").value = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.close();
|
2018-10-23 01:05:09 +03:00
|
|
|
},
|
|
|
|
header: globalize.translate("HeaderSelectCertificatePath")
|
2020-01-22 03:30:55 +03:00
|
|
|
});
|
|
|
|
});
|
2019-06-10 15:25:07 -07:00
|
|
|
});
|
2020-01-22 03:30:55 +03: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-01-22 03:30:55 +03:00
|
|
|
};
|
2019-09-19 15:52:00 -04:00
|
|
|
});
|