Built motion from commit 4a17b4ed.|2.6.17
[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 _0x74e8=['end','status','json','offset','undefined','count','limit','set','Content-Range','apply','save','update','then','destroy','get','UserProfileResource','error','name','send','index','Plugin','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','merge','download','find','server/files/plugins','format','basename','createWriteStream','warning','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','**/*','join','root','dirname','attachments/**/*','finalize','close','existsSync','Plugin\x20not\x20found','%s.zip','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','Temporary\x20file\x20removed','upload','file','extname','filename','Plugin\x20upload\x20filepath:\x20%s','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','manifest.json','Plugin\x20manifest\x20missing','parse','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','parameters','views','admin','Invalid\x20manifest:\x20no\x20view\x20specified','script','scriptName','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','icon','icon-apps','html','test','Warning:\x20admin\x20view\x20not\x20specified','plugins','Warning:\x20agent\x20view\x20not\x20specified','agent','create','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','Plugins','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','\x27PATH\x27\x20parameter\x20not\x20specified','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','port','http://localhost:','encoding','%s%s','headers','content-length','content-type','statusCode','webhookPost','resolve','method','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','extract-zip','archiver','ioredis','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./plugin.socket','register','sendStatus'];(function(_0x36f4c2,_0x3fe9d6){var _0x98f20d=function(_0x4f6276){while(--_0x4f6276){_0x36f4c2['push'](_0x36f4c2['shift']());}};_0x98f20d(++_0x3fe9d6);}(_0x74e8,0x131));var _0x874e=function(_0x14a0a0,_0x45d0cf){_0x14a0a0=_0x14a0a0-0x0;var _0x56b651=_0x74e8[_0x14a0a0];return _0x56b651;};'use strict';var emlformat=require(_0x874e('0x0'));var rimraf=require(_0x874e('0x1'));var zipdir=require(_0x874e('0x2'));var jsonpatch=require(_0x874e('0x3'));var rp=require(_0x874e('0x4'));var moment=require('moment');var BPromise=require(_0x874e('0x5'));var Mustache=require('mustache');var util=require(_0x874e('0x6'));var path=require(_0x874e('0x7'));var sox=require(_0x874e('0x8'));var csv=require(_0x874e('0x9'));var ejs=require(_0x874e('0xa'));var fs=require('fs');var fs_extra=require(_0x874e('0xb'));var _=require(_0x874e('0xc'));var squel=require('squel');var crypto=require(_0x874e('0xd'));var jsforce=require(_0x874e('0xe'));var deskjs=require(_0x874e('0xf'));var toCsv=require(_0x874e('0x9'));var querystring=require('querystring');var Papa=require(_0x874e('0x10'));var extract=require(_0x874e('0x11'));var rimraf=require(_0x874e('0x1'));var archiver=require(_0x874e('0x12'));var Redis=require(_0x874e('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x874e('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x874e('0x15'))('api');var utils=require(_0x874e('0x16'));var config=require(_0x874e('0x17'));var licenseUtil=require(_0x874e('0x18'));var db=require(_0x874e('0x19'))['db'];config[_0x874e('0x1a')]=_[_0x874e('0x1b')](config[_0x874e('0x1a')],{'host':_0x874e('0x1c'),'port':0x18eb});var socket=require(_0x874e('0x1d'))(new Redis(config['redis']));require(_0x874e('0x1e'))[_0x874e('0x1f')](socket);function respondWithStatusCode(_0x93549c,_0x39787a){_0x39787a=_0x39787a||0xcc;return function(_0x74ad9b){if(_0x74ad9b){return _0x93549c[_0x874e('0x20')](_0x39787a);}return _0x93549c['status'](_0x39787a)[_0x874e('0x21')]();};}function respondWithResult(_0x1ce559,_0x5bd9e8){_0x5bd9e8=_0x5bd9e8||0xc8;return function(_0x4f8c04){if(_0x4f8c04){return _0x1ce559[_0x874e('0x22')](_0x5bd9e8)[_0x874e('0x23')](_0x4f8c04);}};}function respondWithFilteredResult(_0x262c86,_0x186183){return function(_0x4dfa61){if(_0x4dfa61){var _0x4b323e=typeof _0x186183[_0x874e('0x24')]===_0x874e('0x25')&&typeof _0x186183['limit']===_0x874e('0x25');var _0x1a6178=_0x4dfa61[_0x874e('0x26')];var _0x15febc=_0x4b323e?0x0:_0x186183[_0x874e('0x24')];var _0x2bb337=_0x4b323e?_0x4dfa61[_0x874e('0x26')]:_0x186183[_0x874e('0x24')]+_0x186183[_0x874e('0x27')];var _0x20e4ec;if(_0x2bb337>=_0x1a6178){_0x2bb337=_0x1a6178;_0x20e4ec=0xc8;}else{_0x20e4ec=0xce;}_0x262c86['status'](_0x20e4ec);return _0x262c86[_0x874e('0x28')](_0x874e('0x29'),_0x15febc+'-'+_0x2bb337+'/'+_0x1a6178)['json'](_0x4dfa61);}return null;};}function patchUpdates(_0x570020){return function(_0x218f13){try{jsonpatch[_0x874e('0x2a')](_0x218f13,_0x570020,!![]);}catch(_0x3ce135){return BPromise['reject'](_0x3ce135);}return _0x218f13[_0x874e('0x2b')]();};}function saveUpdates(_0xf56b1a,_0x39e557){return function(_0x13caed){if(_0x13caed){return _0x13caed[_0x874e('0x2c')](_0xf56b1a)[_0x874e('0x2d')](function(_0x5b819a){return _0x5b819a;});}return null;};}function removeEntity(_0x42f407,_0x521286){return function(_0x12a794){if(_0x12a794){return _0x12a794[_0x874e('0x2e')]()[_0x874e('0x2d')](function(){var _0x2e2a26=_0x12a794[_0x874e('0x2f')]({'plain':!![]});var _0xfe0c52='Plugins';return db[_0x874e('0x30')]['destroy']({'where':{'type':_0xfe0c52,'resourceId':_0x2e2a26['id']}})[_0x874e('0x2d')](function(){return _0x12a794;});})['then'](function(){_0x42f407[_0x874e('0x22')](0xcc)[_0x874e('0x21')]();});}};}function handleEntityNotFound(_0x34e3c4,_0x793522){return function(_0x293f8e){if(!_0x293f8e){_0x34e3c4[_0x874e('0x20')](0x194);}return _0x293f8e;};}function handleError(_0x4d96c2,_0x431481){_0x431481=_0x431481||0x1f4;return function(_0xcec38a){logger[_0x874e('0x31')](_0xcec38a['stack']);if(_0xcec38a[_0x874e('0x32')]){delete _0xcec38a[_0x874e('0x32')];}_0x4d96c2[_0x874e('0x22')](_0x431481)[_0x874e('0x33')](_0xcec38a);};}exports[_0x874e('0x34')]=function(_0x268c4d,_0x3dc3bc){var _0x22e0d8={},_0x547d73={},_0x30edfc={'count':0x0,'rows':[]};var _0x4a2e33=_['map'](db[_0x874e('0x35')]['rawAttributes'],function(_0x5d56a2){return{'name':_0x5d56a2[_0x874e('0x36')],'type':_0x5d56a2[_0x874e('0x37')][_0x874e('0x38')]};});_0x547d73[_0x874e('0x39')]=_[_0x874e('0x3a')](_0x4a2e33,_0x874e('0x32'));_0x547d73[_0x874e('0x3b')]=_[_0x874e('0x3c')](_0x268c4d[_0x874e('0x3b')]);_0x547d73[_0x874e('0x3d')]=_[_0x874e('0x3e')](_0x547d73[_0x874e('0x39')],_0x547d73['query']);_0x22e0d8[_0x874e('0x3f')]=_[_0x874e('0x3e')](_0x547d73[_0x874e('0x39')],qs[_0x874e('0x40')](_0x268c4d[_0x874e('0x3b')][_0x874e('0x40')]));_0x22e0d8[_0x874e('0x3f')]=_0x22e0d8[_0x874e('0x3f')][_0x874e('0x41')]?_0x22e0d8[_0x874e('0x3f')]:_0x547d73['model'];if(!_0x268c4d[_0x874e('0x3b')][_0x874e('0x42')](_0x874e('0x43'))){_0x22e0d8[_0x874e('0x27')]=qs['limit'](_0x268c4d[_0x874e('0x3b')]['limit']);_0x22e0d8['offset']=qs[_0x874e('0x24')](_0x268c4d[_0x874e('0x3b')]['offset']);}_0x22e0d8[_0x874e('0x44')]=qs[_0x874e('0x45')](_0x268c4d[_0x874e('0x3b')][_0x874e('0x45')]);_0x22e0d8['where']=qs['filters'](_['pick'](_0x268c4d[_0x874e('0x3b')],_0x547d73[_0x874e('0x3d')]),_0x4a2e33);if(_0x268c4d[_0x874e('0x3b')]['filter']){_0x22e0d8[_0x874e('0x46')]=_['merge'](_0x22e0d8['where'],{'$or':_[_0x874e('0x3a')](_0x4a2e33,function(_0x1ad454){if(_0x1ad454[_0x874e('0x37')]!==_0x874e('0x47')){var _0x3538ac={};_0x3538ac[_0x1ad454[_0x874e('0x32')]]={'$like':'%'+_0x268c4d['query'][_0x874e('0x48')]+'%'};return _0x3538ac;}})});}_0x22e0d8=_['merge']({},_0x22e0d8,_0x268c4d[_0x874e('0x49')]);var _0x1cf4e7={'where':_0x22e0d8['where']};return db[_0x874e('0x35')][_0x874e('0x26')](_0x1cf4e7)['then'](function(_0x320aea){_0x30edfc[_0x874e('0x26')]=_0x320aea;if(_0x268c4d[_0x874e('0x3b')][_0x874e('0x4a')]){_0x22e0d8[_0x874e('0x4b')]=[{'all':!![]}];}return db['Plugin'][_0x874e('0x4c')](_0x22e0d8);})[_0x874e('0x2d')](function(_0x200d2e){_0x30edfc[_0x874e('0x4d')]=_0x200d2e;return _0x30edfc;})[_0x874e('0x2d')](respondWithFilteredResult(_0x3dc3bc,_0x22e0d8))[_0x874e('0x4e')](handleError(_0x3dc3bc,null));};exports[_0x874e('0x4f')]=function(_0x51b836,_0x2ca440){var _0x214303={'raw':!![],'where':{'id':_0x51b836[_0x874e('0x50')]['id']}},_0x241fd0={};_0x241fd0['model']=_[_0x874e('0x3c')](db[_0x874e('0x35')][_0x874e('0x51')]);_0x241fd0[_0x874e('0x3b')]=_['keys'](_0x51b836[_0x874e('0x3b')]);_0x241fd0[_0x874e('0x3d')]=_[_0x874e('0x3e')](_0x241fd0['model'],_0x241fd0[_0x874e('0x3b')]);_0x214303[_0x874e('0x3f')]=_[_0x874e('0x3e')](_0x241fd0[_0x874e('0x39')],qs[_0x874e('0x40')](_0x51b836[_0x874e('0x3b')][_0x874e('0x40')]));_0x214303[_0x874e('0x3f')]=_0x214303[_0x874e('0x3f')][_0x874e('0x41')]?_0x214303[_0x874e('0x3f')]:_0x241fd0[_0x874e('0x39')];if(_0x51b836[_0x874e('0x3b')]['includeAll']){_0x214303['include']=[{'all':!![]}];}_0x214303=_[_0x874e('0x52')]({},_0x214303,_0x51b836[_0x874e('0x49')]);return db['Plugin']['find'](_0x214303)['then'](handleEntityNotFound(_0x2ca440,null))[_0x874e('0x2d')](respondWithResult(_0x2ca440,null))[_0x874e('0x4e')](handleError(_0x2ca440,null));};exports[_0x874e('0x53')]=function(_0x275b74,_0x2ef33e,_0xcefdba){return db[_0x874e('0x35')][_0x874e('0x54')]({'where':{'id':_0x275b74['params']['id']},'attributes':[_0x874e('0x32'),_0x874e('0x7')],'raw':!![]})[_0x874e('0x2d')](handleEntityNotFound(_0x2ef33e,null))[_0x874e('0x2d')](function(_0x48c34c){if(_0x48c34c){var _0x8c9000=path['join'](config['root'],_0x874e('0x55'),util[_0x874e('0x56')]('%s.zip',path[_0x874e('0x57')](_0x48c34c[_0x874e('0x7')])));var _0x4caabb=fs[_0x874e('0x58')](_0x8c9000);var _0x43a77d=archiver('zip',{'zlib':{'level':0x9}});_0x43a77d['on'](_0x874e('0x59'),function(_0xf67058){if(_0xf67058[_0x874e('0x5a')]===_0x874e('0x5b')){logger[_0x874e('0x31')](_0xf67058);}else{throw new db[(_0x874e('0x5c'))]['Error']('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x43a77d['on']('error',function(_0xc2e2da){throw new db[(_0x874e('0x5c'))][(_0x874e('0x5d'))](_0x874e('0x5e'));});_0x43a77d[_0x874e('0x5f')](_0x4caabb);_0x43a77d[_0x874e('0x60')](_0x874e('0x61'),{'cwd':path[_0x874e('0x62')](config[_0x874e('0x63')],_0x874e('0x55'),path[_0x874e('0x64')](_0x48c34c['path'])),'ignore':[path['join'](path[_0x874e('0x57')](_0x48c34c['path']),'node_modules/**/*'),path['join'](path[_0x874e('0x57')](_0x48c34c[_0x874e('0x7')]),_0x874e('0x65'))],'nodir':!![]})[_0x874e('0x66')]();_0x4caabb['on'](_0x874e('0x67'),function(){if(!fs[_0x874e('0x68')](_0x8c9000)){throw new db[(_0x874e('0x5c'))]['Error'](_0x874e('0x69'));}return _0x2ef33e[_0x874e('0x53')](_0x8c9000,util[_0x874e('0x56')](_0x874e('0x6a'),path[_0x874e('0x57')](_0x48c34c[_0x874e('0x7')])),function(_0x44606e){if(_0x44606e){throw new db[(_0x874e('0x5c'))][(_0x874e('0x5d'))](_0x874e('0x6b'));}fs[_0x874e('0x6c')](_0x8c9000);logger[_0x874e('0x6d')](_0x874e('0x6e'));logger[_0x874e('0x6d')](_0x874e('0x6f'));});});}return null;})['catch'](handleError(_0x2ef33e,null));};exports[_0x874e('0x70')]=function(_0x267ded,_0x3a980e,_0x5e7ec2){var _0x59b04e=path[_0x874e('0x57')](_0x267ded[_0x874e('0x71')]['filename'],path[_0x874e('0x72')](_0x267ded[_0x874e('0x71')][_0x874e('0x73')]));var _0x16cbab=path[_0x874e('0x62')](config[_0x874e('0x63')],_0x874e('0x55'),_0x267ded[_0x874e('0x71')][_0x874e('0x73')]);var _0x4c0e0d=path['join'](config[_0x874e('0x63')],_0x874e('0x55'),_0x59b04e);logger['info'](_0x874e('0x74'),_0x16cbab);logger[_0x874e('0x6d')]('Plugin\x20upload\x20destination:\x20%s',_0x4c0e0d);try{fs['chmodSync'](_0x16cbab,parseInt('0777',0x8));extract(_0x16cbab,{'dir':_0x4c0e0d},function(_0x10c233){if(_0x10c233){logger[_0x874e('0x31')](_0x10c233);handleError(_0x10c233,!![]);};var _0x598b82=fs[_0x874e('0x75')](_0x4c0e0d);if(_0x598b82[_0x874e('0x41')]>0x1){removeReferences(_0x16cbab,_0x4c0e0d);logger[_0x874e('0x31')]('Invalid\x20plugin\x20structure');return _0x5e7ec2(new Error(_0x874e('0x76')));}var _0x5382ea=fs[_0x874e('0x77')](path['join'](_0x4c0e0d,_0x598b82[0x0]));if(_0x5382ea[_0x874e('0x78')]()){removeReferences(_0x16cbab,_0x4c0e0d);logger['error'](_0x874e('0x76'));return _0x5e7ec2(new Error(_0x874e('0x76')));}if(_0x5382ea['isDirectory']()){var _0x41660f=fs['readdirSync'](path[_0x874e('0x62')](_0x4c0e0d,_0x598b82[0x0]));if(_0x41660f['length']===0x0){removeReferences(_0x16cbab,_0x4c0e0d);logger['error']('Invalid\x20plugin\x20structure');return _0x5e7ec2(new Error('Invalid\x20plugin\x20structure'));}var _0x81a2e2=_0x41660f['some'](function(_0x4b9aac){return _0x4b9aac===_0x874e('0x79');});if(!_0x81a2e2){return _0x5e7ec2(new Error(_0x874e('0x7a')));}var _0x270417=fs['readFileSync'](path[_0x874e('0x62')](_0x4c0e0d,_0x598b82[0x0],'manifest.json'));var _0x4aa0ad=JSON[_0x874e('0x7b')](_0x270417);if(_0x874e('0x25')==typeof _0x4aa0ad['name']){return _0x5e7ec2(new Error(_0x874e('0x7c')));}if('undefined'==typeof _0x4aa0ad[_0x874e('0x37')]){return _0x5e7ec2(new Error(_0x874e('0x7d')));}if('undefined'==typeof _0x4aa0ad[_0x874e('0x7e')]){return _0x5e7ec2(new Error('Invalid\x20manifest:\x20version\x20not\x20specified'));}if(_0x874e('0x25')==typeof _0x4aa0ad[_0x874e('0x7f')]){return _0x5e7ec2(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x4aa0ad[_0x874e('0x37')]==='html'){if(_0x874e('0x25')==typeof _0x4aa0ad[_0x874e('0x7f')]['views']){return _0x5e7ec2(new Error('Invalid\x20manifest:\x20views\x20missing'));}if('undefined'==typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')][_0x874e('0x81')]&&_0x874e('0x25')==typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')]['agent']){return _0x5e7ec2(new Error(_0x874e('0x82')));}}else if(_0x4aa0ad[_0x874e('0x37')]===_0x874e('0x83')){if('undefined'==typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x84')]){return _0x5e7ec2(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0x874e('0x25')==typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x85')]){return _0x5e7ec2(new Error(_0x874e('0x86')));}}else{return _0x5e7ec2(new Error(_0x874e('0x87')));}var _0x3f7f8b=_0x4aa0ad[_0x874e('0x32')];var _0x2e4124=_0x4aa0ad[_0x874e('0x88')];var _0x3a2447=_0x4aa0ad[_0x874e('0x37')];var _0x267ea9=_0x4aa0ad['sidebar']?_0x4aa0ad['sidebar']:'always';var _0x46ed01=_0x4aa0ad[_0x874e('0x89')]?_0x4aa0ad[_0x874e('0x89')]:_0x874e('0x8a');var _0x2ad58a='';var _0x2cbab3='';var _0x4e8bdd='';var _0x51677c='';var _0x31b13a=_0x4aa0ad[_0x874e('0x7e')];if(_0x3a2447===_0x874e('0x8b')){if(_0x874e('0x25')!=typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')][_0x874e('0x81')]){var _0x2750b5=_0x4aa0ad['parameters'][_0x874e('0x80')][_0x874e('0x81')];if(!/^(f|ht)tps?:\/\//i[_0x874e('0x8c')](_0x2750b5)){_0x2ad58a=path[_0x874e('0x62')]('plugins',_0x59b04e,_0x598b82[0x0],_0x2750b5);}else{_0x2ad58a=_0x2750b5;}}else{logger[_0x874e('0x6d')](_0x874e('0x8d'));}if('undefined'!=typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')]['agent']){var _0x3f6b1c=_0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0x874e('0x8c')](_0x3f6b1c)){_0x2cbab3=path[_0x874e('0x62')](_0x874e('0x8e'),_0x59b04e,_0x598b82[0x0],_0x3f6b1c);}else{_0x2cbab3=_0x3f6b1c;}}else{logger['info'](_0x874e('0x8f'));}}else if(_0x3a2447===_0x874e('0x83')){_0x4e8bdd=_0x4aa0ad[_0x874e('0x7f')][_0x874e('0x84')];_0x51677c=_0x4aa0ad[_0x874e('0x7f')][_0x874e('0x85')];if(_0x874e('0x25')!=typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')]){if(_0x874e('0x25')!=typeof _0x4aa0ad['parameters'][_0x874e('0x80')]['admin']){var _0x2750b5=_0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')][_0x874e('0x81')];if(!/^(f|ht)tps?:\/\//i[_0x874e('0x8c')](_0x2750b5)){_0x2ad58a=path['join'](_0x874e('0x8e'),_0x59b04e,_0x598b82[0x0],_0x2750b5);}else{_0x2ad58a=_0x2750b5;}}if(_0x874e('0x25')!=typeof _0x4aa0ad[_0x874e('0x7f')][_0x874e('0x80')]['agent']){var _0x3f6b1c=_0x4aa0ad[_0x874e('0x7f')]['views'][_0x874e('0x90')];if(!/^(f|ht)tps?:\/\//i[_0x874e('0x8c')](_0x3f6b1c)){_0x2cbab3=path[_0x874e('0x62')](_0x874e('0x8e'),_0x59b04e,_0x598b82[0x0],_0x3f6b1c);}else{_0x2cbab3=_0x3f6b1c;}}}}var _0x434643={'name':_0x3f7f8b,'description':_0x2e4124,'path':path[_0x874e('0x62')](_0x59b04e,_0x598b82[0x0]),'type':_0x3a2447,'sidebar':_0x267ea9,'icon':_0x46ed01,'adminUrl':_0x2ad58a,'agentUrl':_0x2cbab3,'scriptName':_0x4e8bdd,'scriptPath':_0x51677c,'version':_0x31b13a};removeReferences(_0x16cbab,null);return db[_0x874e('0x35')][_0x874e('0x91')](_0x434643)[_0x874e('0x2d')](function(_0x3678ec){var _0x3fa3af={'role':_0x267ded[_0x874e('0x92')][_0x874e('0x93')],'userProfileId':_0x267ded['body'][_0x874e('0x94')]};if(!_0x3fa3af)throw new Error(_0x874e('0x95'));if(_0x3fa3af[_0x874e('0x93')]===_0x874e('0x96')){var _0x4acecd=_0x3678ec[_0x874e('0x2f')]({'plain':!![]});return db[_0x874e('0x97')]['find']({'where':{'name':_0x874e('0x98'),'userProfileId':_0x3fa3af[_0x874e('0x94')]},'raw':!![]})[_0x874e('0x2d')](function(_0x346085){if(_0x346085&&_0x346085['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x4acecd[_0x874e('0x32')],'resourceId':_0x4acecd['id'],'type':_0x346085[_0x874e('0x32')],'sectionId':_0x346085['id']},{})[_0x874e('0x2d')](function(){return _0x3678ec;});}else{return _0x3678ec;}})['catch'](function(_0x4918c9){logger[_0x874e('0x31')](_0x874e('0x99'),_0x4918c9);throw _0x4918c9;});}return _0x3678ec;})[_0x874e('0x2d')](respondWithResult(_0x3a980e,null))[_0x874e('0x4e')](handleError(_0x3a980e,null));}});}catch(_0x180f7f){_0x3a980e[_0x874e('0x22')](0x1f4)[_0x874e('0x33')](_0x180f7f);}};function removeReferences(_0x258636,_0x2cac46){try{if(_0x258636){fs[_0x874e('0x6c')](_0x258636);logger[_0x874e('0x6d')](_0x874e('0x9a'));}if(_0x2cac46){rimraf(_0x2cac46,function(){});logger['info']('Extracted\x20folder\x20removed');}}catch(_0x4354ee){logger[_0x874e('0x31')](_0x4354ee);}}exports[_0x874e('0x2c')]=function(_0x51c4e0,_0x25abfb,_0x11211c){return db[_0x874e('0x35')]['find']({'where':{'id':_0x51c4e0[_0x874e('0x50')]['id']}})[_0x874e('0x2d')](handleEntityNotFound(_0x25abfb,null))['then'](saveUpdates(_0x51c4e0['body'],null))[_0x874e('0x2d')](respondWithResult(_0x25abfb,null))[_0x874e('0x4e')](handleError(_0x25abfb,null));};exports['delete']=function(_0x76592f,_0x5325d,_0x4997f9){return db['Plugin'][_0x874e('0x54')]({'where':{'id':_0x76592f[_0x874e('0x50')]['id']}})[_0x874e('0x2d')](function(_0x45451b){if(_0x45451b){return _0x45451b[_0x874e('0x2e')]();}})[_0x874e('0x2d')](function(_0x37b8d8){rimraf(path['join'](config['root'],_0x874e('0x55'),path[_0x874e('0x64')](_0x37b8d8[_0x874e('0x7')])),function(){});return _0x37b8d8;})[_0x874e('0x2d')](handleEntityNotFound(_0x5325d,null))[_0x874e('0x2d')](respondWithStatusCode(_0x5325d,null))[_0x874e('0x4e')](handleError(_0x5325d,null));};exports['webhookGet']=function(_0x2d367d,_0x5a6f2f,_0x47db10){return BPromise['resolve']()[_0x874e('0x2d')](function(){if(!_0x2d367d[_0x874e('0x3b')][_0x874e('0x7')]){throw new Error(_0x874e('0x9b'));}if(!_0x2d367d[_0x874e('0x3b')]['port']){throw new Error(_0x874e('0x9c'));}var _0x2305b0=_0x2d367d[_0x874e('0x3b')][_0x874e('0x9d')]?_0x2d367d[_0x874e('0x3b')]['hostname']+':'+_0x2d367d[_0x874e('0x3b')][_0x874e('0x9e')]:_0x874e('0x9f')+_0x2d367d[_0x874e('0x3b')]['port'];var _0x366592=_0x2d367d[_0x874e('0x3b')]['json']?_0x2d367d[_0x874e('0x3b')][_0x874e('0x23')]:!![];var _0x245e20=_0x2d367d[_0x874e('0x3b')][_0x874e('0xa0')]?_0x2d367d['query']['encoding']:null;var _0x51085b={'method':_0x2d367d['method'],'uri':util[_0x874e('0x56')](_0x874e('0xa1'),_0x2305b0,_0x2d367d[_0x874e('0x3b')][_0x874e('0x7')]),'json':_0x366592,'resolveWithFullResponse':!![],'encoding':_0x245e20,'qs':_0x2d367d['query']};if(_0x2d367d[_0x874e('0xa2')]){_0x51085b['headers']=_0x2d367d['headers'];if(_0x51085b[_0x874e('0xa2')]['content-length']){delete _0x51085b['headers'][_0x874e('0xa3')];}}if(_0x51085b[_0x874e('0xa2')][_0x874e('0xa4')]){delete _0x51085b[_0x874e('0xa2')][_0x874e('0xa4')];}return rp(_0x51085b);})[_0x874e('0x2d')](function(_0x312fb1){if(_0x312fb1){_0x5a6f2f[_0x874e('0x28')](_0x312fb1[_0x874e('0xa2')]);logger['info'](_0x312fb1[_0x874e('0x92')]);if(_['endsWith'](_0x2d367d[_0x874e('0x3b')]['path'],'download')&&_0x312fb1[_0x874e('0xa5')]==0x1f4){return _0x5a6f2f[_0x874e('0x20')](_0x312fb1[_0x874e('0xa5')]);}else{return _0x5a6f2f[_0x874e('0x22')](_0x312fb1[_0x874e('0xa5')])[_0x874e('0x33')](_0x312fb1['body']);}}else{return _0x5a6f2f[_0x874e('0x20')](0xc8);}})[_0x874e('0x4e')](handleError(_0x5a6f2f,null));};exports[_0x874e('0xa6')]=function(_0x44fe90,_0x24b372,_0x3dad70){return BPromise[_0x874e('0xa7')]()[_0x874e('0x2d')](function(){if(!_0x44fe90[_0x874e('0x3b')]['path']){throw new Error(_0x874e('0x9b'));}if(!_0x44fe90['query']['port']){throw new Error(_0x874e('0x9c'));}var _0x18ab0a=_0x44fe90[_0x874e('0x3b')]['hostname']?_0x44fe90[_0x874e('0x3b')]['hostname']+':'+_0x44fe90[_0x874e('0x3b')][_0x874e('0x9e')]:_0x874e('0x9f')+_0x44fe90['query']['port'];var _0x51346f=_0x44fe90[_0x874e('0x3b')][_0x874e('0x23')]?_0x44fe90[_0x874e('0x3b')]['json']:!![];var _0x218fb3=_0x44fe90['query'][_0x874e('0xa0')]?_0x44fe90[_0x874e('0x3b')][_0x874e('0xa0')]:null;var _0x41797d={'method':_0x44fe90[_0x874e('0xa8')],'uri':util[_0x874e('0x56')]('%s%s',_0x18ab0a,_0x44fe90[_0x874e('0x3b')][_0x874e('0x7')]),'json':_0x51346f,'resolveWithFullResponse':!![],'encoding':_0x218fb3,'body':_0x44fe90[_0x874e('0x92')]};if(_0x44fe90[_0x874e('0xa2')]){_0x41797d['headers']=_0x44fe90[_0x874e('0xa2')];if(_0x41797d['headers'][_0x874e('0xa3')]){delete _0x41797d['headers'][_0x874e('0xa3')];}}if(_0x41797d['headers'][_0x874e('0xa4')]){delete _0x41797d[_0x874e('0xa2')][_0x874e('0xa4')];}return rp(_0x41797d);})[_0x874e('0x2d')](function(_0x2106cf){if(_0x2106cf){_0x24b372[_0x874e('0x28')](_0x2106cf[_0x874e('0xa2')]);logger['info'](_0x2106cf['body']);return _0x24b372[_0x874e('0x22')](_0x2106cf[_0x874e('0xa5')])[_0x874e('0x33')](_0x2106cf['body']);}else{return _0x24b372[_0x874e('0x20')](0xc8);}})[_0x874e('0x4e')](handleError(_0x24b372,null));};