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(() => {
if (store.state.serverConfiguration?.lockNetwork) {
if (
store.state.serverConfiguration?.lockNetwork &&
store.state.serverConfiguration?.allowMultipleSameHostConnections
) {
if (store.state.networks.length > 0) {
disabled.value = true;
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.
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
// ### `messageStorage`

View file

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

View file

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

View file

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