Built motion from commit (unavailable).|2.4.3
[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 _0xa59d=['child_process','exec','bluebird','sendStatus','status','error','stack','name','send','info','index','then','reject','express','motion2','catch','show','describe','params','create','body','join','../../files/plugins','script','start','dump','Missing\x20name\x20and/or\x20path','update','restart','stop','hasOwnProperty','Unknown\x20status','destroy','delete','Unknown\x20id','lodash','../../config/logger','api','path'];(function(_0x40387f,_0x53a660){var _0x10f4e2=function(_0x33075b){while(--_0x33075b){_0x40387f['push'](_0x40387f['shift']());}};_0x10f4e2(++_0x53a660);}(_0xa59d,0x15b));var _0xda59=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xa59d[_0x321bb2];return _0x9c12ed;};'use strict';var _=require(_0xda59('0x0'));var pm2=require('../../config/pm2');var logger=require(_0xda59('0x1'))(_0xda59('0x2'));var path=require(_0xda59('0x3'));var exec=require(_0xda59('0x4'))[_0xda59('0x5')];var BPromise=require(_0xda59('0x6'));function handleEntityNotFound(_0x4d4990,_0x492f0a){return function(_0x10dbf2){if(!_0x10dbf2){_0x4d4990[_0xda59('0x7')](0x194);;}return _0x10dbf2;};}function respondWithResult(_0x305f9c,_0x582a43){_0x582a43=_0x582a43||0xc8;return function(_0x2cc569){if(_0x2cc569){return _0x305f9c[_0xda59('0x8')](_0x582a43)['json'](_0x2cc569);}return null;};}function handleError(_0x1b0f3e,_0x59bfa7){_0x59bfa7=_0x59bfa7||0x1f4;return function(_0x4a63b1){logger[_0xda59('0x9')](_0x4a63b1[_0xda59('0xa')]);if(_0x4a63b1[_0xda59('0xb')]){delete _0x4a63b1[_0xda59('0xb')];}_0x1b0f3e[_0xda59('0x8')](_0x59bfa7)[_0xda59('0xc')](_0x4a63b1);};}function execChildProcess(){return new BPromise(function(_0x1064b9,_0xd8a0b3){exec('npm\x20install',function(_0x61b7e2,_0xe3e0d1,_0x4d94ed){logger[_0xda59('0xd')](_0xe3e0d1);logger[_0xda59('0xd')](_0x4d94ed);if(_0x61b7e2){logger['error'](_0x61b7e2);return _0xd8a0b3(_0x61b7e2);}return _0x1064b9(_0xe3e0d1);});});}exports[_0xda59('0xe')]=function(_0x1b5c50,_0x49ef6d){return pm2['list']()[_0xda59('0xf')](function(_0x890719){if(_0x890719){var _0x35e7c2=_[_0xda59('0x10')](_0x890719,function(_0x24fa7e){return _0x24fa7e[_0xda59('0xb')]===_0xda59('0x11')||_0x24fa7e[_0xda59('0xb')]===_0xda59('0x12');});return{'rows':_0x35e7c2,'count':_0x35e7c2['length']};}return null;})[_0xda59('0xf')](respondWithResult(_0x49ef6d,null))[_0xda59('0x13')](handleError(_0x49ef6d,null));};exports[_0xda59('0x14')]=function(_0x1b243b,_0x54de38){return pm2[_0xda59('0x15')](_0x1b243b[_0xda59('0x16')]['id'])['then'](respondWithResult(_0x54de38,null))[_0xda59('0xf')](handleEntityNotFound(_0x54de38,null))['catch'](handleError(_0x54de38,null));};exports[_0xda59('0x17')]=function(_0x33904f,_0x5add40){if(_0x33904f[_0xda59('0x18')][_0xda59('0xb')]&&_0x33904f[_0xda59('0x18')]['script']){var _0x48d1af=path[_0xda59('0x19')](__dirname,_0xda59('0x1a'),_0x33904f[_0xda59('0x18')][_0xda59('0x1b')]);var _0x2293d8=process['cwd']();process['chdir'](path['dirname'](_0x48d1af));return execChildProcess()['then'](function(_0x170f4){process['chdir'](_0x2293d8);return pm2[_0xda59('0x1c')]({'name':_0x33904f['body']['name'],'script':_0x48d1af});})[_0xda59('0xf')](function(_0x38a7a9){pm2[_0xda59('0x1d')]();return _0x38a7a9[0x0];})[_0xda59('0xf')](respondWithResult(_0x5add40,0xc9))[_0xda59('0x13')](handleError(_0x5add40,null));}else{return _0x5add40[_0xda59('0x8')](0x1f4)[_0xda59('0xc')]({'message':_0xda59('0x1e')});}};exports[_0xda59('0x1f')]=function(_0x2a83de,_0x3788cc){if(_0x2a83de[_0xda59('0x18')]['id']){delete _0x2a83de[_0xda59('0x18')]['id'];}var _0xc86e1b={'online':_0xda59('0x20'),'stopped':_0xda59('0x21')};if(_0xc86e1b[_0xda59('0x22')](_0x2a83de[_0xda59('0x18')][_0xda59('0x8')])){return pm2[_0xc86e1b[_0x2a83de['body']['status']]](_0x2a83de[_0xda59('0x16')]['id'])['then'](respondWithResult(_0x3788cc,0xc8))[_0xda59('0x13')](handleError(_0x3788cc,null));}else{return _0x3788cc['status'](0x1f4)['send']({'message':_0xda59('0x23')});}};exports[_0xda59('0x24')]=function(_0x2ed87e,_0x5a7b6b){if(_0x2ed87e[_0xda59('0x18')]['id']){delete _0x2ed87e[_0xda59('0x18')]['id'];}if(_0x2ed87e['params']['id']){return pm2[_0xda59('0x25')](_0x2ed87e[_0xda59('0x16')]['id'])[_0xda59('0xf')](function(_0x51aab4){pm2['dump']();return _0x51aab4[0x0];})[_0xda59('0xf')](respondWithResult(_0x5a7b6b,null))['catch'](handleError(_0x5a7b6b,null));}else{return _0x5a7b6b[_0xda59('0x8')](0x1f4)[_0xda59('0xc')]({'message':_0xda59('0x26')});}};