Built motion from commit d6d69adf.|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 _0x0565=['script','../../files/plugins','cwd','chdir','send','update','restart','stop','hasOwnProperty','params','Unknown\x20status','delete','dump','Unknown\x20id','lodash','../../config/pm2','../../config/logger','api','path','child_process','exec','bluebird','sendStatus','error','stack','name','status','npm\x20install','index','list','then','reject','express','length','catch','show','describe','body'];(function(_0x4b7895,_0x3c4f5d){var _0x264180=function(_0xe0e861){while(--_0xe0e861){_0x4b7895['push'](_0x4b7895['shift']());}};_0x264180(++_0x3c4f5d);}(_0x0565,0xf2));var _0x5056=function(_0x342700,_0x569f75){_0x342700=_0x342700-0x0;var _0x53406f=_0x0565[_0x342700];return _0x53406f;};'use strict';var _=require(_0x5056('0x0'));var pm2=require(_0x5056('0x1'));var logger=require(_0x5056('0x2'))(_0x5056('0x3'));var path=require(_0x5056('0x4'));var exec=require(_0x5056('0x5'))[_0x5056('0x6')];var BPromise=require(_0x5056('0x7'));function handleEntityNotFound(_0x3657a8,_0x2b0883){return function(_0x554040){if(!_0x554040){_0x3657a8[_0x5056('0x8')](0x194);;}return _0x554040;};}function respondWithResult(_0x105ea8,_0x1143df){_0x1143df=_0x1143df||0xc8;return function(_0x22afb7){if(_0x22afb7){return _0x105ea8['status'](_0x1143df)['json'](_0x22afb7);}return null;};}function handleError(_0x38f74,_0x223c92){_0x223c92=_0x223c92||0x1f4;return function(_0x417065){logger[_0x5056('0x9')](_0x417065[_0x5056('0xa')]);if(_0x417065[_0x5056('0xb')]){delete _0x417065[_0x5056('0xb')];}_0x38f74[_0x5056('0xc')](_0x223c92)['send'](_0x417065);};}function execChildProcess(){return new BPromise(function(_0x78f7e4,_0xf04ea3){exec(_0x5056('0xd'),function(_0x5ab4b2,_0x4c0255,_0x17f43e){logger['info'](_0x4c0255);logger['info'](_0x17f43e);if(_0x5ab4b2){logger['error'](_0x5ab4b2);return _0xf04ea3(_0x5ab4b2);}return _0x78f7e4(_0x4c0255);});});}exports[_0x5056('0xe')]=function(_0x4b183a,_0x3e523b){return pm2[_0x5056('0xf')]()[_0x5056('0x10')](function(_0x543cee){if(_0x543cee){var _0x1e8b64=_[_0x5056('0x11')](_0x543cee,function(_0x15f52d){return _0x15f52d[_0x5056('0xb')]===_0x5056('0x12')||_0x15f52d[_0x5056('0xb')]==='motion2';});return{'rows':_0x1e8b64,'count':_0x1e8b64[_0x5056('0x13')]};}return null;})['then'](respondWithResult(_0x3e523b,null))[_0x5056('0x14')](handleError(_0x3e523b,null));};exports[_0x5056('0x15')]=function(_0x1c0ee9,_0x1f2ac6){return pm2[_0x5056('0x16')](_0x1c0ee9['params']['id'])[_0x5056('0x10')](respondWithResult(_0x1f2ac6,null))[_0x5056('0x10')](handleEntityNotFound(_0x1f2ac6,null))['catch'](handleError(_0x1f2ac6,null));};exports['create']=function(_0x20776c,_0x517bf3){if(_0x20776c[_0x5056('0x17')][_0x5056('0xb')]&&_0x20776c[_0x5056('0x17')][_0x5056('0x18')]){var _0x33035c=path['join'](__dirname,_0x5056('0x19'),_0x20776c[_0x5056('0x17')]['script']);var _0x271efc=process[_0x5056('0x1a')]();process[_0x5056('0x1b')](path['dirname'](_0x33035c));return execChildProcess()[_0x5056('0x10')](function(_0x26a3c2){process['chdir'](_0x271efc);return pm2['start']({'name':_0x20776c[_0x5056('0x17')][_0x5056('0xb')],'script':_0x33035c});})[_0x5056('0x10')](function(_0x37f7b5){pm2['dump']();return _0x37f7b5[0x0];})[_0x5056('0x10')](respondWithResult(_0x517bf3,0xc9))[_0x5056('0x14')](handleError(_0x517bf3,null));}else{return _0x517bf3['status'](0x1f4)[_0x5056('0x1c')]({'message':'Missing\x20name\x20and/or\x20path'});}};exports[_0x5056('0x1d')]=function(_0x39d539,_0x1106e5){if(_0x39d539[_0x5056('0x17')]['id']){delete _0x39d539[_0x5056('0x17')]['id'];}var _0x50f2a8={'online':_0x5056('0x1e'),'stopped':_0x5056('0x1f')};if(_0x50f2a8[_0x5056('0x20')](_0x39d539[_0x5056('0x17')]['status'])){return pm2[_0x50f2a8[_0x39d539[_0x5056('0x17')]['status']]](_0x39d539[_0x5056('0x21')]['id'])['then'](respondWithResult(_0x1106e5,0xc8))['catch'](handleError(_0x1106e5,null));}else{return _0x1106e5['status'](0x1f4)[_0x5056('0x1c')]({'message':_0x5056('0x22')});}};exports['destroy']=function(_0x27f4be,_0x2c5728){if(_0x27f4be[_0x5056('0x17')]['id']){delete _0x27f4be[_0x5056('0x17')]['id'];}if(_0x27f4be[_0x5056('0x21')]['id']){return pm2[_0x5056('0x23')](_0x27f4be[_0x5056('0x21')]['id'])[_0x5056('0x10')](function(_0xd1aa24){pm2[_0x5056('0x24')]();return _0xd1aa24[0x0];})[_0x5056('0x10')](respondWithResult(_0x2c5728,null))['catch'](handleError(_0x2c5728,null));}else{return _0x2c5728['status'](0x1f4)[_0x5056('0x1c')]({'message':_0x5056('0x25')});}};