Built motion from commit 9b156c94.|2.6.22
[motion2.git] / server / api / plugin / plugin.controller.js
index 4bfd06c..5a3b67b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcf94=['http://localhost:','content-length','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','ejs','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','querystring','extract-zip','rimraf','archiver','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./plugin.socket','register','status','end','json','offset','limit','count','set','save','update','then','destroy','get','Plugins','sendStatus','error','name','send','index','Plugin','rawAttributes','fieldName','key','model','map','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','type','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','params','download','find','join','root','format','createWriteStream','zip','warning','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','glob','**/*','dirname','basename','node_modules/**/*','attachments/**/*','%s.zip','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','Download\x20completed','Temporary\x20file\x20removed','filename','extname','file','server/files/plugins','info','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','isDirectory','some','manifest.json','Plugin\x20manifest\x20missing','readFileSync','parse','undefined','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','views','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','always','icon','icon-apps','html','test','plugins','Warning:\x20agent\x20view\x20not\x20specified','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','autoAssociation','UserProfileResource','Zip\x20archive\x20removed','delete','webhookGet','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','port','hostname','encoding','method','%s%s','headers','content-type','body','endsWith','statusCode','\x27PORT\x27\x20parameter\x20not\x20specified'];(function(_0x30ef05,_0x9b51a){var _0x32b20c=function(_0x46637c){while(--_0x46637c){_0x30ef05['push'](_0x30ef05['shift']());}};_0x32b20c(++_0x9b51a);}(_0xcf94,0x15e));var _0x4cf9=function(_0x2cd72b,_0x2cd9f7){_0x2cd72b=_0x2cd72b-0x0;var _0x3f5c21=_0xcf94[_0x2cd72b];return _0x3f5c21;};'use strict';var emlformat=require(_0x4cf9('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x4cf9('0x1'));var jsonpatch=require(_0x4cf9('0x2'));var rp=require(_0x4cf9('0x3'));var moment=require(_0x4cf9('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x4cf9('0x5'));var path=require(_0x4cf9('0x6'));var sox=require(_0x4cf9('0x7'));var csv=require('to-csv');var ejs=require(_0x4cf9('0x8'));var fs=require('fs');var fs_extra=require(_0x4cf9('0x9'));var _=require(_0x4cf9('0xa'));var squel=require('squel');var crypto=require(_0x4cf9('0xb'));var jsforce=require(_0x4cf9('0xc'));var deskjs=require(_0x4cf9('0xd'));var toCsv=require(_0x4cf9('0xe'));var querystring=require(_0x4cf9('0xf'));var Papa=require('papaparse');var extract=require(_0x4cf9('0x10'));var rimraf=require(_0x4cf9('0x11'));var archiver=require(_0x4cf9('0x12'));var Redis=require(_0x4cf9('0x13'));var authService=require(_0x4cf9('0x14'));var qs=require(_0x4cf9('0x15'));var as=require(_0x4cf9('0x16'));var hardwareService=require(_0x4cf9('0x17'));var logger=require('../../config/logger')(_0x4cf9('0x18'));var utils=require(_0x4cf9('0x19'));var config=require(_0x4cf9('0x1a'));var licenseUtil=require(_0x4cf9('0x1b'));var db=require(_0x4cf9('0x1c'))['db'];config[_0x4cf9('0x1d')]=_[_0x4cf9('0x1e')](config[_0x4cf9('0x1d')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4cf9('0x1d')]));require(_0x4cf9('0x1f'))[_0x4cf9('0x20')](socket);function respondWithStatusCode(_0x3f7950,_0x501143){_0x501143=_0x501143||0xcc;return function(_0x2eea00){if(_0x2eea00){return _0x3f7950['sendStatus'](_0x501143);}return _0x3f7950[_0x4cf9('0x21')](_0x501143)[_0x4cf9('0x22')]();};}function respondWithResult(_0x3e9fa1,_0xab6239){_0xab6239=_0xab6239||0xc8;return function(_0x50a765){if(_0x50a765){return _0x3e9fa1['status'](_0xab6239)[_0x4cf9('0x23')](_0x50a765);}};}function respondWithFilteredResult(_0x4a0f73,_0x16a73f){return function(_0x2800a0){if(_0x2800a0){var _0x45bbbc=typeof _0x16a73f[_0x4cf9('0x24')]==='undefined'&&typeof _0x16a73f[_0x4cf9('0x25')]==='undefined';var _0x566e15=_0x2800a0[_0x4cf9('0x26')];var _0x1278ed=_0x45bbbc?0x0:_0x16a73f['offset'];var _0x4bcf12=_0x45bbbc?_0x2800a0[_0x4cf9('0x26')]:_0x16a73f[_0x4cf9('0x24')]+_0x16a73f[_0x4cf9('0x25')];var _0x45035b;if(_0x4bcf12>=_0x566e15){_0x4bcf12=_0x566e15;_0x45035b=0xc8;}else{_0x45035b=0xce;}_0x4a0f73[_0x4cf9('0x21')](_0x45035b);return _0x4a0f73[_0x4cf9('0x27')]('Content-Range',_0x1278ed+'-'+_0x4bcf12+'/'+_0x566e15)[_0x4cf9('0x23')](_0x2800a0);}return null;};}function patchUpdates(_0x54429e){return function(_0x282ba3){try{jsonpatch['apply'](_0x282ba3,_0x54429e,!![]);}catch(_0x137df9){return BPromise['reject'](_0x137df9);}return _0x282ba3[_0x4cf9('0x28')]();};}function saveUpdates(_0x509d5b,_0x329efa){return function(_0x249bc9){if(_0x249bc9){return _0x249bc9[_0x4cf9('0x29')](_0x509d5b)[_0x4cf9('0x2a')](function(_0xa4490){return _0xa4490;});}return null;};}function removeEntity(_0xf060bf,_0x14b8f5){return function(_0x5880c9){if(_0x5880c9){return _0x5880c9[_0x4cf9('0x2b')]()[_0x4cf9('0x2a')](function(){var _0x243908=_0x5880c9[_0x4cf9('0x2c')]({'plain':!![]});var _0x35fd12=_0x4cf9('0x2d');return db['UserProfileResource']['destroy']({'where':{'type':_0x35fd12,'resourceId':_0x243908['id']}})['then'](function(){return _0x5880c9;});})[_0x4cf9('0x2a')](function(){_0xf060bf[_0x4cf9('0x21')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2be4f5,_0xeb3a9f){return function(_0x4de459){if(!_0x4de459){_0x2be4f5[_0x4cf9('0x2e')](0x194);}return _0x4de459;};}function handleError(_0x4f0158,_0x187dff){_0x187dff=_0x187dff||0x1f4;return function(_0x37eb4c){logger[_0x4cf9('0x2f')](_0x37eb4c['stack']);if(_0x37eb4c[_0x4cf9('0x30')]){delete _0x37eb4c['name'];}_0x4f0158['status'](_0x187dff)[_0x4cf9('0x31')](_0x37eb4c);};}exports[_0x4cf9('0x32')]=function(_0xa88a8f,_0x5853dc){var _0x3f9837={},_0x18f98e={},_0xfdad99={'count':0x0,'rows':[]};var _0x4a9d0f=_['map'](db[_0x4cf9('0x33')][_0x4cf9('0x34')],function(_0x145f64){return{'name':_0x145f64[_0x4cf9('0x35')],'type':_0x145f64['type'][_0x4cf9('0x36')]};});_0x18f98e[_0x4cf9('0x37')]=_[_0x4cf9('0x38')](_0x4a9d0f,_0x4cf9('0x30'));_0x18f98e[_0x4cf9('0x39')]=_[_0x4cf9('0x3a')](_0xa88a8f['query']);_0x18f98e['filters']=_['intersection'](_0x18f98e[_0x4cf9('0x37')],_0x18f98e['query']);_0x3f9837[_0x4cf9('0x3b')]=_[_0x4cf9('0x3c')](_0x18f98e['model'],qs[_0x4cf9('0x3d')](_0xa88a8f['query'][_0x4cf9('0x3d')]));_0x3f9837[_0x4cf9('0x3b')]=_0x3f9837[_0x4cf9('0x3b')][_0x4cf9('0x3e')]?_0x3f9837[_0x4cf9('0x3b')]:_0x18f98e[_0x4cf9('0x37')];if(!_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x3f')](_0x4cf9('0x40'))){_0x3f9837[_0x4cf9('0x25')]=qs[_0x4cf9('0x25')](_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x25')]);_0x3f9837['offset']=qs[_0x4cf9('0x24')](_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x24')]);}_0x3f9837['order']=qs['sort'](_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x41')]);_0x3f9837[_0x4cf9('0x42')]=qs[_0x4cf9('0x43')](_[_0x4cf9('0x44')](_0xa88a8f[_0x4cf9('0x39')],_0x18f98e[_0x4cf9('0x43')]),_0x4a9d0f);if(_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x45')]){_0x3f9837['where']=_['merge'](_0x3f9837[_0x4cf9('0x42')],{'$or':_[_0x4cf9('0x38')](_0x4a9d0f,function(_0x4f8189){if(_0x4f8189[_0x4cf9('0x46')]!==_0x4cf9('0x47')){var _0x438c98={};_0x438c98[_0x4f8189['name']]={'$like':'%'+_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x45')]+'%'};return _0x438c98;}})});}_0x3f9837=_[_0x4cf9('0x48')]({},_0x3f9837,_0xa88a8f[_0x4cf9('0x49')]);var _0x2e5e6e={'where':_0x3f9837[_0x4cf9('0x42')]};return db[_0x4cf9('0x33')][_0x4cf9('0x26')](_0x2e5e6e)[_0x4cf9('0x2a')](function(_0x45b9b3){_0xfdad99[_0x4cf9('0x26')]=_0x45b9b3;if(_0xa88a8f[_0x4cf9('0x39')][_0x4cf9('0x4a')]){_0x3f9837[_0x4cf9('0x4b')]=[{'all':!![]}];}return db['Plugin'][_0x4cf9('0x4c')](_0x3f9837);})[_0x4cf9('0x2a')](function(_0x4b8c53){_0xfdad99[_0x4cf9('0x4d')]=_0x4b8c53;return _0xfdad99;})['then'](respondWithFilteredResult(_0x5853dc,_0x3f9837))[_0x4cf9('0x4e')](handleError(_0x5853dc,null));};exports[_0x4cf9('0x4f')]=function(_0x19ac5b,_0x2dcfa6){var _0x6d0a0e={'raw':!![],'where':{'id':_0x19ac5b[_0x4cf9('0x50')]['id']}},_0x24dd6c={};_0x24dd6c[_0x4cf9('0x37')]=_['keys'](db[_0x4cf9('0x33')][_0x4cf9('0x34')]);_0x24dd6c[_0x4cf9('0x39')]=_[_0x4cf9('0x3a')](_0x19ac5b['query']);_0x24dd6c[_0x4cf9('0x43')]=_['intersection'](_0x24dd6c['model'],_0x24dd6c[_0x4cf9('0x39')]);_0x6d0a0e[_0x4cf9('0x3b')]=_[_0x4cf9('0x3c')](_0x24dd6c[_0x4cf9('0x37')],qs[_0x4cf9('0x3d')](_0x19ac5b['query']['fields']));_0x6d0a0e[_0x4cf9('0x3b')]=_0x6d0a0e['attributes']['length']?_0x6d0a0e[_0x4cf9('0x3b')]:_0x24dd6c[_0x4cf9('0x37')];if(_0x19ac5b['query']['includeAll']){_0x6d0a0e[_0x4cf9('0x4b')]=[{'all':!![]}];}_0x6d0a0e=_[_0x4cf9('0x48')]({},_0x6d0a0e,_0x19ac5b[_0x4cf9('0x49')]);return db[_0x4cf9('0x33')]['find'](_0x6d0a0e)[_0x4cf9('0x2a')](handleEntityNotFound(_0x2dcfa6,null))[_0x4cf9('0x2a')](respondWithResult(_0x2dcfa6,null))['catch'](handleError(_0x2dcfa6,null));};exports[_0x4cf9('0x51')]=function(_0x5ce63c,_0x254039,_0x12dbd3){return db[_0x4cf9('0x33')][_0x4cf9('0x52')]({'where':{'id':_0x5ce63c['params']['id']},'attributes':[_0x4cf9('0x30'),_0x4cf9('0x6')],'raw':!![]})[_0x4cf9('0x2a')](handleEntityNotFound(_0x254039,null))[_0x4cf9('0x2a')](function(_0x2b2632){if(_0x2b2632){var _0x49b20d=path[_0x4cf9('0x53')](config[_0x4cf9('0x54')],'server/files/plugins',util[_0x4cf9('0x55')]('%s.zip',path['basename'](_0x2b2632['path'])));var _0x5cac2c=fs[_0x4cf9('0x56')](_0x49b20d);var _0x165096=archiver(_0x4cf9('0x57'),{'zlib':{'level':0x9}});_0x165096['on'](_0x4cf9('0x58'),function(_0x3d2357){if(_0x3d2357[_0x4cf9('0x59')]===_0x4cf9('0x5a')){logger[_0x4cf9('0x2f')](_0x3d2357);}else{throw new db[(_0x4cf9('0x5b'))][(_0x4cf9('0x5c'))](_0x4cf9('0x5d'));}});_0x165096['on'](_0x4cf9('0x2f'),function(_0x5f12cc){throw new db[(_0x4cf9('0x5b'))]['Error']('Error\x20while\x20generating\x20the\x20zip\x20archive');});_0x165096['pipe'](_0x5cac2c);_0x165096[_0x4cf9('0x5e')](_0x4cf9('0x5f'),{'cwd':path['join'](config[_0x4cf9('0x54')],'server/files/plugins',path[_0x4cf9('0x60')](_0x2b2632[_0x4cf9('0x6')])),'ignore':[path[_0x4cf9('0x53')](path[_0x4cf9('0x61')](_0x2b2632['path']),_0x4cf9('0x62')),path['join'](path[_0x4cf9('0x61')](_0x2b2632['path']),_0x4cf9('0x63'))],'nodir':!![]})['finalize']();_0x5cac2c['on']('close',function(){if(!fs['existsSync'](_0x49b20d)){throw new db[(_0x4cf9('0x5b'))]['Error']('Plugin\x20not\x20found');}return _0x254039[_0x4cf9('0x51')](_0x49b20d,util[_0x4cf9('0x55')](_0x4cf9('0x64'),path[_0x4cf9('0x61')](_0x2b2632[_0x4cf9('0x6')])),function(_0x31d62d){if(_0x31d62d){throw new db['Sequelize'][(_0x4cf9('0x5c'))](_0x4cf9('0x65'));}fs[_0x4cf9('0x66')](_0x49b20d);logger['info'](_0x4cf9('0x67'));logger['info'](_0x4cf9('0x68'));});});}return null;})[_0x4cf9('0x4e')](handleError(_0x254039,null));};exports['upload']=function(_0x2500d2,_0x2894c7,_0x2d74af){var _0x281eff=path['basename'](_0x2500d2['file'][_0x4cf9('0x69')],path[_0x4cf9('0x6a')](_0x2500d2[_0x4cf9('0x6b')][_0x4cf9('0x69')]));var _0x1b5cf2=path[_0x4cf9('0x53')](config['root'],_0x4cf9('0x6c'),_0x2500d2[_0x4cf9('0x6b')][_0x4cf9('0x69')]);var _0x5aa4f9=path[_0x4cf9('0x53')](config[_0x4cf9('0x54')],_0x4cf9('0x6c'),_0x281eff);logger[_0x4cf9('0x6d')](_0x4cf9('0x6e'),_0x1b5cf2);logger[_0x4cf9('0x6d')](_0x4cf9('0x6f'),_0x5aa4f9);try{fs[_0x4cf9('0x70')](_0x1b5cf2,parseInt(_0x4cf9('0x71'),0x8));extract(_0x1b5cf2,{'dir':_0x5aa4f9},function(_0x2f9599){if(_0x2f9599){logger[_0x4cf9('0x2f')](_0x2f9599);handleError(_0x2f9599,!![]);};var _0x20e0de=fs[_0x4cf9('0x72')](_0x5aa4f9);if(_0x20e0de[_0x4cf9('0x3e')]>0x1){removeReferences(_0x1b5cf2,_0x5aa4f9);logger[_0x4cf9('0x2f')](_0x4cf9('0x73'));return _0x2d74af(new Error(_0x4cf9('0x73')));}var _0x1836cf=fs[_0x4cf9('0x74')](path[_0x4cf9('0x53')](_0x5aa4f9,_0x20e0de[0x0]));if(_0x1836cf[_0x4cf9('0x75')]()){removeReferences(_0x1b5cf2,_0x5aa4f9);logger[_0x4cf9('0x2f')]('Invalid\x20plugin\x20structure');return _0x2d74af(new Error(_0x4cf9('0x73')));}if(_0x1836cf[_0x4cf9('0x76')]()){var _0x129317=fs[_0x4cf9('0x72')](path[_0x4cf9('0x53')](_0x5aa4f9,_0x20e0de[0x0]));if(_0x129317[_0x4cf9('0x3e')]===0x0){removeReferences(_0x1b5cf2,_0x5aa4f9);logger['error']('Invalid\x20plugin\x20structure');return _0x2d74af(new Error(_0x4cf9('0x73')));}var _0x2e6c7c=_0x129317[_0x4cf9('0x77')](function(_0x3ed05a){return _0x3ed05a===_0x4cf9('0x78');});if(!_0x2e6c7c){return _0x2d74af(new Error(_0x4cf9('0x79')));}var _0x543034=fs[_0x4cf9('0x7a')](path[_0x4cf9('0x53')](_0x5aa4f9,_0x20e0de[0x0],'manifest.json'));var _0x548093=JSON[_0x4cf9('0x7b')](_0x543034);if(_0x4cf9('0x7c')==typeof _0x548093['name']){return _0x2d74af(new Error(_0x4cf9('0x7d')));}if(_0x4cf9('0x7c')==typeof _0x548093[_0x4cf9('0x46')]){return _0x2d74af(new Error(_0x4cf9('0x7e')));}if('undefined'==typeof _0x548093[_0x4cf9('0x7f')]){return _0x2d74af(new Error(_0x4cf9('0x80')));}if(_0x4cf9('0x7c')==typeof _0x548093[_0x4cf9('0x81')]){return _0x2d74af(new Error(_0x4cf9('0x82')));}if(_0x548093['type']==='html'){if(_0x4cf9('0x7c')==typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')]){return _0x2d74af(new Error(_0x4cf9('0x84')));}if(_0x4cf9('0x7c')==typeof _0x548093['parameters'][_0x4cf9('0x83')][_0x4cf9('0x85')]&&_0x4cf9('0x7c')==typeof _0x548093['parameters']['views'][_0x4cf9('0x86')]){return _0x2d74af(new Error(_0x4cf9('0x87')));}}else if(_0x548093[_0x4cf9('0x46')]==='script'){if(_0x4cf9('0x7c')==typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x88')]){return _0x2d74af(new Error(_0x4cf9('0x89')));}if(_0x4cf9('0x7c')==typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x8a')]){return _0x2d74af(new Error(_0x4cf9('0x8b')));}}else{return _0x2d74af(new Error(_0x4cf9('0x8c')));}var _0x39015d=_0x548093['name'];var _0x56218f=_0x548093[_0x4cf9('0x8d')];var _0x1071c7=_0x548093[_0x4cf9('0x46')];var _0x13bc85=_0x548093['sidebar']?_0x548093['sidebar']:_0x4cf9('0x8e');var _0x3c1e7d=_0x548093['icon']?_0x548093[_0x4cf9('0x8f')]:_0x4cf9('0x90');var _0x46cafb='';var _0x17e041='';var _0x36b9f5='';var _0x3d371e='';var _0x4e3943=_0x548093['version'];if(_0x1071c7===_0x4cf9('0x91')){if(_0x4cf9('0x7c')!=typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')][_0x4cf9('0x85')]){var _0x1e4e0d=_0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')][_0x4cf9('0x85')];if(!/^(f|ht)tps?:\/\//i[_0x4cf9('0x92')](_0x1e4e0d)){_0x46cafb=path[_0x4cf9('0x53')](_0x4cf9('0x93'),_0x281eff,_0x20e0de[0x0],_0x1e4e0d);}else{_0x46cafb=_0x1e4e0d;}}else{logger['info']('Warning:\x20admin\x20view\x20not\x20specified');}if('undefined'!=typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')]['agent']){var _0x43b52d=_0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')][_0x4cf9('0x86')];if(!/^(f|ht)tps?:\/\//i['test'](_0x43b52d)){_0x17e041=path['join'](_0x4cf9('0x93'),_0x281eff,_0x20e0de[0x0],_0x43b52d);}else{_0x17e041=_0x43b52d;}}else{logger['info'](_0x4cf9('0x94'));}}else if(_0x1071c7==='script'){_0x36b9f5=_0x548093[_0x4cf9('0x81')]['scriptName'];_0x3d371e=_0x548093[_0x4cf9('0x81')][_0x4cf9('0x8a')];if(_0x4cf9('0x7c')!=typeof _0x548093['parameters'][_0x4cf9('0x83')]){if(_0x4cf9('0x7c')!=typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')][_0x4cf9('0x85')]){var _0x1e4e0d=_0x548093['parameters'][_0x4cf9('0x83')][_0x4cf9('0x85')];if(!/^(f|ht)tps?:\/\//i[_0x4cf9('0x92')](_0x1e4e0d)){_0x46cafb=path['join'](_0x4cf9('0x93'),_0x281eff,_0x20e0de[0x0],_0x1e4e0d);}else{_0x46cafb=_0x1e4e0d;}}if('undefined'!=typeof _0x548093[_0x4cf9('0x81')][_0x4cf9('0x83')][_0x4cf9('0x86')]){var _0x43b52d=_0x548093['parameters'][_0x4cf9('0x83')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0x4cf9('0x92')](_0x43b52d)){_0x17e041=path[_0x4cf9('0x53')](_0x4cf9('0x93'),_0x281eff,_0x20e0de[0x0],_0x43b52d);}else{_0x17e041=_0x43b52d;}}}}var _0x35efbb={'name':_0x39015d,'description':_0x56218f,'path':path[_0x4cf9('0x53')](_0x281eff,_0x20e0de[0x0]),'type':_0x1071c7,'sidebar':_0x13bc85,'icon':_0x3c1e7d,'adminUrl':_0x46cafb,'agentUrl':_0x17e041,'scriptName':_0x36b9f5,'scriptPath':_0x3d371e,'version':_0x4e3943};removeReferences(_0x1b5cf2,null);return db[_0x4cf9('0x33')]['create'](_0x35efbb)[_0x4cf9('0x2a')](function(_0x4f241b){var _0x4097f8={'role':_0x2500d2['body']['role'],'userProfileId':_0x2500d2['body'][_0x4cf9('0x95')]};if(!_0x4097f8)throw new Error(_0x4cf9('0x96'));if(_0x4097f8[_0x4cf9('0x97')]===_0x4cf9('0x98')){var _0x38d178=_0x4f241b[_0x4cf9('0x2c')]({'plain':!![]});return db[_0x4cf9('0x99')][_0x4cf9('0x52')]({'where':{'name':_0x4cf9('0x2d'),'userProfileId':_0x4097f8[_0x4cf9('0x95')]},'raw':!![]})[_0x4cf9('0x2a')](function(_0x3fd80d){if(_0x3fd80d&&_0x3fd80d[_0x4cf9('0x9a')]===0x0){return db[_0x4cf9('0x9b')]['create']({'name':_0x38d178[_0x4cf9('0x30')],'resourceId':_0x38d178['id'],'type':_0x3fd80d['name'],'sectionId':_0x3fd80d['id']},{})[_0x4cf9('0x2a')](function(){return _0x4f241b;});}else{return _0x4f241b;}})['catch'](function(_0xf3b5b5){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xf3b5b5);throw _0xf3b5b5;});}return _0x4f241b;})[_0x4cf9('0x2a')](respondWithResult(_0x2894c7,null))[_0x4cf9('0x4e')](handleError(_0x2894c7,null));}});}catch(_0x2d2854){_0x2894c7[_0x4cf9('0x21')](0x1f4)['send'](_0x2d2854);}};function removeReferences(_0x471d42,_0xe08732){try{if(_0x471d42){fs[_0x4cf9('0x66')](_0x471d42);logger[_0x4cf9('0x6d')](_0x4cf9('0x9c'));}if(_0xe08732){rimraf(_0xe08732,function(){});logger['info']('Extracted\x20folder\x20removed');}}catch(_0x2bad4a){logger['error'](_0x2bad4a);}}exports['update']=function(_0x4f5abe,_0x30f723,_0x47e59f){return db[_0x4cf9('0x33')][_0x4cf9('0x52')]({'where':{'id':_0x4f5abe[_0x4cf9('0x50')]['id']}})[_0x4cf9('0x2a')](handleEntityNotFound(_0x30f723,null))[_0x4cf9('0x2a')](saveUpdates(_0x4f5abe['body'],null))[_0x4cf9('0x2a')](respondWithResult(_0x30f723,null))[_0x4cf9('0x4e')](handleError(_0x30f723,null));};exports[_0x4cf9('0x9d')]=function(_0x218bef,_0x1c4d6e,_0x52d700){return db['Plugin'][_0x4cf9('0x52')]({'where':{'id':_0x218bef[_0x4cf9('0x50')]['id']}})['then'](function(_0x38b253){if(_0x38b253){return _0x38b253[_0x4cf9('0x2b')]();}})[_0x4cf9('0x2a')](function(_0x107f8d){rimraf(path[_0x4cf9('0x53')](config[_0x4cf9('0x54')],'server/files/plugins',path['dirname'](_0x107f8d[_0x4cf9('0x6')])),function(){});return _0x107f8d;})[_0x4cf9('0x2a')](handleEntityNotFound(_0x1c4d6e,null))[_0x4cf9('0x2a')](respondWithStatusCode(_0x1c4d6e,null))[_0x4cf9('0x4e')](handleError(_0x1c4d6e,null));};exports[_0x4cf9('0x9e')]=function(_0x53fb39,_0x257e13,_0x1cfc6d){return BPromise[_0x4cf9('0x9f')]()[_0x4cf9('0x2a')](function(){if(!_0x53fb39['query']['path']){throw new Error(_0x4cf9('0xa0'));}if(!_0x53fb39[_0x4cf9('0x39')][_0x4cf9('0xa1')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x121e27=_0x53fb39[_0x4cf9('0x39')][_0x4cf9('0xa2')]?_0x53fb39[_0x4cf9('0x39')][_0x4cf9('0xa2')]+':'+_0x53fb39['query'][_0x4cf9('0xa1')]:'http://localhost:'+_0x53fb39['query']['port'];var _0x470f47=_0x53fb39[_0x4cf9('0x39')][_0x4cf9('0x23')]?_0x53fb39[_0x4cf9('0x39')]['json']:!![];var _0x3493ed=_0x53fb39[_0x4cf9('0x39')][_0x4cf9('0xa3')]?_0x53fb39[_0x4cf9('0x39')]['encoding']:null;var _0x262819={'method':_0x53fb39[_0x4cf9('0xa4')],'uri':util[_0x4cf9('0x55')](_0x4cf9('0xa5'),_0x121e27,_0x53fb39['query']['path']),'json':_0x470f47,'resolveWithFullResponse':!![],'encoding':_0x3493ed,'qs':_0x53fb39[_0x4cf9('0x39')]};if(_0x53fb39[_0x4cf9('0xa6')]){_0x262819[_0x4cf9('0xa6')]=_0x53fb39[_0x4cf9('0xa6')];if(_0x262819['headers']['content-length']){delete _0x262819[_0x4cf9('0xa6')]['content-length'];}}if(_0x262819[_0x4cf9('0xa6')][_0x4cf9('0xa7')]){delete _0x262819[_0x4cf9('0xa6')]['content-type'];}return rp(_0x262819);})[_0x4cf9('0x2a')](function(_0x380947){if(_0x380947){_0x257e13[_0x4cf9('0x27')](_0x380947['headers']);logger[_0x4cf9('0x6d')](_0x380947[_0x4cf9('0xa8')]);if(_[_0x4cf9('0xa9')](_0x53fb39['query'][_0x4cf9('0x6')],_0x4cf9('0x51'))&&_0x380947[_0x4cf9('0xaa')]==0x1f4){return _0x257e13['sendStatus'](_0x380947[_0x4cf9('0xaa')]);}else{return _0x257e13[_0x4cf9('0x21')](_0x380947[_0x4cf9('0xaa')])['send'](_0x380947['body']);}}else{return _0x257e13[_0x4cf9('0x2e')](0xc8);}})['catch'](handleError(_0x257e13,null));};exports['webhookPost']=function(_0x4003a6,_0x72af1b,_0x5cf69){return BPromise[_0x4cf9('0x9f')]()[_0x4cf9('0x2a')](function(){if(!_0x4003a6[_0x4cf9('0x39')]['path']){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x4003a6[_0x4cf9('0x39')]['port']){throw new Error(_0x4cf9('0xab'));}var _0x31ade7=_0x4003a6[_0x4cf9('0x39')]['hostname']?_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0xa2')]+':'+_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0xa1')]:_0x4cf9('0xac')+_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0xa1')];var _0x5326c3=_0x4003a6[_0x4cf9('0x39')]['json']?_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0x23')]:!![];var _0x36d7d0=_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0xa3')]?_0x4003a6[_0x4cf9('0x39')]['encoding']:null;var _0x3c61d1={'method':_0x4003a6[_0x4cf9('0xa4')],'uri':util['format'](_0x4cf9('0xa5'),_0x31ade7,_0x4003a6[_0x4cf9('0x39')][_0x4cf9('0x6')]),'json':_0x5326c3,'resolveWithFullResponse':!![],'encoding':_0x36d7d0,'body':_0x4003a6['body']};if(_0x4003a6['headers']){_0x3c61d1[_0x4cf9('0xa6')]=_0x4003a6['headers'];if(_0x3c61d1[_0x4cf9('0xa6')]['content-length']){delete _0x3c61d1[_0x4cf9('0xa6')][_0x4cf9('0xad')];}}if(_0x3c61d1['headers'][_0x4cf9('0xa7')]){delete _0x3c61d1[_0x4cf9('0xa6')]['content-type'];}return rp(_0x3c61d1);})[_0x4cf9('0x2a')](function(_0x5a7d92){if(_0x5a7d92){_0x72af1b[_0x4cf9('0x27')](_0x5a7d92[_0x4cf9('0xa6')]);logger['info'](_0x5a7d92[_0x4cf9('0xa8')]);return _0x72af1b['status'](_0x5a7d92[_0x4cf9('0xaa')])[_0x4cf9('0x31')](_0x5a7d92['body']);}else{return _0x72af1b[_0x4cf9('0x2e')](0xc8);}})[_0x4cf9('0x4e')](handleError(_0x72af1b,null));};
\ No newline at end of file
+var _0x23cb=['Invalid\x20plugin\x20structure','isDirectory','readdirSync','some','Plugin\x20manifest\x20missing','readFileSync','manifest.json','undefined','Invalid\x20manifest:\x20name\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','html','views','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','script','scriptName','Invalid\x20manifest:\x20invalid\x20type','always','icon','icon-apps','test','plugins','Warning:\x20agent\x20view\x20not\x20specified','scriptPath','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','get','UserProfileSection','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','Zip\x20archive\x20removed','update','delete','webhookGet','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','method','%s%s','headers','content-type','statusCode','webhookPost','encoding','content-length','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','to-csv','ejs','fs-extra','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','redis','defaults','localhost','socket.io-emitter','status','end','json','offset','limit','count','set','Content-Range','apply','reject','then','destroy','Plugins','UserProfileResource','sendStatus','error','stack','name','index','map','Plugin','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','keys','find','download','root','server/files/plugins','format','%s.zip','basename','zip','warning','code','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','**/*','join','dirname','node_modules/**/*','attachments/**/*','finalize','close','Plugin\x20not\x20found','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','Temporary\x20file\x20removed','file','filename','extname','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','lstatSync'];(function(_0x4032d4,_0x3db57f){var _0x4763f4=function(_0x3e0264){while(--_0x3e0264){_0x4032d4['push'](_0x4032d4['shift']());}};_0x4763f4(++_0x3db57f);}(_0x23cb,0x180));var _0xb23c=function(_0x20a089,_0x158776){_0x20a089=_0x20a089-0x0;var _0x4521e9=_0x23cb[_0x20a089];return _0x4521e9;};'use strict';var emlformat=require(_0xb23c('0x0'));var rimraf=require(_0xb23c('0x1'));var zipdir=require(_0xb23c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb23c('0x3'));var moment=require(_0xb23c('0x4'));var BPromise=require(_0xb23c('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xb23c('0x6'));var sox=require(_0xb23c('0x7'));var csv=require(_0xb23c('0x8'));var ejs=require(_0xb23c('0x9'));var fs=require('fs');var fs_extra=require(_0xb23c('0xa'));var _=require('lodash');var squel=require(_0xb23c('0xb'));var crypto=require('crypto');var jsforce=require(_0xb23c('0xc'));var deskjs=require(_0xb23c('0xd'));var toCsv=require(_0xb23c('0x8'));var querystring=require(_0xb23c('0xe'));var Papa=require(_0xb23c('0xf'));var extract=require('extract-zip');var rimraf=require('rimraf');var archiver=require('archiver');var Redis=require('ioredis');var authService=require(_0xb23c('0x10'));var qs=require(_0xb23c('0x11'));var as=require(_0xb23c('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb23c('0x13'))(_0xb23c('0x14'));var utils=require(_0xb23c('0x15'));var config=require(_0xb23c('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xb23c('0x17')]=_[_0xb23c('0x18')](config[_0xb23c('0x17')],{'host':_0xb23c('0x19'),'port':0x18eb});var socket=require(_0xb23c('0x1a'))(new Redis(config['redis']));require('./plugin.socket')['register'](socket);function respondWithStatusCode(_0x383b5b,_0x32238e){_0x32238e=_0x32238e||0xcc;return function(_0x712528){if(_0x712528){return _0x383b5b['sendStatus'](_0x32238e);}return _0x383b5b[_0xb23c('0x1b')](_0x32238e)[_0xb23c('0x1c')]();};}function respondWithResult(_0x285758,_0x239cdc){_0x239cdc=_0x239cdc||0xc8;return function(_0x5b7625){if(_0x5b7625){return _0x285758[_0xb23c('0x1b')](_0x239cdc)[_0xb23c('0x1d')](_0x5b7625);}};}function respondWithFilteredResult(_0x4eb741,_0x494f61){return function(_0x110f56){if(_0x110f56){var _0x1ed3a3=typeof _0x494f61[_0xb23c('0x1e')]==='undefined'&&typeof _0x494f61[_0xb23c('0x1f')]==='undefined';var _0xffddca=_0x110f56['count'];var _0x3e1c62=_0x1ed3a3?0x0:_0x494f61[_0xb23c('0x1e')];var _0x27b755=_0x1ed3a3?_0x110f56[_0xb23c('0x20')]:_0x494f61[_0xb23c('0x1e')]+_0x494f61[_0xb23c('0x1f')];var _0x390172;if(_0x27b755>=_0xffddca){_0x27b755=_0xffddca;_0x390172=0xc8;}else{_0x390172=0xce;}_0x4eb741[_0xb23c('0x1b')](_0x390172);return _0x4eb741[_0xb23c('0x21')](_0xb23c('0x22'),_0x3e1c62+'-'+_0x27b755+'/'+_0xffddca)[_0xb23c('0x1d')](_0x110f56);}return null;};}function patchUpdates(_0x2a7fa8){return function(_0x2560f8){try{jsonpatch[_0xb23c('0x23')](_0x2560f8,_0x2a7fa8,!![]);}catch(_0x3d8a45){return BPromise[_0xb23c('0x24')](_0x3d8a45);}return _0x2560f8['save']();};}function saveUpdates(_0x4b598f,_0x2bf8a8){return function(_0x40f1a7){if(_0x40f1a7){return _0x40f1a7['update'](_0x4b598f)[_0xb23c('0x25')](function(_0x45e49a){return _0x45e49a;});}return null;};}function removeEntity(_0x4b5979,_0x902107){return function(_0x4f819c){if(_0x4f819c){return _0x4f819c[_0xb23c('0x26')]()[_0xb23c('0x25')](function(){var _0x5331bd=_0x4f819c['get']({'plain':!![]});var _0xe0e775=_0xb23c('0x27');return db[_0xb23c('0x28')]['destroy']({'where':{'type':_0xe0e775,'resourceId':_0x5331bd['id']}})[_0xb23c('0x25')](function(){return _0x4f819c;});})[_0xb23c('0x25')](function(){_0x4b5979[_0xb23c('0x1b')](0xcc)[_0xb23c('0x1c')]();});}};}function handleEntityNotFound(_0x516ce7,_0x4c9ab0){return function(_0x115dfe){if(!_0x115dfe){_0x516ce7[_0xb23c('0x29')](0x194);}return _0x115dfe;};}function handleError(_0x524266,_0xb7f239){_0xb7f239=_0xb7f239||0x1f4;return function(_0x52aab5){logger[_0xb23c('0x2a')](_0x52aab5[_0xb23c('0x2b')]);if(_0x52aab5[_0xb23c('0x2c')]){delete _0x52aab5['name'];}_0x524266['status'](_0xb7f239)['send'](_0x52aab5);};}exports[_0xb23c('0x2d')]=function(_0x387335,_0x9b8acd){var _0x567842={},_0x654989={},_0x1eedd8={'count':0x0,'rows':[]};var _0x25bcb4=_[_0xb23c('0x2e')](db[_0xb23c('0x2f')][_0xb23c('0x30')],function(_0x21b945){return{'name':_0x21b945[_0xb23c('0x31')],'type':_0x21b945[_0xb23c('0x32')][_0xb23c('0x33')]};});_0x654989[_0xb23c('0x34')]=_[_0xb23c('0x2e')](_0x25bcb4,_0xb23c('0x2c'));_0x654989[_0xb23c('0x35')]=_['keys'](_0x387335[_0xb23c('0x35')]);_0x654989[_0xb23c('0x36')]=_[_0xb23c('0x37')](_0x654989[_0xb23c('0x34')],_0x654989['query']);_0x567842[_0xb23c('0x38')]=_[_0xb23c('0x37')](_0x654989['model'],qs[_0xb23c('0x39')](_0x387335[_0xb23c('0x35')][_0xb23c('0x39')]));_0x567842[_0xb23c('0x38')]=_0x567842[_0xb23c('0x38')][_0xb23c('0x3a')]?_0x567842['attributes']:_0x654989[_0xb23c('0x34')];if(!_0x387335[_0xb23c('0x35')][_0xb23c('0x3b')]('nolimit')){_0x567842[_0xb23c('0x1f')]=qs[_0xb23c('0x1f')](_0x387335['query'][_0xb23c('0x1f')]);_0x567842['offset']=qs['offset'](_0x387335[_0xb23c('0x35')][_0xb23c('0x1e')]);}_0x567842['order']=qs['sort'](_0x387335[_0xb23c('0x35')][_0xb23c('0x3c')]);_0x567842[_0xb23c('0x3d')]=qs[_0xb23c('0x36')](_['pick'](_0x387335['query'],_0x654989['filters']),_0x25bcb4);if(_0x387335[_0xb23c('0x35')][_0xb23c('0x3e')]){_0x567842[_0xb23c('0x3d')]=_[_0xb23c('0x3f')](_0x567842[_0xb23c('0x3d')],{'$or':_[_0xb23c('0x2e')](_0x25bcb4,function(_0x4cfb8d){if(_0x4cfb8d[_0xb23c('0x32')]!==_0xb23c('0x40')){var _0xd4fa6e={};_0xd4fa6e[_0x4cfb8d['name']]={'$like':'%'+_0x387335[_0xb23c('0x35')][_0xb23c('0x3e')]+'%'};return _0xd4fa6e;}})});}_0x567842=_[_0xb23c('0x3f')]({},_0x567842,_0x387335[_0xb23c('0x41')]);var _0x35416e={'where':_0x567842[_0xb23c('0x3d')]};return db[_0xb23c('0x2f')][_0xb23c('0x20')](_0x35416e)[_0xb23c('0x25')](function(_0x362a4d){_0x1eedd8[_0xb23c('0x20')]=_0x362a4d;if(_0x387335[_0xb23c('0x35')][_0xb23c('0x42')]){_0x567842[_0xb23c('0x43')]=[{'all':!![]}];}return db[_0xb23c('0x2f')]['findAll'](_0x567842);})['then'](function(_0x2a580e){_0x1eedd8[_0xb23c('0x44')]=_0x2a580e;return _0x1eedd8;})[_0xb23c('0x25')](respondWithFilteredResult(_0x9b8acd,_0x567842))[_0xb23c('0x45')](handleError(_0x9b8acd,null));};exports[_0xb23c('0x46')]=function(_0x4ea493,_0x5453c1){var _0x472727={'raw':!![],'where':{'id':_0x4ea493[_0xb23c('0x47')]['id']}},_0x43e14c={};_0x43e14c[_0xb23c('0x34')]=_[_0xb23c('0x48')](db['Plugin'][_0xb23c('0x30')]);_0x43e14c[_0xb23c('0x35')]=_[_0xb23c('0x48')](_0x4ea493[_0xb23c('0x35')]);_0x43e14c[_0xb23c('0x36')]=_[_0xb23c('0x37')](_0x43e14c['model'],_0x43e14c[_0xb23c('0x35')]);_0x472727['attributes']=_[_0xb23c('0x37')](_0x43e14c[_0xb23c('0x34')],qs[_0xb23c('0x39')](_0x4ea493[_0xb23c('0x35')]['fields']));_0x472727[_0xb23c('0x38')]=_0x472727['attributes'][_0xb23c('0x3a')]?_0x472727[_0xb23c('0x38')]:_0x43e14c['model'];if(_0x4ea493[_0xb23c('0x35')][_0xb23c('0x42')]){_0x472727['include']=[{'all':!![]}];}_0x472727=_['merge']({},_0x472727,_0x4ea493[_0xb23c('0x41')]);return db[_0xb23c('0x2f')][_0xb23c('0x49')](_0x472727)[_0xb23c('0x25')](handleEntityNotFound(_0x5453c1,null))[_0xb23c('0x25')](respondWithResult(_0x5453c1,null))[_0xb23c('0x45')](handleError(_0x5453c1,null));};exports[_0xb23c('0x4a')]=function(_0xbb22b4,_0x5332d5,_0xd262d3){return db[_0xb23c('0x2f')][_0xb23c('0x49')]({'where':{'id':_0xbb22b4[_0xb23c('0x47')]['id']},'attributes':[_0xb23c('0x2c'),_0xb23c('0x6')],'raw':!![]})[_0xb23c('0x25')](handleEntityNotFound(_0x5332d5,null))[_0xb23c('0x25')](function(_0x4ab537){if(_0x4ab537){var _0x2a8eab=path['join'](config[_0xb23c('0x4b')],_0xb23c('0x4c'),util[_0xb23c('0x4d')](_0xb23c('0x4e'),path[_0xb23c('0x4f')](_0x4ab537[_0xb23c('0x6')])));var _0xb546cf=fs['createWriteStream'](_0x2a8eab);var _0x56e177=archiver(_0xb23c('0x50'),{'zlib':{'level':0x9}});_0x56e177['on'](_0xb23c('0x51'),function(_0x29a573){if(_0x29a573[_0xb23c('0x52')]==='ENOENT'){logger[_0xb23c('0x2a')](_0x29a573);}else{throw new db[(_0xb23c('0x53'))][(_0xb23c('0x54'))](_0xb23c('0x55'));}});_0x56e177['on']('error',function(_0x283306){throw new db['Sequelize']['Error']('Error\x20while\x20generating\x20the\x20zip\x20archive');});_0x56e177[_0xb23c('0x56')](_0xb546cf);_0x56e177[_0xb23c('0x57')](_0xb23c('0x58'),{'cwd':path[_0xb23c('0x59')](config[_0xb23c('0x4b')],_0xb23c('0x4c'),path[_0xb23c('0x5a')](_0x4ab537[_0xb23c('0x6')])),'ignore':[path[_0xb23c('0x59')](path[_0xb23c('0x4f')](_0x4ab537[_0xb23c('0x6')]),_0xb23c('0x5b')),path[_0xb23c('0x59')](path['basename'](_0x4ab537[_0xb23c('0x6')]),_0xb23c('0x5c'))],'nodir':!![]})[_0xb23c('0x5d')]();_0xb546cf['on'](_0xb23c('0x5e'),function(){if(!fs['existsSync'](_0x2a8eab)){throw new db['Sequelize'][(_0xb23c('0x54'))](_0xb23c('0x5f'));}return _0x5332d5[_0xb23c('0x4a')](_0x2a8eab,util['format'](_0xb23c('0x4e'),path[_0xb23c('0x4f')](_0x4ab537[_0xb23c('0x6')])),function(_0x2afa55){if(_0x2afa55){throw new db['Sequelize'][(_0xb23c('0x54'))](_0xb23c('0x60'));}fs[_0xb23c('0x61')](_0x2a8eab);logger[_0xb23c('0x62')](_0xb23c('0x63'));logger[_0xb23c('0x62')](_0xb23c('0x64'));});});}return null;})[_0xb23c('0x45')](handleError(_0x5332d5,null));};exports['upload']=function(_0x4d3893,_0x4fd884,_0x2778b4){var _0x1275d5=path[_0xb23c('0x4f')](_0x4d3893[_0xb23c('0x65')][_0xb23c('0x66')],path[_0xb23c('0x67')](_0x4d3893[_0xb23c('0x65')][_0xb23c('0x66')]));var _0x5c512b=path[_0xb23c('0x59')](config[_0xb23c('0x4b')],'server/files/plugins',_0x4d3893[_0xb23c('0x65')][_0xb23c('0x66')]);var _0x28f6f9=path[_0xb23c('0x59')](config['root'],'server/files/plugins',_0x1275d5);logger[_0xb23c('0x62')](_0xb23c('0x68'),_0x5c512b);logger['info'](_0xb23c('0x69'),_0x28f6f9);try{fs[_0xb23c('0x6a')](_0x5c512b,parseInt('0777',0x8));extract(_0x5c512b,{'dir':_0x28f6f9},function(_0x14ed47){if(_0x14ed47){logger[_0xb23c('0x2a')](_0x14ed47);handleError(_0x14ed47,!![]);};var _0x79455e=fs['readdirSync'](_0x28f6f9);if(_0x79455e[_0xb23c('0x3a')]>0x1){removeReferences(_0x5c512b,_0x28f6f9);logger['error']('Invalid\x20plugin\x20structure');return _0x2778b4(new Error('Invalid\x20plugin\x20structure'));}var _0x5c4ce2=fs[_0xb23c('0x6b')](path['join'](_0x28f6f9,_0x79455e[0x0]));if(_0x5c4ce2['isFile']()){removeReferences(_0x5c512b,_0x28f6f9);logger[_0xb23c('0x2a')](_0xb23c('0x6c'));return _0x2778b4(new Error(_0xb23c('0x6c')));}if(_0x5c4ce2[_0xb23c('0x6d')]()){var _0x30db34=fs[_0xb23c('0x6e')](path[_0xb23c('0x59')](_0x28f6f9,_0x79455e[0x0]));if(_0x30db34[_0xb23c('0x3a')]===0x0){removeReferences(_0x5c512b,_0x28f6f9);logger[_0xb23c('0x2a')]('Invalid\x20plugin\x20structure');return _0x2778b4(new Error('Invalid\x20plugin\x20structure'));}var _0x5687f3=_0x30db34[_0xb23c('0x6f')](function(_0x58c036){return _0x58c036==='manifest.json';});if(!_0x5687f3){return _0x2778b4(new Error(_0xb23c('0x70')));}var _0xe23a5b=fs[_0xb23c('0x71')](path[_0xb23c('0x59')](_0x28f6f9,_0x79455e[0x0],_0xb23c('0x72')));var _0xa747a5=JSON['parse'](_0xe23a5b);if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x2c')]){return _0x2778b4(new Error(_0xb23c('0x74')));}if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x32')]){return _0x2778b4(new Error('Invalid\x20manifest:\x20type\x20missing'));}if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x75')]){return _0x2778b4(new Error(_0xb23c('0x76')));}if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x77')]){return _0x2778b4(new Error(_0xb23c('0x78')));}if(_0xa747a5['type']===_0xb23c('0x79')){if('undefined'==typeof _0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')]){return _0x2778b4(new Error('Invalid\x20manifest:\x20views\x20missing'));}if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x77')]['views'][_0xb23c('0x7b')]&&'undefined'==typeof _0xa747a5[_0xb23c('0x77')]['views'][_0xb23c('0x7c')]){return _0x2778b4(new Error(_0xb23c('0x7d')));}}else if(_0xa747a5[_0xb23c('0x32')]===_0xb23c('0x7e')){if(_0xb23c('0x73')==typeof _0xa747a5['parameters'][_0xb23c('0x7f')]){return _0x2778b4(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0xb23c('0x73')==typeof _0xa747a5[_0xb23c('0x77')]['scriptPath']){return _0x2778b4(new Error('Invalid\x20manifest:\x20script\x20path\x20missing'));}}else{return _0x2778b4(new Error(_0xb23c('0x80')));}var _0x580c09=_0xa747a5[_0xb23c('0x2c')];var _0x1c1120=_0xa747a5['description'];var _0x16819a=_0xa747a5[_0xb23c('0x32')];var _0x368d48=_0xa747a5['sidebar']?_0xa747a5['sidebar']:_0xb23c('0x81');var _0x8f793=_0xa747a5[_0xb23c('0x82')]?_0xa747a5[_0xb23c('0x82')]:_0xb23c('0x83');var _0x43679a='';var _0x260dc0='';var _0x1c00e6='';var _0x52756a='';var _0x15a904=_0xa747a5['version'];if(_0x16819a===_0xb23c('0x79')){if('undefined'!=typeof _0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')][_0xb23c('0x7b')]){var _0x24461c=_0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')][_0xb23c('0x7b')];if(!/^(f|ht)tps?:\/\//i[_0xb23c('0x84')](_0x24461c)){_0x43679a=path['join'](_0xb23c('0x85'),_0x1275d5,_0x79455e[0x0],_0x24461c);}else{_0x43679a=_0x24461c;}}else{logger[_0xb23c('0x62')]('Warning:\x20admin\x20view\x20not\x20specified');}if(_0xb23c('0x73')!=typeof _0xa747a5['parameters'][_0xb23c('0x7a')][_0xb23c('0x7c')]){var _0x812deb=_0xa747a5[_0xb23c('0x77')]['views'][_0xb23c('0x7c')];if(!/^(f|ht)tps?:\/\//i[_0xb23c('0x84')](_0x812deb)){_0x260dc0=path[_0xb23c('0x59')](_0xb23c('0x85'),_0x1275d5,_0x79455e[0x0],_0x812deb);}else{_0x260dc0=_0x812deb;}}else{logger[_0xb23c('0x62')](_0xb23c('0x86'));}}else if(_0x16819a===_0xb23c('0x7e')){_0x1c00e6=_0xa747a5['parameters'][_0xb23c('0x7f')];_0x52756a=_0xa747a5['parameters'][_0xb23c('0x87')];if('undefined'!=typeof _0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')]){if(_0xb23c('0x73')!=typeof _0xa747a5[_0xb23c('0x77')]['views'][_0xb23c('0x7b')]){var _0x24461c=_0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')][_0xb23c('0x7b')];if(!/^(f|ht)tps?:\/\//i[_0xb23c('0x84')](_0x24461c)){_0x43679a=path[_0xb23c('0x59')](_0xb23c('0x85'),_0x1275d5,_0x79455e[0x0],_0x24461c);}else{_0x43679a=_0x24461c;}}if('undefined'!=typeof _0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')][_0xb23c('0x7c')]){var _0x812deb=_0xa747a5[_0xb23c('0x77')][_0xb23c('0x7a')][_0xb23c('0x7c')];if(!/^(f|ht)tps?:\/\//i[_0xb23c('0x84')](_0x812deb)){_0x260dc0=path[_0xb23c('0x59')](_0xb23c('0x85'),_0x1275d5,_0x79455e[0x0],_0x812deb);}else{_0x260dc0=_0x812deb;}}}}var _0x215f3d={'name':_0x580c09,'description':_0x1c1120,'path':path[_0xb23c('0x59')](_0x1275d5,_0x79455e[0x0]),'type':_0x16819a,'sidebar':_0x368d48,'icon':_0x8f793,'adminUrl':_0x43679a,'agentUrl':_0x260dc0,'scriptName':_0x1c00e6,'scriptPath':_0x52756a,'version':_0x15a904};removeReferences(_0x5c512b,null);return db[_0xb23c('0x2f')]['create'](_0x215f3d)[_0xb23c('0x25')](function(_0x598ce8){var _0x30d98c={'role':_0x4d3893[_0xb23c('0x88')][_0xb23c('0x89')],'userProfileId':_0x4d3893[_0xb23c('0x88')][_0xb23c('0x8a')]};if(!_0x30d98c)throw new Error(_0xb23c('0x8b'));if(_0x30d98c[_0xb23c('0x89')]===_0xb23c('0x8c')){var _0x48924c=_0x598ce8[_0xb23c('0x8d')]({'plain':!![]});return db[_0xb23c('0x8e')][_0xb23c('0x49')]({'where':{'name':_0xb23c('0x27'),'userProfileId':_0x30d98c[_0xb23c('0x8a')]},'raw':!![]})[_0xb23c('0x25')](function(_0x8902f2){if(_0x8902f2&&_0x8902f2['autoAssociation']===0x0){return db[_0xb23c('0x28')][_0xb23c('0x8f')]({'name':_0x48924c[_0xb23c('0x2c')],'resourceId':_0x48924c['id'],'type':_0x8902f2[_0xb23c('0x2c')],'sectionId':_0x8902f2['id']},{})[_0xb23c('0x25')](function(){return _0x598ce8;});}else{return _0x598ce8;}})['catch'](function(_0x24b3a1){logger[_0xb23c('0x2a')](_0xb23c('0x90'),_0x24b3a1);throw _0x24b3a1;});}return _0x598ce8;})[_0xb23c('0x25')](respondWithResult(_0x4fd884,null))[_0xb23c('0x45')](handleError(_0x4fd884,null));}});}catch(_0x25be72){_0x4fd884[_0xb23c('0x1b')](0x1f4)[_0xb23c('0x91')](_0x25be72);}};function removeReferences(_0x2053f8,_0x5aeca5){try{if(_0x2053f8){fs[_0xb23c('0x61')](_0x2053f8);logger[_0xb23c('0x62')](_0xb23c('0x92'));}if(_0x5aeca5){rimraf(_0x5aeca5,function(){});logger[_0xb23c('0x62')]('Extracted\x20folder\x20removed');}}catch(_0x55da37){logger[_0xb23c('0x2a')](_0x55da37);}}exports[_0xb23c('0x93')]=function(_0x5e20c0,_0x364995,_0x17ef0c){return db[_0xb23c('0x2f')][_0xb23c('0x49')]({'where':{'id':_0x5e20c0[_0xb23c('0x47')]['id']}})[_0xb23c('0x25')](handleEntityNotFound(_0x364995,null))[_0xb23c('0x25')](saveUpdates(_0x5e20c0['body'],null))[_0xb23c('0x25')](respondWithResult(_0x364995,null))[_0xb23c('0x45')](handleError(_0x364995,null));};exports[_0xb23c('0x94')]=function(_0x31ed22,_0x414ce1,_0x448039){return db['Plugin']['find']({'where':{'id':_0x31ed22[_0xb23c('0x47')]['id']}})[_0xb23c('0x25')](function(_0x1956c2){if(_0x1956c2){return _0x1956c2['destroy']();}})['then'](function(_0xdd3437){rimraf(path[_0xb23c('0x59')](config[_0xb23c('0x4b')],_0xb23c('0x4c'),path['dirname'](_0xdd3437[_0xb23c('0x6')])),function(){});return _0xdd3437;})[_0xb23c('0x25')](handleEntityNotFound(_0x414ce1,null))[_0xb23c('0x25')](respondWithStatusCode(_0x414ce1,null))[_0xb23c('0x45')](handleError(_0x414ce1,null));};exports[_0xb23c('0x95')]=function(_0x3675db,_0x3b0812,_0x28e672){return BPromise[_0xb23c('0x96')]()[_0xb23c('0x25')](function(){if(!_0x3675db[_0xb23c('0x35')][_0xb23c('0x6')]){throw new Error(_0xb23c('0x97'));}if(!_0x3675db['query'][_0xb23c('0x98')]){throw new Error(_0xb23c('0x99'));}var _0x4a3fe6=_0x3675db['query'][_0xb23c('0x9a')]?_0x3675db['query']['hostname']+':'+_0x3675db['query'][_0xb23c('0x98')]:_0xb23c('0x9b')+_0x3675db[_0xb23c('0x35')][_0xb23c('0x98')];var _0x2869d5=_0x3675db[_0xb23c('0x35')][_0xb23c('0x1d')]?_0x3675db['query'][_0xb23c('0x1d')]:!![];var _0x187aaf=_0x3675db['query']['encoding']?_0x3675db['query']['encoding']:null;var _0x5c7fc5={'method':_0x3675db[_0xb23c('0x9c')],'uri':util[_0xb23c('0x4d')](_0xb23c('0x9d'),_0x4a3fe6,_0x3675db[_0xb23c('0x35')]['path']),'json':_0x2869d5,'resolveWithFullResponse':!![],'encoding':_0x187aaf,'qs':_0x3675db[_0xb23c('0x35')]};if(_0x3675db['headers']){_0x5c7fc5['headers']=_0x3675db['headers'];if(_0x5c7fc5[_0xb23c('0x9e')]['content-length']){delete _0x5c7fc5['headers']['content-length'];}}if(_0x5c7fc5[_0xb23c('0x9e')][_0xb23c('0x9f')]){delete _0x5c7fc5[_0xb23c('0x9e')]['content-type'];}return rp(_0x5c7fc5);})['then'](function(_0x2a1ae3){if(_0x2a1ae3){_0x3b0812[_0xb23c('0x21')](_0x2a1ae3['headers']);logger[_0xb23c('0x62')](_0x2a1ae3[_0xb23c('0x88')]);if(_['endsWith'](_0x3675db[_0xb23c('0x35')][_0xb23c('0x6')],'download')&&_0x2a1ae3[_0xb23c('0xa0')]==0x1f4){return _0x3b0812['sendStatus'](_0x2a1ae3[_0xb23c('0xa0')]);}else{return _0x3b0812[_0xb23c('0x1b')](_0x2a1ae3[_0xb23c('0xa0')])[_0xb23c('0x91')](_0x2a1ae3[_0xb23c('0x88')]);}}else{return _0x3b0812[_0xb23c('0x29')](0xc8);}})[_0xb23c('0x45')](handleError(_0x3b0812,null));};exports[_0xb23c('0xa1')]=function(_0x1024c5,_0x5734e4,_0x3ae2d9){return BPromise['resolve']()[_0xb23c('0x25')](function(){if(!_0x1024c5[_0xb23c('0x35')][_0xb23c('0x6')]){throw new Error(_0xb23c('0x97'));}if(!_0x1024c5[_0xb23c('0x35')][_0xb23c('0x98')]){throw new Error(_0xb23c('0x99'));}var _0x47b1d9=_0x1024c5[_0xb23c('0x35')][_0xb23c('0x9a')]?_0x1024c5['query'][_0xb23c('0x9a')]+':'+_0x1024c5[_0xb23c('0x35')]['port']:_0xb23c('0x9b')+_0x1024c5[_0xb23c('0x35')][_0xb23c('0x98')];var _0x30dd83=_0x1024c5[_0xb23c('0x35')][_0xb23c('0x1d')]?_0x1024c5[_0xb23c('0x35')][_0xb23c('0x1d')]:!![];var _0x53f3c7=_0x1024c5['query'][_0xb23c('0xa2')]?_0x1024c5[_0xb23c('0x35')][_0xb23c('0xa2')]:null;var _0x227f47={'method':_0x1024c5[_0xb23c('0x9c')],'uri':util[_0xb23c('0x4d')](_0xb23c('0x9d'),_0x47b1d9,_0x1024c5[_0xb23c('0x35')][_0xb23c('0x6')]),'json':_0x30dd83,'resolveWithFullResponse':!![],'encoding':_0x53f3c7,'body':_0x1024c5[_0xb23c('0x88')]};if(_0x1024c5[_0xb23c('0x9e')]){_0x227f47[_0xb23c('0x9e')]=_0x1024c5['headers'];if(_0x227f47[_0xb23c('0x9e')][_0xb23c('0xa3')]){delete _0x227f47[_0xb23c('0x9e')]['content-length'];}}if(_0x227f47['headers'][_0xb23c('0x9f')]){delete _0x227f47[_0xb23c('0x9e')]['content-type'];}return rp(_0x227f47);})[_0xb23c('0x25')](function(_0x4f6a13){if(_0x4f6a13){_0x5734e4['set'](_0x4f6a13[_0xb23c('0x9e')]);logger['info'](_0x4f6a13[_0xb23c('0x88')]);return _0x5734e4['status'](_0x4f6a13['statusCode'])[_0xb23c('0x91')](_0x4f6a13[_0xb23c('0x88')]);}else{return _0x5734e4[_0xb23c('0x29')](0xc8);}})[_0xb23c('0x45')](handleError(_0x5734e4,null));};
\ No newline at end of file