Built motion from commit 5293bb2a.|2.6.30
[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 _0xa9e0=['list','then','reject','express','motion2','catch','describe','params','create','body','script','join','../../files/plugins','chdir','dirname','start','dump','Missing\x20name\x20and/or\x20path','update','stop','hasOwnProperty','Unknown\x20status','destroy','delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','child_process','bluebird','sendStatus','status','stack','name','send','info','error','index'];(function(_0x1ef210,_0x417516){var _0x53ae55=function(_0x373b51){while(--_0x373b51){_0x1ef210['push'](_0x1ef210['shift']());}};_0x53ae55(++_0x417516);}(_0xa9e0,0x123));var _0x0a9e=function(_0x3b5250,_0x7a0b2c){_0x3b5250=_0x3b5250-0x0;var _0xc844a1=_0xa9e0[_0x3b5250];return _0xc844a1;};'use strict';var _=require(_0x0a9e('0x0'));var pm2=require(_0x0a9e('0x1'));var logger=require(_0x0a9e('0x2'))('api');var path=require('path');var exec=require(_0x0a9e('0x3'))['exec'];var BPromise=require(_0x0a9e('0x4'));function handleEntityNotFound(_0x432180,_0x2ab90b){return function(_0x991246){if(!_0x991246){_0x432180[_0x0a9e('0x5')](0x194);;}return _0x991246;};}function respondWithResult(_0x57b080,_0x219af0){_0x219af0=_0x219af0||0xc8;return function(_0x441e3a){if(_0x441e3a){return _0x57b080[_0x0a9e('0x6')](_0x219af0)['json'](_0x441e3a);}return null;};}function handleError(_0x503809,_0xe42b77){_0xe42b77=_0xe42b77||0x1f4;return function(_0x56465b){logger['error'](_0x56465b[_0x0a9e('0x7')]);if(_0x56465b[_0x0a9e('0x8')]){delete _0x56465b[_0x0a9e('0x8')];}_0x503809[_0x0a9e('0x6')](_0xe42b77)[_0x0a9e('0x9')](_0x56465b);};}function execChildProcess(){return new BPromise(function(_0xbd1168,_0x4a4c56){exec('npm\x20install',function(_0x527cdd,_0x4cfe67,_0x273d4d){logger[_0x0a9e('0xa')](_0x4cfe67);logger[_0x0a9e('0xa')](_0x273d4d);if(_0x527cdd){logger[_0x0a9e('0xb')](_0x527cdd);return _0x4a4c56(_0x527cdd);}return _0xbd1168(_0x4cfe67);});});}exports[_0x0a9e('0xc')]=function(_0x69aeb7,_0x5db4b0){return pm2[_0x0a9e('0xd')]()[_0x0a9e('0xe')](function(_0x2b4227){if(_0x2b4227){var _0x281129=_[_0x0a9e('0xf')](_0x2b4227,function(_0x4d5611){return _0x4d5611['name']===_0x0a9e('0x10')||_0x4d5611['name']===_0x0a9e('0x11');});return{'rows':_0x281129,'count':_0x281129['length']};}return null;})[_0x0a9e('0xe')](respondWithResult(_0x5db4b0,null))[_0x0a9e('0x12')](handleError(_0x5db4b0,null));};exports['show']=function(_0x225616,_0x5a0a06){return pm2[_0x0a9e('0x13')](_0x225616[_0x0a9e('0x14')]['id'])[_0x0a9e('0xe')](respondWithResult(_0x5a0a06,null))[_0x0a9e('0xe')](handleEntityNotFound(_0x5a0a06,null))[_0x0a9e('0x12')](handleError(_0x5a0a06,null));};exports[_0x0a9e('0x15')]=function(_0x530eb7,_0x20559e){if(_0x530eb7[_0x0a9e('0x16')][_0x0a9e('0x8')]&&_0x530eb7[_0x0a9e('0x16')][_0x0a9e('0x17')]){var _0x4bb1e3=path[_0x0a9e('0x18')](__dirname,_0x0a9e('0x19'),_0x530eb7['body'][_0x0a9e('0x17')]);var _0x5a09ef=process['cwd']();process[_0x0a9e('0x1a')](path[_0x0a9e('0x1b')](_0x4bb1e3));return execChildProcess()[_0x0a9e('0xe')](function(_0x30bae6){process['chdir'](_0x5a09ef);return pm2[_0x0a9e('0x1c')]({'name':_0x530eb7[_0x0a9e('0x16')][_0x0a9e('0x8')],'script':_0x4bb1e3});})[_0x0a9e('0xe')](function(_0x370d86){pm2[_0x0a9e('0x1d')]();return _0x370d86[0x0];})[_0x0a9e('0xe')](respondWithResult(_0x20559e,0xc9))['catch'](handleError(_0x20559e,null));}else{return _0x20559e['status'](0x1f4)[_0x0a9e('0x9')]({'message':_0x0a9e('0x1e')});}};exports[_0x0a9e('0x1f')]=function(_0x33161b,_0x526cf3){if(_0x33161b[_0x0a9e('0x16')]['id']){delete _0x33161b['body']['id'];}var _0x45a1e7={'online':'restart','stopped':_0x0a9e('0x20')};if(_0x45a1e7[_0x0a9e('0x21')](_0x33161b[_0x0a9e('0x16')][_0x0a9e('0x6')])){return pm2[_0x45a1e7[_0x33161b[_0x0a9e('0x16')][_0x0a9e('0x6')]]](_0x33161b[_0x0a9e('0x14')]['id'])[_0x0a9e('0xe')](respondWithResult(_0x526cf3,0xc8))['catch'](handleError(_0x526cf3,null));}else{return _0x526cf3[_0x0a9e('0x6')](0x1f4)[_0x0a9e('0x9')]({'message':_0x0a9e('0x22')});}};exports[_0x0a9e('0x23')]=function(_0x5c877d,_0x15b200){if(_0x5c877d[_0x0a9e('0x16')]['id']){delete _0x5c877d[_0x0a9e('0x16')]['id'];}if(_0x5c877d[_0x0a9e('0x14')]['id']){return pm2[_0x0a9e('0x24')](_0x5c877d[_0x0a9e('0x14')]['id'])[_0x0a9e('0xe')](function(_0x2e8759){pm2[_0x0a9e('0x1d')]();return _0x2e8759[0x0];})['then'](respondWithResult(_0x15b200,null))[_0x0a9e('0x12')](handleError(_0x15b200,null));}else{return _0x15b200['status'](0x1f4)[_0x0a9e('0x9')]({'message':_0x0a9e('0x25')});}};