18 var _0xa099=['utf8','server/files/templates/registry.ejs','render','writeFileSync','/etc/asterisk/sip_xcally_trunks.conf','registry','/etc/asterisk/sip_xcally_registers.conf','Reload','chan_sip.so','server/files/templates/trunk.ejs','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','request','then','Trunk,\x20%s,\x20%s','request\x20sent','debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','code','error','message','catch','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','get','Trunks','UserProfileResource','stack','name','send','index','map','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','Trunk','includeAll','include','findAll','rows','show','params','rawAttributes','find','clone','omit','createdAt','updatedAt','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','create','readFileSync','join','root'];(function(_0x24bd55,_0x14c2e3){var _0x103a8f=function(_0x2aa9c4){while(--_0x2aa9c4){_0x24bd55['push'](_0x24bd55['shift']());}};_0x103a8f(++_0x14c2e3);}(_0xa099,0x15d));var _0x9a09=function(_0x9f69c6,_0x44168c){_0x9f69c6=_0x9f69c6-0x0;var _0x1b893f=_0xa099[_0x9f69c6];return _0x1b893f;};'use strict';var pdf=require(_0x9a09('0x0'));var emlformat=require(_0x9a09('0x1'));var rimraf=require(_0x9a09('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x9a09('0x3'));var rp=require(_0x9a09('0x4'));var moment=require('moment');var BPromise=require(_0x9a09('0x5'));var Mustache=require(_0x9a09('0x6'));var util=require('util');var path=require(_0x9a09('0x7'));var sox=require(_0x9a09('0x8'));var csv=require(_0x9a09('0x9'));var ejs=require(_0x9a09('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x9a09('0xb'));var jsforce=require(_0x9a09('0xc'));var deskjs=require(_0x9a09('0xd'));var toCsv=require(_0x9a09('0x9'));var querystring=require(_0x9a09('0xe'));var Papa=require(_0x9a09('0xf'));var Redis=require(_0x9a09('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x9a09('0x11'));var as=require(_0x9a09('0x12'));var hardwareService=require(_0x9a09('0x13'));var logger=require(_0x9a09('0x14'))(_0x9a09('0x15'));var utils=require(_0x9a09('0x16'));var config=require(_0x9a09('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x9a09('0x18'))['db'];var jayson=require(_0x9a09('0x19'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1e78a1,_0x2d6436,_0x546f81,_0x315c4f){return new BPromise(function(_0x48a6c0,_0x305ce9){var _0x3a02c3=_0x315c4f||client;return _0x3a02c3[_0x9a09('0x1a')](_0x1e78a1,_0x546f81)[_0x9a09('0x1b')](function(_0xa717b){logger['info'](_0x9a09('0x1c'),_0x2d6436,_0x9a09('0x1d'));logger[_0x9a09('0x1e')](_0x9a09('0x1f'),_0x2d6436,_0x9a09('0x1d'),JSON[_0x9a09('0x20')](_0xa717b));if(_0xa717b['error']){if(_0xa717b['error'][_0x9a09('0x21')]===0x1f4){logger[_0x9a09('0x22')]('Trunk,\x20%s,\x20%s',_0x2d6436,_0xa717b[_0x9a09('0x22')][_0x9a09('0x23')]);return _0x305ce9(_0xa717b[_0x9a09('0x22')][_0x9a09('0x23')]);}logger[_0x9a09('0x22')](_0x9a09('0x1c'),_0x2d6436,_0xa717b[_0x9a09('0x22')][_0x9a09('0x23')]);return _0x48a6c0(_0xa717b['error'][_0x9a09('0x23')]);}else{logger['info'](_0x9a09('0x1c'),_0x2d6436,_0x9a09('0x1d'));_0x48a6c0(_0xa717b['result'][_0x9a09('0x23')]);}})[_0x9a09('0x24')](function(_0x122b73){logger[_0x9a09('0x22')](_0x9a09('0x1c'),_0x2d6436,_0x122b73);_0x305ce9(_0x122b73);});});}function respondWithStatusCode(_0x3c21f5,_0x3ed1a0){_0x3ed1a0=_0x3ed1a0||0xcc;return function(_0x2d7516){if(_0x2d7516){return _0x3c21f5[_0x9a09('0x25')](_0x3ed1a0);}return _0x3c21f5[_0x9a09('0x26')](_0x3ed1a0)[_0x9a09('0x27')]();};}function respondWithResult(_0x39edca,_0x162a49){_0x162a49=_0x162a49||0xc8;return function(_0x10f30c){if(_0x10f30c){return _0x39edca[_0x9a09('0x26')](_0x162a49)['json'](_0x10f30c);}};}function respondWithFilteredResult(_0x396c71,_0x39da6f){return function(_0x92e465){if(_0x92e465){var _0x21edc0=_0x92e465[_0x9a09('0x28')],_0x31e2d0=_0x39da6f[_0x9a09('0x29')],_0x240f65=_0x39da6f[_0x9a09('0x29')]+_0x39da6f[_0x9a09('0x2a')],_0x4c9241;if(_0x240f65>=_0x21edc0){_0x240f65=_0x21edc0;_0x4c9241=0xc8;}else{_0x4c9241=0xce;}_0x396c71[_0x9a09('0x26')](_0x4c9241);return _0x396c71[_0x9a09('0x2b')](_0x9a09('0x2c'),_0x31e2d0+'-'+_0x240f65+'/'+_0x21edc0)[_0x9a09('0x2d')](_0x92e465);}return null;};}function patchUpdates(_0x5ba6af){return function(_0x422c51){try{jsonpatch[_0x9a09('0x2e')](_0x422c51,_0x5ba6af,!![]);}catch(_0x200a01){return BPromise[_0x9a09('0x2f')](_0x200a01);}return _0x422c51[_0x9a09('0x30')]();};}function saveUpdates(_0x2900c7,_0x557307){return function(_0xb4b112){if(_0xb4b112){return _0xb4b112[_0x9a09('0x31')](_0x2900c7)[_0x9a09('0x1b')](function(_0x122535){return _0x122535;});}return null;};}function removeEntity(_0x10fcda,_0xbd484c){return function(_0x355dfb){if(_0x355dfb){return _0x355dfb[_0x9a09('0x32')]()[_0x9a09('0x1b')](function(){var _0x128e11=_0x355dfb[_0x9a09('0x33')]({'plain':!![]});var _0xbc364=_0x9a09('0x34');return db[_0x9a09('0x35')][_0x9a09('0x32')]({'where':{'type':_0xbc364,'resourceId':_0x128e11['id']}})[_0x9a09('0x1b')](function(){return _0x355dfb;});})[_0x9a09('0x1b')](function(){_0x10fcda[_0x9a09('0x26')](0xcc)[_0x9a09('0x27')]();});}};}function handleEntityNotFound(_0x2112ea,_0x5700b9){return function(_0x27418a){if(!_0x27418a){_0x2112ea[_0x9a09('0x25')](0x194);}return _0x27418a;};}function handleError(_0x454ad2,_0xf85bbb){_0xf85bbb=_0xf85bbb||0x1f4;return function(_0x59fd6f){logger[_0x9a09('0x22')](_0x59fd6f[_0x9a09('0x36')]);if(_0x59fd6f[_0x9a09('0x37')]){delete _0x59fd6f['name'];}_0x454ad2[_0x9a09('0x26')](_0xf85bbb)[_0x9a09('0x38')](_0x59fd6f);};}exports[_0x9a09('0x39')]=function(_0x15b1a2,_0x2240fe){var _0x41cc27={},_0x4278e9={},_0x4894c1={'count':0x0,'rows':[]};var _0x4fe0d7=_[_0x9a09('0x3a')](db['Trunk']['rawAttributes'],function(_0x3287c0){return{'name':_0x3287c0[_0x9a09('0x3b')],'type':_0x3287c0[_0x9a09('0x3c')][_0x9a09('0x3d')]};});_0x4278e9[_0x9a09('0x3e')]=_[_0x9a09('0x3a')](_0x4fe0d7,'name');_0x4278e9[_0x9a09('0x3f')]=_[_0x9a09('0x40')](_0x15b1a2[_0x9a09('0x3f')]);_0x4278e9[_0x9a09('0x41')]=_[_0x9a09('0x42')](_0x4278e9[_0x9a09('0x3e')],_0x4278e9[_0x9a09('0x3f')]);_0x41cc27[_0x9a09('0x43')]=_[_0x9a09('0x42')](_0x4278e9[_0x9a09('0x3e')],qs['fields'](_0x15b1a2['query'][_0x9a09('0x44')]));_0x41cc27['attributes']=_0x41cc27[_0x9a09('0x43')][_0x9a09('0x45')]?_0x41cc27[_0x9a09('0x43')]:_0x4278e9['model'];if(!_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x46')](_0x9a09('0x47'))){_0x41cc27[_0x9a09('0x2a')]=qs['limit'](_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x2a')]);_0x41cc27[_0x9a09('0x29')]=qs[_0x9a09('0x29')](_0x15b1a2['query'][_0x9a09('0x29')]);}_0x41cc27[_0x9a09('0x48')]=qs[_0x9a09('0x49')](_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x49')]);_0x41cc27[_0x9a09('0x4a')]=qs[_0x9a09('0x41')](_[_0x9a09('0x4b')](_0x15b1a2[_0x9a09('0x3f')],_0x4278e9[_0x9a09('0x41')]),_0x4fe0d7);if(_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x4c')]){_0x41cc27[_0x9a09('0x4a')]=_[_0x9a09('0x4d')](_0x41cc27[_0x9a09('0x4a')],{'$or':_['map'](_0x4fe0d7,function(_0x38dde3){if(_0x38dde3[_0x9a09('0x3c')]!=='VIRTUAL'){var _0x59f431={};_0x59f431[_0x38dde3[_0x9a09('0x37')]]={'$like':'%'+_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x4c')]+'%'};return _0x59f431;}})});}_0x41cc27=_[_0x9a09('0x4d')]({},_0x41cc27,_0x15b1a2[_0x9a09('0x4e')]);var _0x17dbd0={'where':_0x41cc27[_0x9a09('0x4a')]};return db[_0x9a09('0x4f')]['count'](_0x17dbd0)[_0x9a09('0x1b')](function(_0x4a1638){_0x4894c1[_0x9a09('0x28')]=_0x4a1638;if(_0x15b1a2[_0x9a09('0x3f')][_0x9a09('0x50')]){_0x41cc27[_0x9a09('0x51')]=[{'all':!![]}];}return db['Trunk'][_0x9a09('0x52')](_0x41cc27);})[_0x9a09('0x1b')](function(_0x12e7b6){_0x4894c1[_0x9a09('0x53')]=_0x12e7b6;return _0x4894c1;})['then'](respondWithFilteredResult(_0x2240fe,_0x41cc27))['catch'](handleError(_0x2240fe,null));};exports[_0x9a09('0x54')]=function(_0x293dac,_0x219939){var _0x44ad4c={'raw':![],'where':{'id':_0x293dac[_0x9a09('0x55')]['id']}},_0x3931a9={};_0x3931a9[_0x9a09('0x3e')]=_['keys'](db['Trunk'][_0x9a09('0x56')]);_0x3931a9[_0x9a09('0x3f')]=_[_0x9a09('0x40')](_0x293dac['query']);_0x3931a9['filters']=_[_0x9a09('0x42')](_0x3931a9[_0x9a09('0x3e')],_0x3931a9[_0x9a09('0x3f')]);_0x44ad4c[_0x9a09('0x43')]=_['intersection'](_0x3931a9[_0x9a09('0x3e')],qs[_0x9a09('0x44')](_0x293dac[_0x9a09('0x3f')][_0x9a09('0x44')]));_0x44ad4c[_0x9a09('0x43')]=_0x44ad4c[_0x9a09('0x43')][_0x9a09('0x45')]?_0x44ad4c[_0x9a09('0x43')]:_0x3931a9['model'];if(_0x293dac[_0x9a09('0x3f')][_0x9a09('0x50')]){_0x44ad4c['include']=[{'all':!![]}];}_0x44ad4c=_[_0x9a09('0x4d')]({},_0x44ad4c,_0x293dac[_0x9a09('0x4e')]);return db['Trunk'][_0x9a09('0x57')](_0x44ad4c)[_0x9a09('0x1b')](handleEntityNotFound(_0x219939,null))[_0x9a09('0x1b')](respondWithResult(_0x219939,null))['catch'](handleError(_0x219939,null));};exports[_0x9a09('0x58')]=function(_0x45ad05,_0x3e505){var _0x149714={'where':{'id':_0x45ad05[_0x9a09('0x55')]['id']}},_0x44909d={};_0x44909d[_0x9a09('0x3e')]=_[_0x9a09('0x40')](db[_0x9a09('0x4f')][_0x9a09('0x56')]);_0x149714[_0x9a09('0x43')]=_['intersection'](_0x44909d['model'],qs['fields'](_0x45ad05[_0x9a09('0x3f')]['fields']));_0x149714[_0x9a09('0x43')]=_0x149714['attributes'][_0x9a09('0x45')]?_0x149714[_0x9a09('0x43')]:_0x44909d['model'];if(_0x45ad05[_0x9a09('0x3f')][_0x9a09('0x50')]){_0x149714[_0x9a09('0x51')]=[{'all':!![]}];}_0x149714=_[_0x9a09('0x4d')]({},_0x149714,_0x45ad05['options']);return db['Trunk'][_0x9a09('0x57')](_0x149714)[_0x9a09('0x1b')](handleEntityNotFound(_0x3e505,null))[_0x9a09('0x1b')](function(_0x1f26dd){if(_0x1f26dd){var _0x514706=_0x1f26dd[_0x9a09('0x33')]({'plain':!![]});_0x514706=qs[_0x9a09('0x59')](_0x514706,['id',_0x9a09('0x5a'),_0x9a09('0x5b')]);_0x45ad05['body']=_[_0x9a09('0x59')](_0x45ad05[_0x9a09('0x5c')],['id',_0x9a09('0x5a'),'updatedAt']);return db[_0x9a09('0x4f')]['create'](_['merge'](_0x514706,_0x45ad05[_0x9a09('0x5c')]),{'include':_0x45ad05[_0x9a09('0x3f')]['includeAll']?[{'all':!![]}]:undefined})[_0x9a09('0x1b')](function(_0x583d47){var _0x180a6c=_0x45ad05[_0x9a09('0x5d')][_0x9a09('0x33')]({'plain':!![]});if(!_0x180a6c)throw new Error(_0x9a09('0x5e'));if(_0x180a6c[_0x9a09('0x5f')]===_0x9a09('0x5d')){var _0x285d44=_0x583d47[_0x9a09('0x33')]({'plain':!![]});var _0x1e0f98=_0x9a09('0x34');return db[_0x9a09('0x60')]['find']({'where':{'name':_0x1e0f98,'userProfileId':_0x180a6c[_0x9a09('0x61')]},'raw':!![]})[_0x9a09('0x1b')](function(_0x2f27a7){if(_0x2f27a7&&_0x2f27a7[_0x9a09('0x62')]===0x0){return db['UserProfileResource'][_0x9a09('0x63')]({'name':_0x285d44[_0x9a09('0x37')],'resourceId':_0x285d44['id'],'type':_0x2f27a7['name'],'sectionId':_0x2f27a7['id']},{})[_0x9a09('0x1b')](function(){return _0x583d47;});}else{return _0x583d47;}})[_0x9a09('0x24')](function(_0x4531d8){logger[_0x9a09('0x22')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4531d8);throw _0x4531d8;});}return _0x583d47;});}})[_0x9a09('0x1b')](respondWithResult(_0x3e505,0xc9))[_0x9a09('0x24')](handleError(_0x3e505,null));};exports[_0x9a09('0x63')]=function(_0x3a737d,_0x237859,_0x2e936b){var _0x3f0435;return db[_0x9a09('0x4f')][_0x9a09('0x63')](_0x3a737d['body'],{'raw':!![]})[_0x9a09('0x1b')](function(_0x403e3e){_0x3f0435=_0x403e3e;return db['Trunk']['findAll']({'raw':!![]});})[_0x9a09('0x1b')](function(_0x4cffd3){var _0x4ef9b9=fs[_0x9a09('0x64')](path[_0x9a09('0x65')](config[_0x9a09('0x66')],'server/files/templates/trunk.ejs'),_0x9a09('0x67'));var _0x565f3b=fs['readFileSync'](path[_0x9a09('0x65')](config[_0x9a09('0x66')],_0x9a09('0x68')),_0x9a09('0x67'));var _0x2c6fa5=ejs[_0x9a09('0x69')](_0x4ef9b9,{'trunks':_0x4cffd3||[]});fs[_0x9a09('0x6a')](_0x9a09('0x6b'),_0x2c6fa5);if(_0x3f0435[_0x9a09('0x6c')]){var _0x1a0e54=ejs[_0x9a09('0x69')](_0x565f3b,{'trunks':_0x4cffd3||[]});fs[_0x9a09('0x6a')](_0x9a09('0x6d'),_0x1a0e54);}})[_0x9a09('0x1b')](function(){return respondWithRpcPromise(_0x9a09('0x6e'),_0x9a09('0x63'),{'module':_0x9a09('0x6f')});})['then'](function(){var _0xf152cb=_0x3a737d['user'][_0x9a09('0x33')]({'plain':!![]});if(!_0xf152cb)throw new Error(_0x9a09('0x5e'));if(_0xf152cb['role']===_0x9a09('0x5d')){var _0x57a08c=_0x3f0435[_0x9a09('0x33')]({'plain':!![]});return db[_0x9a09('0x60')][_0x9a09('0x57')]({'where':{'name':_0x9a09('0x34'),'userProfileId':_0xf152cb['userProfileId']},'raw':!![]})[_0x9a09('0x1b')](function(_0x1b065c){if(_0x1b065c&&_0x1b065c[_0x9a09('0x62')]===0x0){return db[_0x9a09('0x35')][_0x9a09('0x63')]({'name':_0x57a08c[_0x9a09('0x37')],'resourceId':_0x57a08c['id'],'type':_0x1b065c[_0x9a09('0x37')],'sectionId':_0x1b065c['id']},{})[_0x9a09('0x1b')](function(){return _0x3f0435;});}else{return _0x3f0435;}})[_0x9a09('0x24')](function(_0x377b7c){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x377b7c);throw _0x377b7c;});}return _0x3f0435;})[_0x9a09('0x1b')](respondWithResult(_0x237859,0xc9))['catch'](handleError(_0x237859,null));};exports[_0x9a09('0x31')]=function(_0x2c238f,_0x1173e5,_0x594158){var _0x21b889;return db[_0x9a09('0x4f')]['find']({'where':{'id':_0x2c238f[_0x9a09('0x55')]['id']}})[_0x9a09('0x1b')](handleEntityNotFound(_0x1173e5,null))['then'](saveUpdates(_0x2c238f[_0x9a09('0x5c')],null))[_0x9a09('0x1b')](function(_0x1e4ce2){if(_0x1e4ce2){_0x21b889=_0x1e4ce2;return db['Trunk'][_0x9a09('0x52')]({'raw':!![]});}})[_0x9a09('0x1b')](function(_0x4edd46){if(_0x4edd46){var _0x4c15d5=fs['readFileSync'](path[_0x9a09('0x65')](config[_0x9a09('0x66')],_0x9a09('0x70')),_0x9a09('0x67'));var _0x1948bf=fs[_0x9a09('0x64')](path[_0x9a09('0x65')](config[_0x9a09('0x66')],_0x9a09('0x68')),_0x9a09('0x67'));var _0x5104fd=ejs[_0x9a09('0x69')](_0x4c15d5,{'trunks':_0x4edd46||[]});fs[_0x9a09('0x6a')](_0x9a09('0x6b'),_0x5104fd);var _0x2a0548=ejs[_0x9a09('0x69')](_0x1948bf,{'trunks':_0x4edd46||[]});fs[_0x9a09('0x6a')](_0x9a09('0x6d'),_0x2a0548);return respondWithRpcPromise(_0x9a09('0x6e'),_0x9a09('0x31'),{'module':'chan_sip.so'});}return null;})[_0x9a09('0x1b')](function(_0x403dd9){if(_0x403dd9){return _0x21b889;}})[_0x9a09('0x1b')](respondWithResult(_0x1173e5,null))[_0x9a09('0x24')](handleError(_0x1173e5,null));};exports[_0x9a09('0x32')]=function(_0x5bf332,_0x1789e1,_0x1b69e2){var _0x2b49b8;return db['Trunk']['find']({'where':{'id':_0x5bf332[_0x9a09('0x55')]['id']}})[_0x9a09('0x1b')](handleEntityNotFound(_0x1789e1,null))['then'](removeEntity(_0x1789e1,null))['then'](function(){return db[_0x9a09('0x4f')][_0x9a09('0x52')]({'raw':!![]});})[_0x9a09('0x1b')](function(_0x5d3892){var _0x3bdf73=fs['readFileSync'](path[_0x9a09('0x65')](config['root'],_0x9a09('0x70')),'utf8');var _0x4a763b=fs[_0x9a09('0x64')](path[_0x9a09('0x65')](config[_0x9a09('0x66')],_0x9a09('0x68')),_0x9a09('0x67'));var _0x5519ca=ejs['render'](_0x3bdf73,{'trunks':_0x5d3892});var _0x36ddac=ejs[_0x9a09('0x69')](_0x4a763b,{'trunks':_0x5d3892});fs['writeFileSync'](_0x9a09('0x6b'),_0x5519ca);fs[_0x9a09('0x6a')](_0x9a09('0x6d'),_0x36ddac);return respondWithRpcPromise(_0x9a09('0x6e'),_0x9a09('0x32'),{'module':_0x9a09('0x6f')});})[_0x9a09('0x24')](handleError(_0x1789e1,null));};