Built motion from commit (unavailable).|2.5.31
[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 _0x6723=['name','send','npm\x20install','info','index','list','then','reject','express','motion2','length','show','describe','params','catch','create','script','join','../../files/plugins','body','cwd','chdir','dirname','start','dump','update','restart','hasOwnProperty','destroy','delete','Unknown\x20id','lodash','../../config/pm2','../../config/logger','api','path','child_process','exec','sendStatus','status','json','error','stack'];(function(_0x3b0d56,_0x4d4a91){var _0x5219af=function(_0x4f1dfc){while(--_0x4f1dfc){_0x3b0d56['push'](_0x3b0d56['shift']());}};_0x5219af(++_0x4d4a91);}(_0x6723,0xa0));var _0x3672=function(_0x5e8318,_0xbfb901){_0x5e8318=_0x5e8318-0x0;var _0x35fbbf=_0x6723[_0x5e8318];return _0x35fbbf;};'use strict';var _=require(_0x3672('0x0'));var pm2=require(_0x3672('0x1'));var logger=require(_0x3672('0x2'))(_0x3672('0x3'));var path=require(_0x3672('0x4'));var exec=require(_0x3672('0x5'))[_0x3672('0x6')];var BPromise=require('bluebird');function handleEntityNotFound(_0x4ff78f,_0x59656b){return function(_0x405aa0){if(!_0x405aa0){_0x4ff78f[_0x3672('0x7')](0x194);;}return _0x405aa0;};}function respondWithResult(_0xf33673,_0x1c5692){_0x1c5692=_0x1c5692||0xc8;return function(_0x4e52ef){if(_0x4e52ef){return _0xf33673[_0x3672('0x8')](_0x1c5692)[_0x3672('0x9')](_0x4e52ef);}return null;};}function handleError(_0x18ceb2,_0xdee1f3){_0xdee1f3=_0xdee1f3||0x1f4;return function(_0x33955f){logger[_0x3672('0xa')](_0x33955f[_0x3672('0xb')]);if(_0x33955f[_0x3672('0xc')]){delete _0x33955f[_0x3672('0xc')];}_0x18ceb2[_0x3672('0x8')](_0xdee1f3)[_0x3672('0xd')](_0x33955f);};}function execChildProcess(){return new BPromise(function(_0x3e921a,_0x1313c4){exec(_0x3672('0xe'),function(_0x2aac49,_0x2ce847,_0x2e091c){logger[_0x3672('0xf')](_0x2ce847);logger[_0x3672('0xf')](_0x2e091c);if(_0x2aac49){logger[_0x3672('0xa')](_0x2aac49);return _0x1313c4(_0x2aac49);}return _0x3e921a(_0x2ce847);});});}exports[_0x3672('0x10')]=function(_0x307af0,_0x2e1787){return pm2[_0x3672('0x11')]()[_0x3672('0x12')](function(_0x41ff14){if(_0x41ff14){var _0x3152c6=_[_0x3672('0x13')](_0x41ff14,function(_0x19dadd){return _0x19dadd[_0x3672('0xc')]===_0x3672('0x14')||_0x19dadd[_0x3672('0xc')]===_0x3672('0x15');});return{'rows':_0x3152c6,'count':_0x3152c6[_0x3672('0x16')]};}return null;})['then'](respondWithResult(_0x2e1787,null))['catch'](handleError(_0x2e1787,null));};exports[_0x3672('0x17')]=function(_0x1fc92a,_0x498067){return pm2[_0x3672('0x18')](_0x1fc92a[_0x3672('0x19')]['id'])[_0x3672('0x12')](respondWithResult(_0x498067,null))['then'](handleEntityNotFound(_0x498067,null))[_0x3672('0x1a')](handleError(_0x498067,null));};exports[_0x3672('0x1b')]=function(_0x3bd317,_0xea6fbe){if(_0x3bd317['body'][_0x3672('0xc')]&&_0x3bd317['body'][_0x3672('0x1c')]){var _0x43430f=path[_0x3672('0x1d')](__dirname,_0x3672('0x1e'),_0x3bd317[_0x3672('0x1f')][_0x3672('0x1c')]);var _0x673c5b=process[_0x3672('0x20')]();process[_0x3672('0x21')](path[_0x3672('0x22')](_0x43430f));return execChildProcess()[_0x3672('0x12')](function(_0x4d86d0){process[_0x3672('0x21')](_0x673c5b);return pm2[_0x3672('0x23')]({'name':_0x3bd317['body'][_0x3672('0xc')],'script':_0x43430f});})[_0x3672('0x12')](function(_0x307db0){pm2[_0x3672('0x24')]();return _0x307db0[0x0];})[_0x3672('0x12')](respondWithResult(_0xea6fbe,0xc9))[_0x3672('0x1a')](handleError(_0xea6fbe,null));}else{return _0xea6fbe['status'](0x1f4)[_0x3672('0xd')]({'message':'Missing\x20name\x20and/or\x20path'});}};exports[_0x3672('0x25')]=function(_0x5d83a8,_0x2899fd){if(_0x5d83a8[_0x3672('0x1f')]['id']){delete _0x5d83a8[_0x3672('0x1f')]['id'];}var _0x13ebc2={'online':_0x3672('0x26'),'stopped':'stop'};if(_0x13ebc2[_0x3672('0x27')](_0x5d83a8['body'][_0x3672('0x8')])){return pm2[_0x13ebc2[_0x5d83a8['body']['status']]](_0x5d83a8[_0x3672('0x19')]['id'])['then'](respondWithResult(_0x2899fd,0xc8))['catch'](handleError(_0x2899fd,null));}else{return _0x2899fd[_0x3672('0x8')](0x1f4)[_0x3672('0xd')]({'message':'Unknown\x20status'});}};exports[_0x3672('0x28')]=function(_0x462c4b,_0x62319f){if(_0x462c4b[_0x3672('0x1f')]['id']){delete _0x462c4b[_0x3672('0x1f')]['id'];}if(_0x462c4b[_0x3672('0x19')]['id']){return pm2[_0x3672('0x29')](_0x462c4b[_0x3672('0x19')]['id'])['then'](function(_0x5851bb){pm2[_0x3672('0x24')]();return _0x5851bb[0x0];})[_0x3672('0x12')](respondWithResult(_0x62319f,null))[_0x3672('0x1a')](handleError(_0x62319f,null));}else{return _0x62319f[_0x3672('0x8')](0x1f4)[_0x3672('0xd')]({'message':_0x3672('0x2a')});}};