merged upstream develop

This commit is contained in:
Wikinaut 2012-12-07 08:59:13 +01:00
commit 5bf79971b8
20 changed files with 246 additions and 196 deletions

View file

@ -25,7 +25,7 @@ var async = require("async");
var authorManager = require("./AuthorManager");
var padManager = require("./PadManager");
var sessionManager = require("./SessionManager");
var settings = require("../utils/Settings")
var settings = require("../utils/Settings");
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
/**
@ -83,7 +83,7 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
// grant access, with author of token
callback(null, statusObject);
}
})
});
//don't continue
return;
@ -133,10 +133,16 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
var now = Math.floor(new Date().getTime()/1000);
//is it for this group?
if(sessionInfo.groupID != groupID) return;
if(sessionInfo.groupID != groupID) {
callback();
return;
}
//is validUntil still ok?
if(sessionInfo.validUntil <= now) return;
if(sessionInfo.validUntil <= now){
callback();
return;
}
// There is a valid session
validSession = true;
@ -282,4 +288,4 @@ exports.checkAccess = function (padID, sessionCookie, token, password, callback)
if(ERR(err, callback)) return;
callback(null, statusObject);
});
}
};

View file

@ -28,18 +28,25 @@ var resolve = require("resolve");
exports.info = {
buf_stack: [],
block_stack: [],
blocks: {},
file_stack: [],
args: []
};
function getCurrentFile() {
return exports.info.file_stack[exports.info.file_stack.length-1];
}
function createBlockId(name) {
return getCurrentFile().path + '|' + name;
}
exports._init = function (b, recursive) {
exports.info.buf_stack.push(exports.info.buf);
exports.info.buf = b;
}
exports._exit = function (b, recursive) {
exports.info.file_stack[exports.info.file_stack.length-1].inherit.forEach(function (item) {
getCurrentFile().inherit.forEach(function (item) {
exports._require(item.name, item.args);
});
exports.info.buf = exports.info.buf_stack.pop();
@ -59,29 +66,17 @@ exports.end_capture = function () {
}
exports.begin_define_block = function (name) {
if (typeof exports.info.blocks[name] == "undefined")
exports.info.blocks[name] = {};
exports.info.block_stack.push(name);
exports.begin_capture();
}
exports.super = function () {
exports.info.buf.push('<!eejs!super!>');
}
exports.end_define_block = function () {
content = exports.end_capture();
var name = exports.info.block_stack.pop();
if (typeof exports.info.blocks[name].content == "undefined")
exports.info.blocks[name].content = content;
else if (typeof exports.info.blocks[name].content.indexOf('<!eejs!super!>'))
exports.info.blocks[name].content = exports.info.blocks[name].content.replace('<!eejs!super!>', content);
return exports.info.blocks[name].content;
return content;
}
exports.end_block = function () {
var name = exports.info.block_stack[exports.info.block_stack.length-1];
var name = exports.info.block_stack.pop();
var renderContext = exports.info.args[exports.info.args.length-1];
var args = {content: exports.end_define_block(), renderContext: renderContext};
hooks.callAll("eejsBlock_" + name, args);
@ -91,7 +86,7 @@ exports.end_block = function () {
exports.begin_block = exports.begin_define_block;
exports.inherit = function (name, args) {
exports.info.file_stack[exports.info.file_stack.length-1].inherit.push({name:name, args:args});
getCurrentFile().inherit.push({name:name, args:args});
}
exports.require = function (name, args, mod) {
@ -101,7 +96,7 @@ exports.require = function (name, args, mod) {
var paths = [];
if (exports.info.file_stack.length) {
basedir = path.dirname(exports.info.file_stack[exports.info.file_stack.length-1].path);
basedir = path.dirname(getCurrentFile().path);
}
if (mod) {
basedir = path.dirname(mod.filename);

View file

@ -4,6 +4,7 @@
/*
* 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
* 2012 Iván Eixarch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,26 +19,23 @@
* limitations under the License.
*/
var ERR = require("async-stacktrace");
var padManager = require("../db/PadManager");
var padMessageHandler = require("./PadMessageHandler");
var async = require("async");
var fs = require("fs");
var settings = require('../utils/Settings');
var formidable = require('formidable');
var os = require("os");
var ERR = require("async-stacktrace")
, padManager = require("../db/PadManager")
, padMessageHandler = require("./PadMessageHandler")
, async = require("async")
, fs = require("fs")
, path = require("path")
, settings = require('../utils/Settings')
, formidable = require('formidable')
, os = require("os")
, importHtml = require("../utils/ImportHtml");
//load abiword only if its enabled
if(settings.abiword != null)
var abiword = require("../utils/Abiword");
var tempDirectory = "/tmp/";
//tempDirectory changes if the operating system is windows
if(os.type().indexOf("Windows") > -1)
{
tempDirectory = process.env.TEMP;
}
//for node 0.6 compatibily, os.tmpDir() only works from 0.8
var tmpDirectory = process.env.TEMP || process.env.TMPDIR || process.env.TMP || '/tmp';
/**
* do a requested import
@ -45,32 +43,28 @@ if(os.type().indexOf("Windows") > -1)
exports.doImport = function(req, res, padId)
{
//pipe to a file
//convert file to text via abiword
//set text in the pad
//convert file to html via abiword
//set html in the pad
var srcFile, destFile;
var pad;
var text;
var srcFile, destFile
, pad
, text;
async.series([
//save the uploaded file to /tmp
function(callback)
{
function(callback) {
var form = new formidable.IncomingForm();
form.keepExtensions = true;
form.uploadDir = tempDirectory;
form.uploadDir = tmpDirectory;
form.parse(req, function(err, fields, files)
{
form.parse(req, function(err, fields, files) {
//the upload failed, stop at this point
if(err || files.file === undefined)
{
if(err || files.file === undefined) {
console.warn("Uploading Error: " + err.stack);
callback("uploadFailed");
}
//everything ok, continue
else
{
else {
//save the path of the uploaded file
srcFile = files.file.path;
callback();
@ -80,57 +74,48 @@ exports.doImport = function(req, res, padId)
//ensure this is a file ending we know, else we change the file ending to .txt
//this allows us to accept source code files like .c or .java
function(callback)
{
var fileEnding = (srcFile.split(".")[1] || "").toLowerCase();
var knownFileEndings = ["txt", "doc", "docx", "pdf", "odt", "html", "htm"];
//find out if this is a known file ending
var fileEndingKnown = false;
for(var i in knownFileEndings)
{
if(fileEnding == knownFileEndings[i])
{
fileEndingKnown = true;
}
}
function(callback) {
var fileEnding = path.extname(srcFile).toLowerCase()
, knownFileEndings = [".txt", ".doc", ".docx", ".pdf", ".odt", ".html", ".htm"]
, fileEndingKnown = (knownFileEndings.indexOf(fileEnding) > -1);
//if the file ending is known, continue as normal
if(fileEndingKnown)
{
if(fileEndingKnown) {
callback();
}
//we need to rename this file with a .txt ending
else
{
else {
var oldSrcFile = srcFile;
srcFile = srcFile.split(".")[0] + ".txt";
srcFile = path.join(path.dirname(srcFile),path.basename(srcFile, fileEnding)+".txt");
fs.rename(oldSrcFile, srcFile, callback);
}
},
//convert file to text
function(callback)
{
//convert file to html
function(callback) {
var randNum = Math.floor(Math.random()*0xFFFFFFFF);
destFile = tempDirectory + "eplite_import_" + randNum + ".txt";
abiword.convertFile(srcFile, destFile, "txt", function(err){
//catch convert errors
if(err){
console.warn("Converting Error:", err);
return callback("convertFailed");
} else {
callback();
}
});
destFile = path.join(tmpDirectory, "eplite_import_" + randNum + ".htm");
if (abiword) {
abiword.convertFile(srcFile, destFile, "htm", function(err) {
//catch convert errors
if(err) {
console.warn("Converting Error:", err);
return callback("convertFailed");
} else {
callback();
}
});
} else {
// if no abiword only rename
fs.rename(srcFile, destFile, callback);
}
},
//get the pad object
function(callback)
{
padManager.getPad(padId, function(err, _pad)
{
function(callback) {
padManager.getPad(padId, function(err, _pad){
if(ERR(err, callback)) return;
pad = _pad;
callback();
@ -138,52 +123,47 @@ exports.doImport = function(req, res, padId)
},
//read the text
function(callback)
{
fs.readFile(destFile, "utf8", function(err, _text)
{
function(callback) {
fs.readFile(destFile, "utf8", function(err, _text){
if(ERR(err, callback)) return;
text = _text;
//node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this
if(os.type().indexOf("Windows") > -1)
{
setTimeout(function()
{
callback();
}, 100);
}
else
{
callback();
}
if(os.type().indexOf("Windows") > -1){
setTimeout(function() {callback();}, 100);
} else {
callback();
}
});
},
//change text of the pad and broadcast the changeset
function(callback)
{
pad.setText(text);
function(callback) {
var fileEnding = path.extname(srcFile).toLowerCase();
if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
importHtml.setPadHTML(pad, text);
} else {
pad.setText(text);
}
padMessageHandler.updatePadClients(pad, callback);
},
//clean up temporary files
function(callback)
{
function(callback) {
//for node < 0.7 compatible
var fileExists = fs.exists || path.exists;
async.parallel([
function(callback)
{
fs.unlink(srcFile, callback);
function(callback){
fileExists (srcFile, function(exist) { (exist)? fs.unlink(srcFile, callback): callback(); });
},
function(callback)
{
fs.unlink(destFile, callback);
function(callback){
fileExists (destFile, function(exist) { (exist)? fs.unlink(destFile, callback): callback(); });
}
], callback);
}
], function(err)
{
], function(err) {
var status = "ok";
//check for known errors and replace the status
@ -196,6 +176,6 @@ exports.doImport = function(req, res, padId)
ERR(err);
//close the connection
res.send("<script type='text/javascript' src='/static/js/jquery.js'></script><script> if ( (!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf(\"1.8.\") == 0)) ){document.domain = document.domain;}var impexp = window.top.require('/pad_impexp').padimpexp.handleFrameCall('" + status + "');</script>", 200);
res.send("<script type='text/javascript' src='/static/js/jquery.js'></script><script> if ( (!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf(\"1.8.\") == 0)) ){document.domain = document.domain;}var impexp = window.parent.require('/pad_impexp').padimpexp.handleFrameCall('" + status + "');</script>", 200);
});
}

View file

@ -66,8 +66,6 @@ exports.restartServer = function () {
} else {
console.log( "SSL -- not enabled!" );
var http = require('http');
server = http.createServer(app);
}

View file

@ -28,12 +28,6 @@ exports.expressCreateServer = function (hook_name, args, cb) {
//handle import requests
args.app.post('/p/:pad/import', function(req, res, next) {
//if abiword is disabled, skip handling this request
if(settings.abiword == null) {
next();
return;
}
hasPadAccess(req, res, function() {
importHandler.doImport(req, res, req.params.pad);
});

View file

@ -15,8 +15,8 @@ exports.basicAuth = function (req, res, next) {
}
var authorize = function (cb) {
// Do not require auth for static paths...this could be a bit brittle
if (req.path.match(/^\/(static|javascripts|pluginfw)/)) return cb(true);
// Do not require auth for static paths and the API...this could be a bit brittle
if (req.path.match(/^\/(static|javascripts|pluginfw|api)/)) return cb(true);
if (req.path.indexOf('/admin') != 0) {
if (!settings.requireAuthentication) return cb(true);

View file

@ -1,4 +1,4 @@
var languages = require('languages')
var languages = require('languages4translatewiki')
, fs = require('fs')
, path = require('path')
, express = require('express')
@ -8,22 +8,23 @@ var localesPath = __dirname+"/../../locales";
// Serve English strings directly with /locales.ini
var localeIndex = fs.readFileSync(localesPath+'/en.ini')+'\r\n';
// add language base 'en' to availableLangs
exports.availableLangs = {en: languages.getLanguageInfo('en')}
exports.availableLangs = {'en': {'nativeName': 'English', 'direction': 'ltr'}};
fs.readdir(localesPath, function(er, files) {
files.forEach(function(locale) {
locale = locale.split('.')[0]
if(locale.toLowerCase() == 'en') return;
var ext = path.extname(locale);
locale = path.basename(locale, ext).toLowerCase();
if(locale == 'en' || ext != '.ini') return;
// build locale index
localeIndex += '['+locale+']\r\n@import url(locales/'+locale+'.ini)\r\n'
// add info language {name, nativeName, direction} to availableLangs
// add info language {nativeName, direction} to availableLangs
exports.availableLangs[locale]=languages.getLanguageInfo(locale);
})
})
exports.expressCreateServer = function(n, args) {
args.app.use('/locales', express.static(localesPath));