Skip to content

Commit

Permalink
Merge pull request #82 from xPaw/lock-server
Browse files Browse the repository at this point in the history
Allow locking network configuration
  • Loading branch information
astorije committed Mar 2, 2016
2 parents b39b569 + aab7f29 commit ec37b66
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
6 changes: 3 additions & 3 deletions client/index.html
Expand Up @@ -103,11 +103,11 @@ <h2>Network settings</h2>
<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>
Expand All @@ -120,7 +120,7 @@ <h2>Network settings</h2>
<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>
Expand Down
14 changes: 12 additions & 2 deletions defaults/config.js
Expand Up @@ -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
//
Expand Down
34 changes: 32 additions & 2 deletions src/client.js
Expand Up @@ -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) {
Expand Down

0 comments on commit ec37b66

Please sign in to comment.