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/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..8ae10076 --- /dev/null +++ b/lib/server/root.js @@ -0,0 +1,17 @@ +(function() { + 'use strict'; + + var DIR = './', + path = require('path'), + config = require(DIR + 'config'), + mellow = require('mellow'); + + module.exports = function(dir) { + var root = config('root') || '/'; + + if (root === '/') + dir = mellow.pathToWin(dir); + + return path.join(root + 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);