5a0a826b776502e585f304abdfcb77187c538112
[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 _0x9b7f=['script','join','../../files/plugins','cwd','chdir','dirname','send','update','restart','stop','Unknown\x20status','dump','Unknown\x20id','lodash','../../config/pm2','../../config/logger','api','child_process','exec','bluebird','sendStatus','status','json','error','name','npm\x20install','info','index','list','then','reject','motion2','length','catch','show','describe','params','create','body'];(function(_0x474e53,_0xb1f451){var _0x452274=function(_0x47f167){while(--_0x47f167){_0x474e53['push'](_0x474e53['shift']());}};_0x452274(++_0xb1f451);}(_0x9b7f,0x11e));var _0xf9b7=function(_0x39713f,_0x3991c7){_0x39713f=_0x39713f-0x0;var _0x137d42=_0x9b7f[_0x39713f];return _0x137d42;};'use strict';var _=require(_0xf9b7('0x0'));var pm2=require(_0xf9b7('0x1'));var logger=require(_0xf9b7('0x2'))(_0xf9b7('0x3'));var path=require('path');var exec=require(_0xf9b7('0x4'))[_0xf9b7('0x5')];var BPromise=require(_0xf9b7('0x6'));function handleEntityNotFound(_0x11fb8d,_0x1feb7b){return function(_0xe04988){if(!_0xe04988){_0x11fb8d[_0xf9b7('0x7')](0x194);;}return _0xe04988;};}function respondWithResult(_0x189650,_0x5ff20b){_0x5ff20b=_0x5ff20b||0xc8;return function(_0x3fdfff){if(_0x3fdfff){return _0x189650[_0xf9b7('0x8')](_0x5ff20b)[_0xf9b7('0x9')](_0x3fdfff);}return null;};}function handleError(_0x392a93,_0x42c6c1){_0x42c6c1=_0x42c6c1||0x1f4;return function(_0x3eebb3){logger[_0xf9b7('0xa')](_0x3eebb3['stack']);if(_0x3eebb3[_0xf9b7('0xb')]){delete _0x3eebb3[_0xf9b7('0xb')];}_0x392a93[_0xf9b7('0x8')](_0x42c6c1)['send'](_0x3eebb3);};}function execChildProcess(){return new BPromise(function(_0x4cd66f,_0x7ff093){exec(_0xf9b7('0xc'),function(_0x486bdd,_0x47ac2e,_0x1b6625){logger[_0xf9b7('0xd')](_0x47ac2e);logger[_0xf9b7('0xd')](_0x1b6625);if(_0x486bdd){logger[_0xf9b7('0xa')](_0x486bdd);return _0x7ff093(_0x486bdd);}return _0x4cd66f(_0x47ac2e);});});}exports[_0xf9b7('0xe')]=function(_0x3b2732,_0x541ef8){return pm2[_0xf9b7('0xf')]()[_0xf9b7('0x10')](function(_0x35f576){if(_0x35f576){var _0x2816b2=_[_0xf9b7('0x11')](_0x35f576,function(_0x59604f){return _0x59604f[_0xf9b7('0xb')]==='express'||_0x59604f[_0xf9b7('0xb')]===_0xf9b7('0x12');});return{'rows':_0x2816b2,'count':_0x2816b2[_0xf9b7('0x13')]};}return null;})[_0xf9b7('0x10')](respondWithResult(_0x541ef8,null))[_0xf9b7('0x14')](handleError(_0x541ef8,null));};exports[_0xf9b7('0x15')]=function(_0x23c721,_0x57c92c){return pm2[_0xf9b7('0x16')](_0x23c721[_0xf9b7('0x17')]['id'])[_0xf9b7('0x10')](respondWithResult(_0x57c92c,null))['then'](handleEntityNotFound(_0x57c92c,null))['catch'](handleError(_0x57c92c,null));};exports[_0xf9b7('0x18')]=function(_0x59fbe7,_0x5ab61c){if(_0x59fbe7[_0xf9b7('0x19')][_0xf9b7('0xb')]&&_0x59fbe7[_0xf9b7('0x19')][_0xf9b7('0x1a')]){var _0x11b062=path[_0xf9b7('0x1b')](__dirname,_0xf9b7('0x1c'),_0x59fbe7[_0xf9b7('0x19')][_0xf9b7('0x1a')]);var _0xa9c0d8=process[_0xf9b7('0x1d')]();process[_0xf9b7('0x1e')](path[_0xf9b7('0x1f')](_0x11b062));return execChildProcess()[_0xf9b7('0x10')](function(_0x42c26f){process[_0xf9b7('0x1e')](_0xa9c0d8);return pm2['start']({'name':_0x59fbe7[_0xf9b7('0x19')][_0xf9b7('0xb')],'script':_0x11b062});})[_0xf9b7('0x10')](function(_0x215c12){pm2['dump']();return _0x215c12[0x0];})[_0xf9b7('0x10')](respondWithResult(_0x5ab61c,0xc9))[_0xf9b7('0x14')](handleError(_0x5ab61c,null));}else{return _0x5ab61c['status'](0x1f4)[_0xf9b7('0x20')]({'message':'Missing\x20name\x20and/or\x20path'});}};exports[_0xf9b7('0x21')]=function(_0x187061,_0x2f3959){if(_0x187061[_0xf9b7('0x19')]['id']){delete _0x187061['body']['id'];}var _0x21c771={'online':_0xf9b7('0x22'),'stopped':_0xf9b7('0x23')};if(_0x21c771['hasOwnProperty'](_0x187061[_0xf9b7('0x19')][_0xf9b7('0x8')])){return pm2[_0x21c771[_0x187061[_0xf9b7('0x19')][_0xf9b7('0x8')]]](_0x187061[_0xf9b7('0x17')]['id'])[_0xf9b7('0x10')](respondWithResult(_0x2f3959,0xc8))[_0xf9b7('0x14')](handleError(_0x2f3959,null));}else{return _0x2f3959[_0xf9b7('0x8')](0x1f4)[_0xf9b7('0x20')]({'message':_0xf9b7('0x24')});}};exports['destroy']=function(_0x48b155,_0x52348c){if(_0x48b155['body']['id']){delete _0x48b155[_0xf9b7('0x19')]['id'];}if(_0x48b155['params']['id']){return pm2['delete'](_0x48b155[_0xf9b7('0x17')]['id'])['then'](function(_0x355659){pm2[_0xf9b7('0x25')]();return _0x355659[0x0];})[_0xf9b7('0x10')](respondWithResult(_0x52348c,null))[_0xf9b7('0x14')](handleError(_0x52348c,null));}else{return _0x52348c[_0xf9b7('0x8')](0x1f4)[_0xf9b7('0x20')]({'message':_0xf9b7('0x26')});}};