From 8eb43a3ebf7c1b7bd5474d8abff4223b995e911b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Sun, 18 Mar 2012 09:05:46 +0100 Subject: [PATCH 01/16] replaceing AttributePoolFactory by AttributePool --- bin/convert.js | 4 +- src/node/db/Pad.js | 4 +- src/node/easysync_tests.js | 20 +-- src/node/handler/PadMessageHandler.js | 4 +- src/node/handler/TimesliderMessageHandler.js | 4 +- src/node/utils/tar.json | 4 +- src/static/js/AttributePoolFactory.js | 124 +++++++++---------- src/static/js/Changeset.js | 4 +- src/static/js/ace2_inner.js | 3 +- src/static/js/broadcast.js | 2 +- src/static/js/changesettracker.js | 6 +- 11 files changed, 90 insertions(+), 89 deletions(-) diff --git a/bin/convert.js b/bin/convert.js index 24fd393a5..ec792717e 100644 --- a/bin/convert.js +++ b/bin/convert.js @@ -6,7 +6,7 @@ var mysql = require("mysql"); var async = require("async"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; -var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFactory"); +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var settingsFile = process.argv[2]; var sqlOutputFile = process.argv[3]; @@ -384,7 +384,7 @@ function convertPad(padId, callback) } //generate the latest atext - var fullAPool = AttributePoolFactory.createAttributePool().fromJsonable(apool); + var fullAPool = (new AttributePool()).fromJsonable(apool); var keyRev = Math.floor(padmeta.head / padmeta.keyRevInterval) * padmeta.keyRevInterval; var atext = changesetsMeta[keyRev].atext; var curRev = keyRev; diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index b69780a41..c384f172c 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -5,7 +5,7 @@ var ERR = require("async-stacktrace"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); -var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFactory"); +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; var db = require("./DB").db; var async = require("async"); @@ -28,7 +28,7 @@ exports.cleanText = function (txt) { var Pad = function Pad(id) { this.atext = Changeset.makeAText("\n"); - this.pool = AttributePoolFactory.createAttributePool(); + this.pool = new AttributePool(); this.head = -1; this.chatHead = -1; this.publicStatus = false; diff --git a/src/node/easysync_tests.js b/src/node/easysync_tests.js index 7a1482897..374e949fd 100644 --- a/src/node/easysync_tests.js +++ b/src/node/easysync_tests.js @@ -22,7 +22,7 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset"); -var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFactory"); +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); function random() { this.nextInt = function (maxValue) { @@ -227,7 +227,7 @@ function runTests() { return attribs; // it's already an attrib pool } else { // assume it's an array of attrib strings to be split and added - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); attribs.forEach(function (kv) { p.putAttrib(kv.split(',')); }); @@ -325,7 +325,7 @@ function runTests() { runMutateAttributionTest(4, ['foo,bar', 'line,1', 'line,2', 'line,3', 'line,4', 'line,5'], "Z:5>1|2=2+1$x", ["?*1|1+1", "?*2|1+1", "*3|1+1", "?*4|1+1", "?*5|1+1"], ["?*1|1+1", "?*2|1+1", "+1*3|1+1", "?*4|1+1", "?*5|1+1"]); var testPoolWithChars = (function () { - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); p.putAttrib(['char', 'newline']); for (var i = 1; i < 36; i++) { p.putAttrib(['char', Changeset.numToString(i)]); @@ -560,7 +560,7 @@ function runTests() { var rand = new random(); print("> testCompose#" + randomSeed); - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); var startText = randomMultiline(10, 20, rand) + '\n'; @@ -594,7 +594,7 @@ function runTests() { (function simpleComposeAttributesTest() { print("> simpleComposeAttributesTest"); - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); p.putAttrib(['bold', '']); p.putAttrib(['bold', 'true']); var cs1 = Changeset.checkRep("Z:2>1*1+1*1=1$x"); @@ -604,7 +604,7 @@ function runTests() { })(); (function followAttributesTest() { - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); p.putAttrib(['x', '']); p.putAttrib(['x', 'abc']); p.putAttrib(['x', 'def']); @@ -633,7 +633,7 @@ function runTests() { var rand = new random(); print("> testFollow#" + randomSeed); - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); var startText = randomMultiline(10, 20, rand) + '\n'; @@ -682,8 +682,8 @@ function runTests() { (function testMoveOpsToNewPool() { print("> testMoveOpsToNewPool"); - var pool1 = AttributePoolFactory.createAttributePool(); - var pool2 = AttributePoolFactory.createAttributePool(); + var pool1 = new AttributePool(); + var pool2 = new AttributePool(); pool1.putAttrib(['baz', 'qux']); pool1.putAttrib(['foo', 'bar']); @@ -738,7 +738,7 @@ function runTests() { (function testOpAttributeValue() { print("> testOpAttributeValue"); - var p = AttributePoolFactory.createAttributePool(); + var p = new AttributePool(); p.putAttrib(['name', 'david']); p.putAttrib(['color', 'green']); diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index e26bb46e9..b9ab6494d 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -23,7 +23,7 @@ var ERR = require("async-stacktrace"); var async = require("async"); var padManager = require("../db/PadManager"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); -var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFactory"); +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var authorManager = require("../db/AuthorManager"); var readOnlyManager = require("../db/ReadOnlyManager"); var settings = require('../utils/Settings'); @@ -368,7 +368,7 @@ function handleUserChanges(client, message) //get all Vars we need var baseRev = message.data.baseRev; - var wireApool = (AttributePoolFactory.createAttributePool()).fromJsonable(message.data.apool); + var wireApool = (new AttributePool()).fromJsonable(message.data.apool); var changeset = message.data.changeset; var r, apool, pad; diff --git a/src/node/handler/TimesliderMessageHandler.js b/src/node/handler/TimesliderMessageHandler.js index 0081e645d..da8597791 100644 --- a/src/node/handler/TimesliderMessageHandler.js +++ b/src/node/handler/TimesliderMessageHandler.js @@ -23,7 +23,7 @@ var ERR = require("async-stacktrace"); var async = require("async"); var padManager = require("../db/PadManager"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); -var AttributePoolFactory = require("ep_etherpad-lite/static/js/AttributePoolFactory"); +var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); var settings = require('../utils/Settings'); var authorManager = require("../db/AuthorManager"); var log4js = require('log4js'); @@ -265,7 +265,7 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback) var forwardsChangesets = []; var backwardsChangesets = []; var timeDeltas = []; - var apool = AttributePoolFactory.createAttributePool(); + var apool = new AttributePool(); var pad; var composedChangesets = {}; var revisionDate = []; diff --git a/src/node/utils/tar.json b/src/node/utils/tar.json index a905eb442..3f6550e77 100644 --- a/src/node/utils/tar.json +++ b/src/node/utils/tar.json @@ -39,7 +39,7 @@ , "pad_modals.js" , "pad_savedrevs.js" , "pad_impexp.js" - , "AttributePoolFactory.js" + , "AttributePool.js" , "Changeset.js" , "domline.js" , "linestylefilter.js" @@ -51,7 +51,7 @@ ] , "ace2_inner.js": [ "ace2_common.js" - , "AttributePoolFactory.js" + , "AttributePool.js" , "Changeset.js" , "security.js" , "skiplist.js" diff --git a/src/static/js/AttributePoolFactory.js b/src/static/js/AttributePoolFactory.js index 00b58dbb3..a9245daf8 100644 --- a/src/static/js/AttributePoolFactory.js +++ b/src/static/js/AttributePoolFactory.js @@ -22,69 +22,69 @@ * limitations under the License. */ -exports.createAttributePool = function () { - var p = {}; - p.numToAttrib = {}; // e.g. {0: ['foo','bar']} - p.attribToNum = {}; // e.g. {'foo,bar': 0} - p.nextNum = 0; +var AttributePool = function () { + this.numToAttrib = {}; // e.g. {0: ['foo','bar']} + this.attribToNum = {}; // e.g. {'foo,bar': 0} + this.nextNum = 0; +}; - p.putAttrib = function (attrib, dontAddIfAbsent) { - var str = String(attrib); - if (str in p.attribToNum) { - return p.attribToNum[str]; - } - if (dontAddIfAbsent) { - return -1; - } - var num = p.nextNum++; - p.attribToNum[str] = num; - p.numToAttrib[num] = [String(attrib[0] || ''), String(attrib[1] || '')]; - return num; +AttributePool.prototype.putAttrib = function (attrib, dontAddIfAbsent) { + var str = String(attrib); + if (str in this.attribToNum) { + return this.attribToNum[str]; + } + if (dontAddIfAbsent) { + return -1; + } + var num = this.nextNum++; + this.attribToNum[str] = num; + this.numToAttrib[num] = [String(attrib[0] || ''), String(attrib[1] || '')]; + return num; +}; + +AttributePool.prototype.getAttrib = function (num) { + var pair = this.numToAttrib[num]; + if (!pair) { + return pair; + } + return [pair[0], pair[1]]; // return a mutable copy +}; + +AttributePool.prototype.getAttribKey = function (num) { + var pair = this.numToAttrib[num]; + if (!pair) return ''; + return pair[0]; +}; + +AttributePool.prototype.getAttribValue = function (num) { + var pair = this.numToAttrib[num]; + if (!pair) return ''; + return pair[1]; +}; + +AttributePool.prototype.eachAttrib = function (func) { + for (var n in this.numToAttrib) { + var pair = this.numToAttrib[n]; + func(pair[0], pair[1]); + } +}; + +AttributePool.prototype.toJsonable = function () { + return { + numToAttrib: this.numToAttrib, + nextNum: this.nextNum }; +}; - p.getAttrib = function (num) { - var pair = p.numToAttrib[num]; - if (!pair) { - return pair; - } - return [pair[0], pair[1]]; // return a mutable copy - }; +AttributePool.prototype.fromJsonable = function (obj) { + this.numToAttrib = obj.numToAttrib; + this.nextNum = obj.nextNum; + this.attribToNum = {}; + for (var n in this.numToAttrib) { + this.attribToNum[String(this.numToAttrib[n])] = Number(n); + } + return this; +}; + - p.getAttribKey = function (num) { - var pair = p.numToAttrib[num]; - if (!pair) return ''; - return pair[0]; - }; - - p.getAttribValue = function (num) { - var pair = p.numToAttrib[num]; - if (!pair) return ''; - return pair[1]; - }; - - p.eachAttrib = function (func) { - for (var n in p.numToAttrib) { - var pair = p.numToAttrib[n]; - func(pair[0], pair[1]); - } - }; - - p.toJsonable = function () { - return { - numToAttrib: p.numToAttrib, - nextNum: p.nextNum - }; - }; - - p.fromJsonable = function (obj) { - p.numToAttrib = obj.numToAttrib; - p.nextNum = obj.nextNum; - p.attribToNum = {}; - for (var n in p.numToAttrib) { - p.attribToNum[String(p.numToAttrib[n])] = Number(n); - } - return p; - }; - - return p; -} +module.exports = AttributePool; \ No newline at end of file diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index fd1900ba7..738ee1bab 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -25,7 +25,7 @@ * limitations under the License. */ -var AttributePoolFactory = require("./AttributePoolFactory"); +var AttributePool = require("./AttributePool"); var _opt = null; @@ -1731,7 +1731,7 @@ exports.appendATextToAssembler = function (atext, assem) { * @param pool {AtributePool} */ exports.prepareForWire = function (cs, pool) { - var newPool = AttributePoolFactory.createAttributePool();; + var newPool = new AttributePool(); var newCs = exports.moveOpsToNewPool(cs, pool, newPool); return { translated: newCs, diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 66f19faf1..d278254ff 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -43,7 +43,7 @@ var colorutils = require('./colorutils').colorutils; var makeContentCollector = require('./contentcollector').makeContentCollector; var makeCSSManager = require('./cssmanager').makeCSSManager; var domline = require('./domline').domline; -var AttribPool = require('./AttributePoolFactory').createAttributePool; +var AttribPool = require('./AttributePool'); var Changeset = require('./Changeset'); var linestylefilter = require('./linestylefilter').linestylefilter; var newSkipList = require('./skiplist').newSkipList; @@ -51,6 +51,7 @@ var undoModule = require('./undomodule').undoModule; var makeVirtualLineView = require('./virtual_lines').makeVirtualLineView; function Ace2Inner(){ + var DEBUG = false; //$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;" // changed to false var isSetUp = false; diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js index 485db44fb..333e3b652 100644 --- a/src/static/js/broadcast.js +++ b/src/static/js/broadcast.js @@ -22,7 +22,7 @@ var makeCSSManager = require('./cssmanager').makeCSSManager; var domline = require('./domline').domline; -var AttribPool = require('./AttributePoolFactory').createAttributePool; +var AttribPool = require('./AttributePool'); var Changeset = require('./Changeset'); var linestylefilter = require('./linestylefilter').linestylefilter; var colorutils = require('./colorutils').colorutils; diff --git a/src/static/js/changesettracker.js b/src/static/js/changesettracker.js index b02198526..58ef21cb5 100644 --- a/src/static/js/changesettracker.js +++ b/src/static/js/changesettracker.js @@ -20,7 +20,7 @@ * limitations under the License. */ -var AttribPool = require('./AttributePoolFactory').createAttributePool; +var AttributePool = require('./AttributePool'); var Changeset = require('./Changeset'); function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) @@ -83,7 +83,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) baseAText = Changeset.cloneAText(atext); if (apoolJsonObj) { - var wireApool = (new AttribPool()).fromJsonable(apoolJsonObj); + var wireApool = (new AttributePool()).fromJsonable(apoolJsonObj); baseAText.attribs = Changeset.moveOpsToNewPool(baseAText.attribs, wireApool, apool); } submittedChangeset = null; @@ -117,7 +117,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) if (apoolJsonObj) { - var wireApool = (new AttribPool()).fromJsonable(apoolJsonObj); + var wireApool = (new AttributePool()).fromJsonable(apoolJsonObj); c = Changeset.moveOpsToNewPool(c, wireApool, apool); } From 902837f29580996643c99e3b00e74605691cd659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Sun, 18 Mar 2012 09:06:29 +0100 Subject: [PATCH 02/16] renaming AttributePoolFactory --- src/static/js/{AttributePoolFactory.js => AttributePool.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/static/js/{AttributePoolFactory.js => AttributePool.js} (100%) diff --git a/src/static/js/AttributePoolFactory.js b/src/static/js/AttributePool.js similarity index 100% rename from src/static/js/AttributePoolFactory.js rename to src/static/js/AttributePool.js From 38742401c97531d166ad5a02b4e45de913ec272f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Sun, 18 Mar 2012 11:34:56 +0100 Subject: [PATCH 03/16] newSkipList() -> new SkipList() --- src/static/js/ace2_inner.js | 4 ++-- src/static/js/skiplist.js | 36 +++++++----------------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index d278254ff..f30a0467d 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -46,7 +46,7 @@ var domline = require('./domline').domline; var AttribPool = require('./AttributePool'); var Changeset = require('./Changeset'); var linestylefilter = require('./linestylefilter').linestylefilter; -var newSkipList = require('./skiplist').newSkipList; +var SkipList = require('./skiplist'); var undoModule = require('./undomodule').undoModule; var makeVirtualLineView = require('./virtual_lines').makeVirtualLineView; @@ -95,7 +95,7 @@ function Ace2Inner(){ // native IE selections have that behavior (which we try not to interfere with). // Must be false if selection is collapsed! var rep = { - lines: newSkipList(), + lines: new SkipList(), selStart: null, selEnd: null, selFocusAtStart: false, diff --git a/src/static/js/skiplist.js b/src/static/js/skiplist.js index 190bc55b9..2132d8e30 100644 --- a/src/static/js/skiplist.js +++ b/src/static/js/skiplist.js @@ -20,11 +20,11 @@ * limitations under the License. */ +var Ace2Common = require('./ace2_common'); +var noop = Ace2Common.noop; +var extend = Ace2Common.extend; -var noop = require('./ace2_common').noop; - - -function newSkipList() +function SkipList() { var PROFILER = window.PROFILER; if (!PROFILER) @@ -284,27 +284,6 @@ function newSkipList() } return dist; } -/*function _debugToString() { - var array = [start]; - while (array[array.length-1] !== end) { - array[array.length] = array[array.length-1].downPtrs[0]; - } - function getIndex(node) { - if (!node) return null; - for(var i=0;i Date: Tue, 27 Mar 2012 11:44:21 +0200 Subject: [PATCH 04/16] use underscore in skipList --- src/static/js/skiplist.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/static/js/skiplist.js b/src/static/js/skiplist.js index 2132d8e30..58477acca 100644 --- a/src/static/js/skiplist.js +++ b/src/static/js/skiplist.js @@ -20,9 +20,10 @@ * limitations under the License. */ -var Ace2Common = require('./ace2_common'); +var Ace2Common = require('./ace2_common'), + _ = require('./underscore'); + var noop = Ace2Common.noop; -var extend = Ace2Common.extend; function SkipList() { @@ -324,8 +325,9 @@ function SkipList() /* The skip-list contains "entries", JavaScript objects that each must have a unique "key" property that is a string. -*/ - extend(this, { + */ + var self = this; + _.extend(this, { length: function() { return numNodes; From bc76913a6dd8a87a4f34649a1bbaa2c28429dd2f Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 31 Mar 2012 18:15:08 +0100 Subject: [PATCH 05/16] fix pitas fix --- src/node/db/PadManager.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node/db/PadManager.js b/src/node/db/PadManager.js index 4e3a31999..5f08b1b1b 100644 --- a/src/node/db/PadManager.js +++ b/src/node/db/PadManager.js @@ -115,7 +115,13 @@ exports.doesPadExists = function(padId, callback) db.get("pad:"+padId, function(err, value) { if(ERR(err, callback)) return; - callback(null, value != null && value.atext); + if(value != null && value.atext){ + callback(null, true); + } + else + { + callback(null, false); + } }); } From c55f54b972e42cdaef6cb402d84027bd39ac5774 Mon Sep 17 00:00:00 2001 From: Sofian Benaissa Date: Tue, 13 Mar 2012 11:54:49 -0300 Subject: [PATCH 06/16] Fix the nocolor embed parameter --- src/static/js/pad_editor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/static/js/pad_editor.js b/src/static/js/pad_editor.js index 12f83aeb6..b8a4ea0ee 100644 --- a/src/static/js/pad_editor.js +++ b/src/static/js/pad_editor.js @@ -87,8 +87,6 @@ var padeditor = (function() return defaultValue; } - self.ace.setProperty("showsauthorcolors", !settings.noColors); - self.ace.setProperty("rtlIsTrue", settings.rtlIsTrue); var v; @@ -100,6 +98,8 @@ var padeditor = (function() v = getOption('showAuthorColors', true); self.ace.setProperty("showsauthorcolors", v); padutils.setCheckbox($("#options-colorscheck"), v); + // Override from parameters + self.ace.setProperty("showsauthorcolors", !settings.noColors); v = getOption('useMonospaceFont', false); self.ace.setProperty("textface", (v ? "monospace" : "Arial, sans-serif")); From 396b586dbddaa681eebdca65df0ab274f563f5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Tue, 3 Apr 2012 14:17:19 +0200 Subject: [PATCH 07/16] when no password is set, dont allow access to admin page --- settings.json.template | 4 ++-- src/node/hooks/express/webaccess.js | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/settings.json.template b/settings.json.template index ff1359933..7aaa5d7ed 100644 --- a/settings.json.template +++ b/settings.json.template @@ -50,8 +50,8 @@ /* This setting is used if you need http basic auth */ // "httpAuth" : "user:pass", - /* This setting is used for http basic auth for admin pages */ - "adminHttpAuth" : "user:pass", + /* This setting is used for http basic auth for admin pages. If not set, the admin page won't be accessible from web*/ + // "adminHttpAuth" : "user:pass", /* The log level we are using, can be: DEBUG, INFO, WARN, ERROR */ "loglevel": "INFO", diff --git a/src/node/hooks/express/webaccess.js b/src/node/hooks/express/webaccess.js index e77e133c4..d0e287373 100644 --- a/src/node/hooks/express/webaccess.js +++ b/src/node/hooks/express/webaccess.js @@ -6,22 +6,30 @@ var settings = require('../../utils/Settings'); //checks for basic http auth exports.basicAuth = function (req, res, next) { - var pass = settings.httpAuth; + + // When handling HTTP-Auth, an undefined password will lead to no authorization at all + var pass = settings.httpAuth || ''; + if (req.path.indexOf('/admin') == 0) { var pass = settings.adminHttpAuth; + } - // Just pass if not activated in Activate http basic auth if it has been defined in settings.json - if (!pass) { + + // Just pass if password is an empty string + if (pass === '') { return next(); } - - if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) { - // fetch login and password - if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() == pass) { + + + // If a password has been set and auth headers are present... + if (pass && req.headers.authorization && req.headers.authorization.search('Basic ') === 0) { + // ...check login and password + if (new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString() === pass) { return next(); } } + // Otherwise return Auth required Headers, delayed for 1 second, if auth failed. res.header('WWW-Authenticate', 'Basic realm="Protected Area"'); if (req.headers.authorization) { setTimeout(function () { From 7fbcffb30b050b49b4db5b181ca211f9e07b78a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Tue, 3 Apr 2012 20:42:02 +0200 Subject: [PATCH 08/16] fix crash if getFileCompressed fails (i.e. if /static/js is called) --- src/node/utils/Minify.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index b5d7b4727..1466ceafb 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -131,7 +131,10 @@ exports.minify = function(req, res, next) res.end(); } else if (req.method == 'GET') { getFileCompressed(filename, contentType, function (error, content) { - if(ERR(error)) return; + if(ERR(error, function(){ + res.writeHead(500, {}); + res.end(); + })) return; res.header("Content-Type", contentType); res.writeHead(200, {}); res.write(content); From b2173a10846afd08012d8f082b112ca6e29f8285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 09:40:18 +0200 Subject: [PATCH 09/16] get rid of node.extend (since duplicated by underscorejs) --- src/package.json | 5 ++--- src/static/js/pluginfw/plugins.js | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/package.json b/src/package.json index 0d4ad5386..83441da08 100644 --- a/src/package.json +++ b/src/package.json @@ -23,9 +23,8 @@ "log4js" : "0.4.1", "jsdom-nocontextifiy" : "0.2.10", "async-stacktrace" : "0.0.2", - "npm" : "1.1", - "ejs" : "0.6.1", - "node.extend" : "1.0.0", + "npm" : "1.1", + "ejs" : "0.6.1", "graceful-fs" : "1.1.5", "slide" : "1.1.3", "semver" : "1.0.13", diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 058f1351f..3bc13ff60 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -12,7 +12,6 @@ if (!exports.isClient) { var fs = require("fs"); var tsort = require("./tsort"); var util = require("util"); - var extend = require("node.extend"); _ = require("underscore"); }else{ var $, jQuery @@ -123,7 +122,7 @@ exports.getPackages = function (cb) { function flatten(deps) { _.chain(deps).keys().each(function (name) { if (name.indexOf(exports.prefix) == 0) { - packages[name] = extend({}, deps[name]); + packages[name] = _.clone(deps[name]); // Delete anything that creates loops so that the plugin // list can be sent as JSON to the web client delete packages[name].dependencies; From 5a779794863c81cb8f297500414fdcb7e2d3ff78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 09:51:46 +0200 Subject: [PATCH 10/16] make jshint happy --- src/static/js/pluginfw/plugins.js | 59 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 3bc13ff60..1cf1023e2 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -14,7 +14,7 @@ if (!exports.isClient) { var util = require("util"); _ = require("underscore"); }else{ - var $, jQuery + var $, jQuery; $ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$; _ = require("ep_etherpad-lite/static/js/underscore"); } @@ -30,15 +30,15 @@ exports.ensure = function (cb) { exports.update(cb); else cb(); -} +}; exports.formatPlugins = function () { return _.keys(exports.plugins).join(", "); -} +}; exports.formatParts = function () { return _.map(exports.parts, function (part) { return part.full_name; }).join("\n"); -} +}; exports.formatHooks = function () { var res = []; @@ -48,7 +48,7 @@ exports.formatHooks = function () { }); }); return res.join("\n"); -} +}; exports.loadFn = function (path) { var x = path.split(":"); @@ -57,7 +57,7 @@ exports.loadFn = function (path) { fn = fn[name]; }); return fn; -} +}; exports.extractHooks = function (parts, hook_set_name) { var hooks = {}; @@ -69,12 +69,12 @@ exports.extractHooks = function (parts, hook_set_name) { if (hook_fn) { hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part}); } else { - console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); + console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); } }); }); return hooks; -} +}; if (exports.isClient) { @@ -89,7 +89,7 @@ if (exports.isClient) { console.error("Failed to load plugin-definitions: " + err); cb(); }); - } + }; } else { exports.update = function (cb) { @@ -103,15 +103,15 @@ exports.update = function (cb) { exports.loadPlugin(packages, plugin_name, plugins, parts, cb); }, function (err) { - exports.plugins = plugins; + exports.plugins = plugins; exports.parts = exports.sortParts(parts); exports.hooks = exports.extractHooks(exports.parts, "hooks"); - exports.loaded = true; + exports.loaded = true; cb(err); } ); }); -} + }; exports.getPackages = function (cb) { // Load list of installed NPM packages, flatten it to a list, and filter out only packages with names that @@ -121,49 +121,50 @@ exports.getPackages = function (cb) { var packages = {}; function flatten(deps) { _.chain(deps).keys().each(function (name) { - if (name.indexOf(exports.prefix) == 0) { + if (name.indexOf(exports.prefix) === 0) { packages[name] = _.clone(deps[name]); // Delete anything that creates loops so that the plugin // list can be sent as JSON to the web client delete packages[name].dependencies; delete packages[name].parent; - } - if (deps[name].dependencies !== undefined) - flatten(deps[name].dependencies); + } + + if (deps[name].dependencies !== undefined) flatten(deps[name].dependencies); }); } + var tmp = {}; tmp[data.name] = data; flatten(tmp); cb(null, packages); }); -} + }; -exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) { + exports.loadPlugin = function (packages, plugin_name, plugins, parts, cb) { var plugin_path = path.resolve(packages[plugin_name].path, "ep.json"); fs.readFile( plugin_path, function (er, data) { if (er) { - console.error("Unable to load plugin definition file " + plugin_path); + console.error("Unable to load plugin definition file " + plugin_path); return cb(); } try { var plugin = JSON.parse(data); - plugin.package = packages[plugin_name]; - plugins[plugin_name] = plugin; - _.each(plugin.parts, function (part) { - part.plugin = plugin_name; - part.full_name = plugin_name + "/" + part.name; - parts[part.full_name] = part; - }); + plugin['package'] = packages[plugin_name]; + plugins[plugin_name] = plugin; + _.each(plugin.parts, function (part) { + part.plugin = plugin_name; + part.full_name = plugin_name + "/" + part.name; + parts[part.full_name] = part; + }); } catch (ex) { - console.error("Unable to parse plugin definition file " + plugin_path + ": " + ex.toString()); + console.error("Unable to parse plugin definition file " + plugin_path + ": " + ex.toString()); } cb(); } ); -} + }; exports.partsToParentChildList = function (parts) { var res = []; @@ -179,7 +180,7 @@ exports.partsToParentChildList = function (parts) { } }); return res; -} +}; // Used only in Node, so no need for _ From 5115f74f6679af7d7eda37873c92ae936e270df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 15:03:28 +0200 Subject: [PATCH 11/16] use hook name as function name, if not specified Example `"[hookName]": "ep_plugin/static/js/index:[hookName]"` becomes `"[hookName]": "ep_plugin/static/js/index"` --- src/static/js/pluginfw/plugins.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 058f1351f..b56c0dd9f 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -51,10 +51,12 @@ exports.formatHooks = function () { return res.join("\n"); } -exports.loadFn = function (path) { +exports.loadFn = function (path, hookName) { var x = path.split(":"); var fn = require(x[0]); - _.each(x[1].split("."), function (name) { + var functionName = x[1] ? x[1] : hookName; + + _.each(functionName.split("."), function (name) { fn = fn[name]; }); return fn; @@ -63,14 +65,18 @@ exports.loadFn = function (path) { exports.extractHooks = function (parts, hook_set_name) { var hooks = {}; _.each(parts,function (part) { - _.chain(part[hook_set_name] || {}).keys().each(function (hook_name) { + _.chain(part[hook_set_name] || {}) + .keys() + .each(function (hook_name) { if (hooks[hook_name] === undefined) hooks[hook_name] = []; + + var hook_fn_name = part[hook_set_name][hook_name]; - var hook_fn = exports.loadFn(part[hook_set_name][hook_name]); + var hook_fn = exports.loadFn(hook_fn_name, hook_name); if (hook_fn) { hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part}); } else { - console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); + console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]); } }); }); From f34e13f761646bf75d7f41a4d8958bb6033a48a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 15:10:27 +0200 Subject: [PATCH 12/16] on plugin definitions, only expose plugins with client_hooks registered. dont expose 'package' property --- src/node/hooks/express/static.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 9209967ce..f284e4783 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -6,6 +6,7 @@ var settings = require("../../utils/Settings"); var Yajsml = require('yajsml'); var fs = require("fs"); var ERR = require("async-stacktrace"); +var _ = require("underscore"); exports.expressCreateServer = function (hook_name, args, cb) { // Cache both minified and static. @@ -35,8 +36,22 @@ exports.expressCreateServer = function (hook_name, args, cb) { // serve plugin definitions // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) { + + var clientParts = _(plugins.parts) + .filter(function(part){ return _(part).has('client_hooks') }); + + var clientPlugins = {}; + + _(clientParts).chain() + .map(function(part){ return part.plugin }) + .uniq() + .each(function(name){ + clientPlugins[name] = _(plugins.plugins[name]).clone(); + delete clientPlugins[name]['package']; + }); + res.header("Content-Type","application/json; charset=utf-8"); - res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts})); + res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts})); res.end(); }); } From 5c4551b09857d20a7a8e206e1ab65504acc05044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bartelme=C3=9F?= Date: Wed, 4 Apr 2012 17:41:03 +0200 Subject: [PATCH 13/16] remove maxAge: undefined header, send maxAge even if set to 0 --- src/node/hooks/express/specialpages.js | 12 ++++++------ src/node/server.js | 4 ---- src/node/utils/Minify.js | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js index 585a7eab8..474f475ec 100644 --- a/src/node/hooks/express/specialpages.js +++ b/src/node/hooks/express/specialpages.js @@ -6,27 +6,27 @@ exports.expressCreateServer = function (hook_name, args, cb) { //serve index.html under / args.app.get('/', function(req, res) { - res.send(eejs.require("ep_etherpad-lite/templates/index.html"), { maxAge: exports.maxAge }); + res.send(eejs.require("ep_etherpad-lite/templates/index.html")); }); //serve robots.txt args.app.get('/robots.txt', function(req, res) { var filePath = path.normalize(__dirname + "/../../../static/robots.txt"); - res.sendfile(filePath, { maxAge: exports.maxAge }); + res.sendfile(filePath); }); //serve favicon.ico args.app.get('/favicon.ico', function(req, res) { var filePath = path.normalize(__dirname + "/../../../static/custom/favicon.ico"); - res.sendfile(filePath, { maxAge: exports.maxAge }, function(err) + res.sendfile(filePath, function(err) { //there is no custom favicon, send the default favicon if(err) { filePath = path.normalize(__dirname + "/../../../static/favicon.ico"); - res.sendfile(filePath, { maxAge: exports.maxAge }); + res.sendfile(filePath); } }); }); @@ -34,13 +34,13 @@ exports.expressCreateServer = function (hook_name, args, cb) { //serve pad.html under /p args.app.get('/p/:pad', function(req, res, next) { - res.send(eejs.require("ep_etherpad-lite/templates/pad.html"), { maxAge: exports.maxAge }); + res.send(eejs.require("ep_etherpad-lite/templates/pad.html")); }); //serve timeslider.html under /p/$padname/timeslider args.app.get('/p/:pad/timeslider', function(req, res, next) { - res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html"), { maxAge: exports.maxAge }); + res.send(eejs.require("ep_etherpad-lite/templates/timeslider.html")); }); } \ No newline at end of file diff --git a/src/node/server.js b/src/node/server.js index 8e6d6fa0b..bc4333cdc 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -51,10 +51,6 @@ console.log("Report bugs at https://github.com/Pita/etherpad-lite/issues") var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)"; -//cache 6 hours, by default -var hour = 60*60; -exports.maxAge = settings.maxAge || 6 * hour; - //set loglevel log4js.setGlobalLogLevel(settings.loglevel); diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index 1466ceafb..c59965653 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -108,7 +108,7 @@ exports.minify = function(req, res, next) date = new Date(date); res.setHeader('last-modified', date.toUTCString()); res.setHeader('date', (new Date()).toUTCString()); - if (settings.maxAge) { + if (settings.maxAge !== undefined) { var expiresDate = new Date((new Date()).getTime()+settings.maxAge*1000); res.setHeader('expires', expiresDate.toUTCString()); res.setHeader('cache-control', 'max-age=' + settings.maxAge); From d3cc8e33741489e34e9d7b6a90f4550910d4e951 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Thu, 5 Apr 2012 17:49:03 +0100 Subject: [PATCH 14/16] Make the console show the url that admin/plugins is available at --- src/node/server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node/server.js b/src/node/server.js index bc4333cdc..6b443edb7 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -88,7 +88,12 @@ async.waterfall([ //let the server listen app.listen(settings.port, settings.ip); console.log("Server is listening at " + settings.ip + ":" + settings.port); - + if(settings.adminHttpAuth){ + console.log("Plugin admin page listening at " + settings.ip + ":" + settings.port + "/admin/plugins"); + } + else{ + console.log("Admin username and password not set in settings.json. To access admin please uncomment and edit adminHttpAuth in settings.json"); + } callback(null); } ]); From 28aeb24f86724040281d8a636b1211c7dc5724b4 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Thu, 5 Apr 2012 18:00:38 +0100 Subject: [PATCH 15/16] add some sense to the buttons on the plugin page --- src/templates/admin/plugins.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/admin/plugins.html b/src/templates/admin/plugins.html index 7dcb6fa3e..2d419bc2a 100644 --- a/src/templates/admin/plugins.html +++ b/src/templates/admin/plugins.html @@ -167,7 +167,7 @@ - + @@ -195,7 +195,7 @@ - + From 66fdacf9cf31343721dd8fb38a4584e11ea76e6e Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Thu, 5 Apr 2012 18:04:17 +0100 Subject: [PATCH 16/16] move css out of html --- src/static/css/admin.css | 49 +++++++++++++++++++++++++++++ src/templates/admin/plugins.html | 53 ++------------------------------ 2 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/static/css/admin.css diff --git a/src/static/css/admin.css b/src/static/css/admin.css new file mode 100644 index 000000000..80089c4ca --- /dev/null +++ b/src/static/css/admin.css @@ -0,0 +1,49 @@ +table { + border-collapse: collapse; +} +td, th { + border: 1px solid black; + padding-left: 10px; + padding-right: 10px; + padding-top: 2px; + padding-bottom: 2px; +} +.template { + display: none; +} +.dialog { + display: none; + position: absolute; + left: 50%; + top: 50%; + width: 700px; + height: 500px; + margin-left: -350px; + margin-top: -250px; + border: 3px solid #999999; + background: #eeeeee; +} +.dialog .title { + margin: 0; + padding: 2px; + border-bottom: 3px solid #999999; + font-size: 24px; + line-height: 24px; + height: 24px; + overflow: hidden; +} +.dialog .title .close { + float: right; +} +.dialog .history { + background: #222222; + color: #eeeeee; + position: absolute; + top: 41px; + bottom: 10px; + left: 10px; + right: 10px; + padding: 2px; + overflow: auto; +} + diff --git a/src/templates/admin/plugins.html b/src/templates/admin/plugins.html index 2d419bc2a..5e5a1b035 100644 --- a/src/templates/admin/plugins.html +++ b/src/templates/admin/plugins.html @@ -1,56 +1,7 @@ Plugin manager - +