Built motion from commit e6806ed6.|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 _0xbf6e=['start','dump','Missing\x20name\x20and/or\x20path','restart','stop','hasOwnProperty','Unknown\x20status','delete','Unknown\x20id','../../config/logger','api','path','child_process','exec','bluebird','sendStatus','status','json','error','name','send','npm\x20install','info','index','list','then','motion2','length','catch','show','describe','params','create','body','script','join','../../files/plugins','cwd','chdir','dirname'];(function(_0x7c864,_0x73bfa8){var _0x246623=function(_0x1d1371){while(--_0x1d1371){_0x7c864['push'](_0x7c864['shift']());}};_0x246623(++_0x73bfa8);}(_0xbf6e,0x149));var _0xebf6=function(_0x5c187a,_0x2a00d4){_0x5c187a=_0x5c187a-0x0;var _0x168a2a=_0xbf6e[_0x5c187a];return _0x168a2a;};'use strict';var _=require('lodash');var pm2=require('../../config/pm2');var logger=require(_0xebf6('0x0'))(_0xebf6('0x1'));var path=require(_0xebf6('0x2'));var exec=require(_0xebf6('0x3'))[_0xebf6('0x4')];var BPromise=require(_0xebf6('0x5'));function handleEntityNotFound(_0x5c2323,_0x49de28){return function(_0x2b0c61){if(!_0x2b0c61){_0x5c2323[_0xebf6('0x6')](0x194);;}return _0x2b0c61;};}function respondWithResult(_0x3b2bb6,_0x1e15cf){_0x1e15cf=_0x1e15cf||0xc8;return function(_0x143344){if(_0x143344){return _0x3b2bb6[_0xebf6('0x7')](_0x1e15cf)[_0xebf6('0x8')](_0x143344);}return null;};}function handleError(_0x548e9e,_0x1d8035){_0x1d8035=_0x1d8035||0x1f4;return function(_0x40b28a){logger[_0xebf6('0x9')](_0x40b28a['stack']);if(_0x40b28a[_0xebf6('0xa')]){delete _0x40b28a[_0xebf6('0xa')];}_0x548e9e['status'](_0x1d8035)[_0xebf6('0xb')](_0x40b28a);};}function execChildProcess(){return new BPromise(function(_0x231d6b,_0x474dbe){exec(_0xebf6('0xc'),function(_0x1bd481,_0x36f588,_0x47ee12){logger[_0xebf6('0xd')](_0x36f588);logger[_0xebf6('0xd')](_0x47ee12);if(_0x1bd481){logger['error'](_0x1bd481);return _0x474dbe(_0x1bd481);}return _0x231d6b(_0x36f588);});});}exports[_0xebf6('0xe')]=function(_0x101a6c,_0x20c9ce){return pm2[_0xebf6('0xf')]()[_0xebf6('0x10')](function(_0x4dbf51){if(_0x4dbf51){var _0x4c01f4=_['reject'](_0x4dbf51,function(_0x4cecbc){return _0x4cecbc[_0xebf6('0xa')]==='express'||_0x4cecbc[_0xebf6('0xa')]===_0xebf6('0x11');});return{'rows':_0x4c01f4,'count':_0x4c01f4[_0xebf6('0x12')]};}return null;})[_0xebf6('0x10')](respondWithResult(_0x20c9ce,null))[_0xebf6('0x13')](handleError(_0x20c9ce,null));};exports[_0xebf6('0x14')]=function(_0x219621,_0x2dc96f){return pm2[_0xebf6('0x15')](_0x219621[_0xebf6('0x16')]['id'])['then'](respondWithResult(_0x2dc96f,null))['then'](handleEntityNotFound(_0x2dc96f,null))[_0xebf6('0x13')](handleError(_0x2dc96f,null));};exports[_0xebf6('0x17')]=function(_0x10051e,_0x410f06){if(_0x10051e[_0xebf6('0x18')][_0xebf6('0xa')]&&_0x10051e[_0xebf6('0x18')][_0xebf6('0x19')]){var _0x4fb497=path[_0xebf6('0x1a')](__dirname,_0xebf6('0x1b'),_0x10051e[_0xebf6('0x18')][_0xebf6('0x19')]);var _0x6303ac=process[_0xebf6('0x1c')]();process[_0xebf6('0x1d')](path[_0xebf6('0x1e')](_0x4fb497));return execChildProcess()[_0xebf6('0x10')](function(_0x2e32c6){process[_0xebf6('0x1d')](_0x6303ac);return pm2[_0xebf6('0x1f')]({'name':_0x10051e[_0xebf6('0x18')][_0xebf6('0xa')],'script':_0x4fb497});})[_0xebf6('0x10')](function(_0x1d0078){pm2[_0xebf6('0x20')]();return _0x1d0078[0x0];})[_0xebf6('0x10')](respondWithResult(_0x410f06,0xc9))[_0xebf6('0x13')](handleError(_0x410f06,null));}else{return _0x410f06['status'](0x1f4)['send']({'message':_0xebf6('0x21')});}};exports['update']=function(_0x230d84,_0x430eb7){if(_0x230d84['body']['id']){delete _0x230d84['body']['id'];}var _0x37950c={'online':_0xebf6('0x22'),'stopped':_0xebf6('0x23')};if(_0x37950c[_0xebf6('0x24')](_0x230d84[_0xebf6('0x18')][_0xebf6('0x7')])){return pm2[_0x37950c[_0x230d84[_0xebf6('0x18')][_0xebf6('0x7')]]](_0x230d84['params']['id'])[_0xebf6('0x10')](respondWithResult(_0x430eb7,0xc8))[_0xebf6('0x13')](handleError(_0x430eb7,null));}else{return _0x430eb7['status'](0x1f4)[_0xebf6('0xb')]({'message':_0xebf6('0x25')});}};exports['destroy']=function(_0x2901fc,_0x1fa407){if(_0x2901fc[_0xebf6('0x18')]['id']){delete _0x2901fc[_0xebf6('0x18')]['id'];}if(_0x2901fc[_0xebf6('0x16')]['id']){return pm2[_0xebf6('0x26')](_0x2901fc['params']['id'])[_0xebf6('0x10')](function(_0x34cc38){pm2['dump']();return _0x34cc38[0x0];})['then'](respondWithResult(_0x1fa407,null))[_0xebf6('0x13')](handleError(_0x1fa407,null));}else{return _0x1fa407[_0xebf6('0x7')](0x1f4)['send']({'message':_0xebf6('0x27')});}};