Built motion from commit (unavailable).|2.5.0
[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 _0x10bb=['method','html-pdf','fast-json-patch','request-promise','moment','bluebird','mustache','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','extract-zip','rimraf','archiver','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','set','Content-Range','json','apply','reject','save','update','then','destroy','Plugins','UserProfileResource','end','error','name','send','index','map','Plugin','rawAttributes','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','nolimit','limit','offset','order','sort','where','filter','VIRTUAL','merge','options','count','includeAll','include','findAll','rows','catch','show','params','keys','find','download','path','join','server/files/plugins','format','basename','createWriteStream','zip','warning','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','**/*','dirname','node_modules/**/*','attachments/**/*','finalize','existsSync','Plugin\x20not\x20found','%s.zip','unlinkSync','Temporary\x20file\x20removed','upload','file','filename','root','info','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','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','views','Invalid\x20manifest:\x20views\x20missing','Invalid\x20manifest:\x20no\x20view\x20specified','script','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','html','admin','plugins','agent','test','Warning:\x20agent\x20view\x20not\x20specified','scriptName','create','body','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','get','UserProfileSection','autoAssociation','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','webhookGet','resolve','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','encoding','%s%s','headers','content-length','content-type','endsWith','statusCode','webhookPost','\x27PATH\x27\x20parameter\x20not\x20specified','http://localhost:'];(function(_0x4ef24e,_0x265500){var _0xd08163=function(_0x35ea42){while(--_0x35ea42){_0x4ef24e['push'](_0x4ef24e['shift']());}};_0xd08163(++_0x265500);}(_0x10bb,0x167));var _0xb10b=function(_0x353491,_0x2764b3){_0x353491=_0x353491-0x0;var _0x52782d=_0x10bb[_0x353491];return _0x52782d;};'use strict';var pdf=require(_0xb10b('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xb10b('0x1'));var rp=require(_0xb10b('0x2'));var moment=require(_0xb10b('0x3'));var BPromise=require(_0xb10b('0x4'));var Mustache=require(_0xb10b('0x5'));var util=require('util');var path=require('path');var sox=require(_0xb10b('0x6'));var csv=require('to-csv');var ejs=require(_0xb10b('0x7'));var fs=require('fs');var _=require(_0xb10b('0x8'));var squel=require(_0xb10b('0x9'));var crypto=require(_0xb10b('0xa'));var jsforce=require(_0xb10b('0xb'));var deskjs=require(_0xb10b('0xc'));var toCsv=require(_0xb10b('0xd'));var querystring=require('querystring');var Papa=require(_0xb10b('0xe'));var extract=require(_0xb10b('0xf'));var rimraf=require(_0xb10b('0x10'));var archiver=require(_0xb10b('0x11'));var Redis=require(_0xb10b('0x12'));var authService=require(_0xb10b('0x13'));var qs=require(_0xb10b('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xb10b('0x15'))(_0xb10b('0x16'));var utils=require(_0xb10b('0x17'));var config=require(_0xb10b('0x18'));var db=require(_0xb10b('0x19'))['db'];config['redis']=_['defaults'](config[_0xb10b('0x1a')],{'host':_0xb10b('0x1b'),'port':0x18eb});var socket=require(_0xb10b('0x1c'))(new Redis(config[_0xb10b('0x1a')]));require(_0xb10b('0x1d'))[_0xb10b('0x1e')](socket);function respondWithStatusCode(_0x4d2fe0,_0x17e63d){_0x17e63d=_0x17e63d||0xcc;return function(_0x1b1896){if(_0x1b1896){return _0x4d2fe0[_0xb10b('0x1f')](_0x17e63d);}return _0x4d2fe0[_0xb10b('0x20')](_0x17e63d)['end']();};}function respondWithResult(_0x434f0f,_0x3dd235){_0x3dd235=_0x3dd235||0xc8;return function(_0x13b96e){if(_0x13b96e){return _0x434f0f[_0xb10b('0x20')](_0x3dd235)['json'](_0x13b96e);}};}function respondWithFilteredResult(_0x2683e9,_0xaca66){return function(_0x20e19a){if(_0x20e19a){var _0x49c046=_0x20e19a['count'],_0x4520f1=_0xaca66['offset'],_0x3bf38b=_0xaca66['offset']+_0xaca66['limit'],_0x2378a4;if(_0x3bf38b>=_0x49c046){_0x3bf38b=_0x49c046;_0x2378a4=0xc8;}else{_0x2378a4=0xce;}_0x2683e9[_0xb10b('0x20')](_0x2378a4);return _0x2683e9[_0xb10b('0x21')](_0xb10b('0x22'),_0x4520f1+'-'+_0x3bf38b+'/'+_0x49c046)[_0xb10b('0x23')](_0x20e19a);}return null;};}function patchUpdates(_0x2e33a4){return function(_0x16d83c){try{jsonpatch[_0xb10b('0x24')](_0x16d83c,_0x2e33a4,!![]);}catch(_0x5c4578){return BPromise[_0xb10b('0x25')](_0x5c4578);}return _0x16d83c[_0xb10b('0x26')]();};}function saveUpdates(_0x475d65,_0x3e6ec1){return function(_0x263136){if(_0x263136){return _0x263136[_0xb10b('0x27')](_0x475d65)[_0xb10b('0x28')](function(_0xcdcac6){return _0xcdcac6;});}return null;};}function removeEntity(_0x517a33,_0x16be17){return function(_0x512321){if(_0x512321){return _0x512321[_0xb10b('0x29')]()[_0xb10b('0x28')](function(){var _0x45c180=_0x512321['get']({'plain':!![]});var _0x1a220e=_0xb10b('0x2a');return db[_0xb10b('0x2b')][_0xb10b('0x29')]({'where':{'type':_0x1a220e,'resourceId':_0x45c180['id']}})[_0xb10b('0x28')](function(){return _0x512321;});})[_0xb10b('0x28')](function(){_0x517a33[_0xb10b('0x20')](0xcc)[_0xb10b('0x2c')]();});}};}function handleEntityNotFound(_0x4f7414,_0x1e98bf){return function(_0x58a38c){if(!_0x58a38c){_0x4f7414[_0xb10b('0x1f')](0x194);}return _0x58a38c;};}function handleError(_0x5a669b,_0x5cabd1){_0x5cabd1=_0x5cabd1||0x1f4;return function(_0x4583b7){logger[_0xb10b('0x2d')](_0x4583b7['stack']);if(_0x4583b7[_0xb10b('0x2e')]){delete _0x4583b7[_0xb10b('0x2e')];}_0x5a669b[_0xb10b('0x20')](_0x5cabd1)[_0xb10b('0x2f')](_0x4583b7);};}exports[_0xb10b('0x30')]=function(_0x3c6c17,_0x258365){var _0x52d99f={},_0xebf5b9={},_0x53da16={'count':0x0,'rows':[]};var _0x34261a=_[_0xb10b('0x31')](db[_0xb10b('0x32')][_0xb10b('0x33')],function(_0x480bb6){return{'name':_0x480bb6[_0xb10b('0x34')],'type':_0x480bb6[_0xb10b('0x35')][_0xb10b('0x36')]};});_0xebf5b9[_0xb10b('0x37')]=_[_0xb10b('0x31')](_0x34261a,_0xb10b('0x2e'));_0xebf5b9[_0xb10b('0x38')]=_['keys'](_0x3c6c17['query']);_0xebf5b9[_0xb10b('0x39')]=_[_0xb10b('0x3a')](_0xebf5b9[_0xb10b('0x37')],_0xebf5b9[_0xb10b('0x38')]);_0x52d99f['attributes']=_[_0xb10b('0x3a')](_0xebf5b9[_0xb10b('0x37')],qs[_0xb10b('0x3b')](_0x3c6c17[_0xb10b('0x38')]['fields']));_0x52d99f['attributes']=_0x52d99f[_0xb10b('0x3c')][_0xb10b('0x3d')]?_0x52d99f[_0xb10b('0x3c')]:_0xebf5b9['model'];if(!_0x3c6c17[_0xb10b('0x38')]['hasOwnProperty'](_0xb10b('0x3e'))){_0x52d99f['limit']=qs[_0xb10b('0x3f')](_0x3c6c17['query'][_0xb10b('0x3f')]);_0x52d99f[_0xb10b('0x40')]=qs[_0xb10b('0x40')](_0x3c6c17[_0xb10b('0x38')][_0xb10b('0x40')]);}_0x52d99f[_0xb10b('0x41')]=qs[_0xb10b('0x42')](_0x3c6c17[_0xb10b('0x38')]['sort']);_0x52d99f[_0xb10b('0x43')]=qs[_0xb10b('0x39')](_['pick'](_0x3c6c17[_0xb10b('0x38')],_0xebf5b9['filters']));if(_0x3c6c17[_0xb10b('0x38')][_0xb10b('0x44')]){_0x52d99f[_0xb10b('0x43')]=_['merge'](_0x52d99f[_0xb10b('0x43')],{'$or':_[_0xb10b('0x31')](_0x34261a,function(_0x5acf75){if(_0x5acf75['type']!==_0xb10b('0x45')){var _0x12af8f={};_0x12af8f[_0x5acf75[_0xb10b('0x2e')]]={'$like':'%'+_0x3c6c17['query'][_0xb10b('0x44')]+'%'};return _0x12af8f;}})});}_0x52d99f=_[_0xb10b('0x46')]({},_0x52d99f,_0x3c6c17[_0xb10b('0x47')]);var _0x521be7={'where':_0x52d99f[_0xb10b('0x43')]};return db[_0xb10b('0x32')][_0xb10b('0x48')](_0x521be7)[_0xb10b('0x28')](function(_0x269fa1){_0x53da16['count']=_0x269fa1;if(_0x3c6c17[_0xb10b('0x38')][_0xb10b('0x49')]){_0x52d99f[_0xb10b('0x4a')]=[{'all':!![]}];}return db['Plugin'][_0xb10b('0x4b')](_0x52d99f);})['then'](function(_0x5e4687){_0x53da16[_0xb10b('0x4c')]=_0x5e4687;return _0x53da16;})[_0xb10b('0x28')](respondWithFilteredResult(_0x258365,_0x52d99f))[_0xb10b('0x4d')](handleError(_0x258365,null));};exports[_0xb10b('0x4e')]=function(_0x5ea150,_0x9179ee){var _0x484fed={'raw':!![],'where':{'id':_0x5ea150[_0xb10b('0x4f')]['id']}},_0xcc4252={};_0xcc4252['model']=_[_0xb10b('0x50')](db['Plugin'][_0xb10b('0x33')]);_0xcc4252[_0xb10b('0x38')]=_[_0xb10b('0x50')](_0x5ea150[_0xb10b('0x38')]);_0xcc4252[_0xb10b('0x39')]=_[_0xb10b('0x3a')](_0xcc4252[_0xb10b('0x37')],_0xcc4252[_0xb10b('0x38')]);_0x484fed[_0xb10b('0x3c')]=_['intersection'](_0xcc4252[_0xb10b('0x37')],qs[_0xb10b('0x3b')](_0x5ea150[_0xb10b('0x38')]['fields']));_0x484fed[_0xb10b('0x3c')]=_0x484fed[_0xb10b('0x3c')]['length']?_0x484fed[_0xb10b('0x3c')]:_0xcc4252[_0xb10b('0x37')];if(_0x5ea150['query']['includeAll']){_0x484fed[_0xb10b('0x4a')]=[{'all':!![]}];}_0x484fed=_[_0xb10b('0x46')]({},_0x484fed,_0x5ea150[_0xb10b('0x47')]);return db[_0xb10b('0x32')][_0xb10b('0x51')](_0x484fed)[_0xb10b('0x28')](handleEntityNotFound(_0x9179ee,null))[_0xb10b('0x28')](respondWithResult(_0x9179ee,null))['catch'](handleError(_0x9179ee,null));};exports[_0xb10b('0x52')]=function(_0xe74ec7,_0x3684c9,_0x22c07a){return db[_0xb10b('0x32')][_0xb10b('0x51')]({'where':{'id':_0xe74ec7[_0xb10b('0x4f')]['id']},'attributes':['name',_0xb10b('0x53')],'raw':!![]})[_0xb10b('0x28')](handleEntityNotFound(_0x3684c9,null))[_0xb10b('0x28')](function(_0x57b558){if(_0x57b558){var _0x1b3214=path[_0xb10b('0x54')](config['root'],_0xb10b('0x55'),util[_0xb10b('0x56')]('%s.zip',path[_0xb10b('0x57')](_0x57b558[_0xb10b('0x53')])));var _0x2f182a=fs[_0xb10b('0x58')](_0x1b3214);var _0x40b4c7=archiver(_0xb10b('0x59'),{'zlib':{'level':0x9}});_0x40b4c7['on'](_0xb10b('0x5a'),function(_0x12554c){if(_0x12554c[_0xb10b('0x5b')]===_0xb10b('0x5c')){logger[_0xb10b('0x2d')](_0x12554c);}else{throw new db[(_0xb10b('0x5d'))][(_0xb10b('0x5e'))](_0xb10b('0x5f'));}});_0x40b4c7['on'](_0xb10b('0x2d'),function(_0x1eb490){throw new db[(_0xb10b('0x5d'))][(_0xb10b('0x5e'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');});_0x40b4c7[_0xb10b('0x60')](_0x2f182a);_0x40b4c7[_0xb10b('0x61')](_0xb10b('0x62'),{'cwd':path[_0xb10b('0x54')](config['root'],_0xb10b('0x55'),path[_0xb10b('0x63')](_0x57b558['path'])),'ignore':[path[_0xb10b('0x54')](path['basename'](_0x57b558['path']),_0xb10b('0x64')),path[_0xb10b('0x54')](path[_0xb10b('0x57')](_0x57b558[_0xb10b('0x53')]),_0xb10b('0x65'))],'nodir':!![]})[_0xb10b('0x66')]();_0x2f182a['on']('close',function(){if(!fs[_0xb10b('0x67')](_0x1b3214)){throw new db['Sequelize'][(_0xb10b('0x5e'))](_0xb10b('0x68'));}return _0x3684c9[_0xb10b('0x52')](_0x1b3214,util['format'](_0xb10b('0x69'),path[_0xb10b('0x57')](_0x57b558[_0xb10b('0x53')])),function(_0x3e8adc){if(_0x3e8adc){throw new db[(_0xb10b('0x5d'))][(_0xb10b('0x5e'))]('Error\x20while\x20downloading\x20the\x20plugin');}fs[_0xb10b('0x6a')](_0x1b3214);logger['info']('Download\x20completed');logger['info'](_0xb10b('0x6b'));});});}return null;})[_0xb10b('0x4d')](handleError(_0x3684c9,null));};exports[_0xb10b('0x6c')]=function(_0x5e0b24,_0xdb8a5a,_0x5c4160){var _0xec8ef6=path['basename'](_0x5e0b24[_0xb10b('0x6d')][_0xb10b('0x6e')],path['extname'](_0x5e0b24['file'][_0xb10b('0x6e')]));var _0x1f5bb2=path[_0xb10b('0x54')](config[_0xb10b('0x6f')],_0xb10b('0x55'),_0x5e0b24[_0xb10b('0x6d')][_0xb10b('0x6e')]);var _0x41993=path['join'](config[_0xb10b('0x6f')],_0xb10b('0x55'),_0xec8ef6);logger[_0xb10b('0x70')](_0xb10b('0x71'),_0x1f5bb2);logger[_0xb10b('0x70')](_0xb10b('0x72'),_0x41993);try{fs[_0xb10b('0x73')](_0x1f5bb2,parseInt('0777',0x8));extract(_0x1f5bb2,{'dir':_0x41993},function(_0x18a8de){if(_0x18a8de){logger[_0xb10b('0x2d')](_0x18a8de);handleError(_0x18a8de,!![]);};var _0x30a674=fs[_0xb10b('0x74')](_0x41993);if(_0x30a674[_0xb10b('0x3d')]>0x1){removeReferences(_0x1f5bb2,_0x41993);logger[_0xb10b('0x2d')](_0xb10b('0x75'));return _0x5c4160(new Error(_0xb10b('0x75')));}var _0x46b9e2=fs[_0xb10b('0x76')](path[_0xb10b('0x54')](_0x41993,_0x30a674[0x0]));if(_0x46b9e2[_0xb10b('0x77')]()){removeReferences(_0x1f5bb2,_0x41993);logger[_0xb10b('0x2d')](_0xb10b('0x75'));return _0x5c4160(new Error(_0xb10b('0x75')));}if(_0x46b9e2[_0xb10b('0x78')]()){var _0x5a18e0=fs[_0xb10b('0x74')](path[_0xb10b('0x54')](_0x41993,_0x30a674[0x0]));if(_0x5a18e0[_0xb10b('0x3d')]===0x0){removeReferences(_0x1f5bb2,_0x41993);logger[_0xb10b('0x2d')](_0xb10b('0x75'));return _0x5c4160(new Error(_0xb10b('0x75')));}var _0x162580=_0x5a18e0[_0xb10b('0x79')](function(_0x1fc1dc){return _0x1fc1dc===_0xb10b('0x7a');});if(!_0x162580){return _0x5c4160(new Error(_0xb10b('0x7b')));}var _0x3916f0=fs[_0xb10b('0x7c')](path['join'](_0x41993,_0x30a674[0x0],_0xb10b('0x7a')));var _0x1981d9=JSON['parse'](_0x3916f0);if(_0xb10b('0x7d')==typeof _0x1981d9[_0xb10b('0x2e')]){return _0x5c4160(new Error(_0xb10b('0x7e')));}if(_0xb10b('0x7d')==typeof _0x1981d9[_0xb10b('0x35')]){return _0x5c4160(new Error(_0xb10b('0x7f')));}if(_0xb10b('0x7d')==typeof _0x1981d9[_0xb10b('0x80')]){return _0x5c4160(new Error(_0xb10b('0x81')));}if('undefined'==typeof _0x1981d9[_0xb10b('0x82')]){return _0x5c4160(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x1981d9[_0xb10b('0x35')]==='html'){if(_0xb10b('0x7d')==typeof _0x1981d9['parameters'][_0xb10b('0x83')]){return _0x5c4160(new Error(_0xb10b('0x84')));}if('undefined'==typeof _0x1981d9['parameters'][_0xb10b('0x83')]['admin']&&_0xb10b('0x7d')==typeof _0x1981d9[_0xb10b('0x82')]['views']['agent']){return _0x5c4160(new Error(_0xb10b('0x85')));}}else if(_0x1981d9[_0xb10b('0x35')]===_0xb10b('0x86')){if(_0xb10b('0x7d')==typeof _0x1981d9[_0xb10b('0x82')]['scriptName']){return _0x5c4160(new Error(_0xb10b('0x87')));}if(_0xb10b('0x7d')==typeof _0x1981d9['parameters'][_0xb10b('0x88')]){return _0x5c4160(new Error(_0xb10b('0x89')));}}else{return _0x5c4160(new Error(_0xb10b('0x8a')));}var _0x113f86=_0x1981d9['name'];var _0x81b387=_0x1981d9[_0xb10b('0x8b')];var _0x278b63=_0x1981d9[_0xb10b('0x35')];var _0x26e123=_0x1981d9[_0xb10b('0x8c')]?_0x1981d9[_0xb10b('0x8c')]:_0xb10b('0x8d');var _0x3f6448=_0x1981d9[_0xb10b('0x8e')]?_0x1981d9[_0xb10b('0x8e')]:_0xb10b('0x8f');var _0x556e25='';var _0x3dfc43='';var _0x336328='';var _0x1c031f='';var _0x554417=_0x1981d9[_0xb10b('0x80')];if(_0x278b63===_0xb10b('0x90')){if(_0xb10b('0x7d')!=typeof _0x1981d9['parameters'][_0xb10b('0x83')][_0xb10b('0x91')]){var _0x50598f=_0x1981d9[_0xb10b('0x82')][_0xb10b('0x83')][_0xb10b('0x91')];if(!/^(f|ht)tps?:\/\//i['test'](_0x50598f)){_0x556e25=path[_0xb10b('0x54')](_0xb10b('0x92'),_0xec8ef6,_0x30a674[0x0],_0x50598f);}else{_0x556e25=_0x50598f;}}else{logger[_0xb10b('0x70')]('Warning:\x20admin\x20view\x20not\x20specified');}if(_0xb10b('0x7d')!=typeof _0x1981d9[_0xb10b('0x82')]['views'][_0xb10b('0x93')]){var _0x3f3c30=_0x1981d9[_0xb10b('0x82')][_0xb10b('0x83')][_0xb10b('0x93')];if(!/^(f|ht)tps?:\/\//i[_0xb10b('0x94')](_0x3f3c30)){_0x3dfc43=path[_0xb10b('0x54')]('plugins',_0xec8ef6,_0x30a674[0x0],_0x3f3c30);}else{_0x3dfc43=_0x3f3c30;}}else{logger[_0xb10b('0x70')](_0xb10b('0x95'));}}else if(_0x278b63===_0xb10b('0x86')){_0x336328=_0x1981d9['parameters'][_0xb10b('0x96')];_0x1c031f=_0x1981d9[_0xb10b('0x82')][_0xb10b('0x88')];if(_0xb10b('0x7d')!=typeof _0x1981d9[_0xb10b('0x82')][_0xb10b('0x83')]){if(_0xb10b('0x7d')!=typeof _0x1981d9[_0xb10b('0x82')]['views']['admin']){var _0x50598f=_0x1981d9[_0xb10b('0x82')]['views'][_0xb10b('0x91')];if(!/^(f|ht)tps?:\/\//i[_0xb10b('0x94')](_0x50598f)){_0x556e25=path[_0xb10b('0x54')](_0xb10b('0x92'),_0xec8ef6,_0x30a674[0x0],_0x50598f);}else{_0x556e25=_0x50598f;}}if(_0xb10b('0x7d')!=typeof _0x1981d9['parameters'][_0xb10b('0x83')][_0xb10b('0x93')]){var _0x3f3c30=_0x1981d9[_0xb10b('0x82')][_0xb10b('0x83')][_0xb10b('0x93')];if(!/^(f|ht)tps?:\/\//i[_0xb10b('0x94')](_0x3f3c30)){_0x3dfc43=path[_0xb10b('0x54')](_0xb10b('0x92'),_0xec8ef6,_0x30a674[0x0],_0x3f3c30);}else{_0x3dfc43=_0x3f3c30;}}}}var _0x14ab51={'name':_0x113f86,'description':_0x81b387,'path':path[_0xb10b('0x54')](_0xec8ef6,_0x30a674[0x0]),'type':_0x278b63,'sidebar':_0x26e123,'icon':_0x3f6448,'adminUrl':_0x556e25,'agentUrl':_0x3dfc43,'scriptName':_0x336328,'scriptPath':_0x1c031f,'version':_0x554417};removeReferences(_0x1f5bb2,null);return db[_0xb10b('0x32')][_0xb10b('0x97')](_0x14ab51)[_0xb10b('0x28')](function(_0x28927c){var _0x41ea3d={'role':_0x5e0b24[_0xb10b('0x98')]['role'],'userProfileId':_0x5e0b24[_0xb10b('0x98')][_0xb10b('0x99')]};if(!_0x41ea3d)throw new Error(_0xb10b('0x9a'));if(_0x41ea3d[_0xb10b('0x9b')]===_0xb10b('0x9c')){var _0x147198=_0x28927c[_0xb10b('0x9d')]({'plain':!![]});return db[_0xb10b('0x9e')]['find']({'where':{'name':_0xb10b('0x2a'),'userProfileId':_0x41ea3d[_0xb10b('0x99')]},'raw':!![]})[_0xb10b('0x28')](function(_0x461df6){if(_0x461df6&&_0x461df6[_0xb10b('0x9f')]===0x0){return db[_0xb10b('0x2b')][_0xb10b('0x97')]({'name':_0x147198[_0xb10b('0x2e')],'resourceId':_0x147198['id'],'type':_0x461df6[_0xb10b('0x2e')],'sectionId':_0x461df6['id']},{})[_0xb10b('0x28')](function(){return _0x28927c;});}else{return _0x28927c;}})['catch'](function(_0x268e3a){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x268e3a);throw _0x268e3a;});}return _0x28927c;})[_0xb10b('0x28')](respondWithResult(_0xdb8a5a,null))[_0xb10b('0x4d')](handleError(_0xdb8a5a,null));}});}catch(_0x4b36df){_0xdb8a5a['status'](0x1f4)[_0xb10b('0x2f')](_0x4b36df);}};function removeReferences(_0x485edc,_0x271cd3){try{if(_0x485edc){fs[_0xb10b('0x6a')](_0x485edc);logger[_0xb10b('0x70')](_0xb10b('0xa0'));}if(_0x271cd3){rimraf(_0x271cd3,function(){});logger[_0xb10b('0x70')](_0xb10b('0xa1'));}}catch(_0x28ffbc){logger[_0xb10b('0x2d')](_0x28ffbc);}}exports[_0xb10b('0x27')]=function(_0x29aaa8,_0x22d441,_0x3197fa){return db['Plugin'][_0xb10b('0x51')]({'where':{'id':_0x29aaa8['params']['id']}})[_0xb10b('0x28')](handleEntityNotFound(_0x22d441,null))[_0xb10b('0x28')](saveUpdates(_0x29aaa8[_0xb10b('0x98')],null))['then'](respondWithResult(_0x22d441,null))[_0xb10b('0x4d')](handleError(_0x22d441,null));};exports[_0xb10b('0xa2')]=function(_0x38ca07,_0x96cbf5,_0x31697d){return db['Plugin'][_0xb10b('0x51')]({'where':{'id':_0x38ca07[_0xb10b('0x4f')]['id']}})['then'](function(_0x4d49d3){if(_0x4d49d3){return _0x4d49d3[_0xb10b('0x29')]();}})[_0xb10b('0x28')](function(_0x18a734){rimraf(path[_0xb10b('0x54')](config[_0xb10b('0x6f')],'server/files/plugins',path[_0xb10b('0x63')](_0x18a734['path'])),function(){});return _0x18a734;})[_0xb10b('0x28')](handleEntityNotFound(_0x96cbf5,null))[_0xb10b('0x28')](respondWithStatusCode(_0x96cbf5,null))['catch'](handleError(_0x96cbf5,null));};exports[_0xb10b('0xa3')]=function(_0x4049a1,_0x4510ad,_0xd5a636){return BPromise[_0xb10b('0xa4')]()['then'](function(){if(!_0x4049a1[_0xb10b('0x38')][_0xb10b('0x53')]){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x4049a1[_0xb10b('0x38')][_0xb10b('0xa5')]){throw new Error(_0xb10b('0xa6'));}var _0x3d0f22=_0x4049a1[_0xb10b('0x38')]['hostname']?_0x4049a1['query'][_0xb10b('0xa7')]+':'+_0x4049a1[_0xb10b('0x38')]['port']:'http://localhost:'+_0x4049a1[_0xb10b('0x38')]['port'];var _0x37405f=_0x4049a1[_0xb10b('0x38')][_0xb10b('0x23')]?_0x4049a1[_0xb10b('0x38')][_0xb10b('0x23')]:!![];var _0x53574c=_0x4049a1[_0xb10b('0x38')][_0xb10b('0xa8')]?_0x4049a1[_0xb10b('0x38')]['encoding']:null;var _0xc53669={'method':_0x4049a1['method'],'uri':util[_0xb10b('0x56')](_0xb10b('0xa9'),_0x3d0f22,_0x4049a1[_0xb10b('0x38')][_0xb10b('0x53')]),'json':_0x37405f,'resolveWithFullResponse':!![],'encoding':_0x53574c,'qs':_0x4049a1[_0xb10b('0x38')]};if(_0x4049a1['headers']){_0xc53669[_0xb10b('0xaa')]=_0x4049a1['headers'];if(_0xc53669[_0xb10b('0xaa')][_0xb10b('0xab')]){delete _0xc53669[_0xb10b('0xaa')][_0xb10b('0xab')];}}if(_0xc53669[_0xb10b('0xaa')]['content-type']){delete _0xc53669[_0xb10b('0xaa')][_0xb10b('0xac')];}return rp(_0xc53669);})[_0xb10b('0x28')](function(_0x4ec829){if(_0x4ec829){_0x4510ad[_0xb10b('0x21')](_0x4ec829[_0xb10b('0xaa')]);logger[_0xb10b('0x70')](_0x4ec829[_0xb10b('0x98')]);if(_[_0xb10b('0xad')](_0x4049a1['query']['path'],'download')&&_0x4ec829[_0xb10b('0xae')]==0x1f4){return _0x4510ad['sendStatus'](_0x4ec829[_0xb10b('0xae')]);}else{return _0x4510ad[_0xb10b('0x20')](_0x4ec829[_0xb10b('0xae')])[_0xb10b('0x2f')](_0x4ec829[_0xb10b('0x98')]);}}else{return _0x4510ad[_0xb10b('0x1f')](0xc8);}})[_0xb10b('0x4d')](handleError(_0x4510ad,null));};exports[_0xb10b('0xaf')]=function(_0x56e2d3,_0x2e03ba,_0x356ea7){return BPromise[_0xb10b('0xa4')]()[_0xb10b('0x28')](function(){if(!_0x56e2d3['query'][_0xb10b('0x53')]){throw new Error(_0xb10b('0xb0'));}if(!_0x56e2d3[_0xb10b('0x38')][_0xb10b('0xa5')]){throw new Error(_0xb10b('0xa6'));}var _0x2de57e=_0x56e2d3['query'][_0xb10b('0xa7')]?_0x56e2d3['query'][_0xb10b('0xa7')]+':'+_0x56e2d3[_0xb10b('0x38')][_0xb10b('0xa5')]:_0xb10b('0xb1')+_0x56e2d3[_0xb10b('0x38')][_0xb10b('0xa5')];var _0x30e4c2=_0x56e2d3['query'][_0xb10b('0x23')]?_0x56e2d3[_0xb10b('0x38')]['json']:!![];var _0x45f834=_0x56e2d3[_0xb10b('0x38')][_0xb10b('0xa8')]?_0x56e2d3['query']['encoding']:null;var _0x5e2441={'method':_0x56e2d3[_0xb10b('0xb2')],'uri':util[_0xb10b('0x56')]('%s%s',_0x2de57e,_0x56e2d3['query'][_0xb10b('0x53')]),'json':_0x30e4c2,'resolveWithFullResponse':!![],'encoding':_0x45f834,'body':_0x56e2d3['body']};if(_0x56e2d3[_0xb10b('0xaa')]){_0x5e2441[_0xb10b('0xaa')]=_0x56e2d3['headers'];if(_0x5e2441[_0xb10b('0xaa')][_0xb10b('0xab')]){delete _0x5e2441[_0xb10b('0xaa')][_0xb10b('0xab')];}}if(_0x5e2441[_0xb10b('0xaa')]['content-type']){delete _0x5e2441['headers']['content-type'];}return rp(_0x5e2441);})['then'](function(_0x185fb2){if(_0x185fb2){_0x2e03ba[_0xb10b('0x21')](_0x185fb2[_0xb10b('0xaa')]);logger[_0xb10b('0x70')](_0x185fb2['body']);return _0x2e03ba[_0xb10b('0x20')](_0x185fb2['statusCode'])[_0xb10b('0x2f')](_0x185fb2[_0xb10b('0x98')]);}else{return _0x2e03ba[_0xb10b('0x1f')](0xc8);}})[_0xb10b('0x4d')](handleError(_0x2e03ba,null));};