Merge pull request #82 from xPaw/lock-server

Allow locking network configuration
This commit is contained in:
Jérémie Astori 2016-03-02 00:37:27 -05:00
commit ec37b6671b
3 changed files with 47 additions and 7 deletions

View File

@ -103,11 +103,11 @@
<label>Server</label> <label>Server</label>
</div> </div>
<div class="col-sm-6 col-xs-8"> <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>
<div class="col-sm-3 col-xs-4"> <div class="col-sm-3 col-xs-4">
<div class="port"> <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> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
@ -120,7 +120,7 @@
<div class="col-sm-3"></div> <div class="col-sm-3"></div>
<div class="col-sm-9"> <div class="col-sm-9">
<label class="tls"> <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 Enable TLS/SSL
</label> </label>
</div> </div>

View File

@ -79,14 +79,24 @@ module.exports = {
// //
// Display network // Display network
// //
// If set to false The Lounge will not expose network settings in login // If set to false network settings will not be shown in the login form.
// form, limiting client to connect to the configured network.
// //
// @type boolean // @type boolean
// @default true // @default true
// //
displayNetwork: 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 // Log settings
// //

View File

@ -123,13 +123,43 @@ Client.prototype.find = function(id) {
Client.prototype.connect = function(args) { Client.prototype.connect = function(args) {
var config = Helper.getConfig(); var config = Helper.getConfig();
var client = this; 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 = { var server = {
name: args.name || "", name: args.name || "",
host: args.host || "chat.freenode.net", host: args.host || "",
port: args.port || (args.tls ? 6697 : 6667), port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),
rejectUnauthorized: false 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) { if (config.bind) {
server.localAddress = config.bind; server.localAddress = config.bind;
if (args.tls) { if (args.tls) {