Allow locking network configuration

This commit is contained in:
Pavel Djundik 2016-02-21 14:02:35 +02:00
parent 36f2ee3617
commit aab7f298d8
3 changed files with 47 additions and 7 deletions

View File

@ -103,11 +103,11 @@
<label>Server</label>
</div>
<div class="col-sm-6 col-xs-8">
<input class="input" name="host" value="<%= defaults.host %>">
<input class="input" name="host" value="<%= defaults.host %>" <%= typeof(lockNetwork) !== "undefined" && lockNetwork ? 'disabled' : ''%>>
</div>
<div class="col-sm-3 col-xs-4">
<div class="port">
<input class="input" name="port" value="<%= defaults.port %>">
<input class="input" name="port" value="<%= defaults.port %>" <%= typeof(lockNetwork) !== "undefined" && lockNetwork ? 'disabled' : ''%>>
</div>
</div>
<div class="clearfix"></div>
@ -120,7 +120,7 @@
<div class="col-sm-3"></div>
<div class="col-sm-9">
<label class="tls">
<input type="checkbox" name="tls" <%= defaults.tls ? 'checked="checked"' : '' %>>
<input type="checkbox" name="tls" <%= defaults.tls ? 'checked="checked"' : '' %> <%= typeof(lockNetwork) !== "undefined" && lockNetwork ? 'disabled' : ''%>>
Enable TLS/SSL
</label>
</div>

View File

@ -79,14 +79,24 @@ module.exports = {
//
// Display network
//
// If set to false The Lounge will not expose network settings in login
// form, limiting client to connect to the configured network.
// If set to false network settings will not be shown in the login form.
//
// @type boolean
// @default true
//
displayNetwork: true,
//
// Lock network
//
// If set to true, users will not be able to modify host, port and tls
// settings and will be limited to the configured network.
//
// @type boolean
// @default false
//
lockNetwork: false,
//
// Log settings
//

View File

@ -123,13 +123,43 @@ Client.prototype.find = function(id) {
Client.prototype.connect = function(args) {
var config = Helper.getConfig();
var client = this;
if (config.lockNetwork) {
// This check is needed to prevent invalid user configurations
if (args.host && args.host.length > 0 && args.host !== config.defaults.host) {
var invalidHostnameMsg = new Msg({
type: Msg.Type.ERROR,
text: "Hostname you specified is not allowed."
});
client.emit("msg", {
msg: invalidHostnameMsg
});
return;
}
args.host = config.defaults.host;
args.port = config.defaults.port;
args.tls = config.defaults.tls;
}
var server = {
name: args.name || "",
host: args.host || "chat.freenode.net",
port: args.port || (args.tls ? 6697 : 6667),
host: args.host || "",
port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),
rejectUnauthorized: false
};
if (server.host.length === 0) {
var emptyHostnameMsg = new Msg({
type: Msg.Type.ERROR,
text: "You must specify a hostname to connect."
});
client.emit("msg", {
msg: emptyHostnameMsg
});
return;
}
if (config.bind) {
server.localAddress = config.bind;
if (args.tls) {