1f4610921a4158e0b1a8ba626320495827ca5009
[motion2.git] / server / api / pm2 / pm2.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x153f=['Unknown\x20status','destroy','Unknown\x20id','lodash','../../config/pm2','../../config/logger','api','path','child_process','exec','sendStatus','json','error','stack','name','status','send','npm\x20install','info','index','list','then','reject','express','motion2','length','catch','describe','params','create','body','script','join','../../files/plugins','cwd','chdir','dirname','start','dump','Missing\x20name\x20and/or\x20path','update','restart','hasOwnProperty'];(function(_0x571601,_0x984923){var _0x1894e0=function(_0x1a31dc){while(--_0x1a31dc){_0x571601['push'](_0x571601['shift']());}};_0x1894e0(++_0x984923);}(_0x153f,0x15b));var _0xf153=function(_0x5d32a5,_0x5aa329){_0x5d32a5=_0x5d32a5-0x0;var _0x442dc5=_0x153f[_0x5d32a5];return _0x442dc5;};'use strict';var _=require(_0xf153('0x0'));var pm2=require(_0xf153('0x1'));var logger=require(_0xf153('0x2'))(_0xf153('0x3'));var path=require(_0xf153('0x4'));var exec=require(_0xf153('0x5'))[_0xf153('0x6')];var BPromise=require('bluebird');function handleEntityNotFound(_0x364e65,_0x5c49c7){return function(_0x1f9ead){if(!_0x1f9ead){_0x364e65[_0xf153('0x7')](0x194);;}return _0x1f9ead;};}function respondWithResult(_0x342a45,_0xafd987){_0xafd987=_0xafd987||0xc8;return function(_0x21f432){if(_0x21f432){return _0x342a45['status'](_0xafd987)[_0xf153('0x8')](_0x21f432);}return null;};}function handleError(_0x143497,_0x224f88){_0x224f88=_0x224f88||0x1f4;return function(_0x5f6cb5){logger[_0xf153('0x9')](_0x5f6cb5[_0xf153('0xa')]);if(_0x5f6cb5[_0xf153('0xb')]){delete _0x5f6cb5[_0xf153('0xb')];}_0x143497[_0xf153('0xc')](_0x224f88)[_0xf153('0xd')](_0x5f6cb5);};}function execChildProcess(){return new BPromise(function(_0x5c8ae9,_0x2b76eb){exec(_0xf153('0xe'),function(_0x2bea70,_0x493324,_0x3a8838){logger[_0xf153('0xf')](_0x493324);logger[_0xf153('0xf')](_0x3a8838);if(_0x2bea70){logger[_0xf153('0x9')](_0x2bea70);return _0x2b76eb(_0x2bea70);}return _0x5c8ae9(_0x493324);});});}exports[_0xf153('0x10')]=function(_0x107d31,_0x3f915c){return pm2[_0xf153('0x11')]()[_0xf153('0x12')](function(_0x4c5283){if(_0x4c5283){var _0x18be7e=_[_0xf153('0x13')](_0x4c5283,function(_0x2b666e){return _0x2b666e[_0xf153('0xb')]===_0xf153('0x14')||_0x2b666e[_0xf153('0xb')]===_0xf153('0x15');});return{'rows':_0x18be7e,'count':_0x18be7e[_0xf153('0x16')]};}return null;})['then'](respondWithResult(_0x3f915c,null))[_0xf153('0x17')](handleError(_0x3f915c,null));};exports['show']=function(_0x37093a,_0x2c62b6){return pm2[_0xf153('0x18')](_0x37093a[_0xf153('0x19')]['id'])['then'](respondWithResult(_0x2c62b6,null))[_0xf153('0x12')](handleEntityNotFound(_0x2c62b6,null))[_0xf153('0x17')](handleError(_0x2c62b6,null));};exports[_0xf153('0x1a')]=function(_0x14b83f,_0x15230c){if(_0x14b83f[_0xf153('0x1b')][_0xf153('0xb')]&&_0x14b83f[_0xf153('0x1b')][_0xf153('0x1c')]){var _0x1dd340=path[_0xf153('0x1d')](__dirname,_0xf153('0x1e'),_0x14b83f['body'][_0xf153('0x1c')]);var _0x395f28=process[_0xf153('0x1f')]();process[_0xf153('0x20')](path[_0xf153('0x21')](_0x1dd340));return execChildProcess()[_0xf153('0x12')](function(_0x465d88){process[_0xf153('0x20')](_0x395f28);return pm2[_0xf153('0x22')]({'name':_0x14b83f[_0xf153('0x1b')][_0xf153('0xb')],'script':_0x1dd340});})[_0xf153('0x12')](function(_0x35cfe3){pm2[_0xf153('0x23')]();return _0x35cfe3[0x0];})[_0xf153('0x12')](respondWithResult(_0x15230c,0xc9))[_0xf153('0x17')](handleError(_0x15230c,null));}else{return _0x15230c[_0xf153('0xc')](0x1f4)[_0xf153('0xd')]({'message':_0xf153('0x24')});}};exports[_0xf153('0x25')]=function(_0x48ebdc,_0x6d62ef){if(_0x48ebdc[_0xf153('0x1b')]['id']){delete _0x48ebdc['body']['id'];}var _0x16cdcd={'online':_0xf153('0x26'),'stopped':'stop'};if(_0x16cdcd[_0xf153('0x27')](_0x48ebdc[_0xf153('0x1b')][_0xf153('0xc')])){return pm2[_0x16cdcd[_0x48ebdc[_0xf153('0x1b')][_0xf153('0xc')]]](_0x48ebdc[_0xf153('0x19')]['id'])[_0xf153('0x12')](respondWithResult(_0x6d62ef,0xc8))[_0xf153('0x17')](handleError(_0x6d62ef,null));}else{return _0x6d62ef[_0xf153('0xc')](0x1f4)[_0xf153('0xd')]({'message':_0xf153('0x28')});}};exports[_0xf153('0x29')]=function(_0x5b5237,_0x258fb0){if(_0x5b5237[_0xf153('0x1b')]['id']){delete _0x5b5237[_0xf153('0x1b')]['id'];}if(_0x5b5237[_0xf153('0x19')]['id']){return pm2['delete'](_0x5b5237['params']['id'])[_0xf153('0x12')](function(_0x4c6ea0){pm2['dump']();return _0x4c6ea0[0x0];})[_0xf153('0x12')](respondWithResult(_0x258fb0,null))['catch'](handleError(_0x258fb0,null));}else{return _0x258fb0[_0xf153('0xc')](0x1f4)['send']({'message':_0xf153('0x2a')});}};