mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
prepare to async: trivial reformatting
This change is only cosmetic. Its aim is do make it easier to understand the async changes that are going to be merged later on. It was extracted from the original work from Ray Bellis. To verify that nothing has changed, you can run the following command on each file touched by this commit: npm install uglify-es diff --unified <(uglify-js --beautify bracketize <BEFORE.js>) <(uglify-js --beautify bracketize <AFTER.js>) This is a complete script that does the same automatically (works from a mercurial clone): ```bash #!/usr/bin/env bash set -eu REVISION=<THIS_REVISION> PARENT_REV=$(hg identify --rev "${REVISION}" --template '{p1rev}') FILE_LIST=$(hg status --no-status --change ${REVISION}) UGLIFYJS="node_modules/uglify-es/bin/uglifyjs" for FILE_NAME in ${FILE_LIST[@]}; do echo "Checking ${FILE_NAME}" diff --unified \ <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${PARENT_REV}" "${FILE_NAME}")) \ <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${REVISION}" "${FILE_NAME}")) done ```
This commit is contained in:
parent
cc23bd18a4
commit
9497ee734f
33 changed files with 2706 additions and 2943 deletions
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* This is the Socket.IO Router. It routes the Messages between the
|
||||
* This is the Socket.IO Router. It routes the Messages between the
|
||||
* components of the Server. The components are at the moment: pad and timeslider
|
||||
*/
|
||||
|
||||
|
@ -31,20 +31,20 @@ var settings = require('../utils/Settings');
|
|||
* Saves all components
|
||||
* key is the component name
|
||||
* value is the component module
|
||||
*/
|
||||
*/
|
||||
var components = {};
|
||||
|
||||
var socket;
|
||||
|
||||
|
||||
/**
|
||||
* adds a component
|
||||
*/
|
||||
exports.addComponent = function(moduleName, module)
|
||||
{
|
||||
//save the component
|
||||
// save the component
|
||||
components[moduleName] = module;
|
||||
|
||||
//give the module the socket
|
||||
|
||||
// give the module the socket
|
||||
module.setSocketIO(socket);
|
||||
}
|
||||
|
||||
|
@ -52,57 +52,55 @@ exports.addComponent = function(moduleName, module)
|
|||
* sets the socket.io and adds event functions for routing
|
||||
*/
|
||||
exports.setSocketIO = function(_socket) {
|
||||
//save this socket internaly
|
||||
// save this socket internaly
|
||||
socket = _socket;
|
||||
|
||||
|
||||
socket.sockets.on('connection', function(client)
|
||||
{
|
||||
|
||||
// Broken: See http://stackoverflow.com/questions/4647348/send-message-to-specific-client-with-socket-io-and-node-js
|
||||
// Fixed by having a persistant object, ideally this would actually be in the database layer
|
||||
// TODO move to database layer
|
||||
if(settings.trustProxy && client.handshake.headers['x-forwarded-for'] !== undefined){
|
||||
if (settings.trustProxy && client.handshake.headers['x-forwarded-for'] !== undefined) {
|
||||
remoteAddress[client.id] = client.handshake.headers['x-forwarded-for'];
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
remoteAddress[client.id] = client.handshake.address;
|
||||
}
|
||||
|
||||
var clientAuthorized = false;
|
||||
|
||||
//wrap the original send function to log the messages
|
||||
|
||||
// wrap the original send function to log the messages
|
||||
client._send = client.send;
|
||||
client.send = function(message) {
|
||||
messageLogger.debug("to " + client.id + ": " + stringifyWithoutPassword(message));
|
||||
client._send(message);
|
||||
}
|
||||
|
||||
//tell all components about this connect
|
||||
for(var i in components) {
|
||||
components[i].handleConnect(client);
|
||||
}
|
||||
|
||||
client.on('message', function(message)
|
||||
{
|
||||
if(message.protocolVersion && message.protocolVersion != 2) {
|
||||
// tell all components about this connect
|
||||
for (var i in components) {
|
||||
components[i].handleConnect(client);
|
||||
}
|
||||
|
||||
client.on('message', function(message) {
|
||||
if (message.protocolVersion && message.protocolVersion != 2) {
|
||||
messageLogger.warn("Protocolversion header is not correct:" + stringifyWithoutPassword(message));
|
||||
return;
|
||||
}
|
||||
|
||||
//client is authorized, everything ok
|
||||
if(clientAuthorized) {
|
||||
if (clientAuthorized) {
|
||||
// client is authorized, everything ok
|
||||
handleMessage(client, message);
|
||||
} else { //try to authorize the client
|
||||
if(message.padId !== undefined && message.sessionID !== undefined && message.token !== undefined && message.password !== undefined) {
|
||||
} else {
|
||||
// try to authorize the client
|
||||
if (message.padId !== undefined && message.sessionID !== undefined && message.token !== undefined && message.password !== undefined) {
|
||||
var checkAccessCallback = function(err, statusObject) {
|
||||
ERR(err);
|
||||
|
||||
//access was granted, mark the client as authorized and handle the message
|
||||
if(statusObject.accessStatus == "grant") {
|
||||
if (statusObject.accessStatus == "grant") {
|
||||
// access was granted, mark the client as authorized and handle the message
|
||||
clientAuthorized = true;
|
||||
handleMessage(client, message);
|
||||
}
|
||||
//no access, send the client a message that tell him why
|
||||
else {
|
||||
} else {
|
||||
// no access, send the client a message that tells him why
|
||||
messageLogger.warn("Authentication try failed:" + stringifyWithoutPassword(message));
|
||||
client.json.send({accessStatus: statusObject.accessStatus});
|
||||
}
|
||||
|
@ -110,57 +108,55 @@ exports.setSocketIO = function(_socket) {
|
|||
if (message.padId.indexOf("r.") === 0) {
|
||||
readOnlyManager.getPadId(message.padId, function(err, value) {
|
||||
ERR(err);
|
||||
securityManager.checkAccess (value, message.sessionID, message.token, message.password, checkAccessCallback);
|
||||
securityManager.checkAccess(value, message.sessionID, message.token, message.password, checkAccessCallback);
|
||||
});
|
||||
} else {
|
||||
//this message has everything to try an authorization
|
||||
// this message has everything to try an authorization
|
||||
securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, checkAccessCallback);
|
||||
}
|
||||
} else { //drop message
|
||||
} else {
|
||||
// drop message
|
||||
messageLogger.warn("Dropped message cause of bad permissions:" + stringifyWithoutPassword(message));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.on('disconnect', function()
|
||||
{
|
||||
//tell all components about this disconnect
|
||||
for(var i in components)
|
||||
{
|
||||
client.on('disconnect', function() {
|
||||
// tell all components about this disconnect
|
||||
for (var i in components) {
|
||||
components[i].handleDisconnect(client);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//try to handle the message of this client
|
||||
// try to handle the message of this client
|
||||
function handleMessage(client, message)
|
||||
{
|
||||
|
||||
if(message.component && components[message.component]) {
|
||||
//check if component is registered in the components array
|
||||
if(components[message.component]) {
|
||||
if (message.component && components[message.component]) {
|
||||
// check if component is registered in the components array
|
||||
if (components[message.component]) {
|
||||
messageLogger.debug("from " + client.id + ": " + stringifyWithoutPassword(message));
|
||||
components[message.component].handleMessage(client, message);
|
||||
}
|
||||
} else {
|
||||
messageLogger.error("Can't route the message:" + stringifyWithoutPassword(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//returns a stringified representation of a message, removes the password
|
||||
//this ensures there are no passwords in the log
|
||||
// returns a stringified representation of a message, removes the password
|
||||
// this ensures there are no passwords in the log
|
||||
function stringifyWithoutPassword(message)
|
||||
{
|
||||
var newMessage = {};
|
||||
|
||||
for(var i in message)
|
||||
{
|
||||
if(i == "password" && message[i] != null)
|
||||
|
||||
for (var i in message) {
|
||||
if (i == "password" && message[i] != null) {
|
||||
newMessage["password"] = "xxx";
|
||||
else
|
||||
newMessage[i]=message[i];
|
||||
} else {
|
||||
newMessage[i] = message[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return JSON.stringify(newMessage);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue