ff10e20641eb6797ad867142a14b485aaa760b07
[motion2.git] / server / api / plugin / plugin.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 _0xf15b=['filter','VIRTUAL','merge','Plugin','count','includeAll','include','findAll','rows','catch','show','params','keys','length','find','download','root','server/files/plugins','format','basename','createWriteStream','warning','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','**/*','join','node_modules/**/*','attachments/**/*','finalize','close','existsSync','Plugin\x20not\x20found','%s.zip','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','Temporary\x20file\x20removed','upload','file','filename','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','Invalid\x20plugin\x20structure','lstatSync','isFile','isDirectory','readdirSync','some','manifest.json','Plugin\x20manifest\x20missing','parse','undefined','Invalid\x20manifest:\x20name\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','html','views','script','scriptName','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','sidebar','icon-apps','admin','test','plugins','Warning:\x20agent\x20view\x20not\x20specified','agent','create','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','dirname','webhookGet','\x27PATH\x27\x20parameter\x20not\x20specified','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','port','encoding','method','headers','content-length','content-type','endsWith','statusCode','webhookPost','resolve','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','extract-zip','rimraf','archiver','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','then','destroy','get','Plugins','error','stack','name','send','index','map','rawAttributes','type','key','model','query','intersection','attributes','fields','hasOwnProperty','where','filters','pick'];(function(_0x424a9a,_0x2dd9af){var _0xa7831c=function(_0x512534){while(--_0x512534){_0x424a9a['push'](_0x424a9a['shift']());}};_0xa7831c(++_0x2dd9af);}(_0xf15b,0x6a));var _0xbf15=function(_0x53b37c,_0x1e3dae){_0x53b37c=_0x53b37c-0x0;var _0x912a5=_0xf15b[_0x53b37c];return _0x912a5;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xbf15('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbf15('0x1'));var jsonpatch=require(_0xbf15('0x2'));var rp=require(_0xbf15('0x3'));var moment=require('moment');var BPromise=require(_0xbf15('0x4'));var Mustache=require(_0xbf15('0x5'));var util=require(_0xbf15('0x6'));var path=require(_0xbf15('0x7'));var sox=require(_0xbf15('0x8'));var csv=require('to-csv');var ejs=require(_0xbf15('0x9'));var fs=require('fs');var _=require(_0xbf15('0xa'));var squel=require(_0xbf15('0xb'));var crypto=require(_0xbf15('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xbf15('0xd'));var toCsv=require(_0xbf15('0xe'));var querystring=require(_0xbf15('0xf'));var Papa=require(_0xbf15('0x10'));var extract=require(_0xbf15('0x11'));var rimraf=require(_0xbf15('0x12'));var archiver=require(_0xbf15('0x13'));var Redis=require('ioredis');var authService=require(_0xbf15('0x14'));var qs=require(_0xbf15('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbf15('0x16'));var logger=require(_0xbf15('0x17'))(_0xbf15('0x18'));var utils=require(_0xbf15('0x19'));var config=require(_0xbf15('0x1a'));var db=require(_0xbf15('0x1b'))['db'];config[_0xbf15('0x1c')]=_[_0xbf15('0x1d')](config[_0xbf15('0x1c')],{'host':_0xbf15('0x1e'),'port':0x18eb});var socket=require(_0xbf15('0x1f'))(new Redis(config[_0xbf15('0x1c')]));require(_0xbf15('0x20'))[_0xbf15('0x21')](socket);function respondWithStatusCode(_0x3f0c4e,_0x19a54b){_0x19a54b=_0x19a54b||0xcc;return function(_0x40445b){if(_0x40445b){return _0x3f0c4e[_0xbf15('0x22')](_0x19a54b);}return _0x3f0c4e[_0xbf15('0x23')](_0x19a54b)[_0xbf15('0x24')]();};}function respondWithResult(_0x3f233f,_0x4ecc34){_0x4ecc34=_0x4ecc34||0xc8;return function(_0xd4510a){if(_0xd4510a){return _0x3f233f['status'](_0x4ecc34)[_0xbf15('0x25')](_0xd4510a);}};}function respondWithFilteredResult(_0x19df5c,_0x4e3103){return function(_0x125f17){if(_0x125f17){var _0x4505f0=_0x125f17['count'],_0x82f5f7=_0x4e3103['offset'],_0x449608=_0x4e3103[_0xbf15('0x26')]+_0x4e3103[_0xbf15('0x27')],_0x4093da;if(_0x449608>=_0x4505f0){_0x449608=_0x4505f0;_0x4093da=0xc8;}else{_0x4093da=0xce;}_0x19df5c[_0xbf15('0x23')](_0x4093da);return _0x19df5c[_0xbf15('0x28')](_0xbf15('0x29'),_0x82f5f7+'-'+_0x449608+'/'+_0x4505f0)[_0xbf15('0x25')](_0x125f17);}return null;};}function patchUpdates(_0x581ccb){return function(_0x35e2e1){try{jsonpatch[_0xbf15('0x2a')](_0x35e2e1,_0x581ccb,!![]);}catch(_0x3c510b){return BPromise['reject'](_0x3c510b);}return _0x35e2e1['save']();};}function saveUpdates(_0x3f3fe4,_0x1b9147){return function(_0x504eff){if(_0x504eff){return _0x504eff['update'](_0x3f3fe4)[_0xbf15('0x2b')](function(_0x4df54d){return _0x4df54d;});}return null;};}function removeEntity(_0x268c9e,_0x2bc8db){return function(_0x240be9){if(_0x240be9){return _0x240be9[_0xbf15('0x2c')]()[_0xbf15('0x2b')](function(){var _0xfbb498=_0x240be9[_0xbf15('0x2d')]({'plain':!![]});var _0x151e31=_0xbf15('0x2e');return db['UserProfileResource'][_0xbf15('0x2c')]({'where':{'type':_0x151e31,'resourceId':_0xfbb498['id']}})[_0xbf15('0x2b')](function(){return _0x240be9;});})[_0xbf15('0x2b')](function(){_0x268c9e['status'](0xcc)[_0xbf15('0x24')]();});}};}function handleEntityNotFound(_0x5ca988,_0x66bf7e){return function(_0x45abe6){if(!_0x45abe6){_0x5ca988[_0xbf15('0x22')](0x194);}return _0x45abe6;};}function handleError(_0xac8ce9,_0xfee53b){_0xfee53b=_0xfee53b||0x1f4;return function(_0x1f0508){logger[_0xbf15('0x2f')](_0x1f0508[_0xbf15('0x30')]);if(_0x1f0508[_0xbf15('0x31')]){delete _0x1f0508[_0xbf15('0x31')];}_0xac8ce9[_0xbf15('0x23')](_0xfee53b)[_0xbf15('0x32')](_0x1f0508);};}exports[_0xbf15('0x33')]=function(_0x2b5066,_0x1e2180){var _0xd52cc3={},_0x482392={},_0x5ed504={'count':0x0,'rows':[]};var _0x181a1e=_[_0xbf15('0x34')](db['Plugin'][_0xbf15('0x35')],function(_0xd7c177){return{'name':_0xd7c177['fieldName'],'type':_0xd7c177[_0xbf15('0x36')][_0xbf15('0x37')]};});_0x482392[_0xbf15('0x38')]=_['map'](_0x181a1e,_0xbf15('0x31'));_0x482392[_0xbf15('0x39')]=_['keys'](_0x2b5066[_0xbf15('0x39')]);_0x482392['filters']=_[_0xbf15('0x3a')](_0x482392[_0xbf15('0x38')],_0x482392[_0xbf15('0x39')]);_0xd52cc3[_0xbf15('0x3b')]=_[_0xbf15('0x3a')](_0x482392['model'],qs['fields'](_0x2b5066[_0xbf15('0x39')][_0xbf15('0x3c')]));_0xd52cc3[_0xbf15('0x3b')]=_0xd52cc3[_0xbf15('0x3b')]['length']?_0xd52cc3['attributes']:_0x482392['model'];if(!_0x2b5066[_0xbf15('0x39')][_0xbf15('0x3d')]('nolimit')){_0xd52cc3['limit']=qs[_0xbf15('0x27')](_0x2b5066[_0xbf15('0x39')][_0xbf15('0x27')]);_0xd52cc3[_0xbf15('0x26')]=qs[_0xbf15('0x26')](_0x2b5066['query'][_0xbf15('0x26')]);}_0xd52cc3['order']=qs['sort'](_0x2b5066[_0xbf15('0x39')]['sort']);_0xd52cc3[_0xbf15('0x3e')]=qs[_0xbf15('0x3f')](_[_0xbf15('0x40')](_0x2b5066[_0xbf15('0x39')],_0x482392[_0xbf15('0x3f')]),_0x181a1e);if(_0x2b5066[_0xbf15('0x39')][_0xbf15('0x41')]){_0xd52cc3[_0xbf15('0x3e')]=_['merge'](_0xd52cc3[_0xbf15('0x3e')],{'$or':_['map'](_0x181a1e,function(_0x6aaec7){if(_0x6aaec7['type']!==_0xbf15('0x42')){var _0x9544fc={};_0x9544fc[_0x6aaec7[_0xbf15('0x31')]]={'$like':'%'+_0x2b5066[_0xbf15('0x39')][_0xbf15('0x41')]+'%'};return _0x9544fc;}})});}_0xd52cc3=_[_0xbf15('0x43')]({},_0xd52cc3,_0x2b5066['options']);var _0x321a41={'where':_0xd52cc3[_0xbf15('0x3e')]};return db[_0xbf15('0x44')][_0xbf15('0x45')](_0x321a41)[_0xbf15('0x2b')](function(_0x9399ac){_0x5ed504['count']=_0x9399ac;if(_0x2b5066[_0xbf15('0x39')][_0xbf15('0x46')]){_0xd52cc3[_0xbf15('0x47')]=[{'all':!![]}];}return db[_0xbf15('0x44')][_0xbf15('0x48')](_0xd52cc3);})[_0xbf15('0x2b')](function(_0x1a6ca1){_0x5ed504[_0xbf15('0x49')]=_0x1a6ca1;return _0x5ed504;})[_0xbf15('0x2b')](respondWithFilteredResult(_0x1e2180,_0xd52cc3))[_0xbf15('0x4a')](handleError(_0x1e2180,null));};exports[_0xbf15('0x4b')]=function(_0xd02f38,_0x23b005){var _0x228670={'raw':!![],'where':{'id':_0xd02f38[_0xbf15('0x4c')]['id']}},_0x1320af={};_0x1320af[_0xbf15('0x38')]=_[_0xbf15('0x4d')](db['Plugin'][_0xbf15('0x35')]);_0x1320af[_0xbf15('0x39')]=_['keys'](_0xd02f38['query']);_0x1320af[_0xbf15('0x3f')]=_[_0xbf15('0x3a')](_0x1320af[_0xbf15('0x38')],_0x1320af[_0xbf15('0x39')]);_0x228670[_0xbf15('0x3b')]=_[_0xbf15('0x3a')](_0x1320af[_0xbf15('0x38')],qs['fields'](_0xd02f38[_0xbf15('0x39')][_0xbf15('0x3c')]));_0x228670[_0xbf15('0x3b')]=_0x228670[_0xbf15('0x3b')][_0xbf15('0x4e')]?_0x228670['attributes']:_0x1320af[_0xbf15('0x38')];if(_0xd02f38['query'][_0xbf15('0x46')]){_0x228670['include']=[{'all':!![]}];}_0x228670=_[_0xbf15('0x43')]({},_0x228670,_0xd02f38['options']);return db[_0xbf15('0x44')][_0xbf15('0x4f')](_0x228670)['then'](handleEntityNotFound(_0x23b005,null))[_0xbf15('0x2b')](respondWithResult(_0x23b005,null))[_0xbf15('0x4a')](handleError(_0x23b005,null));};exports[_0xbf15('0x50')]=function(_0x206085,_0x26bd01,_0x3a9b18){return db[_0xbf15('0x44')]['find']({'where':{'id':_0x206085['params']['id']},'attributes':[_0xbf15('0x31'),'path'],'raw':!![]})[_0xbf15('0x2b')](handleEntityNotFound(_0x26bd01,null))[_0xbf15('0x2b')](function(_0x516469){if(_0x516469){var _0x13e873=path['join'](config[_0xbf15('0x51')],_0xbf15('0x52'),util[_0xbf15('0x53')]('%s.zip',path[_0xbf15('0x54')](_0x516469[_0xbf15('0x7')])));var _0x14d3c8=fs[_0xbf15('0x55')](_0x13e873);var _0x4aba27=archiver('zip',{'zlib':{'level':0x9}});_0x4aba27['on'](_0xbf15('0x56'),function(_0x36e6c8){if(_0x36e6c8['code']===_0xbf15('0x57')){logger[_0xbf15('0x2f')](_0x36e6c8);}else{throw new db[(_0xbf15('0x58'))]['Error']('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x4aba27['on'](_0xbf15('0x2f'),function(_0xde9c82){throw new db['Sequelize'][(_0xbf15('0x59'))](_0xbf15('0x5a'));});_0x4aba27[_0xbf15('0x5b')](_0x14d3c8);_0x4aba27[_0xbf15('0x5c')](_0xbf15('0x5d'),{'cwd':path['join'](config[_0xbf15('0x51')],_0xbf15('0x52'),path['dirname'](_0x516469[_0xbf15('0x7')])),'ignore':[path[_0xbf15('0x5e')](path['basename'](_0x516469[_0xbf15('0x7')]),_0xbf15('0x5f')),path[_0xbf15('0x5e')](path[_0xbf15('0x54')](_0x516469[_0xbf15('0x7')]),_0xbf15('0x60'))],'nodir':!![]})[_0xbf15('0x61')]();_0x14d3c8['on'](_0xbf15('0x62'),function(){if(!fs[_0xbf15('0x63')](_0x13e873)){throw new db[(_0xbf15('0x58'))][(_0xbf15('0x59'))](_0xbf15('0x64'));}return _0x26bd01[_0xbf15('0x50')](_0x13e873,util[_0xbf15('0x53')](_0xbf15('0x65'),path[_0xbf15('0x54')](_0x516469[_0xbf15('0x7')])),function(_0x282302){if(_0x282302){throw new db[(_0xbf15('0x58'))]['Error'](_0xbf15('0x66'));}fs[_0xbf15('0x67')](_0x13e873);logger[_0xbf15('0x68')](_0xbf15('0x69'));logger[_0xbf15('0x68')](_0xbf15('0x6a'));});});}return null;})[_0xbf15('0x4a')](handleError(_0x26bd01,null));};exports[_0xbf15('0x6b')]=function(_0x3c81ae,_0x33ddd7,_0x38a01d){var _0x1c9023=path[_0xbf15('0x54')](_0x3c81ae[_0xbf15('0x6c')][_0xbf15('0x6d')],path['extname'](_0x3c81ae['file'][_0xbf15('0x6d')]));var _0x1c304e=path[_0xbf15('0x5e')](config[_0xbf15('0x51')],_0xbf15('0x52'),_0x3c81ae[_0xbf15('0x6c')]['filename']);var _0x2ee873=path[_0xbf15('0x5e')](config['root'],_0xbf15('0x52'),_0x1c9023);logger[_0xbf15('0x68')](_0xbf15('0x6e'),_0x1c304e);logger[_0xbf15('0x68')](_0xbf15('0x6f'),_0x2ee873);try{fs[_0xbf15('0x70')](_0x1c304e,parseInt(_0xbf15('0x71'),0x8));extract(_0x1c304e,{'dir':_0x2ee873},function(_0x136d4f){if(_0x136d4f){logger['error'](_0x136d4f);handleError(_0x136d4f,!![]);};var _0x5789b0=fs['readdirSync'](_0x2ee873);if(_0x5789b0[_0xbf15('0x4e')]>0x1){removeReferences(_0x1c304e,_0x2ee873);logger[_0xbf15('0x2f')]('Invalid\x20plugin\x20structure');return _0x38a01d(new Error(_0xbf15('0x72')));}var _0x2ed81f=fs[_0xbf15('0x73')](path['join'](_0x2ee873,_0x5789b0[0x0]));if(_0x2ed81f[_0xbf15('0x74')]()){removeReferences(_0x1c304e,_0x2ee873);logger['error'](_0xbf15('0x72'));return _0x38a01d(new Error(_0xbf15('0x72')));}if(_0x2ed81f[_0xbf15('0x75')]()){var _0x37c8da=fs[_0xbf15('0x76')](path[_0xbf15('0x5e')](_0x2ee873,_0x5789b0[0x0]));if(_0x37c8da[_0xbf15('0x4e')]===0x0){removeReferences(_0x1c304e,_0x2ee873);logger[_0xbf15('0x2f')](_0xbf15('0x72'));return _0x38a01d(new Error(_0xbf15('0x72')));}var _0x9c6955=_0x37c8da[_0xbf15('0x77')](function(_0x252175){return _0x252175===_0xbf15('0x78');});if(!_0x9c6955){return _0x38a01d(new Error(_0xbf15('0x79')));}var _0x4fe81f=fs['readFileSync'](path[_0xbf15('0x5e')](_0x2ee873,_0x5789b0[0x0],'manifest.json'));var _0x16f260=JSON[_0xbf15('0x7a')](_0x4fe81f);if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x31')]){return _0x38a01d(new Error(_0xbf15('0x7c')));}if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x36')]){return _0x38a01d(new Error('Invalid\x20manifest:\x20type\x20missing'));}if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7d')]){return _0x38a01d(new Error(_0xbf15('0x7e')));}if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7f')]){return _0x38a01d(new Error(_0xbf15('0x80')));}if(_0x16f260[_0xbf15('0x36')]===_0xbf15('0x81')){if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')]){return _0x38a01d(new Error('Invalid\x20manifest:\x20views\x20missing'));}if('undefined'==typeof _0x16f260['parameters'][_0xbf15('0x82')]['admin']&&_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')]['agent']){return _0x38a01d(new Error('Invalid\x20manifest:\x20no\x20view\x20specified'));}}else if(_0x16f260[_0xbf15('0x36')]===_0xbf15('0x83')){if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x84')]){return _0x38a01d(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0xbf15('0x7b')==typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x85')]){return _0x38a01d(new Error(_0xbf15('0x86')));}}else{return _0x38a01d(new Error(_0xbf15('0x87')));}var _0x39624f=_0x16f260[_0xbf15('0x31')];var _0x224d4c=_0x16f260['description'];var _0x527b6e=_0x16f260[_0xbf15('0x36')];var _0xd862d7=_0x16f260[_0xbf15('0x88')]?_0x16f260['sidebar']:'always';var _0x142450=_0x16f260['icon']?_0x16f260['icon']:_0xbf15('0x89');var _0x25e9ea='';var _0x5454bf='';var _0x13e4b5='';var _0x416169='';var _0x4cde49=_0x16f260[_0xbf15('0x7d')];if(_0x527b6e===_0xbf15('0x81')){if(_0xbf15('0x7b')!=typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')]['admin']){var _0x560823=_0x16f260[_0xbf15('0x7f')]['views'][_0xbf15('0x8a')];if(!/^(f|ht)tps?:\/\//i[_0xbf15('0x8b')](_0x560823)){_0x25e9ea=path[_0xbf15('0x5e')]('plugins',_0x1c9023,_0x5789b0[0x0],_0x560823);}else{_0x25e9ea=_0x560823;}}else{logger[_0xbf15('0x68')]('Warning:\x20admin\x20view\x20not\x20specified');}if('undefined'!=typeof _0x16f260[_0xbf15('0x7f')]['views']['agent']){var _0x56a236=_0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0xbf15('0x8b')](_0x56a236)){_0x5454bf=path[_0xbf15('0x5e')](_0xbf15('0x8c'),_0x1c9023,_0x5789b0[0x0],_0x56a236);}else{_0x5454bf=_0x56a236;}}else{logger['info'](_0xbf15('0x8d'));}}else if(_0x527b6e===_0xbf15('0x83')){_0x13e4b5=_0x16f260[_0xbf15('0x7f')][_0xbf15('0x84')];_0x416169=_0x16f260[_0xbf15('0x7f')][_0xbf15('0x85')];if('undefined'!=typeof _0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')]){if(_0xbf15('0x7b')!=typeof _0x16f260['parameters'][_0xbf15('0x82')][_0xbf15('0x8a')]){var _0x560823=_0x16f260[_0xbf15('0x7f')][_0xbf15('0x82')][_0xbf15('0x8a')];if(!/^(f|ht)tps?:\/\//i[_0xbf15('0x8b')](_0x560823)){_0x25e9ea=path['join']('plugins',_0x1c9023,_0x5789b0[0x0],_0x560823);}else{_0x25e9ea=_0x560823;}}if(_0xbf15('0x7b')!=typeof _0x16f260[_0xbf15('0x7f')]['views'][_0xbf15('0x8e')]){var _0x56a236=_0x16f260['parameters'][_0xbf15('0x82')][_0xbf15('0x8e')];if(!/^(f|ht)tps?:\/\//i[_0xbf15('0x8b')](_0x56a236)){_0x5454bf=path[_0xbf15('0x5e')]('plugins',_0x1c9023,_0x5789b0[0x0],_0x56a236);}else{_0x5454bf=_0x56a236;}}}}var _0x1c0350={'name':_0x39624f,'description':_0x224d4c,'path':path[_0xbf15('0x5e')](_0x1c9023,_0x5789b0[0x0]),'type':_0x527b6e,'sidebar':_0xd862d7,'icon':_0x142450,'adminUrl':_0x25e9ea,'agentUrl':_0x5454bf,'scriptName':_0x13e4b5,'scriptPath':_0x416169,'version':_0x4cde49};removeReferences(_0x1c304e,null);return db[_0xbf15('0x44')][_0xbf15('0x8f')](_0x1c0350)[_0xbf15('0x2b')](function(_0x34cb05){var _0x104c29={'role':_0x3c81ae[_0xbf15('0x90')][_0xbf15('0x91')],'userProfileId':_0x3c81ae[_0xbf15('0x90')][_0xbf15('0x92')]};if(!_0x104c29)throw new Error(_0xbf15('0x93'));if(_0x104c29[_0xbf15('0x91')]===_0xbf15('0x94')){var _0x3ae5e6=_0x34cb05['get']({'plain':!![]});return db[_0xbf15('0x95')][_0xbf15('0x4f')]({'where':{'name':_0xbf15('0x2e'),'userProfileId':_0x104c29[_0xbf15('0x92')]},'raw':!![]})[_0xbf15('0x2b')](function(_0x1b003e){if(_0x1b003e&&_0x1b003e[_0xbf15('0x96')]===0x0){return db['UserProfileResource'][_0xbf15('0x8f')]({'name':_0x3ae5e6[_0xbf15('0x31')],'resourceId':_0x3ae5e6['id'],'type':_0x1b003e[_0xbf15('0x31')],'sectionId':_0x1b003e['id']},{})['then'](function(){return _0x34cb05;});}else{return _0x34cb05;}})[_0xbf15('0x4a')](function(_0x4cc6f5){logger[_0xbf15('0x2f')](_0xbf15('0x97'),_0x4cc6f5);throw _0x4cc6f5;});}return _0x34cb05;})[_0xbf15('0x2b')](respondWithResult(_0x33ddd7,null))['catch'](handleError(_0x33ddd7,null));}});}catch(_0x1d55a7){_0x33ddd7[_0xbf15('0x23')](0x1f4)[_0xbf15('0x32')](_0x1d55a7);}};function removeReferences(_0x371ae9,_0x4584ec){try{if(_0x371ae9){fs[_0xbf15('0x67')](_0x371ae9);logger[_0xbf15('0x68')](_0xbf15('0x98'));}if(_0x4584ec){rimraf(_0x4584ec,function(){});logger['info'](_0xbf15('0x99'));}}catch(_0x2d49b6){logger[_0xbf15('0x2f')](_0x2d49b6);}}exports['update']=function(_0xca8eb2,_0x34778d,_0x38c482){return db[_0xbf15('0x44')]['find']({'where':{'id':_0xca8eb2[_0xbf15('0x4c')]['id']}})[_0xbf15('0x2b')](handleEntityNotFound(_0x34778d,null))[_0xbf15('0x2b')](saveUpdates(_0xca8eb2[_0xbf15('0x90')],null))[_0xbf15('0x2b')](respondWithResult(_0x34778d,null))[_0xbf15('0x4a')](handleError(_0x34778d,null));};exports[_0xbf15('0x9a')]=function(_0x1fff0f,_0x53321a,_0x5f452a){return db[_0xbf15('0x44')]['find']({'where':{'id':_0x1fff0f[_0xbf15('0x4c')]['id']}})[_0xbf15('0x2b')](function(_0x3e0bc9){if(_0x3e0bc9){return _0x3e0bc9[_0xbf15('0x2c')]();}})['then'](function(_0x385b32){rimraf(path['join'](config[_0xbf15('0x51')],'server/files/plugins',path[_0xbf15('0x9b')](_0x385b32['path'])),function(){});return _0x385b32;})[_0xbf15('0x2b')](handleEntityNotFound(_0x53321a,null))[_0xbf15('0x2b')](respondWithStatusCode(_0x53321a,null))['catch'](handleError(_0x53321a,null));};exports[_0xbf15('0x9c')]=function(_0x27e928,_0x5a0ef6,_0x32d07a){return BPromise['resolve']()[_0xbf15('0x2b')](function(){if(!_0x27e928[_0xbf15('0x39')][_0xbf15('0x7')]){throw new Error(_0xbf15('0x9d'));}if(!_0x27e928['query']['port']){throw new Error(_0xbf15('0x9e'));}var _0x468369=_0x27e928[_0xbf15('0x39')][_0xbf15('0x9f')]?_0x27e928[_0xbf15('0x39')][_0xbf15('0x9f')]+':'+_0x27e928['query']['port']:_0xbf15('0xa0')+_0x27e928[_0xbf15('0x39')][_0xbf15('0xa1')];var _0x456a43=_0x27e928[_0xbf15('0x39')][_0xbf15('0x25')]?_0x27e928[_0xbf15('0x39')][_0xbf15('0x25')]:!![];var _0x57646c=_0x27e928[_0xbf15('0x39')][_0xbf15('0xa2')]?_0x27e928[_0xbf15('0x39')][_0xbf15('0xa2')]:null;var _0xbf406d={'method':_0x27e928[_0xbf15('0xa3')],'uri':util[_0xbf15('0x53')]('%s%s',_0x468369,_0x27e928[_0xbf15('0x39')][_0xbf15('0x7')]),'json':_0x456a43,'resolveWithFullResponse':!![],'encoding':_0x57646c,'qs':_0x27e928[_0xbf15('0x39')]};if(_0x27e928[_0xbf15('0xa4')]){_0xbf406d[_0xbf15('0xa4')]=_0x27e928['headers'];if(_0xbf406d[_0xbf15('0xa4')][_0xbf15('0xa5')]){delete _0xbf406d[_0xbf15('0xa4')][_0xbf15('0xa5')];}}if(_0xbf406d['headers'][_0xbf15('0xa6')]){delete _0xbf406d[_0xbf15('0xa4')][_0xbf15('0xa6')];}return rp(_0xbf406d);})[_0xbf15('0x2b')](function(_0x549162){if(_0x549162){_0x5a0ef6[_0xbf15('0x28')](_0x549162['headers']);logger[_0xbf15('0x68')](_0x549162[_0xbf15('0x90')]);if(_[_0xbf15('0xa7')](_0x27e928[_0xbf15('0x39')][_0xbf15('0x7')],_0xbf15('0x50'))&&_0x549162['statusCode']==0x1f4){return _0x5a0ef6[_0xbf15('0x22')](_0x549162[_0xbf15('0xa8')]);}else{return _0x5a0ef6[_0xbf15('0x23')](_0x549162['statusCode'])[_0xbf15('0x32')](_0x549162[_0xbf15('0x90')]);}}else{return _0x5a0ef6[_0xbf15('0x22')](0xc8);}})[_0xbf15('0x4a')](handleError(_0x5a0ef6,null));};exports[_0xbf15('0xa9')]=function(_0x1d8f6b,_0xe3ec56,_0x4b4f2a){return BPromise[_0xbf15('0xaa')]()[_0xbf15('0x2b')](function(){if(!_0x1d8f6b[_0xbf15('0x39')][_0xbf15('0x7')]){throw new Error(_0xbf15('0x9d'));}if(!_0x1d8f6b[_0xbf15('0x39')][_0xbf15('0xa1')]){throw new Error(_0xbf15('0x9e'));}var _0x3920c7=_0x1d8f6b[_0xbf15('0x39')][_0xbf15('0x9f')]?_0x1d8f6b['query'][_0xbf15('0x9f')]+':'+_0x1d8f6b['query'][_0xbf15('0xa1')]:_0xbf15('0xa0')+_0x1d8f6b[_0xbf15('0x39')]['port'];var _0x441e7a=_0x1d8f6b['query']['json']?_0x1d8f6b[_0xbf15('0x39')]['json']:!![];var _0x156542=_0x1d8f6b[_0xbf15('0x39')][_0xbf15('0xa2')]?_0x1d8f6b[_0xbf15('0x39')]['encoding']:null;var _0x20fbe3={'method':_0x1d8f6b[_0xbf15('0xa3')],'uri':util[_0xbf15('0x53')]('%s%s',_0x3920c7,_0x1d8f6b[_0xbf15('0x39')]['path']),'json':_0x441e7a,'resolveWithFullResponse':!![],'encoding':_0x156542,'body':_0x1d8f6b['body']};if(_0x1d8f6b['headers']){_0x20fbe3['headers']=_0x1d8f6b[_0xbf15('0xa4')];if(_0x20fbe3[_0xbf15('0xa4')][_0xbf15('0xa5')]){delete _0x20fbe3['headers'][_0xbf15('0xa5')];}}if(_0x20fbe3[_0xbf15('0xa4')][_0xbf15('0xa6')]){delete _0x20fbe3[_0xbf15('0xa4')][_0xbf15('0xa6')];}return rp(_0x20fbe3);})[_0xbf15('0x2b')](function(_0x2a289a){if(_0x2a289a){_0xe3ec56[_0xbf15('0x28')](_0x2a289a[_0xbf15('0xa4')]);logger[_0xbf15('0x68')](_0x2a289a['body']);return _0xe3ec56['status'](_0x2a289a[_0xbf15('0xa8')])[_0xbf15('0x32')](_0x2a289a[_0xbf15('0x90')]);}else{return _0xe3ec56['sendStatus'](0xc8);}})['catch'](handleError(_0xe3ec56,null));};