Skip to content

Commit

Permalink
Merge pull request #669 from Half-Shot/hs/double-bridging
Browse files Browse the repository at this point in the history
Double bridging rule files
  • Loading branch information
Half-Shot authored Oct 12, 2018
2 parents 98cd363 + 5e83785 commit 8c2f90c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ ircService:
# allotted time period, the provisioning request will fail.
# Default: 300 seconds (5 mins)
requestTimeoutSeconds: 300
# A file defining the provisioning rules for rooms. Format is documented
# in rules.sample.yaml. Leave undefined to not specify any rules.
ruleFile: "./provisioning.rules.yaml"
# Watch the file for changes, and apply the rules. Default: false
enableReload: true

# WARNING: The bridge needs to send plaintext passwords to the IRC server, it cannot
# send a password hash. As a result, passwords (NOT hashes) are stored encrypted in
Expand Down
13 changes: 12 additions & 1 deletion lib/bridge/IrcBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ function IrcBridge(config, registration) {
this.ircHandler = new IrcHandler(this, this.config.ircHandler);
this._clientPool = new ClientPool(this);
var dirPath = this.config.ircService.databaseUri.substring("nedb://".length);
let roomLinkValidation = undefined;
let provisioning = config.ircService.provisioning;
if (provisioning && provisioning.enabled &&
typeof (provisioning.ruleFile) === "string") {
roomLinkValidation = {
ruleFile: provisioning.ruleFile,
triggerEndpoint: provisioning.enableReload
};
}

this._bridge = new Bridge({
registration: this.registration,
homeserverUrl: this.config.homeserver.url,
Expand Down Expand Up @@ -89,7 +99,8 @@ function IrcBridge(config, registration) {
dontCheckPowerLevel: true,
enablePresence: this.config.homeserver.enablePresence,
}
}
},
roomLinkValidation,
});

this._timers = null; // lazy map of Histogram instances used as metrics
Expand Down
4 changes: 4 additions & 0 deletions lib/config/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ properties:
type: "boolean"
requestTimeoutSeconds:
type: "number"
ruleFile:
type: "string"
enableReload:
type: "boolean"
passwordEncryptionKeyPath:
type: "string"
matrixHandler:
Expand Down
10 changes: 10 additions & 0 deletions lib/provisioning/Provisioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ Provisioner.prototype._userHasProvisioningPower = Promise.coroutine(

// Try 100 times to join a room, or timeout after 10 min
yield retry(req, 100, 5000, matrixClient, matrixClient.joinRoom, roomId).timeout(600000);
try {
yield this._ircBridge.getAppServiceBridge().canProvisionRoom(roomId);
}
catch (err) {
req.log.error(`Room failed room validator check: (${err})`);
throw new Error(
'Room failed validation. You may be attempting to "double bridge" this room.' +
' Error: ' + err
);
}

try {
powerState = yield matrixClient.getStateEvent(roomId, 'm.room.power_levels');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"he": "^1.1.1",
"irc": "matrix-org/node-irc#c9abb427bec5016d94a2abf3e058cc62de09ea5a",
"js-yaml": "^3.2.7",
"matrix-appservice-bridge": "1.6.0c",
"matrix-appservice-bridge": "^1.7.0",
"nedb": "^1.1.2",
"nopt": "^3.0.1",
"prom-client": "^6.3.0",
Expand Down
12 changes: 12 additions & 0 deletions provisioning.rules.sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# A set of regexes to match against joined members in rooms.
# If one of the regexes matches a userId, then do not allow provisioning
# to the room UNLESS it also matches a exempt regex.
# This doesn't affect existing bridge entrys, only new provisioned rooms.
#
# For this to work, config.provisioning.ruleFile must point to this file.
userIds:
exempt:
- "@appservice-irc:localhost"
- "@irc_.+:localhost"
conflict:
- "@irc_.+:.+"
1 change: 1 addition & 0 deletions spec/util/client-sdk-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function MockClient(config) {
this.setRoomTopic = jasmine.createSpy("sdk.setRoomTopic(roomId, topic)");
this.setDisplayName = jasmine.createSpy("sdk.setDisplayName(name)");
this.getStateEvent = jasmine.createSpy("sdk.getStateEvent(room,type,key)");
this.fetchRoomEvent = jasmine.createSpy("sdk.fetchRoomEvent(room,event_id)");
this.sendStateEvent = jasmine.createSpy("sdk.sendStateEvent(room,type,content,key)");
this.sendEvent = jasmine.createSpy("sdk.sendEvent(roomId,type,content)");
this.invite = jasmine.createSpy("sdk.invite(roomId, userId)");
Expand Down

0 comments on commit 8c2f90c

Please sign in to comment.