Built motion from commit (unavailable).|2.5.8
[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 _0x7ce6=['error','stack','name','send','npm\x20install','info','index','then','reject','express','show','params','catch','create','body','script','join','../../files/plugins','chdir','start','Missing\x20name\x20and/or\x20path','hasOwnProperty','dump','Unknown\x20id','lodash','../../config/logger','api','path','exec','bluebird','status','json'];(function(_0x2b9a68,_0x4ca98e){var _0x19bbe9=function(_0x4a8008){while(--_0x4a8008){_0x2b9a68['push'](_0x2b9a68['shift']());}};_0x19bbe9(++_0x4ca98e);}(_0x7ce6,0x158));var _0x67ce=function(_0x12be10,_0x467786){_0x12be10=_0x12be10-0x0;var _0x4ede80=_0x7ce6[_0x12be10];return _0x4ede80;};'use strict';var _=require(_0x67ce('0x0'));var pm2=require('../../config/pm2');var logger=require(_0x67ce('0x1'))(_0x67ce('0x2'));var path=require(_0x67ce('0x3'));var exec=require('child_process')[_0x67ce('0x4')];var BPromise=require(_0x67ce('0x5'));function handleEntityNotFound(_0x141568,_0x1f1e59){return function(_0xb3038a){if(!_0xb3038a){_0x141568['sendStatus'](0x194);;}return _0xb3038a;};}function respondWithResult(_0x1e476c,_0x539355){_0x539355=_0x539355||0xc8;return function(_0x3a57a1){if(_0x3a57a1){return _0x1e476c[_0x67ce('0x6')](_0x539355)[_0x67ce('0x7')](_0x3a57a1);}return null;};}function handleError(_0x27e456,_0x2128d0){_0x2128d0=_0x2128d0||0x1f4;return function(_0xbb3468){logger[_0x67ce('0x8')](_0xbb3468[_0x67ce('0x9')]);if(_0xbb3468[_0x67ce('0xa')]){delete _0xbb3468['name'];}_0x27e456[_0x67ce('0x6')](_0x2128d0)[_0x67ce('0xb')](_0xbb3468);};}function execChildProcess(){return new BPromise(function(_0x1f99e0,_0x1f6122){exec(_0x67ce('0xc'),function(_0x1b71e4,_0x5500fe,_0x2d267a){logger[_0x67ce('0xd')](_0x5500fe);logger[_0x67ce('0xd')](_0x2d267a);if(_0x1b71e4){logger[_0x67ce('0x8')](_0x1b71e4);return _0x1f6122(_0x1b71e4);}return _0x1f99e0(_0x5500fe);});});}exports[_0x67ce('0xe')]=function(_0x52deb4,_0x1967f9){return pm2['list']()[_0x67ce('0xf')](function(_0x410ed8){if(_0x410ed8){var _0x33b195=_[_0x67ce('0x10')](_0x410ed8,function(_0x3628c4){return _0x3628c4[_0x67ce('0xa')]===_0x67ce('0x11')||_0x3628c4['name']==='motion2';});return{'rows':_0x33b195,'count':_0x33b195['length']};}return null;})[_0x67ce('0xf')](respondWithResult(_0x1967f9,null))['catch'](handleError(_0x1967f9,null));};exports[_0x67ce('0x12')]=function(_0x4057d0,_0x33241b){return pm2['describe'](_0x4057d0[_0x67ce('0x13')]['id'])[_0x67ce('0xf')](respondWithResult(_0x33241b,null))[_0x67ce('0xf')](handleEntityNotFound(_0x33241b,null))[_0x67ce('0x14')](handleError(_0x33241b,null));};exports[_0x67ce('0x15')]=function(_0x566161,_0x4fb4c1){if(_0x566161[_0x67ce('0x16')]['name']&&_0x566161[_0x67ce('0x16')][_0x67ce('0x17')]){var _0x199e34=path[_0x67ce('0x18')](__dirname,_0x67ce('0x19'),_0x566161[_0x67ce('0x16')][_0x67ce('0x17')]);var _0x31d917=process['cwd']();process[_0x67ce('0x1a')](path['dirname'](_0x199e34));return execChildProcess()[_0x67ce('0xf')](function(_0xcf330e){process[_0x67ce('0x1a')](_0x31d917);return pm2[_0x67ce('0x1b')]({'name':_0x566161['body'][_0x67ce('0xa')],'script':_0x199e34});})['then'](function(_0x37ce93){pm2['dump']();return _0x37ce93[0x0];})[_0x67ce('0xf')](respondWithResult(_0x4fb4c1,0xc9))[_0x67ce('0x14')](handleError(_0x4fb4c1,null));}else{return _0x4fb4c1[_0x67ce('0x6')](0x1f4)[_0x67ce('0xb')]({'message':_0x67ce('0x1c')});}};exports['update']=function(_0x5e5d4e,_0x46bdc9){if(_0x5e5d4e[_0x67ce('0x16')]['id']){delete _0x5e5d4e[_0x67ce('0x16')]['id'];}var _0xd6fbc={'online':'restart','stopped':'stop'};if(_0xd6fbc[_0x67ce('0x1d')](_0x5e5d4e['body']['status'])){return pm2[_0xd6fbc[_0x5e5d4e[_0x67ce('0x16')][_0x67ce('0x6')]]](_0x5e5d4e[_0x67ce('0x13')]['id'])['then'](respondWithResult(_0x46bdc9,0xc8))['catch'](handleError(_0x46bdc9,null));}else{return _0x46bdc9[_0x67ce('0x6')](0x1f4)[_0x67ce('0xb')]({'message':'Unknown\x20status'});}};exports['destroy']=function(_0x46b7a5,_0x34c78d){if(_0x46b7a5[_0x67ce('0x16')]['id']){delete _0x46b7a5[_0x67ce('0x16')]['id'];}if(_0x46b7a5[_0x67ce('0x13')]['id']){return pm2['delete'](_0x46b7a5[_0x67ce('0x13')]['id'])[_0x67ce('0xf')](function(_0x33f8c2){pm2[_0x67ce('0x1e')]();return _0x33f8c2[0x0];})[_0x67ce('0xf')](respondWithResult(_0x34c78d,null))[_0x67ce('0x14')](handleError(_0x34c78d,null));}else{return _0x34c78d[_0x67ce('0x6')](0x1f4)[_0x67ce('0xb')]({'message':_0x67ce('0x1f')});}};