Built motion from commit (unavailable).|2.4.10
[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 _0x39ab=['name','send','npm\x20install','info','error','index','list','then','reject','catch','show','params','create','body','script','join','cwd','chdir','dirname','start','dump','Missing\x20name\x20and/or\x20path','stop','hasOwnProperty','Unknown\x20status','destroy','delete','lodash','../../config/pm2','../../config/logger','api','path','child_process','exec','sendStatus','status','stack'];(function(_0x8f55d9,_0x1b1b8d){var _0x164443=function(_0x496965){while(--_0x496965){_0x8f55d9['push'](_0x8f55d9['shift']());}};_0x164443(++_0x1b1b8d);}(_0x39ab,0x8a));var _0xb39a=function(_0x579ba2,_0x31311e){_0x579ba2=_0x579ba2-0x0;var _0x1c97cb=_0x39ab[_0x579ba2];return _0x1c97cb;};'use strict';var _=require(_0xb39a('0x0'));var pm2=require(_0xb39a('0x1'));var logger=require(_0xb39a('0x2'))(_0xb39a('0x3'));var path=require(_0xb39a('0x4'));var exec=require(_0xb39a('0x5'))[_0xb39a('0x6')];var BPromise=require('bluebird');function handleEntityNotFound(_0x140d79,_0x2258ba){return function(_0x32b9af){if(!_0x32b9af){_0x140d79[_0xb39a('0x7')](0x194);;}return _0x32b9af;};}function respondWithResult(_0x3bb748,_0x3a368d){_0x3a368d=_0x3a368d||0xc8;return function(_0x596400){if(_0x596400){return _0x3bb748[_0xb39a('0x8')](_0x3a368d)['json'](_0x596400);}return null;};}function handleError(_0x22ca1c,_0x4cc2b1){_0x4cc2b1=_0x4cc2b1||0x1f4;return function(_0x5d39cf){logger['error'](_0x5d39cf[_0xb39a('0x9')]);if(_0x5d39cf[_0xb39a('0xa')]){delete _0x5d39cf['name'];}_0x22ca1c[_0xb39a('0x8')](_0x4cc2b1)[_0xb39a('0xb')](_0x5d39cf);};}function execChildProcess(){return new BPromise(function(_0x3111dc,_0x41fc8f){exec(_0xb39a('0xc'),function(_0x29e951,_0x403b2f,_0x4d16dc){logger[_0xb39a('0xd')](_0x403b2f);logger[_0xb39a('0xd')](_0x4d16dc);if(_0x29e951){logger[_0xb39a('0xe')](_0x29e951);return _0x41fc8f(_0x29e951);}return _0x3111dc(_0x403b2f);});});}exports[_0xb39a('0xf')]=function(_0x3c9941,_0x353954){return pm2[_0xb39a('0x10')]()[_0xb39a('0x11')](function(_0x610a54){if(_0x610a54){var _0x1e5512=_[_0xb39a('0x12')](_0x610a54,function(_0x4d6fb2){return _0x4d6fb2['name']==='express'||_0x4d6fb2[_0xb39a('0xa')]==='motion2';});return{'rows':_0x1e5512,'count':_0x1e5512['length']};}return null;})['then'](respondWithResult(_0x353954,null))[_0xb39a('0x13')](handleError(_0x353954,null));};exports[_0xb39a('0x14')]=function(_0x17b0f3,_0x5c6cbf){return pm2['describe'](_0x17b0f3[_0xb39a('0x15')]['id'])['then'](respondWithResult(_0x5c6cbf,null))[_0xb39a('0x11')](handleEntityNotFound(_0x5c6cbf,null))['catch'](handleError(_0x5c6cbf,null));};exports[_0xb39a('0x16')]=function(_0x23f6b3,_0x37ebe1){if(_0x23f6b3[_0xb39a('0x17')]['name']&&_0x23f6b3['body'][_0xb39a('0x18')]){var _0x59f6f1=path[_0xb39a('0x19')](__dirname,'../../files/plugins',_0x23f6b3[_0xb39a('0x17')][_0xb39a('0x18')]);var _0x3e3b77=process[_0xb39a('0x1a')]();process[_0xb39a('0x1b')](path[_0xb39a('0x1c')](_0x59f6f1));return execChildProcess()[_0xb39a('0x11')](function(_0x12e654){process[_0xb39a('0x1b')](_0x3e3b77);return pm2[_0xb39a('0x1d')]({'name':_0x23f6b3[_0xb39a('0x17')][_0xb39a('0xa')],'script':_0x59f6f1});})['then'](function(_0xaec52a){pm2[_0xb39a('0x1e')]();return _0xaec52a[0x0];})['then'](respondWithResult(_0x37ebe1,0xc9))[_0xb39a('0x13')](handleError(_0x37ebe1,null));}else{return _0x37ebe1['status'](0x1f4)['send']({'message':_0xb39a('0x1f')});}};exports['update']=function(_0x5ea566,_0x54b95c){if(_0x5ea566[_0xb39a('0x17')]['id']){delete _0x5ea566[_0xb39a('0x17')]['id'];}var _0x1f78c5={'online':'restart','stopped':_0xb39a('0x20')};if(_0x1f78c5[_0xb39a('0x21')](_0x5ea566['body'][_0xb39a('0x8')])){return pm2[_0x1f78c5[_0x5ea566['body'][_0xb39a('0x8')]]](_0x5ea566[_0xb39a('0x15')]['id'])[_0xb39a('0x11')](respondWithResult(_0x54b95c,0xc8))[_0xb39a('0x13')](handleError(_0x54b95c,null));}else{return _0x54b95c[_0xb39a('0x8')](0x1f4)[_0xb39a('0xb')]({'message':_0xb39a('0x22')});}};exports[_0xb39a('0x23')]=function(_0x2d4144,_0x50e9d3){if(_0x2d4144[_0xb39a('0x17')]['id']){delete _0x2d4144['body']['id'];}if(_0x2d4144[_0xb39a('0x15')]['id']){return pm2[_0xb39a('0x24')](_0x2d4144[_0xb39a('0x15')]['id'])[_0xb39a('0x11')](function(_0x2ae0a4){pm2['dump']();return _0x2ae0a4[0x0];})[_0xb39a('0x11')](respondWithResult(_0x50e9d3,null))[_0xb39a('0x13')](handleError(_0x50e9d3,null));}else{return _0x50e9d3[_0xb39a('0x8')](0x1f4)[_0xb39a('0xb')]({'message':'Unknown\x20id'});}};