5980e7ca285a5e4eac230d8dddad5a9385c53e36
[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 _0x59db=['Invalid\x20plugin\x20structure','isFile','some','manifest.json','Plugin\x20manifest\x20missing','readFileSync','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','html','parameters','Invalid\x20manifest:\x20views\x20missing','views','admin','agent','script','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','Warning:\x20agent\x20view\x20not\x20specified','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','create','webhookGet','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','encoding','method','%s%s','headers','content-length','content-type','endsWith','statusCode','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','http://localhost:','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','extract-zip','archiver','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../mysqldb','redis','defaults','socket.io-emitter','./plugin.socket','register','sendStatus','status','offset','undefined','count','limit','set','Content-Range','json','reject','save','update','then','destroy','get','Plugins','UserProfileResource','end','error','stack','name','send','map','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','sort','where','pick','type','filter','options','includeAll','include','Plugin','findAll','rows','show','params','rawAttributes','length','find','catch','download','join','root','server/files/plugins','format','%s.zip','basename','createWriteStream','zip','warning','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','**/*','dirname','node_modules/**/*','attachments/**/*','close','existsSync','Plugin\x20not\x20found','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','upload','file','extname','filename','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync'];(function(_0x2f3848,_0x48564d){var _0x102668=function(_0x5e32ab){while(--_0x5e32ab){_0x2f3848['push'](_0x2f3848['shift']());}};_0x102668(++_0x48564d);}(_0x59db,0xda));var _0xb59d=function(_0x2ee4a0,_0xe398a6){_0x2ee4a0=_0x2ee4a0-0x0;var _0x35baa7=_0x59db[_0x2ee4a0];return _0x35baa7;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb59d('0x0'));var zipdir=require(_0xb59d('0x1'));var jsonpatch=require(_0xb59d('0x2'));var rp=require(_0xb59d('0x3'));var moment=require(_0xb59d('0x4'));var BPromise=require(_0xb59d('0x5'));var Mustache=require(_0xb59d('0x6'));var util=require('util');var path=require(_0xb59d('0x7'));var sox=require('sox');var csv=require(_0xb59d('0x8'));var ejs=require(_0xb59d('0x9'));var fs=require('fs');var fs_extra=require(_0xb59d('0xa'));var _=require(_0xb59d('0xb'));var squel=require(_0xb59d('0xc'));var crypto=require(_0xb59d('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xb59d('0xe'));var toCsv=require(_0xb59d('0x8'));var querystring=require(_0xb59d('0xf'));var Papa=require(_0xb59d('0x10'));var extract=require(_0xb59d('0x11'));var rimraf=require('rimraf');var archiver=require(_0xb59d('0x12'));var Redis=require(_0xb59d('0x13'));var authService=require(_0xb59d('0x14'));var qs=require(_0xb59d('0x15'));var as=require(_0xb59d('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb59d('0x17'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb59d('0x18'))['db'];config[_0xb59d('0x19')]=_[_0xb59d('0x1a')](config[_0xb59d('0x19')],{'host':'localhost','port':0x18eb});var socket=require(_0xb59d('0x1b'))(new Redis(config[_0xb59d('0x19')]));require(_0xb59d('0x1c'))[_0xb59d('0x1d')](socket);function respondWithStatusCode(_0x57cd1a,_0x33f5e4){_0x33f5e4=_0x33f5e4||0xcc;return function(_0x5efc6e){if(_0x5efc6e){return _0x57cd1a[_0xb59d('0x1e')](_0x33f5e4);}return _0x57cd1a[_0xb59d('0x1f')](_0x33f5e4)['end']();};}function respondWithResult(_0x34adf8,_0x25236d){_0x25236d=_0x25236d||0xc8;return function(_0x482335){if(_0x482335){return _0x34adf8[_0xb59d('0x1f')](_0x25236d)['json'](_0x482335);}};}function respondWithFilteredResult(_0x266c5b,_0x480b14){return function(_0x3a099c){if(_0x3a099c){var _0x581018=typeof _0x480b14[_0xb59d('0x20')]===_0xb59d('0x21')&&typeof _0x480b14['limit']===_0xb59d('0x21');var _0x2a3236=_0x3a099c['count'];var _0x2a08a3=_0x581018?0x0:_0x480b14[_0xb59d('0x20')];var _0x25558f=_0x581018?_0x3a099c[_0xb59d('0x22')]:_0x480b14['offset']+_0x480b14[_0xb59d('0x23')];var _0x272038;if(_0x25558f>=_0x2a3236){_0x25558f=_0x2a3236;_0x272038=0xc8;}else{_0x272038=0xce;}_0x266c5b[_0xb59d('0x1f')](_0x272038);return _0x266c5b[_0xb59d('0x24')](_0xb59d('0x25'),_0x2a08a3+'-'+_0x25558f+'/'+_0x2a3236)[_0xb59d('0x26')](_0x3a099c);}return null;};}function patchUpdates(_0x3b8476){return function(_0x168edf){try{jsonpatch['apply'](_0x168edf,_0x3b8476,!![]);}catch(_0x34edbe){return BPromise[_0xb59d('0x27')](_0x34edbe);}return _0x168edf[_0xb59d('0x28')]();};}function saveUpdates(_0x396022,_0x188fe1){return function(_0x560462){if(_0x560462){return _0x560462[_0xb59d('0x29')](_0x396022)[_0xb59d('0x2a')](function(_0x6c0f43){return _0x6c0f43;});}return null;};}function removeEntity(_0x22367c,_0x5edb97){return function(_0x24e1df){if(_0x24e1df){return _0x24e1df[_0xb59d('0x2b')]()['then'](function(){var _0x172149=_0x24e1df[_0xb59d('0x2c')]({'plain':!![]});var _0x99d4c8=_0xb59d('0x2d');return db[_0xb59d('0x2e')][_0xb59d('0x2b')]({'where':{'type':_0x99d4c8,'resourceId':_0x172149['id']}})['then'](function(){return _0x24e1df;});})[_0xb59d('0x2a')](function(){_0x22367c[_0xb59d('0x1f')](0xcc)[_0xb59d('0x2f')]();});}};}function handleEntityNotFound(_0x68de05,_0x2334aa){return function(_0x2fe29e){if(!_0x2fe29e){_0x68de05[_0xb59d('0x1e')](0x194);}return _0x2fe29e;};}function handleError(_0x5e18b5,_0x24b530){_0x24b530=_0x24b530||0x1f4;return function(_0x2fe119){logger[_0xb59d('0x30')](_0x2fe119[_0xb59d('0x31')]);if(_0x2fe119['name']){delete _0x2fe119[_0xb59d('0x32')];}_0x5e18b5[_0xb59d('0x1f')](_0x24b530)[_0xb59d('0x33')](_0x2fe119);};}exports['index']=function(_0x54d65b,_0x148199){var _0x2f0a35={},_0x42b27e={},_0x540838={'count':0x0,'rows':[]};var _0x380df6=_[_0xb59d('0x34')](db['Plugin']['rawAttributes'],function(_0x5b9429){return{'name':_0x5b9429['fieldName'],'type':_0x5b9429['type']['key']};});_0x42b27e[_0xb59d('0x35')]=_[_0xb59d('0x34')](_0x380df6,_0xb59d('0x32'));_0x42b27e[_0xb59d('0x36')]=_[_0xb59d('0x37')](_0x54d65b['query']);_0x42b27e[_0xb59d('0x38')]=_[_0xb59d('0x39')](_0x42b27e[_0xb59d('0x35')],_0x42b27e[_0xb59d('0x36')]);_0x2f0a35[_0xb59d('0x3a')]=_[_0xb59d('0x39')](_0x42b27e[_0xb59d('0x35')],qs[_0xb59d('0x3b')](_0x54d65b[_0xb59d('0x36')]['fields']));_0x2f0a35['attributes']=_0x2f0a35[_0xb59d('0x3a')]['length']?_0x2f0a35[_0xb59d('0x3a')]:_0x42b27e['model'];if(!_0x54d65b[_0xb59d('0x36')][_0xb59d('0x3c')]('nolimit')){_0x2f0a35[_0xb59d('0x23')]=qs[_0xb59d('0x23')](_0x54d65b[_0xb59d('0x36')][_0xb59d('0x23')]);_0x2f0a35['offset']=qs[_0xb59d('0x20')](_0x54d65b[_0xb59d('0x36')][_0xb59d('0x20')]);}_0x2f0a35['order']=qs[_0xb59d('0x3d')](_0x54d65b[_0xb59d('0x36')][_0xb59d('0x3d')]);_0x2f0a35[_0xb59d('0x3e')]=qs[_0xb59d('0x38')](_[_0xb59d('0x3f')](_0x54d65b['query'],_0x42b27e[_0xb59d('0x38')]),_0x380df6);if(_0x54d65b['query']['filter']){_0x2f0a35['where']=_['merge'](_0x2f0a35['where'],{'$or':_[_0xb59d('0x34')](_0x380df6,function(_0x12a920){if(_0x12a920[_0xb59d('0x40')]!=='VIRTUAL'){var _0x4f959f={};_0x4f959f[_0x12a920[_0xb59d('0x32')]]={'$like':'%'+_0x54d65b[_0xb59d('0x36')][_0xb59d('0x41')]+'%'};return _0x4f959f;}})});}_0x2f0a35=_['merge']({},_0x2f0a35,_0x54d65b[_0xb59d('0x42')]);var _0x303168={'where':_0x2f0a35['where']};return db['Plugin']['count'](_0x303168)[_0xb59d('0x2a')](function(_0x5564e6){_0x540838[_0xb59d('0x22')]=_0x5564e6;if(_0x54d65b[_0xb59d('0x36')][_0xb59d('0x43')]){_0x2f0a35[_0xb59d('0x44')]=[{'all':!![]}];}return db[_0xb59d('0x45')][_0xb59d('0x46')](_0x2f0a35);})['then'](function(_0x62f0b6){_0x540838[_0xb59d('0x47')]=_0x62f0b6;return _0x540838;})['then'](respondWithFilteredResult(_0x148199,_0x2f0a35))['catch'](handleError(_0x148199,null));};exports[_0xb59d('0x48')]=function(_0x553f0d,_0x2a5c8e){var _0x50153f={'raw':!![],'where':{'id':_0x553f0d[_0xb59d('0x49')]['id']}},_0x5065c4={};_0x5065c4['model']=_['keys'](db[_0xb59d('0x45')][_0xb59d('0x4a')]);_0x5065c4[_0xb59d('0x36')]=_[_0xb59d('0x37')](_0x553f0d[_0xb59d('0x36')]);_0x5065c4[_0xb59d('0x38')]=_[_0xb59d('0x39')](_0x5065c4[_0xb59d('0x35')],_0x5065c4[_0xb59d('0x36')]);_0x50153f[_0xb59d('0x3a')]=_['intersection'](_0x5065c4['model'],qs[_0xb59d('0x3b')](_0x553f0d[_0xb59d('0x36')]['fields']));_0x50153f[_0xb59d('0x3a')]=_0x50153f[_0xb59d('0x3a')][_0xb59d('0x4b')]?_0x50153f[_0xb59d('0x3a')]:_0x5065c4[_0xb59d('0x35')];if(_0x553f0d['query'][_0xb59d('0x43')]){_0x50153f[_0xb59d('0x44')]=[{'all':!![]}];}_0x50153f=_['merge']({},_0x50153f,_0x553f0d[_0xb59d('0x42')]);return db[_0xb59d('0x45')][_0xb59d('0x4c')](_0x50153f)['then'](handleEntityNotFound(_0x2a5c8e,null))[_0xb59d('0x2a')](respondWithResult(_0x2a5c8e,null))[_0xb59d('0x4d')](handleError(_0x2a5c8e,null));};exports[_0xb59d('0x4e')]=function(_0x2b8e15,_0x281af5,_0x40b570){return db[_0xb59d('0x45')][_0xb59d('0x4c')]({'where':{'id':_0x2b8e15[_0xb59d('0x49')]['id']},'attributes':[_0xb59d('0x32'),_0xb59d('0x7')],'raw':!![]})['then'](handleEntityNotFound(_0x281af5,null))['then'](function(_0x58fdc7){if(_0x58fdc7){var _0x2477f6=path[_0xb59d('0x4f')](config[_0xb59d('0x50')],_0xb59d('0x51'),util[_0xb59d('0x52')](_0xb59d('0x53'),path[_0xb59d('0x54')](_0x58fdc7[_0xb59d('0x7')])));var _0x241f2e=fs[_0xb59d('0x55')](_0x2477f6);var _0x585995=archiver(_0xb59d('0x56'),{'zlib':{'level':0x9}});_0x585995['on'](_0xb59d('0x57'),function(_0x1b811d){if(_0x1b811d['code']===_0xb59d('0x58')){logger[_0xb59d('0x30')](_0x1b811d);}else{throw new db[(_0xb59d('0x59'))][(_0xb59d('0x5a'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x585995['on'](_0xb59d('0x30'),function(_0x5eda40){throw new db[(_0xb59d('0x59'))][(_0xb59d('0x5a'))](_0xb59d('0x5b'));});_0x585995['pipe'](_0x241f2e);_0x585995['glob'](_0xb59d('0x5c'),{'cwd':path['join'](config[_0xb59d('0x50')],'server/files/plugins',path[_0xb59d('0x5d')](_0x58fdc7[_0xb59d('0x7')])),'ignore':[path[_0xb59d('0x4f')](path['basename'](_0x58fdc7[_0xb59d('0x7')]),_0xb59d('0x5e')),path[_0xb59d('0x4f')](path[_0xb59d('0x54')](_0x58fdc7[_0xb59d('0x7')]),_0xb59d('0x5f'))],'nodir':!![]})['finalize']();_0x241f2e['on'](_0xb59d('0x60'),function(){if(!fs[_0xb59d('0x61')](_0x2477f6)){throw new db['Sequelize'][(_0xb59d('0x5a'))](_0xb59d('0x62'));}return _0x281af5[_0xb59d('0x4e')](_0x2477f6,util[_0xb59d('0x52')](_0xb59d('0x53'),path[_0xb59d('0x54')](_0x58fdc7[_0xb59d('0x7')])),function(_0x1001f7){if(_0x1001f7){throw new db['Sequelize']['Error'](_0xb59d('0x63'));}fs[_0xb59d('0x64')](_0x2477f6);logger[_0xb59d('0x65')](_0xb59d('0x66'));logger[_0xb59d('0x65')]('Temporary\x20file\x20removed');});});}return null;})[_0xb59d('0x4d')](handleError(_0x281af5,null));};exports[_0xb59d('0x67')]=function(_0x2cd334,_0xde8f63,_0x55e3fb){var _0x317100=path['basename'](_0x2cd334[_0xb59d('0x68')]['filename'],path[_0xb59d('0x69')](_0x2cd334['file']['filename']));var _0x37edf9=path['join'](config[_0xb59d('0x50')],_0xb59d('0x51'),_0x2cd334[_0xb59d('0x68')][_0xb59d('0x6a')]);var _0x223668=path[_0xb59d('0x4f')](config[_0xb59d('0x50')],_0xb59d('0x51'),_0x317100);logger[_0xb59d('0x65')](_0xb59d('0x6b'),_0x37edf9);logger[_0xb59d('0x65')](_0xb59d('0x6c'),_0x223668);try{fs[_0xb59d('0x6d')](_0x37edf9,parseInt(_0xb59d('0x6e'),0x8));extract(_0x37edf9,{'dir':_0x223668},function(_0x115aa0){if(_0x115aa0){logger['error'](_0x115aa0);handleError(_0x115aa0,!![]);};var _0xe37756=fs[_0xb59d('0x6f')](_0x223668);if(_0xe37756[_0xb59d('0x4b')]>0x1){removeReferences(_0x37edf9,_0x223668);logger[_0xb59d('0x30')](_0xb59d('0x70'));return _0x55e3fb(new Error(_0xb59d('0x70')));}var _0x2d6398=fs['lstatSync'](path[_0xb59d('0x4f')](_0x223668,_0xe37756[0x0]));if(_0x2d6398[_0xb59d('0x71')]()){removeReferences(_0x37edf9,_0x223668);logger['error']('Invalid\x20plugin\x20structure');return _0x55e3fb(new Error(_0xb59d('0x70')));}if(_0x2d6398['isDirectory']()){var _0x4cad07=fs[_0xb59d('0x6f')](path['join'](_0x223668,_0xe37756[0x0]));if(_0x4cad07['length']===0x0){removeReferences(_0x37edf9,_0x223668);logger[_0xb59d('0x30')](_0xb59d('0x70'));return _0x55e3fb(new Error(_0xb59d('0x70')));}var _0x435577=_0x4cad07[_0xb59d('0x72')](function(_0x4a6fd0){return _0x4a6fd0===_0xb59d('0x73');});if(!_0x435577){return _0x55e3fb(new Error(_0xb59d('0x74')));}var _0x12a7d6=fs[_0xb59d('0x75')](path[_0xb59d('0x4f')](_0x223668,_0xe37756[0x0],'manifest.json'));var _0x4846b5=JSON['parse'](_0x12a7d6);if(_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x32')]){return _0x55e3fb(new Error(_0xb59d('0x76')));}if(_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x40')]){return _0x55e3fb(new Error(_0xb59d('0x77')));}if(_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x78')]){return _0x55e3fb(new Error(_0xb59d('0x79')));}if(_0xb59d('0x21')==typeof _0x4846b5['parameters']){return _0x55e3fb(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x4846b5[_0xb59d('0x40')]===_0xb59d('0x7a')){if(_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x7b')]['views']){return _0x55e3fb(new Error(_0xb59d('0x7c')));}if(_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x7b')][_0xb59d('0x7d')][_0xb59d('0x7e')]&&_0xb59d('0x21')==typeof _0x4846b5[_0xb59d('0x7b')]['views'][_0xb59d('0x7f')]){return _0x55e3fb(new Error('Invalid\x20manifest:\x20no\x20view\x20specified'));}}else if(_0x4846b5['type']===_0xb59d('0x80')){if(_0xb59d('0x21')==typeof _0x4846b5['parameters'][_0xb59d('0x81')]){return _0x55e3fb(new Error(_0xb59d('0x82')));}if('undefined'==typeof _0x4846b5['parameters'][_0xb59d('0x83')]){return _0x55e3fb(new Error(_0xb59d('0x84')));}}else{return _0x55e3fb(new Error(_0xb59d('0x85')));}var _0x1a2bfc=_0x4846b5['name'];var _0x4031cd=_0x4846b5[_0xb59d('0x86')];var _0x360f40=_0x4846b5[_0xb59d('0x40')];var _0x4d3d0d=_0x4846b5[_0xb59d('0x87')]?_0x4846b5[_0xb59d('0x87')]:_0xb59d('0x88');var _0x18bc33=_0x4846b5[_0xb59d('0x89')]?_0x4846b5[_0xb59d('0x89')]:_0xb59d('0x8a');var _0x557c5c='';var _0x1fcc35='';var _0x10348b='';var _0x18c85e='';var _0x53a619=_0x4846b5['version'];if(_0x360f40===_0xb59d('0x7a')){if(_0xb59d('0x21')!=typeof _0x4846b5[_0xb59d('0x7b')]['views'][_0xb59d('0x7e')]){var _0x3774cf=_0x4846b5[_0xb59d('0x7b')]['views'][_0xb59d('0x7e')];if(!/^(f|ht)tps?:\/\//i[_0xb59d('0x8b')](_0x3774cf)){_0x557c5c=path[_0xb59d('0x4f')](_0xb59d('0x8c'),_0x317100,_0xe37756[0x0],_0x3774cf);}else{_0x557c5c=_0x3774cf;}}else{logger[_0xb59d('0x65')](_0xb59d('0x8d'));}if('undefined'!=typeof _0x4846b5['parameters'][_0xb59d('0x7d')][_0xb59d('0x7f')]){var _0x57293f=_0x4846b5['parameters'][_0xb59d('0x7d')][_0xb59d('0x7f')];if(!/^(f|ht)tps?:\/\//i[_0xb59d('0x8b')](_0x57293f)){_0x1fcc35=path['join'](_0xb59d('0x8c'),_0x317100,_0xe37756[0x0],_0x57293f);}else{_0x1fcc35=_0x57293f;}}else{logger[_0xb59d('0x65')](_0xb59d('0x8e'));}}else if(_0x360f40===_0xb59d('0x80')){_0x10348b=_0x4846b5[_0xb59d('0x7b')]['scriptName'];_0x18c85e=_0x4846b5[_0xb59d('0x7b')][_0xb59d('0x83')];if(_0xb59d('0x21')!=typeof _0x4846b5['parameters'][_0xb59d('0x7d')]){if('undefined'!=typeof _0x4846b5[_0xb59d('0x7b')][_0xb59d('0x7d')][_0xb59d('0x7e')]){var _0x3774cf=_0x4846b5[_0xb59d('0x7b')][_0xb59d('0x7d')][_0xb59d('0x7e')];if(!/^(f|ht)tps?:\/\//i['test'](_0x3774cf)){_0x557c5c=path['join'](_0xb59d('0x8c'),_0x317100,_0xe37756[0x0],_0x3774cf);}else{_0x557c5c=_0x3774cf;}}if(_0xb59d('0x21')!=typeof _0x4846b5['parameters']['views'][_0xb59d('0x7f')]){var _0x57293f=_0x4846b5[_0xb59d('0x7b')][_0xb59d('0x7d')]['agent'];if(!/^(f|ht)tps?:\/\//i['test'](_0x57293f)){_0x1fcc35=path[_0xb59d('0x4f')]('plugins',_0x317100,_0xe37756[0x0],_0x57293f);}else{_0x1fcc35=_0x57293f;}}}}var _0x5dbcd5={'name':_0x1a2bfc,'description':_0x4031cd,'path':path[_0xb59d('0x4f')](_0x317100,_0xe37756[0x0]),'type':_0x360f40,'sidebar':_0x4d3d0d,'icon':_0x18bc33,'adminUrl':_0x557c5c,'agentUrl':_0x1fcc35,'scriptName':_0x10348b,'scriptPath':_0x18c85e,'version':_0x53a619};removeReferences(_0x37edf9,null);return db[_0xb59d('0x45')]['create'](_0x5dbcd5)[_0xb59d('0x2a')](function(_0x4c7cf4){var _0x4b42a6={'role':_0x2cd334[_0xb59d('0x8f')][_0xb59d('0x90')],'userProfileId':_0x2cd334[_0xb59d('0x8f')][_0xb59d('0x91')]};if(!_0x4b42a6)throw new Error(_0xb59d('0x92'));if(_0x4b42a6[_0xb59d('0x90')]===_0xb59d('0x93')){var _0x459008=_0x4c7cf4['get']({'plain':!![]});return db[_0xb59d('0x94')][_0xb59d('0x4c')]({'where':{'name':'Plugins','userProfileId':_0x4b42a6['userProfileId']},'raw':!![]})[_0xb59d('0x2a')](function(_0x144e20){if(_0x144e20&&_0x144e20['autoAssociation']===0x0){return db[_0xb59d('0x2e')][_0xb59d('0x95')]({'name':_0x459008['name'],'resourceId':_0x459008['id'],'type':_0x144e20['name'],'sectionId':_0x144e20['id']},{})['then'](function(){return _0x4c7cf4;});}else{return _0x4c7cf4;}})[_0xb59d('0x4d')](function(_0x233454){logger[_0xb59d('0x30')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x233454);throw _0x233454;});}return _0x4c7cf4;})[_0xb59d('0x2a')](respondWithResult(_0xde8f63,null))['catch'](handleError(_0xde8f63,null));}});}catch(_0x2d15f3){_0xde8f63[_0xb59d('0x1f')](0x1f4)[_0xb59d('0x33')](_0x2d15f3);}};function removeReferences(_0xd95468,_0x388069){try{if(_0xd95468){fs['unlinkSync'](_0xd95468);logger[_0xb59d('0x65')]('Zip\x20archive\x20removed');}if(_0x388069){rimraf(_0x388069,function(){});logger[_0xb59d('0x65')]('Extracted\x20folder\x20removed');}}catch(_0x5941f1){logger[_0xb59d('0x30')](_0x5941f1);}}exports[_0xb59d('0x29')]=function(_0x5e08ad,_0x2e0107,_0x32b4e4){return db[_0xb59d('0x45')][_0xb59d('0x4c')]({'where':{'id':_0x5e08ad[_0xb59d('0x49')]['id']}})[_0xb59d('0x2a')](handleEntityNotFound(_0x2e0107,null))['then'](saveUpdates(_0x5e08ad[_0xb59d('0x8f')],null))[_0xb59d('0x2a')](respondWithResult(_0x2e0107,null))[_0xb59d('0x4d')](handleError(_0x2e0107,null));};exports['delete']=function(_0x30ec24,_0x3d2170,_0x191364){return db['Plugin']['find']({'where':{'id':_0x30ec24[_0xb59d('0x49')]['id']}})[_0xb59d('0x2a')](function(_0x18a422){if(_0x18a422){return _0x18a422[_0xb59d('0x2b')]();}})[_0xb59d('0x2a')](function(_0x218e46){rimraf(path['join'](config[_0xb59d('0x50')],'server/files/plugins',path[_0xb59d('0x5d')](_0x218e46[_0xb59d('0x7')])),function(){});return _0x218e46;})[_0xb59d('0x2a')](handleEntityNotFound(_0x3d2170,null))[_0xb59d('0x2a')](respondWithStatusCode(_0x3d2170,null))[_0xb59d('0x4d')](handleError(_0x3d2170,null));};exports[_0xb59d('0x96')]=function(_0x40d5f2,_0x5644d8,_0x299e5c){return BPromise['resolve']()[_0xb59d('0x2a')](function(){if(!_0x40d5f2['query'][_0xb59d('0x7')]){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x97')]){throw new Error(_0xb59d('0x98'));}var _0x37f443=_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x99')]?_0x40d5f2['query'][_0xb59d('0x99')]+':'+_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x97')]:'http://localhost:'+_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x97')];var _0x547176=_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x26')]?_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x26')]:!![];var _0x459aa2=_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x9a')]?_0x40d5f2[_0xb59d('0x36')][_0xb59d('0x9a')]:null;var _0x263191={'method':_0x40d5f2[_0xb59d('0x9b')],'uri':util['format'](_0xb59d('0x9c'),_0x37f443,_0x40d5f2['query'][_0xb59d('0x7')]),'json':_0x547176,'resolveWithFullResponse':!![],'encoding':_0x459aa2,'qs':_0x40d5f2[_0xb59d('0x36')]};if(_0x40d5f2['headers']){_0x263191[_0xb59d('0x9d')]=_0x40d5f2[_0xb59d('0x9d')];if(_0x263191[_0xb59d('0x9d')]['content-length']){delete _0x263191[_0xb59d('0x9d')][_0xb59d('0x9e')];}}if(_0x263191[_0xb59d('0x9d')][_0xb59d('0x9f')]){delete _0x263191[_0xb59d('0x9d')]['content-type'];}return rp(_0x263191);})[_0xb59d('0x2a')](function(_0x30ce9a){if(_0x30ce9a){_0x5644d8[_0xb59d('0x24')](_0x30ce9a[_0xb59d('0x9d')]);logger['info'](_0x30ce9a['body']);if(_[_0xb59d('0xa0')](_0x40d5f2[_0xb59d('0x36')]['path'],_0xb59d('0x4e'))&&_0x30ce9a[_0xb59d('0xa1')]==0x1f4){return _0x5644d8['sendStatus'](_0x30ce9a[_0xb59d('0xa1')]);}else{return _0x5644d8[_0xb59d('0x1f')](_0x30ce9a[_0xb59d('0xa1')])[_0xb59d('0x33')](_0x30ce9a[_0xb59d('0x8f')]);}}else{return _0x5644d8[_0xb59d('0x1e')](0xc8);}})['catch'](handleError(_0x5644d8,null));};exports['webhookPost']=function(_0x2ea001,_0x249dd9,_0x3d5423){return BPromise[_0xb59d('0xa2')]()[_0xb59d('0x2a')](function(){if(!_0x2ea001[_0xb59d('0x36')][_0xb59d('0x7')]){throw new Error(_0xb59d('0xa3'));}if(!_0x2ea001['query'][_0xb59d('0x97')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x3808f5=_0x2ea001[_0xb59d('0x36')][_0xb59d('0x99')]?_0x2ea001['query'][_0xb59d('0x99')]+':'+_0x2ea001['query'][_0xb59d('0x97')]:_0xb59d('0xa4')+_0x2ea001['query'][_0xb59d('0x97')];var _0x1790b6=_0x2ea001[_0xb59d('0x36')]['json']?_0x2ea001[_0xb59d('0x36')][_0xb59d('0x26')]:!![];var _0x542ca9=_0x2ea001[_0xb59d('0x36')][_0xb59d('0x9a')]?_0x2ea001[_0xb59d('0x36')]['encoding']:null;var _0x5dd463={'method':_0x2ea001[_0xb59d('0x9b')],'uri':util[_0xb59d('0x52')](_0xb59d('0x9c'),_0x3808f5,_0x2ea001[_0xb59d('0x36')][_0xb59d('0x7')]),'json':_0x1790b6,'resolveWithFullResponse':!![],'encoding':_0x542ca9,'body':_0x2ea001[_0xb59d('0x8f')]};if(_0x2ea001['headers']){_0x5dd463[_0xb59d('0x9d')]=_0x2ea001[_0xb59d('0x9d')];if(_0x5dd463[_0xb59d('0x9d')][_0xb59d('0x9e')]){delete _0x5dd463[_0xb59d('0x9d')][_0xb59d('0x9e')];}}if(_0x5dd463[_0xb59d('0x9d')][_0xb59d('0x9f')]){delete _0x5dd463[_0xb59d('0x9d')][_0xb59d('0x9f')];}return rp(_0x5dd463);})['then'](function(_0x4c37f7){if(_0x4c37f7){_0x249dd9[_0xb59d('0x24')](_0x4c37f7[_0xb59d('0x9d')]);logger[_0xb59d('0x65')](_0x4c37f7[_0xb59d('0x8f')]);return _0x249dd9['status'](_0x4c37f7['statusCode'])['send'](_0x4c37f7[_0xb59d('0x8f')]);}else{return _0x249dd9['sendStatus'](0xc8);}})[_0xb59d('0x4d')](handleError(_0x249dd9,null));};