beeebfa964bffae1b952595e4b9dc2223e159352
[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 _0x270b=['delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','path','exec','bluebird','sendStatus','status','json','stack','name','npm\x20install','info','error','index','list','then','reject','express','motion2','length','show','params','catch','create','body','script','join','cwd','chdir','dirname','start','dump','send','Missing\x20name\x20and/or\x20path','update','restart','stop','destroy'];(function(_0x4f698e,_0x17fcac){var _0x107668=function(_0x2d0e56){while(--_0x2d0e56){_0x4f698e['push'](_0x4f698e['shift']());}};_0x107668(++_0x17fcac);}(_0x270b,0x173));var _0xb270=function(_0x3090b9,_0x44b3e7){_0x3090b9=_0x3090b9-0x0;var _0x5ab367=_0x270b[_0x3090b9];return _0x5ab367;};'use strict';var _=require(_0xb270('0x0'));var pm2=require(_0xb270('0x1'));var logger=require(_0xb270('0x2'))('api');var path=require(_0xb270('0x3'));var exec=require('child_process')[_0xb270('0x4')];var BPromise=require(_0xb270('0x5'));function handleEntityNotFound(_0x4db732,_0x787652){return function(_0x44fbcd){if(!_0x44fbcd){_0x4db732[_0xb270('0x6')](0x194);;}return _0x44fbcd;};}function respondWithResult(_0x22be85,_0xcf3c55){_0xcf3c55=_0xcf3c55||0xc8;return function(_0x49d31c){if(_0x49d31c){return _0x22be85[_0xb270('0x7')](_0xcf3c55)[_0xb270('0x8')](_0x49d31c);}return null;};}function handleError(_0x14f362,_0x3d3723){_0x3d3723=_0x3d3723||0x1f4;return function(_0x2b94f1){logger['error'](_0x2b94f1[_0xb270('0x9')]);if(_0x2b94f1[_0xb270('0xa')]){delete _0x2b94f1['name'];}_0x14f362[_0xb270('0x7')](_0x3d3723)['send'](_0x2b94f1);};}function execChildProcess(){return new BPromise(function(_0x6a3b4b,_0x410fc0){exec(_0xb270('0xb'),function(_0x403e65,_0x4fbb9d,_0x2ecf20){logger[_0xb270('0xc')](_0x4fbb9d);logger[_0xb270('0xc')](_0x2ecf20);if(_0x403e65){logger[_0xb270('0xd')](_0x403e65);return _0x410fc0(_0x403e65);}return _0x6a3b4b(_0x4fbb9d);});});}exports[_0xb270('0xe')]=function(_0x5656d4,_0x4da5eb){return pm2[_0xb270('0xf')]()[_0xb270('0x10')](function(_0xe7eb22){if(_0xe7eb22){var _0x4c3dd1=_[_0xb270('0x11')](_0xe7eb22,function(_0x35f8d3){return _0x35f8d3[_0xb270('0xa')]===_0xb270('0x12')||_0x35f8d3['name']===_0xb270('0x13');});return{'rows':_0x4c3dd1,'count':_0x4c3dd1[_0xb270('0x14')]};}return null;})[_0xb270('0x10')](respondWithResult(_0x4da5eb,null))['catch'](handleError(_0x4da5eb,null));};exports[_0xb270('0x15')]=function(_0x1b1734,_0x15bde6){return pm2['describe'](_0x1b1734[_0xb270('0x16')]['id'])[_0xb270('0x10')](respondWithResult(_0x15bde6,null))['then'](handleEntityNotFound(_0x15bde6,null))[_0xb270('0x17')](handleError(_0x15bde6,null));};exports[_0xb270('0x18')]=function(_0x59bb0b,_0x4736ef){if(_0x59bb0b[_0xb270('0x19')][_0xb270('0xa')]&&_0x59bb0b['body'][_0xb270('0x1a')]){var _0x1da86b=path[_0xb270('0x1b')](__dirname,'../../files/plugins',_0x59bb0b[_0xb270('0x19')][_0xb270('0x1a')]);var _0x36384f=process[_0xb270('0x1c')]();process[_0xb270('0x1d')](path[_0xb270('0x1e')](_0x1da86b));return execChildProcess()[_0xb270('0x10')](function(_0x533a87){process[_0xb270('0x1d')](_0x36384f);return pm2[_0xb270('0x1f')]({'name':_0x59bb0b[_0xb270('0x19')][_0xb270('0xa')],'script':_0x1da86b});})['then'](function(_0x3eba40){pm2[_0xb270('0x20')]();return _0x3eba40[0x0];})[_0xb270('0x10')](respondWithResult(_0x4736ef,0xc9))[_0xb270('0x17')](handleError(_0x4736ef,null));}else{return _0x4736ef[_0xb270('0x7')](0x1f4)[_0xb270('0x21')]({'message':_0xb270('0x22')});}};exports[_0xb270('0x23')]=function(_0xa326eb,_0x33b07e){if(_0xa326eb[_0xb270('0x19')]['id']){delete _0xa326eb[_0xb270('0x19')]['id'];}var _0x1bbcb8={'online':_0xb270('0x24'),'stopped':_0xb270('0x25')};if(_0x1bbcb8['hasOwnProperty'](_0xa326eb[_0xb270('0x19')][_0xb270('0x7')])){return pm2[_0x1bbcb8[_0xa326eb[_0xb270('0x19')][_0xb270('0x7')]]](_0xa326eb[_0xb270('0x16')]['id'])['then'](respondWithResult(_0x33b07e,0xc8))[_0xb270('0x17')](handleError(_0x33b07e,null));}else{return _0x33b07e[_0xb270('0x7')](0x1f4)[_0xb270('0x21')]({'message':'Unknown\x20status'});}};exports[_0xb270('0x26')]=function(_0x51630d,_0x535470){if(_0x51630d['body']['id']){delete _0x51630d[_0xb270('0x19')]['id'];}if(_0x51630d[_0xb270('0x16')]['id']){return pm2[_0xb270('0x27')](_0x51630d[_0xb270('0x16')]['id'])[_0xb270('0x10')](function(_0x38949a){pm2[_0xb270('0x20')]();return _0x38949a[0x0];})[_0xb270('0x10')](respondWithResult(_0x535470,null))[_0xb270('0x17')](handleError(_0x535470,null));}else{return _0x535470[_0xb270('0x7')](0x1f4)[_0xb270('0x21')]({'message':_0xb270('0x28')});}};