f357a7dd198ed1d2f20eadc0b52ee4ab24f16110
[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 _0x2830=['index','list','reject','express','then','catch','create','body','script','join','../../files/plugins','chdir','dirname','start','dump','Missing\x20name\x20and/or\x20path','update','stop','params','Unknown\x20status','delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','path','child_process','bluebird','status','error','stack','name','send','npm\x20install','info'];(function(_0x4a9fb1,_0x273043){var _0x348672=function(_0x142b69){while(--_0x142b69){_0x4a9fb1['push'](_0x4a9fb1['shift']());}};_0x348672(++_0x273043);}(_0x2830,0x10b));var _0x0283=function(_0x1bb829,_0x3e4bb7){_0x1bb829=_0x1bb829-0x0;var _0x549a73=_0x2830[_0x1bb829];return _0x549a73;};'use strict';var _=require(_0x0283('0x0'));var pm2=require(_0x0283('0x1'));var logger=require(_0x0283('0x2'))('api');var path=require(_0x0283('0x3'));var exec=require(_0x0283('0x4'))['exec'];var BPromise=require(_0x0283('0x5'));function handleEntityNotFound(_0x3d0be3,_0x1d9741){return function(_0x57bcf2){if(!_0x57bcf2){_0x3d0be3['sendStatus'](0x194);;}return _0x57bcf2;};}function respondWithResult(_0x2d5a2e,_0x4b19bd){_0x4b19bd=_0x4b19bd||0xc8;return function(_0x48967f){if(_0x48967f){return _0x2d5a2e[_0x0283('0x6')](_0x4b19bd)['json'](_0x48967f);}return null;};}function handleError(_0x561e53,_0xc05b9d){_0xc05b9d=_0xc05b9d||0x1f4;return function(_0x37f434){logger[_0x0283('0x7')](_0x37f434[_0x0283('0x8')]);if(_0x37f434[_0x0283('0x9')]){delete _0x37f434['name'];}_0x561e53['status'](_0xc05b9d)[_0x0283('0xa')](_0x37f434);};}function execChildProcess(){return new BPromise(function(_0x4d8257,_0x1b1f4e){exec(_0x0283('0xb'),function(_0x12f510,_0x3da5bf,_0x3979cd){logger['info'](_0x3da5bf);logger[_0x0283('0xc')](_0x3979cd);if(_0x12f510){logger[_0x0283('0x7')](_0x12f510);return _0x1b1f4e(_0x12f510);}return _0x4d8257(_0x3da5bf);});});}exports[_0x0283('0xd')]=function(_0x2ad803,_0x19ee6d){return pm2[_0x0283('0xe')]()['then'](function(_0x51cee5){if(_0x51cee5){var _0x2a492b=_[_0x0283('0xf')](_0x51cee5,function(_0x5e8da3){return _0x5e8da3[_0x0283('0x9')]===_0x0283('0x10')||_0x5e8da3[_0x0283('0x9')]==='motion2';});return{'rows':_0x2a492b,'count':_0x2a492b['length']};}return null;})[_0x0283('0x11')](respondWithResult(_0x19ee6d,null))[_0x0283('0x12')](handleError(_0x19ee6d,null));};exports['show']=function(_0x3388cd,_0x4f74c6){return pm2['describe'](_0x3388cd['params']['id'])['then'](respondWithResult(_0x4f74c6,null))[_0x0283('0x11')](handleEntityNotFound(_0x4f74c6,null))[_0x0283('0x12')](handleError(_0x4f74c6,null));};exports[_0x0283('0x13')]=function(_0x3376a2,_0xa1eb56){if(_0x3376a2[_0x0283('0x14')]['name']&&_0x3376a2[_0x0283('0x14')][_0x0283('0x15')]){var _0x22885d=path[_0x0283('0x16')](__dirname,_0x0283('0x17'),_0x3376a2['body'][_0x0283('0x15')]);var _0x14c3ff=process['cwd']();process[_0x0283('0x18')](path[_0x0283('0x19')](_0x22885d));return execChildProcess()[_0x0283('0x11')](function(_0xf0a2de){process[_0x0283('0x18')](_0x14c3ff);return pm2[_0x0283('0x1a')]({'name':_0x3376a2[_0x0283('0x14')][_0x0283('0x9')],'script':_0x22885d});})[_0x0283('0x11')](function(_0x14ccad){pm2[_0x0283('0x1b')]();return _0x14ccad[0x0];})[_0x0283('0x11')](respondWithResult(_0xa1eb56,0xc9))[_0x0283('0x12')](handleError(_0xa1eb56,null));}else{return _0xa1eb56['status'](0x1f4)[_0x0283('0xa')]({'message':_0x0283('0x1c')});}};exports[_0x0283('0x1d')]=function(_0x2e08d6,_0x4570a6){if(_0x2e08d6['body']['id']){delete _0x2e08d6[_0x0283('0x14')]['id'];}var _0x3b5d0e={'online':'restart','stopped':_0x0283('0x1e')};if(_0x3b5d0e['hasOwnProperty'](_0x2e08d6[_0x0283('0x14')][_0x0283('0x6')])){return pm2[_0x3b5d0e[_0x2e08d6['body'][_0x0283('0x6')]]](_0x2e08d6[_0x0283('0x1f')]['id'])[_0x0283('0x11')](respondWithResult(_0x4570a6,0xc8))[_0x0283('0x12')](handleError(_0x4570a6,null));}else{return _0x4570a6[_0x0283('0x6')](0x1f4)[_0x0283('0xa')]({'message':_0x0283('0x20')});}};exports['destroy']=function(_0x374591,_0x47bd33){if(_0x374591[_0x0283('0x14')]['id']){delete _0x374591[_0x0283('0x14')]['id'];}if(_0x374591[_0x0283('0x1f')]['id']){return pm2[_0x0283('0x21')](_0x374591['params']['id'])[_0x0283('0x11')](function(_0x540985){pm2[_0x0283('0x1b')]();return _0x540985[0x0];})[_0x0283('0x11')](respondWithResult(_0x47bd33,null))[_0x0283('0x12')](handleError(_0x47bd33,null));}else{return _0x47bd33['status'](0x1f4)[_0x0283('0xa')]({'message':_0x0283('0x22')});}};