diff --git a/HELP.md b/HELP.md index 93807a4a..c501d12e 100644 --- a/HELP.md +++ b/HELP.md @@ -65,6 +65,7 @@ Cloud Commander supports command line parameters: | `-u, --username` | set username | `-p, --password` | set password | `-c, --config` | configuration file path +| `--root` | set root folder | `--port` | set port number | `--no-auth` | disable authorization | `--no-server` | do not start server diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index ed78a849..cf45114d 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -20,7 +20,8 @@ 'username', 'online', 'offline', - 'config' + 'config', + 'root' ], boolean: [ 'auth', @@ -61,6 +62,7 @@ config('auth', args.auth); config('online', args.online); config('username', args.username); + config('root', args.root); readConfig(args.config); diff --git a/json/bin.json b/json/bin.json index 62501a1a..8cfaa73b 100644 --- a/json/bin.json +++ b/json/bin.json @@ -7,6 +7,7 @@ "-u, --username " : "set username", "-p, --password " : "set password", "-c, --config " : "configuration file path", + "--root" : "set root folder", "--port " : "set port number", "--no-auth " : "disable authorization", "--no-server " : "do not start server", diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index 84cf72eb..dcfddc38 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -60,11 +60,13 @@ config.socket(socket); edward.listen(socket, { - size: size + size: size, + root: config('root') }); dword.listen(socket, { - size: size + size: size, + root: config('root') }); }; @@ -89,7 +91,8 @@ authFunc, config(), restafary({ - prefix: cloudfunc.apiURL + '/fs' + prefix : cloudfunc.apiURL + '/fs', + root : config('root') }), rest, route, diff --git a/lib/server/rest.js b/lib/server/rest.js index 845b4d8e..0679c7c1 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -14,6 +14,7 @@ DIR_JSON = DIR_LIB + '../json/', path = require('path'), + root = require(DIR + 'root'), Util = require(DIR_LIB + 'util'), CloudFunc = require(DIR_LIB + 'cloudfunc'), @@ -23,7 +24,6 @@ github = require('faust'), packer = require('jag'), - mellow = require('mellow'), flop = require('flop'), pipe = require('pipe-io'), ponse = require('ponse'), @@ -198,8 +198,8 @@ callback(error); } else { - files.from = mellow.pathToWin(files.from); - files.to = mellow.pathToWin(files.to); + files.from = root(files.from); + files.to = root(files.to); if (files.names) data = files.names.slice(); @@ -227,8 +227,8 @@ error = getWin32RootMsg('from'); callback(error); } else { - files.from = mellow.pathToWin(files.from); - files.to = mellow.pathToWin(files.to); + files.from = root(files.from); + files.to = root(files.to); msg = formatMsg('copy', files.names); @@ -242,10 +242,10 @@ if (!files.from) { callback(body); } else { - from = mellow.pathToWin(files.from); + from = root(files.from); if (files.to) - to = mellow.pathToWin(files.to); + to = root(files.to); else to = from + '.gz'; @@ -262,10 +262,10 @@ if (!files.from) { callback(body); } else { - from = mellow.pathToWin(files.from); + from = root(files.from); if (files.to) - to = mellow.pathToWin(files.to); + to = root(files.to); else to = files.from.replace(/(\.gz|\.tar\.gz)$/, ''); diff --git a/lib/server/root.js b/lib/server/root.js new file mode 100644 index 00000000..95f50d05 --- /dev/null +++ b/lib/server/root.js @@ -0,0 +1,22 @@ +(function() { + 'use strict'; + + var DIR = './', + path = require('path'), + config = require(DIR + 'config'), + mellow = require('mellow'); + + module.exports = function(dir) { + var root = config('root') || '/'; + + if (dir === '/') + dir = root; + else + if (root === '/') + dir = mellow.pathToWin(dir); + else + dir = path.join(root, dir); + + return dir; + }; +})(); diff --git a/lib/server/route.js b/lib/server/route.js index 9b025a6c..8c3183cf 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -19,6 +19,7 @@ format = require('format-io'), config = require(DIR_SERVER + 'config'), + root = require(DIR_SERVER + 'root'), CloudFunc = require(DIR_LIB + 'cloudfunc'), @@ -126,7 +127,7 @@ * routing of server queries */ function route(request, response, callback) { - var name, p, isAuth, isFS, path; + var name, p, isAuth, isFS, fullPath; if (!request) throw Error('request could not be empty!'); @@ -157,10 +158,10 @@ p.name = DIR_HTML + name + '.html'; ponse.sendFile(p); } else if (isFS) { - name = name.replace(CloudFunc.FS, '') || '/'; - path = mellow.pathToWin(name); + name = name.replace(CloudFunc.FS, '') || '/'; + fullPath = root(name); - mellow.read(path, function(error, dir) { + mellow.read(fullPath, function(error, dir) { if (dir) dir.path = format.addSlashToEnd(name); @@ -176,11 +177,11 @@ else if (error.code !== 'ENOTDIR') ponse.sendError(error, p); else - fs.realpath(path, function(error, pathReal) { + fs.realpath(fullPath, function(error, pathReal) { if (!error) p.name = pathReal; else - p.name = path; + p.name = name; p.gzip = false; ponse.sendFile(p); diff --git a/package.json b/package.json index 62c5954c..1d653880 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "checkup": "~1.0.3", "console-io": "~2.2.0", "copymitter": "~1.6.0", - "dword": "~1.3.2", - "edward": "~1.4.0", + "dword": "~1.4.0", + "edward": "~1.5.0", "execon": "~1.1.0", "express": "~4.12.0", "faust": "~1.0.0", @@ -46,14 +46,14 @@ "join-io": "~1.3.0", "jonny": "~1.0.0", "markdown-it": "~4.1.0", - "mellow": "~1.0.0", + "mellow": "~1.3.0", "minify": "~1.4.0", "minimist": "~1.1.0", "mollify": "~1.0.0", "pipe-io": "~1.1.1", "ponse": "~1.3.0", "rendy": "~1.0.2", - "restafary": "~1.1.0", + "restafary": "~1.2.0", "socket.io": "~1.3.5", "try-catch": "~1.0.0", "tryrequire": "~1.1.5"