34a3e8c0de9cccc69c219bc7949838508b8b4e43
[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 _0x527e=['Invalid\x20manifest:\x20script\x20path\x20missing','description','sidebar','icon','icon-apps','version','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','Warning:\x20agent\x20view\x20not\x20specified','scriptPath','create','body','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','params','delete','webhookGet','port','hostname','http://localhost:','encoding','method','%s%s','headers','content-length','content-type','set','endsWith','statusCode','webhookPost','\x27PATH\x27\x20parameter\x20not\x20specified','\x27PORT\x27\x20parameter\x20not\x20specified','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','to-csv','lodash','crypto','jsforce','desk.js','querystring','papaparse','extract-zip','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./plugin.socket','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','get','Plugins','UserProfileResource','destroy','error','stack','name','send','index','map','Plugin','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','then','includeAll','include','findAll','rows','catch','options','find','download','join','root','server/files/plugins','format','%s.zip','basename','path','createWriteStream','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','glob','**/*','dirname','node_modules/**/*','attachments/**/*','finalize','existsSync','Plugin\x20not\x20found','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Temporary\x20file\x20removed','file','filename','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','isDirectory','some','manifest.json','Plugin\x20manifest\x20missing','readFileSync','undefined','Invalid\x20manifest:\x20name\x20missing','parameters','html','views','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','script','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing'];(function(_0x304aca,_0x4f8e0b){var _0x3b811c=function(_0x3f6c71){while(--_0x3f6c71){_0x304aca['push'](_0x304aca['shift']());}};_0x3b811c(++_0x4f8e0b);}(_0x527e,0xd2));var _0xe527=function(_0x1286a0,_0x27eff2){_0x1286a0=_0x1286a0-0x0;var _0x3efaf4=_0x527e[_0x1286a0];return _0x3efaf4;};'use strict';var pdf=require(_0xe527('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xe527('0x1'));var zipdir=require(_0xe527('0x2'));var jsonpatch=require(_0xe527('0x3'));var rp=require(_0xe527('0x4'));var moment=require('moment');var BPromise=require(_0xe527('0x5'));var Mustache=require(_0xe527('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0xe527('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xe527('0x8'));var squel=require('squel');var crypto=require(_0xe527('0x9'));var jsforce=require(_0xe527('0xa'));var deskjs=require(_0xe527('0xb'));var toCsv=require('to-csv');var querystring=require(_0xe527('0xc'));var Papa=require(_0xe527('0xd'));var extract=require(_0xe527('0xe'));var rimraf=require(_0xe527('0x1'));var archiver=require('archiver');var Redis=require(_0xe527('0xf'));var authService=require(_0xe527('0x10'));var qs=require(_0xe527('0x11'));var as=require(_0xe527('0x12'));var hardwareService=require(_0xe527('0x13'));var logger=require(_0xe527('0x14'))(_0xe527('0x15'));var utils=require(_0xe527('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xe527('0x17'));var db=require(_0xe527('0x18'))['db'];config['redis']=_[_0xe527('0x19')](config[_0xe527('0x1a')],{'host':_0xe527('0x1b'),'port':0x18eb});var socket=require(_0xe527('0x1c'))(new Redis(config['redis']));require(_0xe527('0x1d'))['register'](socket);function respondWithStatusCode(_0x3254de,_0x246715){_0x246715=_0x246715||0xcc;return function(_0x457a0e){if(_0x457a0e){return _0x3254de[_0xe527('0x1e')](_0x246715);}return _0x3254de[_0xe527('0x1f')](_0x246715)[_0xe527('0x20')]();};}function respondWithResult(_0xfb9184,_0x2bc166){_0x2bc166=_0x2bc166||0xc8;return function(_0x137ef6){if(_0x137ef6){return _0xfb9184[_0xe527('0x1f')](_0x2bc166)[_0xe527('0x21')](_0x137ef6);}};}function respondWithFilteredResult(_0x1efa48,_0x41d553){return function(_0x485e51){if(_0x485e51){var _0x20143c=_0x485e51[_0xe527('0x22')],_0x16e7c9=_0x41d553[_0xe527('0x23')],_0x3028fe=_0x41d553[_0xe527('0x23')]+_0x41d553[_0xe527('0x24')],_0x1387f5;if(_0x3028fe>=_0x20143c){_0x3028fe=_0x20143c;_0x1387f5=0xc8;}else{_0x1387f5=0xce;}_0x1efa48['status'](_0x1387f5);return _0x1efa48['set'](_0xe527('0x25'),_0x16e7c9+'-'+_0x3028fe+'/'+_0x20143c)[_0xe527('0x21')](_0x485e51);}return null;};}function patchUpdates(_0x471e35){return function(_0x418ec8){try{jsonpatch[_0xe527('0x26')](_0x418ec8,_0x471e35,!![]);}catch(_0x42540e){return BPromise[_0xe527('0x27')](_0x42540e);}return _0x418ec8['save']();};}function saveUpdates(_0x4b6a85,_0x107152){return function(_0x51f10f){if(_0x51f10f){return _0x51f10f['update'](_0x4b6a85)['then'](function(_0x4a1546){return _0x4a1546;});}return null;};}function removeEntity(_0x811487,_0x98a7ae){return function(_0x40837b){if(_0x40837b){return _0x40837b['destroy']()['then'](function(){var _0x5abc49=_0x40837b[_0xe527('0x28')]({'plain':!![]});var _0x50e27d=_0xe527('0x29');return db[_0xe527('0x2a')][_0xe527('0x2b')]({'where':{'type':_0x50e27d,'resourceId':_0x5abc49['id']}})['then'](function(){return _0x40837b;});})['then'](function(){_0x811487['status'](0xcc)[_0xe527('0x20')]();});}};}function handleEntityNotFound(_0x3042c9,_0x5647f4){return function(_0x3c13ec){if(!_0x3c13ec){_0x3042c9[_0xe527('0x1e')](0x194);}return _0x3c13ec;};}function handleError(_0x1e5f8d,_0x963daf){_0x963daf=_0x963daf||0x1f4;return function(_0x154d56){logger[_0xe527('0x2c')](_0x154d56[_0xe527('0x2d')]);if(_0x154d56['name']){delete _0x154d56[_0xe527('0x2e')];}_0x1e5f8d['status'](_0x963daf)[_0xe527('0x2f')](_0x154d56);};}exports[_0xe527('0x30')]=function(_0x341e36,_0x8caa2e){var _0x469884={},_0x2825f9={},_0x2abc98={'count':0x0,'rows':[]};var _0x396a42=_[_0xe527('0x31')](db[_0xe527('0x32')][_0xe527('0x33')],function(_0x427fdf){return{'name':_0x427fdf[_0xe527('0x34')],'type':_0x427fdf[_0xe527('0x35')][_0xe527('0x36')]};});_0x2825f9[_0xe527('0x37')]=_['map'](_0x396a42,_0xe527('0x2e'));_0x2825f9[_0xe527('0x38')]=_[_0xe527('0x39')](_0x341e36[_0xe527('0x38')]);_0x2825f9[_0xe527('0x3a')]=_[_0xe527('0x3b')](_0x2825f9['model'],_0x2825f9[_0xe527('0x38')]);_0x469884[_0xe527('0x3c')]=_[_0xe527('0x3b')](_0x2825f9[_0xe527('0x37')],qs[_0xe527('0x3d')](_0x341e36['query'][_0xe527('0x3d')]));_0x469884[_0xe527('0x3c')]=_0x469884[_0xe527('0x3c')][_0xe527('0x3e')]?_0x469884['attributes']:_0x2825f9['model'];if(!_0x341e36[_0xe527('0x38')][_0xe527('0x3f')](_0xe527('0x40'))){_0x469884[_0xe527('0x24')]=qs['limit'](_0x341e36[_0xe527('0x38')][_0xe527('0x24')]);_0x469884[_0xe527('0x23')]=qs[_0xe527('0x23')](_0x341e36['query']['offset']);}_0x469884[_0xe527('0x41')]=qs[_0xe527('0x42')](_0x341e36['query'][_0xe527('0x42')]);_0x469884[_0xe527('0x43')]=qs['filters'](_[_0xe527('0x44')](_0x341e36[_0xe527('0x38')],_0x2825f9[_0xe527('0x3a')]),_0x396a42);if(_0x341e36[_0xe527('0x38')][_0xe527('0x45')]){_0x469884[_0xe527('0x43')]=_[_0xe527('0x46')](_0x469884[_0xe527('0x43')],{'$or':_[_0xe527('0x31')](_0x396a42,function(_0x2ee39f){if(_0x2ee39f[_0xe527('0x35')]!==_0xe527('0x47')){var _0x49b133={};_0x49b133[_0x2ee39f[_0xe527('0x2e')]]={'$like':'%'+_0x341e36[_0xe527('0x38')]['filter']+'%'};return _0x49b133;}})});}_0x469884=_['merge']({},_0x469884,_0x341e36['options']);var _0x1e8737={'where':_0x469884['where']};return db[_0xe527('0x32')][_0xe527('0x22')](_0x1e8737)[_0xe527('0x48')](function(_0x5a53b5){_0x2abc98[_0xe527('0x22')]=_0x5a53b5;if(_0x341e36['query'][_0xe527('0x49')]){_0x469884[_0xe527('0x4a')]=[{'all':!![]}];}return db[_0xe527('0x32')][_0xe527('0x4b')](_0x469884);})[_0xe527('0x48')](function(_0x937066){_0x2abc98[_0xe527('0x4c')]=_0x937066;return _0x2abc98;})['then'](respondWithFilteredResult(_0x8caa2e,_0x469884))[_0xe527('0x4d')](handleError(_0x8caa2e,null));};exports['show']=function(_0x440c4a,_0x321d5e){var _0x54d7aa={'raw':!![],'where':{'id':_0x440c4a['params']['id']}},_0x52c0c7={};_0x52c0c7[_0xe527('0x37')]=_['keys'](db[_0xe527('0x32')][_0xe527('0x33')]);_0x52c0c7[_0xe527('0x38')]=_['keys'](_0x440c4a[_0xe527('0x38')]);_0x52c0c7['filters']=_[_0xe527('0x3b')](_0x52c0c7[_0xe527('0x37')],_0x52c0c7[_0xe527('0x38')]);_0x54d7aa[_0xe527('0x3c')]=_[_0xe527('0x3b')](_0x52c0c7[_0xe527('0x37')],qs[_0xe527('0x3d')](_0x440c4a[_0xe527('0x38')][_0xe527('0x3d')]));_0x54d7aa[_0xe527('0x3c')]=_0x54d7aa[_0xe527('0x3c')][_0xe527('0x3e')]?_0x54d7aa[_0xe527('0x3c')]:_0x52c0c7['model'];if(_0x440c4a[_0xe527('0x38')][_0xe527('0x49')]){_0x54d7aa['include']=[{'all':!![]}];}_0x54d7aa=_[_0xe527('0x46')]({},_0x54d7aa,_0x440c4a[_0xe527('0x4e')]);return db['Plugin'][_0xe527('0x4f')](_0x54d7aa)[_0xe527('0x48')](handleEntityNotFound(_0x321d5e,null))[_0xe527('0x48')](respondWithResult(_0x321d5e,null))[_0xe527('0x4d')](handleError(_0x321d5e,null));};exports[_0xe527('0x50')]=function(_0x447316,_0x416b79,_0x125ed7){return db['Plugin'][_0xe527('0x4f')]({'where':{'id':_0x447316['params']['id']},'attributes':[_0xe527('0x2e'),'path'],'raw':!![]})[_0xe527('0x48')](handleEntityNotFound(_0x416b79,null))[_0xe527('0x48')](function(_0x1c45ec){if(_0x1c45ec){var _0x161557=path[_0xe527('0x51')](config[_0xe527('0x52')],_0xe527('0x53'),util[_0xe527('0x54')](_0xe527('0x55'),path[_0xe527('0x56')](_0x1c45ec[_0xe527('0x57')])));var _0x54c8be=fs[_0xe527('0x58')](_0x161557);var _0x5d0caa=archiver('zip',{'zlib':{'level':0x9}});_0x5d0caa['on']('warning',function(_0x2d06dc){if(_0x2d06dc[_0xe527('0x59')]===_0xe527('0x5a')){logger[_0xe527('0x2c')](_0x2d06dc);}else{throw new db[(_0xe527('0x5b'))][(_0xe527('0x5c'))](_0xe527('0x5d'));}});_0x5d0caa['on'](_0xe527('0x2c'),function(_0x1f20e5){throw new db['Sequelize'][(_0xe527('0x5c'))](_0xe527('0x5d'));});_0x5d0caa['pipe'](_0x54c8be);_0x5d0caa[_0xe527('0x5e')](_0xe527('0x5f'),{'cwd':path['join'](config[_0xe527('0x52')],_0xe527('0x53'),path[_0xe527('0x60')](_0x1c45ec[_0xe527('0x57')])),'ignore':[path[_0xe527('0x51')](path[_0xe527('0x56')](_0x1c45ec['path']),_0xe527('0x61')),path['join'](path[_0xe527('0x56')](_0x1c45ec[_0xe527('0x57')]),_0xe527('0x62'))],'nodir':!![]})[_0xe527('0x63')]();_0x54c8be['on']('close',function(){if(!fs[_0xe527('0x64')](_0x161557)){throw new db['Sequelize'][(_0xe527('0x5c'))](_0xe527('0x65'));}return _0x416b79[_0xe527('0x50')](_0x161557,util['format'](_0xe527('0x55'),path['basename'](_0x1c45ec['path'])),function(_0x39fde9){if(_0x39fde9){throw new db[(_0xe527('0x5b'))][(_0xe527('0x5c'))](_0xe527('0x66'));}fs[_0xe527('0x67')](_0x161557);logger[_0xe527('0x68')]('Download\x20completed');logger[_0xe527('0x68')](_0xe527('0x69'));});});}return null;})[_0xe527('0x4d')](handleError(_0x416b79,null));};exports['upload']=function(_0x1a9779,_0x10f2cf,_0x1dd723){var _0x390ae9=path[_0xe527('0x56')](_0x1a9779[_0xe527('0x6a')][_0xe527('0x6b')],path['extname'](_0x1a9779[_0xe527('0x6a')][_0xe527('0x6b')]));var _0x1d680e=path[_0xe527('0x51')](config[_0xe527('0x52')],_0xe527('0x53'),_0x1a9779['file'][_0xe527('0x6b')]);var _0x44dc60=path['join'](config[_0xe527('0x52')],_0xe527('0x53'),_0x390ae9);logger[_0xe527('0x68')](_0xe527('0x6c'),_0x1d680e);logger[_0xe527('0x68')](_0xe527('0x6d'),_0x44dc60);try{fs[_0xe527('0x6e')](_0x1d680e,parseInt('0777',0x8));extract(_0x1d680e,{'dir':_0x44dc60},function(_0x297bcc){if(_0x297bcc){logger[_0xe527('0x2c')](_0x297bcc);handleError(_0x297bcc,!![]);};var _0x3069b2=fs[_0xe527('0x6f')](_0x44dc60);if(_0x3069b2[_0xe527('0x3e')]>0x1){removeReferences(_0x1d680e,_0x44dc60);logger[_0xe527('0x2c')]('Invalid\x20plugin\x20structure');return _0x1dd723(new Error(_0xe527('0x70')));}var _0x1a6721=fs[_0xe527('0x71')](path['join'](_0x44dc60,_0x3069b2[0x0]));if(_0x1a6721[_0xe527('0x72')]()){removeReferences(_0x1d680e,_0x44dc60);logger['error'](_0xe527('0x70'));return _0x1dd723(new Error(_0xe527('0x70')));}if(_0x1a6721[_0xe527('0x73')]()){var _0x4b8a95=fs[_0xe527('0x6f')](path[_0xe527('0x51')](_0x44dc60,_0x3069b2[0x0]));if(_0x4b8a95[_0xe527('0x3e')]===0x0){removeReferences(_0x1d680e,_0x44dc60);logger[_0xe527('0x2c')](_0xe527('0x70'));return _0x1dd723(new Error(_0xe527('0x70')));}var _0x68e861=_0x4b8a95[_0xe527('0x74')](function(_0x3a6155){return _0x3a6155===_0xe527('0x75');});if(!_0x68e861){return _0x1dd723(new Error(_0xe527('0x76')));}var _0x2adab2=fs[_0xe527('0x77')](path[_0xe527('0x51')](_0x44dc60,_0x3069b2[0x0],'manifest.json'));var _0x506f48=JSON['parse'](_0x2adab2);if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x2e')]){return _0x1dd723(new Error(_0xe527('0x79')));}if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x35')]){return _0x1dd723(new Error('Invalid\x20manifest:\x20type\x20missing'));}if('undefined'==typeof _0x506f48['version']){return _0x1dd723(new Error('Invalid\x20manifest:\x20version\x20not\x20specified'));}if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x7a')]){return _0x1dd723(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x506f48['type']===_0xe527('0x7b')){if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x7c')]){return _0x1dd723(new Error(_0xe527('0x7d')));}if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x7c')][_0xe527('0x7e')]&&'undefined'==typeof _0x506f48['parameters']['views'][_0xe527('0x7f')]){return _0x1dd723(new Error(_0xe527('0x80')));}}else if(_0x506f48[_0xe527('0x35')]===_0xe527('0x81')){if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x82')]){return _0x1dd723(new Error(_0xe527('0x83')));}if(_0xe527('0x78')==typeof _0x506f48[_0xe527('0x7a')]['scriptPath']){return _0x1dd723(new Error(_0xe527('0x84')));}}else{return _0x1dd723(new Error('Invalid\x20manifest:\x20invalid\x20type'));}var _0x3629f2=_0x506f48[_0xe527('0x2e')];var _0x195649=_0x506f48[_0xe527('0x85')];var _0x403ebf=_0x506f48[_0xe527('0x35')];var _0x343eef=_0x506f48[_0xe527('0x86')]?_0x506f48['sidebar']:'always';var _0x437d4f=_0x506f48[_0xe527('0x87')]?_0x506f48[_0xe527('0x87')]:_0xe527('0x88');var _0x4907f9='';var _0xbbd88='';var _0x26c2bf='';var _0x10bfcd='';var _0x3a1bf5=_0x506f48[_0xe527('0x89')];if(_0x403ebf===_0xe527('0x7b')){if(_0xe527('0x78')!=typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x7c')][_0xe527('0x7e')]){var _0x378cc4=_0x506f48['parameters'][_0xe527('0x7c')][_0xe527('0x7e')];if(!/^(f|ht)tps?:\/\//i[_0xe527('0x8a')](_0x378cc4)){_0x4907f9=path['join'](_0xe527('0x8b'),_0x390ae9,_0x3069b2[0x0],_0x378cc4);}else{_0x4907f9=_0x378cc4;}}else{logger[_0xe527('0x68')](_0xe527('0x8c'));}if(_0xe527('0x78')!=typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x7c')][_0xe527('0x7f')]){var _0x2dbeb1=_0x506f48[_0xe527('0x7a')][_0xe527('0x7c')][_0xe527('0x7f')];if(!/^(f|ht)tps?:\/\//i[_0xe527('0x8a')](_0x2dbeb1)){_0xbbd88=path[_0xe527('0x51')]('plugins',_0x390ae9,_0x3069b2[0x0],_0x2dbeb1);}else{_0xbbd88=_0x2dbeb1;}}else{logger['info'](_0xe527('0x8d'));}}else if(_0x403ebf===_0xe527('0x81')){_0x26c2bf=_0x506f48['parameters'][_0xe527('0x82')];_0x10bfcd=_0x506f48[_0xe527('0x7a')][_0xe527('0x8e')];if(_0xe527('0x78')!=typeof _0x506f48['parameters'][_0xe527('0x7c')]){if(_0xe527('0x78')!=typeof _0x506f48[_0xe527('0x7a')]['views'][_0xe527('0x7e')]){var _0x378cc4=_0x506f48[_0xe527('0x7a')][_0xe527('0x7c')][_0xe527('0x7e')];if(!/^(f|ht)tps?:\/\//i[_0xe527('0x8a')](_0x378cc4)){_0x4907f9=path[_0xe527('0x51')](_0xe527('0x8b'),_0x390ae9,_0x3069b2[0x0],_0x378cc4);}else{_0x4907f9=_0x378cc4;}}if(_0xe527('0x78')!=typeof _0x506f48[_0xe527('0x7a')][_0xe527('0x7c')]['agent']){var _0x2dbeb1=_0x506f48[_0xe527('0x7a')]['views']['agent'];if(!/^(f|ht)tps?:\/\//i[_0xe527('0x8a')](_0x2dbeb1)){_0xbbd88=path['join'](_0xe527('0x8b'),_0x390ae9,_0x3069b2[0x0],_0x2dbeb1);}else{_0xbbd88=_0x2dbeb1;}}}}var _0x4fd115={'name':_0x3629f2,'description':_0x195649,'path':path['join'](_0x390ae9,_0x3069b2[0x0]),'type':_0x403ebf,'sidebar':_0x343eef,'icon':_0x437d4f,'adminUrl':_0x4907f9,'agentUrl':_0xbbd88,'scriptName':_0x26c2bf,'scriptPath':_0x10bfcd,'version':_0x3a1bf5};removeReferences(_0x1d680e,null);return db['Plugin'][_0xe527('0x8f')](_0x4fd115)[_0xe527('0x48')](function(_0x711a8a){var _0x588ec1={'role':_0x1a9779[_0xe527('0x90')]['role'],'userProfileId':_0x1a9779[_0xe527('0x90')][_0xe527('0x91')]};if(!_0x588ec1)throw new Error(_0xe527('0x92'));if(_0x588ec1[_0xe527('0x93')]===_0xe527('0x94')){var _0x4b796f=_0x711a8a[_0xe527('0x28')]({'plain':!![]});return db['UserProfileSection'][_0xe527('0x4f')]({'where':{'name':_0xe527('0x29'),'userProfileId':_0x588ec1['userProfileId']},'raw':!![]})[_0xe527('0x48')](function(_0x11f86a){if(_0x11f86a&&_0x11f86a[_0xe527('0x95')]===0x0){return db[_0xe527('0x2a')][_0xe527('0x8f')]({'name':_0x4b796f[_0xe527('0x2e')],'resourceId':_0x4b796f['id'],'type':_0x11f86a[_0xe527('0x2e')],'sectionId':_0x11f86a['id']},{})[_0xe527('0x48')](function(){return _0x711a8a;});}else{return _0x711a8a;}})[_0xe527('0x4d')](function(_0x19ac5c){logger[_0xe527('0x2c')](_0xe527('0x96'),_0x19ac5c);throw _0x19ac5c;});}return _0x711a8a;})['then'](respondWithResult(_0x10f2cf,null))[_0xe527('0x4d')](handleError(_0x10f2cf,null));}});}catch(_0x273f8c){_0x10f2cf[_0xe527('0x1f')](0x1f4)[_0xe527('0x2f')](_0x273f8c);}};function removeReferences(_0x5df6f5,_0x34a898){try{if(_0x5df6f5){fs[_0xe527('0x67')](_0x5df6f5);logger['info'](_0xe527('0x97'));}if(_0x34a898){rimraf(_0x34a898,function(){});logger[_0xe527('0x68')](_0xe527('0x98'));}}catch(_0x19def9){logger[_0xe527('0x2c')](_0x19def9);}}exports['update']=function(_0x2beb6e,_0xfc9e03,_0x2f4800){return db[_0xe527('0x32')][_0xe527('0x4f')]({'where':{'id':_0x2beb6e[_0xe527('0x99')]['id']}})['then'](handleEntityNotFound(_0xfc9e03,null))[_0xe527('0x48')](saveUpdates(_0x2beb6e[_0xe527('0x90')],null))['then'](respondWithResult(_0xfc9e03,null))[_0xe527('0x4d')](handleError(_0xfc9e03,null));};exports[_0xe527('0x9a')]=function(_0x7e44d9,_0x13429f,_0x4dc4a4){return db[_0xe527('0x32')][_0xe527('0x4f')]({'where':{'id':_0x7e44d9[_0xe527('0x99')]['id']}})['then'](function(_0x4a46b8){if(_0x4a46b8){return _0x4a46b8[_0xe527('0x2b')]();}})[_0xe527('0x48')](function(_0x5e788c){rimraf(path[_0xe527('0x51')](config[_0xe527('0x52')],'server/files/plugins',path[_0xe527('0x60')](_0x5e788c['path'])),function(){});return _0x5e788c;})[_0xe527('0x48')](handleEntityNotFound(_0x13429f,null))[_0xe527('0x48')](respondWithStatusCode(_0x13429f,null))['catch'](handleError(_0x13429f,null));};exports[_0xe527('0x9b')]=function(_0x557c88,_0x31d4ed,_0x43e775){return BPromise['resolve']()[_0xe527('0x48')](function(){if(!_0x557c88[_0xe527('0x38')]['path']){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x557c88['query'][_0xe527('0x9c')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x2e0eda=_0x557c88[_0xe527('0x38')][_0xe527('0x9d')]?_0x557c88[_0xe527('0x38')]['hostname']+':'+_0x557c88['query'][_0xe527('0x9c')]:_0xe527('0x9e')+_0x557c88['query'][_0xe527('0x9c')];var _0x4d9b06=_0x557c88[_0xe527('0x38')][_0xe527('0x21')]?_0x557c88[_0xe527('0x38')][_0xe527('0x21')]:!![];var _0x2b08b3=_0x557c88[_0xe527('0x38')][_0xe527('0x9f')]?_0x557c88[_0xe527('0x38')][_0xe527('0x9f')]:null;var _0x47df66={'method':_0x557c88[_0xe527('0xa0')],'uri':util[_0xe527('0x54')](_0xe527('0xa1'),_0x2e0eda,_0x557c88[_0xe527('0x38')]['path']),'json':_0x4d9b06,'resolveWithFullResponse':!![],'encoding':_0x2b08b3,'qs':_0x557c88['query']};if(_0x557c88[_0xe527('0xa2')]){_0x47df66['headers']=_0x557c88[_0xe527('0xa2')];if(_0x47df66[_0xe527('0xa2')][_0xe527('0xa3')]){delete _0x47df66['headers']['content-length'];}}if(_0x47df66[_0xe527('0xa2')]['content-type']){delete _0x47df66[_0xe527('0xa2')][_0xe527('0xa4')];}return rp(_0x47df66);})[_0xe527('0x48')](function(_0x12ba13){if(_0x12ba13){_0x31d4ed[_0xe527('0xa5')](_0x12ba13[_0xe527('0xa2')]);logger['info'](_0x12ba13['body']);if(_[_0xe527('0xa6')](_0x557c88['query'][_0xe527('0x57')],'download')&&_0x12ba13['statusCode']==0x1f4){return _0x31d4ed[_0xe527('0x1e')](_0x12ba13[_0xe527('0xa7')]);}else{return _0x31d4ed[_0xe527('0x1f')](_0x12ba13['statusCode'])[_0xe527('0x2f')](_0x12ba13[_0xe527('0x90')]);}}else{return _0x31d4ed[_0xe527('0x1e')](0xc8);}})[_0xe527('0x4d')](handleError(_0x31d4ed,null));};exports[_0xe527('0xa8')]=function(_0x262373,_0x3e3a4f,_0x57978b){return BPromise['resolve']()[_0xe527('0x48')](function(){if(!_0x262373['query']['path']){throw new Error(_0xe527('0xa9'));}if(!_0x262373[_0xe527('0x38')]['port']){throw new Error(_0xe527('0xaa'));}var _0x5b52fc=_0x262373[_0xe527('0x38')][_0xe527('0x9d')]?_0x262373[_0xe527('0x38')][_0xe527('0x9d')]+':'+_0x262373['query'][_0xe527('0x9c')]:'http://localhost:'+_0x262373['query'][_0xe527('0x9c')];var _0x4b4f7f=_0x262373['query']['json']?_0x262373[_0xe527('0x38')][_0xe527('0x21')]:!![];var _0x414fcf=_0x262373[_0xe527('0x38')][_0xe527('0x9f')]?_0x262373[_0xe527('0x38')]['encoding']:null;var _0x2c99bc={'method':_0x262373[_0xe527('0xa0')],'uri':util[_0xe527('0x54')]('%s%s',_0x5b52fc,_0x262373[_0xe527('0x38')][_0xe527('0x57')]),'json':_0x4b4f7f,'resolveWithFullResponse':!![],'encoding':_0x414fcf,'body':_0x262373['body']};if(_0x262373[_0xe527('0xa2')]){_0x2c99bc[_0xe527('0xa2')]=_0x262373[_0xe527('0xa2')];if(_0x2c99bc[_0xe527('0xa2')][_0xe527('0xa3')]){delete _0x2c99bc['headers']['content-length'];}}if(_0x2c99bc[_0xe527('0xa2')]['content-type']){delete _0x2c99bc[_0xe527('0xa2')]['content-type'];}return rp(_0x2c99bc);})[_0xe527('0x48')](function(_0x49c980){if(_0x49c980){_0x3e3a4f[_0xe527('0xa5')](_0x49c980[_0xe527('0xa2')]);logger[_0xe527('0x68')](_0x49c980[_0xe527('0x90')]);return _0x3e3a4f['status'](_0x49c980[_0xe527('0xa7')])[_0xe527('0x2f')](_0x49c980[_0xe527('0x90')]);}else{return _0x3e3a4f[_0xe527('0x1e')](0xc8);}})[_0xe527('0x4d')](handleError(_0x3e3a4f,null));};