Built motion from commit 0c5f406c.|2.6.29
[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 _0xc788=['body','script','join','../../files/plugins','chdir','dirname','start','dump','send','update','stop','hasOwnProperty','Unknown\x20status','params','delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','child_process','exec','bluebird','sendStatus','status','error','stack','name','info','index','list','then','reject','motion2','catch','show','describe'];(function(_0x4ed786,_0x74f270){var _0x2f0243=function(_0x5642f5){while(--_0x5642f5){_0x4ed786['push'](_0x4ed786['shift']());}};_0x2f0243(++_0x74f270);}(_0xc788,0xc4));var _0x8c78=function(_0x4730bd,_0x1e9541){_0x4730bd=_0x4730bd-0x0;var _0x1b2849=_0xc788[_0x4730bd];return _0x1b2849;};'use strict';var _=require(_0x8c78('0x0'));var pm2=require(_0x8c78('0x1'));var logger=require(_0x8c78('0x2'))('api');var path=require('path');var exec=require(_0x8c78('0x3'))[_0x8c78('0x4')];var BPromise=require(_0x8c78('0x5'));function handleEntityNotFound(_0x1d0670,_0x386f0a){return function(_0x5498f9){if(!_0x5498f9){_0x1d0670[_0x8c78('0x6')](0x194);;}return _0x5498f9;};}function respondWithResult(_0x4555da,_0x329152){_0x329152=_0x329152||0xc8;return function(_0x1ac27f){if(_0x1ac27f){return _0x4555da[_0x8c78('0x7')](_0x329152)['json'](_0x1ac27f);}return null;};}function handleError(_0x247188,_0x299d9d){_0x299d9d=_0x299d9d||0x1f4;return function(_0x9bc075){logger[_0x8c78('0x8')](_0x9bc075[_0x8c78('0x9')]);if(_0x9bc075[_0x8c78('0xa')]){delete _0x9bc075['name'];}_0x247188[_0x8c78('0x7')](_0x299d9d)['send'](_0x9bc075);};}function execChildProcess(){return new BPromise(function(_0x3d55f0,_0x45935a){exec('npm\x20install',function(_0x1a05a7,_0x95e78e,_0x5ee642){logger[_0x8c78('0xb')](_0x95e78e);logger['info'](_0x5ee642);if(_0x1a05a7){logger['error'](_0x1a05a7);return _0x45935a(_0x1a05a7);}return _0x3d55f0(_0x95e78e);});});}exports[_0x8c78('0xc')]=function(_0x1b1d0e,_0x26178c){return pm2[_0x8c78('0xd')]()[_0x8c78('0xe')](function(_0x3d1306){if(_0x3d1306){var _0xe5f8ae=_[_0x8c78('0xf')](_0x3d1306,function(_0x2f44af){return _0x2f44af[_0x8c78('0xa')]==='express'||_0x2f44af[_0x8c78('0xa')]===_0x8c78('0x10');});return{'rows':_0xe5f8ae,'count':_0xe5f8ae['length']};}return null;})[_0x8c78('0xe')](respondWithResult(_0x26178c,null))[_0x8c78('0x11')](handleError(_0x26178c,null));};exports[_0x8c78('0x12')]=function(_0x23824e,_0x2a982c){return pm2[_0x8c78('0x13')](_0x23824e['params']['id'])['then'](respondWithResult(_0x2a982c,null))[_0x8c78('0xe')](handleEntityNotFound(_0x2a982c,null))['catch'](handleError(_0x2a982c,null));};exports['create']=function(_0xece4f0,_0x56c191){if(_0xece4f0[_0x8c78('0x14')][_0x8c78('0xa')]&&_0xece4f0['body'][_0x8c78('0x15')]){var _0x5b111b=path[_0x8c78('0x16')](__dirname,_0x8c78('0x17'),_0xece4f0['body'][_0x8c78('0x15')]);var _0x188cc3=process['cwd']();process[_0x8c78('0x18')](path[_0x8c78('0x19')](_0x5b111b));return execChildProcess()[_0x8c78('0xe')](function(_0x9581c6){process[_0x8c78('0x18')](_0x188cc3);return pm2[_0x8c78('0x1a')]({'name':_0xece4f0[_0x8c78('0x14')][_0x8c78('0xa')],'script':_0x5b111b});})[_0x8c78('0xe')](function(_0x4a7d20){pm2[_0x8c78('0x1b')]();return _0x4a7d20[0x0];})[_0x8c78('0xe')](respondWithResult(_0x56c191,0xc9))[_0x8c78('0x11')](handleError(_0x56c191,null));}else{return _0x56c191['status'](0x1f4)[_0x8c78('0x1c')]({'message':'Missing\x20name\x20and/or\x20path'});}};exports[_0x8c78('0x1d')]=function(_0x24f9a7,_0x8d9ff9){if(_0x24f9a7['body']['id']){delete _0x24f9a7[_0x8c78('0x14')]['id'];}var _0x2568d5={'online':'restart','stopped':_0x8c78('0x1e')};if(_0x2568d5[_0x8c78('0x1f')](_0x24f9a7[_0x8c78('0x14')][_0x8c78('0x7')])){return pm2[_0x2568d5[_0x24f9a7[_0x8c78('0x14')][_0x8c78('0x7')]]](_0x24f9a7['params']['id'])[_0x8c78('0xe')](respondWithResult(_0x8d9ff9,0xc8))['catch'](handleError(_0x8d9ff9,null));}else{return _0x8d9ff9[_0x8c78('0x7')](0x1f4)[_0x8c78('0x1c')]({'message':_0x8c78('0x20')});}};exports['destroy']=function(_0x1f1a0c,_0x3816d2){if(_0x1f1a0c['body']['id']){delete _0x1f1a0c[_0x8c78('0x14')]['id'];}if(_0x1f1a0c[_0x8c78('0x21')]['id']){return pm2[_0x8c78('0x22')](_0x1f1a0c['params']['id'])[_0x8c78('0xe')](function(_0x63307e){pm2[_0x8c78('0x1b')]();return _0x63307e[0x0];})['then'](respondWithResult(_0x3816d2,null))[_0x8c78('0x11')](handleError(_0x3816d2,null));}else{return _0x3816d2[_0x8c78('0x7')](0x1f4)['send']({'message':_0x8c78('0x23')});}};