Built motion from commit 06eb8eb0.|2.6.31
[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 _0x2dd8=['../../config/utils','../../config/environment','defaults','redis','sendStatus','status','end','json','offset','undefined','limit','Content-Range','apply','reject','save','get','Plugins','destroy','then','error','name','index','Plugin','fieldName','model','map','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','pick','filter','merge','type','options','count','includeAll','include','findAll','rows','catch','params','keys','rawAttributes','length','find','path','join','root','server/files/plugins','format','basename','createWriteStream','zip','code','ENOENT','Sequelize','Error\x20while\x20generating\x20the\x20zip\x20archive','Error','pipe','glob','**/*','dirname','node_modules/**/*','finalize','close','existsSync','Plugin\x20not\x20found','download','%s.zip','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Temporary\x20file\x20removed','upload','file','filename','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isDirectory','some','manifest.json','Plugin\x20manifest\x20missing','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20parameters\x20missing','html','parameters','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','scriptName','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','views','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','Warning:\x20agent\x20view\x20not\x20specified','script','scriptPath','create','body','userProfileId','role','user','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','update','delete','webhookGet','\x27PATH\x27\x20parameter\x20not\x20specified','port','hostname','http://localhost:','encoding','%s%s','headers','content-length','content-type','set','endsWith','statusCode','send','webhookPost','resolve','method','eml-format','rimraf','request-promise','moment','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','extract-zip','archiver','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api'];(function(_0x333a5b,_0x2fe2c3){var _0x24f0d4=function(_0x3be709){while(--_0x3be709){_0x333a5b['push'](_0x333a5b['shift']());}};_0x24f0d4(++_0x2fe2c3);}(_0x2dd8,0x91));var _0x82dd=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0x2dd8[_0xa464c9];return _0x3d73c4;};'use strict';var emlformat=require(_0x82dd('0x0'));var rimraf=require(_0x82dd('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x82dd('0x2'));var moment=require(_0x82dd('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x82dd('0x4'));var util=require(_0x82dd('0x5'));var path=require('path');var sox=require(_0x82dd('0x6'));var csv=require('to-csv');var ejs=require(_0x82dd('0x7'));var fs=require('fs');var fs_extra=require(_0x82dd('0x8'));var _=require(_0x82dd('0x9'));var squel=require(_0x82dd('0xa'));var crypto=require(_0x82dd('0xb'));var jsforce=require(_0x82dd('0xc'));var deskjs=require(_0x82dd('0xd'));var toCsv=require('to-csv');var querystring=require(_0x82dd('0xe'));var Papa=require(_0x82dd('0xf'));var extract=require(_0x82dd('0x10'));var rimraf=require(_0x82dd('0x1'));var archiver=require(_0x82dd('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x82dd('0x12'));var as=require(_0x82dd('0x13'));var hardwareService=require(_0x82dd('0x14'));var logger=require(_0x82dd('0x15'))(_0x82dd('0x16'));var utils=require(_0x82dd('0x17'));var config=require(_0x82dd('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config['redis']=_[_0x82dd('0x19')](config[_0x82dd('0x1a')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x82dd('0x1a')]));require('./plugin.socket')['register'](socket);function respondWithStatusCode(_0x26d617,_0x5b286d){_0x5b286d=_0x5b286d||0xcc;return function(_0x14a9c8){if(_0x14a9c8){return _0x26d617[_0x82dd('0x1b')](_0x5b286d);}return _0x26d617[_0x82dd('0x1c')](_0x5b286d)[_0x82dd('0x1d')]();};}function respondWithResult(_0x329f75,_0x482aa6){_0x482aa6=_0x482aa6||0xc8;return function(_0x4195a6){if(_0x4195a6){return _0x329f75[_0x82dd('0x1c')](_0x482aa6)[_0x82dd('0x1e')](_0x4195a6);}};}function respondWithFilteredResult(_0x2d737a,_0x28cca6){return function(_0xf39459){if(_0xf39459){var _0x5419cf=typeof _0x28cca6[_0x82dd('0x1f')]===_0x82dd('0x20')&&typeof _0x28cca6[_0x82dd('0x21')]===_0x82dd('0x20');var _0x1e1861=_0xf39459['count'];var _0x1fc62a=_0x5419cf?0x0:_0x28cca6['offset'];var _0x4d971c=_0x5419cf?_0xf39459['count']:_0x28cca6[_0x82dd('0x1f')]+_0x28cca6['limit'];var _0x4bcdd2;if(_0x4d971c>=_0x1e1861){_0x4d971c=_0x1e1861;_0x4bcdd2=0xc8;}else{_0x4bcdd2=0xce;}_0x2d737a['status'](_0x4bcdd2);return _0x2d737a['set'](_0x82dd('0x22'),_0x1fc62a+'-'+_0x4d971c+'/'+_0x1e1861)[_0x82dd('0x1e')](_0xf39459);}return null;};}function patchUpdates(_0x415414){return function(_0x3c81a9){try{jsonpatch[_0x82dd('0x23')](_0x3c81a9,_0x415414,!![]);}catch(_0x38f9df){return BPromise[_0x82dd('0x24')](_0x38f9df);}return _0x3c81a9[_0x82dd('0x25')]();};}function saveUpdates(_0x2ad78e,_0x33c987){return function(_0x50ba1b){if(_0x50ba1b){return _0x50ba1b['update'](_0x2ad78e)['then'](function(_0x4441b7){return _0x4441b7;});}return null;};}function removeEntity(_0x3d25b0,_0x241ec0){return function(_0x3ad53f){if(_0x3ad53f){return _0x3ad53f['destroy']()['then'](function(){var _0x7fb6a2=_0x3ad53f[_0x82dd('0x26')]({'plain':!![]});var _0x544e14=_0x82dd('0x27');return db['UserProfileResource'][_0x82dd('0x28')]({'where':{'type':_0x544e14,'resourceId':_0x7fb6a2['id']}})[_0x82dd('0x29')](function(){return _0x3ad53f;});})[_0x82dd('0x29')](function(){_0x3d25b0[_0x82dd('0x1c')](0xcc)[_0x82dd('0x1d')]();});}};}function handleEntityNotFound(_0x486dac,_0xc77c8c){return function(_0x1d7657){if(!_0x1d7657){_0x486dac['sendStatus'](0x194);}return _0x1d7657;};}function handleError(_0x4c1fd9,_0x5351e8){_0x5351e8=_0x5351e8||0x1f4;return function(_0x319af7){logger[_0x82dd('0x2a')](_0x319af7['stack']);if(_0x319af7[_0x82dd('0x2b')]){delete _0x319af7[_0x82dd('0x2b')];}_0x4c1fd9['status'](_0x5351e8)['send'](_0x319af7);};}exports[_0x82dd('0x2c')]=function(_0x2264d4,_0x1572d3){var _0x80ef46={},_0x252a69={},_0x5aed46={'count':0x0,'rows':[]};var _0xcdd62d=_['map'](db[_0x82dd('0x2d')]['rawAttributes'],function(_0x1020eb){return{'name':_0x1020eb[_0x82dd('0x2e')],'type':_0x1020eb['type']['key']};});_0x252a69[_0x82dd('0x2f')]=_[_0x82dd('0x30')](_0xcdd62d,_0x82dd('0x2b'));_0x252a69[_0x82dd('0x31')]=_['keys'](_0x2264d4[_0x82dd('0x31')]);_0x252a69[_0x82dd('0x32')]=_[_0x82dd('0x33')](_0x252a69[_0x82dd('0x2f')],_0x252a69['query']);_0x80ef46['attributes']=_[_0x82dd('0x33')](_0x252a69[_0x82dd('0x2f')],qs[_0x82dd('0x34')](_0x2264d4[_0x82dd('0x31')][_0x82dd('0x34')]));_0x80ef46['attributes']=_0x80ef46[_0x82dd('0x35')]['length']?_0x80ef46[_0x82dd('0x35')]:_0x252a69[_0x82dd('0x2f')];if(!_0x2264d4[_0x82dd('0x31')][_0x82dd('0x36')](_0x82dd('0x37'))){_0x80ef46['limit']=qs[_0x82dd('0x21')](_0x2264d4['query'][_0x82dd('0x21')]);_0x80ef46['offset']=qs['offset'](_0x2264d4[_0x82dd('0x31')][_0x82dd('0x1f')]);}_0x80ef46['order']=qs[_0x82dd('0x38')](_0x2264d4['query'][_0x82dd('0x38')]);_0x80ef46[_0x82dd('0x39')]=qs[_0x82dd('0x32')](_[_0x82dd('0x3a')](_0x2264d4['query'],_0x252a69[_0x82dd('0x32')]),_0xcdd62d);if(_0x2264d4[_0x82dd('0x31')][_0x82dd('0x3b')]){_0x80ef46[_0x82dd('0x39')]=_[_0x82dd('0x3c')](_0x80ef46[_0x82dd('0x39')],{'$or':_[_0x82dd('0x30')](_0xcdd62d,function(_0x9fb0d5){if(_0x9fb0d5[_0x82dd('0x3d')]!=='VIRTUAL'){var _0x479806={};_0x479806[_0x9fb0d5[_0x82dd('0x2b')]]={'$like':'%'+_0x2264d4[_0x82dd('0x31')]['filter']+'%'};return _0x479806;}})});}_0x80ef46=_['merge']({},_0x80ef46,_0x2264d4[_0x82dd('0x3e')]);var _0x6d7532={'where':_0x80ef46['where']};return db['Plugin'][_0x82dd('0x3f')](_0x6d7532)[_0x82dd('0x29')](function(_0x6ab89){_0x5aed46[_0x82dd('0x3f')]=_0x6ab89;if(_0x2264d4[_0x82dd('0x31')][_0x82dd('0x40')]){_0x80ef46[_0x82dd('0x41')]=[{'all':!![]}];}return db[_0x82dd('0x2d')][_0x82dd('0x42')](_0x80ef46);})[_0x82dd('0x29')](function(_0xc685a1){_0x5aed46[_0x82dd('0x43')]=_0xc685a1;return _0x5aed46;})[_0x82dd('0x29')](respondWithFilteredResult(_0x1572d3,_0x80ef46))[_0x82dd('0x44')](handleError(_0x1572d3,null));};exports['show']=function(_0x2e58e4,_0x3a1ede){var _0x145d4c={'raw':!![],'where':{'id':_0x2e58e4[_0x82dd('0x45')]['id']}},_0x121014={};_0x121014[_0x82dd('0x2f')]=_[_0x82dd('0x46')](db[_0x82dd('0x2d')][_0x82dd('0x47')]);_0x121014[_0x82dd('0x31')]=_[_0x82dd('0x46')](_0x2e58e4[_0x82dd('0x31')]);_0x121014[_0x82dd('0x32')]=_['intersection'](_0x121014[_0x82dd('0x2f')],_0x121014[_0x82dd('0x31')]);_0x145d4c[_0x82dd('0x35')]=_[_0x82dd('0x33')](_0x121014[_0x82dd('0x2f')],qs[_0x82dd('0x34')](_0x2e58e4[_0x82dd('0x31')][_0x82dd('0x34')]));_0x145d4c[_0x82dd('0x35')]=_0x145d4c[_0x82dd('0x35')][_0x82dd('0x48')]?_0x145d4c[_0x82dd('0x35')]:_0x121014[_0x82dd('0x2f')];if(_0x2e58e4[_0x82dd('0x31')]['includeAll']){_0x145d4c[_0x82dd('0x41')]=[{'all':!![]}];}_0x145d4c=_['merge']({},_0x145d4c,_0x2e58e4[_0x82dd('0x3e')]);return db[_0x82dd('0x2d')][_0x82dd('0x49')](_0x145d4c)['then'](handleEntityNotFound(_0x3a1ede,null))[_0x82dd('0x29')](respondWithResult(_0x3a1ede,null))[_0x82dd('0x44')](handleError(_0x3a1ede,null));};exports['download']=function(_0x55c1c8,_0x5f51f7,_0x48231c){return db[_0x82dd('0x2d')]['find']({'where':{'id':_0x55c1c8[_0x82dd('0x45')]['id']},'attributes':['name',_0x82dd('0x4a')],'raw':!![]})['then'](handleEntityNotFound(_0x5f51f7,null))[_0x82dd('0x29')](function(_0x506860){if(_0x506860){var _0x4058b0=path[_0x82dd('0x4b')](config[_0x82dd('0x4c')],_0x82dd('0x4d'),util[_0x82dd('0x4e')]('%s.zip',path[_0x82dd('0x4f')](_0x506860['path'])));var _0x5391b4=fs[_0x82dd('0x50')](_0x4058b0);var _0x554ebc=archiver(_0x82dd('0x51'),{'zlib':{'level':0x9}});_0x554ebc['on']('warning',function(_0x40309a){if(_0x40309a[_0x82dd('0x52')]===_0x82dd('0x53')){logger['error'](_0x40309a);}else{throw new db[(_0x82dd('0x54'))]['Error'](_0x82dd('0x55'));}});_0x554ebc['on'](_0x82dd('0x2a'),function(_0x4c0ce7){throw new db[(_0x82dd('0x54'))][(_0x82dd('0x56'))](_0x82dd('0x55'));});_0x554ebc[_0x82dd('0x57')](_0x5391b4);_0x554ebc[_0x82dd('0x58')](_0x82dd('0x59'),{'cwd':path[_0x82dd('0x4b')](config[_0x82dd('0x4c')],_0x82dd('0x4d'),path[_0x82dd('0x5a')](_0x506860[_0x82dd('0x4a')])),'ignore':[path[_0x82dd('0x4b')](path[_0x82dd('0x4f')](_0x506860[_0x82dd('0x4a')]),_0x82dd('0x5b')),path[_0x82dd('0x4b')](path[_0x82dd('0x4f')](_0x506860[_0x82dd('0x4a')]),'attachments/**/*')],'nodir':!![]})[_0x82dd('0x5c')]();_0x5391b4['on'](_0x82dd('0x5d'),function(){if(!fs[_0x82dd('0x5e')](_0x4058b0)){throw new db[(_0x82dd('0x54'))][(_0x82dd('0x56'))](_0x82dd('0x5f'));}return _0x5f51f7[_0x82dd('0x60')](_0x4058b0,util['format'](_0x82dd('0x61'),path['basename'](_0x506860['path'])),function(_0x175018){if(_0x175018){throw new db[(_0x82dd('0x54'))]['Error'](_0x82dd('0x62'));}fs[_0x82dd('0x63')](_0x4058b0);logger[_0x82dd('0x64')]('Download\x20completed');logger['info'](_0x82dd('0x65'));});});}return null;})[_0x82dd('0x44')](handleError(_0x5f51f7,null));};exports[_0x82dd('0x66')]=function(_0x401375,_0x596103,_0x10fe6e){var _0x5ab1b7=path[_0x82dd('0x4f')](_0x401375[_0x82dd('0x67')]['filename'],path['extname'](_0x401375[_0x82dd('0x67')]['filename']));var _0x23e5a2=path[_0x82dd('0x4b')](config[_0x82dd('0x4c')],_0x82dd('0x4d'),_0x401375[_0x82dd('0x67')][_0x82dd('0x68')]);var _0x1f0159=path[_0x82dd('0x4b')](config[_0x82dd('0x4c')],_0x82dd('0x4d'),_0x5ab1b7);logger[_0x82dd('0x64')](_0x82dd('0x69'),_0x23e5a2);logger[_0x82dd('0x64')](_0x82dd('0x6a'),_0x1f0159);try{fs[_0x82dd('0x6b')](_0x23e5a2,parseInt(_0x82dd('0x6c'),0x8));extract(_0x23e5a2,{'dir':_0x1f0159},function(_0x1f1aa6){if(_0x1f1aa6){logger[_0x82dd('0x2a')](_0x1f1aa6);handleError(_0x1f1aa6,!![]);};var _0x2fe0bc=fs[_0x82dd('0x6d')](_0x1f0159);if(_0x2fe0bc[_0x82dd('0x48')]>0x1){removeReferences(_0x23e5a2,_0x1f0159);logger[_0x82dd('0x2a')](_0x82dd('0x6e'));return _0x10fe6e(new Error(_0x82dd('0x6e')));}var _0xac78b1=fs[_0x82dd('0x6f')](path[_0x82dd('0x4b')](_0x1f0159,_0x2fe0bc[0x0]));if(_0xac78b1['isFile']()){removeReferences(_0x23e5a2,_0x1f0159);logger['error']('Invalid\x20plugin\x20structure');return _0x10fe6e(new Error(_0x82dd('0x6e')));}if(_0xac78b1[_0x82dd('0x70')]()){var _0x447658=fs[_0x82dd('0x6d')](path['join'](_0x1f0159,_0x2fe0bc[0x0]));if(_0x447658[_0x82dd('0x48')]===0x0){removeReferences(_0x23e5a2,_0x1f0159);logger[_0x82dd('0x2a')](_0x82dd('0x6e'));return _0x10fe6e(new Error(_0x82dd('0x6e')));}var _0xe04f06=_0x447658[_0x82dd('0x71')](function(_0x5bf279){return _0x5bf279===_0x82dd('0x72');});if(!_0xe04f06){return _0x10fe6e(new Error(_0x82dd('0x73')));}var _0x1e7b16=fs['readFileSync'](path[_0x82dd('0x4b')](_0x1f0159,_0x2fe0bc[0x0],_0x82dd('0x72')));var _0x4b8d99=JSON['parse'](_0x1e7b16);if(_0x82dd('0x20')==typeof _0x4b8d99[_0x82dd('0x2b')]){return _0x10fe6e(new Error(_0x82dd('0x74')));}if('undefined'==typeof _0x4b8d99[_0x82dd('0x3d')]){return _0x10fe6e(new Error(_0x82dd('0x75')));}if(_0x82dd('0x20')==typeof _0x4b8d99[_0x82dd('0x76')]){return _0x10fe6e(new Error('Invalid\x20manifest:\x20version\x20not\x20specified'));}if(_0x82dd('0x20')==typeof _0x4b8d99['parameters']){return _0x10fe6e(new Error(_0x82dd('0x77')));}if(_0x4b8d99[_0x82dd('0x3d')]===_0x82dd('0x78')){if(_0x82dd('0x20')==typeof _0x4b8d99[_0x82dd('0x79')]['views']){return _0x10fe6e(new Error(_0x82dd('0x7a')));}if(_0x82dd('0x20')==typeof _0x4b8d99[_0x82dd('0x79')]['views'][_0x82dd('0x7b')]&&'undefined'==typeof _0x4b8d99['parameters']['views'][_0x82dd('0x7c')]){return _0x10fe6e(new Error(_0x82dd('0x7d')));}}else if(_0x4b8d99[_0x82dd('0x3d')]==='script'){if('undefined'==typeof _0x4b8d99[_0x82dd('0x79')][_0x82dd('0x7e')]){return _0x10fe6e(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if(_0x82dd('0x20')==typeof _0x4b8d99[_0x82dd('0x79')]['scriptPath']){return _0x10fe6e(new Error(_0x82dd('0x7f')));}}else{return _0x10fe6e(new Error(_0x82dd('0x80')));}var _0x434446=_0x4b8d99[_0x82dd('0x2b')];var _0x34853e=_0x4b8d99[_0x82dd('0x81')];var _0x5d1c0c=_0x4b8d99[_0x82dd('0x3d')];var _0x217831=_0x4b8d99[_0x82dd('0x82')]?_0x4b8d99['sidebar']:_0x82dd('0x83');var _0x4c60de=_0x4b8d99['icon']?_0x4b8d99[_0x82dd('0x84')]:_0x82dd('0x85');var _0x45b2dc='';var _0x33d738='';var _0x32178d='';var _0x23885d='';var _0x3e40cc=_0x4b8d99[_0x82dd('0x76')];if(_0x5d1c0c===_0x82dd('0x78')){if('undefined'!=typeof _0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')][_0x82dd('0x7b')]){var _0x30c1b4=_0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')][_0x82dd('0x7b')];if(!/^(f|ht)tps?:\/\//i[_0x82dd('0x87')](_0x30c1b4)){_0x45b2dc=path[_0x82dd('0x4b')](_0x82dd('0x88'),_0x5ab1b7,_0x2fe0bc[0x0],_0x30c1b4);}else{_0x45b2dc=_0x30c1b4;}}else{logger[_0x82dd('0x64')](_0x82dd('0x89'));}if('undefined'!=typeof _0x4b8d99['parameters'][_0x82dd('0x86')][_0x82dd('0x7c')]){var _0x56a067=_0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')][_0x82dd('0x7c')];if(!/^(f|ht)tps?:\/\//i[_0x82dd('0x87')](_0x56a067)){_0x33d738=path[_0x82dd('0x4b')](_0x82dd('0x88'),_0x5ab1b7,_0x2fe0bc[0x0],_0x56a067);}else{_0x33d738=_0x56a067;}}else{logger[_0x82dd('0x64')](_0x82dd('0x8a'));}}else if(_0x5d1c0c===_0x82dd('0x8b')){_0x32178d=_0x4b8d99[_0x82dd('0x79')][_0x82dd('0x7e')];_0x23885d=_0x4b8d99[_0x82dd('0x79')][_0x82dd('0x8c')];if(_0x82dd('0x20')!=typeof _0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')]){if(_0x82dd('0x20')!=typeof _0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')][_0x82dd('0x7b')]){var _0x30c1b4=_0x4b8d99[_0x82dd('0x79')]['views'][_0x82dd('0x7b')];if(!/^(f|ht)tps?:\/\//i[_0x82dd('0x87')](_0x30c1b4)){_0x45b2dc=path[_0x82dd('0x4b')](_0x82dd('0x88'),_0x5ab1b7,_0x2fe0bc[0x0],_0x30c1b4);}else{_0x45b2dc=_0x30c1b4;}}if('undefined'!=typeof _0x4b8d99[_0x82dd('0x79')]['views'][_0x82dd('0x7c')]){var _0x56a067=_0x4b8d99[_0x82dd('0x79')][_0x82dd('0x86')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0x82dd('0x87')](_0x56a067)){_0x33d738=path[_0x82dd('0x4b')](_0x82dd('0x88'),_0x5ab1b7,_0x2fe0bc[0x0],_0x56a067);}else{_0x33d738=_0x56a067;}}}}var _0x441209={'name':_0x434446,'description':_0x34853e,'path':path[_0x82dd('0x4b')](_0x5ab1b7,_0x2fe0bc[0x0]),'type':_0x5d1c0c,'sidebar':_0x217831,'icon':_0x4c60de,'adminUrl':_0x45b2dc,'agentUrl':_0x33d738,'scriptName':_0x32178d,'scriptPath':_0x23885d,'version':_0x3e40cc};removeReferences(_0x23e5a2,null);return db['Plugin'][_0x82dd('0x8d')](_0x441209)[_0x82dd('0x29')](function(_0x433845){var _0x1e70a1={'role':_0x401375[_0x82dd('0x8e')]['role'],'userProfileId':_0x401375['body'][_0x82dd('0x8f')]};if(!_0x1e70a1)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1e70a1[_0x82dd('0x90')]===_0x82dd('0x91')){var _0x4f408c=_0x433845[_0x82dd('0x26')]({'plain':!![]});return db[_0x82dd('0x92')][_0x82dd('0x49')]({'where':{'name':_0x82dd('0x27'),'userProfileId':_0x1e70a1[_0x82dd('0x8f')]},'raw':!![]})[_0x82dd('0x29')](function(_0x24ac5e){if(_0x24ac5e&&_0x24ac5e['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x4f408c['name'],'resourceId':_0x4f408c['id'],'type':_0x24ac5e[_0x82dd('0x2b')],'sectionId':_0x24ac5e['id']},{})[_0x82dd('0x29')](function(){return _0x433845;});}else{return _0x433845;}})['catch'](function(_0x5c94e2){logger[_0x82dd('0x2a')](_0x82dd('0x93'),_0x5c94e2);throw _0x5c94e2;});}return _0x433845;})['then'](respondWithResult(_0x596103,null))['catch'](handleError(_0x596103,null));}});}catch(_0x1dba95){_0x596103['status'](0x1f4)['send'](_0x1dba95);}};function removeReferences(_0x2c0660,_0x53c042){try{if(_0x2c0660){fs[_0x82dd('0x63')](_0x2c0660);logger[_0x82dd('0x64')](_0x82dd('0x94'));}if(_0x53c042){rimraf(_0x53c042,function(){});logger['info']('Extracted\x20folder\x20removed');}}catch(_0x180537){logger[_0x82dd('0x2a')](_0x180537);}}exports[_0x82dd('0x95')]=function(_0x130b88,_0x2c41a6,_0x5ec206){return db[_0x82dd('0x2d')][_0x82dd('0x49')]({'where':{'id':_0x130b88[_0x82dd('0x45')]['id']}})[_0x82dd('0x29')](handleEntityNotFound(_0x2c41a6,null))[_0x82dd('0x29')](saveUpdates(_0x130b88[_0x82dd('0x8e')],null))[_0x82dd('0x29')](respondWithResult(_0x2c41a6,null))['catch'](handleError(_0x2c41a6,null));};exports[_0x82dd('0x96')]=function(_0x2eb9b7,_0x1fb150,_0x398cb3){return db[_0x82dd('0x2d')]['find']({'where':{'id':_0x2eb9b7[_0x82dd('0x45')]['id']}})[_0x82dd('0x29')](function(_0x2f9994){if(_0x2f9994){return _0x2f9994[_0x82dd('0x28')]();}})[_0x82dd('0x29')](function(_0x41b884){rimraf(path['join'](config[_0x82dd('0x4c')],'server/files/plugins',path[_0x82dd('0x5a')](_0x41b884[_0x82dd('0x4a')])),function(){});return _0x41b884;})[_0x82dd('0x29')](handleEntityNotFound(_0x1fb150,null))['then'](respondWithStatusCode(_0x1fb150,null))[_0x82dd('0x44')](handleError(_0x1fb150,null));};exports[_0x82dd('0x97')]=function(_0x4a685a,_0x1f333c,_0x48eb4a){return BPromise['resolve']()['then'](function(){if(!_0x4a685a['query'][_0x82dd('0x4a')]){throw new Error(_0x82dd('0x98'));}if(!_0x4a685a[_0x82dd('0x31')][_0x82dd('0x99')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x306ea8=_0x4a685a[_0x82dd('0x31')][_0x82dd('0x9a')]?_0x4a685a[_0x82dd('0x31')][_0x82dd('0x9a')]+':'+_0x4a685a[_0x82dd('0x31')][_0x82dd('0x99')]:_0x82dd('0x9b')+_0x4a685a[_0x82dd('0x31')][_0x82dd('0x99')];var _0x2a4bee=_0x4a685a['query']['json']?_0x4a685a[_0x82dd('0x31')][_0x82dd('0x1e')]:!![];var _0x495b6c=_0x4a685a[_0x82dd('0x31')][_0x82dd('0x9c')]?_0x4a685a[_0x82dd('0x31')][_0x82dd('0x9c')]:null;var _0x4aef5d={'method':_0x4a685a['method'],'uri':util[_0x82dd('0x4e')](_0x82dd('0x9d'),_0x306ea8,_0x4a685a[_0x82dd('0x31')][_0x82dd('0x4a')]),'json':_0x2a4bee,'resolveWithFullResponse':!![],'encoding':_0x495b6c,'qs':_0x4a685a['query']};if(_0x4a685a['headers']){_0x4aef5d[_0x82dd('0x9e')]=_0x4a685a[_0x82dd('0x9e')];if(_0x4aef5d[_0x82dd('0x9e')]['content-length']){delete _0x4aef5d[_0x82dd('0x9e')][_0x82dd('0x9f')];}}if(_0x4aef5d['headers'][_0x82dd('0xa0')]){delete _0x4aef5d['headers'][_0x82dd('0xa0')];}return rp(_0x4aef5d);})[_0x82dd('0x29')](function(_0x3fe90e){if(_0x3fe90e){_0x1f333c[_0x82dd('0xa1')](_0x3fe90e[_0x82dd('0x9e')]);logger[_0x82dd('0x64')](_0x3fe90e['body']);if(_[_0x82dd('0xa2')](_0x4a685a[_0x82dd('0x31')][_0x82dd('0x4a')],_0x82dd('0x60'))&&_0x3fe90e[_0x82dd('0xa3')]==0x1f4){return _0x1f333c[_0x82dd('0x1b')](_0x3fe90e[_0x82dd('0xa3')]);}else{return _0x1f333c[_0x82dd('0x1c')](_0x3fe90e[_0x82dd('0xa3')])[_0x82dd('0xa4')](_0x3fe90e['body']);}}else{return _0x1f333c[_0x82dd('0x1b')](0xc8);}})[_0x82dd('0x44')](handleError(_0x1f333c,null));};exports[_0x82dd('0xa5')]=function(_0x2fae8b,_0x506c9c,_0x539468){return BPromise[_0x82dd('0xa6')]()['then'](function(){if(!_0x2fae8b['query'][_0x82dd('0x4a')]){throw new Error(_0x82dd('0x98'));}if(!_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x99')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x125234=_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x9a')]?_0x2fae8b[_0x82dd('0x31')]['hostname']+':'+_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x99')]:_0x82dd('0x9b')+_0x2fae8b['query'][_0x82dd('0x99')];var _0x5198e9=_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x1e')]?_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x1e')]:!![];var _0x7b1bf8=_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x9c')]?_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x9c')]:null;var _0x21aa21={'method':_0x2fae8b[_0x82dd('0xa7')],'uri':util['format'](_0x82dd('0x9d'),_0x125234,_0x2fae8b[_0x82dd('0x31')][_0x82dd('0x4a')]),'json':_0x5198e9,'resolveWithFullResponse':!![],'encoding':_0x7b1bf8,'body':_0x2fae8b[_0x82dd('0x8e')]};if(_0x2fae8b[_0x82dd('0x9e')]){_0x21aa21[_0x82dd('0x9e')]=_0x2fae8b['headers'];if(_0x21aa21[_0x82dd('0x9e')][_0x82dd('0x9f')]){delete _0x21aa21['headers'][_0x82dd('0x9f')];}}if(_0x21aa21['headers']['content-type']){delete _0x21aa21[_0x82dd('0x9e')][_0x82dd('0xa0')];}return rp(_0x21aa21);})['then'](function(_0x507ae9){if(_0x507ae9){_0x506c9c[_0x82dd('0xa1')](_0x507ae9[_0x82dd('0x9e')]);logger[_0x82dd('0x64')](_0x507ae9['body']);return _0x506c9c[_0x82dd('0x1c')](_0x507ae9['statusCode'])[_0x82dd('0xa4')](_0x507ae9[_0x82dd('0x8e')]);}else{return _0x506c9c[_0x82dd('0x1b')](0xc8);}})[_0x82dd('0x44')](handleError(_0x506c9c,null));};