6480ccfc625877c6de5b59bf607e7a45562ee614
[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 _0xfc2b=['parse','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','html','views','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','webhookGet','\x27PATH\x27\x20parameter\x20not\x20specified','port','hostname','http://localhost:','encoding','headers','content-length','content-type','statusCode','webhookPost','resolve','\x27PORT\x27\x20parameter\x20not\x20specified','%s%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','extract-zip','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','end','undefined','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','then','get','Plugins','UserProfileResource','stack','send','Plugin','fieldName','type','model','map','query','keys','filters','attributes','intersection','fields','length','sort','where','pick','filter','merge','name','options','include','findAll','rows','catch','show','params','rawAttributes','includeAll','find','download','root','server/files/plugins','%s.zip','basename','createWriteStream','zip','code','error','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','join','dirname','node_modules/**/*','attachments/**/*','finalize','close','existsSync','Plugin\x20not\x20found','format','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','upload','file','filename','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','some','manifest.json'];(function(_0x3be2e2,_0x5c166d){var _0x53b9c5=function(_0x248aa7){while(--_0x248aa7){_0x3be2e2['push'](_0x3be2e2['shift']());}};_0x53b9c5(++_0x5c166d);}(_0xfc2b,0x187));var _0xbfc2=function(_0x14de88,_0x5deaa3){_0x14de88=_0x14de88-0x0;var _0x295cef=_0xfc2b[_0x14de88];return _0x295cef;};'use strict';var emlformat=require(_0xbfc2('0x0'));var rimraf=require(_0xbfc2('0x1'));var zipdir=require(_0xbfc2('0x2'));var jsonpatch=require(_0xbfc2('0x3'));var rp=require(_0xbfc2('0x4'));var moment=require(_0xbfc2('0x5'));var BPromise=require(_0xbfc2('0x6'));var Mustache=require(_0xbfc2('0x7'));var util=require(_0xbfc2('0x8'));var path=require(_0xbfc2('0x9'));var sox=require(_0xbfc2('0xa'));var csv=require('to-csv');var ejs=require(_0xbfc2('0xb'));var fs=require('fs');var fs_extra=require(_0xbfc2('0xc'));var _=require(_0xbfc2('0xd'));var squel=require(_0xbfc2('0xe'));var crypto=require(_0xbfc2('0xf'));var jsforce=require('jsforce');var deskjs=require(_0xbfc2('0x10'));var toCsv=require(_0xbfc2('0x11'));var querystring=require(_0xbfc2('0x12'));var Papa=require(_0xbfc2('0x13'));var extract=require(_0xbfc2('0x14'));var rimraf=require(_0xbfc2('0x1'));var archiver=require('archiver');var Redis=require(_0xbfc2('0x15'));var authService=require('../../components/auth/service');var qs=require(_0xbfc2('0x16'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xbfc2('0x17'));var logger=require(_0xbfc2('0x18'))(_0xbfc2('0x19'));var utils=require(_0xbfc2('0x1a'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xbfc2('0x1b'))['db'];config[_0xbfc2('0x1c')]=_[_0xbfc2('0x1d')](config[_0xbfc2('0x1c')],{'host':_0xbfc2('0x1e'),'port':0x18eb});var socket=require(_0xbfc2('0x1f'))(new Redis(config['redis']));require(_0xbfc2('0x20'))[_0xbfc2('0x21')](socket);function respondWithStatusCode(_0xb2dfa2,_0x30b1f0){_0x30b1f0=_0x30b1f0||0xcc;return function(_0xa74432){if(_0xa74432){return _0xb2dfa2[_0xbfc2('0x22')](_0x30b1f0);}return _0xb2dfa2[_0xbfc2('0x23')](_0x30b1f0)[_0xbfc2('0x24')]();};}function respondWithResult(_0x4b1c82,_0xb61894){_0xb61894=_0xb61894||0xc8;return function(_0x3179b2){if(_0x3179b2){return _0x4b1c82[_0xbfc2('0x23')](_0xb61894)['json'](_0x3179b2);}};}function respondWithFilteredResult(_0x25da74,_0x53bc5e){return function(_0xd05c04){if(_0xd05c04){var _0x4fbd3a=typeof _0x53bc5e['offset']==='undefined'&&typeof _0x53bc5e['limit']===_0xbfc2('0x25');var _0x16f487=_0xd05c04[_0xbfc2('0x26')];var _0x4e57a6=_0x4fbd3a?0x0:_0x53bc5e['offset'];var _0x133841=_0x4fbd3a?_0xd05c04[_0xbfc2('0x26')]:_0x53bc5e[_0xbfc2('0x27')]+_0x53bc5e[_0xbfc2('0x28')];var _0x1e1291;if(_0x133841>=_0x16f487){_0x133841=_0x16f487;_0x1e1291=0xc8;}else{_0x1e1291=0xce;}_0x25da74['status'](_0x1e1291);return _0x25da74[_0xbfc2('0x29')](_0xbfc2('0x2a'),_0x4e57a6+'-'+_0x133841+'/'+_0x16f487)[_0xbfc2('0x2b')](_0xd05c04);}return null;};}function patchUpdates(_0x8e8769){return function(_0x390c0a){try{jsonpatch[_0xbfc2('0x2c')](_0x390c0a,_0x8e8769,!![]);}catch(_0x460d26){return BPromise[_0xbfc2('0x2d')](_0x460d26);}return _0x390c0a[_0xbfc2('0x2e')]();};}function saveUpdates(_0x269be0,_0xef364a){return function(_0x6ce32b){if(_0x6ce32b){return _0x6ce32b[_0xbfc2('0x2f')](_0x269be0)['then'](function(_0x20d284){return _0x20d284;});}return null;};}function removeEntity(_0x1ddba1,_0x295529){return function(_0xe86517){if(_0xe86517){return _0xe86517[_0xbfc2('0x30')]()[_0xbfc2('0x31')](function(){var _0x755c28=_0xe86517[_0xbfc2('0x32')]({'plain':!![]});var _0x119f68=_0xbfc2('0x33');return db[_0xbfc2('0x34')]['destroy']({'where':{'type':_0x119f68,'resourceId':_0x755c28['id']}})[_0xbfc2('0x31')](function(){return _0xe86517;});})[_0xbfc2('0x31')](function(){_0x1ddba1[_0xbfc2('0x23')](0xcc)[_0xbfc2('0x24')]();});}};}function handleEntityNotFound(_0x50cf32,_0x463cc4){return function(_0x5f0628){if(!_0x5f0628){_0x50cf32[_0xbfc2('0x22')](0x194);}return _0x5f0628;};}function handleError(_0x4bb6f2,_0x593fc9){_0x593fc9=_0x593fc9||0x1f4;return function(_0x45cee9){logger['error'](_0x45cee9[_0xbfc2('0x35')]);if(_0x45cee9['name']){delete _0x45cee9['name'];}_0x4bb6f2[_0xbfc2('0x23')](_0x593fc9)[_0xbfc2('0x36')](_0x45cee9);};}exports['index']=function(_0x167f9e,_0x32a47){var _0x202e25={},_0x1666a8={},_0x33d03b={'count':0x0,'rows':[]};var _0x5709d2=_['map'](db[_0xbfc2('0x37')]['rawAttributes'],function(_0x354aae){return{'name':_0x354aae[_0xbfc2('0x38')],'type':_0x354aae[_0xbfc2('0x39')]['key']};});_0x1666a8[_0xbfc2('0x3a')]=_[_0xbfc2('0x3b')](_0x5709d2,'name');_0x1666a8[_0xbfc2('0x3c')]=_[_0xbfc2('0x3d')](_0x167f9e['query']);_0x1666a8[_0xbfc2('0x3e')]=_['intersection'](_0x1666a8['model'],_0x1666a8[_0xbfc2('0x3c')]);_0x202e25[_0xbfc2('0x3f')]=_[_0xbfc2('0x40')](_0x1666a8[_0xbfc2('0x3a')],qs[_0xbfc2('0x41')](_0x167f9e[_0xbfc2('0x3c')][_0xbfc2('0x41')]));_0x202e25[_0xbfc2('0x3f')]=_0x202e25[_0xbfc2('0x3f')][_0xbfc2('0x42')]?_0x202e25[_0xbfc2('0x3f')]:_0x1666a8[_0xbfc2('0x3a')];if(!_0x167f9e[_0xbfc2('0x3c')]['hasOwnProperty']('nolimit')){_0x202e25[_0xbfc2('0x28')]=qs['limit'](_0x167f9e[_0xbfc2('0x3c')][_0xbfc2('0x28')]);_0x202e25['offset']=qs[_0xbfc2('0x27')](_0x167f9e[_0xbfc2('0x3c')][_0xbfc2('0x27')]);}_0x202e25['order']=qs[_0xbfc2('0x43')](_0x167f9e[_0xbfc2('0x3c')][_0xbfc2('0x43')]);_0x202e25[_0xbfc2('0x44')]=qs[_0xbfc2('0x3e')](_[_0xbfc2('0x45')](_0x167f9e[_0xbfc2('0x3c')],_0x1666a8[_0xbfc2('0x3e')]),_0x5709d2);if(_0x167f9e[_0xbfc2('0x3c')][_0xbfc2('0x46')]){_0x202e25[_0xbfc2('0x44')]=_[_0xbfc2('0x47')](_0x202e25[_0xbfc2('0x44')],{'$or':_['map'](_0x5709d2,function(_0x45cf02){if(_0x45cf02[_0xbfc2('0x39')]!=='VIRTUAL'){var _0xffbedd={};_0xffbedd[_0x45cf02[_0xbfc2('0x48')]]={'$like':'%'+_0x167f9e[_0xbfc2('0x3c')]['filter']+'%'};return _0xffbedd;}})});}_0x202e25=_[_0xbfc2('0x47')]({},_0x202e25,_0x167f9e[_0xbfc2('0x49')]);var _0x1c9ae8={'where':_0x202e25[_0xbfc2('0x44')]};return db[_0xbfc2('0x37')][_0xbfc2('0x26')](_0x1c9ae8)[_0xbfc2('0x31')](function(_0x4fadf6){_0x33d03b['count']=_0x4fadf6;if(_0x167f9e[_0xbfc2('0x3c')]['includeAll']){_0x202e25[_0xbfc2('0x4a')]=[{'all':!![]}];}return db[_0xbfc2('0x37')][_0xbfc2('0x4b')](_0x202e25);})[_0xbfc2('0x31')](function(_0x7c2a50){_0x33d03b[_0xbfc2('0x4c')]=_0x7c2a50;return _0x33d03b;})[_0xbfc2('0x31')](respondWithFilteredResult(_0x32a47,_0x202e25))[_0xbfc2('0x4d')](handleError(_0x32a47,null));};exports[_0xbfc2('0x4e')]=function(_0x36f73a,_0x38854a){var _0x1d9600={'raw':!![],'where':{'id':_0x36f73a[_0xbfc2('0x4f')]['id']}},_0x55c768={};_0x55c768[_0xbfc2('0x3a')]=_[_0xbfc2('0x3d')](db[_0xbfc2('0x37')][_0xbfc2('0x50')]);_0x55c768[_0xbfc2('0x3c')]=_[_0xbfc2('0x3d')](_0x36f73a['query']);_0x55c768[_0xbfc2('0x3e')]=_[_0xbfc2('0x40')](_0x55c768[_0xbfc2('0x3a')],_0x55c768[_0xbfc2('0x3c')]);_0x1d9600[_0xbfc2('0x3f')]=_['intersection'](_0x55c768['model'],qs[_0xbfc2('0x41')](_0x36f73a[_0xbfc2('0x3c')][_0xbfc2('0x41')]));_0x1d9600['attributes']=_0x1d9600[_0xbfc2('0x3f')][_0xbfc2('0x42')]?_0x1d9600['attributes']:_0x55c768['model'];if(_0x36f73a['query'][_0xbfc2('0x51')]){_0x1d9600[_0xbfc2('0x4a')]=[{'all':!![]}];}_0x1d9600=_[_0xbfc2('0x47')]({},_0x1d9600,_0x36f73a[_0xbfc2('0x49')]);return db[_0xbfc2('0x37')][_0xbfc2('0x52')](_0x1d9600)[_0xbfc2('0x31')](handleEntityNotFound(_0x38854a,null))[_0xbfc2('0x31')](respondWithResult(_0x38854a,null))[_0xbfc2('0x4d')](handleError(_0x38854a,null));};exports[_0xbfc2('0x53')]=function(_0x2aa774,_0x467414,_0x28c88d){return db[_0xbfc2('0x37')][_0xbfc2('0x52')]({'where':{'id':_0x2aa774[_0xbfc2('0x4f')]['id']},'attributes':[_0xbfc2('0x48'),_0xbfc2('0x9')],'raw':!![]})[_0xbfc2('0x31')](handleEntityNotFound(_0x467414,null))[_0xbfc2('0x31')](function(_0x44d680){if(_0x44d680){var _0x29fab3=path['join'](config[_0xbfc2('0x54')],_0xbfc2('0x55'),util['format'](_0xbfc2('0x56'),path[_0xbfc2('0x57')](_0x44d680[_0xbfc2('0x9')])));var _0x1c7381=fs[_0xbfc2('0x58')](_0x29fab3);var _0x280e53=archiver(_0xbfc2('0x59'),{'zlib':{'level':0x9}});_0x280e53['on']('warning',function(_0x3ab77d){if(_0x3ab77d[_0xbfc2('0x5a')]==='ENOENT'){logger[_0xbfc2('0x5b')](_0x3ab77d);}else{throw new db[(_0xbfc2('0x5c'))][(_0xbfc2('0x5d'))](_0xbfc2('0x5e'));}});_0x280e53['on'](_0xbfc2('0x5b'),function(_0x2daa77){throw new db[(_0xbfc2('0x5c'))][(_0xbfc2('0x5d'))](_0xbfc2('0x5e'));});_0x280e53[_0xbfc2('0x5f')](_0x1c7381);_0x280e53[_0xbfc2('0x60')]('**/*',{'cwd':path[_0xbfc2('0x61')](config['root'],_0xbfc2('0x55'),path[_0xbfc2('0x62')](_0x44d680[_0xbfc2('0x9')])),'ignore':[path['join'](path['basename'](_0x44d680[_0xbfc2('0x9')]),_0xbfc2('0x63')),path[_0xbfc2('0x61')](path['basename'](_0x44d680['path']),_0xbfc2('0x64'))],'nodir':!![]})[_0xbfc2('0x65')]();_0x1c7381['on'](_0xbfc2('0x66'),function(){if(!fs[_0xbfc2('0x67')](_0x29fab3)){throw new db['Sequelize'][(_0xbfc2('0x5d'))](_0xbfc2('0x68'));}return _0x467414['download'](_0x29fab3,util[_0xbfc2('0x69')](_0xbfc2('0x56'),path[_0xbfc2('0x57')](_0x44d680['path'])),function(_0x22ba08){if(_0x22ba08){throw new db['Sequelize']['Error'](_0xbfc2('0x6a'));}fs[_0xbfc2('0x6b')](_0x29fab3);logger[_0xbfc2('0x6c')](_0xbfc2('0x6d'));logger['info']('Temporary\x20file\x20removed');});});}return null;})[_0xbfc2('0x4d')](handleError(_0x467414,null));};exports[_0xbfc2('0x6e')]=function(_0x13f27b,_0x2df093,_0x54a89c){var _0x58573b=path[_0xbfc2('0x57')](_0x13f27b[_0xbfc2('0x6f')]['filename'],path['extname'](_0x13f27b[_0xbfc2('0x6f')]['filename']));var _0x4e2aeb=path[_0xbfc2('0x61')](config['root'],'server/files/plugins',_0x13f27b['file'][_0xbfc2('0x70')]);var _0x2a0185=path['join'](config['root'],'server/files/plugins',_0x58573b);logger[_0xbfc2('0x6c')]('Plugin\x20upload\x20filepath:\x20%s',_0x4e2aeb);logger[_0xbfc2('0x6c')](_0xbfc2('0x71'),_0x2a0185);try{fs[_0xbfc2('0x72')](_0x4e2aeb,parseInt(_0xbfc2('0x73'),0x8));extract(_0x4e2aeb,{'dir':_0x2a0185},function(_0x870524){if(_0x870524){logger[_0xbfc2('0x5b')](_0x870524);handleError(_0x870524,!![]);};var _0x3db93b=fs[_0xbfc2('0x74')](_0x2a0185);if(_0x3db93b[_0xbfc2('0x42')]>0x1){removeReferences(_0x4e2aeb,_0x2a0185);logger[_0xbfc2('0x5b')](_0xbfc2('0x75'));return _0x54a89c(new Error(_0xbfc2('0x75')));}var _0x253feb=fs[_0xbfc2('0x76')](path['join'](_0x2a0185,_0x3db93b[0x0]));if(_0x253feb[_0xbfc2('0x77')]()){removeReferences(_0x4e2aeb,_0x2a0185);logger[_0xbfc2('0x5b')](_0xbfc2('0x75'));return _0x54a89c(new Error(_0xbfc2('0x75')));}if(_0x253feb['isDirectory']()){var _0x47338d=fs[_0xbfc2('0x74')](path[_0xbfc2('0x61')](_0x2a0185,_0x3db93b[0x0]));if(_0x47338d[_0xbfc2('0x42')]===0x0){removeReferences(_0x4e2aeb,_0x2a0185);logger[_0xbfc2('0x5b')](_0xbfc2('0x75'));return _0x54a89c(new Error('Invalid\x20plugin\x20structure'));}var _0x4eadca=_0x47338d[_0xbfc2('0x78')](function(_0x5eef86){return _0x5eef86===_0xbfc2('0x79');});if(!_0x4eadca){return _0x54a89c(new Error('Plugin\x20manifest\x20missing'));}var _0x5daa1a=fs['readFileSync'](path[_0xbfc2('0x61')](_0x2a0185,_0x3db93b[0x0],'manifest.json'));var _0x2d7c2c=JSON[_0xbfc2('0x7a')](_0x5daa1a);if(_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x48')]){return _0x54a89c(new Error('Invalid\x20manifest:\x20name\x20missing'));}if(_0xbfc2('0x25')==typeof _0x2d7c2c['type']){return _0x54a89c(new Error(_0xbfc2('0x7b')));}if(_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x7c')]){return _0x54a89c(new Error(_0xbfc2('0x7d')));}if(_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x7e')]){return _0x54a89c(new Error(_0xbfc2('0x7f')));}if(_0x2d7c2c[_0xbfc2('0x39')]===_0xbfc2('0x80')){if('undefined'==typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')]){return _0x54a89c(new Error(_0xbfc2('0x82')));}if('undefined'==typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')][_0xbfc2('0x83')]&&_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')][_0xbfc2('0x84')]){return _0x54a89c(new Error(_0xbfc2('0x85')));}}else if(_0x2d7c2c[_0xbfc2('0x39')]==='script'){if(_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x86')]){return _0x54a89c(new Error(_0xbfc2('0x87')));}if(_0xbfc2('0x25')==typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x88')]){return _0x54a89c(new Error('Invalid\x20manifest:\x20script\x20path\x20missing'));}}else{return _0x54a89c(new Error(_0xbfc2('0x89')));}var _0x4f4136=_0x2d7c2c[_0xbfc2('0x48')];var _0x589591=_0x2d7c2c[_0xbfc2('0x8a')];var _0x2a7e14=_0x2d7c2c[_0xbfc2('0x39')];var _0x4fd65b=_0x2d7c2c[_0xbfc2('0x8b')]?_0x2d7c2c[_0xbfc2('0x8b')]:_0xbfc2('0x8c');var _0x49fed1=_0x2d7c2c[_0xbfc2('0x8d')]?_0x2d7c2c[_0xbfc2('0x8d')]:_0xbfc2('0x8e');var _0x40f88d='';var _0x3bb7f4='';var _0xf5806d='';var _0x95affc='';var _0x17d80d=_0x2d7c2c[_0xbfc2('0x7c')];if(_0x2a7e14===_0xbfc2('0x80')){if('undefined'!=typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')][_0xbfc2('0x83')]){var _0x3b0d1b=_0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')][_0xbfc2('0x83')];if(!/^(f|ht)tps?:\/\//i[_0xbfc2('0x8f')](_0x3b0d1b)){_0x40f88d=path['join'](_0xbfc2('0x90'),_0x58573b,_0x3db93b[0x0],_0x3b0d1b);}else{_0x40f88d=_0x3b0d1b;}}else{logger[_0xbfc2('0x6c')](_0xbfc2('0x91'));}if(_0xbfc2('0x25')!=typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')][_0xbfc2('0x84')]){var _0x39d0ba=_0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0xbfc2('0x8f')](_0x39d0ba)){_0x3bb7f4=path['join'](_0xbfc2('0x90'),_0x58573b,_0x3db93b[0x0],_0x39d0ba);}else{_0x3bb7f4=_0x39d0ba;}}else{logger[_0xbfc2('0x6c')]('Warning:\x20agent\x20view\x20not\x20specified');}}else if(_0x2a7e14==='script'){_0xf5806d=_0x2d7c2c['parameters'][_0xbfc2('0x86')];_0x95affc=_0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x88')];if(_0xbfc2('0x25')!=typeof _0x2d7c2c[_0xbfc2('0x7e')][_0xbfc2('0x81')]){if(_0xbfc2('0x25')!=typeof _0x2d7c2c['parameters'][_0xbfc2('0x81')]['admin']){var _0x3b0d1b=_0x2d7c2c[_0xbfc2('0x7e')]['views'][_0xbfc2('0x83')];if(!/^(f|ht)tps?:\/\//i[_0xbfc2('0x8f')](_0x3b0d1b)){_0x40f88d=path[_0xbfc2('0x61')](_0xbfc2('0x90'),_0x58573b,_0x3db93b[0x0],_0x3b0d1b);}else{_0x40f88d=_0x3b0d1b;}}if('undefined'!=typeof _0x2d7c2c['parameters'][_0xbfc2('0x81')][_0xbfc2('0x84')]){var _0x39d0ba=_0x2d7c2c['parameters'][_0xbfc2('0x81')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0xbfc2('0x8f')](_0x39d0ba)){_0x3bb7f4=path[_0xbfc2('0x61')]('plugins',_0x58573b,_0x3db93b[0x0],_0x39d0ba);}else{_0x3bb7f4=_0x39d0ba;}}}}var _0x59982b={'name':_0x4f4136,'description':_0x589591,'path':path[_0xbfc2('0x61')](_0x58573b,_0x3db93b[0x0]),'type':_0x2a7e14,'sidebar':_0x4fd65b,'icon':_0x49fed1,'adminUrl':_0x40f88d,'agentUrl':_0x3bb7f4,'scriptName':_0xf5806d,'scriptPath':_0x95affc,'version':_0x17d80d};removeReferences(_0x4e2aeb,null);return db[_0xbfc2('0x37')][_0xbfc2('0x92')](_0x59982b)['then'](function(_0x239b71){var _0x3d10d4={'role':_0x13f27b[_0xbfc2('0x93')]['role'],'userProfileId':_0x13f27b[_0xbfc2('0x93')]['userProfileId']};if(!_0x3d10d4)throw new Error(_0xbfc2('0x94'));if(_0x3d10d4[_0xbfc2('0x95')]==='user'){var _0x4577bf=_0x239b71[_0xbfc2('0x32')]({'plain':!![]});return db[_0xbfc2('0x96')][_0xbfc2('0x52')]({'where':{'name':_0xbfc2('0x33'),'userProfileId':_0x3d10d4[_0xbfc2('0x97')]},'raw':!![]})['then'](function(_0x1dfa21){if(_0x1dfa21&&_0x1dfa21[_0xbfc2('0x98')]===0x0){return db['UserProfileResource'][_0xbfc2('0x92')]({'name':_0x4577bf[_0xbfc2('0x48')],'resourceId':_0x4577bf['id'],'type':_0x1dfa21[_0xbfc2('0x48')],'sectionId':_0x1dfa21['id']},{})[_0xbfc2('0x31')](function(){return _0x239b71;});}else{return _0x239b71;}})[_0xbfc2('0x4d')](function(_0x36d730){logger[_0xbfc2('0x5b')](_0xbfc2('0x99'),_0x36d730);throw _0x36d730;});}return _0x239b71;})[_0xbfc2('0x31')](respondWithResult(_0x2df093,null))[_0xbfc2('0x4d')](handleError(_0x2df093,null));}});}catch(_0x48066d){_0x2df093['status'](0x1f4)['send'](_0x48066d);}};function removeReferences(_0x177c7e,_0x14604f){try{if(_0x177c7e){fs[_0xbfc2('0x6b')](_0x177c7e);logger[_0xbfc2('0x6c')](_0xbfc2('0x9a'));}if(_0x14604f){rimraf(_0x14604f,function(){});logger[_0xbfc2('0x6c')](_0xbfc2('0x9b'));}}catch(_0x3f36c0){logger[_0xbfc2('0x5b')](_0x3f36c0);}}exports['update']=function(_0x408167,_0x32f087,_0x1f6b3e){return db[_0xbfc2('0x37')][_0xbfc2('0x52')]({'where':{'id':_0x408167[_0xbfc2('0x4f')]['id']}})[_0xbfc2('0x31')](handleEntityNotFound(_0x32f087,null))['then'](saveUpdates(_0x408167[_0xbfc2('0x93')],null))[_0xbfc2('0x31')](respondWithResult(_0x32f087,null))[_0xbfc2('0x4d')](handleError(_0x32f087,null));};exports[_0xbfc2('0x9c')]=function(_0x2fbfc5,_0x59e116,_0x5e9151){return db[_0xbfc2('0x37')]['find']({'where':{'id':_0x2fbfc5[_0xbfc2('0x4f')]['id']}})['then'](function(_0x208211){if(_0x208211){return _0x208211[_0xbfc2('0x30')]();}})[_0xbfc2('0x31')](function(_0x34fd0f){rimraf(path[_0xbfc2('0x61')](config[_0xbfc2('0x54')],_0xbfc2('0x55'),path[_0xbfc2('0x62')](_0x34fd0f['path'])),function(){});return _0x34fd0f;})[_0xbfc2('0x31')](handleEntityNotFound(_0x59e116,null))[_0xbfc2('0x31')](respondWithStatusCode(_0x59e116,null))['catch'](handleError(_0x59e116,null));};exports[_0xbfc2('0x9d')]=function(_0x9c3920,_0x2c3762,_0x3da2cd){return BPromise['resolve']()['then'](function(){if(!_0x9c3920[_0xbfc2('0x3c')]['path']){throw new Error(_0xbfc2('0x9e'));}if(!_0x9c3920[_0xbfc2('0x3c')][_0xbfc2('0x9f')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x453cee=_0x9c3920[_0xbfc2('0x3c')][_0xbfc2('0xa0')]?_0x9c3920[_0xbfc2('0x3c')][_0xbfc2('0xa0')]+':'+_0x9c3920[_0xbfc2('0x3c')]['port']:_0xbfc2('0xa1')+_0x9c3920['query'][_0xbfc2('0x9f')];var _0x335ed2=_0x9c3920['query'][_0xbfc2('0x2b')]?_0x9c3920[_0xbfc2('0x3c')][_0xbfc2('0x2b')]:!![];var _0x4f0db4=_0x9c3920['query'][_0xbfc2('0xa2')]?_0x9c3920['query'][_0xbfc2('0xa2')]:null;var _0x60bfcc={'method':_0x9c3920['method'],'uri':util[_0xbfc2('0x69')]('%s%s',_0x453cee,_0x9c3920[_0xbfc2('0x3c')][_0xbfc2('0x9')]),'json':_0x335ed2,'resolveWithFullResponse':!![],'encoding':_0x4f0db4,'qs':_0x9c3920[_0xbfc2('0x3c')]};if(_0x9c3920[_0xbfc2('0xa3')]){_0x60bfcc['headers']=_0x9c3920['headers'];if(_0x60bfcc[_0xbfc2('0xa3')][_0xbfc2('0xa4')]){delete _0x60bfcc[_0xbfc2('0xa3')]['content-length'];}}if(_0x60bfcc[_0xbfc2('0xa3')][_0xbfc2('0xa5')]){delete _0x60bfcc[_0xbfc2('0xa3')]['content-type'];}return rp(_0x60bfcc);})[_0xbfc2('0x31')](function(_0x49d740){if(_0x49d740){_0x2c3762[_0xbfc2('0x29')](_0x49d740[_0xbfc2('0xa3')]);logger[_0xbfc2('0x6c')](_0x49d740[_0xbfc2('0x93')]);if(_['endsWith'](_0x9c3920['query'][_0xbfc2('0x9')],_0xbfc2('0x53'))&&_0x49d740[_0xbfc2('0xa6')]==0x1f4){return _0x2c3762[_0xbfc2('0x22')](_0x49d740[_0xbfc2('0xa6')]);}else{return _0x2c3762[_0xbfc2('0x23')](_0x49d740[_0xbfc2('0xa6')])[_0xbfc2('0x36')](_0x49d740[_0xbfc2('0x93')]);}}else{return _0x2c3762[_0xbfc2('0x22')](0xc8);}})[_0xbfc2('0x4d')](handleError(_0x2c3762,null));};exports[_0xbfc2('0xa7')]=function(_0x3efa45,_0x4099a4,_0x5558fc){return BPromise[_0xbfc2('0xa8')]()[_0xbfc2('0x31')](function(){if(!_0x3efa45['query'][_0xbfc2('0x9')]){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x3efa45[_0xbfc2('0x3c')][_0xbfc2('0x9f')]){throw new Error(_0xbfc2('0xa9'));}var _0x192e9a=_0x3efa45[_0xbfc2('0x3c')]['hostname']?_0x3efa45[_0xbfc2('0x3c')]['hostname']+':'+_0x3efa45[_0xbfc2('0x3c')][_0xbfc2('0x9f')]:_0xbfc2('0xa1')+_0x3efa45[_0xbfc2('0x3c')][_0xbfc2('0x9f')];var _0x25f0a8=_0x3efa45[_0xbfc2('0x3c')][_0xbfc2('0x2b')]?_0x3efa45['query']['json']:!![];var _0xd2bfef=_0x3efa45[_0xbfc2('0x3c')][_0xbfc2('0xa2')]?_0x3efa45[_0xbfc2('0x3c')]['encoding']:null;var _0x335c46={'method':_0x3efa45['method'],'uri':util[_0xbfc2('0x69')](_0xbfc2('0xaa'),_0x192e9a,_0x3efa45['query'][_0xbfc2('0x9')]),'json':_0x25f0a8,'resolveWithFullResponse':!![],'encoding':_0xd2bfef,'body':_0x3efa45[_0xbfc2('0x93')]};if(_0x3efa45[_0xbfc2('0xa3')]){_0x335c46[_0xbfc2('0xa3')]=_0x3efa45[_0xbfc2('0xa3')];if(_0x335c46[_0xbfc2('0xa3')]['content-length']){delete _0x335c46['headers'][_0xbfc2('0xa4')];}}if(_0x335c46['headers'][_0xbfc2('0xa5')]){delete _0x335c46[_0xbfc2('0xa3')][_0xbfc2('0xa5')];}return rp(_0x335c46);})[_0xbfc2('0x31')](function(_0x18c58c){if(_0x18c58c){_0x4099a4['set'](_0x18c58c[_0xbfc2('0xa3')]);logger[_0xbfc2('0x6c')](_0x18c58c['body']);return _0x4099a4['status'](_0x18c58c[_0xbfc2('0xa6')])[_0xbfc2('0x36')](_0x18c58c['body']);}else{return _0x4099a4[_0xbfc2('0x22')](0xc8);}})[_0xbfc2('0x4d')](handleError(_0x4099a4,null));};