Built motion from commit d13fb11b.|2.6.34
[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 _0xf246=['ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','get','Plugins','UserProfileResource','error','name','index','map','Plugin','fieldName','type','key','model','query','intersection','attributes','fields','length','nolimit','order','sort','where','filters','merge','VIRTUAL','filter','options','includeAll','findAll','catch','params','keys','rawAttributes','include','find','download','join','server/files/plugins','format','basename','createWriteStream','zip','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','glob','root','attachments/**/*','finalize','close','existsSync','%s.zip','Error\x20while\x20downloading\x20the\x20plugin','info','upload','file','filename','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','Invalid\x20plugin\x20structure','isFile','Plugin\x20manifest\x20missing','readFileSync','manifest.json','Invalid\x20manifest:\x20type\x20missing','version','parameters','views','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','script','scriptName','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','sidebar','always','icon','icon-apps','html','test','Warning:\x20admin\x20view\x20not\x20specified','Warning:\x20agent\x20view\x20not\x20specified','plugins','body','role','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','Extracted\x20folder\x20removed','delete','dirname','webhookGet','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','hostname','port','http://localhost:','%s%s','headers','content-length','content-type','endsWith','statusCode','webhookPost','\x27PORT\x27\x20parameter\x20not\x20specified','encoding','method','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','extract-zip','archiver'];(function(_0x939a59,_0x174b9d){var _0x37206e=function(_0x5473d0){while(--_0x5473d0){_0x939a59['push'](_0x939a59['shift']());}};_0x37206e(++_0x174b9d);}(_0xf246,0x1d7));var _0x6f24=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf246[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x6f24('0x0'));var rimraf=require(_0x6f24('0x1'));var zipdir=require(_0x6f24('0x2'));var jsonpatch=require(_0x6f24('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x6f24('0x4'));var Mustache=require(_0x6f24('0x5'));var util=require('util');var path=require(_0x6f24('0x6'));var sox=require(_0x6f24('0x7'));var csv=require(_0x6f24('0x8'));var ejs=require(_0x6f24('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x6f24('0xa'));var squel=require(_0x6f24('0xb'));var crypto=require(_0x6f24('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x6f24('0xd'));var toCsv=require(_0x6f24('0x8'));var querystring=require(_0x6f24('0xe'));var Papa=require(_0x6f24('0xf'));var extract=require(_0x6f24('0x10'));var rimraf=require('rimraf');var archiver=require(_0x6f24('0x11'));var Redis=require(_0x6f24('0x12'));var authService=require(_0x6f24('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x6f24('0x14'));var hardwareService=require(_0x6f24('0x15'));var logger=require('../../config/logger')(_0x6f24('0x16'));var utils=require('../../config/utils');var config=require(_0x6f24('0x17'));var licenseUtil=require(_0x6f24('0x18'));var db=require('../../mysqldb')['db'];config[_0x6f24('0x19')]=_[_0x6f24('0x1a')](config[_0x6f24('0x19')],{'host':_0x6f24('0x1b'),'port':0x18eb});var socket=require(_0x6f24('0x1c'))(new Redis(config[_0x6f24('0x19')]));require(_0x6f24('0x1d'))[_0x6f24('0x1e')](socket);function respondWithStatusCode(_0x4f3a8c,_0x48d55d){_0x48d55d=_0x48d55d||0xcc;return function(_0x193780){if(_0x193780){return _0x4f3a8c[_0x6f24('0x1f')](_0x48d55d);}return _0x4f3a8c[_0x6f24('0x20')](_0x48d55d)[_0x6f24('0x21')]();};}function respondWithResult(_0x2e85af,_0x47ba0b){_0x47ba0b=_0x47ba0b||0xc8;return function(_0x28f68a){if(_0x28f68a){return _0x2e85af[_0x6f24('0x20')](_0x47ba0b)[_0x6f24('0x22')](_0x28f68a);}};}function respondWithFilteredResult(_0x591991,_0xa7e6d0){return function(_0x1126f7){if(_0x1126f7){var _0x4ce3ca=typeof _0xa7e6d0[_0x6f24('0x23')]===_0x6f24('0x24')&&typeof _0xa7e6d0[_0x6f24('0x25')]===_0x6f24('0x24');var _0x4836e4=_0x1126f7[_0x6f24('0x26')];var _0x236354=_0x4ce3ca?0x0:_0xa7e6d0[_0x6f24('0x23')];var _0x270695=_0x4ce3ca?_0x1126f7[_0x6f24('0x26')]:_0xa7e6d0[_0x6f24('0x23')]+_0xa7e6d0['limit'];var _0x425479;if(_0x270695>=_0x4836e4){_0x270695=_0x4836e4;_0x425479=0xc8;}else{_0x425479=0xce;}_0x591991[_0x6f24('0x20')](_0x425479);return _0x591991[_0x6f24('0x27')](_0x6f24('0x28'),_0x236354+'-'+_0x270695+'/'+_0x4836e4)[_0x6f24('0x22')](_0x1126f7);}return null;};}function patchUpdates(_0x19e9ac){return function(_0x292414){try{jsonpatch[_0x6f24('0x29')](_0x292414,_0x19e9ac,!![]);}catch(_0x244767){return BPromise[_0x6f24('0x2a')](_0x244767);}return _0x292414[_0x6f24('0x2b')]();};}function saveUpdates(_0x3b62d7,_0x317c22){return function(_0x5aff4f){if(_0x5aff4f){return _0x5aff4f[_0x6f24('0x2c')](_0x3b62d7)['then'](function(_0x1e5048){return _0x1e5048;});}return null;};}function removeEntity(_0x30b08b,_0x1e495a){return function(_0x1cc6cd){if(_0x1cc6cd){return _0x1cc6cd[_0x6f24('0x2d')]()[_0x6f24('0x2e')](function(){var _0x1a6c76=_0x1cc6cd[_0x6f24('0x2f')]({'plain':!![]});var _0x674bc8=_0x6f24('0x30');return db[_0x6f24('0x31')][_0x6f24('0x2d')]({'where':{'type':_0x674bc8,'resourceId':_0x1a6c76['id']}})[_0x6f24('0x2e')](function(){return _0x1cc6cd;});})[_0x6f24('0x2e')](function(){_0x30b08b[_0x6f24('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x242d5e,_0x57496e){return function(_0x1ddc53){if(!_0x1ddc53){_0x242d5e[_0x6f24('0x1f')](0x194);}return _0x1ddc53;};}function handleError(_0x23f32e,_0x17cd65){_0x17cd65=_0x17cd65||0x1f4;return function(_0x1d6303){logger[_0x6f24('0x32')](_0x1d6303['stack']);if(_0x1d6303[_0x6f24('0x33')]){delete _0x1d6303[_0x6f24('0x33')];}_0x23f32e['status'](_0x17cd65)['send'](_0x1d6303);};}exports[_0x6f24('0x34')]=function(_0x1499ba,_0x45158b){var _0x1366f2={},_0xbec75c={},_0x5ce40e={'count':0x0,'rows':[]};var _0x18ee17=_[_0x6f24('0x35')](db[_0x6f24('0x36')]['rawAttributes'],function(_0x4bed3d){return{'name':_0x4bed3d[_0x6f24('0x37')],'type':_0x4bed3d[_0x6f24('0x38')][_0x6f24('0x39')]};});_0xbec75c[_0x6f24('0x3a')]=_[_0x6f24('0x35')](_0x18ee17,'name');_0xbec75c[_0x6f24('0x3b')]=_['keys'](_0x1499ba[_0x6f24('0x3b')]);_0xbec75c['filters']=_[_0x6f24('0x3c')](_0xbec75c[_0x6f24('0x3a')],_0xbec75c[_0x6f24('0x3b')]);_0x1366f2[_0x6f24('0x3d')]=_['intersection'](_0xbec75c[_0x6f24('0x3a')],qs[_0x6f24('0x3e')](_0x1499ba['query'][_0x6f24('0x3e')]));_0x1366f2[_0x6f24('0x3d')]=_0x1366f2[_0x6f24('0x3d')][_0x6f24('0x3f')]?_0x1366f2[_0x6f24('0x3d')]:_0xbec75c[_0x6f24('0x3a')];if(!_0x1499ba['query']['hasOwnProperty'](_0x6f24('0x40'))){_0x1366f2[_0x6f24('0x25')]=qs['limit'](_0x1499ba['query']['limit']);_0x1366f2[_0x6f24('0x23')]=qs['offset'](_0x1499ba[_0x6f24('0x3b')][_0x6f24('0x23')]);}_0x1366f2[_0x6f24('0x41')]=qs['sort'](_0x1499ba['query'][_0x6f24('0x42')]);_0x1366f2[_0x6f24('0x43')]=qs[_0x6f24('0x44')](_['pick'](_0x1499ba[_0x6f24('0x3b')],_0xbec75c[_0x6f24('0x44')]),_0x18ee17);if(_0x1499ba[_0x6f24('0x3b')]['filter']){_0x1366f2['where']=_[_0x6f24('0x45')](_0x1366f2[_0x6f24('0x43')],{'$or':_[_0x6f24('0x35')](_0x18ee17,function(_0x11a259){if(_0x11a259['type']!==_0x6f24('0x46')){var _0x74efae={};_0x74efae[_0x11a259[_0x6f24('0x33')]]={'$like':'%'+_0x1499ba[_0x6f24('0x3b')][_0x6f24('0x47')]+'%'};return _0x74efae;}})});}_0x1366f2=_['merge']({},_0x1366f2,_0x1499ba[_0x6f24('0x48')]);var _0x1e3f56={'where':_0x1366f2[_0x6f24('0x43')]};return db['Plugin']['count'](_0x1e3f56)[_0x6f24('0x2e')](function(_0x15647e){_0x5ce40e[_0x6f24('0x26')]=_0x15647e;if(_0x1499ba[_0x6f24('0x3b')][_0x6f24('0x49')]){_0x1366f2['include']=[{'all':!![]}];}return db[_0x6f24('0x36')][_0x6f24('0x4a')](_0x1366f2);})[_0x6f24('0x2e')](function(_0x1c99bd){_0x5ce40e['rows']=_0x1c99bd;return _0x5ce40e;})[_0x6f24('0x2e')](respondWithFilteredResult(_0x45158b,_0x1366f2))[_0x6f24('0x4b')](handleError(_0x45158b,null));};exports['show']=function(_0x3c51b7,_0x15aa58){var _0x10bc57={'raw':!![],'where':{'id':_0x3c51b7[_0x6f24('0x4c')]['id']}},_0x3f879e={};_0x3f879e[_0x6f24('0x3a')]=_[_0x6f24('0x4d')](db['Plugin'][_0x6f24('0x4e')]);_0x3f879e['query']=_[_0x6f24('0x4d')](_0x3c51b7['query']);_0x3f879e['filters']=_[_0x6f24('0x3c')](_0x3f879e[_0x6f24('0x3a')],_0x3f879e[_0x6f24('0x3b')]);_0x10bc57[_0x6f24('0x3d')]=_['intersection'](_0x3f879e[_0x6f24('0x3a')],qs[_0x6f24('0x3e')](_0x3c51b7[_0x6f24('0x3b')]['fields']));_0x10bc57[_0x6f24('0x3d')]=_0x10bc57[_0x6f24('0x3d')][_0x6f24('0x3f')]?_0x10bc57[_0x6f24('0x3d')]:_0x3f879e[_0x6f24('0x3a')];if(_0x3c51b7[_0x6f24('0x3b')][_0x6f24('0x49')]){_0x10bc57[_0x6f24('0x4f')]=[{'all':!![]}];}_0x10bc57=_[_0x6f24('0x45')]({},_0x10bc57,_0x3c51b7['options']);return db[_0x6f24('0x36')][_0x6f24('0x50')](_0x10bc57)[_0x6f24('0x2e')](handleEntityNotFound(_0x15aa58,null))['then'](respondWithResult(_0x15aa58,null))[_0x6f24('0x4b')](handleError(_0x15aa58,null));};exports[_0x6f24('0x51')]=function(_0x7f824d,_0x208080,_0x24d8a6){return db['Plugin'][_0x6f24('0x50')]({'where':{'id':_0x7f824d[_0x6f24('0x4c')]['id']},'attributes':[_0x6f24('0x33'),_0x6f24('0x6')],'raw':!![]})[_0x6f24('0x2e')](handleEntityNotFound(_0x208080,null))[_0x6f24('0x2e')](function(_0x40a638){if(_0x40a638){var _0xf682b0=path[_0x6f24('0x52')](config['root'],_0x6f24('0x53'),util[_0x6f24('0x54')]('%s.zip',path[_0x6f24('0x55')](_0x40a638[_0x6f24('0x6')])));var _0x4d011e=fs[_0x6f24('0x56')](_0xf682b0);var _0x25e997=archiver(_0x6f24('0x57'),{'zlib':{'level':0x9}});_0x25e997['on']('warning',function(_0x5d205c){if(_0x5d205c[_0x6f24('0x58')]===_0x6f24('0x59')){logger[_0x6f24('0x32')](_0x5d205c);}else{throw new db[(_0x6f24('0x5a'))][(_0x6f24('0x5b'))](_0x6f24('0x5c'));}});_0x25e997['on'](_0x6f24('0x32'),function(_0x5d9646){throw new db['Sequelize'][(_0x6f24('0x5b'))](_0x6f24('0x5c'));});_0x25e997[_0x6f24('0x5d')](_0x4d011e);_0x25e997[_0x6f24('0x5e')]('**/*',{'cwd':path[_0x6f24('0x52')](config[_0x6f24('0x5f')],'server/files/plugins',path['dirname'](_0x40a638[_0x6f24('0x6')])),'ignore':[path['join'](path[_0x6f24('0x55')](_0x40a638['path']),'node_modules/**/*'),path[_0x6f24('0x52')](path[_0x6f24('0x55')](_0x40a638['path']),_0x6f24('0x60'))],'nodir':!![]})[_0x6f24('0x61')]();_0x4d011e['on'](_0x6f24('0x62'),function(){if(!fs[_0x6f24('0x63')](_0xf682b0)){throw new db[(_0x6f24('0x5a'))]['Error']('Plugin\x20not\x20found');}return _0x208080[_0x6f24('0x51')](_0xf682b0,util[_0x6f24('0x54')](_0x6f24('0x64'),path['basename'](_0x40a638[_0x6f24('0x6')])),function(_0x339cf0){if(_0x339cf0){throw new db[(_0x6f24('0x5a'))][(_0x6f24('0x5b'))](_0x6f24('0x65'));}fs['unlinkSync'](_0xf682b0);logger[_0x6f24('0x66')]('Download\x20completed');logger[_0x6f24('0x66')]('Temporary\x20file\x20removed');});});}return null;})['catch'](handleError(_0x208080,null));};exports[_0x6f24('0x67')]=function(_0x1a740d,_0x1c423a,_0x29f633){var _0x39c49b=path['basename'](_0x1a740d[_0x6f24('0x68')][_0x6f24('0x69')],path['extname'](_0x1a740d[_0x6f24('0x68')][_0x6f24('0x69')]));var _0x1df326=path['join'](config[_0x6f24('0x5f')],_0x6f24('0x53'),_0x1a740d[_0x6f24('0x68')]['filename']);var _0x1199b1=path[_0x6f24('0x52')](config[_0x6f24('0x5f')],'server/files/plugins',_0x39c49b);logger['info'](_0x6f24('0x6a'),_0x1df326);logger[_0x6f24('0x66')](_0x6f24('0x6b'),_0x1199b1);try{fs[_0x6f24('0x6c')](_0x1df326,parseInt(_0x6f24('0x6d'),0x8));extract(_0x1df326,{'dir':_0x1199b1},function(_0x5e1ced){if(_0x5e1ced){logger[_0x6f24('0x32')](_0x5e1ced);handleError(_0x5e1ced,!![]);};var _0x24c574=fs['readdirSync'](_0x1199b1);if(_0x24c574['length']>0x1){removeReferences(_0x1df326,_0x1199b1);logger[_0x6f24('0x32')](_0x6f24('0x6e'));return _0x29f633(new Error(_0x6f24('0x6e')));}var _0x2030f2=fs['lstatSync'](path[_0x6f24('0x52')](_0x1199b1,_0x24c574[0x0]));if(_0x2030f2[_0x6f24('0x6f')]()){removeReferences(_0x1df326,_0x1199b1);logger[_0x6f24('0x32')](_0x6f24('0x6e'));return _0x29f633(new Error(_0x6f24('0x6e')));}if(_0x2030f2['isDirectory']()){var _0x58d2bc=fs['readdirSync'](path[_0x6f24('0x52')](_0x1199b1,_0x24c574[0x0]));if(_0x58d2bc[_0x6f24('0x3f')]===0x0){removeReferences(_0x1df326,_0x1199b1);logger[_0x6f24('0x32')](_0x6f24('0x6e'));return _0x29f633(new Error(_0x6f24('0x6e')));}var _0x228000=_0x58d2bc['some'](function(_0x356ad3){return _0x356ad3==='manifest.json';});if(!_0x228000){return _0x29f633(new Error(_0x6f24('0x70')));}var _0x43be2a=fs[_0x6f24('0x71')](path[_0x6f24('0x52')](_0x1199b1,_0x24c574[0x0],_0x6f24('0x72')));var _0x2d9ea0=JSON['parse'](_0x43be2a);if(_0x6f24('0x24')==typeof _0x2d9ea0['name']){return _0x29f633(new Error('Invalid\x20manifest:\x20name\x20missing'));}if(_0x6f24('0x24')==typeof _0x2d9ea0[_0x6f24('0x38')]){return _0x29f633(new Error(_0x6f24('0x73')));}if(_0x6f24('0x24')==typeof _0x2d9ea0[_0x6f24('0x74')]){return _0x29f633(new Error('Invalid\x20manifest:\x20version\x20not\x20specified'));}if(_0x6f24('0x24')==typeof _0x2d9ea0[_0x6f24('0x75')]){return _0x29f633(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x2d9ea0['type']==='html'){if(_0x6f24('0x24')==typeof _0x2d9ea0['parameters'][_0x6f24('0x76')]){return _0x29f633(new Error(_0x6f24('0x77')));}if(_0x6f24('0x24')==typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x78')]&&'undefined'==typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x79')]){return _0x29f633(new Error(_0x6f24('0x7a')));}}else if(_0x2d9ea0[_0x6f24('0x38')]===_0x6f24('0x7b')){if('undefined'==typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x7c')]){return _0x29f633(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0x6f24('0x24')==typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x7d')]){return _0x29f633(new Error(_0x6f24('0x7e')));}}else{return _0x29f633(new Error(_0x6f24('0x7f')));}var _0x218b16=_0x2d9ea0[_0x6f24('0x33')];var _0x35af73=_0x2d9ea0['description'];var _0x4a7a99=_0x2d9ea0[_0x6f24('0x38')];var _0x24d98a=_0x2d9ea0[_0x6f24('0x80')]?_0x2d9ea0[_0x6f24('0x80')]:_0x6f24('0x81');var _0xce3ee8=_0x2d9ea0[_0x6f24('0x82')]?_0x2d9ea0['icon']:_0x6f24('0x83');var _0x34f0f3='';var _0x367916='';var _0x20ea53='';var _0x13b254='';var _0x23315a=_0x2d9ea0[_0x6f24('0x74')];if(_0x4a7a99===_0x6f24('0x84')){if(_0x6f24('0x24')!=typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x78')]){var _0x35cdb5=_0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x78')];if(!/^(f|ht)tps?:\/\//i[_0x6f24('0x85')](_0x35cdb5)){_0x34f0f3=path[_0x6f24('0x52')]('plugins',_0x39c49b,_0x24c574[0x0],_0x35cdb5);}else{_0x34f0f3=_0x35cdb5;}}else{logger[_0x6f24('0x66')](_0x6f24('0x86'));}if(_0x6f24('0x24')!=typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x79')]){var _0x55be9d=_0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x79')];if(!/^(f|ht)tps?:\/\//i[_0x6f24('0x85')](_0x55be9d)){_0x367916=path[_0x6f24('0x52')]('plugins',_0x39c49b,_0x24c574[0x0],_0x55be9d);}else{_0x367916=_0x55be9d;}}else{logger[_0x6f24('0x66')](_0x6f24('0x87'));}}else if(_0x4a7a99===_0x6f24('0x7b')){_0x20ea53=_0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x7c')];_0x13b254=_0x2d9ea0[_0x6f24('0x75')]['scriptPath'];if(_0x6f24('0x24')!=typeof _0x2d9ea0['parameters'][_0x6f24('0x76')]){if('undefined'!=typeof _0x2d9ea0[_0x6f24('0x75')]['views']['admin']){var _0x35cdb5=_0x2d9ea0[_0x6f24('0x75')]['views'][_0x6f24('0x78')];if(!/^(f|ht)tps?:\/\//i[_0x6f24('0x85')](_0x35cdb5)){_0x34f0f3=path[_0x6f24('0x52')](_0x6f24('0x88'),_0x39c49b,_0x24c574[0x0],_0x35cdb5);}else{_0x34f0f3=_0x35cdb5;}}if('undefined'!=typeof _0x2d9ea0[_0x6f24('0x75')][_0x6f24('0x76')][_0x6f24('0x79')]){var _0x55be9d=_0x2d9ea0['parameters'][_0x6f24('0x76')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0x6f24('0x85')](_0x55be9d)){_0x367916=path[_0x6f24('0x52')](_0x6f24('0x88'),_0x39c49b,_0x24c574[0x0],_0x55be9d);}else{_0x367916=_0x55be9d;}}}}var _0x443154={'name':_0x218b16,'description':_0x35af73,'path':path['join'](_0x39c49b,_0x24c574[0x0]),'type':_0x4a7a99,'sidebar':_0x24d98a,'icon':_0xce3ee8,'adminUrl':_0x34f0f3,'agentUrl':_0x367916,'scriptName':_0x20ea53,'scriptPath':_0x13b254,'version':_0x23315a};removeReferences(_0x1df326,null);return db[_0x6f24('0x36')]['create'](_0x443154)[_0x6f24('0x2e')](function(_0x2e7b2e){var _0xf826c6={'role':_0x1a740d[_0x6f24('0x89')][_0x6f24('0x8a')],'userProfileId':_0x1a740d[_0x6f24('0x89')][_0x6f24('0x8b')]};if(!_0xf826c6)throw new Error(_0x6f24('0x8c'));if(_0xf826c6[_0x6f24('0x8a')]==='user'){var _0x5ee9de=_0x2e7b2e[_0x6f24('0x2f')]({'plain':!![]});return db['UserProfileSection']['find']({'where':{'name':_0x6f24('0x30'),'userProfileId':_0xf826c6[_0x6f24('0x8b')]},'raw':!![]})[_0x6f24('0x2e')](function(_0x214bfb){if(_0x214bfb&&_0x214bfb['autoAssociation']===0x0){return db[_0x6f24('0x31')][_0x6f24('0x8d')]({'name':_0x5ee9de[_0x6f24('0x33')],'resourceId':_0x5ee9de['id'],'type':_0x214bfb['name'],'sectionId':_0x214bfb['id']},{})['then'](function(){return _0x2e7b2e;});}else{return _0x2e7b2e;}})[_0x6f24('0x4b')](function(_0x3324ed){logger[_0x6f24('0x32')](_0x6f24('0x8e'),_0x3324ed);throw _0x3324ed;});}return _0x2e7b2e;})[_0x6f24('0x2e')](respondWithResult(_0x1c423a,null))['catch'](handleError(_0x1c423a,null));}});}catch(_0x1fdc6f){_0x1c423a['status'](0x1f4)[_0x6f24('0x8f')](_0x1fdc6f);}};function removeReferences(_0x54477a,_0xa3e740){try{if(_0x54477a){fs['unlinkSync'](_0x54477a);logger[_0x6f24('0x66')]('Zip\x20archive\x20removed');}if(_0xa3e740){rimraf(_0xa3e740,function(){});logger[_0x6f24('0x66')](_0x6f24('0x90'));}}catch(_0x35a8a6){logger[_0x6f24('0x32')](_0x35a8a6);}}exports[_0x6f24('0x2c')]=function(_0x2ad40c,_0x1c77db,_0x366b00){return db[_0x6f24('0x36')]['find']({'where':{'id':_0x2ad40c[_0x6f24('0x4c')]['id']}})[_0x6f24('0x2e')](handleEntityNotFound(_0x1c77db,null))[_0x6f24('0x2e')](saveUpdates(_0x2ad40c['body'],null))[_0x6f24('0x2e')](respondWithResult(_0x1c77db,null))[_0x6f24('0x4b')](handleError(_0x1c77db,null));};exports[_0x6f24('0x91')]=function(_0x165311,_0x4ec0cc,_0x30cdc7){return db['Plugin']['find']({'where':{'id':_0x165311[_0x6f24('0x4c')]['id']}})[_0x6f24('0x2e')](function(_0x538861){if(_0x538861){return _0x538861[_0x6f24('0x2d')]();}})['then'](function(_0x13efe1){rimraf(path[_0x6f24('0x52')](config[_0x6f24('0x5f')],'server/files/plugins',path[_0x6f24('0x92')](_0x13efe1[_0x6f24('0x6')])),function(){});return _0x13efe1;})['then'](handleEntityNotFound(_0x4ec0cc,null))[_0x6f24('0x2e')](respondWithStatusCode(_0x4ec0cc,null))['catch'](handleError(_0x4ec0cc,null));};exports[_0x6f24('0x93')]=function(_0x5bdaba,_0x466061,_0x310445){return BPromise[_0x6f24('0x94')]()['then'](function(){if(!_0x5bdaba['query']['path']){throw new Error(_0x6f24('0x95'));}if(!_0x5bdaba[_0x6f24('0x3b')]['port']){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x10ad2b=_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x96')]?_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x96')]+':'+_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x97')]:_0x6f24('0x98')+_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x97')];var _0x3eece3=_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x22')]?_0x5bdaba['query'][_0x6f24('0x22')]:!![];var _0x38da0f=_0x5bdaba[_0x6f24('0x3b')]['encoding']?_0x5bdaba[_0x6f24('0x3b')]['encoding']:null;var _0x344214={'method':_0x5bdaba['method'],'uri':util['format'](_0x6f24('0x99'),_0x10ad2b,_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x6')]),'json':_0x3eece3,'resolveWithFullResponse':!![],'encoding':_0x38da0f,'qs':_0x5bdaba[_0x6f24('0x3b')]};if(_0x5bdaba[_0x6f24('0x9a')]){_0x344214['headers']=_0x5bdaba[_0x6f24('0x9a')];if(_0x344214['headers']['content-length']){delete _0x344214[_0x6f24('0x9a')][_0x6f24('0x9b')];}}if(_0x344214[_0x6f24('0x9a')][_0x6f24('0x9c')]){delete _0x344214[_0x6f24('0x9a')][_0x6f24('0x9c')];}return rp(_0x344214);})['then'](function(_0x41546a){if(_0x41546a){_0x466061[_0x6f24('0x27')](_0x41546a[_0x6f24('0x9a')]);logger[_0x6f24('0x66')](_0x41546a[_0x6f24('0x89')]);if(_[_0x6f24('0x9d')](_0x5bdaba[_0x6f24('0x3b')][_0x6f24('0x6')],_0x6f24('0x51'))&&_0x41546a[_0x6f24('0x9e')]==0x1f4){return _0x466061[_0x6f24('0x1f')](_0x41546a['statusCode']);}else{return _0x466061[_0x6f24('0x20')](_0x41546a[_0x6f24('0x9e')])[_0x6f24('0x8f')](_0x41546a[_0x6f24('0x89')]);}}else{return _0x466061['sendStatus'](0xc8);}})[_0x6f24('0x4b')](handleError(_0x466061,null));};exports[_0x6f24('0x9f')]=function(_0x48f95a,_0x5c9e45,_0x4e3b90){return BPromise[_0x6f24('0x94')]()[_0x6f24('0x2e')](function(){if(!_0x48f95a[_0x6f24('0x3b')][_0x6f24('0x6')]){throw new Error(_0x6f24('0x95'));}if(!_0x48f95a[_0x6f24('0x3b')][_0x6f24('0x97')]){throw new Error(_0x6f24('0xa0'));}var _0x9a69a8=_0x48f95a['query'][_0x6f24('0x96')]?_0x48f95a[_0x6f24('0x3b')][_0x6f24('0x96')]+':'+_0x48f95a[_0x6f24('0x3b')]['port']:_0x6f24('0x98')+_0x48f95a[_0x6f24('0x3b')][_0x6f24('0x97')];var _0x21d04a=_0x48f95a['query'][_0x6f24('0x22')]?_0x48f95a[_0x6f24('0x3b')][_0x6f24('0x22')]:!![];var _0x3c17a0=_0x48f95a[_0x6f24('0x3b')][_0x6f24('0xa1')]?_0x48f95a['query'][_0x6f24('0xa1')]:null;var _0x3d1f36={'method':_0x48f95a[_0x6f24('0xa2')],'uri':util['format'](_0x6f24('0x99'),_0x9a69a8,_0x48f95a['query'][_0x6f24('0x6')]),'json':_0x21d04a,'resolveWithFullResponse':!![],'encoding':_0x3c17a0,'body':_0x48f95a[_0x6f24('0x89')]};if(_0x48f95a[_0x6f24('0x9a')]){_0x3d1f36['headers']=_0x48f95a[_0x6f24('0x9a')];if(_0x3d1f36[_0x6f24('0x9a')][_0x6f24('0x9b')]){delete _0x3d1f36[_0x6f24('0x9a')][_0x6f24('0x9b')];}}if(_0x3d1f36['headers'][_0x6f24('0x9c')]){delete _0x3d1f36[_0x6f24('0x9a')][_0x6f24('0x9c')];}return rp(_0x3d1f36);})[_0x6f24('0x2e')](function(_0x2e7c90){if(_0x2e7c90){_0x5c9e45['set'](_0x2e7c90['headers']);logger[_0x6f24('0x66')](_0x2e7c90[_0x6f24('0x89')]);return _0x5c9e45[_0x6f24('0x20')](_0x2e7c90[_0x6f24('0x9e')])[_0x6f24('0x8f')](_0x2e7c90[_0x6f24('0x89')]);}else{return _0x5c9e45[_0x6f24('0x1f')](0xc8);}})[_0x6f24('0x4b')](handleError(_0x5c9e45,null));};