Built motion from commit 1efd3d96.|2.6.31
[motion2.git] / server / api / plugin / plugin.controller.js
index a438682..e4d681c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x18f0=['agent','scriptName','create','body','role','user','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','\x27PATH\x27\x20parameter\x20not\x20specified','hostname','port','http://localhost:','encoding','%s%s','headers','content-length','content-type','endsWith','statusCode','webhookPost','resolve','\x27PORT\x27\x20parameter\x20not\x20specified','method','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','extract-zip','../../components/auth/service','../../components/parsers/qs','api','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','localhost','socket.io-emitter','./plugin.socket','register','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','destroy','then','get','Plugins','UserProfileResource','sendStatus','stack','name','send','map','Plugin','type','model','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','rawAttributes','find','catch','download','join','root','server/files/plugins','format','%s.zip','basename','zip','warning','code','ENOENT','error','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','**/*','dirname','node_modules/**/*','attachments/**/*','finalize','close','existsSync','Plugin\x20not\x20found','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Temporary\x20file\x20removed','upload','file','filename','extname','Plugin\x20upload\x20filepath:\x20%s','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','isDirectory','manifest.json','Plugin\x20manifest\x20missing','readFileSync','parse','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','views','admin','Invalid\x20manifest:\x20no\x20view\x20specified','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','icon','icon-apps','html','test','plugins','Warning:\x20admin\x20view\x20not\x20specified'];(function(_0x3ce64e,_0xc28f93){var _0x3698b1=function(_0x42f75d){while(--_0x42f75d){_0x3ce64e['push'](_0x3ce64e['shift']());}};_0x3698b1(++_0xc28f93);}(_0x18f0,0xc4));var _0x018f=function(_0x1b3ed9,_0x23c04){_0x1b3ed9=_0x1b3ed9-0x0;var _0x5a8e35=_0x18f0[_0x1b3ed9];return _0x5a8e35;};'use strict';var emlformat=require(_0x018f('0x0'));var rimraf=require(_0x018f('0x1'));var zipdir=require(_0x018f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x018f('0x3'));var moment=require(_0x018f('0x4'));var BPromise=require(_0x018f('0x5'));var Mustache=require(_0x018f('0x6'));var util=require('util');var path=require(_0x018f('0x7'));var sox=require('sox');var csv=require(_0x018f('0x8'));var ejs=require(_0x018f('0x9'));var fs=require('fs');var fs_extra=require(_0x018f('0xa'));var _=require(_0x018f('0xb'));var squel=require(_0x018f('0xc'));var crypto=require(_0x018f('0xd'));var jsforce=require(_0x018f('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x018f('0x8'));var querystring=require(_0x018f('0xf'));var Papa=require('papaparse');var extract=require(_0x018f('0x10'));var rimraf=require(_0x018f('0x1'));var archiver=require('archiver');var Redis=require('ioredis');var authService=require(_0x018f('0x11'));var qs=require(_0x018f('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x018f('0x13'));var utils=require(_0x018f('0x14'));var config=require(_0x018f('0x15'));var licenseUtil=require(_0x018f('0x16'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x018f('0x17')](config[_0x018f('0x18')],{'host':_0x018f('0x19'),'port':0x18eb});var socket=require(_0x018f('0x1a'))(new Redis(config[_0x018f('0x18')]));require(_0x018f('0x1b'))[_0x018f('0x1c')](socket);function respondWithStatusCode(_0x2aa872,_0x3e7c14){_0x3e7c14=_0x3e7c14||0xcc;return function(_0x74bf9e){if(_0x74bf9e){return _0x2aa872['sendStatus'](_0x3e7c14);}return _0x2aa872[_0x018f('0x1d')](_0x3e7c14)[_0x018f('0x1e')]();};}function respondWithResult(_0x52a55e,_0x1eeeff){_0x1eeeff=_0x1eeeff||0xc8;return function(_0x1395c1){if(_0x1395c1){return _0x52a55e['status'](_0x1eeeff)[_0x018f('0x1f')](_0x1395c1);}};}function respondWithFilteredResult(_0x14b9ac,_0x41807f){return function(_0x45aad6){if(_0x45aad6){var _0x35e43d=typeof _0x41807f[_0x018f('0x20')]===_0x018f('0x21')&&typeof _0x41807f[_0x018f('0x22')]===_0x018f('0x21');var _0x3e7250=_0x45aad6[_0x018f('0x23')];var _0x5773c6=_0x35e43d?0x0:_0x41807f[_0x018f('0x20')];var _0x334cde=_0x35e43d?_0x45aad6['count']:_0x41807f[_0x018f('0x20')]+_0x41807f[_0x018f('0x22')];var _0x3bf329;if(_0x334cde>=_0x3e7250){_0x334cde=_0x3e7250;_0x3bf329=0xc8;}else{_0x3bf329=0xce;}_0x14b9ac[_0x018f('0x1d')](_0x3bf329);return _0x14b9ac[_0x018f('0x24')](_0x018f('0x25'),_0x5773c6+'-'+_0x334cde+'/'+_0x3e7250)[_0x018f('0x1f')](_0x45aad6);}return null;};}function patchUpdates(_0x2aab4c){return function(_0x21db3c){try{jsonpatch[_0x018f('0x26')](_0x21db3c,_0x2aab4c,!![]);}catch(_0x438bb7){return BPromise['reject'](_0x438bb7);}return _0x21db3c[_0x018f('0x27')]();};}function saveUpdates(_0x13bfcd,_0x747429){return function(_0x37d5fd){if(_0x37d5fd){return _0x37d5fd['update'](_0x13bfcd)['then'](function(_0x1e3da6){return _0x1e3da6;});}return null;};}function removeEntity(_0x54145f,_0x41aefa){return function(_0x2cf4d7){if(_0x2cf4d7){return _0x2cf4d7[_0x018f('0x28')]()[_0x018f('0x29')](function(){var _0x2ab947=_0x2cf4d7[_0x018f('0x2a')]({'plain':!![]});var _0x425309=_0x018f('0x2b');return db[_0x018f('0x2c')][_0x018f('0x28')]({'where':{'type':_0x425309,'resourceId':_0x2ab947['id']}})[_0x018f('0x29')](function(){return _0x2cf4d7;});})[_0x018f('0x29')](function(){_0x54145f[_0x018f('0x1d')](0xcc)[_0x018f('0x1e')]();});}};}function handleEntityNotFound(_0x24aa27,_0x450f3d){return function(_0x56a330){if(!_0x56a330){_0x24aa27[_0x018f('0x2d')](0x194);}return _0x56a330;};}function handleError(_0x88ccad,_0x19af77){_0x19af77=_0x19af77||0x1f4;return function(_0x22e6fb){logger['error'](_0x22e6fb[_0x018f('0x2e')]);if(_0x22e6fb[_0x018f('0x2f')]){delete _0x22e6fb[_0x018f('0x2f')];}_0x88ccad[_0x018f('0x1d')](_0x19af77)[_0x018f('0x30')](_0x22e6fb);};}exports['index']=function(_0x31c8ef,_0x4197d2){var _0x4f2ed0={},_0x2263cf={},_0x215429={'count':0x0,'rows':[]};var _0x2d8def=_[_0x018f('0x31')](db[_0x018f('0x32')]['rawAttributes'],function(_0x52af91){return{'name':_0x52af91['fieldName'],'type':_0x52af91[_0x018f('0x33')]['key']};});_0x2263cf[_0x018f('0x34')]=_[_0x018f('0x31')](_0x2d8def,_0x018f('0x2f'));_0x2263cf[_0x018f('0x35')]=_['keys'](_0x31c8ef[_0x018f('0x35')]);_0x2263cf[_0x018f('0x36')]=_['intersection'](_0x2263cf['model'],_0x2263cf[_0x018f('0x35')]);_0x4f2ed0[_0x018f('0x37')]=_[_0x018f('0x38')](_0x2263cf['model'],qs[_0x018f('0x39')](_0x31c8ef[_0x018f('0x35')][_0x018f('0x39')]));_0x4f2ed0['attributes']=_0x4f2ed0['attributes'][_0x018f('0x3a')]?_0x4f2ed0['attributes']:_0x2263cf[_0x018f('0x34')];if(!_0x31c8ef[_0x018f('0x35')][_0x018f('0x3b')](_0x018f('0x3c'))){_0x4f2ed0[_0x018f('0x22')]=qs[_0x018f('0x22')](_0x31c8ef['query'][_0x018f('0x22')]);_0x4f2ed0[_0x018f('0x20')]=qs['offset'](_0x31c8ef[_0x018f('0x35')]['offset']);}_0x4f2ed0[_0x018f('0x3d')]=qs[_0x018f('0x3e')](_0x31c8ef[_0x018f('0x35')][_0x018f('0x3e')]);_0x4f2ed0['where']=qs[_0x018f('0x36')](_[_0x018f('0x3f')](_0x31c8ef['query'],_0x2263cf['filters']),_0x2d8def);if(_0x31c8ef[_0x018f('0x35')][_0x018f('0x40')]){_0x4f2ed0[_0x018f('0x41')]=_[_0x018f('0x42')](_0x4f2ed0[_0x018f('0x41')],{'$or':_[_0x018f('0x31')](_0x2d8def,function(_0x24401f){if(_0x24401f[_0x018f('0x33')]!==_0x018f('0x43')){var _0x20a958={};_0x20a958[_0x24401f['name']]={'$like':'%'+_0x31c8ef[_0x018f('0x35')][_0x018f('0x40')]+'%'};return _0x20a958;}})});}_0x4f2ed0=_[_0x018f('0x42')]({},_0x4f2ed0,_0x31c8ef[_0x018f('0x44')]);var _0x3b1464={'where':_0x4f2ed0[_0x018f('0x41')]};return db['Plugin'][_0x018f('0x23')](_0x3b1464)[_0x018f('0x29')](function(_0x41682f){_0x215429[_0x018f('0x23')]=_0x41682f;if(_0x31c8ef[_0x018f('0x35')][_0x018f('0x45')]){_0x4f2ed0[_0x018f('0x46')]=[{'all':!![]}];}return db['Plugin'][_0x018f('0x47')](_0x4f2ed0);})[_0x018f('0x29')](function(_0x5d0606){_0x215429[_0x018f('0x48')]=_0x5d0606;return _0x215429;})[_0x018f('0x29')](respondWithFilteredResult(_0x4197d2,_0x4f2ed0))['catch'](handleError(_0x4197d2,null));};exports[_0x018f('0x49')]=function(_0x28c7a2,_0x3b4c32){var _0x5e7add={'raw':!![],'where':{'id':_0x28c7a2[_0x018f('0x4a')]['id']}},_0x3eae8f={};_0x3eae8f[_0x018f('0x34')]=_[_0x018f('0x4b')](db[_0x018f('0x32')][_0x018f('0x4c')]);_0x3eae8f[_0x018f('0x35')]=_['keys'](_0x28c7a2[_0x018f('0x35')]);_0x3eae8f[_0x018f('0x36')]=_[_0x018f('0x38')](_0x3eae8f[_0x018f('0x34')],_0x3eae8f[_0x018f('0x35')]);_0x5e7add[_0x018f('0x37')]=_[_0x018f('0x38')](_0x3eae8f[_0x018f('0x34')],qs[_0x018f('0x39')](_0x28c7a2[_0x018f('0x35')]['fields']));_0x5e7add[_0x018f('0x37')]=_0x5e7add[_0x018f('0x37')][_0x018f('0x3a')]?_0x5e7add[_0x018f('0x37')]:_0x3eae8f[_0x018f('0x34')];if(_0x28c7a2['query'][_0x018f('0x45')]){_0x5e7add[_0x018f('0x46')]=[{'all':!![]}];}_0x5e7add=_[_0x018f('0x42')]({},_0x5e7add,_0x28c7a2[_0x018f('0x44')]);return db[_0x018f('0x32')][_0x018f('0x4d')](_0x5e7add)[_0x018f('0x29')](handleEntityNotFound(_0x3b4c32,null))[_0x018f('0x29')](respondWithResult(_0x3b4c32,null))[_0x018f('0x4e')](handleError(_0x3b4c32,null));};exports[_0x018f('0x4f')]=function(_0xe1db6,_0x538bf1,_0x4234a9){return db['Plugin'][_0x018f('0x4d')]({'where':{'id':_0xe1db6[_0x018f('0x4a')]['id']},'attributes':[_0x018f('0x2f'),_0x018f('0x7')],'raw':!![]})[_0x018f('0x29')](handleEntityNotFound(_0x538bf1,null))['then'](function(_0x45b7b3){if(_0x45b7b3){var _0x3b42aa=path[_0x018f('0x50')](config[_0x018f('0x51')],_0x018f('0x52'),util[_0x018f('0x53')](_0x018f('0x54'),path[_0x018f('0x55')](_0x45b7b3[_0x018f('0x7')])));var _0x46fe5c=fs['createWriteStream'](_0x3b42aa);var _0xca44ac=archiver(_0x018f('0x56'),{'zlib':{'level':0x9}});_0xca44ac['on'](_0x018f('0x57'),function(_0x14b39e){if(_0x14b39e[_0x018f('0x58')]===_0x018f('0x59')){logger[_0x018f('0x5a')](_0x14b39e);}else{throw new db[(_0x018f('0x5b'))][(_0x018f('0x5c'))](_0x018f('0x5d'));}});_0xca44ac['on']('error',function(_0x2902d6){throw new db['Sequelize'][(_0x018f('0x5c'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');});_0xca44ac[_0x018f('0x5e')](_0x46fe5c);_0xca44ac['glob'](_0x018f('0x5f'),{'cwd':path[_0x018f('0x50')](config[_0x018f('0x51')],_0x018f('0x52'),path[_0x018f('0x60')](_0x45b7b3[_0x018f('0x7')])),'ignore':[path[_0x018f('0x50')](path['basename'](_0x45b7b3[_0x018f('0x7')]),_0x018f('0x61')),path['join'](path[_0x018f('0x55')](_0x45b7b3['path']),_0x018f('0x62'))],'nodir':!![]})[_0x018f('0x63')]();_0x46fe5c['on'](_0x018f('0x64'),function(){if(!fs[_0x018f('0x65')](_0x3b42aa)){throw new db[(_0x018f('0x5b'))][(_0x018f('0x5c'))](_0x018f('0x66'));}return _0x538bf1[_0x018f('0x4f')](_0x3b42aa,util['format'](_0x018f('0x54'),path[_0x018f('0x55')](_0x45b7b3[_0x018f('0x7')])),function(_0x2ede23){if(_0x2ede23){throw new db[(_0x018f('0x5b'))][(_0x018f('0x5c'))](_0x018f('0x67'));}fs[_0x018f('0x68')](_0x3b42aa);logger['info']('Download\x20completed');logger[_0x018f('0x69')](_0x018f('0x6a'));});});}return null;})[_0x018f('0x4e')](handleError(_0x538bf1,null));};exports[_0x018f('0x6b')]=function(_0x2f15fb,_0x3c3a49,_0xf2795a){var _0x27fda2=path['basename'](_0x2f15fb[_0x018f('0x6c')][_0x018f('0x6d')],path[_0x018f('0x6e')](_0x2f15fb[_0x018f('0x6c')]['filename']));var _0xfd6c6e=path['join'](config[_0x018f('0x51')],_0x018f('0x52'),_0x2f15fb[_0x018f('0x6c')]['filename']);var _0x1de3c3=path['join'](config['root'],_0x018f('0x52'),_0x27fda2);logger[_0x018f('0x69')](_0x018f('0x6f'),_0xfd6c6e);logger['info']('Plugin\x20upload\x20destination:\x20%s',_0x1de3c3);try{fs['chmodSync'](_0xfd6c6e,parseInt(_0x018f('0x70'),0x8));extract(_0xfd6c6e,{'dir':_0x1de3c3},function(_0x347d47){if(_0x347d47){logger[_0x018f('0x5a')](_0x347d47);handleError(_0x347d47,!![]);};var _0x565261=fs[_0x018f('0x71')](_0x1de3c3);if(_0x565261[_0x018f('0x3a')]>0x1){removeReferences(_0xfd6c6e,_0x1de3c3);logger[_0x018f('0x5a')](_0x018f('0x72'));return _0xf2795a(new Error('Invalid\x20plugin\x20structure'));}var _0x1b4f47=fs[_0x018f('0x73')](path['join'](_0x1de3c3,_0x565261[0x0]));if(_0x1b4f47[_0x018f('0x74')]()){removeReferences(_0xfd6c6e,_0x1de3c3);logger[_0x018f('0x5a')](_0x018f('0x72'));return _0xf2795a(new Error('Invalid\x20plugin\x20structure'));}if(_0x1b4f47[_0x018f('0x75')]()){var _0x5b9ecf=fs[_0x018f('0x71')](path[_0x018f('0x50')](_0x1de3c3,_0x565261[0x0]));if(_0x5b9ecf[_0x018f('0x3a')]===0x0){removeReferences(_0xfd6c6e,_0x1de3c3);logger['error'](_0x018f('0x72'));return _0xf2795a(new Error('Invalid\x20plugin\x20structure'));}var _0x1f3387=_0x5b9ecf['some'](function(_0x3f90cc){return _0x3f90cc===_0x018f('0x76');});if(!_0x1f3387){return _0xf2795a(new Error(_0x018f('0x77')));}var _0x2dc740=fs[_0x018f('0x78')](path[_0x018f('0x50')](_0x1de3c3,_0x565261[0x0],'manifest.json'));var _0x3818e8=JSON[_0x018f('0x79')](_0x2dc740);if(_0x018f('0x21')==typeof _0x3818e8[_0x018f('0x2f')]){return _0xf2795a(new Error('Invalid\x20manifest:\x20name\x20missing'));}if('undefined'==typeof _0x3818e8[_0x018f('0x33')]){return _0xf2795a(new Error(_0x018f('0x7a')));}if('undefined'==typeof _0x3818e8[_0x018f('0x7b')]){return _0xf2795a(new Error(_0x018f('0x7c')));}if('undefined'==typeof _0x3818e8[_0x018f('0x7d')]){return _0xf2795a(new Error(_0x018f('0x7e')));}if(_0x3818e8['type']==='html'){if(_0x018f('0x21')==typeof _0x3818e8['parameters'][_0x018f('0x7f')]){return _0xf2795a(new Error('Invalid\x20manifest:\x20views\x20missing'));}if(_0x018f('0x21')==typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')][_0x018f('0x80')]&&_0x018f('0x21')==typeof _0x3818e8['parameters'][_0x018f('0x7f')]['agent']){return _0xf2795a(new Error(_0x018f('0x81')));}}else if(_0x3818e8['type']==='script'){if('undefined'==typeof _0x3818e8['parameters']['scriptName']){return _0xf2795a(new Error(_0x018f('0x82')));}if('undefined'==typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x83')]){return _0xf2795a(new Error(_0x018f('0x84')));}}else{return _0xf2795a(new Error(_0x018f('0x85')));}var _0x23af6a=_0x3818e8[_0x018f('0x2f')];var _0x413147=_0x3818e8[_0x018f('0x86')];var _0x23cf9f=_0x3818e8[_0x018f('0x33')];var _0x5d1597=_0x3818e8[_0x018f('0x87')]?_0x3818e8[_0x018f('0x87')]:'always';var _0x59ae10=_0x3818e8[_0x018f('0x88')]?_0x3818e8[_0x018f('0x88')]:_0x018f('0x89');var _0x3879b1='';var _0x437fb1='';var _0x48d460='';var _0x54e2b1='';var _0x1ab32f=_0x3818e8['version'];if(_0x23cf9f===_0x018f('0x8a')){if(_0x018f('0x21')!=typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')][_0x018f('0x80')]){var _0x33382e=_0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')][_0x018f('0x80')];if(!/^(f|ht)tps?:\/\//i[_0x018f('0x8b')](_0x33382e)){_0x3879b1=path[_0x018f('0x50')](_0x018f('0x8c'),_0x27fda2,_0x565261[0x0],_0x33382e);}else{_0x3879b1=_0x33382e;}}else{logger[_0x018f('0x69')](_0x018f('0x8d'));}if(_0x018f('0x21')!=typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')]['agent']){var _0xf5826c=_0x3818e8[_0x018f('0x7d')]['views'][_0x018f('0x8e')];if(!/^(f|ht)tps?:\/\//i[_0x018f('0x8b')](_0xf5826c)){_0x437fb1=path['join'](_0x018f('0x8c'),_0x27fda2,_0x565261[0x0],_0xf5826c);}else{_0x437fb1=_0xf5826c;}}else{logger[_0x018f('0x69')]('Warning:\x20agent\x20view\x20not\x20specified');}}else if(_0x23cf9f==='script'){_0x48d460=_0x3818e8['parameters'][_0x018f('0x8f')];_0x54e2b1=_0x3818e8[_0x018f('0x7d')]['scriptPath'];if(_0x018f('0x21')!=typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')]){if(_0x018f('0x21')!=typeof _0x3818e8[_0x018f('0x7d')]['views'][_0x018f('0x80')]){var _0x33382e=_0x3818e8[_0x018f('0x7d')]['views'][_0x018f('0x80')];if(!/^(f|ht)tps?:\/\//i['test'](_0x33382e)){_0x3879b1=path['join'](_0x018f('0x8c'),_0x27fda2,_0x565261[0x0],_0x33382e);}else{_0x3879b1=_0x33382e;}}if(_0x018f('0x21')!=typeof _0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')][_0x018f('0x8e')]){var _0xf5826c=_0x3818e8[_0x018f('0x7d')][_0x018f('0x7f')][_0x018f('0x8e')];if(!/^(f|ht)tps?:\/\//i[_0x018f('0x8b')](_0xf5826c)){_0x437fb1=path[_0x018f('0x50')](_0x018f('0x8c'),_0x27fda2,_0x565261[0x0],_0xf5826c);}else{_0x437fb1=_0xf5826c;}}}}var _0x524cb1={'name':_0x23af6a,'description':_0x413147,'path':path[_0x018f('0x50')](_0x27fda2,_0x565261[0x0]),'type':_0x23cf9f,'sidebar':_0x5d1597,'icon':_0x59ae10,'adminUrl':_0x3879b1,'agentUrl':_0x437fb1,'scriptName':_0x48d460,'scriptPath':_0x54e2b1,'version':_0x1ab32f};removeReferences(_0xfd6c6e,null);return db['Plugin'][_0x018f('0x90')](_0x524cb1)['then'](function(_0x1c5e18){var _0x16f61f={'role':_0x2f15fb[_0x018f('0x91')][_0x018f('0x92')],'userProfileId':_0x2f15fb['body']['userProfileId']};if(!_0x16f61f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x16f61f[_0x018f('0x92')]===_0x018f('0x93')){var _0x195c64=_0x1c5e18['get']({'plain':!![]});return db[_0x018f('0x94')][_0x018f('0x4d')]({'where':{'name':_0x018f('0x2b'),'userProfileId':_0x16f61f['userProfileId']},'raw':!![]})['then'](function(_0x24e41b){if(_0x24e41b&&_0x24e41b[_0x018f('0x95')]===0x0){return db[_0x018f('0x2c')][_0x018f('0x90')]({'name':_0x195c64['name'],'resourceId':_0x195c64['id'],'type':_0x24e41b[_0x018f('0x2f')],'sectionId':_0x24e41b['id']},{})[_0x018f('0x29')](function(){return _0x1c5e18;});}else{return _0x1c5e18;}})[_0x018f('0x4e')](function(_0x4a84ff){logger[_0x018f('0x5a')](_0x018f('0x96'),_0x4a84ff);throw _0x4a84ff;});}return _0x1c5e18;})[_0x018f('0x29')](respondWithResult(_0x3c3a49,null))['catch'](handleError(_0x3c3a49,null));}});}catch(_0x533db5){_0x3c3a49[_0x018f('0x1d')](0x1f4)[_0x018f('0x30')](_0x533db5);}};function removeReferences(_0x100cce,_0x191444){try{if(_0x100cce){fs['unlinkSync'](_0x100cce);logger[_0x018f('0x69')](_0x018f('0x97'));}if(_0x191444){rimraf(_0x191444,function(){});logger[_0x018f('0x69')](_0x018f('0x98'));}}catch(_0x504724){logger['error'](_0x504724);}}exports['update']=function(_0x595fb6,_0x36386e,_0x26586e){return db['Plugin']['find']({'where':{'id':_0x595fb6[_0x018f('0x4a')]['id']}})[_0x018f('0x29')](handleEntityNotFound(_0x36386e,null))[_0x018f('0x29')](saveUpdates(_0x595fb6['body'],null))[_0x018f('0x29')](respondWithResult(_0x36386e,null))[_0x018f('0x4e')](handleError(_0x36386e,null));};exports[_0x018f('0x99')]=function(_0xa651dc,_0x1ee2f7,_0x278d27){return db[_0x018f('0x32')][_0x018f('0x4d')]({'where':{'id':_0xa651dc[_0x018f('0x4a')]['id']}})['then'](function(_0x12e58a){if(_0x12e58a){return _0x12e58a[_0x018f('0x28')]();}})[_0x018f('0x29')](function(_0x2ac4df){rimraf(path[_0x018f('0x50')](config[_0x018f('0x51')],'server/files/plugins',path[_0x018f('0x60')](_0x2ac4df[_0x018f('0x7')])),function(){});return _0x2ac4df;})[_0x018f('0x29')](handleEntityNotFound(_0x1ee2f7,null))[_0x018f('0x29')](respondWithStatusCode(_0x1ee2f7,null))[_0x018f('0x4e')](handleError(_0x1ee2f7,null));};exports['webhookGet']=function(_0x265a3d,_0x4a4b16,_0x2e785e){return BPromise['resolve']()[_0x018f('0x29')](function(){if(!_0x265a3d[_0x018f('0x35')][_0x018f('0x7')]){throw new Error(_0x018f('0x9a'));}if(!_0x265a3d[_0x018f('0x35')]['port']){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0xd29198=_0x265a3d[_0x018f('0x35')][_0x018f('0x9b')]?_0x265a3d[_0x018f('0x35')][_0x018f('0x9b')]+':'+_0x265a3d[_0x018f('0x35')][_0x018f('0x9c')]:_0x018f('0x9d')+_0x265a3d[_0x018f('0x35')][_0x018f('0x9c')];var _0x5b5577=_0x265a3d['query'][_0x018f('0x1f')]?_0x265a3d['query'][_0x018f('0x1f')]:!![];var _0x36de28=_0x265a3d[_0x018f('0x35')][_0x018f('0x9e')]?_0x265a3d[_0x018f('0x35')][_0x018f('0x9e')]:null;var _0x350787={'method':_0x265a3d['method'],'uri':util['format'](_0x018f('0x9f'),_0xd29198,_0x265a3d[_0x018f('0x35')][_0x018f('0x7')]),'json':_0x5b5577,'resolveWithFullResponse':!![],'encoding':_0x36de28,'qs':_0x265a3d[_0x018f('0x35')]};if(_0x265a3d['headers']){_0x350787[_0x018f('0xa0')]=_0x265a3d['headers'];if(_0x350787['headers'][_0x018f('0xa1')]){delete _0x350787[_0x018f('0xa0')][_0x018f('0xa1')];}}if(_0x350787[_0x018f('0xa0')]['content-type']){delete _0x350787[_0x018f('0xa0')][_0x018f('0xa2')];}return rp(_0x350787);})[_0x018f('0x29')](function(_0x45b3f1){if(_0x45b3f1){_0x4a4b16[_0x018f('0x24')](_0x45b3f1[_0x018f('0xa0')]);logger[_0x018f('0x69')](_0x45b3f1[_0x018f('0x91')]);if(_[_0x018f('0xa3')](_0x265a3d[_0x018f('0x35')][_0x018f('0x7')],_0x018f('0x4f'))&&_0x45b3f1[_0x018f('0xa4')]==0x1f4){return _0x4a4b16[_0x018f('0x2d')](_0x45b3f1[_0x018f('0xa4')]);}else{return _0x4a4b16[_0x018f('0x1d')](_0x45b3f1[_0x018f('0xa4')])[_0x018f('0x30')](_0x45b3f1['body']);}}else{return _0x4a4b16[_0x018f('0x2d')](0xc8);}})['catch'](handleError(_0x4a4b16,null));};exports[_0x018f('0xa5')]=function(_0x23eb8e,_0x372553,_0x355089){return BPromise[_0x018f('0xa6')]()[_0x018f('0x29')](function(){if(!_0x23eb8e[_0x018f('0x35')][_0x018f('0x7')]){throw new Error(_0x018f('0x9a'));}if(!_0x23eb8e['query']['port']){throw new Error(_0x018f('0xa7'));}var _0x229b3b=_0x23eb8e['query'][_0x018f('0x9b')]?_0x23eb8e[_0x018f('0x35')][_0x018f('0x9b')]+':'+_0x23eb8e['query'][_0x018f('0x9c')]:_0x018f('0x9d')+_0x23eb8e['query'][_0x018f('0x9c')];var _0x299fcb=_0x23eb8e[_0x018f('0x35')][_0x018f('0x1f')]?_0x23eb8e[_0x018f('0x35')]['json']:!![];var _0x5794f8=_0x23eb8e[_0x018f('0x35')]['encoding']?_0x23eb8e[_0x018f('0x35')][_0x018f('0x9e')]:null;var _0x134659={'method':_0x23eb8e[_0x018f('0xa8')],'uri':util[_0x018f('0x53')](_0x018f('0x9f'),_0x229b3b,_0x23eb8e[_0x018f('0x35')][_0x018f('0x7')]),'json':_0x299fcb,'resolveWithFullResponse':!![],'encoding':_0x5794f8,'body':_0x23eb8e[_0x018f('0x91')]};if(_0x23eb8e[_0x018f('0xa0')]){_0x134659[_0x018f('0xa0')]=_0x23eb8e['headers'];if(_0x134659[_0x018f('0xa0')][_0x018f('0xa1')]){delete _0x134659['headers'][_0x018f('0xa1')];}}if(_0x134659[_0x018f('0xa0')][_0x018f('0xa2')]){delete _0x134659[_0x018f('0xa0')][_0x018f('0xa2')];}return rp(_0x134659);})['then'](function(_0x58722d){if(_0x58722d){_0x372553[_0x018f('0x24')](_0x58722d[_0x018f('0xa0')]);logger['info'](_0x58722d[_0x018f('0x91')]);return _0x372553[_0x018f('0x1d')](_0x58722d[_0x018f('0xa4')])[_0x018f('0x30')](_0x58722d[_0x018f('0x91')]);}else{return _0x372553[_0x018f('0x2d')](0xc8);}})[_0x018f('0x4e')](handleError(_0x372553,null));};
\ No newline at end of file
+var _0x39ac=['html','parameters','views','script','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','sidebar','always','icon','icon-apps','admin','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','agent','scriptPath','create','body','userProfileId','role','user','UserProfileSection','Plugins','autoAssociation','send','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','update','delete','webhookGet','\x27PATH\x27\x20parameter\x20not\x20specified','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','port','http://localhost:','encoding','method','%s%s','headers','content-length','content-type','endsWith','download','statusCode','resolve','eml-format','rimraf','fast-json-patch','request-promise','util','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','extract-zip','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','register','status','end','offset','undefined','count','limit','set','json','apply','then','get','UserProfileResource','destroy','sendStatus','error','stack','name','index','Plugin','fieldName','type','key','model','query','filters','fields','attributes','hasOwnProperty','order','sort','where','pick','filter','merge','map','VIRTUAL','include','findAll','rows','catch','params','keys','rawAttributes','intersection','options','find','path','format','%s.zip','createWriteStream','warning','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','**/*','root','dirname','join','basename','node_modules/**/*','finalize','existsSync','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','Download\x20completed','Temporary\x20file\x20removed','upload','file','filename','extname','server/files/plugins','Plugin\x20upload\x20filepath:\x20%s','info','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync','length','Invalid\x20plugin\x20structure','lstatSync','isDirectory','some','Plugin\x20manifest\x20missing','readFileSync','manifest.json','parse','Invalid\x20manifest:\x20name\x20missing','version'];(function(_0x52f497,_0x132ec4){var _0x280215=function(_0x5b83f9){while(--_0x5b83f9){_0x52f497['push'](_0x52f497['shift']());}};_0x280215(++_0x132ec4);}(_0x39ac,0x16f));var _0xc39a=function(_0x41e722,_0x35f5b4){_0x41e722=_0x41e722-0x0;var _0x2b3647=_0x39ac[_0x41e722];return _0x2b3647;};'use strict';var emlformat=require(_0xc39a('0x0'));var rimraf=require(_0xc39a('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xc39a('0x2'));var rp=require(_0xc39a('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xc39a('0x4'));var path=require('path');var sox=require(_0xc39a('0x5'));var csv=require(_0xc39a('0x6'));var ejs=require(_0xc39a('0x7'));var fs=require('fs');var fs_extra=require(_0xc39a('0x8'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xc39a('0x9'));var jsforce=require(_0xc39a('0xa'));var deskjs=require(_0xc39a('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var extract=require(_0xc39a('0xc'));var rimraf=require('rimraf');var archiver=require('archiver');var Redis=require(_0xc39a('0xd'));var authService=require('../../components/auth/service');var qs=require(_0xc39a('0xe'));var as=require(_0xc39a('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xc39a('0x10'));var utils=require('../../config/utils');var config=require(_0xc39a('0x11'));var licenseUtil=require(_0xc39a('0x12'));var db=require(_0xc39a('0x13'))['db'];config[_0xc39a('0x14')]=_['defaults'](config[_0xc39a('0x14')],{'host':_0xc39a('0x15'),'port':0x18eb});var socket=require(_0xc39a('0x16'))(new Redis(config['redis']));require('./plugin.socket')[_0xc39a('0x17')](socket);function respondWithStatusCode(_0x3f272e,_0x3c00ee){_0x3c00ee=_0x3c00ee||0xcc;return function(_0x2fca40){if(_0x2fca40){return _0x3f272e['sendStatus'](_0x3c00ee);}return _0x3f272e[_0xc39a('0x18')](_0x3c00ee)[_0xc39a('0x19')]();};}function respondWithResult(_0x4cb638,_0x25ed73){_0x25ed73=_0x25ed73||0xc8;return function(_0x3ab6f2){if(_0x3ab6f2){return _0x4cb638[_0xc39a('0x18')](_0x25ed73)['json'](_0x3ab6f2);}};}function respondWithFilteredResult(_0x275d01,_0x337996){return function(_0x136129){if(_0x136129){var _0x27b18a=typeof _0x337996[_0xc39a('0x1a')]===_0xc39a('0x1b')&&typeof _0x337996['limit']===_0xc39a('0x1b');var _0x23e8d7=_0x136129[_0xc39a('0x1c')];var _0x56c157=_0x27b18a?0x0:_0x337996[_0xc39a('0x1a')];var _0x3ae0b9=_0x27b18a?_0x136129[_0xc39a('0x1c')]:_0x337996['offset']+_0x337996[_0xc39a('0x1d')];var _0xe76287;if(_0x3ae0b9>=_0x23e8d7){_0x3ae0b9=_0x23e8d7;_0xe76287=0xc8;}else{_0xe76287=0xce;}_0x275d01[_0xc39a('0x18')](_0xe76287);return _0x275d01[_0xc39a('0x1e')]('Content-Range',_0x56c157+'-'+_0x3ae0b9+'/'+_0x23e8d7)[_0xc39a('0x1f')](_0x136129);}return null;};}function patchUpdates(_0xa5f289){return function(_0x281b76){try{jsonpatch[_0xc39a('0x20')](_0x281b76,_0xa5f289,!![]);}catch(_0x402470){return BPromise['reject'](_0x402470);}return _0x281b76['save']();};}function saveUpdates(_0x14954c,_0x5f2cfc){return function(_0x4d700){if(_0x4d700){return _0x4d700['update'](_0x14954c)[_0xc39a('0x21')](function(_0x16d0ad){return _0x16d0ad;});}return null;};}function removeEntity(_0x34490b,_0x65c6ea){return function(_0x312ea7){if(_0x312ea7){return _0x312ea7['destroy']()[_0xc39a('0x21')](function(){var _0x70f3ff=_0x312ea7[_0xc39a('0x22')]({'plain':!![]});var _0x52dd53='Plugins';return db[_0xc39a('0x23')][_0xc39a('0x24')]({'where':{'type':_0x52dd53,'resourceId':_0x70f3ff['id']}})[_0xc39a('0x21')](function(){return _0x312ea7;});})[_0xc39a('0x21')](function(){_0x34490b[_0xc39a('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x319c18,_0x3aa08a){return function(_0x44c530){if(!_0x44c530){_0x319c18[_0xc39a('0x25')](0x194);}return _0x44c530;};}function handleError(_0x4508b0,_0x2b3bdd){_0x2b3bdd=_0x2b3bdd||0x1f4;return function(_0x9ad171){logger[_0xc39a('0x26')](_0x9ad171[_0xc39a('0x27')]);if(_0x9ad171[_0xc39a('0x28')]){delete _0x9ad171[_0xc39a('0x28')];}_0x4508b0[_0xc39a('0x18')](_0x2b3bdd)['send'](_0x9ad171);};}exports[_0xc39a('0x29')]=function(_0x5f1b60,_0xc110be){var _0x27a60d={},_0xdcdf37={},_0x5295e5={'count':0x0,'rows':[]};var _0x2391fb=_['map'](db[_0xc39a('0x2a')]['rawAttributes'],function(_0x41588e){return{'name':_0x41588e[_0xc39a('0x2b')],'type':_0x41588e[_0xc39a('0x2c')][_0xc39a('0x2d')]};});_0xdcdf37[_0xc39a('0x2e')]=_['map'](_0x2391fb,_0xc39a('0x28'));_0xdcdf37[_0xc39a('0x2f')]=_['keys'](_0x5f1b60['query']);_0xdcdf37[_0xc39a('0x30')]=_['intersection'](_0xdcdf37[_0xc39a('0x2e')],_0xdcdf37[_0xc39a('0x2f')]);_0x27a60d['attributes']=_['intersection'](_0xdcdf37['model'],qs[_0xc39a('0x31')](_0x5f1b60['query']['fields']));_0x27a60d['attributes']=_0x27a60d['attributes']['length']?_0x27a60d[_0xc39a('0x32')]:_0xdcdf37[_0xc39a('0x2e')];if(!_0x5f1b60[_0xc39a('0x2f')][_0xc39a('0x33')]('nolimit')){_0x27a60d[_0xc39a('0x1d')]=qs['limit'](_0x5f1b60['query'][_0xc39a('0x1d')]);_0x27a60d['offset']=qs[_0xc39a('0x1a')](_0x5f1b60[_0xc39a('0x2f')]['offset']);}_0x27a60d[_0xc39a('0x34')]=qs[_0xc39a('0x35')](_0x5f1b60[_0xc39a('0x2f')][_0xc39a('0x35')]);_0x27a60d[_0xc39a('0x36')]=qs['filters'](_[_0xc39a('0x37')](_0x5f1b60[_0xc39a('0x2f')],_0xdcdf37['filters']),_0x2391fb);if(_0x5f1b60[_0xc39a('0x2f')][_0xc39a('0x38')]){_0x27a60d[_0xc39a('0x36')]=_[_0xc39a('0x39')](_0x27a60d['where'],{'$or':_[_0xc39a('0x3a')](_0x2391fb,function(_0x5e74c1){if(_0x5e74c1[_0xc39a('0x2c')]!==_0xc39a('0x3b')){var _0xf56151={};_0xf56151[_0x5e74c1['name']]={'$like':'%'+_0x5f1b60[_0xc39a('0x2f')][_0xc39a('0x38')]+'%'};return _0xf56151;}})});}_0x27a60d=_[_0xc39a('0x39')]({},_0x27a60d,_0x5f1b60['options']);var _0x4440ca={'where':_0x27a60d[_0xc39a('0x36')]};return db['Plugin'][_0xc39a('0x1c')](_0x4440ca)[_0xc39a('0x21')](function(_0x2e66d1){_0x5295e5[_0xc39a('0x1c')]=_0x2e66d1;if(_0x5f1b60[_0xc39a('0x2f')]['includeAll']){_0x27a60d[_0xc39a('0x3c')]=[{'all':!![]}];}return db[_0xc39a('0x2a')][_0xc39a('0x3d')](_0x27a60d);})[_0xc39a('0x21')](function(_0x3fed5c){_0x5295e5[_0xc39a('0x3e')]=_0x3fed5c;return _0x5295e5;})[_0xc39a('0x21')](respondWithFilteredResult(_0xc110be,_0x27a60d))[_0xc39a('0x3f')](handleError(_0xc110be,null));};exports['show']=function(_0x1e22b6,_0xe307d3){var _0x384282={'raw':!![],'where':{'id':_0x1e22b6[_0xc39a('0x40')]['id']}},_0x1ac62e={};_0x1ac62e[_0xc39a('0x2e')]=_[_0xc39a('0x41')](db[_0xc39a('0x2a')][_0xc39a('0x42')]);_0x1ac62e[_0xc39a('0x2f')]=_[_0xc39a('0x41')](_0x1e22b6[_0xc39a('0x2f')]);_0x1ac62e[_0xc39a('0x30')]=_[_0xc39a('0x43')](_0x1ac62e[_0xc39a('0x2e')],_0x1ac62e['query']);_0x384282[_0xc39a('0x32')]=_['intersection'](_0x1ac62e[_0xc39a('0x2e')],qs[_0xc39a('0x31')](_0x1e22b6[_0xc39a('0x2f')][_0xc39a('0x31')]));_0x384282[_0xc39a('0x32')]=_0x384282[_0xc39a('0x32')]['length']?_0x384282[_0xc39a('0x32')]:_0x1ac62e['model'];if(_0x1e22b6['query']['includeAll']){_0x384282[_0xc39a('0x3c')]=[{'all':!![]}];}_0x384282=_[_0xc39a('0x39')]({},_0x384282,_0x1e22b6[_0xc39a('0x44')]);return db['Plugin'][_0xc39a('0x45')](_0x384282)[_0xc39a('0x21')](handleEntityNotFound(_0xe307d3,null))[_0xc39a('0x21')](respondWithResult(_0xe307d3,null))[_0xc39a('0x3f')](handleError(_0xe307d3,null));};exports['download']=function(_0x280a56,_0x390cb0,_0x200f56){return db[_0xc39a('0x2a')][_0xc39a('0x45')]({'where':{'id':_0x280a56['params']['id']},'attributes':[_0xc39a('0x28'),_0xc39a('0x46')],'raw':!![]})['then'](handleEntityNotFound(_0x390cb0,null))[_0xc39a('0x21')](function(_0x2ed405){if(_0x2ed405){var _0xf3e5d2=path['join'](config['root'],'server/files/plugins',util[_0xc39a('0x47')](_0xc39a('0x48'),path['basename'](_0x2ed405[_0xc39a('0x46')])));var _0x5f0af5=fs[_0xc39a('0x49')](_0xf3e5d2);var _0x20cc5b=archiver('zip',{'zlib':{'level':0x9}});_0x20cc5b['on'](_0xc39a('0x4a'),function(_0x5176f6){if(_0x5176f6[_0xc39a('0x4b')]===_0xc39a('0x4c')){logger[_0xc39a('0x26')](_0x5176f6);}else{throw new db[(_0xc39a('0x4d'))][(_0xc39a('0x4e'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x20cc5b['on'](_0xc39a('0x26'),function(_0x1ebd35){throw new db[(_0xc39a('0x4d'))][(_0xc39a('0x4e'))](_0xc39a('0x4f'));});_0x20cc5b[_0xc39a('0x50')](_0x5f0af5);_0x20cc5b[_0xc39a('0x51')](_0xc39a('0x52'),{'cwd':path['join'](config[_0xc39a('0x53')],'server/files/plugins',path[_0xc39a('0x54')](_0x2ed405[_0xc39a('0x46')])),'ignore':[path[_0xc39a('0x55')](path[_0xc39a('0x56')](_0x2ed405[_0xc39a('0x46')]),_0xc39a('0x57')),path[_0xc39a('0x55')](path[_0xc39a('0x56')](_0x2ed405[_0xc39a('0x46')]),'attachments/**/*')],'nodir':!![]})[_0xc39a('0x58')]();_0x5f0af5['on']('close',function(){if(!fs[_0xc39a('0x59')](_0xf3e5d2)){throw new db[(_0xc39a('0x4d'))][(_0xc39a('0x4e'))]('Plugin\x20not\x20found');}return _0x390cb0['download'](_0xf3e5d2,util[_0xc39a('0x47')]('%s.zip',path['basename'](_0x2ed405[_0xc39a('0x46')])),function(_0x2019e1){if(_0x2019e1){throw new db[(_0xc39a('0x4d'))]['Error'](_0xc39a('0x5a'));}fs[_0xc39a('0x5b')](_0xf3e5d2);logger['info'](_0xc39a('0x5c'));logger['info'](_0xc39a('0x5d'));});});}return null;})['catch'](handleError(_0x390cb0,null));};exports[_0xc39a('0x5e')]=function(_0x40b0fe,_0x5b9468,_0x21f8e6){var _0x236918=path[_0xc39a('0x56')](_0x40b0fe[_0xc39a('0x5f')][_0xc39a('0x60')],path[_0xc39a('0x61')](_0x40b0fe[_0xc39a('0x5f')][_0xc39a('0x60')]));var _0x31d684=path[_0xc39a('0x55')](config['root'],_0xc39a('0x62'),_0x40b0fe[_0xc39a('0x5f')]['filename']);var _0x187c5c=path[_0xc39a('0x55')](config[_0xc39a('0x53')],'server/files/plugins',_0x236918);logger['info'](_0xc39a('0x63'),_0x31d684);logger[_0xc39a('0x64')](_0xc39a('0x65'),_0x187c5c);try{fs[_0xc39a('0x66')](_0x31d684,parseInt(_0xc39a('0x67'),0x8));extract(_0x31d684,{'dir':_0x187c5c},function(_0x195aa1){if(_0x195aa1){logger['error'](_0x195aa1);handleError(_0x195aa1,!![]);};var _0x28ade1=fs[_0xc39a('0x68')](_0x187c5c);if(_0x28ade1[_0xc39a('0x69')]>0x1){removeReferences(_0x31d684,_0x187c5c);logger['error']('Invalid\x20plugin\x20structure');return _0x21f8e6(new Error(_0xc39a('0x6a')));}var _0x26c3ed=fs[_0xc39a('0x6b')](path['join'](_0x187c5c,_0x28ade1[0x0]));if(_0x26c3ed['isFile']()){removeReferences(_0x31d684,_0x187c5c);logger[_0xc39a('0x26')](_0xc39a('0x6a'));return _0x21f8e6(new Error(_0xc39a('0x6a')));}if(_0x26c3ed[_0xc39a('0x6c')]()){var _0x242058=fs['readdirSync'](path[_0xc39a('0x55')](_0x187c5c,_0x28ade1[0x0]));if(_0x242058[_0xc39a('0x69')]===0x0){removeReferences(_0x31d684,_0x187c5c);logger[_0xc39a('0x26')]('Invalid\x20plugin\x20structure');return _0x21f8e6(new Error(_0xc39a('0x6a')));}var _0x9db1d0=_0x242058[_0xc39a('0x6d')](function(_0x24de46){return _0x24de46==='manifest.json';});if(!_0x9db1d0){return _0x21f8e6(new Error(_0xc39a('0x6e')));}var _0x31309a=fs[_0xc39a('0x6f')](path[_0xc39a('0x55')](_0x187c5c,_0x28ade1[0x0],_0xc39a('0x70')));var _0x45719f=JSON[_0xc39a('0x71')](_0x31309a);if(_0xc39a('0x1b')==typeof _0x45719f[_0xc39a('0x28')]){return _0x21f8e6(new Error(_0xc39a('0x72')));}if(_0xc39a('0x1b')==typeof _0x45719f['type']){return _0x21f8e6(new Error('Invalid\x20manifest:\x20type\x20missing'));}if(_0xc39a('0x1b')==typeof _0x45719f[_0xc39a('0x73')]){return _0x21f8e6(new Error('Invalid\x20manifest:\x20version\x20not\x20specified'));}if('undefined'==typeof _0x45719f['parameters']){return _0x21f8e6(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x45719f[_0xc39a('0x2c')]===_0xc39a('0x74')){if('undefined'==typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')]){return _0x21f8e6(new Error('Invalid\x20manifest:\x20views\x20missing'));}if(_0xc39a('0x1b')==typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')]['admin']&&'undefined'==typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')]['agent']){return _0x21f8e6(new Error('Invalid\x20manifest:\x20no\x20view\x20specified'));}}else if(_0x45719f['type']===_0xc39a('0x77')){if(_0xc39a('0x1b')==typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x78')]){return _0x21f8e6(new Error(_0xc39a('0x79')));}if(_0xc39a('0x1b')==typeof _0x45719f[_0xc39a('0x75')]['scriptPath']){return _0x21f8e6(new Error('Invalid\x20manifest:\x20script\x20path\x20missing'));}}else{return _0x21f8e6(new Error('Invalid\x20manifest:\x20invalid\x20type'));}var _0xc6076a=_0x45719f[_0xc39a('0x28')];var _0x5094ef=_0x45719f['description'];var _0xe9b69f=_0x45719f[_0xc39a('0x2c')];var _0x60849c=_0x45719f[_0xc39a('0x7a')]?_0x45719f['sidebar']:_0xc39a('0x7b');var _0x4d68c1=_0x45719f[_0xc39a('0x7c')]?_0x45719f['icon']:_0xc39a('0x7d');var _0x2c4723='';var _0x5b7eb8='';var _0x5dabca='';var _0x25d8eb='';var _0x393e9f=_0x45719f[_0xc39a('0x73')];if(_0xe9b69f===_0xc39a('0x74')){if(_0xc39a('0x1b')!=typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')][_0xc39a('0x7e')]){var _0x374fa7=_0x45719f[_0xc39a('0x75')]['views'][_0xc39a('0x7e')];if(!/^(f|ht)tps?:\/\//i[_0xc39a('0x7f')](_0x374fa7)){_0x2c4723=path[_0xc39a('0x55')](_0xc39a('0x80'),_0x236918,_0x28ade1[0x0],_0x374fa7);}else{_0x2c4723=_0x374fa7;}}else{logger[_0xc39a('0x64')](_0xc39a('0x81'));}if(_0xc39a('0x1b')!=typeof _0x45719f[_0xc39a('0x75')]['views']['agent']){var _0xed2ae1=_0x45719f[_0xc39a('0x75')][_0xc39a('0x76')][_0xc39a('0x82')];if(!/^(f|ht)tps?:\/\//i[_0xc39a('0x7f')](_0xed2ae1)){_0x5b7eb8=path['join'](_0xc39a('0x80'),_0x236918,_0x28ade1[0x0],_0xed2ae1);}else{_0x5b7eb8=_0xed2ae1;}}else{logger[_0xc39a('0x64')]('Warning:\x20agent\x20view\x20not\x20specified');}}else if(_0xe9b69f===_0xc39a('0x77')){_0x5dabca=_0x45719f[_0xc39a('0x75')]['scriptName'];_0x25d8eb=_0x45719f['parameters'][_0xc39a('0x83')];if(_0xc39a('0x1b')!=typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')]){if(_0xc39a('0x1b')!=typeof _0x45719f[_0xc39a('0x75')][_0xc39a('0x76')][_0xc39a('0x7e')]){var _0x374fa7=_0x45719f[_0xc39a('0x75')]['views']['admin'];if(!/^(f|ht)tps?:\/\//i[_0xc39a('0x7f')](_0x374fa7)){_0x2c4723=path[_0xc39a('0x55')](_0xc39a('0x80'),_0x236918,_0x28ade1[0x0],_0x374fa7);}else{_0x2c4723=_0x374fa7;}}if(_0xc39a('0x1b')!=typeof _0x45719f[_0xc39a('0x75')]['views'][_0xc39a('0x82')]){var _0xed2ae1=_0x45719f[_0xc39a('0x75')]['views'][_0xc39a('0x82')];if(!/^(f|ht)tps?:\/\//i['test'](_0xed2ae1)){_0x5b7eb8=path[_0xc39a('0x55')](_0xc39a('0x80'),_0x236918,_0x28ade1[0x0],_0xed2ae1);}else{_0x5b7eb8=_0xed2ae1;}}}}var _0x4a0d30={'name':_0xc6076a,'description':_0x5094ef,'path':path[_0xc39a('0x55')](_0x236918,_0x28ade1[0x0]),'type':_0xe9b69f,'sidebar':_0x60849c,'icon':_0x4d68c1,'adminUrl':_0x2c4723,'agentUrl':_0x5b7eb8,'scriptName':_0x5dabca,'scriptPath':_0x25d8eb,'version':_0x393e9f};removeReferences(_0x31d684,null);return db[_0xc39a('0x2a')][_0xc39a('0x84')](_0x4a0d30)['then'](function(_0x2b5583){var _0x4518dc={'role':_0x40b0fe[_0xc39a('0x85')]['role'],'userProfileId':_0x40b0fe[_0xc39a('0x85')][_0xc39a('0x86')]};if(!_0x4518dc)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x4518dc[_0xc39a('0x87')]===_0xc39a('0x88')){var _0x12e028=_0x2b5583['get']({'plain':!![]});return db[_0xc39a('0x89')][_0xc39a('0x45')]({'where':{'name':_0xc39a('0x8a'),'userProfileId':_0x4518dc[_0xc39a('0x86')]},'raw':!![]})[_0xc39a('0x21')](function(_0x4d6650){if(_0x4d6650&&_0x4d6650[_0xc39a('0x8b')]===0x0){return db[_0xc39a('0x23')][_0xc39a('0x84')]({'name':_0x12e028[_0xc39a('0x28')],'resourceId':_0x12e028['id'],'type':_0x4d6650[_0xc39a('0x28')],'sectionId':_0x4d6650['id']},{})[_0xc39a('0x21')](function(){return _0x2b5583;});}else{return _0x2b5583;}})[_0xc39a('0x3f')](function(_0x339997){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x339997);throw _0x339997;});}return _0x2b5583;})[_0xc39a('0x21')](respondWithResult(_0x5b9468,null))[_0xc39a('0x3f')](handleError(_0x5b9468,null));}});}catch(_0x5ad6fd){_0x5b9468[_0xc39a('0x18')](0x1f4)[_0xc39a('0x8c')](_0x5ad6fd);}};function removeReferences(_0x5369ab,_0x34b607){try{if(_0x5369ab){fs[_0xc39a('0x5b')](_0x5369ab);logger[_0xc39a('0x64')](_0xc39a('0x8d'));}if(_0x34b607){rimraf(_0x34b607,function(){});logger[_0xc39a('0x64')](_0xc39a('0x8e'));}}catch(_0x299344){logger[_0xc39a('0x26')](_0x299344);}}exports[_0xc39a('0x8f')]=function(_0x3f620c,_0x6d3699,_0x2ca4a2){return db[_0xc39a('0x2a')]['find']({'where':{'id':_0x3f620c[_0xc39a('0x40')]['id']}})[_0xc39a('0x21')](handleEntityNotFound(_0x6d3699,null))[_0xc39a('0x21')](saveUpdates(_0x3f620c[_0xc39a('0x85')],null))[_0xc39a('0x21')](respondWithResult(_0x6d3699,null))[_0xc39a('0x3f')](handleError(_0x6d3699,null));};exports[_0xc39a('0x90')]=function(_0x59aa8a,_0x44946f,_0x133189){return db[_0xc39a('0x2a')][_0xc39a('0x45')]({'where':{'id':_0x59aa8a[_0xc39a('0x40')]['id']}})['then'](function(_0xaa3639){if(_0xaa3639){return _0xaa3639[_0xc39a('0x24')]();}})[_0xc39a('0x21')](function(_0x28c61b){rimraf(path[_0xc39a('0x55')](config[_0xc39a('0x53')],_0xc39a('0x62'),path[_0xc39a('0x54')](_0x28c61b['path'])),function(){});return _0x28c61b;})['then'](handleEntityNotFound(_0x44946f,null))[_0xc39a('0x21')](respondWithStatusCode(_0x44946f,null))[_0xc39a('0x3f')](handleError(_0x44946f,null));};exports[_0xc39a('0x91')]=function(_0x352d3d,_0x32c520,_0x2c4617){return BPromise['resolve']()[_0xc39a('0x21')](function(){if(!_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x46')]){throw new Error(_0xc39a('0x92'));}if(!_0x352d3d['query']['port']){throw new Error(_0xc39a('0x93'));}var _0x4b395e=_0x352d3d['query'][_0xc39a('0x94')]?_0x352d3d['query'][_0xc39a('0x94')]+':'+_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x95')]:_0xc39a('0x96')+_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x95')];var _0x4d5dd5=_0x352d3d['query'][_0xc39a('0x1f')]?_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x1f')]:!![];var _0x129d23=_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x97')]?_0x352d3d['query']['encoding']:null;var _0xa65c79={'method':_0x352d3d[_0xc39a('0x98')],'uri':util[_0xc39a('0x47')](_0xc39a('0x99'),_0x4b395e,_0x352d3d[_0xc39a('0x2f')]['path']),'json':_0x4d5dd5,'resolveWithFullResponse':!![],'encoding':_0x129d23,'qs':_0x352d3d[_0xc39a('0x2f')]};if(_0x352d3d[_0xc39a('0x9a')]){_0xa65c79[_0xc39a('0x9a')]=_0x352d3d[_0xc39a('0x9a')];if(_0xa65c79[_0xc39a('0x9a')]['content-length']){delete _0xa65c79['headers'][_0xc39a('0x9b')];}}if(_0xa65c79[_0xc39a('0x9a')][_0xc39a('0x9c')]){delete _0xa65c79['headers'][_0xc39a('0x9c')];}return rp(_0xa65c79);})[_0xc39a('0x21')](function(_0x220db0){if(_0x220db0){_0x32c520[_0xc39a('0x1e')](_0x220db0['headers']);logger[_0xc39a('0x64')](_0x220db0[_0xc39a('0x85')]);if(_[_0xc39a('0x9d')](_0x352d3d[_0xc39a('0x2f')][_0xc39a('0x46')],_0xc39a('0x9e'))&&_0x220db0[_0xc39a('0x9f')]==0x1f4){return _0x32c520[_0xc39a('0x25')](_0x220db0[_0xc39a('0x9f')]);}else{return _0x32c520[_0xc39a('0x18')](_0x220db0[_0xc39a('0x9f')])['send'](_0x220db0[_0xc39a('0x85')]);}}else{return _0x32c520['sendStatus'](0xc8);}})[_0xc39a('0x3f')](handleError(_0x32c520,null));};exports['webhookPost']=function(_0xa10d70,_0x1769fb,_0x270f3e){return BPromise[_0xc39a('0xa0')]()[_0xc39a('0x21')](function(){if(!_0xa10d70['query'][_0xc39a('0x46')]){throw new Error(_0xc39a('0x92'));}if(!_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x95')]){throw new Error(_0xc39a('0x93'));}var _0x113fc6=_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x94')]?_0xa10d70[_0xc39a('0x2f')]['hostname']+':'+_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x95')]:_0xc39a('0x96')+_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x95')];var _0x48cd5e=_0xa10d70['query'][_0xc39a('0x1f')]?_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x1f')]:!![];var _0x18cfc8=_0xa10d70['query'][_0xc39a('0x97')]?_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x97')]:null;var _0x5b4eb9={'method':_0xa10d70[_0xc39a('0x98')],'uri':util['format'](_0xc39a('0x99'),_0x113fc6,_0xa10d70[_0xc39a('0x2f')][_0xc39a('0x46')]),'json':_0x48cd5e,'resolveWithFullResponse':!![],'encoding':_0x18cfc8,'body':_0xa10d70[_0xc39a('0x85')]};if(_0xa10d70[_0xc39a('0x9a')]){_0x5b4eb9[_0xc39a('0x9a')]=_0xa10d70['headers'];if(_0x5b4eb9[_0xc39a('0x9a')]['content-length']){delete _0x5b4eb9['headers']['content-length'];}}if(_0x5b4eb9[_0xc39a('0x9a')]['content-type']){delete _0x5b4eb9[_0xc39a('0x9a')][_0xc39a('0x9c')];}return rp(_0x5b4eb9);})[_0xc39a('0x21')](function(_0xb29322){if(_0xb29322){_0x1769fb['set'](_0xb29322['headers']);logger[_0xc39a('0x64')](_0xb29322['body']);return _0x1769fb[_0xc39a('0x18')](_0xb29322['statusCode'])[_0xc39a('0x8c')](_0xb29322[_0xc39a('0x85')]);}else{return _0x1769fb[_0xc39a('0x25')](0xc8);}})['catch'](handleError(_0x1769fb,null));};
\ No newline at end of file