From b0976a292f70c2c6d344bafd2793aed09027f74b Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 10 Nov 2011 11:37:12 +0100 Subject: [PATCH 1/2] Fixed a somewhat quirky random string generator, made another windows-only delay actually windows-only. --- node/handler/ImportHandler.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/node/handler/ImportHandler.js b/node/handler/ImportHandler.js index a1ddf9924..ec520a47c 100644 --- a/node/handler/ImportHandler.js +++ b/node/handler/ImportHandler.js @@ -112,7 +112,7 @@ exports.doImport = function(req, res, padId) //convert file to text function(callback) { - var randNum = Math.floor(Math.random()*new Date().getTime()); + var randNum = Math.floor(Math.random()*0xFFFFFFFF); destFile = tempDirectory + "eplite_import_" + randNum + ".txt"; abiword.convertFile(srcFile, destFile, "txt", callback); }, @@ -136,10 +136,13 @@ exports.doImport = function(req, res, padId) //node on windows has a delay on releasing of the file lock. //We add a 100ms delay to work around this - setTimeout(function() - { - callback(err); - }, 100); + if(os.type().indexOf("Windows") > -1) + { + setTimeout(function() + { + callback(err); + }, 100); + } }); }, From dc8ff695533d4ba07eff06eb4148797c2e9e9e2d Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 6 Dec 2011 22:00:42 +0100 Subject: [PATCH 2/2] mod so one can set passwords a) for pads that are in no group and b) via the web interface --- node/db/API.js | 8 ++--- node/db/GroupManager.js | 5 ++- node/db/Pad.js | 11 ++++--- node/db/SecurityManager.js | 4 +-- static/index.html | 67 +++++++++++++++++++++++++++++--------- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/node/db/API.js b/node/db/API.js index 9912b098d..973d60d28 100644 --- a/node/db/API.js +++ b/node/db/API.js @@ -280,11 +280,11 @@ Example returns: exports.setPublicStatus = function(padID, publicStatus, callback) { //ensure this is a group pad - if(padID.indexOf("$") == -1) + /*if(padID.indexOf("$") == -1) { callback({stop: "You can only get/set the publicStatus of pads that belong to a group"}); return; - } + }*/ //get the pad getPadSafe(padID, true, function(err, pad) @@ -349,8 +349,8 @@ exports.setPassword = function(padID, password, callback) //ensure this is a group pad if(padID.indexOf("$") == -1) { - callback({stop: "You can only get/set the password of pads that belong to a group"}); - return; + //callback({stop: "You can only get/set the password of pads that belong to a group"}); + //return; } //get the pad diff --git a/node/db/GroupManager.js b/node/db/GroupManager.js index 1598e72e1..df0445e1b 100644 --- a/node/db/GroupManager.js +++ b/node/db/GroupManager.js @@ -202,7 +202,7 @@ exports.createGroupPad = function(groupID, padName, text, callback) } }); }, - //ensure pad does not exists + //ensure pad does not exist function (callback) { padManager.doesPadExists(padID, function(err, exists) @@ -278,8 +278,7 @@ function randomString(len) var randomstring = ''; for (var i = 0; i < len; i++) { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); + randomstring += chars[Math.floor(Math.random() * chars.length)]; } return randomstring; } diff --git a/node/db/Pad.js b/node/db/Pad.js index bba7562c8..4214b8d99 100644 --- a/node/db/Pad.js +++ b/node/db/Pad.js @@ -52,7 +52,7 @@ Class('Pad', { publicStatus : { is: 'rw', - init: false, + init: true, getterName : 'getPublicStatus' }, //publicStatus @@ -486,7 +486,11 @@ Class('Pad', { }, setPassword: function(password) { - this.passwordHash = password == null ? null : hash(password, generateSalt()); + if(password == null){ + this.passwordHash = null; + }else{ + this.passwordHash = hash(password, generateSalt()); + } db.setSub("pad:"+this.id, ["passwordHash"], this.passwordHash); }, isCorrectPassword: function(password) @@ -516,8 +520,7 @@ function generateSalt() var randomstring = ''; for (var i = 0; i < len; i++) { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); + randomstring += chars[Math.floor(Math.random() * chars.length)]; } return randomstring; } diff --git a/node/db/SecurityManager.js b/node/db/SecurityManager.js index 7ad8f8d25..0a20a6f7d 100644 --- a/node/db/SecurityManager.js +++ b/node/db/SecurityManager.js @@ -35,7 +35,7 @@ var sessionManager = require("./SessionManager"); exports.checkAccess = function (padID, sessionID, token, password, callback) { // it's not a group pad, means we can grant access - if(padID.indexOf("$") == -1) + /*if(padID.indexOf("$") == -1) { //get author for this token authorManager.getAuthor4Token(token, function(err, author) @@ -46,7 +46,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback) //don't continue return; - } + }*/ var groupID = padID.split("$")[0]; var padExists = false; diff --git a/static/index.html b/static/index.html index e995cdb2f..a24a45e92 100644 --- a/static/index.html +++ b/static/index.html @@ -69,7 +69,7 @@ font-weight: bold; font-size: 15px } - input[type="text"] { + input[type="text"], input[type="password"] { width: 243px; padding: 10px 47px 10px 10px; background: #fff; @@ -78,7 +78,13 @@ border-radius: 3px; text-shadow: 0 0 1px #fff } - input[type="submit"] { + #usepwlabel { + display: inline; + } + #usePasswordContainer { + margin: 10px 0 5px 0 + } + input[type="submit"] { width: 45px; margin-left: -50px; padding: 8px @@ -88,39 +94,68 @@ +
New Pad

or create/open a Pad with the name
- - + +
+
+
- \ No newline at end of file +