Disable connecting to the same network multiple times if lockNetwork is enabled

This commit is contained in:
Max Leiter 2022-09-07 21:33:51 -07:00
parent 6221f96ff2
commit 85f83a7c9a
5 changed files with 24 additions and 3 deletions

View file

@ -34,7 +34,10 @@ export default defineComponent({
}; };
onMounted(() => { onMounted(() => {
if (store.state.serverConfiguration?.lockNetwork) { if (
store.state.serverConfiguration?.lockNetwork &&
store.state.serverConfiguration?.allowMultipleSameHostConnections
) {
if (store.state.networks.length > 0) { if (store.state.networks.length > 0) {
disabled.value = true; disabled.value = true;
disabledReason.value = "You have already connected and cannot connect again."; disabledReason.value = "You have already connected and cannot connect again.";

View file

@ -285,6 +285,15 @@ module.exports = {
// This value is set to `false` by default. // This value is set to `false` by default.
lockNetwork: false, lockNetwork: false,
// ### `sameHostLockedNetworkConnections`
//
// When set to `true`, users will be able to connect to the configured
// network multiple times. This can be useful if you connect to
// a bouncer like ZNC. Requires `lockNetwork` to be set to `true`.
//
// This value is set to `false` by default.
allowMultipleSameHostConnections: false,
// ## User management // ## User management
// ### `messageStorage` // ### `messageStorage`

View file

@ -96,6 +96,7 @@ export type ConfigType = {
leaveMessage: string; leaveMessage: string;
defaults: Defaults; defaults: Defaults;
lockNetwork: boolean; lockNetwork: boolean;
allowMultipleSameHostConnections: boolean;
messageStorage: string[]; messageStorage: string[];
useHexIp: boolean; useHexIp: boolean;
webirc?: WebIRC; webirc?: WebIRC;

View file

@ -48,7 +48,12 @@ type IndexTemplateConfiguration = ServerConfiguration & {
export type ClientConfiguration = Pick< export type ClientConfiguration = Pick<
ConfigType, ConfigType,
"public" | "lockNetwork" | "useHexIp" | "prefetch" | "defaults" | "public"
| "lockNetwork"
| "useHexIp"
| "prefetch"
| "defaults"
| "allowMultipleSameHostConnections"
> & { > & {
fileUpload: boolean; fileUpload: boolean;
ldapEnabled: boolean; ldapEnabled: boolean;
@ -478,7 +483,7 @@ function initializeClient(
}); });
socket.on("network:new", (data) => { socket.on("network:new", (data) => {
if (Config.values.lockNetwork) { if (Config.values.lockNetwork && Config.values.allowMultipleSameHostConnections) {
if (client.networks.length > 0) { if (client.networks.length > 0) {
return; return;
} }
@ -869,6 +874,8 @@ function getClientConfiguration(): ClientConfiguration {
"lockNetwork", "lockNetwork",
"useHexIp", "useHexIp",
"prefetch", "prefetch",
"allowMultipleSameHostConnections",
// TODO: remove this type cast
]) as ClientConfiguration; ]) as ClientConfiguration;
config.fileUpload = Config.values.fileUpload.enable; config.fileUpload = Config.values.fileUpload.enable;

View file

@ -131,6 +131,7 @@ describe("Server", function () {
expect(data.defaultTheme).to.equal("default"); expect(data.defaultTheme).to.equal("default");
expect(data.themes).to.be.an("array"); expect(data.themes).to.be.an("array");
expect(data.lockNetwork).to.equal(false); expect(data.lockNetwork).to.equal(false);
expect(data.useHexIp).to.equal(false); expect(data.useHexIp).to.equal(false);
done(); done();