mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 12:03:11 +00:00
Network.validate: Deduplicate code + tell users what the invalid hostname is (#4475)
* De-duplicate error message creation in Network.validate() * Tell users what the invalid hostname is. * Reword the log error message
This commit is contained in:
parent
cb28204517
commit
c12dd6c740
1 changed files with 16 additions and 25 deletions
|
@ -114,6 +114,17 @@ Network.prototype.validate = function (client) {
|
||||||
this.proxyPassword = cleanString(this.proxyPassword);
|
this.proxyPassword = cleanString(this.proxyPassword);
|
||||||
this.proxyEnabled = !!this.proxyEnabled;
|
this.proxyEnabled = !!this.proxyEnabled;
|
||||||
|
|
||||||
|
const error = function (network, text) {
|
||||||
|
network.channels[0].pushMessage(
|
||||||
|
client,
|
||||||
|
new Msg({
|
||||||
|
type: Msg.Type.ERROR,
|
||||||
|
text: text,
|
||||||
|
}),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (!this.port) {
|
if (!this.port) {
|
||||||
this.port = this.tls ? 6697 : 6667;
|
this.port = this.tls ? 6697 : 6667;
|
||||||
}
|
}
|
||||||
|
@ -134,15 +145,7 @@ Network.prototype.validate = function (client) {
|
||||||
this.host.length > 0 &&
|
this.host.length > 0 &&
|
||||||
this.host !== Helper.config.defaults.host
|
this.host !== Helper.config.defaults.host
|
||||||
) {
|
) {
|
||||||
this.channels[0].pushMessage(
|
error(this, `The hostname you specified (${this.host}) is not allowed.`);
|
||||||
client,
|
|
||||||
new Msg({
|
|
||||||
type: Msg.Type.ERROR,
|
|
||||||
text: "Hostname you specified is not allowed.",
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,28 +162,16 @@ Network.prototype.validate = function (client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.host.length === 0) {
|
if (this.host.length === 0) {
|
||||||
this.channels[0].pushMessage(
|
error(this, "You must specify a hostname to connect.");
|
||||||
client,
|
|
||||||
new Msg({
|
|
||||||
type: Msg.Type.ERROR,
|
|
||||||
text: "You must specify a hostname to connect.",
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stsPolicy = STSPolicies.get(this.host);
|
const stsPolicy = STSPolicies.get(this.host);
|
||||||
|
|
||||||
if (stsPolicy && !this.tls) {
|
if (stsPolicy && !this.tls) {
|
||||||
this.channels[0].pushMessage(
|
error(
|
||||||
client,
|
this,
|
||||||
new Msg({
|
`${this.host} has an active strict transport security policy, will connect to port ${stsPolicy.port} over a secure connection.`
|
||||||
type: Msg.Type.ERROR,
|
|
||||||
text: `${this.host} has an active strict transport security policy, will connect to port ${stsPolicy.port} over a secure connection.`,
|
|
||||||
}),
|
|
||||||
true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.port = stsPolicy.port;
|
this.port = stsPolicy.port;
|
||||||
|
|
Loading…
Reference in a new issue