Built motion from commit (unavailable).|2.6.0
[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 _0x72b8=['../../config/pm2','api','path','child_process','exec','status','json','error','stack','name','send','npm\x20install','info','index','list','reject','express','motion2','then','show','describe','body','../../files/plugins','cwd','chdir','dirname','dump','catch','Missing\x20name\x20and/or\x20path','update','stop','destroy','params','Unknown\x20id','lodash'];(function(_0x9fd887,_0x47f76c){var _0x1a54ab=function(_0xb65c08){while(--_0xb65c08){_0x9fd887['push'](_0x9fd887['shift']());}};_0x1a54ab(++_0x47f76c);}(_0x72b8,0xae));var _0x872b=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x72b8[_0x2641f9];return _0x585741;};'use strict';var _=require(_0x872b('0x0'));var pm2=require(_0x872b('0x1'));var logger=require('../../config/logger')(_0x872b('0x2'));var path=require(_0x872b('0x3'));var exec=require(_0x872b('0x4'))[_0x872b('0x5')];var BPromise=require('bluebird');function handleEntityNotFound(_0x2a8cdf,_0x329bdd){return function(_0x516e7e){if(!_0x516e7e){_0x2a8cdf['sendStatus'](0x194);;}return _0x516e7e;};}function respondWithResult(_0x157efe,_0x1c4414){_0x1c4414=_0x1c4414||0xc8;return function(_0x37b298){if(_0x37b298){return _0x157efe[_0x872b('0x6')](_0x1c4414)[_0x872b('0x7')](_0x37b298);}return null;};}function handleError(_0x14b1d2,_0x139113){_0x139113=_0x139113||0x1f4;return function(_0x3d5b37){logger[_0x872b('0x8')](_0x3d5b37[_0x872b('0x9')]);if(_0x3d5b37[_0x872b('0xa')]){delete _0x3d5b37[_0x872b('0xa')];}_0x14b1d2[_0x872b('0x6')](_0x139113)[_0x872b('0xb')](_0x3d5b37);};}function execChildProcess(){return new BPromise(function(_0x2d1db8,_0x39939){exec(_0x872b('0xc'),function(_0x263477,_0x135df6,_0x1cc757){logger[_0x872b('0xd')](_0x135df6);logger[_0x872b('0xd')](_0x1cc757);if(_0x263477){logger[_0x872b('0x8')](_0x263477);return _0x39939(_0x263477);}return _0x2d1db8(_0x135df6);});});}exports[_0x872b('0xe')]=function(_0x1a6393,_0x2d8ef9){return pm2[_0x872b('0xf')]()['then'](function(_0x2300ab){if(_0x2300ab){var _0x55743b=_[_0x872b('0x10')](_0x2300ab,function(_0x55ad77){return _0x55ad77[_0x872b('0xa')]===_0x872b('0x11')||_0x55ad77['name']===_0x872b('0x12');});return{'rows':_0x55743b,'count':_0x55743b['length']};}return null;})[_0x872b('0x13')](respondWithResult(_0x2d8ef9,null))['catch'](handleError(_0x2d8ef9,null));};exports[_0x872b('0x14')]=function(_0xee131c,_0x5c5e7f){return pm2[_0x872b('0x15')](_0xee131c['params']['id'])[_0x872b('0x13')](respondWithResult(_0x5c5e7f,null))[_0x872b('0x13')](handleEntityNotFound(_0x5c5e7f,null))['catch'](handleError(_0x5c5e7f,null));};exports['create']=function(_0x529a70,_0x484af){if(_0x529a70[_0x872b('0x16')]['name']&&_0x529a70['body']['script']){var _0x582703=path['join'](__dirname,_0x872b('0x17'),_0x529a70[_0x872b('0x16')]['script']);var _0xfec58b=process[_0x872b('0x18')]();process[_0x872b('0x19')](path[_0x872b('0x1a')](_0x582703));return execChildProcess()[_0x872b('0x13')](function(_0x4134a6){process[_0x872b('0x19')](_0xfec58b);return pm2['start']({'name':_0x529a70[_0x872b('0x16')]['name'],'script':_0x582703});})[_0x872b('0x13')](function(_0xed0bee){pm2[_0x872b('0x1b')]();return _0xed0bee[0x0];})[_0x872b('0x13')](respondWithResult(_0x484af,0xc9))[_0x872b('0x1c')](handleError(_0x484af,null));}else{return _0x484af['status'](0x1f4)[_0x872b('0xb')]({'message':_0x872b('0x1d')});}};exports[_0x872b('0x1e')]=function(_0x4d81ed,_0x814eaa){if(_0x4d81ed[_0x872b('0x16')]['id']){delete _0x4d81ed[_0x872b('0x16')]['id'];}var _0x2fd952={'online':'restart','stopped':_0x872b('0x1f')};if(_0x2fd952['hasOwnProperty'](_0x4d81ed['body'][_0x872b('0x6')])){return pm2[_0x2fd952[_0x4d81ed[_0x872b('0x16')][_0x872b('0x6')]]](_0x4d81ed['params']['id'])['then'](respondWithResult(_0x814eaa,0xc8))['catch'](handleError(_0x814eaa,null));}else{return _0x814eaa[_0x872b('0x6')](0x1f4)[_0x872b('0xb')]({'message':'Unknown\x20status'});}};exports[_0x872b('0x20')]=function(_0x8c9607,_0xe24d3d){if(_0x8c9607[_0x872b('0x16')]['id']){delete _0x8c9607[_0x872b('0x16')]['id'];}if(_0x8c9607[_0x872b('0x21')]['id']){return pm2['delete'](_0x8c9607[_0x872b('0x21')]['id'])[_0x872b('0x13')](function(_0x2b599f){pm2[_0x872b('0x1b')]();return _0x2b599f[0x0];})[_0x872b('0x13')](respondWithResult(_0xe24d3d,null))[_0x872b('0x1c')](handleError(_0xe24d3d,null));}else{return _0xe24d3d[_0x872b('0x6')](0x1f4)['send']({'message':_0x872b('0x22')});}};