mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
chore(socket) move var to top of func
This commit is contained in:
parent
0791b28e26
commit
89cf78f056
1 changed files with 42 additions and 39 deletions
|
|
@ -14,18 +14,35 @@
|
|||
ClientFuncs = [],
|
||||
OnMessageFuncs = [],
|
||||
INFO_LOG_LEVEL = 2,
|
||||
Win32_b = main.WIN32;
|
||||
WIN32 = main.WIN32,
|
||||
|
||||
/* windows commands thet require
|
||||
* unicode charset on locales
|
||||
* different then English
|
||||
*/
|
||||
Win32Commands = ['ASSOC', 'AT', 'ATTRIB', 'BREAK', 'CACLS', 'CALL',
|
||||
'CD', 'CHCP', 'CHDIR', 'CHKDSK', 'CHKNTFS', 'CLS',
|
||||
'CMD', 'COLOR', 'COMP', 'COMPACT', 'CONVERT', 'COPY',
|
||||
'DATE', 'DEL', 'DIR', 'DISKCOMP', 'DISKCOPY', 'DOSKEY',
|
||||
'ECHO', 'ENDLOCAL', 'ERASE', 'EXIT', 'FC', 'FIND',
|
||||
'FINDSTR', 'FOR', 'FORMAT', 'FTYPE', 'GOTO', 'GRAFTABL',
|
||||
'HELP', 'IF', 'LABEL', 'MD', 'MKDIR', 'MODE', 'MORE',
|
||||
'MOVE', 'PATH', 'PAUSE', 'POPD', 'PRINT', 'PROMPT',
|
||||
'PUSHD', 'RD', 'RECOVER', 'REM', 'REN', 'RENAME',
|
||||
'REPLACE', 'RMDIR', 'SET', 'SETLOCAL', 'SHIFT', 'SORT',
|
||||
'START', 'SUBST', 'TIME', 'TITLE', 'TREE', 'TYPE',
|
||||
'VER', 'VERIFY', 'VOL', 'XCOPY'];
|
||||
|
||||
/**
|
||||
* function listen on servers port
|
||||
* @pServer {Object} started server object
|
||||
*/
|
||||
exports.listen = function(pServer){
|
||||
var lRet;
|
||||
var lRet, lListen, lConnNum, lConn_func;
|
||||
|
||||
if(io){
|
||||
var lListen = io.listen(pServer),
|
||||
/* number of connections */
|
||||
lConnNum = 0;
|
||||
lListen = io.listen(pServer),
|
||||
lConnNum = 0;
|
||||
|
||||
lListen.set('log level', INFO_LOG_LEVEL);
|
||||
lRet = lListen.sockets.on('connection', function (socket){
|
||||
|
|
@ -37,7 +54,7 @@
|
|||
if(!OnMessageFuncs[lConnNum])
|
||||
OnMessageFuncs[lConnNum] = onMessage(lConnNum, socket);
|
||||
|
||||
var lConn_func = OnMessageFuncs[lConnNum];
|
||||
lConn_func = OnMessageFuncs[lConnNum];
|
||||
|
||||
socket.on('message', lConn_func);
|
||||
|
||||
|
|
@ -55,6 +72,8 @@
|
|||
*/
|
||||
function onMessage(pConnNum, pSocket){
|
||||
return function(pCommand) {
|
||||
var lMsg, lWinCommand, lExec_func;
|
||||
|
||||
Util.log(pCommand);
|
||||
|
||||
if( Util.isContainStrAtBegin(pCommand, 'cloudcmd') ){
|
||||
|
|
@ -67,15 +86,16 @@
|
|||
update.get();
|
||||
|
||||
if( Util.strCmp(pCommand, 'exit') )
|
||||
if(main.WIN32)
|
||||
if(WIN32)
|
||||
pCommand = 'taskkill -f /PID ' + process.pid;
|
||||
else
|
||||
pCommand = 'kill -9 ' + process.pid;
|
||||
}
|
||||
else {
|
||||
var lMsg = {
|
||||
stdout : 'cloudcmd exit - for shutdown cloudcmd',
|
||||
stderr : null
|
||||
lMsg = {
|
||||
stdout : 'cloudcmd exit \n' +
|
||||
'cloudcmd update \n',
|
||||
stderr : null
|
||||
};
|
||||
|
||||
lMsg = JSON.stringify(lMsg);
|
||||
|
|
@ -90,17 +110,17 @@
|
|||
* change code page to unicode becouse
|
||||
* windows use unicode on non English versions
|
||||
*/
|
||||
if(Win32_b){
|
||||
var lWinCommand = pCommand.toUpperCase();
|
||||
if(WIN32){
|
||||
lWinCommand = pCommand.toUpperCase();
|
||||
|
||||
if( Win32Commands.indexOf(lWinCommand) > 0 )
|
||||
if( Win32Commands.indexOf(lWinCommand) >= 0 )
|
||||
pCommand = 'chcp 65001 |' + pCommand;
|
||||
}
|
||||
|
||||
if(!ClientFuncs[pConnNum])
|
||||
ClientFuncs[pConnNum] = getExec(pSocket);
|
||||
|
||||
var lExec_func = ClientFuncs[pConnNum];
|
||||
lExec_func = ClientFuncs[pConnNum];
|
||||
|
||||
exec(pCommand, lExec_func);
|
||||
};
|
||||
|
|
@ -113,35 +133,18 @@
|
|||
*/
|
||||
function getExec(pSocket){
|
||||
return function(pError, pStdout, pStderr) {
|
||||
if (pError !== null) {
|
||||
var lExec = {
|
||||
stdout : pStdout,
|
||||
stderr : pStderr || pError
|
||||
},
|
||||
|
||||
lExec_str = JSON.stringify(lExec);
|
||||
|
||||
if (pError) {
|
||||
Util.log('exec error: ' + pError);
|
||||
}
|
||||
|
||||
var lExec = {
|
||||
stdout : pStdout,
|
||||
stderr : pStderr || pError
|
||||
},
|
||||
lExec_str = JSON.stringify(lExec);
|
||||
|
||||
pSocket.send(lExec_str);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* windows commands thet require
|
||||
* unicode charset on locales
|
||||
* different then English
|
||||
*/
|
||||
var Win32Commands = ['ASSOC', 'AT', 'ATTRIB', 'BREAK', 'CACLS', 'CALL',
|
||||
'CD', 'CHCP', 'CHDIR', 'CHKDSK', 'CHKNTFS', 'CLS',
|
||||
'CMD', 'COLOR', 'COMP', 'COMPACT', 'CONVERT', 'COPY',
|
||||
'DATE', 'DEL', 'DIR', 'DISKCOMP', 'DISKCOPY', 'DOSKEY',
|
||||
'ECHO', 'ENDLOCAL', 'ERASE', 'EXIT', 'FC', 'FIND',
|
||||
'FINDSTR', 'FOR', 'FORMAT', 'FTYPE', 'GOTO', 'GRAFTABL',
|
||||
'HELP', 'IF', 'LABEL', 'MD', 'MKDIR', 'MODE', 'MORE',
|
||||
'MOVE', 'PATH', 'PAUSE', 'POPD', 'PRINT', 'PROMPT',
|
||||
'PUSHD', 'RD', 'RECOVER', 'REM', 'REN', 'RENAME',
|
||||
'REPLACE', 'RMDIR', 'SET', 'SETLOCAL', 'SHIFT', 'SORT',
|
||||
'START', 'SUBST', 'TIME', 'TITLE', 'TREE', 'TYPE',
|
||||
'VER', 'VERIFY', 'VOL', 'XCOPY'];
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue