diff --git a/cloudcmd.js b/cloudcmd.js
index 722ba0b8..3ca5b066 100644
--- a/cloudcmd.js
+++ b/cloudcmd.js
@@ -23,8 +23,14 @@
INDEX = HTMLDIR + 'index.html',
CONFIG_PATH = JSONDIR + 'config.json',
- FS = CloudFunc.FS;
+ CA = DIR + 'ssl/sub.class1.server.ca.pem',
+ KEY = DIR + 'ssl/ssl.key',
+ CERT = DIR + 'ssl/ssl.crt',
+ TEMPLATEPATH= HTMLDIR + 'file.html',
+ Template,
+
+ FS = CloudFunc.FS;
/* reinit main dir os if we on
* Win32 should be backslashes */
DIR = main.DIR;
@@ -181,27 +187,26 @@
route : route
};
- if(Config.ssl){
- var CA = DIR + 'ssl/sub.class1.server.ca.pem',
- KEY = DIR + 'ssl/ssl.key',
- CERT = DIR + 'ssl/ssl.crt';
-
- readFiles([ CA, KEY, CERT ], function(pErrors, pFiles){
- if(pErrors)
- Util.log(pErrors);
- else{
+ var lFiles = [TEMPLATEPATH];
+
+ if(Config.ssl)
+ lFiles.push(CA, KEY, CERT);
+
+ main.readFiles(lFiles, function(pErrors, pFiles){
+ if(pErrors)
+ Util.log(pErrors);
+ else{
+ Template = pFiles[TEMPLATEPATH].toString();
+ if(Config.ssl)
lParams.ssl = {
ca : pFiles[CA],
key : pFiles[KEY],
cert : pFiles[CERT]
};
-
- server.start(lParams);
- }
- });
- }
- else
- server.start(lParams);
+
+ server.start(lParams);
+ }
+ });
}
else
Util.log('read error: config.json');
@@ -301,7 +306,7 @@
p.name = Minify.allowed.html ? Minify.getName(INDEX) : INDEX;
fs.readFile(p.name, function(pError, pData){
if(!pError){
- var lPanel = CloudFunc.buildFromJSON(pJSON),
+ var lPanel = CloudFunc.buildFromJSON(pJSON, Template),
lList = '
' +
'';
@@ -321,46 +326,6 @@
}
}
- function readFiles(pFiles, pCallBack){
- var lDone = [],
- lFiles,
- lErrors,
- lReadedFiles = {},
- lDoneFunc = function (pParams){
- var lRet = Util.checkObj(pParams, ['error', 'data', 'params']);
-
- if(lRet){
- lDone.pop();
- var p = pParams,
- lName = p.params;
-
- if(p.error){
- if(!lErrors) lErrors = {};
-
- lErrors[lName] = p.error;
- }
- else
- lReadedFiles[lName] = p.data;
-
- if( !lDone.length )
- Util.exec(pCallBack, lErrors, lReadedFiles);
- }
- };
-
- if( Util.isArray(pFiles) )
- lFiles = pFiles;
- else
- lFiles = [pFiles];
-
- for(var i = 0, n = lFiles.length; i < n; i++){
- var lName = lFiles.pop();
- lDone.push(lName);
-
- fs.readFile(lName, Util.call( lDoneFunc, lName ));
- }
-
- }
-
/* function sets stdout to file log.txt */
function writeLogsToFile(){
diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js
index 2b3d786d..6f9a4e78 100644
--- a/lib/cloudfunc.js
+++ b/lib/cloudfunc.js
@@ -348,27 +348,14 @@ var CloudFunc, exports, Util;
lLink = FS + lDotDot;
/* Сохраняем путь к каталогу верхнего уровня*/
-
- if(pTemplate)
- lFileTable += Util.render(pTemplate,{
- type : 'directory',
- link : lLink,
- name : '..',
- size : '<dir>',
- owner : '.',
- mode : ''
- });
- else
- lFileTable += '' +
- '' +
- '' +
- '' + ".." +
- '' +
- '<dir>' +
- '.' +
- '' +
- '';
+ lFileTable += Util.render(pTemplate,{
+ type : 'directory',
+ link : lLink,
+ name : '..',
+ size : '<dir>',
+ owner : '.',
+ mode : ''
+ });
}
for(var i = 1, n = files.length; i < n; i++){
@@ -385,44 +372,14 @@ var CloudFunc, exports, Util;
lSize = CloudFunc.getShortSize( lFile.size );
}
- if(pTemplate)
- lFileTable += Util.render(pTemplate,{
+ lFileTable += Util.render(pTemplate,{
type : lType,
link : FS + lPath + lFile.name,
name : lFile.name,
size : '<dir>',
owner : lOwner,
mode : lMode
- });
- else
- {
- lFileTable += '';
- lFileTable += '' +
- '' +
- '' +
- '' + lFile.name +
- "" +
- '';
- /* если папка - не выводим размер */
- lFileTable += '' + lSize +
- '' +
- '' + lOwner +
- '' +
- '' + lMode +
- '';
- lFileTable += '';
- }
+ });
}
return lFileTable;
diff --git a/lib/server/main.js b/lib/server/main.js
index 3a71141e..e8077f6d 100644
--- a/lib/server/main.js
+++ b/lib/server/main.js
@@ -65,6 +65,7 @@
exports.sendResponse = sendResponse,
exports.sendError = sendError,
exports.redirect = redirect,
+ exports.readFiles = readFiles,
exports.checkParams = checkParams,
@@ -363,6 +364,47 @@
return Util.checkObj(pParams, ['error', 'data', 'params']);
}
+ function readFiles(pFiles, pCallBack){
+ var lDone = [],
+ lFiles,
+ lErrors,
+ lReadedFiles = {},
+ lDoneFunc = function (pParams){
+ var lRet = Util.checkObj(pParams, ['error', 'data', 'params']);
+
+ if(lRet){
+ lDone.pop();
+ var p = pParams,
+ lName = p.params;
+
+ if(p.error){
+ if(!lErrors) lErrors = {};
+
+ lErrors[lName] = p.error;
+ }
+ else{
+ Util.log(lName + ' readed');
+ lReadedFiles[lName] = p.data;
+ }
+
+ if( !lDone.length )
+ Util.exec(pCallBack, lErrors, lReadedFiles);
+ }
+ };
+
+ if( Util.isArray(pFiles) )
+ lFiles = pFiles;
+ else
+ lFiles = [pFiles];
+
+ for(var i = 0, n = lFiles.length; i < n; i++){
+ var lName = lFiles.pop();
+ lDone.push(lName);
+
+ fs.readFile(lName, Util.call( lDoneFunc, lName ));
+ }
+ }
+
function checkParams(pParams, pAdditional){
var lRet = Util.checkObjTrue( pParams, ['name', REQUEST, RESPONSE] );