Built motion from commit (unavailable).|2.5.14
[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 _0x6172=['npm\x20install','info','then','reject','express','length','catch','show','params','create','body','script','../../files/plugins','cwd','dirname','chdir','dump','Missing\x20name\x20and/or\x20path','update','restart','hasOwnProperty','destroy','Unknown\x20id','lodash','../../config/pm2','../../config/logger','path','child_process','sendStatus','status','json','error','stack','name','send'];(function(_0x164eca,_0x555e28){var _0x2ce562=function(_0x148ca6){while(--_0x148ca6){_0x164eca['push'](_0x164eca['shift']());}};_0x2ce562(++_0x555e28);}(_0x6172,0xa3));var _0x2617=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x6172[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x2617('0x0'));var pm2=require(_0x2617('0x1'));var logger=require(_0x2617('0x2'))('api');var path=require(_0x2617('0x3'));var exec=require(_0x2617('0x4'))['exec'];var BPromise=require('bluebird');function handleEntityNotFound(_0x4331a3,_0x15509f){return function(_0x1a785c){if(!_0x1a785c){_0x4331a3[_0x2617('0x5')](0x194);;}return _0x1a785c;};}function respondWithResult(_0x3fc0a7,_0xf9eba2){_0xf9eba2=_0xf9eba2||0xc8;return function(_0x1d1f5a){if(_0x1d1f5a){return _0x3fc0a7[_0x2617('0x6')](_0xf9eba2)[_0x2617('0x7')](_0x1d1f5a);}return null;};}function handleError(_0x253911,_0x95582){_0x95582=_0x95582||0x1f4;return function(_0x32dd65){logger[_0x2617('0x8')](_0x32dd65[_0x2617('0x9')]);if(_0x32dd65[_0x2617('0xa')]){delete _0x32dd65[_0x2617('0xa')];}_0x253911[_0x2617('0x6')](_0x95582)[_0x2617('0xb')](_0x32dd65);};}function execChildProcess(){return new BPromise(function(_0x24098c,_0x1a3012){exec(_0x2617('0xc'),function(_0x1ebd1f,_0x359b59,_0x1f3df1){logger['info'](_0x359b59);logger[_0x2617('0xd')](_0x1f3df1);if(_0x1ebd1f){logger[_0x2617('0x8')](_0x1ebd1f);return _0x1a3012(_0x1ebd1f);}return _0x24098c(_0x359b59);});});}exports['index']=function(_0x336323,_0x2f56ab){return pm2['list']()[_0x2617('0xe')](function(_0x4b6d52){if(_0x4b6d52){var _0x3f1d3c=_[_0x2617('0xf')](_0x4b6d52,function(_0x11a675){return _0x11a675[_0x2617('0xa')]===_0x2617('0x10')||_0x11a675[_0x2617('0xa')]==='motion2';});return{'rows':_0x3f1d3c,'count':_0x3f1d3c[_0x2617('0x11')]};}return null;})['then'](respondWithResult(_0x2f56ab,null))[_0x2617('0x12')](handleError(_0x2f56ab,null));};exports[_0x2617('0x13')]=function(_0x28a6e8,_0x7ee075){return pm2['describe'](_0x28a6e8[_0x2617('0x14')]['id'])[_0x2617('0xe')](respondWithResult(_0x7ee075,null))[_0x2617('0xe')](handleEntityNotFound(_0x7ee075,null))[_0x2617('0x12')](handleError(_0x7ee075,null));};exports[_0x2617('0x15')]=function(_0x583808,_0x2d66b6){if(_0x583808[_0x2617('0x16')]['name']&&_0x583808[_0x2617('0x16')][_0x2617('0x17')]){var _0x41cb00=path['join'](__dirname,_0x2617('0x18'),_0x583808[_0x2617('0x16')][_0x2617('0x17')]);var _0x5c8129=process[_0x2617('0x19')]();process['chdir'](path[_0x2617('0x1a')](_0x41cb00));return execChildProcess()[_0x2617('0xe')](function(_0x3bcded){process[_0x2617('0x1b')](_0x5c8129);return pm2['start']({'name':_0x583808[_0x2617('0x16')][_0x2617('0xa')],'script':_0x41cb00});})[_0x2617('0xe')](function(_0xbe13d2){pm2[_0x2617('0x1c')]();return _0xbe13d2[0x0];})[_0x2617('0xe')](respondWithResult(_0x2d66b6,0xc9))[_0x2617('0x12')](handleError(_0x2d66b6,null));}else{return _0x2d66b6[_0x2617('0x6')](0x1f4)[_0x2617('0xb')]({'message':_0x2617('0x1d')});}};exports[_0x2617('0x1e')]=function(_0x120bbd,_0x14ea46){if(_0x120bbd[_0x2617('0x16')]['id']){delete _0x120bbd[_0x2617('0x16')]['id'];}var _0xa39474={'online':_0x2617('0x1f'),'stopped':'stop'};if(_0xa39474[_0x2617('0x20')](_0x120bbd['body'][_0x2617('0x6')])){return pm2[_0xa39474[_0x120bbd['body'][_0x2617('0x6')]]](_0x120bbd[_0x2617('0x14')]['id'])[_0x2617('0xe')](respondWithResult(_0x14ea46,0xc8))['catch'](handleError(_0x14ea46,null));}else{return _0x14ea46[_0x2617('0x6')](0x1f4)['send']({'message':'Unknown\x20status'});}};exports[_0x2617('0x21')]=function(_0x5697c5,_0x38f908){if(_0x5697c5[_0x2617('0x16')]['id']){delete _0x5697c5[_0x2617('0x16')]['id'];}if(_0x5697c5[_0x2617('0x14')]['id']){return pm2['delete'](_0x5697c5['params']['id'])[_0x2617('0xe')](function(_0x63843e){pm2[_0x2617('0x1c')]();return _0x63843e[0x0];})[_0x2617('0xe')](respondWithResult(_0x38f908,null))[_0x2617('0x12')](handleError(_0x38f908,null));}else{return _0x38f908['status'](0x1f4)[_0x2617('0xb')]({'message':_0x2617('0x22')});}};