Built motion from commit b0a9a629.|2.6.33
[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 _0x222f=['dump','send','Missing\x20name\x20and/or\x20path','update','restart','stop','hasOwnProperty','destroy','delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','api','exec','bluebird','sendStatus','json','error','stack','name','status','npm\x20install','info','index','list','reject','express','motion2','length','then','catch','describe','params','body','join','../../files/plugins','script','chdir','dirname','start'];(function(_0xbca1b1,_0x33f0ce){var _0x4e1686=function(_0x58a80c){while(--_0x58a80c){_0xbca1b1['push'](_0xbca1b1['shift']());}};_0x4e1686(++_0x33f0ce);}(_0x222f,0x1a4));var _0xf222=function(_0x180c9b,_0x13d173){_0x180c9b=_0x180c9b-0x0;var _0x3ff116=_0x222f[_0x180c9b];return _0x3ff116;};'use strict';var _=require(_0xf222('0x0'));var pm2=require(_0xf222('0x1'));var logger=require(_0xf222('0x2'))(_0xf222('0x3'));var path=require('path');var exec=require('child_process')[_0xf222('0x4')];var BPromise=require(_0xf222('0x5'));function handleEntityNotFound(_0x307791,_0x7b187d){return function(_0x59a619){if(!_0x59a619){_0x307791[_0xf222('0x6')](0x194);;}return _0x59a619;};}function respondWithResult(_0x54a758,_0x112e6d){_0x112e6d=_0x112e6d||0xc8;return function(_0x26f129){if(_0x26f129){return _0x54a758['status'](_0x112e6d)[_0xf222('0x7')](_0x26f129);}return null;};}function handleError(_0x302d7a,_0x4aceb4){_0x4aceb4=_0x4aceb4||0x1f4;return function(_0x31c027){logger[_0xf222('0x8')](_0x31c027[_0xf222('0x9')]);if(_0x31c027[_0xf222('0xa')]){delete _0x31c027[_0xf222('0xa')];}_0x302d7a[_0xf222('0xb')](_0x4aceb4)['send'](_0x31c027);};}function execChildProcess(){return new BPromise(function(_0x2e29ad,_0x405080){exec(_0xf222('0xc'),function(_0x182bc3,_0x48f740,_0x3c9b96){logger[_0xf222('0xd')](_0x48f740);logger[_0xf222('0xd')](_0x3c9b96);if(_0x182bc3){logger[_0xf222('0x8')](_0x182bc3);return _0x405080(_0x182bc3);}return _0x2e29ad(_0x48f740);});});}exports[_0xf222('0xe')]=function(_0x334017,_0x11fca0){return pm2[_0xf222('0xf')]()['then'](function(_0x5b8f97){if(_0x5b8f97){var _0x1feb86=_[_0xf222('0x10')](_0x5b8f97,function(_0x4c2314){return _0x4c2314[_0xf222('0xa')]===_0xf222('0x11')||_0x4c2314[_0xf222('0xa')]===_0xf222('0x12');});return{'rows':_0x1feb86,'count':_0x1feb86[_0xf222('0x13')]};}return null;})[_0xf222('0x14')](respondWithResult(_0x11fca0,null))[_0xf222('0x15')](handleError(_0x11fca0,null));};exports['show']=function(_0x1efa9f,_0x823314){return pm2[_0xf222('0x16')](_0x1efa9f[_0xf222('0x17')]['id'])[_0xf222('0x14')](respondWithResult(_0x823314,null))[_0xf222('0x14')](handleEntityNotFound(_0x823314,null))[_0xf222('0x15')](handleError(_0x823314,null));};exports['create']=function(_0xf26a16,_0x1bdd0a){if(_0xf26a16[_0xf222('0x18')][_0xf222('0xa')]&&_0xf26a16['body']['script']){var _0x398ff4=path[_0xf222('0x19')](__dirname,_0xf222('0x1a'),_0xf26a16[_0xf222('0x18')][_0xf222('0x1b')]);var _0x151a89=process['cwd']();process[_0xf222('0x1c')](path[_0xf222('0x1d')](_0x398ff4));return execChildProcess()[_0xf222('0x14')](function(_0x12d443){process[_0xf222('0x1c')](_0x151a89);return pm2[_0xf222('0x1e')]({'name':_0xf26a16[_0xf222('0x18')][_0xf222('0xa')],'script':_0x398ff4});})['then'](function(_0x145e2e){pm2[_0xf222('0x1f')]();return _0x145e2e[0x0];})[_0xf222('0x14')](respondWithResult(_0x1bdd0a,0xc9))[_0xf222('0x15')](handleError(_0x1bdd0a,null));}else{return _0x1bdd0a[_0xf222('0xb')](0x1f4)[_0xf222('0x20')]({'message':_0xf222('0x21')});}};exports[_0xf222('0x22')]=function(_0x15bf4e,_0x2ec2e9){if(_0x15bf4e[_0xf222('0x18')]['id']){delete _0x15bf4e['body']['id'];}var _0x14b2b1={'online':_0xf222('0x23'),'stopped':_0xf222('0x24')};if(_0x14b2b1[_0xf222('0x25')](_0x15bf4e[_0xf222('0x18')][_0xf222('0xb')])){return pm2[_0x14b2b1[_0x15bf4e[_0xf222('0x18')][_0xf222('0xb')]]](_0x15bf4e[_0xf222('0x17')]['id'])['then'](respondWithResult(_0x2ec2e9,0xc8))[_0xf222('0x15')](handleError(_0x2ec2e9,null));}else{return _0x2ec2e9[_0xf222('0xb')](0x1f4)[_0xf222('0x20')]({'message':'Unknown\x20status'});}};exports[_0xf222('0x26')]=function(_0x5d5963,_0x40c7e7){if(_0x5d5963[_0xf222('0x18')]['id']){delete _0x5d5963[_0xf222('0x18')]['id'];}if(_0x5d5963[_0xf222('0x17')]['id']){return pm2[_0xf222('0x27')](_0x5d5963[_0xf222('0x17')]['id'])[_0xf222('0x14')](function(_0x5075ad){pm2['dump']();return _0x5075ad[0x0];})[_0xf222('0x14')](respondWithResult(_0x40c7e7,null))[_0xf222('0x15')](handleError(_0x40c7e7,null));}else{return _0x40c7e7[_0xf222('0xb')](0x1f4)[_0xf222('0x20')]({'message':_0xf222('0x28')});}};